List of usage examples for com.itextpdf.text.pdf.security KeyStoreUtil loadCacertsKeyStore
public static KeyStore loadCacertsKeyStore()
From source file:controller.CCInstance.java
License:Open Source License
public final int getNumberOfSignatures(final String pdfPath) { final KeyStore keystore = KeyStoreUtil.loadCacertsKeyStore(); try {//from w ww . ja v a2 s . c o m keystore.load(null, null); final PdfReader reader = new PdfReader(pdfPath); final int numSigs = reader.getAcroFields().getSignatureNames().size(); reader.close(); return numSigs; } catch (IOException ex) { controller.Logger.getLogger().addEntry(ex); } catch (NoSuchAlgorithmException ex) { controller.Logger.getLogger().addEntry(ex); } catch (CertificateException ex) { controller.Logger.getLogger().addEntry(ex); } return -1; }
From source file:ec.rubrica.pdf.FirmaPDF.java
License:Open Source License
/** * TODO: Mas de dos firmas?/*from ww w.j a v a 2 s. c o m*/ * * @param pdf * @throws IOException * @throws SignatureException */ public static boolean verificar(byte[] pdf) throws IOException, SignatureException { PdfReader reader = new PdfReader(pdf); AcroFields af = reader.getAcroFields(); ArrayList<String> names = af.getSignatureNames(); for (int k = 0; k < names.size(); ++k) { String name = (String) names.get(k); System.out.println("Signature name: " + name); System.out.println("Signature covers whole document: " + af.signatureCoversWholeDocument(name)); System.out.println("Document revision: " + af.getRevision(name) + " of " + af.getTotalRevisions()); PdfPKCS7 pk = af.verifySignature(name); Calendar cal = pk.getSignDate(); Certificate[] pkc = pk.getCertificates(); TimeStampToken ts = pk.getTimeStampToken(); if (ts != null) { cal = pk.getTimeStampDate(); } if (!pk.isTsp() && ts != null) { boolean impr; try { impr = pk.verifyTimestampImprint(); System.out.println("Timestamp imprint verifies: " + impr); System.out.println("Timestamp date: " + cal); } catch (NoSuchAlgorithmException e) { throw new SignatureException(e); } } System.out.println("Subject: " + CertificateInfo.getSubjectFields(pk.getSigningCertificate())); System.out.println("Document modified: " + !pk.verify()); KeyStore kall = KeyStoreUtil.loadCacertsKeyStore(); Object fails[] = CertificateVerification.verifyCertificates(pkc, kall, null, cal); if (fails == null) { System.out.println("Certificates verified against the KeyStore"); } else { System.out.println("Certificate failed: " + fails[0]); return false; } BasicOCSPResp ocsp = pk.getOcsp(); if (ocsp != null) { try { X509Certificate cert = new SecurityDataSubCaCert(); boolean verifies = ocsp.isSignatureValid(new JcaContentVerifierProviderBuilder() .setProvider(BouncyCastleProvider.PROVIDER_NAME).build(cert.getPublicKey())); System.out.println("OCSP signature verifies: " + verifies); System.out.println("OCSP revocation refers to this certificate: " + pk.isRevocationValid()); return verifies; } catch (OperatorCreationException e) { throw new SignatureException(e); } catch (OCSPException e) { throw new SignatureException(e); } } else { return true; } } return false; }
From source file:ec.rubrica.pdf.VerificadorFirmaPdf.java
License:Open Source License
public VerificadorFirmaPdf(byte[] pdf) throws IOException { PdfReader pdfReader = new PdfReader(pdf); this.af = pdfReader.getAcroFields(); this.cacerts = KeyStoreUtil.loadCacertsKeyStore(); }