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());
}
}
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());
}
}
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);
}
}
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();
}
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());
}
Aggregations