Search in sources :

Example 1 with GeneralizedTime

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);
    }
}
Also used : UTCTime(org.mozilla.jss.asn1.UTCTime) Calendar(java.util.Calendar) GeneralizedTime(org.mozilla.jss.asn1.GeneralizedTime)

Example 2 with GeneralizedTime

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();
}
Also used : GeneralizedTime(org.demoiselle.signer.policy.engine.asn1.GeneralizedTime)

Example 3 with GeneralizedTime

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);
    }
}
Also used : PolicyFactory(org.demoiselle.signer.policy.engine.factory.PolicyFactory) PolicyException(org.demoiselle.signer.policy.engine.exception.PolicyException) GregorianCalendar(java.util.GregorianCalendar) GeneralizedTime(org.demoiselle.signer.policy.engine.asn1.GeneralizedTime) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) PolicyException(org.demoiselle.signer.policy.engine.exception.PolicyException)

Example 4 with GeneralizedTime

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());
    }
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) GeneralizedTime(org.demoiselle.signer.policy.engine.asn1.GeneralizedTime)

Example 5 with GeneralizedTime

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());
    }
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) GeneralizedTime(org.demoiselle.signer.policy.engine.asn1.GeneralizedTime)

Aggregations

GeneralizedTime (org.demoiselle.signer.policy.engine.asn1.GeneralizedTime)6 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)4 Calendar (java.util.Calendar)2 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)2 GeneralizedTime (org.mozilla.jss.asn1.GeneralizedTime)2 UTCTime (org.mozilla.jss.asn1.UTCTime)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)1 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)1 DERIA5String (org.bouncycastle.asn1.DERIA5String)1 DEROctetString (org.bouncycastle.asn1.DEROctetString)1 DLSequence (org.bouncycastle.asn1.DLSequence)1 OtherHashAlgAndValue (org.bouncycastle.asn1.esf.OtherHashAlgAndValue)1 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)1 ObjectIdentifier (org.demoiselle.signer.policy.engine.asn1.etsi.ObjectIdentifier)1 SigningPeriod (org.demoiselle.signer.policy.engine.asn1.etsi.SigningPeriod)1 PolicyException (org.demoiselle.signer.policy.engine.exception.PolicyException)1 PolicyFactory (org.demoiselle.signer.policy.engine.factory.PolicyFactory)1