use of org.apache.pdfbox.examples.signature.validation.CertInformationCollector.CertSignatureInformation in project pdfbox by apache.
the class AddValidationInformation method doValidation.
/**
* Fetches certificate information from the last signature of the document and appends a DSS with the validation
* information to the document.
*
* @param document containing the Signature
* @param filename in file to extract signature
* @param output where to write the changed document
* @throws IOException
*/
private void doValidation(String filename, OutputStream output) throws IOException {
certInformationHelper = new CertInformationCollector();
CertSignatureInformation certInfo;
try {
certInfo = certInformationHelper.getLastCertInfo(document, filename);
} catch (CertificateProccessingException e) {
throw new IOException("An Error occurred processing the Signature", e);
}
if (certInfo == null) {
throw new IOException("No Certificate information or signature found in the given document");
}
PDDocumentCatalog docCatalog = document.getDocumentCatalog();
COSDictionary catalog = docCatalog.getCOSObject();
catalog.setNeedToBeUpdated(true);
COSDictionary dss = getOrCreateDictionaryEntry(COSDictionary.class, catalog, "DSS");
addExtensions(docCatalog);
vriBase = getOrCreateDictionaryEntry(COSDictionary.class, dss, "VRI");
ocsps = getOrCreateDictionaryEntry(COSArray.class, dss, "OCSPs");
crls = getOrCreateDictionaryEntry(COSArray.class, dss, "CRLs");
certs = getOrCreateDictionaryEntry(COSArray.class, dss, "Certs");
addRevocationData(certInfo);
addAllCertsToCertArray();
// write incremental
document.saveIncremental(output);
}
Aggregations