You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/10/11 15:23:12 UTC
[1/2] git commit: CAMEL-6837: PGP Data Format:allow other JCE
providers than BC. Thanks to Franz Forsthofer for the patch.
Updated Branches:
refs/heads/camel-2.12.x e8288db96 -> 77b27f8d4
refs/heads/master c698df6e7 -> 4bae319a9
CAMEL-6837: PGP Data Format:allow other JCE providers than BC. Thanks to Franz Forsthofer for the patch.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4bae319a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4bae319a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4bae319a
Branch: refs/heads/master
Commit: 4bae319a927c69b2c7cc99e5263b78b397d80e9e
Parents: c698df6
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Oct 11 15:22:25 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Oct 11 15:22:25 2013 +0200
----------------------------------------------------------------------
.../camel/model/dataformat/PGPDataFormat.java | 13 +++
.../camel/converter/crypto/PGPDataFormat.java | 88 +++++++++++++-------
.../converter/crypto/PGPDataFormatUtil.java | 20 ++---
.../converter/crypto/PGPDataFormatTest.java | 12 +++
.../crypto/PGPDataFormatWithProvider.java | 25 ++++++
5 files changed, 120 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4bae319a/camel-core/src/main/java/org/apache/camel/model/dataformat/PGPDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/PGPDataFormat.java b/camel-core/src/main/java/org/apache/camel/model/dataformat/PGPDataFormat.java
index 6f9fa26..39e9869 100644
--- a/camel-core/src/main/java/org/apache/camel/model/dataformat/PGPDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/PGPDataFormat.java
@@ -42,6 +42,8 @@ public class PGPDataFormat extends DataFormatDefinition {
private Boolean armored;
@XmlAttribute
private Boolean integrity;
+ @XmlAttribute
+ private String provider;
public PGPDataFormat() {
super("pgp");
@@ -64,6 +66,9 @@ public class PGPDataFormat extends DataFormatDefinition {
if (integrity != null) {
setProperty(camelContext, dataFormat, "integrity", integrity);
}
+ if (provider != null) {
+ setProperty(camelContext, dataFormat, "provider", provider);
+ }
}
public Boolean getArmored() {
@@ -105,4 +110,12 @@ public class PGPDataFormat extends DataFormatDefinition {
public void setPassword(String password) {
this.password = password;
}
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/4bae319a/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 d0d3730..eab0e71 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
@@ -30,6 +30,7 @@ import java.util.Date;
import org.apache.camel.Exchange;
import org.apache.camel.spi.DataFormat;
+import org.apache.camel.support.ServiceSupport;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
@@ -65,12 +66,15 @@ 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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * <code>PGPDataFormat</code> uses the <a href="http://www.bouncycastle.org/java.htm">bouncy castle</a>
- * libraries to enable encryption and decryption in the PGP format.
+ * <code>PGPDataFormat</code> uses the <a
+ * href="http://www.bouncycastle.org/java.htm">bouncy castle</a> libraries to
+ * enable encryption and decryption in the PGP format.
*/
-public class PGPDataFormat implements DataFormat {
+public class PGPDataFormat extends ServiceSupport implements DataFormat {
public static final String KEY_FILE_NAME = "CamelPGPDataFormatKeyFileName";
public static final String ENCRYPTION_KEY_RING = "CamelPGPDataFormatEncryptionKeyRing";
@@ -81,8 +85,14 @@ public class PGPDataFormat implements DataFormat {
public static final String SIGNATURE_KEY_USERID = "CamelPGPDataFormatSignatureKeyUserid";
public static final String SIGNATURE_KEY_PASSWORD = "CamelPGPDataFormatSignatureKeyPassword";
+ private static final Logger LOG = LoggerFactory.getLogger(PGPDataFormat.class);
+
+ private static final String BC = "BC";
private static final int BUFFER_SIZE = 16 * 1024;
+ // Java Cryptography Extension provider, default is Bouncy Castle
+ private String provider = BC;
+
// encryption / decryption key info (required)
private String keyUserid;
private String password;
@@ -94,30 +104,27 @@ public class PGPDataFormat implements DataFormat {
private String signatureKeyUserid;
private String signaturePassword;
private String signatureKeyFileName;
- // alternatively to the sigknature key file name you can specify the signature key ring as byte array
+ // alternatively to the signature key file name you can specify the signature key ring as byte array
private byte[] signatureKeyRing;
private boolean armored;
private boolean integrity = true;
public PGPDataFormat() {
- if (Security.getProvider("BC") == null) {
- Security.addProvider(new BouncyCastleProvider());
- }
}
-
+
protected String findKeyFileName(Exchange exchange) {
return exchange.getIn().getHeader(KEY_FILE_NAME, getKeyFileName(), String.class);
}
-
+
protected byte[] findEncryptionKeyRing(Exchange exchange) {
return exchange.getIn().getHeader(ENCRYPTION_KEY_RING, getEncryptionKeyRing(), byte[].class);
}
-
+
protected String findKeyUserid(Exchange exchange) {
return exchange.getIn().getHeader(KEY_USERID, getKeyUserid(), String.class);
}
-
+
protected String findKeyPassword(Exchange exchange) {
return exchange.getIn().getHeader(KEY_PASSWORD, getPassword(), String.class);
}
@@ -125,7 +132,7 @@ public class PGPDataFormat implements DataFormat {
protected String findSignatureKeyFileName(Exchange exchange) {
return exchange.getIn().getHeader(SIGNATURE_KEY_FILE_NAME, getSignatureKeyFileName(), String.class);
}
-
+
protected byte[] findSignatureKeyRing(Exchange exchange) {
return exchange.getIn().getHeader(SIGNATURE_KEY_RING, getSignatureKeyRing(), byte[].class);
}
@@ -139,7 +146,8 @@ public class PGPDataFormat implements DataFormat {
}
public void marshal(Exchange exchange, Object graph, OutputStream outputStream) throws Exception {
- PGPPublicKey key = PGPDataFormatUtil.findPublicKey(exchange.getContext(), findKeyFileName(exchange), findEncryptionKeyRing(exchange), findKeyUserid(exchange), true);
+ PGPPublicKey key = PGPDataFormatUtil.findPublicKey(exchange.getContext(), findKeyFileName(exchange),
+ findEncryptionKeyRing(exchange), findKeyUserid(exchange), true);
if (key == null) {
throw new IllegalArgumentException("Public key is null, cannot proceed");
}
@@ -150,10 +158,8 @@ public class PGPDataFormat implements DataFormat {
outputStream = new ArmoredOutputStream(outputStream);
}
- PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.CAST5).
- setWithIntegrityPacket(integrity).
- setSecureRandom(new SecureRandom()).
- setProvider("BC"));
+ PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.CAST5)
+ .setWithIntegrityPacket(integrity).setSecureRandom(new SecureRandom()).setProvider(getProvider()));
encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(key));
OutputStream encOut = encGen.open(outputStream, new byte[BUFFER_SIZE]);
@@ -190,8 +196,8 @@ public class PGPDataFormat implements DataFormat {
}
}
- protected PGPSignatureGenerator createSignatureGenerator(Exchange exchange, OutputStream out)
- throws IOException, PGPException, NoSuchProviderException, NoSuchAlgorithmException {
+ protected PGPSignatureGenerator createSignatureGenerator(Exchange exchange, OutputStream out) throws IOException, PGPException,
+ NoSuchProviderException, NoSuchAlgorithmException {
String sigKeyFileName = findSignatureKeyFileName(exchange);
String sigKeyUserid = findSignatureKeyUserid(exchange);
@@ -202,12 +208,13 @@ public class PGPDataFormat implements DataFormat {
return null;
}
- PGPSecretKey sigSecretKey = PGPDataFormatUtil.findSecretKey(exchange.getContext(), sigKeyFileName, sigKeyRing, sigKeyPassword);
+ PGPSecretKey sigSecretKey = PGPDataFormatUtil.findSecretKey(exchange.getContext(), sigKeyFileName, sigKeyRing, sigKeyPassword, getProvider());
if (sigSecretKey == null) {
throw new IllegalArgumentException("Signature secret key is null, cannot proceed");
}
- PGPPrivateKey sigPrivateKey = sigSecretKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(sigKeyPassword.toCharArray()));
+ PGPPrivateKey sigPrivateKey = sigSecretKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(getProvider()).build(
+ sigKeyPassword.toCharArray()));
if (sigPrivateKey == null) {
throw new IllegalArgumentException("Signature private key is null, cannot proceed");
}
@@ -216,7 +223,8 @@ public class PGPDataFormat implements DataFormat {
spGen.setSignerUserID(false, sigKeyUserid);
int algorithm = sigSecretKey.getPublicKey().getAlgorithm();
- PGPSignatureGenerator sigGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(algorithm, HashAlgorithmTags.SHA1).setProvider("BC"));
+ PGPSignatureGenerator sigGen = new PGPSignatureGenerator(
+ new JcaPGPContentSignerBuilder(algorithm, HashAlgorithmTags.SHA1).setProvider(getProvider()));
sigGen.init(PGPSignature.BINARY_DOCUMENT, sigPrivateKey);
sigGen.setHashedSubpackets(spGen.generate());
sigGen.generateOnePassVersion(false).encode(out);
@@ -228,7 +236,8 @@ public class PGPDataFormat implements DataFormat {
return null;
}
- PGPPrivateKey key = PGPDataFormatUtil.findPrivateKey(exchange.getContext(), findKeyFileName(exchange), findEncryptionKeyRing(exchange), encryptedStream, findKeyPassword(exchange));
+ PGPPrivateKey key = PGPDataFormatUtil.findPrivateKey(exchange.getContext(), findKeyFileName(exchange),
+ findEncryptionKeyRing(exchange), encryptedStream, findKeyPassword(exchange), getProvider());
if (key == null) {
throw new IllegalArgumentException("Private key is null, cannot proceed");
}
@@ -255,7 +264,7 @@ public class PGPDataFormat implements DataFormat {
IOHelper.close(in);
PGPPublicKeyEncryptedData pbe = (PGPPublicKeyEncryptedData) enc.get(0);
- InputStream encData = pbe.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(key));
+ InputStream encData = pbe.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider(getProvider()).build(key));
pgpFactory = new PGPObjectFactory(encData);
PGPCompressedData comData = (PGPCompressedData) pgpFactory.nextObject();
@@ -291,16 +300,17 @@ public class PGPDataFormat implements DataFormat {
return answer;
}
- protected PGPOnePassSignature getSignature(Exchange exchange, PGPOnePassSignatureList signatureList)
- throws IOException, PGPException, NoSuchProviderException {
+ protected PGPOnePassSignature getSignature(Exchange exchange, PGPOnePassSignatureList signatureList) throws IOException, PGPException,
+ NoSuchProviderException {
- PGPPublicKey sigPublicKey = PGPDataFormatUtil.findPublicKey(exchange.getContext(), findSignatureKeyFileName(exchange), findSignatureKeyRing(exchange), findSignatureKeyUserid(exchange), false);
+ PGPPublicKey sigPublicKey = PGPDataFormatUtil.findPublicKey(exchange.getContext(), findSignatureKeyFileName(exchange),
+ findSignatureKeyRing(exchange), findSignatureKeyUserid(exchange), false);
if (sigPublicKey == null) {
throw new IllegalArgumentException("Signature public key is null, cannot proceed");
}
PGPOnePassSignature signature = signatureList.get(0);
- signature.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), sigPublicKey);
+ signature.init(new JcaPGPContentVerifierBuilderProvider().setProvider(getProvider()), sigPublicKey);
return signature;
}
@@ -408,4 +418,26 @@ public class PGPDataFormat implements DataFormat {
this.signatureKeyRing = signatureKeyRing;
}
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ if (Security.getProvider(BC) == null && BC.equals(getProvider())) {
+ LOG.debug("Adding BouncyCastleProvider as security provider");
+ Security.addProvider(new BouncyCastleProvider());
+ } else {
+ LOG.debug("Using custom provider {} which is expected to be enlisted manually.", getProvider());
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ // noop
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4bae319a/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 aa4b9c7..1dfa33a 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
@@ -125,23 +125,23 @@ public final class PGPDataFormatUtil {
public static PGPPrivateKey findPrivateKey(CamelContext context, String keychainFilename, InputStream encryptedInput, String passphrase)
throws IOException, PGPException, NoSuchProviderException {
- return findPrivateKey(context, keychainFilename, null, encryptedInput, passphrase);
+ return findPrivateKey(context, keychainFilename, null, encryptedInput, passphrase, "BC");
}
public static PGPPrivateKey findPrivateKey(CamelContext context, String keychainFilename, byte[] secKeyRing,
- InputStream encryptedInput, String passphrase) throws IOException, PGPException, NoSuchProviderException {
+ InputStream encryptedInput, String passphrase, String provider) throws IOException, PGPException, NoSuchProviderException {
InputStream keyChainInputStream = determineKeyRingInputStream(context, keychainFilename, secKeyRing, true);
PGPPrivateKey privKey = null;
try {
- privKey = findPrivateKey(keyChainInputStream, encryptedInput, passphrase);
+ privKey = findPrivateKey(keyChainInputStream, encryptedInput, passphrase, provider);
} finally {
IOHelper.close(keyChainInputStream);
}
return privKey;
}
- private static PGPPrivateKey findPrivateKey(InputStream keyringInput, InputStream encryptedInput, String passphrase) throws IOException,
+ private static PGPPrivateKey findPrivateKey(InputStream keyringInput, InputStream encryptedInput, String passphrase, String provider) throws IOException,
PGPException, NoSuchProviderException {
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(keyringInput));
PGPObjectFactory factory = new PGPObjectFactory(PGPUtil.getDecoderStream(encryptedInput));
@@ -163,7 +163,7 @@ public final class PGPDataFormatUtil {
encryptedData = (PGPPublicKeyEncryptedData) encryptedDataObjects.next();
PGPSecretKey pgpSecKey = pgpSec.getSecretKey(encryptedData.getKeyID());
if (pgpSecKey != null) {
- privateKey = pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(passphrase.toCharArray()));
+ privateKey = pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(provider).build(passphrase.toCharArray()));
}
}
if (privateKey == null && pgpSec.size() > 0 && encryptedData != null) {
@@ -174,23 +174,23 @@ public final class PGPDataFormatUtil {
public static PGPSecretKey findSecretKey(CamelContext context, String keychainFilename, String passphrase)
throws IOException, PGPException, NoSuchProviderException {
- return findSecretKey(context, keychainFilename, null, passphrase);
+ return findSecretKey(context, keychainFilename, null, passphrase, "BC");
}
- public static PGPSecretKey findSecretKey(CamelContext context, String keychainFilename, byte[] secKeyRing, String passphrase)
+ public static PGPSecretKey findSecretKey(CamelContext context, String keychainFilename, byte[] secKeyRing, String passphrase, String provider)
throws IOException, PGPException, NoSuchProviderException {
InputStream keyChainInputStream = determineKeyRingInputStream(context, keychainFilename, secKeyRing, false);
PGPSecretKey secKey = null;
try {
- secKey = findSecretKey(keyChainInputStream, passphrase);
+ secKey = findSecretKey(keyChainInputStream, passphrase, provider);
} finally {
IOHelper.close(keyChainInputStream);
}
return secKey;
}
- private static PGPSecretKey findSecretKey(InputStream keyringInput, String passphrase) throws IOException, PGPException, NoSuchProviderException {
+ private static PGPSecretKey findSecretKey(InputStream keyringInput, String passphrase, String provider) throws IOException, PGPException, NoSuchProviderException {
PGPSecretKey pgpSecKey = null;
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(keyringInput));
for (Iterator<?> i = pgpSec.getKeyRings(); i.hasNext() && pgpSecKey == null;) {
@@ -198,7 +198,7 @@ public final class PGPDataFormatUtil {
if (data instanceof PGPSecretKeyRing) {
PGPSecretKeyRing keyring = (PGPSecretKeyRing) data;
PGPSecretKey secKey = keyring.getSecretKey();
- PGPPrivateKey privateKey = secKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(passphrase.toCharArray()));
+ PGPPrivateKey privateKey = secKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(provider).build(passphrase.toCharArray()));
if (privateKey != null) {
pgpSecKey = secKey;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4bae319a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatTest.java
----------------------------------------------------------------------
diff --git a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatTest.java b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatTest.java
index 8597d12..8424ac4 100644
--- a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatTest.java
+++ b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatTest.java
@@ -45,6 +45,10 @@ public class PGPDataFormatTest extends AbstractPGPDataFormatTest {
protected String getKeyPassword() {
return "sdude";
}
+
+ protected String getProvider() {
+ return "BC";
+ }
@Test
public void testEncryption() throws Exception {
@@ -100,11 +104,13 @@ public class PGPDataFormatTest extends AbstractPGPDataFormatTest {
PGPDataFormat pgpEncrypt = new PGPDataFormat();
pgpEncrypt.setKeyFileName(keyFileName);
pgpEncrypt.setKeyUserid(keyUserid);
+ pgpEncrypt.setProvider(getProvider());
PGPDataFormat pgpDecrypt = new PGPDataFormat();
pgpDecrypt.setKeyFileName(keyFileNameSec);
pgpDecrypt.setKeyUserid(keyUserid);
pgpDecrypt.setPassword(keyPassword);
+ pgpDecrypt.setProvider(getProvider());
from("direct:inline2")
.marshal(pgpEncrypt)
@@ -126,6 +132,7 @@ public class PGPDataFormatTest extends AbstractPGPDataFormatTest {
pgpSignAndEncrypt.setSignatureKeyFileName(keyFileNameSec);
pgpSignAndEncrypt.setSignatureKeyUserid(keyUserid);
pgpSignAndEncrypt.setSignaturePassword(keyPassword);
+ pgpSignAndEncrypt.setProvider(getProvider());
PGPDataFormat pgpVerifyAndDecrypt = new PGPDataFormat();
pgpVerifyAndDecrypt.setKeyFileName(keyFileNameSec);
@@ -133,6 +140,7 @@ public class PGPDataFormatTest extends AbstractPGPDataFormatTest {
pgpVerifyAndDecrypt.setPassword(keyPassword);
pgpVerifyAndDecrypt.setSignatureKeyFileName(keyFileName);
pgpVerifyAndDecrypt.setSignatureKeyUserid(keyUserid);
+ pgpVerifyAndDecrypt.setProvider(getProvider());
from("direct:inline-sign")
.marshal(pgpSignAndEncrypt)
@@ -145,11 +153,13 @@ public class PGPDataFormatTest extends AbstractPGPDataFormatTest {
PGPDataFormat pgpEncryptByteArray = new PGPDataFormat();
pgpEncryptByteArray.setEncryptionKeyRing(getPublicKeyRing());
pgpEncryptByteArray.setKeyUserid(keyUserid);
+ pgpEncryptByteArray.setProvider(getProvider());
PGPDataFormat pgpDecryptByteArray = new PGPDataFormat();
pgpDecryptByteArray.setEncryptionKeyRing(getSecKeyRing());
pgpDecryptByteArray.setKeyUserid(keyUserid);
pgpDecryptByteArray.setPassword(keyPassword);
+ pgpDecryptByteArray.setProvider(getProvider());
from("direct:key-ring-byte-array").marshal(pgpEncryptByteArray).to("mock:encrypted").unmarshal(pgpDecryptByteArray)
.to("mock:unencrypted");
@@ -161,12 +171,14 @@ public class PGPDataFormatTest extends AbstractPGPDataFormatTest {
pgpSignAndEncryptByteArray.setSignatureKeyRing(getSecKeyRing());
pgpSignAndEncryptByteArray.setSignatureKeyUserid(keyUserid);
pgpSignAndEncryptByteArray.setSignaturePassword(keyPassword);
+ pgpSignAndEncryptByteArray.setProvider(getProvider());
PGPDataFormat pgpVerifyAndDecryptByteArray = new PGPDataFormat();
pgpVerifyAndDecryptByteArray.setKeyUserid(keyUserid);
pgpVerifyAndDecryptByteArray.setPassword(keyPassword);
pgpVerifyAndDecryptByteArray.setEncryptionKeyRing(getSecKeyRing());
pgpVerifyAndDecryptByteArray.setSignatureKeyUserid(keyUserid);
+ pgpVerifyAndDecryptByteArray.setProvider(getProvider());
from("direct:sign-key-ring-byte-array")
// encryption key ring can also be set as header
http://git-wip-us.apache.org/repos/asf/camel/blob/4bae319a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatWithProvider.java
----------------------------------------------------------------------
diff --git a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatWithProvider.java b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatWithProvider.java
new file mode 100644
index 0000000..12621c1
--- /dev/null
+++ b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatWithProvider.java
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.converter.crypto;
+
+public class PGPDataFormatWithProvider extends PGPDataFormatTest {
+
+ protected String getProvider() {
+ return "BC"; //"IAIK";
+ }
+
+}
[2/2] git commit: CAMEL-6837: PGP Data Format:allow other JCE
providers than BC. Thanks to Franz Forsthofer for the patch.
Posted by da...@apache.org.
CAMEL-6837: PGP Data Format:allow other JCE providers than BC. Thanks to Franz Forsthofer for the patch.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/77b27f8d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/77b27f8d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/77b27f8d
Branch: refs/heads/camel-2.12.x
Commit: 77b27f8d41473ef2e529fda5d85113b82934b680
Parents: e8288db
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Oct 11 15:22:25 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Oct 11 15:22:39 2013 +0200
----------------------------------------------------------------------
.../camel/model/dataformat/PGPDataFormat.java | 13 +++
.../camel/converter/crypto/PGPDataFormat.java | 88 +++++++++++++-------
.../converter/crypto/PGPDataFormatUtil.java | 20 ++---
.../converter/crypto/PGPDataFormatTest.java | 12 +++
.../crypto/PGPDataFormatWithProvider.java | 25 ++++++
5 files changed, 120 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/77b27f8d/camel-core/src/main/java/org/apache/camel/model/dataformat/PGPDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/PGPDataFormat.java b/camel-core/src/main/java/org/apache/camel/model/dataformat/PGPDataFormat.java
index 6f9fa26..39e9869 100644
--- a/camel-core/src/main/java/org/apache/camel/model/dataformat/PGPDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/PGPDataFormat.java
@@ -42,6 +42,8 @@ public class PGPDataFormat extends DataFormatDefinition {
private Boolean armored;
@XmlAttribute
private Boolean integrity;
+ @XmlAttribute
+ private String provider;
public PGPDataFormat() {
super("pgp");
@@ -64,6 +66,9 @@ public class PGPDataFormat extends DataFormatDefinition {
if (integrity != null) {
setProperty(camelContext, dataFormat, "integrity", integrity);
}
+ if (provider != null) {
+ setProperty(camelContext, dataFormat, "provider", provider);
+ }
}
public Boolean getArmored() {
@@ -105,4 +110,12 @@ public class PGPDataFormat extends DataFormatDefinition {
public void setPassword(String password) {
this.password = password;
}
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/77b27f8d/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 d0d3730..eab0e71 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
@@ -30,6 +30,7 @@ import java.util.Date;
import org.apache.camel.Exchange;
import org.apache.camel.spi.DataFormat;
+import org.apache.camel.support.ServiceSupport;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
@@ -65,12 +66,15 @@ 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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * <code>PGPDataFormat</code> uses the <a href="http://www.bouncycastle.org/java.htm">bouncy castle</a>
- * libraries to enable encryption and decryption in the PGP format.
+ * <code>PGPDataFormat</code> uses the <a
+ * href="http://www.bouncycastle.org/java.htm">bouncy castle</a> libraries to
+ * enable encryption and decryption in the PGP format.
*/
-public class PGPDataFormat implements DataFormat {
+public class PGPDataFormat extends ServiceSupport implements DataFormat {
public static final String KEY_FILE_NAME = "CamelPGPDataFormatKeyFileName";
public static final String ENCRYPTION_KEY_RING = "CamelPGPDataFormatEncryptionKeyRing";
@@ -81,8 +85,14 @@ public class PGPDataFormat implements DataFormat {
public static final String SIGNATURE_KEY_USERID = "CamelPGPDataFormatSignatureKeyUserid";
public static final String SIGNATURE_KEY_PASSWORD = "CamelPGPDataFormatSignatureKeyPassword";
+ private static final Logger LOG = LoggerFactory.getLogger(PGPDataFormat.class);
+
+ private static final String BC = "BC";
private static final int BUFFER_SIZE = 16 * 1024;
+ // Java Cryptography Extension provider, default is Bouncy Castle
+ private String provider = BC;
+
// encryption / decryption key info (required)
private String keyUserid;
private String password;
@@ -94,30 +104,27 @@ public class PGPDataFormat implements DataFormat {
private String signatureKeyUserid;
private String signaturePassword;
private String signatureKeyFileName;
- // alternatively to the sigknature key file name you can specify the signature key ring as byte array
+ // alternatively to the signature key file name you can specify the signature key ring as byte array
private byte[] signatureKeyRing;
private boolean armored;
private boolean integrity = true;
public PGPDataFormat() {
- if (Security.getProvider("BC") == null) {
- Security.addProvider(new BouncyCastleProvider());
- }
}
-
+
protected String findKeyFileName(Exchange exchange) {
return exchange.getIn().getHeader(KEY_FILE_NAME, getKeyFileName(), String.class);
}
-
+
protected byte[] findEncryptionKeyRing(Exchange exchange) {
return exchange.getIn().getHeader(ENCRYPTION_KEY_RING, getEncryptionKeyRing(), byte[].class);
}
-
+
protected String findKeyUserid(Exchange exchange) {
return exchange.getIn().getHeader(KEY_USERID, getKeyUserid(), String.class);
}
-
+
protected String findKeyPassword(Exchange exchange) {
return exchange.getIn().getHeader(KEY_PASSWORD, getPassword(), String.class);
}
@@ -125,7 +132,7 @@ public class PGPDataFormat implements DataFormat {
protected String findSignatureKeyFileName(Exchange exchange) {
return exchange.getIn().getHeader(SIGNATURE_KEY_FILE_NAME, getSignatureKeyFileName(), String.class);
}
-
+
protected byte[] findSignatureKeyRing(Exchange exchange) {
return exchange.getIn().getHeader(SIGNATURE_KEY_RING, getSignatureKeyRing(), byte[].class);
}
@@ -139,7 +146,8 @@ public class PGPDataFormat implements DataFormat {
}
public void marshal(Exchange exchange, Object graph, OutputStream outputStream) throws Exception {
- PGPPublicKey key = PGPDataFormatUtil.findPublicKey(exchange.getContext(), findKeyFileName(exchange), findEncryptionKeyRing(exchange), findKeyUserid(exchange), true);
+ PGPPublicKey key = PGPDataFormatUtil.findPublicKey(exchange.getContext(), findKeyFileName(exchange),
+ findEncryptionKeyRing(exchange), findKeyUserid(exchange), true);
if (key == null) {
throw new IllegalArgumentException("Public key is null, cannot proceed");
}
@@ -150,10 +158,8 @@ public class PGPDataFormat implements DataFormat {
outputStream = new ArmoredOutputStream(outputStream);
}
- PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.CAST5).
- setWithIntegrityPacket(integrity).
- setSecureRandom(new SecureRandom()).
- setProvider("BC"));
+ PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.CAST5)
+ .setWithIntegrityPacket(integrity).setSecureRandom(new SecureRandom()).setProvider(getProvider()));
encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(key));
OutputStream encOut = encGen.open(outputStream, new byte[BUFFER_SIZE]);
@@ -190,8 +196,8 @@ public class PGPDataFormat implements DataFormat {
}
}
- protected PGPSignatureGenerator createSignatureGenerator(Exchange exchange, OutputStream out)
- throws IOException, PGPException, NoSuchProviderException, NoSuchAlgorithmException {
+ protected PGPSignatureGenerator createSignatureGenerator(Exchange exchange, OutputStream out) throws IOException, PGPException,
+ NoSuchProviderException, NoSuchAlgorithmException {
String sigKeyFileName = findSignatureKeyFileName(exchange);
String sigKeyUserid = findSignatureKeyUserid(exchange);
@@ -202,12 +208,13 @@ public class PGPDataFormat implements DataFormat {
return null;
}
- PGPSecretKey sigSecretKey = PGPDataFormatUtil.findSecretKey(exchange.getContext(), sigKeyFileName, sigKeyRing, sigKeyPassword);
+ PGPSecretKey sigSecretKey = PGPDataFormatUtil.findSecretKey(exchange.getContext(), sigKeyFileName, sigKeyRing, sigKeyPassword, getProvider());
if (sigSecretKey == null) {
throw new IllegalArgumentException("Signature secret key is null, cannot proceed");
}
- PGPPrivateKey sigPrivateKey = sigSecretKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(sigKeyPassword.toCharArray()));
+ PGPPrivateKey sigPrivateKey = sigSecretKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(getProvider()).build(
+ sigKeyPassword.toCharArray()));
if (sigPrivateKey == null) {
throw new IllegalArgumentException("Signature private key is null, cannot proceed");
}
@@ -216,7 +223,8 @@ public class PGPDataFormat implements DataFormat {
spGen.setSignerUserID(false, sigKeyUserid);
int algorithm = sigSecretKey.getPublicKey().getAlgorithm();
- PGPSignatureGenerator sigGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(algorithm, HashAlgorithmTags.SHA1).setProvider("BC"));
+ PGPSignatureGenerator sigGen = new PGPSignatureGenerator(
+ new JcaPGPContentSignerBuilder(algorithm, HashAlgorithmTags.SHA1).setProvider(getProvider()));
sigGen.init(PGPSignature.BINARY_DOCUMENT, sigPrivateKey);
sigGen.setHashedSubpackets(spGen.generate());
sigGen.generateOnePassVersion(false).encode(out);
@@ -228,7 +236,8 @@ public class PGPDataFormat implements DataFormat {
return null;
}
- PGPPrivateKey key = PGPDataFormatUtil.findPrivateKey(exchange.getContext(), findKeyFileName(exchange), findEncryptionKeyRing(exchange), encryptedStream, findKeyPassword(exchange));
+ PGPPrivateKey key = PGPDataFormatUtil.findPrivateKey(exchange.getContext(), findKeyFileName(exchange),
+ findEncryptionKeyRing(exchange), encryptedStream, findKeyPassword(exchange), getProvider());
if (key == null) {
throw new IllegalArgumentException("Private key is null, cannot proceed");
}
@@ -255,7 +264,7 @@ public class PGPDataFormat implements DataFormat {
IOHelper.close(in);
PGPPublicKeyEncryptedData pbe = (PGPPublicKeyEncryptedData) enc.get(0);
- InputStream encData = pbe.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(key));
+ InputStream encData = pbe.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider(getProvider()).build(key));
pgpFactory = new PGPObjectFactory(encData);
PGPCompressedData comData = (PGPCompressedData) pgpFactory.nextObject();
@@ -291,16 +300,17 @@ public class PGPDataFormat implements DataFormat {
return answer;
}
- protected PGPOnePassSignature getSignature(Exchange exchange, PGPOnePassSignatureList signatureList)
- throws IOException, PGPException, NoSuchProviderException {
+ protected PGPOnePassSignature getSignature(Exchange exchange, PGPOnePassSignatureList signatureList) throws IOException, PGPException,
+ NoSuchProviderException {
- PGPPublicKey sigPublicKey = PGPDataFormatUtil.findPublicKey(exchange.getContext(), findSignatureKeyFileName(exchange), findSignatureKeyRing(exchange), findSignatureKeyUserid(exchange), false);
+ PGPPublicKey sigPublicKey = PGPDataFormatUtil.findPublicKey(exchange.getContext(), findSignatureKeyFileName(exchange),
+ findSignatureKeyRing(exchange), findSignatureKeyUserid(exchange), false);
if (sigPublicKey == null) {
throw new IllegalArgumentException("Signature public key is null, cannot proceed");
}
PGPOnePassSignature signature = signatureList.get(0);
- signature.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), sigPublicKey);
+ signature.init(new JcaPGPContentVerifierBuilderProvider().setProvider(getProvider()), sigPublicKey);
return signature;
}
@@ -408,4 +418,26 @@ public class PGPDataFormat implements DataFormat {
this.signatureKeyRing = signatureKeyRing;
}
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ if (Security.getProvider(BC) == null && BC.equals(getProvider())) {
+ LOG.debug("Adding BouncyCastleProvider as security provider");
+ Security.addProvider(new BouncyCastleProvider());
+ } else {
+ LOG.debug("Using custom provider {} which is expected to be enlisted manually.", getProvider());
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ // noop
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/77b27f8d/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 aa4b9c7..1dfa33a 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
@@ -125,23 +125,23 @@ public final class PGPDataFormatUtil {
public static PGPPrivateKey findPrivateKey(CamelContext context, String keychainFilename, InputStream encryptedInput, String passphrase)
throws IOException, PGPException, NoSuchProviderException {
- return findPrivateKey(context, keychainFilename, null, encryptedInput, passphrase);
+ return findPrivateKey(context, keychainFilename, null, encryptedInput, passphrase, "BC");
}
public static PGPPrivateKey findPrivateKey(CamelContext context, String keychainFilename, byte[] secKeyRing,
- InputStream encryptedInput, String passphrase) throws IOException, PGPException, NoSuchProviderException {
+ InputStream encryptedInput, String passphrase, String provider) throws IOException, PGPException, NoSuchProviderException {
InputStream keyChainInputStream = determineKeyRingInputStream(context, keychainFilename, secKeyRing, true);
PGPPrivateKey privKey = null;
try {
- privKey = findPrivateKey(keyChainInputStream, encryptedInput, passphrase);
+ privKey = findPrivateKey(keyChainInputStream, encryptedInput, passphrase, provider);
} finally {
IOHelper.close(keyChainInputStream);
}
return privKey;
}
- private static PGPPrivateKey findPrivateKey(InputStream keyringInput, InputStream encryptedInput, String passphrase) throws IOException,
+ private static PGPPrivateKey findPrivateKey(InputStream keyringInput, InputStream encryptedInput, String passphrase, String provider) throws IOException,
PGPException, NoSuchProviderException {
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(keyringInput));
PGPObjectFactory factory = new PGPObjectFactory(PGPUtil.getDecoderStream(encryptedInput));
@@ -163,7 +163,7 @@ public final class PGPDataFormatUtil {
encryptedData = (PGPPublicKeyEncryptedData) encryptedDataObjects.next();
PGPSecretKey pgpSecKey = pgpSec.getSecretKey(encryptedData.getKeyID());
if (pgpSecKey != null) {
- privateKey = pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(passphrase.toCharArray()));
+ privateKey = pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(provider).build(passphrase.toCharArray()));
}
}
if (privateKey == null && pgpSec.size() > 0 && encryptedData != null) {
@@ -174,23 +174,23 @@ public final class PGPDataFormatUtil {
public static PGPSecretKey findSecretKey(CamelContext context, String keychainFilename, String passphrase)
throws IOException, PGPException, NoSuchProviderException {
- return findSecretKey(context, keychainFilename, null, passphrase);
+ return findSecretKey(context, keychainFilename, null, passphrase, "BC");
}
- public static PGPSecretKey findSecretKey(CamelContext context, String keychainFilename, byte[] secKeyRing, String passphrase)
+ public static PGPSecretKey findSecretKey(CamelContext context, String keychainFilename, byte[] secKeyRing, String passphrase, String provider)
throws IOException, PGPException, NoSuchProviderException {
InputStream keyChainInputStream = determineKeyRingInputStream(context, keychainFilename, secKeyRing, false);
PGPSecretKey secKey = null;
try {
- secKey = findSecretKey(keyChainInputStream, passphrase);
+ secKey = findSecretKey(keyChainInputStream, passphrase, provider);
} finally {
IOHelper.close(keyChainInputStream);
}
return secKey;
}
- private static PGPSecretKey findSecretKey(InputStream keyringInput, String passphrase) throws IOException, PGPException, NoSuchProviderException {
+ private static PGPSecretKey findSecretKey(InputStream keyringInput, String passphrase, String provider) throws IOException, PGPException, NoSuchProviderException {
PGPSecretKey pgpSecKey = null;
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(keyringInput));
for (Iterator<?> i = pgpSec.getKeyRings(); i.hasNext() && pgpSecKey == null;) {
@@ -198,7 +198,7 @@ public final class PGPDataFormatUtil {
if (data instanceof PGPSecretKeyRing) {
PGPSecretKeyRing keyring = (PGPSecretKeyRing) data;
PGPSecretKey secKey = keyring.getSecretKey();
- PGPPrivateKey privateKey = secKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(passphrase.toCharArray()));
+ PGPPrivateKey privateKey = secKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(provider).build(passphrase.toCharArray()));
if (privateKey != null) {
pgpSecKey = secKey;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/77b27f8d/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatTest.java
----------------------------------------------------------------------
diff --git a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatTest.java b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatTest.java
index 8597d12..8424ac4 100644
--- a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatTest.java
+++ b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatTest.java
@@ -45,6 +45,10 @@ public class PGPDataFormatTest extends AbstractPGPDataFormatTest {
protected String getKeyPassword() {
return "sdude";
}
+
+ protected String getProvider() {
+ return "BC";
+ }
@Test
public void testEncryption() throws Exception {
@@ -100,11 +104,13 @@ public class PGPDataFormatTest extends AbstractPGPDataFormatTest {
PGPDataFormat pgpEncrypt = new PGPDataFormat();
pgpEncrypt.setKeyFileName(keyFileName);
pgpEncrypt.setKeyUserid(keyUserid);
+ pgpEncrypt.setProvider(getProvider());
PGPDataFormat pgpDecrypt = new PGPDataFormat();
pgpDecrypt.setKeyFileName(keyFileNameSec);
pgpDecrypt.setKeyUserid(keyUserid);
pgpDecrypt.setPassword(keyPassword);
+ pgpDecrypt.setProvider(getProvider());
from("direct:inline2")
.marshal(pgpEncrypt)
@@ -126,6 +132,7 @@ public class PGPDataFormatTest extends AbstractPGPDataFormatTest {
pgpSignAndEncrypt.setSignatureKeyFileName(keyFileNameSec);
pgpSignAndEncrypt.setSignatureKeyUserid(keyUserid);
pgpSignAndEncrypt.setSignaturePassword(keyPassword);
+ pgpSignAndEncrypt.setProvider(getProvider());
PGPDataFormat pgpVerifyAndDecrypt = new PGPDataFormat();
pgpVerifyAndDecrypt.setKeyFileName(keyFileNameSec);
@@ -133,6 +140,7 @@ public class PGPDataFormatTest extends AbstractPGPDataFormatTest {
pgpVerifyAndDecrypt.setPassword(keyPassword);
pgpVerifyAndDecrypt.setSignatureKeyFileName(keyFileName);
pgpVerifyAndDecrypt.setSignatureKeyUserid(keyUserid);
+ pgpVerifyAndDecrypt.setProvider(getProvider());
from("direct:inline-sign")
.marshal(pgpSignAndEncrypt)
@@ -145,11 +153,13 @@ public class PGPDataFormatTest extends AbstractPGPDataFormatTest {
PGPDataFormat pgpEncryptByteArray = new PGPDataFormat();
pgpEncryptByteArray.setEncryptionKeyRing(getPublicKeyRing());
pgpEncryptByteArray.setKeyUserid(keyUserid);
+ pgpEncryptByteArray.setProvider(getProvider());
PGPDataFormat pgpDecryptByteArray = new PGPDataFormat();
pgpDecryptByteArray.setEncryptionKeyRing(getSecKeyRing());
pgpDecryptByteArray.setKeyUserid(keyUserid);
pgpDecryptByteArray.setPassword(keyPassword);
+ pgpDecryptByteArray.setProvider(getProvider());
from("direct:key-ring-byte-array").marshal(pgpEncryptByteArray).to("mock:encrypted").unmarshal(pgpDecryptByteArray)
.to("mock:unencrypted");
@@ -161,12 +171,14 @@ public class PGPDataFormatTest extends AbstractPGPDataFormatTest {
pgpSignAndEncryptByteArray.setSignatureKeyRing(getSecKeyRing());
pgpSignAndEncryptByteArray.setSignatureKeyUserid(keyUserid);
pgpSignAndEncryptByteArray.setSignaturePassword(keyPassword);
+ pgpSignAndEncryptByteArray.setProvider(getProvider());
PGPDataFormat pgpVerifyAndDecryptByteArray = new PGPDataFormat();
pgpVerifyAndDecryptByteArray.setKeyUserid(keyUserid);
pgpVerifyAndDecryptByteArray.setPassword(keyPassword);
pgpVerifyAndDecryptByteArray.setEncryptionKeyRing(getSecKeyRing());
pgpVerifyAndDecryptByteArray.setSignatureKeyUserid(keyUserid);
+ pgpVerifyAndDecryptByteArray.setProvider(getProvider());
from("direct:sign-key-ring-byte-array")
// encryption key ring can also be set as header
http://git-wip-us.apache.org/repos/asf/camel/blob/77b27f8d/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatWithProvider.java
----------------------------------------------------------------------
diff --git a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatWithProvider.java b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatWithProvider.java
new file mode 100644
index 0000000..12621c1
--- /dev/null
+++ b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/PGPDataFormatWithProvider.java
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.converter.crypto;
+
+public class PGPDataFormatWithProvider extends PGPDataFormatTest {
+
+ protected String getProvider() {
+ return "BC"; //"IAIK";
+ }
+
+}