pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1599005 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java
Date Sun, 01 Jun 2014 15:58:41 GMT
Author: lehmi
Date: Sun Jun  1 15:58:40 2014
New Revision: 1599005

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

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java?rev=1599005&r1=1599004&r2=1599005&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java
Sun Jun  1 15:58:40 2014
@@ -26,7 +26,7 @@ import java.security.InvalidKeyException
 import java.security.KeyStoreException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
+import java.security.PrivateKey;
 import java.security.SecureRandom;
 import java.security.Security;
 import java.security.cert.CertificateEncodingException;
@@ -41,9 +41,9 @@ import javax.crypto.NoSuchPaddingExcepti
 import javax.crypto.SecretKey;
 
 import org.bouncycastle.asn1.ASN1InputStream;
+import org.bouncycastle.asn1.ASN1ObjectIdentifier;
 import org.bouncycastle.asn1.ASN1Primitive;
 import org.bouncycastle.asn1.ASN1Set;
-import org.bouncycastle.asn1.DERObjectIdentifier;
 import org.bouncycastle.asn1.DEROctetString;
 import org.bouncycastle.asn1.DEROutputStream;
 import org.bouncycastle.asn1.DERSet;
@@ -60,6 +60,7 @@ import org.bouncycastle.asn1.x509.TBSCer
 import org.bouncycastle.cms.CMSEnvelopedData;
 import org.bouncycastle.cms.CMSException;
 import org.bouncycastle.cms.RecipientInformation;
+import org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSString;
@@ -165,7 +166,7 @@ public final class PublicKeySecurityHand
 	              COSString recipientFieldString = encryption.getRecipientStringAt(i);
 	              byte[] recipientBytes = recipientFieldString.getBytes();
 	              CMSEnvelopedData data = new CMSEnvelopedData(recipientBytes);
-	              Iterator recipCertificatesIt = data.getRecipientInfos().getRecipients().iterator();
+	              Iterator<?> recipCertificatesIt = data.getRecipientInfos().getRecipients().iterator();
 	              while(recipCertificatesIt.hasNext())
 	              {
 	                  RecipientInformation ri =
@@ -175,7 +176,8 @@ public final class PublicKeySecurityHand
 	                  if(ri.getRID().match(material.getCertificate()) && !foundRecipient)
 	                  {
 	                      foundRecipient = true;
-	                      envelopedData = ri.getContent(material.getPrivateKey(), "BC");
+	                      PrivateKey privateKey = (PrivateKey)material.getPrivateKey();
+	                      envelopedData = ri.getContent(new JceKeyTransEnvelopedRecipient(privateKey).setProvider("BC"));
 	                      break;
 	                  }
 	              }
@@ -231,10 +233,6 @@ public final class PublicKeySecurityHand
 	      {
 	          throw new IOException(e);
 	      }
-	      catch(NoSuchProviderException e)
-	      {
-	          throw new IOException(e);
-	      }
     }
     
     /**
@@ -287,13 +285,13 @@ public final class PublicKeySecurityHand
             System.arraycopy(sk.getEncoded(), 0, seed, 0, 20); // create the 20 bytes seed
 
 
-            Iterator it = policy.getRecipientsIterator();
+            Iterator<PublicKeyRecipient> it = policy.getRecipientsIterator();
             int i = 0;
 
 
             while(it.hasNext())
             {
-                PublicKeyRecipient recipient = (PublicKeyRecipient)it.next();
+                PublicKeyRecipient recipient = it.next();
                 X509Certificate certificate = recipient.getX509();
                 int permission = recipient.getPermission().getPermissionBytesForPublicKey();
 
@@ -393,6 +391,7 @@ public final class PublicKeySecurityHand
 
         ASN1InputStream input = new ASN1InputStream(parameters.getEncoded("ASN.1"));
         ASN1Primitive object = input.readObject();
+        input.close();
 
         keygen.init(128);
         SecretKey secretkey = keygen.generateKey();
@@ -403,7 +402,7 @@ public final class PublicKeySecurityHand
         KeyTransRecipientInfo recipientInfo = computeRecipientInfo(cert, secretkey.getEncoded());
         DERSet set = new DERSet(new RecipientInfo(recipientInfo));
 
-        AlgorithmIdentifier algorithmId = new AlgorithmIdentifier(new DERObjectIdentifier(algorithm),
object);
+        AlgorithmIdentifier algorithmId = new AlgorithmIdentifier(new ASN1ObjectIdentifier(algorithm),
object);
         EncryptedContentInfo encryptedInfo = new EncryptedContentInfo(PKCSObjectIdentifiers.data,
algorithmId, new DEROctetString(bytes));
         EnvelopedData enveloped = new EnvelopedData(null, set, encryptedInfo, (ASN1Set) null);
 
@@ -416,9 +415,10 @@ public final class PublicKeySecurityHand
             BadPaddingException, IllegalBlockSizeException
     {
         ASN1InputStream input = new ASN1InputStream(x509certificate.getTBSCertificate());
-
         TBSCertificateStructure certificate = TBSCertificateStructure.getInstance(input.readObject());
-        AlgorithmIdentifier algorithmId = certificate.getSubjectPublicKeyInfo().getAlgorithmId();
+        input.close();
+
+        AlgorithmIdentifier algorithmId = certificate.getSubjectPublicKeyInfo().getAlgorithm();
 
         IssuerAndSerialNumber serial = new IssuerAndSerialNumber(
                 certificate.getIssuer(),
@@ -427,7 +427,7 @@ public final class PublicKeySecurityHand
         Cipher cipher;
         try
         {
-            cipher = Cipher.getInstance(algorithmId.getObjectId().getId());
+            cipher = Cipher.getInstance(algorithmId.getAlgorithm().getId());
         }
         catch (NoSuchAlgorithmException e)
         {



Mime
View raw message