pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1599017 - in /pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature: CMSProcessableInputStream.java CreateSignature.java CreateVisibleSignature.java ShowSignature.java TSAClient.java
Date Sun, 01 Jun 2014 17:47:24 GMT
Author: lehmi
Date: Sun Jun  1 17:47:23 2014
New Revision: 1599017

URL: http://svn.apache.org/r1599017
Log:
PDFBOX-2088: removed almost all deprecated bouncy castle calls to be compatible with bc 1.50

Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CMSProcessableInputStream.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/TSAClient.java

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CMSProcessableInputStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CMSProcessableInputStream.java?rev=1599017&r1=1599016&r2=1599017&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CMSProcessableInputStream.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CMSProcessableInputStream.java
Sun Jun  1 17:47:23 2014
@@ -16,8 +16,10 @@
  */
 package org.apache.pdfbox.examples.signature;
 
+import org.bouncycastle.asn1.ASN1ObjectIdentifier;
+import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
 import org.bouncycastle.cms.CMSException;
-import org.bouncycastle.cms.CMSProcessable;
+import org.bouncycastle.cms.CMSTypedData;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -28,12 +30,19 @@ import java.io.OutputStream;
  * It's an alternative to the CMSProcessableByteArray.
  * @author Thomas Chojecki
  */
-class CMSProcessableInputStream implements CMSProcessable
+class CMSProcessableInputStream implements CMSTypedData
 {
     private InputStream in;
+    private final ASN1ObjectIdentifier contentType;
 
     public CMSProcessableInputStream(InputStream is)
     {
+        this(new ASN1ObjectIdentifier(CMSObjectIdentifiers.data.getId()), is);
+    }
+
+    public CMSProcessableInputStream(ASN1ObjectIdentifier type, InputStream is)
+    {
+        contentType = type;
         in = is;
     }
 
@@ -53,4 +62,10 @@ class CMSProcessableInputStream implemen
         }
         in.close();
     }
+
+    @Override
+    public ASN1ObjectIdentifier getContentType()
+    {
+        return contentType;
+    }
 }
\ No newline at end of file

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java?rev=1599017&r1=1599016&r2=1599017&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java
Sun Jun  1 17:47:23 2014
@@ -31,12 +31,9 @@ import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.security.PrivateKey;
 import java.security.UnrecoverableKeyException;
-import java.security.cert.CertStore;
 import java.security.cert.Certificate;
-import java.security.cert.CollectionCertStoreParameters;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Collection;
 import java.util.Enumeration;
@@ -50,13 +47,14 @@ import org.bouncycastle.asn1.ASN1Encodab
 import org.bouncycastle.asn1.ASN1InputStream;
 import org.bouncycastle.asn1.ASN1Object;
 import org.bouncycastle.asn1.ASN1ObjectIdentifier;
+import org.bouncycastle.asn1.ASN1Primitive;
 import org.bouncycastle.asn1.DERSet;
 import org.bouncycastle.asn1.cms.Attribute;
 import org.bouncycastle.asn1.cms.AttributeTable;
 import org.bouncycastle.asn1.cms.Attributes;
 import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
+import org.bouncycastle.cert.X509CertificateHolder;
 import org.bouncycastle.cms.CMSException;
-import org.bouncycastle.cms.CMSProcessable;
 import org.bouncycastle.cms.CMSSignedData;
 import org.bouncycastle.cms.CMSSignedDataGenerator;
 import org.bouncycastle.cms.CMSSignedGenerator;
