Search in sources :

Example 1 with CertSignatureInformation

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);
}
Also used : COSDictionary(org.apache.pdfbox.cos.COSDictionary) COSArray(org.apache.pdfbox.cos.COSArray) CertSignatureInformation(org.apache.pdfbox.examples.signature.validation.CertInformationCollector.CertSignatureInformation) IOException(java.io.IOException) PDDocumentCatalog(org.apache.pdfbox.pdmodel.PDDocumentCatalog)

Aggregations

IOException (java.io.IOException)1 COSArray (org.apache.pdfbox.cos.COSArray)1 COSDictionary (org.apache.pdfbox.cos.COSDictionary)1 CertSignatureInformation (org.apache.pdfbox.examples.signature.validation.CertInformationCollector.CertSignatureInformation)1 PDDocumentCatalog (org.apache.pdfbox.pdmodel.PDDocumentCatalog)1