List of usage examples for com.lowagie.text.pdf PdfArray getAsStream
public PdfStream getAsStream(int idx)
PdfObject
as a PdfStream
, resolving indirect references. From source file:eu.europa.ec.markt.dss.validation.pades.PAdESCertificateSource.java
License:Open Source License
@Override public List<X509Certificate> getCertificates() { try {/*from w w w. j a v a 2s . c om*/ List<X509Certificate> certs = new ArrayList<X509Certificate>(); PdfDictionary dss = catalog.getAsDict(new PdfName("DSS")); if (dss != null) { PdfArray certsArray = dss.getAsArray(new PdfName("Certs")); if (certsArray != null) { CertificateFactory factory = CertificateFactory.getInstance("X509"); for (int i = 0; i < certsArray.size(); i++) { PdfStream stream = certsArray.getAsStream(i); X509Certificate cert = (X509Certificate) factory.generateCertificate( new ByteArrayInputStream(PdfReader.getStreamBytes((PRStream) stream))); if (!certs.contains(cert)) { certs.add(cert); } } } } return certs; } catch (IOException ex) { throw new RuntimeException(ex); } catch (CertificateException e) { throw new RuntimeException(e); } }
From source file:eu.europa.ec.markt.dss.validation.pades.PAdESCRLSource.java
License:Open Source License
@Override public List<X509CRL> getCRLsFromSignature() { try {//www. j av a 2s. co m List<X509CRL> crls = new ArrayList<X509CRL>(); PdfDictionary dss = catalog.getAsDict(new PdfName("DSS")); if (dss != null) { PdfArray crlArray = dss.getAsArray(new PdfName("CRLs")); if (crlArray != null) { CertificateFactory factory = CertificateFactory.getInstance("X509"); for (int i = 0; i < crlArray.size(); i++) { PdfStream stream = crlArray.getAsStream(i); X509CRL cert = (X509CRL) factory .generateCRL(new ByteArrayInputStream(PdfReader.getStreamBytes((PRStream) stream))); if (!crls.contains(cert)) { crls.add(cert); } } } } return crls; } catch (IOException ex) { throw new RuntimeException(ex); } catch (CertificateException e) { throw new RuntimeException(e); } catch (CRLException e) { throw new RuntimeException(e); } }
From source file:eu.europa.ec.markt.dss.validation.pades.PAdESOCSPSource.java
License:Open Source License
@Override public List<BasicOCSPResp> getOCSPResponsesFromSignature() { try {/* w w w . j a v a2 s.c o m*/ List<BasicOCSPResp> ocsps = new ArrayList<BasicOCSPResp>(); PdfDictionary dss = catalog.getAsDict(new PdfName("DSS")); if (dss != null) { PdfArray ocspArray = dss.getAsArray(new PdfName("OCSPs")); if (ocspArray != null) { for (int i = 0; i < ocspArray.size(); i++) { PdfStream stream = ocspArray.getAsStream(i); ocsps.add((BasicOCSPResp) new OCSPResp(PdfReader.getStreamBytes((PRStream) stream)) .getResponseObject()); } } } return ocsps; } catch (OCSPException ex) { throw new RuntimeException(ex); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:eu.europa.ec.markt.dss.validation.pades.PDFDocumentValidator.java
License:Open Source License
private boolean checkVriDict(PdfDictionary vriSigDictionary, boolean _vriVerificationresult, PAdESSignature pades, ValidationContext ctx, String hexHash) throws CertificateException, IOException, CRLException, OCSPException { boolean vriVerificationresult = _vriVerificationresult; if (vriSigDictionary == null) { LOG.info("Couldn't find the signature VRI identified by " + hexHash + " in the DSS"); vriVerificationresult = false;//from w w w . ja v a 2 s . c o m } else { LOG.info("Found the signature VRI identified by " + hexHash + " in the DSS"); // Verify the certs in the VRI PdfArray vricert = vriSigDictionary.getAsArray(new PdfName("Cert")); if (vricert != null) { CertificateFactory factory = CertificateFactory.getInstance("X509"); List<X509Certificate> certs = new ArrayList<X509Certificate>(); for (int i = 0; i < vricert.size(); i++) { PdfStream stream = vricert.getAsStream(i); certs.add((X509Certificate) factory.generateCertificate( new ByteArrayInputStream(PdfReader.getStreamBytes((PRStream) stream)))); } vriVerificationresult &= everyCertificateValueAreThere(ctx, certs, pades.getSigningCertificate()); } // Verify the CRLs in the VRI PdfArray vricrl = vriSigDictionary.getAsArray(new PdfName("CRL")); if (vricrl != null) { CertificateFactory factory = CertificateFactory.getInstance("X509"); List<X509CRL> crls = new ArrayList<X509CRL>(); for (int i = 0; i < vricrl.size(); i++) { PdfStream stream = vricrl.getAsStream(i); crls.add((X509CRL) factory .generateCRL(new ByteArrayInputStream(PdfReader.getStreamBytes((PRStream) stream)))); } vriVerificationresult &= everyCRLValueOrRefAreThere(ctx, crls); } // Verify the OCSPs in the VRI PdfArray vriocsp = vriSigDictionary.getAsArray(new PdfName("OCSP")); if (vriocsp != null) { List<BasicOCSPResp> ocsps = new ArrayList<BasicOCSPResp>(); for (int i = 0; i < vriocsp.size(); i++) { PdfStream stream = vriocsp.getAsStream(i); ocsps.add((BasicOCSPResp) new OCSPResp(PdfReader.getStreamBytes((PRStream) stream)) .getResponseObject()); } vriVerificationresult &= everyOCSPValueOrRefAreThere(ctx, ocsps); } } return vriVerificationresult; }
From source file:questions.forms.FillDynamicXfa.java
public static void main(String[] args) { try {/*from w w w .ja v a 2s . com*/ PdfReader reader = new PdfReader(RESOURCE_PDF); File file = new File(RESOURCE_DATA); byte[] data = new byte[(int) file.length()]; FileInputStream is = new FileInputStream(file); int offset = 0; int numRead = 0; int datalength = data.length; while (offset < datalength && (numRead = is.read(data, offset, datalength - offset)) >= 0) { offset += numRead; } PdfDictionary root = reader.getCatalog(); PdfDictionary acroform = root.getAsDict(PdfName.ACROFORM); PdfArray xfa = acroform.getAsArray(PdfName.XFA); for (int i = 0; i < xfa.size(); i += 2) { if ("datasets".equals(xfa.getAsString(i).toString())) { PRStream s = (PRStream) xfa.getAsStream(i + 1); s.setData(data); } } PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.forms.ReadXfa.java
public static void main(String[] args) { try {//from www. j a v a2s . c o m PdfReader reader = new PdfReader(RESOURCE); FileOutputStream os = new FileOutputStream(RESULT); PdfDictionary root = reader.getCatalog(); PdfDictionary acroform = root.getAsDict(PdfName.ACROFORM); PdfArray xfa = acroform.getAsArray(PdfName.XFA); for (int i = 0; i < xfa.size(); i += 2) { System.out.println("Reading: " + xfa.getAsString(i)); PRStream s = (PRStream) xfa.getAsStream(i + 1); os.write(PdfReader.getStreamBytes(s)); } os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); } }