Repository: camel Updated Branches: refs/heads/master 11423ecbe -> ad77114ad
Add the ability to use Camel's KeyStoreParameters Object with the Camel Crypto (Signature) component Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ad77114a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ad77114a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ad77114a Branch: refs/heads/master Commit: ad77114ad91ccf5d0e665e7d93e78a320444b095 Parents: 11423ec Author: Colm O hEigeartaigh <cohei...@apache.org> Authored: Tue Dec 9 12:55:17 2014 +0000 Committer: Colm O hEigeartaigh <cohei...@apache.org> Committed: Tue Dec 9 12:56:51 2014 +0000 ---------------------------------------------------------------------- .../crypto/DigitalSignatureConfiguration.java | 10 ++++++++++ .../camel/component/crypto/SignatureTests.java | 18 ++++++++++++++++++ .../component/crypto/SpringSignatureTests.xml | 12 ++++++++++++ 3 files changed, 40 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/ad77114a/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java b/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java index b7a1873..554db3b 100644 --- a/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java +++ b/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.crypto; +import java.io.IOException; +import java.security.GeneralSecurityException; import java.security.KeyStore; import java.security.PrivateKey; import java.security.PublicKey; @@ -26,6 +28,7 @@ import java.security.cert.Certificate; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; import org.apache.camel.RuntimeCamelException; +import org.apache.camel.util.jsse.KeyStoreParameters; public class DigitalSignatureConfiguration implements Cloneable, CamelContextAware { @@ -297,6 +300,13 @@ public class DigitalSignatureConfiguration implements Cloneable, CamelContextAwa public void setPassword(char[] password) { this.password = password; } + + public void setKeyStoreParameters(KeyStoreParameters parameters) + throws GeneralSecurityException, IOException { + if (parameters != null) { + this.keystore = parameters.createKeyStore(); + } + } /** * Get the SecureRandom used to initialize the Signature service http://git-wip-us.apache.org/repos/asf/camel/blob/ad77114a/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java ---------------------------------------------------------------------- diff --git a/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java b/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java index 8991695..4d8148f 100644 --- a/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java +++ b/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java @@ -37,6 +37,7 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.impl.JndiRegistry; import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.util.jsse.KeyStoreParameters; import org.junit.Before; import org.junit.Test; @@ -54,6 +55,10 @@ public class SignatureTests extends CamelTestSupport { JndiRegistry registry = super.createRegistry(); KeyStore keystore = loadKeystore(); Certificate cert = keystore.getCertificate("bob"); + KeyStoreParameters keystoreParameters = new KeyStoreParameters(); + keystoreParameters.setPassword("letmein"); + keystoreParameters.setResource("./ks.keystore"); + registry.bind("signatureParams", keystoreParameters); registry.bind("keystore", keystore); registry.bind("myPublicKey", cert.getPublicKey()); registry.bind("myCert", cert); @@ -134,6 +139,12 @@ public class SignatureTests extends CamelTestSupport { } }, new RouteBuilder() { public void configure() throws Exception { + // START SNIPPET: keystore + from("direct:keystoreParameters").to("crypto:sign://keyStoreParameters?keyStoreParameters=#signatureParams&alias=bob&password=letmein", "crypto:verify://keyStoreParameters?keyStoreParameters=#signatureParams&alias=bob", "mock:result"); + // END SNIPPET: keystore + } + }, new RouteBuilder() { + public void configure() throws Exception { // START SNIPPET: signature-header from("direct:signature-header").to("crypto:sign://another?privateKey=#myPrivateKey&signatureHeader=AnotherDigitalSignature", "crypto:verify://another?publicKey=#myPublicKey&signatureHeader=AnotherDigitalSignature", "mock:result"); @@ -242,6 +253,13 @@ public class SignatureTests extends CamelTestSupport { } @Test + public void testSetKeystoreParametersInRouteDefinition() throws Exception { + setupMock(); + sendBody("direct:keystoreParameters", payload); + assertMockEndpointsSatisfied(); + } + + @Test public void testSignatureHeaderInRouteDefinition() throws Exception { setupMock(); Exchange signed = getMandatoryEndpoint("direct:signature-header").createExchange(); http://git-wip-us.apache.org/repos/asf/camel/blob/ad77114a/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringSignatureTests.xml ---------------------------------------------------------------------- diff --git a/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringSignatureTests.xml b/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringSignatureTests.xml index 04cef37..057aab1 100644 --- a/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringSignatureTests.xml +++ b/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringSignatureTests.xml @@ -104,6 +104,15 @@ </route> <!-- END SNIPPET: keystore --> + <!-- START SNIPPET: keystoreParameters --> + <route> + <from uri="direct:keystoreParameters"/> + <to uri="crypto:sign://keystoreParameters?keyStoreParameters=#signatureParams&alias=bob&password=letmein" /> + <to uri="crypto:verify://keystoreParameters?keyStoreParameters=#signatureParams&alias=bob" /> + <to uri="mock:result"/> + </route> + <!-- END SNIPPET: keystoreParameters --> + <!-- START SNIPPET: signature-header --> <route> <from uri="direct:signature-header"/> @@ -154,4 +163,7 @@ <bean id="rsaPublicKey" class="org.apache.camel.component.crypto.SpringSignatureTest" factory-method="publicRSAKey"/> <bean id="someRandom" class="org.apache.camel.component.crypto.SpringSignatureTest" factory-method="random"/> + <keyStoreParameters xmlns="http://camel.apache.org/schema/spring" id="signatureParams" + resource="./ks.keystore" password="letmein" /> + </beans>