Class ShowSignature
- java.lang.Object
-
- org.apache.pdfbox.examples.signature.ShowSignature
-
public final class ShowSignature extends java.lang.ObjectThis 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.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateShowSignature()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidanalyseDSS(PDDocument document)Analyzes the DSS-Dictionary (Document Security Store) of the document.private voidcheckContentValueWithFile(java.io.File file, int[] byteRange, byte[] contents)private java.util.Set<java.security.cert.X509Certificate>getRootCertificates()static voidmain(java.lang.String[] args)This is the entry point for the application.private voidprintStreamsFromArray(COSArray elements, java.lang.String description)Go through the elements of a COSArray containing each an COSStream to print in Hex.private voidshowSignature(java.lang.String[] args)private static voidusage()This will print a usage message.private voidverifyETSIdotRFC3161(java.io.InputStream signedContentAsStream, byte[] contents)Verify ETSI.RFC3161 TimeStampTokenprivate voidverifyPKCS7(java.io.InputStream signedContentAsStream, byte[] contents, PDSignature sig)Verify a PKCS7 signature.
-
-
-
Method Detail
-
main
public static void main(java.lang.String[] args) throws java.io.IOException, org.bouncycastle.tsp.TSPException, CertificateVerificationException, java.security.GeneralSecurityExceptionThis is the entry point for the application.- Parameters:
args- The command-line arguments.- Throws:
java.io.IOException- If there is an error reading the file.org.bouncycastle.tsp.TSPExceptionCertificateVerificationExceptionjava.security.GeneralSecurityException
-
showSignature
private void showSignature(java.lang.String[] args) throws java.io.IOException, java.security.GeneralSecurityException, org.bouncycastle.tsp.TSPException, CertificateVerificationException- Throws:
java.io.IOExceptionjava.security.GeneralSecurityExceptionorg.bouncycastle.tsp.TSPExceptionCertificateVerificationException
-
checkContentValueWithFile
private void checkContentValueWithFile(java.io.File file, int[] byteRange, byte[] contents) throws java.io.IOException- Throws:
java.io.IOException
-
verifyETSIdotRFC3161
private void verifyETSIdotRFC3161(java.io.InputStream signedContentAsStream, byte[] contents) throws org.bouncycastle.cms.CMSException, java.security.NoSuchAlgorithmException, java.io.IOException, org.bouncycastle.tsp.TSPException, org.bouncycastle.operator.OperatorCreationException, CertificateVerificationException, java.security.cert.CertificateExceptionVerify ETSI.RFC3161 TimeStampToken- Parameters:
signedContentAsStream- the byte sequence that has been signedcontents- the /Contents field as a COSString- Throws:
org.bouncycastle.cms.CMSExceptionjava.security.NoSuchAlgorithmExceptionjava.io.IOExceptionorg.bouncycastle.tsp.TSPExceptionorg.bouncycastle.operator.OperatorCreationExceptionCertificateVerificationExceptionjava.security.cert.CertificateException
-
verifyPKCS7
private void verifyPKCS7(java.io.InputStream signedContentAsStream, byte[] contents, PDSignature sig) throws org.bouncycastle.cms.CMSException, org.bouncycastle.operator.OperatorCreationException, CertificateVerificationException, java.security.GeneralSecurityException, org.bouncycastle.tsp.TSPException, java.io.IOExceptionVerify a PKCS7 signature.- Parameters:
signedContentAsStream- the byte sequence that has been signedcontents- the /Contents field as a COSStringsig- the PDF signature (the /V dictionary)- Throws:
org.bouncycastle.cms.CMSExceptionorg.bouncycastle.operator.OperatorCreationExceptionjava.security.GeneralSecurityExceptionCertificateVerificationExceptionorg.bouncycastle.tsp.TSPExceptionjava.io.IOException
-
getRootCertificates
private java.util.Set<java.security.cert.X509Certificate> getRootCertificates() throws java.security.GeneralSecurityException, java.io.IOException- Throws:
java.security.GeneralSecurityExceptionjava.io.IOException
-
analyseDSS
private void analyseDSS(PDDocument document) throws java.io.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, to get the DSS from- Throws:
java.io.IOException
-
printStreamsFromArray
private void printStreamsFromArray(COSArray elements, java.lang.String description) throws java.io.IOException
Go through the elements of a COSArray containing each an COSStream to print in Hex.- Parameters:
elements- COSArray of elements containing a COS Streamdescription- to append on Print- Throws:
java.io.IOException
-
usage
private static void usage()
This will print a usage message.
-
-