You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/10/24 13:31:40 UTC
[camel] 01/02: CAMEL-12897 - PGP Decryption in XML DSL not working
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit c8a560467d7d9e90672dd43f409315df7a8889ca
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Oct 24 15:07:58 2018 +0200
CAMEL-12897 - PGP Decryption in XML DSL not working
---
.../camel/converter/crypto/PGPDataFormatUtil.java | 8 ++++
...va => SpringPGPDataFormatNoPassPhraseTest.java} | 2 +-
.../converter/crypto/SpringPGPDataFormatTest.java | 7 +---
.../crypto/SpringPGPDataFormatNoPassPhraseTest.xml | 43 +++++++++++++++++++++
.../camel/component/crypto/camel-private.pgp | Bin 0 -> 2547 bytes
.../apache/camel/component/crypto/camel-public.pgp | Bin 0 -> 1245 bytes
6 files changed, 53 insertions(+), 7 deletions(-)
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 1fa1727..c515892 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
@@ -162,6 +162,14 @@ public final class PGPDataFormatUtil {
return privateKey;
}
}
+ if (passphrase == null && passphraseAccessor == null) {
+ passphrase = "";
+ PGPPrivateKey privateKey = secKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(provider)
+ .build(passphrase.toCharArray()));
+ if (privateKey != null) {
+ return privateKey;
+ }
+ }
}
}
diff --git a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringPGPDataFormatTest.java b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringPGPDataFormatNoPassPhraseTest.java
similarity index 94%
copy from components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringPGPDataFormatTest.java
copy to components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringPGPDataFormatNoPassPhraseTest.java
index 1c8d6fa..838cb1b 100644
--- a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringPGPDataFormatTest.java
+++ b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringPGPDataFormatNoPassPhraseTest.java
@@ -20,7 +20,7 @@ import org.apache.camel.CamelContext;
import org.apache.camel.spring.SpringCamelContext;
import org.junit.Test;
-public class SpringPGPDataFormatTest extends AbstractPGPDataFormatTest {
+public class SpringPGPDataFormatNoPassPhraseTest extends AbstractPGPDataFormatTest {
protected CamelContext createCamelContext() throws Exception {
return SpringCamelContext.springCamelContext("/org/apache/camel/component/crypto/SpringPGPDataFormatTest.xml");
diff --git a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringPGPDataFormatTest.java b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringPGPDataFormatTest.java
index 1c8d6fa..c311feb 100644
--- a/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringPGPDataFormatTest.java
+++ b/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringPGPDataFormatTest.java
@@ -23,17 +23,12 @@ import org.junit.Test;
public class SpringPGPDataFormatTest extends AbstractPGPDataFormatTest {
protected CamelContext createCamelContext() throws Exception {
- return SpringCamelContext.springCamelContext("/org/apache/camel/component/crypto/SpringPGPDataFormatTest.xml");
+ return SpringCamelContext.springCamelContext("/org/apache/camel/component/crypto/SpringPGPDataFormatNoPassPhraseTest.xml");
}
@Test
public void testEncryption() throws Exception {
doRoundTripEncryptionTests("direct:inline");
}
-
- @Test
- public void testEncryptionWithKeyRingByteArray() throws Exception {
- doRoundTripEncryptionTests("direct:pgp-key-ring-byte-array");
- }
}
diff --git a/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringPGPDataFormatNoPassPhraseTest.xml b/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringPGPDataFormatNoPassPhraseTest.xml
new file mode 100644
index 0000000..52917eb
--- /dev/null
+++ b/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringPGPDataFormatNoPassPhraseTest.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <!-- START SNIPPET: pgp-xml-basic -->
+ <dataFormats>
+ <!-- will load the file from classpath by default, but you can prefix with file: to load from file system -->
+ <pgp id="encrypt" keyFileName="org/apache/camel/component/crypto/camel-public.pgp" keyUserid="CamelPGPTest"/>
+ <pgp id="decrypt" keyFileName="org/apache/camel/component/crypto/camel-private.pgp"/>
+ </dataFormats>
+
+ <route>
+ <from uri="direct:inline"/>
+ <marshal ref="encrypt"/>
+ <to uri="mock:encrypted"/>
+ <unmarshal ref="decrypt"/>
+ <to uri="mock:unencrypted"/>
+ </route>
+
+ </camelContext>
+</beans>
\ No newline at end of file
diff --git a/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/camel-private.pgp b/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/camel-private.pgp
new file mode 100644
index 0000000..6f2a010
Binary files /dev/null and b/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/camel-private.pgp differ
diff --git a/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/camel-public.pgp b/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/camel-public.pgp
new file mode 100644
index 0000000..e50ec8d
Binary files /dev/null and b/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/camel-public.pgp differ