You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2013/07/17 10:00:33 UTC

svn commit: r1504038 - in /commons/sandbox/openpgp/trunk: pom.xml src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpStreamingSignatureVerifier.java src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpStreamingSigner.java

Author: ebourg
Date: Wed Jul 17 08:00:32 2013
New Revision: 1504038

URL: http://svn.apache.org/r1504038
Log:
Upgrade to Bouncy Castle 1.49 and replace the deprecated methods, thanks to Dennis Kieselhorst (SANDBOX-459)

Modified:
    commons/sandbox/openpgp/trunk/pom.xml
    commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpStreamingSignatureVerifier.java
    commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpStreamingSigner.java

Modified: commons/sandbox/openpgp/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/openpgp/trunk/pom.xml?rev=1504038&r1=1504037&r2=1504038&view=diff
==============================================================================
--- commons/sandbox/openpgp/trunk/pom.xml (original)
+++ commons/sandbox/openpgp/trunk/pom.xml Wed Jul 17 08:00:32 2013
@@ -16,7 +16,7 @@
     <dependency>
       <groupId>org.bouncycastle</groupId>
       <artifactId>bcpg-jdk15on</artifactId>
-      <version>1.48</version>
+      <version>1.49</version>
     </dependency>
     <dependency>
       <groupId>junit</groupId>

Modified: commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpStreamingSignatureVerifier.java
URL: http://svn.apache.org/viewvc/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpStreamingSignatureVerifier.java?rev=1504038&r1=1504037&r2=1504038&view=diff
==============================================================================
--- commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpStreamingSignatureVerifier.java (original)
+++ commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpStreamingSignatureVerifier.java Wed Jul 17 08:00:32 2013
@@ -19,7 +19,6 @@ package org.apache.commons.openpgp;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.security.NoSuchProviderException;
 import java.security.Security;
 import java.security.SignatureException;
 
@@ -31,6 +30,7 @@ import org.bouncycastle.openpgp.PGPPubli
 import org.bouncycastle.openpgp.PGPSignature;
 import org.bouncycastle.openpgp.PGPSignatureList;
 import org.bouncycastle.openpgp.PGPUtil;
+import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
 
 /**
  * Bouncy Castle implementation of the OpenPGP signer.
@@ -106,13 +106,7 @@ public class BouncyCastleOpenPgpStreamin
                     + Long.toHexString( sig.getKeyID() ).toUpperCase() + "' in public key ring" );
             }
 
-            sig.initVerify( key, "BC" );
-        }
-        catch ( NoSuchProviderException e )
-        {
-            throw new OpenPgpException(
-                                        "Unable to find the correct provider for PGP - check that the Bouncy Castle provider is correctly installed",
-                                        e );
+            sig.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), key);
         }
         catch ( PGPException e )
         {

Modified: commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpStreamingSigner.java
URL: http://svn.apache.org/viewvc/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpStreamingSigner.java?rev=1504038&r1=1504037&r2=1504038&view=diff
==============================================================================
--- commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpStreamingSigner.java (original)
+++ commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpStreamingSigner.java Wed Jul 17 08:00:32 2013
@@ -19,19 +19,20 @@ package org.apache.commons.openpgp;
 
 import org.bouncycastle.bcpg.ArmoredOutputStream;
 import org.bouncycastle.bcpg.BCPGOutputStream;
+import org.bouncycastle.bcpg.HashAlgorithmTags;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.bouncycastle.openpgp.PGPException;
 import org.bouncycastle.openpgp.PGPPrivateKey;
 import org.bouncycastle.openpgp.PGPSecretKey;
 import org.bouncycastle.openpgp.PGPSignature;
 import org.bouncycastle.openpgp.PGPSignatureGenerator;
-import org.bouncycastle.openpgp.PGPUtil;
+import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
 import java.security.Security;
 import java.security.SignatureException;
 
@@ -90,21 +91,12 @@ public class BouncyCastleOpenPgpStreamin
             {
                 throw new OpenPgpException( "The key with id '" + keyId + "' was not found in the secret keyring." );
             }
-            PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey( keyRing.getPassword(), PROVIDER );
-            sGen = new PGPSignatureGenerator( pgpSec.getPublicKey().getAlgorithm(), PGPUtil.SHA1, PROVIDER );
-            sGen.initSign( PGPSignature.BINARY_DOCUMENT, pgpPrivKey );
-        }
-        catch ( NoSuchAlgorithmException e )
-        {
-            throw new OpenPgpException(
-                "Unable to find the correct algorithm for PGP - check that the Bouncy Castle provider is correctly installed",
-                e );
-        }
-        catch ( NoSuchProviderException e )
-        {
-            throw new OpenPgpException(
-                "Unable to find the correct provider for PGP - check that the Bouncy Castle provider is correctly installed",
-                e );
+            PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder(
+                    new JcaPGPDigestCalculatorProviderBuilder().setProvider(PROVIDER).build()).setProvider(PROVIDER).
+                    build(keyRing.getPassword()));
+            sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(),
+                    HashAlgorithmTags.SHA1).setProvider(PROVIDER).setDigestProvider(PROVIDER));
+            sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);
         }
         catch ( PGPException e )
         {