@@ -266,21 +264,17 @@ public class CreateSignature implements 
     {
         try
         {
-            CMSProcessable processable = new CMSProcessableInputStream(content);
-
-            CertStore certStore = CertStore.getInstance("Collection",
-                    new CollectionCertStoreParameters(Arrays.asList(certificateChain)));
-
+            CMSProcessableInputStream processable = new CMSProcessableInputStream(content);
+            org.bouncycastle.asn1.x509.Certificate certificate =
+                    org.bouncycastle.asn1.x509.Certificate.getInstance(ASN1Primitive.fromByteArray(certificateChain[0].getEncoded()));
             CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
             gen.addSigner(privateKey, (X509Certificate) certificateChain[0], CMSSignedGenerator.DIGEST_SHA256);
-            gen.addCertificatesAndCRLs(certStore);
+            gen.addCertificate(new X509CertificateHolder(certificate));
             CMSSignedData signedData = gen.generate(processable, false, new BouncyCastleProvider());
-
             if (tsaClient != null)
             {
                 signedData = signTimeStamps(signedData);
             }
-
             return signedData.getEncoded();
         }
         catch (GeneralSecurityException e)

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java?rev=1599017&r1=1599016&r2=1599017&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
Sun Jun  1 17:47:23 2014
@@ -26,15 +26,11 @@ import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
 import java.security.PrivateKey;
 import java.security.UnrecoverableKeyException;
-import java.security.cert.CertStore;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateException;
-import java.security.cert.CollectionCertStoreParameters;
 import java.security.cert.X509Certificate;
-import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Enumeration;
-import java.util.List;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
@@ -42,6 +38,8 @@ import org.apache.pdfbox.pdmodel.interac
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureOptions;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible.PDVisibleSigProperties;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible.PDVisibleSignDesigner;
+import org.bouncycastle.asn1.ASN1Primitive;
+import org.bouncycastle.cert.X509CertificateHolder;
 import org.bouncycastle.cms.CMSSignedData;
 import org.bouncycastle.cms.CMSSignedDataGenerator;
 import org.bouncycastle.cms.CMSSignedGenerator;
@@ -187,16 +185,13 @@ public class CreateVisibleSignature impl
     {
         CMSProcessableInputStream input = new CMSProcessableInputStream(content);
         CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
-        // CertificateChain
-        List<Certificate> certList = Arrays.asList(cert);
-
-        CertStore certStore = null;
         try
         {
-            certStore = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certList),
provider);
-            gen.addSigner(privKey, (X509Certificate) certList.get(0), CMSSignedGenerator.DIGEST_SHA256);
-            gen.addCertificatesAndCRLs(certStore);
-            CMSSignedData signedData = gen.generate(input, false, provider);
+            org.bouncycastle.asn1.x509.Certificate certificate = 
+                    org.bouncycastle.asn1.x509.Certificate.getInstance(ASN1Primitive.fromByteArray(cert[0].getEncoded()));

+            gen.addSigner(privKey, (X509Certificate) cert[0], CMSSignedGenerator.DIGEST_SHA256);
+            gen.addCertificate(new X509CertificateHolder(certificate));
+            CMSSignedData signedData = gen.generate(input, false, new BouncyCastleProvider());
             return signedData.getEncoded();
         }
         catch (Exception e)

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=1599017&r1=1599016&r2=1599017&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
Sun Jun  1 17:47:23 2014
@@ -30,7 +30,6 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSString;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
 import org.apache.pdfbox.pdmodel.encryption.StandardDecryptionMaterial;
 
 /**

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/TSAClient.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/TSAClient.java?rev=1599017&r1=1599016&r2=1599017&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/TSAClient.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/TSAClient.java
Sun Jun  1 17:47:23 2014
@@ -20,8 +20,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.math.BigInteger;
-import java.net.InetSocketAddress;
-import java.net.Proxy;
 import java.net.URL;
 import java.net.URLConnection;
 import java.security.MessageDigest;
@@ -30,11 +28,7 @@ import java.security.SecureRandom;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.io.IOUtils;
-import org.bouncycastle.asn1.ASN1InputStream;
-import org.bouncycastle.asn1.ASN1Object;
 import org.bouncycastle.asn1.ASN1ObjectIdentifier;
-import org.bouncycastle.asn1.DERSet;
-import org.bouncycastle.asn1.cms.Attribute;
 import org.bouncycastle.tsp.TSPException;
 import org.bouncycastle.tsp.TimeStampRequest;
 import org.bouncycastle.tsp.TimeStampRequestGenerator;



Mime
View raw message