Search in sources :

Example 6 with SignatureInformations

use of org.demoiselle.signer.policy.impl.cades.SignatureInformations in project signer by demoiselle.

the class CAdESCheckerTest method testVerifyAttachedSignature.

/**
 * Verifica assinatura com conteúdo anexado
 */
// @Test
public void testVerifyAttachedSignature() {
    String fileSignatureDirName = "local_e_nome_do_arquivo_da_assinatura_com_conteudo_anexado";
    byte[] signatureFile = readContent(fileSignatureDirName);
    CAdESChecker checker = new CAdESChecker();
    System.out.println("Efetuando a validacao da assinatura");
    List<SignatureInformations> signaturesInfo = checker.checkAttachedSignature(signatureFile);
    if (signaturesInfo != null) {
        System.out.println("A assinatura foi validada.");
        for (SignatureInformations si : signaturesInfo) {
            System.out.println(si.getSignDate());
            if (si.getTimeStampSigner() != null) {
                System.out.println("Serial" + si.getTimeStampSigner().toString());
            }
            for (X509Certificate cert : si.getChain()) {
                BasicCertificate certificate = new BasicCertificate(cert);
                if (!certificate.isCACertificate()) {
                    System.out.println(certificate.toString());
                }
            }
            for (String valErr : si.getValidatorErrors()) {
                System.out.println("++++++++++++++ ERROS ++++++++++++++++++");
                System.out.println(valErr);
            }
            System.out.println(si.getSignaturePolicy().toString());
        }
        assertTrue(true);
    } else {
        System.out.println("A assinatura foi invalidada!");
        assertTrue(false);
    }
}
Also used : BasicCertificate(org.demoiselle.signer.core.extension.BasicCertificate) SignatureInformations(org.demoiselle.signer.policy.impl.cades.SignatureInformations) X509Certificate(java.security.cert.X509Certificate)

Aggregations

X509Certificate (java.security.cert.X509Certificate)6 SignatureInformations (org.demoiselle.signer.policy.impl.cades.SignatureInformations)6 IOException (java.io.IOException)4 BasicCertificate (org.demoiselle.signer.core.extension.BasicCertificate)4 ParseException (java.text.ParseException)2 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)2 ASN1UTCTime (org.bouncycastle.asn1.ASN1UTCTime)2 Attribute (org.bouncycastle.asn1.cms.Attribute)2 AttributeTable (org.bouncycastle.asn1.cms.AttributeTable)2 X509CertificateHolder (org.bouncycastle.cert.X509CertificateHolder)2 JcaX509CertificateConverter (org.bouncycastle.cert.jcajce.JcaX509CertificateConverter)2 CMSException (org.bouncycastle.cms.CMSException)2 CMSProcessableByteArray (org.bouncycastle.cms.CMSProcessableByteArray)2 CMSSignedData (org.bouncycastle.cms.CMSSignedData)2 CMSSignerDigestMismatchException (org.bouncycastle.cms.CMSSignerDigestMismatchException)2 SignerInformation (org.bouncycastle.cms.SignerInformation)2 SignerInformationStore (org.bouncycastle.cms.SignerInformationStore)2 JcaSimpleSignerInfoVerifierBuilder (org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoVerifierBuilder)2