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/03 12:54:30 UTC
[2/5] git commit: CAMEL-6817: Throw PGPException instead of NPE.
Thanks to Milan Baran for the patch.
CAMEL-6817: Throw PGPException instead of NPE. Thanks to Milan Baran 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/44f8c1b9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/44f8c1b9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/44f8c1b9
Branch: refs/heads/camel-2.12.x
Commit: 44f8c1b98d457ed63390af081e5295a28b1bc61f
Parents: 7066fd5
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Oct 3 12:18:43 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Oct 3 12:19:02 2013 +0200
----------------------------------------------------------------------
.../camel/converter/crypto/PGPDataFormatUtil.java | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/44f8c1b9/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 0916075..aa4b9c7 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
@@ -16,8 +16,6 @@
*/
package org.apache.camel.converter.crypto;
-
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -149,6 +147,9 @@ public final class PGPDataFormatUtil {
PGPObjectFactory factory = new PGPObjectFactory(PGPUtil.getDecoderStream(encryptedInput));
PGPEncryptedDataList enc;
Object o = factory.nextObject();
+ if (o == null) {
+ throw new PGPException("Provided input is not encrypted.");
+ }
if (o instanceof PGPEncryptedDataList) {
enc = (PGPEncryptedDataList) o;
} else {
@@ -157,11 +158,16 @@ public final class PGPDataFormatUtil {
encryptedInput.reset(); // nextObject() method reads from the InputStream, so rewind it!
Iterator<?> encryptedDataObjects = enc.getEncryptedDataObjects();
PGPPrivateKey privateKey = null;
- PGPPublicKeyEncryptedData encryptedData;
+ PGPPublicKeyEncryptedData encryptedData = null;
while (privateKey == null && encryptedDataObjects.hasNext()) {
encryptedData = (PGPPublicKeyEncryptedData) encryptedDataObjects.next();
PGPSecretKey pgpSecKey = pgpSec.getSecretKey(encryptedData.getKeyID());
- privateKey = pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(passphrase.toCharArray()));
+ if (pgpSecKey != null) {
+ privateKey = pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(passphrase.toCharArray()));
+ }
+ }
+ if (privateKey == null && pgpSec.size() > 0 && encryptedData != null) {
+ throw new PGPException("Provided input is encrypted with unknown pair of keys.");
}
return privateKey;
}