Search in sources :

Example 6 with BasicCertificate

use of org.demoiselle.signer.core.extension.BasicCertificate 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

BasicCertificate (org.demoiselle.signer.core.extension.BasicCertificate)6 IOException (java.io.IOException)4 X509Certificate (java.security.cert.X509Certificate)4 SignatureInformations (org.demoiselle.signer.policy.impl.cades.SignatureInformations)4 ArrayList (java.util.ArrayList)3 ICPBR_CRL (org.demoiselle.signer.core.extension.ICPBR_CRL)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 COSDictionary (org.apache.pdfbox.cos.COSDictionary)1 COSString (org.apache.pdfbox.cos.COSString)1 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)1 PDSignature (org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature)1