You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/11/15 07:26:31 UTC

svn commit: r1869834 - /pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/CertInformationCollector.java

Author: tilman
Date: Fri Nov 15 07:26:31 2019
New Revision: 1869834

URL: http://svn.apache.org/viewvc?rev=1869834&view=rev
Log:
PDFBOX-3017: remove uneeded wrapper class, simplify code

Modified:
    pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/CertInformationCollector.java

Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/CertInformationCollector.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/CertInformationCollector.java?rev=1869834&r1=1869833&r2=1869834&view=diff
==============================================================================
--- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/CertInformationCollector.java (original)
+++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/CertInformationCollector.java Fri Nov 15 07:26:31 2019
@@ -50,8 +50,6 @@ import org.bouncycastle.cert.jcajce.JcaX
 import org.bouncycastle.cms.CMSException;
 import org.bouncycastle.cms.CMSSignedData;
 import org.bouncycastle.cms.SignerInformation;
-import org.bouncycastle.tsp.TSPException;
-import org.bouncycastle.tsp.TimeStampToken;
 import org.bouncycastle.util.Selector;
 import org.bouncycastle.util.Store;
 
@@ -118,11 +116,7 @@ public class CertInformationCollector
         try
         {
             CMSSignedData signedData = new CMSSignedData(signatureContent);
-            Store<X509CertificateHolder> certificatesStore = signedData.getCertificates();
-
-            SignerInformation signerInformation = processSignerStore(certificatesStore, signedData,
-                    rootCertInfo);
-
+            SignerInformation signerInformation = processSignerStore(signedData, rootCertInfo);
             addTimestampCerts(signerInformation);
         }
         catch (CMSException e)
@@ -156,18 +150,9 @@ public class CertInformationCollector
 
         try
         {
-            TimeStampToken tsToken = new TimeStampToken(new CMSSignedData(tsSeq.getEncoded("DER")));
-
+            CMSSignedData signedData = new CMSSignedData(tsSeq.getEncoded("DER"));
             rootCertInfo.tsaCerts = new CertSignatureInformation();
-
-            @SuppressWarnings("unchecked")
-            Store<X509CertificateHolder> certificatesStore = tsToken.getCertificates();
-
-            processSignerStore(certificatesStore, tsToken.toCMSSignedData(), rootCertInfo.tsaCerts);
-        }
-        catch (TSPException e)
-        {
-            throw new IOException("Error parsing timestamp token", e);
+            processSignerStore(signedData, rootCertInfo.tsaCerts);
         }
         catch (CMSException e)
         {
@@ -180,15 +165,13 @@ public class CertInformationCollector
      * to the certInfo. Handles only the first signer, although multiple would be possible, but is
      * not yet practicable.
      *
-     * @param certificatesStore To get the certificate information from. Certificates will be saved
-     * in certificateSet.
      * @param signedData data from which to get the SignerInformation
      * @param certInfo where to add certificate information
      * @return Signer Information of the processed certificatesStore for further usage.
      * @throws IOException on data-processing error
      * @throws CertificateProccessingException on a specific error with a certificate
      */
-    private SignerInformation processSignerStore(Store<X509CertificateHolder> certificatesStore,
+    private SignerInformation processSignerStore(
             CMSSignedData signedData, CertSignatureInformation certInfo)
             throws IOException, CertificateProccessingException
     {
@@ -196,6 +179,8 @@ public class CertInformationCollector
         SignerInformation signerInformation = signers.iterator().next();
 
         @SuppressWarnings("unchecked")
+        Store<X509CertificateHolder> certificatesStore = signedData.getCertificates();
+        @SuppressWarnings("unchecked")
         Collection<X509CertificateHolder> matches = certificatesStore
                 .getMatches((Selector<X509CertificateHolder>) signerInformation.getSID());