This is an automated email from the ASF dual-hosted git repository. coheigea pushed a commit to branch camel-2.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0ff13f9ee1a50f37740fda4dd15fe3ab160f35f2 Author: Colm O hEigeartaigh <[email protected]> AuthorDate: Thu Apr 25 14:36:13 2019 +0100 Adding more RPK tests --- .../java/org/apache/camel/coap/CoAPEndpoint.java | 4 +- .../apache/camel/coap/CoAPComponentTLSTest.java | 49 ++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java index 926bc24..add9aab 100644 --- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java +++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java @@ -42,6 +42,7 @@ import org.apache.camel.util.jsse.KeyStoreParameters; import org.eclipse.californium.core.CoapServer; import org.eclipse.californium.scandium.DTLSConnector; import org.eclipse.californium.scandium.config.DtlsConnectorConfig; +import org.eclipse.californium.scandium.dtls.CertificateType; import org.eclipse.californium.scandium.dtls.rpkstore.TrustedRpkStore; /** @@ -365,7 +366,7 @@ public class CoAPEndpoint extends DefaultEndpoint { throw new IllegalStateException("A password must be configured to use TLS"); } if ((isClientAuthenticationRequired() || isClientAuthenticationWanted()) - && getTruststore() == null) { + && (getTruststore() == null && publicKey == null)) { throw new IllegalStateException("A truststore must be configured to support TLS client authentication"); } @@ -390,6 +391,7 @@ public class CoAPEndpoint extends DefaultEndpoint { builder.setTrustStore(certs); } if (trustedRpkStore != null) { + builder.setTrustCertificateTypes(CertificateType.RAW_PUBLIC_KEY); builder.setRpkTrustStore(trustedRpkStore); } } catch (GeneralSecurityException e) { diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTLSTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTLSTest.java index 146fd1d..b9d6b70 100644 --- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTLSTest.java +++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTLSTest.java @@ -43,6 +43,7 @@ public class CoAPComponentTLSTest extends CamelTestSupport { protected static final int PORT3 = AvailablePortFinder.getNextAvailable(); protected static final int PORT4 = AvailablePortFinder.getNextAvailable(); protected static final int PORT5 = AvailablePortFinder.getNextAvailable(); + protected static final int PORT6 = AvailablePortFinder.getNextAvailable(); @Produce(uri = "direct:start") protected ProducerTemplate sender; @@ -126,6 +127,33 @@ public class CoAPComponentTLSTest extends CamelTestSupport { assertMockEndpointsSatisfied(); } + @Test + public void testRawPublicKeyNoTruststore() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(0); + sendBodyAndHeader("direct:rpknotruststore", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST"); + assertMockEndpointsSatisfied(); + } + + @Test + public void testRawPublicKeyFailedTrust() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(0); + sendBodyAndHeader("direct:rpkfailedtrust", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST"); + assertMockEndpointsSatisfied(); + } + + @Test + public void testRawPublicKeyClientAuth() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMinimumMessageCount(1); + mock.expectedBodiesReceived("Hello Camel CoAP"); + mock.expectedHeaderReceived(Exchange.CONTENT_TYPE, MediaTypeRegistry.toString(MediaTypeRegistry.APPLICATION_OCTET_STREAM)); + mock.expectedHeaderReceived(CoAPConstants.COAP_RESPONSE_CODE, CoAP.ResponseCode.CONTENT.toString()); + sendBodyAndHeader("direct:rpkclientauth", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST"); + assertMockEndpointsSatisfied(); + } + @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); @@ -157,6 +185,7 @@ public class CoAPComponentTLSTest extends CamelTestSupport { truststoreParameters2.setPassword("storepass"); TrustedRpkStore trustedRpkStore = id -> { return true;}; + TrustedRpkStore failedTrustedRpkStore = id -> { return false;}; registry.bind("keyParams", keystoreParameters); registry.bind("keyParams2", keystoreParameters2); @@ -166,6 +195,7 @@ public class CoAPComponentTLSTest extends CamelTestSupport { registry.bind("privateKey", privateKey); registry.bind("publicKey", publicKey); registry.bind("trustedRpkStore", trustedRpkStore); + registry.bind("failedTrustedRpkStore", failedTrustedRpkStore); return registry; } @@ -176,6 +206,7 @@ public class CoAPComponentTLSTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { + fromF("coaps://localhost:%d/TestResource?alias=service&password=security&" + "keyStoreParameters=#keyParams", PORT) .transform(body().prepend("Hello ")); @@ -197,6 +228,11 @@ public class CoAPComponentTLSTest extends CamelTestSupport { + "privateKey=#privateKey&publicKey=#publicKey", PORT5) .transform(body().prepend("Hello ")); + fromF("coaps://localhost:%d/TestResource?alias=service&password=security&" + + "privateKey=#privateKey&publicKey=#publicKey&clientAuthentication=REQUIRE&" + + "trustedRpkStore=#trustedRpkStore", PORT6) + .transform(body().prepend("Hello ")); + from("direct:start") .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams", PORT) .to("mock:result"); @@ -231,6 +267,19 @@ public class CoAPComponentTLSTest extends CamelTestSupport { from("direct:rpk") .toF("coaps://localhost:%d/TestResource?trustedRpkStore=#trustedRpkStore", PORT5) .to("mock:result"); + + from("direct:rpknotruststore") + .toF("coaps://localhost:%d/TestResource", PORT5) + .to("mock:result"); + + from("direct:rpkfailedtrust") + .toF("coaps://localhost:%d/TestResource?trustedRpkStore=#failedTrustedRpkStore", PORT5) + .to("mock:result"); + + from("direct:rpkclientauth") + .toF("coaps://localhost:%d/TestResource?trustedRpkStore=#trustedRpkStore&" + + "privateKey=#privateKey&publicKey=#publicKey", PORT6) + .to("mock:result"); } }; }
