camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bvah...@apache.org
Subject git commit: Upgrade to Bouncy Castle 1.48 which is already an OSGi bundle out-of-the-box (no need for a SMX bundle anymore). Also cleaned up all the @deprecated Bouncy Castle API usages inside the code base of this component.
Date Fri, 31 May 2013 19:56:20 GMT
Updated Branches:
  refs/heads/master 9016ac6a2 -> 343fd1cf5


Upgrade to Bouncy Castle 1.48 which is already an OSGi bundle out-of-the-box (no need for
a SMX bundle anymore). Also cleaned up all the @deprecated Bouncy Castle API usages inside
the code base of this component.

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/343fd1cf
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/343fd1cf
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/343fd1cf

Branch: refs/heads/master
Commit: 343fd1cf5b08953072f4f3b5bb344dbfad87343c
Parents: 9016ac6
Author: Babak Vahdat <bvahdat@apache.org>
Authored: Fri May 31 21:56:14 2013 +0200
Committer: Babak Vahdat <bvahdat@apache.org>
Committed: Fri May 31 21:56:14 2013 +0200

----------------------------------------------------------------------
 .../camel/converter/crypto/PGPDataFormat.java      |   25 ++++++++++-----
 .../camel/converter/crypto/PGPDataFormatUtil.java  |    5 ++-
 .../crypto/AbstractPGPDataFormatTest.java          |    3 +-
 .../converter/crypto/CryptoDataFormatTest.java     |    7 ++--
 parent/pom.xml                                     |    3 +-
 .../karaf/features/src/main/resources/features.xml |    3 +-
 6 files changed, 27 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/343fd1cf/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
b/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
index 4eaa074..4f315a9 100644
--- a/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
+++ b/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
@@ -58,6 +58,12 @@ import org.bouncycastle.openpgp.PGPSignatureGenerator;
 import org.bouncycastle.openpgp.PGPSignatureList;
 import org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator;
 import org.bouncycastle.openpgp.PGPUtil;
