Search in sources :

Example 1 with GeneralizedTime

use of org.demoiselle.signer.policy.engine.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)

Example 2 with GeneralizedTime

use of org.demoiselle.signer.policy.engine.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 3 with GeneralizedTime

use of org.demoiselle.signer.policy.engine.asn1.GeneralizedTime in project signer by demoiselle.

the class PolicyValidator method validate.

public boolean validate() {
    try {
        boolean valid = true;
        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)) {
            throw new PolicyException(policyMessagesBundle.getString("error.policy.valid.period", sdf.format(dateNotBefore), sdf.format(dateNotBefore)));
        }
        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.info(policyMessagesBundle.getString("info.lpa.load.local"));
                tempListOfPolicies = factory.loadLPACAdESLocal();
                if (tempListOfPolicies != null) {
                    nextUpdate = tempListOfPolicies.getNextUpdate().getDate();
                    if (actualDate.after(nextUpdate)) {
                        LOGGER.warn(policyMessagesBundle.getString("error.policy.local.not.updated", LPARepository.FULL_PATH_FOLDER_SIGNER.toString() + "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())) {
                    GeneralizedTime revocationDate = policyInfo.getRevocationDate();
                    if (revocationDate != null) {
                        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", LPARepository.FULL_PATH_FOLDER_SIGNER.toString() + "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())) {
                        GeneralizedTime revocationDate = policyInfo.getRevocationDate();
                        if (revocationDate != null) {
                            throw new PolicyException(policyMessagesBundle.getString("error.policy.revocated", sdf.format(revocationDate.getDate())));
                        }
                    }
                }
            } else {
                if (policyName.contains("XADES")) {
                    // TODO verificar como é procesado em XML
                    listOfPolicies = factory.loadLPAXAdES();
                } else {
                    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.demoiselle.signer.policy.engine.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 5 with GeneralizedTime

use of org.demoiselle.signer.policy.engine.asn1.GeneralizedTime in project signer by demoiselle.

the class LPA method parse.

public void parse(ASN1Primitive derObject) {
    ASN1Sequence sequence = ASN1Object.getDERSequence(derObject);
    ASN1Primitive firstObject = sequence.getObjectAt(0).toASN1Primitive();
    this.version = new Version();
    int indice = 0;
    if (firstObject instanceof ASN1Integer) {
        this.version.parse(firstObject);
        indice++;
    }
    ASN1Primitive policyInfos = sequence.getObjectAt(indice).toASN1Primitive();
    DLSequence policyInfosSequence = (DLSequence) policyInfos;
    if (policyInfosSequence != null && policyInfosSequence.size() > 0) {
        this.policyInfos = new ArrayList<>();
        for (int i = 0; i < policyInfosSequence.size(); i++) {
            PolicyInfo policyInfo = new PolicyInfo();
            policyInfo.parse(policyInfosSequence.getObjectAt(i).toASN1Primitive());
            this.policyInfos.add(policyInfo);
        }
    }
    this.nextUpdate = new GeneralizedTime();
    this.nextUpdate.parse(sequence.getObjectAt(indice + 1).toASN1Primitive());
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DLSequence(org.bouncycastle.asn1.DLSequence) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) GeneralizedTime(org.demoiselle.signer.policy.engine.asn1.GeneralizedTime) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive)

Aggregations

GeneralizedTime (org.demoiselle.signer.policy.engine.asn1.GeneralizedTime)6 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)4 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)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