You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by co...@apache.org on 2019/04/25 13:39:22 UTC

[camel] branch CAMEL-13402 updated: Adding more RPK tests

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch CAMEL-13402
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/CAMEL-13402 by this push:
     new 017f059  Adding more RPK tests
017f059 is described below

commit 017f059b944031dece3672380f0f95afa743f6a6
Author: Colm O hEigeartaigh <co...@apache.org>
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 3fc76f9..b84a312 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.support.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 aa64a27..a7389cb 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
@@ -40,6 +40,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();
 
     @Test
     public void testSuccessfulCall() throws Exception {
@@ -120,6 +121,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 RouteBuilder createRouteBuilder() throws Exception {
         KeyStoreParameters keystoreParameters = new KeyStoreParameters();
@@ -149,6 +177,7 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         truststoreParameters2.setPassword("storepass");
 
         TrustedRpkStore trustedRpkStore = id -> { return true;};
+        TrustedRpkStore failedTrustedRpkStore = id -> { return false;};
 
         context.getRegistry().bind("keyParams", keystoreParameters);
         context.getRegistry().bind("keyParams2", keystoreParameters2);
@@ -158,10 +187,12 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         context.getRegistry().bind("privateKey", privateKey);
         context.getRegistry().bind("publicKey", publicKey);
         context.getRegistry().bind("trustedRpkStore", trustedRpkStore);
+        context.getRegistry().bind("failedTrustedRpkStore", failedTrustedRpkStore);
 
         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 "));
@@ -183,6 +214,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");
@@ -217,6 +253,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");
             }
         };
     }