List of usage examples for org.apache.pdfbox.pdmodel.interactive.digitalsignature PDSignature getName
public String getName()
From source file:eu.europa.esig.dss.pades.signature.PAdESLevelBWithContentTimestampTest.java
License:Open Source License
@Override protected void onDocumentSigned(byte[] byteArray) { super.onDocumentSigned(byteArray); try (PDDocument doc = PDDocument.load(byteArray)) { List<PDSignature> signatureDictionaries = doc.getSignatureDictionaries(); assertEquals(1, signatureDictionaries.size()); PDSignature pdSignature = signatureDictionaries.get(0); assertNotNull(pdSignature.getName()); assertNotNull(pdSignature.getReason()); assertNotNull(pdSignature.getLocation()); assertNotNull(pdSignature.getContactInfo()); assertNotNull(pdSignature.getSignDate()); // M assertEquals("Adobe.PPKLite", pdSignature.getFilter()); assertEquals("ETSI.CAdES.detached", pdSignature.getSubFilter()); } catch (IOException e) { throw new DSSException(e); }/* ww w .j a v a 2 s. co m*/ }
From source file:mj.ocraptor.extraction.tika.parser.pdf.PDF2XHTML.java
License:Apache License
private void handleSignature(AttributesImpl parentAttributes, PDSignatureField sigField, XHTMLContentHandler handler) throws SAXException { PDSignature sig = sigField.getSignature(); if (sig == null) { return;//from w w w .j a v a2 s .c o m } Map<String, String> vals = new TreeMap<String, String>(); vals.put("name", sig.getName()); vals.put("contactInfo", sig.getContactInfo()); vals.put("location", sig.getLocation()); vals.put("reason", sig.getReason()); Calendar cal = sig.getSignDate(); if (cal != null) { dateFormat.setTimeZone(cal.getTimeZone()); vals.put("date", dateFormat.format(cal.getTime())); } // see if there is any data int nonNull = 0; for (String val : vals.keySet()) { if (val != null && !val.equals("")) { nonNull++; } } // if there is, process it if (nonNull > 0) { handler.startElement("li", parentAttributes); AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "type", "type", "CDATA", "signaturedata"); handler.startElement("ol", attrs); for (Map.Entry<String, String> e : vals.entrySet()) { if (e.getValue() == null || e.getValue().equals("")) { continue; } attrs = new AttributesImpl(); attrs.addAttribute("", "signdata", "signdata", "CDATA", e.getKey()); handler.startElement("li", attrs); handler.characters(e.getValue()); handler.endElement("li"); } handler.endElement("ol"); handler.endElement("li"); } }
From source file:org.apache.tika.parser.pdf.AbstractPDF2XHTML.java
License:Apache License
private void handleSignature(AttributesImpl parentAttributes, PDSignatureField sigField) throws SAXException { PDSignature sig = sigField.getSignature(); if (sig == null) { return;/* www.j a v a2 s. c om*/ } Map<String, String> vals = new TreeMap<>(); vals.put("name", sig.getName()); vals.put("contactInfo", sig.getContactInfo()); vals.put("location", sig.getLocation()); vals.put("reason", sig.getReason()); Calendar cal = sig.getSignDate(); if (cal != null) { dateFormat.setTimeZone(cal.getTimeZone()); vals.put("date", dateFormat.format(cal.getTime())); } //see if there is any data int nonNull = 0; for (String val : vals.keySet()) { if (val != null && !val.equals("")) { nonNull++; } } //if there is, process it if (nonNull > 0) { xhtml.startElement("li", parentAttributes); AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "type", "type", "CDATA", "signaturedata"); xhtml.startElement("ol", attrs); for (Map.Entry<String, String> e : vals.entrySet()) { if (e.getValue() == null || e.getValue().equals("")) { continue; } attrs = new AttributesImpl(); attrs.addAttribute("", "signdata", "signdata", "CDATA", e.getKey()); xhtml.startElement("li", attrs); xhtml.characters(e.getValue()); xhtml.endElement("li"); } xhtml.endElement("ol"); xhtml.endElement("li"); } }
From source file:org.apache.tika.parser.pdf.EnhancedPDF2XHTML.java
License:Apache License
private void handleSignature(AttributesImpl parentAttributes, PDSignatureField sigField, XHTMLContentHandler handler) throws SAXException { PDSignature sig = sigField.getSignature(); if (sig == null) { return;/*from w w w. j a v a2 s . co m*/ } Map<String, String> vals = new TreeMap<String, String>(); vals.put("name", sig.getName()); vals.put("contactInfo", sig.getContactInfo()); vals.put("location", sig.getLocation()); vals.put("reason", sig.getReason()); Calendar cal = sig.getSignDate(); if (cal != null) { dateFormat.setTimeZone(cal.getTimeZone()); vals.put("date", dateFormat.format(cal.getTime())); } //see if there is any data int nonNull = 0; for (String val : vals.keySet()) { if (val != null && !val.equals("")) { nonNull++; } } //if there is, process it if (nonNull > 0) { handler.startElement("li", parentAttributes); AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "type", "type", "CDATA", "signaturedata"); handler.startElement("ol", attrs); for (Map.Entry<String, String> e : vals.entrySet()) { if (e.getValue() == null || e.getValue().equals("")) { continue; } attrs = new AttributesImpl(); attrs.addAttribute("", "signdata", "signdata", "CDATA", e.getKey()); handler.startElement("li", attrs); handler.characters(e.getValue()); handler.endElement("li"); } handler.endElement("ol"); handler.endElement("li"); } }
From source file:pdfbox.SignatureVerifier.java
License:Apache License
public Map<String, SignatureResult> extractSignatures(File infile) throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException { Map<String, SignatureResult> result = new HashMap<>(); try (PDDocument document = PDDocument.load(infile)) { for (PDSignature sig : document.getSignatureDictionaries()) { COSDictionary sigDict = sig.getCOSObject(); COSString contents = (COSString) sigDict.getDictionaryObject(COSName.CONTENTS); // download the signed content byte[] buf; try (FileInputStream fis = new FileInputStream(infile)) { buf = sig.getSignedContent(fis); }/* w ww .j av a 2 s.c o m*/ System.out.println("Signature found"); System.out.println("Name: " + sig.getName()); System.out.println("Modified: " + sdf.format(sig.getSignDate().getTime())); String subFilter = sig.getSubFilter(); if (subFilter != null) { switch (subFilter) { case "adbe.pkcs7.detached": // COSName.ADBE_PKCS7_DETACHED result.put(sig.getName(), verifyPKCS7(buf, contents, sig)); //TODO check certificate chain, revocation lists, timestamp... break; case "adbe.pkcs7.sha1": // COSName.ADBE_PKCS7_SHA1 { // example: PDFBOX-1452.pdf //COSString certString = (COSString) sigDict.getDictionaryObject( // COSName.CONTENTS); byte[] certData = contents.getBytes(); Collection<? extends Certificate> certs = getCertificates(certData); System.out.println("certs=" + certs); byte[] hash = MessageDigest.getInstance("SHA1").digest(buf); result.put(sig.getName(), verifyPKCS7(hash, contents, sig)); //TODO check certificate chain, revocation lists, timestamp... break; } case "adbe.x509.rsa_sha1": // COSName.ADBE_PKCS7_SHA1 { // example: PDFBOX-2693.pdf COSString certString = (COSString) sigDict.getDictionaryObject(COSName.getPDFName("Cert")); byte[] certData = certString.getBytes(); Collection<? extends Certificate> certs = getCertificates(certData); System.out.println("certs=" + certs); //TODO verify signature throw new IOException(subFilter + " verification not supported"); //break; } default: throw new IOException("Unknown certificate type: " + subFilter); //break; } } else { throw new IOException("Missing subfilter for cert dictionary"); } } } catch (CMSException | OperatorCreationException ex) { throw new IOException(ex); } return result; }