pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1845379 - /pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
Date Wed, 31 Oct 2018 20:07:18 GMT
Author: tilman
Date: Wed Oct 31 20:07:18 2018
New Revision: 1845379

URL: http://svn.apache.org/viewvc?rev=1845379&view=rev
Log:
PDFBOX-3017: refactor TimeStampToken extraction

Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java?rev=1845379&r1=1845378&r2=1845379&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
Wed Oct 31 20:07:18 2018
@@ -333,18 +333,10 @@ public final class ShowSignature
 
         SigUtils.checkCertificateUsage(certFromSignedData);
         
-        if (signerInformation.getUnsignedAttributes() != null)
+        // Embedded timestamp
+        TimeStampToken timeStampToken = extractTimeStampTokenFromSignerInformation(signerInformation);
+        if (timeStampToken != null)
         {
-            // Embedded timestamp
-            AttributeTable unsignedAttributes = signerInformation.getUnsignedAttributes();
-
-            // https://stackoverflow.com/questions/1647759/how-to-validate-if-a-signed-jar-contains-a-timestamp
-            Attribute attribute = unsignedAttributes.get(
-                    PKCSObjectIdentifiers.id_aa_signatureTimeStampToken);
-            ASN1Object obj = (ASN1Object) attribute.getAttrValues().getObjectAt(0);
-            CMSSignedData signedTSTData = new CMSSignedData(obj.getEncoded());
-            TimeStampToken timeStampToken = new TimeStampToken(signedTSTData);
-
             // tested with QV_RCA1_RCA3_CPCPS_V4_11.pdf
             // https://www.quovadisglobal.com/~/media/Files/Repository/QV_RCA1_RCA3_CPCPS_V4_11.ashx
             // timeStampToken.getCertificates() only contained the local certificate and
not
@@ -432,6 +424,22 @@ public final class ShowSignature
         }
     }
 
+    private TimeStampToken extractTimeStampTokenFromSignerInformation(SignerInformation signerInformation)
+            throws CMSException, IOException, TSPException
+    {
+        if (signerInformation.getUnsignedAttributes() == null)
+        {
+            return null;
+        }
+        AttributeTable unsignedAttributes = signerInformation.getUnsignedAttributes();
+        // https://stackoverflow.com/questions/1647759/how-to-validate-if-a-signed-jar-contains-a-timestamp
+        Attribute attribute = unsignedAttributes.get(
+                PKCSObjectIdentifiers.id_aa_signatureTimeStampToken);
+        ASN1Object obj = (ASN1Object) attribute.getAttrValues().getObjectAt(0);
+        CMSSignedData signedTSTData = new CMSSignedData(obj.getEncoded());
+        return new TimeStampToken(signedTSTData);
+    }
+
     private void verifyCertificateChain(Store<X509CertificateHolder> certificatesStore,
             X509Certificate certFromSignedData, Date signDate)
             throws CertificateVerificationException, CertificateException



Mime
View raw message