Class ShowSignature
java.lang.Object
org.apache.pdfbox.examples.signature.ShowSignature
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.apache.commons.logging.Logprivate final SimpleDateFormat -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidanalyseDSS(PDDocument document) Analyzes the DSS-Dictionary (Document Security Store) of the document.private voidcheckContentValueWithFile(File file, int[] byteRange, byte[] contents) private Set<X509Certificate> static voidThis is the entry point for the application.private voidprintStreamsFromArray(COSArray elements, String description) Go through the elements of a COSArray containing each an COSStream to print in Hex.private voidshowSignature(String[] args) private static voidusage()This will print a usage message.private voidverifyETSIdotRFC3161(InputStream signedContentAsStream, byte[] contents) Verify ETSI.RFC3161 TimeStampTokenprivate voidverifyPKCS7(InputStream signedContentAsStream, byte[] contents, PDSignature sig) Verify a PKCS7 signature.
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG -
sdf
-
-
Constructor Details
-
ShowSignature
private ShowSignature()
-
-
Method Details
-
main
public static void main(String[] args) throws IOException, org.bouncycastle.tsp.TSPException, CertificateVerificationException, GeneralSecurityException This is the entry point for the application.- Parameters:
args- The command-line arguments.- Throws:
IOException- If there is an error reading the file.org.bouncycastle.tsp.TSPExceptionCertificateVerificationExceptionGeneralSecurityException
-
showSignature
private void showSignature(String[] args) throws IOException, GeneralSecurityException, org.bouncycastle.tsp.TSPException, CertificateVerificationException - Throws:
IOExceptionGeneralSecurityExceptionorg.bouncycastle.tsp.TSPExceptionCertificateVerificationException
-
checkContentValueWithFile
private void checkContentValueWithFile(File file, int[] byteRange, byte[] contents) throws IOException - Throws:
IOException
-
verifyETSIdotRFC3161
private void verifyETSIdotRFC3161(InputStream signedContentAsStream, byte[] contents) throws org.bouncycastle.cms.CMSException, NoSuchAlgorithmException, IOException, org.bouncycastle.tsp.TSPException, org.bouncycastle.operator.OperatorCreationException, CertificateVerificationException, CertificateException Verify ETSI.RFC3161 TimeStampToken- Parameters:
signedContentAsStream- the byte sequence that has been signedcontents- the /Contents field as a COSString- Throws:
org.bouncycastle.cms.CMSExceptionNoSuchAlgorithmExceptionIOExceptionorg.bouncycastle.tsp.TSPExceptionorg.bouncycastle.operator.OperatorCreationExceptionCertificateVerificationExceptionCertificateException
-
verifyPKCS7
private void verifyPKCS7(InputStream signedContentAsStream, byte[] contents, PDSignature sig) throws org.bouncycastle.cms.CMSException, org.bouncycastle.operator.OperatorCreationException, CertificateVerificationException, GeneralSecurityException, org.bouncycastle.tsp.TSPException, IOException Verify 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.OperatorCreationExceptionGeneralSecurityExceptionCertificateVerificationExceptionorg.bouncycastle.tsp.TSPExceptionIOException
-
getRootCertificates
- Throws:
GeneralSecurityExceptionIOException
-
analyseDSS
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:
IOException
-
printStreamsFromArray
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:
IOException
-
usage
private static void usage()This will print a usage message.
-