Search in sources :

Example 1 with PolicyFactory

use of org.demoiselle.signer.policy.engine.factory.PolicyFactory in project signer by demoiselle.

the class CAdESChecker method setSignaturePolicy.

private void setSignaturePolicy(PolicyFactory.Policies signaturePolicy) {
    this.setPolicyName(signaturePolicy.name());
    PolicyFactory policyFactory = PolicyFactory.getInstance();
    org.demoiselle.signer.policy.engine.asn1.etsi.SignaturePolicy sp = policyFactory.loadPolicy(signaturePolicy);
    this.signaturePolicy = sp;
}
Also used : PolicyFactory(org.demoiselle.signer.policy.engine.factory.PolicyFactory) SignaturePolicy(org.demoiselle.signer.policy.engine.asn1.etsi.SignaturePolicy)

Example 2 with PolicyFactory

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

use of org.demoiselle.signer.policy.engine.factory.PolicyFactory in project signer by demoiselle.

the class PolicyFactoryTest method testLoadPolicy.

// @Test
public void testLoadPolicy() {
    PolicyFactory factory = PolicyFactory.getInstance();
    Policies[] policies = PolicyFactory.Policies.values();
    for (Policies policy : policies) {
        // TODO - falta implentar policy para XADES
        if (policy.toString().contains("CADES") || policy.toString().contains("PADES")) {
            logger.info(factory.loadPolicy(policy).toString());
        }
    }
}
Also used : Policies(org.demoiselle.signer.policy.engine.factory.PolicyFactory.Policies) PolicyFactory(org.demoiselle.signer.policy.engine.factory.PolicyFactory)

Example 4 with PolicyFactory

use of org.demoiselle.signer.policy.engine.factory.PolicyFactory in project signer by demoiselle.

the class CAdESSigner method setSignaturePolicy.

@Override
public void setSignaturePolicy(PolicyFactory.Policies signaturePolicy) {
    this.setPolicyName(signaturePolicy.name());
    PolicyFactory policyFactory = PolicyFactory.getInstance();
    org.demoiselle.signer.policy.engine.asn1.etsi.SignaturePolicy sp = policyFactory.loadPolicy(signaturePolicy);
    this.signaturePolicy = sp;
}
Also used : PolicyFactory(org.demoiselle.signer.policy.engine.factory.PolicyFactory) SignaturePolicy(org.demoiselle.signer.policy.engine.asn1.etsi.SignaturePolicy)

Example 5 with PolicyFactory

use of org.demoiselle.signer.policy.engine.factory.PolicyFactory in project signer by demoiselle.

the class CAdESTimeStampSigner method setSignaturePolicy.

@Override
public void setSignaturePolicy(PolicyFactory.Policies signaturePolicy) {
    PolicyFactory policyFactory = PolicyFactory.getInstance();
    org.demoiselle.signer.policy.engine.asn1.etsi.SignaturePolicy sp = policyFactory.loadPolicy(signaturePolicy);
    this.signaturePolicy = sp;
}
Also used : PolicyFactory(org.demoiselle.signer.policy.engine.factory.PolicyFactory) SignaturePolicy(org.demoiselle.signer.policy.engine.asn1.etsi.SignaturePolicy)

Aggregations

PolicyFactory (org.demoiselle.signer.policy.engine.factory.PolicyFactory)8 SignaturePolicy (org.demoiselle.signer.policy.engine.asn1.etsi.SignaturePolicy)3 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 GeneralizedTime (org.demoiselle.signer.policy.engine.asn1.GeneralizedTime)1 PolicyException (org.demoiselle.signer.policy.engine.exception.PolicyException)1 Policies (org.demoiselle.signer.policy.engine.factory.PolicyFactory.Policies)1 Test (org.junit.Test)1