Class AddValidationInformation
java.lang.Object
org.apache.pdfbox.examples.signature.validation.AddValidationInformation
An example for adding Validation Information to a signed PDF, inspired by ETSI TS 102 778-4
V1.1.2 (2009-12), Part 4: PAdES Long Term - PAdES-LTV Profile. This procedure appends the
Validation Information of the last signature (more precise its signer(s)) to a copy of the
document. The signature and the signed data will not be touched and stay valid.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CertInformationCollectorprivate final Map<X509Certificate, COSStream> private COSArrayprivate COSArrayprivate COSArrayprivate COSArrayprivate PDDocumentprivate final Set<X509Certificate> private static final org.apache.commons.logging.Logprivate final Set<X509Certificate> private COSArrayprivate Calendarprivate COSDictionary -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidAdds all certs to the certs-array.private voidFetches and adds CRL data to storage for the given Certificate.private voidaddExtensions(PDDocumentCatalog catalog) Adds Extensions to the document catalog.private voidFetches and adds OCSP data to storage for the given Certificate.private voidFetches and adds revocation information based on the certInfo to the DSS.private voidTries to get Revocation Data (first OCSP, else CRL) from the given Certificate Chain.private voiddoValidation(String filename, OutputStream output) Fetches certificate information from the last signature of the document and appends a DSS with the validation information to the document.private voidTries to fetch and add CRL Data to its containers.private booleanTries to fetch and add OCSP Data to its containers.private static <T extends COSBase & COSUpdateInfo>
TgetOrCreateDictionaryEntry(Class<T> clazz, COSDictionary parent, String name) Gets or creates a dictionary entry.static voidprivate voidprivate static voidusage()voidvalidateSignature(File inFile, File outFile) Signs the given PDF file.private COSStreamwriteDataToStream(byte[] data) Creates a Flate encodedCOSStreamobject with the given data.
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG -
certInformationHelper
-
correspondingOCSPs
-
correspondingCRLs
-
vriBase
-
ocsps
-
crls
-
certs
-
certMap
-
document
-
foundRevocationInformation
-
signDate
-
ocspChecked
-
-
Constructor Details
-
AddValidationInformation
public AddValidationInformation()
-
-
Method Details
-
validateSignature
Signs the given PDF file.- Parameters:
inFile- input PDF fileoutFile- output PDF file- Throws:
IOException- if the input file could not be read
-
doValidation
Fetches certificate information from the last signature of the document and appends a DSS with the validation information to the document.- Parameters:
filename- in file to extract signatureoutput- where to write the changed document- Throws:
IOException
-
getOrCreateDictionaryEntry
private static <T extends COSBase & COSUpdateInfo> T getOrCreateDictionaryEntry(Class<T> clazz, COSDictionary parent, String name) throws IOException Gets or creates a dictionary entry. If existing checks for the type and sets need to be updated.- Parameters:
clazz- the class of the dictionary entry, must implement COSUpdateInfoparent- where to find the elementname- of the element- Returns:
- a Element of given class, new or existing
- Throws:
IOException- when the type of the element is wrong
-
addRevocationData
private void addRevocationData(CertInformationCollector.CertSignatureInformation certInfo) throws IOException Fetches and adds revocation information based on the certInfo to the DSS.- Parameters:
certInfo- Certificate information from CertInformationHelper containing certificate chains.- Throws:
IOException
-
addRevocationDataRecursive
private void addRevocationDataRecursive(CertInformationCollector.CertSignatureInformation certInfo) throws IOException Tries to get Revocation Data (first OCSP, else CRL) from the given Certificate Chain.- Parameters:
certInfo- from which to fetch revocation data. Will work recursively through its chains.- Throws:
IOException- when failed to fetch an revocation data.
-
fetchOcspData
private boolean fetchOcspData(CertInformationCollector.CertSignatureInformation certInfo) throws IOException Tries to fetch and add OCSP Data to its containers.- Parameters:
certInfo- the certificate info, for it to check OCSP data.- Returns:
- true when the OCSP data has successfully been fetched and added
- Throws:
IOException- when Certificate is revoked.
-
fetchCrlData
private void fetchCrlData(CertInformationCollector.CertSignatureInformation certInfo) throws IOException Tries to fetch and add CRL Data to its containers.- Parameters:
certInfo- the certificate info, for it to check CRL data.- Throws:
IOException- when failed to fetch, because no validation data could be fetched for data.
-
addOcspData
private void addOcspData(CertInformationCollector.CertSignatureInformation certInfo) throws IOException, org.bouncycastle.cert.ocsp.OCSPException, CertificateProccessingException, RevokedCertificateException, URISyntaxException Fetches and adds OCSP data to storage for the given Certificate.- Parameters:
certInfo- the certificate info, for it to check OCSP data.- Throws:
IOExceptionorg.bouncycastle.cert.ocsp.OCSPExceptionCertificateProccessingExceptionRevokedCertificateExceptionURISyntaxException
-
addCrlRevocationInfo
private void addCrlRevocationInfo(CertInformationCollector.CertSignatureInformation certInfo) throws IOException, RevokedCertificateException, GeneralSecurityException, CertificateVerificationException, URISyntaxException Fetches and adds CRL data to storage for the given Certificate.- Parameters:
certInfo- the certificate info, for it to check CRL data.- Throws:
IOExceptionURISyntaxExceptionRevokedCertificateExceptionGeneralSecurityExceptionCertificateVerificationException
-
updateVRI
private void updateVRI(CertInformationCollector.CertSignatureInformation certInfo, COSDictionary vri) throws IOException - Throws:
IOException
-
addAllCertsToCertArray
Adds all certs to the certs-array. Make sure that all certificates are inside the certificateStore of certInformationHelper. This should be the only call to fill certs.- Throws:
IOException
-
writeDataToStream
Creates a Flate encodedCOSStreamobject with the given data.- Parameters:
data- to write into the COSStream- Returns:
- COSStream a COSStream object that can be added to the document
- Throws:
IOException
-
addExtensions
Adds Extensions to the document catalog. So that the use of DSS is identified. Described in PAdES Part 4, Chapter 4.4.- Parameters:
catalog- to add Extensions into
-
main
- Throws:
IOException
-
usage
private static void usage()
-