+import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
+import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
 import org.bouncycastle.util.io.Streams;
 
 /**
@@ -130,8 +136,12 @@ public class PGPDataFormat implements DataFormat {
             outputStream = new ArmoredOutputStream(outputStream);
         }
 
-        PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5,
integrity, new SecureRandom(), "BC");
-        encGen.addMethod(key);
+        SecureRandom random = new SecureRandom();
+        PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).
+                                                                             setWithIntegrityPacket(integrity).
+                                                                             setSecureRandom(random).
+                                                                             setProvider("BC"));
+        encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(key));
         OutputStream encOut = encGen.open(outputStream, new byte[BUFFER_SIZE]);
 
         PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(CompressionAlgorithmTags.ZIP);
@@ -183,7 +193,7 @@ public class PGPDataFormat implements DataFormat {
             throw new IllegalArgumentException("Signature secret key is null, cannot proceed");
         }
 
-        PGPPrivateKey sigPrivateKey = sigSecretKey.extractPrivateKey(sigKeyPassword.toCharArray(),
"BC");
+        PGPPrivateKey sigPrivateKey = sigSecretKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(sigKeyPassword.toCharArray()));
         if (sigPrivateKey == null) {
             throw new IllegalArgumentException("Signature private key is null, cannot proceed");
         }
@@ -192,8 +202,8 @@ public class PGPDataFormat implements DataFormat {
         spGen.setSignerUserID(false, sigKeyUserid);
 
         int algorithm = sigSecretKey.getPublicKey().getAlgorithm();
-        PGPSignatureGenerator sigGen = new PGPSignatureGenerator(algorithm, HashAlgorithmTags.SHA1,
"BC");
-        sigGen.initSign(PGPSignature.BINARY_DOCUMENT, sigPrivateKey);
+        PGPSignatureGenerator sigGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(algorithm,
HashAlgorithmTags.SHA1).setProvider("BC"));
+        sigGen.init(PGPSignature.BINARY_DOCUMENT, sigPrivateKey);
         sigGen.setHashedSubpackets(spGen.generate());
         sigGen.generateOnePassVersion(false).encode(out);
         return sigGen;
@@ -231,8 +241,7 @@ public class PGPDataFormat implements DataFormat {
         IOHelper.close(in);
 
         PGPPublicKeyEncryptedData pbe = (PGPPublicKeyEncryptedData) enc.get(0);
-        InputStream encData = pbe.getDataStream(key, "BC");
-
+        InputStream encData = pbe.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(key));
         pgpFactory = new PGPObjectFactory(encData);
         PGPCompressedData comData = (PGPCompressedData) pgpFactory.nextObject();
 
@@ -277,7 +286,7 @@ public class PGPDataFormat implements DataFormat {
         }
 
         PGPOnePassSignature signature = signatureList.get(0);
-        signature.initVerify(sigPublicKey, "BC");
+        signature.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), sigPublicKey);
         return signature;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/343fd1cf/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormatUtil.java
----------------------------------------------------------------------
diff --git a/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormatUtil.java
b/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormatUtil.java
index f2240b2..f01724d 100644
--- a/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormatUtil.java
+++ b/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormatUtil.java
@@ -36,6 +36,7 @@ import org.bouncycastle.openpgp.PGPSecretKey;
 import org.bouncycastle.openpgp.PGPSecretKeyRing;
 import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
 import org.bouncycastle.openpgp.PGPUtil;
+import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
 
 import static org.bouncycastle.bcpg.PublicKeyAlgorithmTags.DSA;
 import static org.bouncycastle.bcpg.PublicKeyAlgorithmTags.ECDSA;
@@ -127,7 +128,7 @@ public final class PGPDataFormatUtil {
         while (privateKey == null && encryptedDataObjects.hasNext()) {
             encryptedData = (PGPPublicKeyEncryptedData) encryptedDataObjects.next();
             PGPSecretKey pgpSecKey = pgpSec.getSecretKey(encryptedData.getKeyID());
-            privateKey = pgpSecKey.extractPrivateKey(passphrase.toCharArray(), "BC");
+            privateKey = pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(passphrase.toCharArray()));
         }
         return privateKey;
     }
@@ -154,7 +155,7 @@ public final class PGPDataFormatUtil {
             if (data instanceof PGPSecretKeyRing) {
                 PGPSecretKeyRing keyring = (PGPSecretKeyRing) data;
                 PGPSecretKey secKey = keyring.getSecretKey();
-                PGPPrivateKey privateKey = secKey.extractPrivateKey(passphrase.toCharArray(),
"BC");
+                PGPPrivateKey privateKey = secKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(passphrase.toCharArray()));
                 if (privateKey != null) {
                     pgpSecKey = secKey;
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/343fd1cf/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/AbstractPGPDataFormatTest.java
----------------------------------------------------------------------
diff --git a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/AbstractPGPDataFormatTest.java
b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/AbstractPGPDataFormatTest.java
index eadaefb..e941ce7 100644
--- a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/AbstractPGPDataFormatTest.java
+++ b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/AbstractPGPDataFormatTest.java
@@ -22,7 +22,6 @@ import java.util.Map;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
-import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 
@@ -45,7 +44,7 @@ public abstract class AbstractPGPDataFormatTest extends CamelTestSupport
{
         return new HashMap<String, Object>();
     }
 
-    protected void assertMocksSatisfied(MockEndpoint encrypted, MockEndpoint unencrypted,
String payload) throws InterruptedException, InvalidPayloadException {
+    protected void assertMocksSatisfied(MockEndpoint encrypted, MockEndpoint unencrypted,
String payload) throws Exception {
         awaitAndAssert(unencrypted);
         awaitAndAssert(encrypted);
         for (Exchange e : unencrypted.getReceivedExchanges()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/343fd1cf/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatTest.java
----------------------------------------------------------------------
diff --git a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatTest.java
b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatTest.java
index fb8cd5b..9d0f5a9 100644
--- a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatTest.java
+++ b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatTest.java
@@ -25,7 +25,6 @@ import javax.crypto.SecretKey;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
-import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -88,11 +87,11 @@ public class CryptoDataFormatTest extends CamelTestSupport {
         assertTrue(!ex.getIn().getHeaders().containsKey(CryptoDataFormat.KEY) || "".equals(header)
|| header == null);
     }
 
-    private void doRoundTripEncryptionTests(String endpointUri) throws Exception, InterruptedException,
InvalidPayloadException {
+    private void doRoundTripEncryptionTests(String endpointUri) throws Exception {
         doRoundTripEncryptionTests(endpointUri, Collections.<String, Object>emptyMap());
     }
 
-    private void doRoundTripEncryptionTests(String endpoint, Map<String, Object> headers)
throws Exception, InterruptedException, InvalidPayloadException {
+    private void doRoundTripEncryptionTests(String endpoint, Map<String, Object> headers)
throws Exception {
         MockEndpoint encrypted = setupExpectations(context, 3, "mock:encrypted");
         MockEndpoint unencrypted = setupExpectations(context, 3, "mock:unencrypted");
 
@@ -104,7 +103,7 @@ public class CryptoDataFormatTest extends CamelTestSupport {
         assertMocksSatisfied(encrypted, unencrypted, payload);
     }
 
-    private void assertMocksSatisfied(MockEndpoint encrypted, MockEndpoint unencrypted, String
payload) throws InterruptedException, InvalidPayloadException {
+    private void assertMocksSatisfied(MockEndpoint encrypted, MockEndpoint unencrypted, String
payload) throws Exception {
         awaitAndAssert(unencrypted);
         awaitAndAssert(encrypted);
         for (Exchange e : unencrypted.getReceivedExchanges()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/343fd1cf/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 25318b7..d592905 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -63,10 +63,9 @@
     <aws-java-sdk-version>1.3.27</aws-java-sdk-version>
     <axiom-version>1.2.14</axiom-version>
     <bcel-bundle-version>5.2_4</bcel-bundle-version>
-    <bcpg-jdk15on-bundle-version>1.47_1</bcpg-jdk15on-bundle-version>
     <beanio-version>2.0.5</beanio-version>
     <bsh-version>2.0b5</bsh-version>
-    <bouncycastle-version>1.47</bouncycastle-version>
+    <bouncycastle-version>1.48</bouncycastle-version>
     <build-helper-maven-plugin-version>1.7</build-helper-maven-plugin-version>
     <castor-bundle-version>1.3.2_2</castor-bundle-version>
     <cglib-bundle-version>2.1_3_7</cglib-bundle-version>

http://git-wip-us.apache.org/repos/asf/camel/blob/343fd1cf/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index ef87c06..165f9bb 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -196,7 +196,8 @@
     <feature version='${project.version}'>camel-core</feature>
     <bundle dependency='true'>mvn:commons-codec/commons-codec/${commons-codec-version}</bundle>
     <bundle dependency='true'>mvn:commons-io/commons-io/${commons-io-version}</bundle>
-    <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.bcpg-jdk15on/${bcpg-jdk15on-bundle-version}</bundle>
+    <bundle dependency='true'>mvn:org.bouncycastle/bcpg-jdk15on/${bouncycastle-version}</bundle>
+    <bundle dependency='true'>mvn:org.bouncycastle/bcprov-jdk15on/${bouncycastle-version}</bundle>
     <bundle>mvn:org.apache.camel/camel-crypto/${project.version}</bundle>
   </feature>
   <feature name='camel-csv' version='${project.version}' resolver='(obr)' start-level='50'>


Mime
View raw message