Class SigUtils
java.lang.Object
org.apache.pdfbox.examples.signature.SigUtils
Utility class for the signature / timestamp examples.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckCertificateUsage(X509Certificate x509Certificate) Log if the certificate is not valid for signature usage.static voidLook for gaps in the cross reference table and display warnings if any found.static voidcheckResponderCertificateUsage(X509Certificate x509Certificate) Log if the certificate is not valid for responding.static voidcheckTimeStampCertificateUsage(X509Certificate x509Certificate) Log if the certificate is not valid for timestamping.static org.bouncycastle.tsp.TimeStampTokenextractTimeStampTokenFromSignerInformation(org.bouncycastle.cms.SignerInformation signerInformation) static X509CertificategetCertificateFromTimeStampToken(org.bouncycastle.tsp.TimeStampToken timeStampToken) Extract X.509 certificate from a timestampstatic PDSignaturegetLastRelevantSignature(PDDocument document) Gets the last relevant signature in the document, i.e.static intGet the access permissions granted for this document in the DocMDP transform parameters dictionary.static X509CertificategetTsaCertificate(String tsaUrl) Get certificate of a TSA.static InputStreamLikeURL.openStream()but will follow redirection from http to https.static voidsetMDPPermission(PDDocument doc, PDSignature signature, int accessPermissions) Set the "modification detection and prevention" permissions granted for this document in the DocMDP transform parameters dictionary.static voidvalidateTimestampToken(org.bouncycastle.tsp.TimeStampToken timeStampToken) static voidverifyCertificateChain(org.bouncycastle.util.Store<org.bouncycastle.cert.X509CertificateHolder> certificatesStore, X509Certificate certFromSignedData, Date signDate) Verify the certificate chain up to the root, including OCSP or CRL.
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG
-
-
Constructor Details
-
SigUtils
private SigUtils()
-
-
Method Details
-
getMDPPermission
Get the access permissions granted for this document in the DocMDP transform parameters dictionary. Details are described in the table "Entries in the DocMDP transform parameters dictionary" in the PDF specification.- Parameters:
doc- document.- Returns:
- the permission value. 0 means no DocMDP transform parameters dictionary exists. Other return values are 1, 2 or 3. 2 is also returned if the DocMDP transform parameters dictionary is found but did not contain a /P entry, or if the value is outside the valid range.
-
setMDPPermission
public static void setMDPPermission(PDDocument doc, PDSignature signature, int accessPermissions) throws IOException Set the "modification detection and prevention" permissions granted for this document in the DocMDP transform parameters dictionary. Details are described in the table "Entries in the DocMDP transform parameters dictionary" in the PDF specification.- Parameters:
doc- The document.signature- The signature object.accessPermissions- The permission value (1, 2 or 3).- Throws:
IOException- if a signature exists.
-
checkCertificateUsage
public static void checkCertificateUsage(X509Certificate x509Certificate) throws CertificateParsingException Log if the certificate is not valid for signature usage. Doing this anyway results in Adobe Reader failing to validate the PDF.- Parameters:
x509Certificate-- Throws:
CertificateParsingException
-
checkTimeStampCertificateUsage
public static void checkTimeStampCertificateUsage(X509Certificate x509Certificate) throws CertificateParsingException Log if the certificate is not valid for timestamping.- Parameters:
x509Certificate-- Throws:
CertificateParsingException
-
checkResponderCertificateUsage
public static void checkResponderCertificateUsage(X509Certificate x509Certificate) throws CertificateParsingException Log if the certificate is not valid for responding.- Parameters:
x509Certificate-- Throws:
CertificateParsingException
-
getLastRelevantSignature
Gets the last relevant signature in the document, i.e. the one with the highest offset.- Parameters:
document- to get its last signature- Returns:
- last signature or null when none found
-
extractTimeStampTokenFromSignerInformation
public static org.bouncycastle.tsp.TimeStampToken extractTimeStampTokenFromSignerInformation(org.bouncycastle.cms.SignerInformation signerInformation) throws org.bouncycastle.cms.CMSException, IOException, org.bouncycastle.tsp.TSPException - Throws:
org.bouncycastle.cms.CMSExceptionIOExceptionorg.bouncycastle.tsp.TSPException
-
validateTimestampToken
public static void validateTimestampToken(org.bouncycastle.tsp.TimeStampToken timeStampToken) throws org.bouncycastle.tsp.TSPException, CertificateException, org.bouncycastle.operator.OperatorCreationException, IOException - Throws:
org.bouncycastle.tsp.TSPExceptionCertificateExceptionorg.bouncycastle.operator.OperatorCreationExceptionIOException
-
verifyCertificateChain
public static void verifyCertificateChain(org.bouncycastle.util.Store<org.bouncycastle.cert.X509CertificateHolder> certificatesStore, X509Certificate certFromSignedData, Date signDate) throws CertificateVerificationException, CertificateException Verify the certificate chain up to the root, including OCSP or CRL. However this does not test whether the root certificate is in a trusted list.
Please post bad PDF files that succeed and good PDF files that fail in PDFBOX-3017.- Parameters:
certificatesStore-certFromSignedData-signDate-- Throws:
CertificateVerificationExceptionCertificateException
-
getTsaCertificate
public static X509Certificate getTsaCertificate(String tsaUrl) throws GeneralSecurityException, IOException, URISyntaxException Get certificate of a TSA.- Parameters:
tsaUrl- URL- Returns:
- the X.509 certificate.
- Throws:
GeneralSecurityExceptionIOExceptionURISyntaxException
-
getCertificateFromTimeStampToken
public static X509Certificate getCertificateFromTimeStampToken(org.bouncycastle.tsp.TimeStampToken timeStampToken) throws CertificateException Extract X.509 certificate from a timestamp- Parameters:
timeStampToken-- Returns:
- the X.509 certificate.
- Throws:
CertificateException
-
checkCrossReferenceTable
Look for gaps in the cross reference table and display warnings if any found. See also here.- Parameters:
doc- document.
-
openURL
LikeURL.openStream()but will follow redirection from http to https.- Parameters:
urlString-- Returns:
- Throws:
IOExceptionURISyntaxException
-