Top Description Fields Constructors Methods
org.apache.pdfbox.examples.signature

public final Class ShowSignature

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .File, .FileInputStream, .IOException, .InputStream, java.nio.charset.StandardCharsets, java.security.DigestInputStream, .GeneralSecurityException, .InvalidAlgorithmParameterException, .KeyStore, .KeyStoreException, .MessageDigest, .NoSuchAlgorithmException, .Security, java.security.cert.Certificate, .CertificateException, .CertificateExpiredException, .CertificateFactory, .CertificateNotYetValidException, .PKIXParameters, .TrustAnchor, .X509Certificate, java.text.SimpleDateFormat, java.util.Arrays, .Collection, .HashSet, .Set, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSName, .COSObject, .COSStream, .COSString, org.apache.pdfbox.examples.signature.cert.CertificateVerificationException, .CertificateVerifier, org.apache.pdfbox.io.IOUtils, .RandomAccessReadBufferedFile, org.apache.pdfbox.pdfparser.PDFParser, org.apache.pdfbox.pdmodel.PDDocument, .PDDocumentCatalog, org.apache.pdfbox.pdmodel.encryption.SecurityProvider, org.apache.pdfbox.pdmodel.interactive.digitalsignature.COSFilterInputStream, .PDSignature, org.apache.pdfbox.util.Hex, org.bouncycastle.asn1.cms.Attribute, .CMSAttributes, org.bouncycastle.asn1.x509.Time, org.bouncycastle.cert.X509CertificateHolder, org.bouncycastle.cert.jcajce.JcaCertStore, .JcaX509CertificateConverter, org.bouncycastle.cms.CMSException, .CMSProcessable, .CMSSignedData, .SignerInformation, org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoVerifierBuilder, org.bouncycastle.operator.OperatorCreationException, org.bouncycastle.tsp.TSPException, .TimeStampToken, .TimeStampTokenInfo, org.bouncycastle.util.CollectionStore, .Store

This will get the signature(s) from the document, do some verifications and show the signature(s) and the certificates. This is a complex topic - the code here is an example and not a production-ready solution.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private static final Log
private final SimpleDateFormat

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
analyseDSS(PDDocument
PDDocument, to get the DSS from
document
)

Analyzes the DSS-Dictionary (Document Security Store) of the document.

private void
checkContentValueWithFile(File file, int[] byteRange, byte[] contents)

private Set<X509Certificate>
public static void
main(String[]
The command-line arguments.
args
)

This is the entry point for the application.

private void
printStreamsFromArray(COSArray
COSArray of elements containing a COS Stream
elements
,
String
to append on Print
description
)

Go through the elements of a COSArray containing each an COSStream to print in Hex.

private void
private static void
usage()

This will print a usage message.

private void
verifyETSIdotRFC3161(InputStream
the byte sequence that has been signed
signedContentAsStream
,
byte[]
the /Contents field as a COSString
contents
)

Verify ETSI.RFC3161 TimeStampToken

private void
verifyPKCS7(InputStream
the byte sequence that has been signed
signedContentAsStream
,
byte[]
the /Contents field as a COSString
contents
,
PDSignature
the PDF signature (the /V dictionary)
sig
)

Verify a PKCS7 signature.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Log LOG
sdfback to summary
private final SimpleDateFormat sdf

Constructor Detail

ShowSignatureback to summary
private ShowSignature()

Method Detail

analyseDSSback to summary
private void analyseDSS(PDDocument document) throws IOException

Analyzes the DSS-Dictionary (Document Security Store) of the document. Which is used for signature validation. The DSS is defined in PAdES Part 4 - Long Term Validation.

Parameters
document:PDDocument

PDDocument, to get the DSS from

checkContentValueWithFileback to summary
private void checkContentValueWithFile(File file, int[] byteRange, byte[] contents) throws IOException
getRootCertificatesback to summary
private Set<X509Certificate> getRootCertificates() throws GeneralSecurityException, IOException
mainback to summary
public static void main(String[] args) throws IOException, TSPException, CertificateVerificationException, GeneralSecurityException

This is the entry point for the application.

Parameters
args:String[]

The command-line arguments.

Exceptions
IOException:
If there is an error reading the file.
printStreamsFromArrayback to summary
private void printStreamsFromArray(COSArray elements, String description) throws IOException

Go through the elements of a COSArray containing each an COSStream to print in Hex.

Parameters
elements:COSArray

COSArray of elements containing a COS Stream

description:String

to append on Print

showSignatureback to summary
private void showSignature(String[] args) throws IOException, GeneralSecurityException, TSPException, CertificateVerificationException
usageback to summary
private static void usage()

This will print a usage message.

verifyETSIdotRFC3161back to summary
private void verifyETSIdotRFC3161(InputStream signedContentAsStream, byte[] contents) throws CMSException, NoSuchAlgorithmException, IOException, TSPException, OperatorCreationException, CertificateVerificationException, CertificateException

Verify ETSI.RFC3161 TimeStampToken

Parameters
signedContentAsStream:InputStream

the byte sequence that has been signed

contents:byte[]

the /Contents field as a COSString

verifyPKCS7back to summary
private void verifyPKCS7(InputStream signedContentAsStream, byte[] contents, PDSignature sig) throws CMSException, OperatorCreationException, CertificateVerificationException, GeneralSecurityException, TSPException, IOException

Verify a PKCS7 signature.

Parameters
signedContentAsStream:InputStream

the byte sequence that has been signed

contents:byte[]

the /Contents field as a COSString

sig:PDSignature

the PDF signature (the /V dictionary)