Updated Branches:
  refs/heads/camel-2.11.x fb5156065 -> 4b92dcb83
  refs/heads/camel-2.12.x 7066fd532 -> 652a05f5d
  refs/heads/master a49053bd7 -> e90d061b2


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/22f26e29
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/22f26e29
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/22f26e29

Branch: refs/heads/master
Commit: 22f26e297ce87a8e2859972389d86c9ffee59932
Parents: a49053b
Author: Claus Ibsen <davscl...@apache.org>
Authored: Thu Oct 3 12:18:43 2013 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Thu Oct 3 12:18:43 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/22f26e29/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;
     }

Reply via email to