use of org.mozilla.jss.asn1.GeneralizedTime in project jss by dogtagpki.
the class CertificateInfo method encodeValidityDate.
/**
* Returns the correct ASN1Value (UTCTime or GeneralizedTime) to represent
* the given certificate validity date.
*/
private static ASN1Value encodeValidityDate(Date d) {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.setTime(d);
if (cal.get(Calendar.YEAR) <= UTCTIME_CUTOFF_YEAR) {
return new UTCTime(d);
} else {
return new GeneralizedTime(d);
}
}
use of org.mozilla.jss.asn1.GeneralizedTime in project signer by demoiselle.
the class LPA method toString.
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("===================================================").append("\n");
builder.append(policyMessagesBundle.getString("text.next.update")).append(this.getNextUpdate().getDate()).append("\n");
builder.append(policyMessagesBundle.getString("text.quantity")).append(this.getPolicyInfos().size()).append("\n");
builder.append("===================================================");
for (PolicyInfo policyInfo : this.getPolicyInfos()) {
builder.append(policyMessagesBundle.getString("text.valid")).append(policyInfo.getSigningPeriod()).append("\n");
builder.append(policyMessagesBundle.getString("text.oid")).append(policyInfo.getPolicyOID().getValue()).append("\n");
builder.append(policyMessagesBundle.getString("text.uri")).append(policyInfo.getPolicyURI()).append("\n");
builder.append(policyMessagesBundle.getString("text.algo.hash")).append(policyInfo.getPolicyDigest().getHashAlgorithm().getAlgorithm().getId()).append("\n");
builder.append(policyMessagesBundle.getString("text.hash")).append(policyInfo.getPolicyDigest().getHashValue().toString()).append("\n");
builder.append(policyMessagesBundle.getString("text.status"));
GeneralizedTime revocationDate = policyInfo.getRevocationDate();
if (revocationDate != null) {
builder.append(policyMessagesBundle.getString("text.repealed")).append("\n");
builder.append(policyMessagesBundle.getString("text.revocation.date")).append(revocationDate != null ? revocationDate.getDate() : policyMessagesBundle.getString("text.revocation.no.date")).append("\n");
} else {
builder.append(policyMessagesBundle.getString("text.still.valid")).append("\n");
}
builder.append("\t===================================================").append("\n");
}
return builder.toString();
}
use of org.mozilla.jss.asn1.GeneralizedTime in project signer by demoiselle.
the class PolicyValidator method validate.
public boolean validate() {
try {
boolean valid = false;
Date dateNotBefore = this.sp.getSignPolicyInfo().getSignatureValidationPolicy().getSigningPeriod().getNotBefore().getDate();
Date dateNotAfter = this.sp.getSignPolicyInfo().getSignatureValidationPolicy().getSigningPeriod().getNotAfter().getDate();
Date actualDate = new GregorianCalendar().getTime();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy - hh:mm:ss");
if (actualDate.before(dateNotBefore) || actualDate.after(dateNotAfter)) {
LOGGER.error(policyMessagesBundle.getString("error.policy.valid.period", sdf.format(dateNotBefore), sdf.format(dateNotAfter)));
throw new PolicyException(policyMessagesBundle.getString("error.policy.valid.period", sdf.format(dateNotBefore), sdf.format(dateNotAfter)));
}
PolicyFactory factory = PolicyFactory.getInstance();
LPA tempListOfPolicies = null;
if (policyName.contains("CADES")) {
tempListOfPolicies = factory.loadLPACAdES();
listOfPolicies = tempListOfPolicies;
Date nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.not.updated", sdf.format(nextUpdate)));
LOGGER.debug(policyMessagesBundle.getString("info.lpa.load.local", config.getLpaPath()));
tempListOfPolicies = factory.loadLPACAdESLocal();
if (tempListOfPolicies != null) {
nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.local.not.updated", config.getLpaPath() + "LPA_CAdES.der", sdf.format(nextUpdate)));
tempListOfPolicies = factory.loadLPACAdESUrl();
if (tempListOfPolicies != null) {
nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.not.updated", sdf.format(nextUpdate)));
} else {
listOfPolicies = tempListOfPolicies;
}
}
} else {
listOfPolicies = tempListOfPolicies;
}
} else {
tempListOfPolicies = factory.loadLPACAdESUrl();
if (tempListOfPolicies != null) {
nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.not.updated", sdf.format(nextUpdate)));
} else {
listOfPolicies = tempListOfPolicies;
}
} else {
LOGGER.warn(policyMessagesBundle.getString("error.lpa.not.found"));
}
}
}
for (PolicyInfo policyInfo : listOfPolicies.getPolicyInfos()) {
if (policyInfo.getPolicyOID().getValue().contentEquals(sp.getSignPolicyInfo().getSignPolicyIdentifier().getValue())) {
valid = true;
GeneralizedTime revocationDate = policyInfo.getRevocationDate();
if (revocationDate != null) {
LOGGER.error(policyMessagesBundle.getString("error.policy.revocated", sdf.format(revocationDate.getDate())));
throw new PolicyException(policyMessagesBundle.getString("error.policy.revocated", sdf.format(revocationDate.getDate())));
}
}
}
} else {
if (policyName.contains("PADES")) {
tempListOfPolicies = factory.loadLPAPAdES();
listOfPolicies = tempListOfPolicies;
Date nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.not.updated", sdf.format(nextUpdate)));
LOGGER.info(policyMessagesBundle.getString("info.lpa.load.local"));
tempListOfPolicies = factory.loadLPAPAdESLocal();
if (tempListOfPolicies != null) {
nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.local.not.updated", config.getLpaPath() + "LPA_PAdES.der", sdf.format(nextUpdate)));
tempListOfPolicies = factory.loadLPAPAdESUrl();
if (tempListOfPolicies != null) {
nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.not.updated", sdf.format(nextUpdate)));
} else {
listOfPolicies = tempListOfPolicies;
}
}
} else {
listOfPolicies = tempListOfPolicies;
}
} else {
tempListOfPolicies = factory.loadLPAPAdESUrl();
if (tempListOfPolicies != null) {
nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
if (actualDate.after(nextUpdate)) {
LOGGER.warn(policyMessagesBundle.getString("error.policy.not.updated", sdf.format(nextUpdate)));
} else {
listOfPolicies = tempListOfPolicies;
}
} else {
LOGGER.warn(policyMessagesBundle.getString("error.lpa.not.found"));
}
}
}
for (PolicyInfo policyInfo : listOfPolicies.getPolicyInfos()) {
if (policyInfo.getPolicyOID().getValue().contentEquals(sp.getSignPolicyInfo().getSignPolicyIdentifier().getValue())) {
valid = true;
GeneralizedTime revocationDate = policyInfo.getRevocationDate();
if (revocationDate != null) {
LOGGER.error(policyMessagesBundle.getString("error.policy.revocated", sdf.format(revocationDate.getDate())));
throw new PolicyException(policyMessagesBundle.getString("error.policy.revocated", sdf.format(revocationDate.getDate())));
}
}
}
} else {
if (policyName.contains("XADES")) {
LOGGER.error(policyMessagesBundle.getString("error.policy.not.recognized", policyName));
throw new PolicyException(policyMessagesBundle.getString("error.policy.not.recognized", policyName));
} else {
LOGGER.error(policyMessagesBundle.getString("error.policy.not.recognized", policyName));
throw new PolicyException(policyMessagesBundle.getString("error.policy.not.recognized", policyName));
}
}
}
return valid;
} catch (Exception ex) {
throw new PolicyException(ex.getMessage(), ex);
}
}
use of org.mozilla.jss.asn1.GeneralizedTime in project signer by demoiselle.
the class SigningPeriod method parse.
@Override
public void parse(ASN1Primitive derObject) {
ASN1Sequence derSequence = ASN1Object.getDERSequence(derObject);
this.notBefore = new GeneralizedTime();
this.notBefore.parse(derSequence.getObjectAt(0).toASN1Primitive());
if (derSequence.size() == 2) {
this.notAfter = new GeneralizedTime();
this.notAfter.parse(derSequence.getObjectAt(1).toASN1Primitive());
}
}
use of org.mozilla.jss.asn1.GeneralizedTime in project signer by demoiselle.
the class SignPolicyInfo method parse.
@Override
public void parse(ASN1Primitive derObject) {
ASN1Sequence derSequence = ASN1Object.getDERSequence(derObject);
this.signPolicyIdentifier = new SignPolicyId();
this.signPolicyIdentifier.parse(derSequence.getObjectAt(0).toASN1Primitive());
this.dateOfIssue = new GeneralizedTime();
this.dateOfIssue.parse(derSequence.getObjectAt(1).toASN1Primitive());
this.policyIssuerName = new PolicyIssuerName();
this.policyIssuerName.parse(derSequence.getObjectAt(2).toASN1Primitive());
this.fieldOfApplication = new FieldOfApplication();
this.fieldOfApplication.parse(derSequence.getObjectAt(3).toASN1Primitive());
this.signatureValidationPolicy = new SignatureValidationPolicy();
this.signatureValidationPolicy.parse(derSequence.getObjectAt(4).toASN1Primitive());
if (derSequence.size() == 6) {
this.signPolExtensions = new SignPolExtensions();
this.signPolExtensions.parse(derSequence.getObjectAt(5).toASN1Primitive());
}
}
Aggregations