List of usage examples for org.bouncycastle.asn1.x509 AttCertValidityPeriod getNotBeforeTime
public ASN1GeneralizedTime getNotBeforeTime()
From source file:eu.europa.ec.markt.dss.validation102853.cades.CAdESSignature.java
License:Open Source License
@Override public List<CertifiedRole> getCertifiedSignerRoles() { final AttributeTable signedAttributes = signerInformation.getSignedAttributes(); if (signedAttributes == null) { return null; }//from ww w. jav a 2 s. c o m final Attribute id_aa_ets_signerAttr = signedAttributes.get(PKCSObjectIdentifiers.id_aa_ets_signerAttr); if (id_aa_ets_signerAttr == null) { return null; } final ASN1Set attrValues = id_aa_ets_signerAttr.getAttrValues(); final ASN1Encodable asn1EncodableAttrValue = attrValues.getObjectAt(0); try { final SignerAttribute signerAttr = SignerAttribute.getInstance(asn1EncodableAttrValue); if (signerAttr == null) { return null; } List<CertifiedRole> roles = null; final Object[] signerAttrValues = signerAttr.getValues(); for (final Object signerAttrValue : signerAttrValues) { if (signerAttrValue instanceof AttributeCertificate) { if (roles == null) { roles = new ArrayList<CertifiedRole>(); } final AttributeCertificate attributeCertificate = (AttributeCertificate) signerAttrValue; final AttributeCertificateInfo acInfo = attributeCertificate.getAcinfo(); final AttCertValidityPeriod attrCertValidityPeriod = acInfo.getAttrCertValidityPeriod(); final ASN1Sequence attributes = acInfo.getAttributes(); for (int ii = 0; ii < attributes.size(); ii++) { final ASN1Encodable objectAt = attributes.getObjectAt(ii); final org.bouncycastle.asn1.x509.Attribute attribute = org.bouncycastle.asn1.x509.Attribute .getInstance(objectAt); final ASN1Set attrValues1 = attribute.getAttrValues(); DERSequence derSequence = (DERSequence) attrValues1.getObjectAt(0); RoleSyntax roleSyntax = RoleSyntax.getInstance(derSequence); CertifiedRole certifiedRole = new CertifiedRole(); certifiedRole.setRole(roleSyntax.getRoleNameAsString()); certifiedRole.setNotBefore(DSSASN1Utils.toDate(attrCertValidityPeriod.getNotBeforeTime())); certifiedRole.setNotAfter(DSSASN1Utils.toDate(attrCertValidityPeriod.getNotAfterTime())); roles.add(certifiedRole); } } } return roles; } catch (Exception e) { throw new DSSException( "Error when dealing with certified signer roles: [" + asn1EncodableAttrValue.toString() + "]", e); } }
From source file:org.glite.voms.ac.AttributeCertificate.java
License:eu-egee.org license
/** * Checks if the AC was valid at the provided timestamp. * @param date if <code>null</code>, current time is used * @return true if the AC was valid at the time in question. *///from w ww . j a v a2 s. c om public boolean validAt(Date date) { AttCertValidityPeriod validity = acInfo.getAttrCertValidityPeriod(); if (date == null) { date = new Date(); } try { Calendar notAfter = Calendar.getInstance(); Calendar notBefore = Calendar.getInstance(); notAfter.setTime(getDate(validity.getNotAfterTime())); notBefore.setTime(getDate(validity.getNotBeforeTime())); // 5 "academic" minutes tolerance notAfter.add(Calendar.MINUTE, 5); notBefore.add(Calendar.MINUTE, -5); return notAfter.getTime().after(date) && notBefore.getTime().before(date); } catch (ParseException e) { throw new IllegalArgumentException("Invalid validity encoding in Attribute Certificate"); } }