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/05/24 19:39:22 UTC

[camel] branch camel-2.x updated (07a2e12 -> 8c58923)

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

coheigea pushed a change to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 07a2e12  [CAMEL-13576]avoid adding cxf message context map into camel exchange
     new 8c4f277  CAMEL-13402 - Updating to Californium 2.0.x
     new 7765e80  Adding initial TLS support
     new 97fd0e7  Avoid writing out Californium.properties
     new a7f884d  Improving TLS configuration
     new cc61165  Adding support for client authentication
     new 8ebae08  Consolidate TLS configuration
     new 0117334  Adding TLS tests
     new 8671e19  Fixing tests
     new 27b5f7f  Adding more CoAP TLS tests
     new 8d6374b  Updating the certs to use the right curves
     new 39538df  Added initial support for raw public keys
     new 0ff13f9  Adding more RPK tests
     new bafb543  Supporting pre-shared keys
     new 189104c  Adding X.509 + PSK tests
     new d4d31ae  Updating the docs
     new 1adf517  Removing some whitespace
     new 33edefe  Doc change
     new 9501988  Cleanup of testcode
     new cfe2e88  CAMEL-13402 - Fixed CS
     new 414f35b  CAMEL-13402 - Fixed Karaf feature after upgrading to Californium 2.x
     new 8c58923  Removing unused import

The 21 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 camel-core/readme.adoc                             |  82 +----
 components/camel-coap/pom.xml                      |   5 +
 .../camel-coap/src/main/docs/coap-component.adoc   |  13 +-
 .../java/org/apache/camel/coap/CoAPComponent.java  |  26 +-
 .../java/org/apache/camel/coap/CoAPEndpoint.java   | 343 ++++++++++++++++++++-
 .../java/org/apache/camel/coap/CoAPProducer.java   |  12 +
 .../org/apache/camel/component/{coap => coaps}     |   0
 .../apache/camel/coap/CoAPComponentTLSTest.java    | 321 +++++++++++++++++++
 .../org/apache/camel/coap/CoAPComponentTest.java   |   4 +-
 .../apache/camel/coap/CoAPMethodRestrictTest.java  |   2 +-
 .../camel/coap/CoAPRestComponentTLSTest.java       | 109 +++++++
 .../apache/camel/coap/CoAPRestComponentTest.java   |   6 +-
 .../camel-coap/src/test/resources/client.jks       | Bin 0 -> 1968 bytes
 .../camel-coap/src/test/resources/selfsigned.jks   | Bin 0 -> 706 bytes
 .../camel-coap/src/test/resources/service.jks      | Bin 0 -> 1969 bytes
 .../camel-coap/src/test/resources/truststore.jks   | Bin 0 -> 582 bytes
 .../camel-coap/src/test/resources/truststore2.jks  | Bin 0 -> 582 bytes
 components/readme.adoc                             |  98 ++++--
 parent/pom.xml                                     |   2 +-
 .../karaf/features/src/main/resources/features.xml |   4 +-
 .../src/main/resources/camel-connector-schema.json |   2 +-
 .../src/main/resources/camel-connector.json        |   4 +-
 22 files changed, 905 insertions(+), 128 deletions(-)
 copy components/camel-coap/src/main/resources/META-INF/services/org/apache/camel/component/{coap => coaps} (100%)
 create mode 100644 components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTLSTest.java
 create mode 100644 components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTLSTest.java
 create mode 100644 components/camel-coap/src/test/resources/client.jks
 create mode 100644 components/camel-coap/src/test/resources/selfsigned.jks
 create mode 100644 components/camel-coap/src/test/resources/service.jks
 create mode 100644 components/camel-coap/src/test/resources/truststore.jks
 create mode 100644 components/camel-coap/src/test/resources/truststore2.jks


[camel] 05/21: Adding support for client authentication

Posted by co...@apache.org.
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 cc61165ee7fc75b5f5fc607b9c2a89fa0bd64add
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Thu Apr 11 13:07:12 2019 +0100

    Adding support for client authentication
---
 .../java/org/apache/camel/coap/CoAPComponent.java  |  3 +-
 .../java/org/apache/camel/coap/CoAPEndpoint.java   | 38 ++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
index 13f0c9b..1a17d94 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
@@ -98,7 +98,8 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
                     throw new IllegalStateException("Error in configuring TLS", e);
                 }
 
-                builder.setClientAuthenticationRequired(false); //TODO
+                builder.setClientAuthenticationRequired(endpoint.isClientAuthenticationRequired());
+                builder.setClientAuthenticationWanted(endpoint.isClientAuthenticationWanted());
 
                 if (endpoint.getConfiguredCipherSuites() != null) {
                     builder.setSupportedCipherSuites(endpoint.getConfiguredCipherSuites());
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 2a3c0ad..e0a0b7e 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
@@ -35,6 +35,7 @@ import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriPath;
+import org.apache.camel.util.jsse.ClientAuthentication;
 import org.apache.camel.util.jsse.KeyStoreParameters;
 import org.eclipse.californium.core.CoapServer;
 
@@ -70,6 +71,8 @@ public class CoAPEndpoint extends DefaultEndpoint {
     private String cipherSuites;
     
     private String[] configuredCipherSuites;
+    
+    private String clientAuthentication;
         
     private CoAPComponent component;
     
@@ -232,6 +235,35 @@ public class CoAPEndpoint extends DefaultEndpoint {
         return configuredCipherSuites;
     }
     
+    
+    /**
+     * Gets the configuration options for server-side client-authentication requirements. The value is
+     * either null or one of NONE, WANT, REQUIRE.
+     */
+    public String getClientAuthentication() {
+        return clientAuthentication;
+    }
+
+    /**
+     * Sets the configuration options for server-side client-authentication requirements.
+     * The value must be one of NONE, WANT, REQUIRE.
+     * 
+     * @param value the desired configuration options or {@code null} to use the defaults
+     */
+    public void setClientAuthentication(String clientAuthentication) {
+        this.clientAuthentication = clientAuthentication;
+    }
+    
+    public boolean isClientAuthenticationRequired() {
+        return clientAuthentication != null 
+            && ClientAuthentication.valueOf(clientAuthentication) == ClientAuthentication.REQUIRE;
+    }
+    
+    public boolean isClientAuthenticationWanted() {
+        return clientAuthentication != null 
+            && ClientAuthentication.valueOf(clientAuthentication) == ClientAuthentication.WANT;
+    }
+    
     public Certificate[] getTrustedCerts() throws KeyStoreException {
         Enumeration<String> aliases = truststore.aliases();
         List<Certificate> trustCerts = new ArrayList<>();
@@ -245,4 +277,10 @@ public class CoAPEndpoint extends DefaultEndpoint {
         
         return trustCerts.toArray(new Certificate[0]);
     }
+
+    /*
+    public DTLSConnector createDTLSConnector() {
+        
+    }
+    */
 }


[camel] 19/21: CAMEL-13402 - Fixed CS

Posted by co...@apache.org.
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 cfe2e8881dc66436f8c88d36f9efbc35eaca2f24
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Apr 30 11:44:52 2019 +0200

    CAMEL-13402 - Fixed CS
---
 .../java/org/apache/camel/coap/CoAPProducer.java   |  2 +-
 .../apache/camel/coap/CoAPComponentTLSTest.java    | 87 ++++++++--------------
 2 files changed, 32 insertions(+), 57 deletions(-)

diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
index 5441481..71766df 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
@@ -95,7 +95,7 @@ public class CoAPProducer extends DefaultProducer {
             client = new CoapClient(uri);
 
             // Configure TLS
-            if (CoAPEndpoint.enableTLS((uri))) {
+            if (CoAPEndpoint.enableTLS(uri)) {
                 DTLSConnector connector = endpoint.createDTLSConnector(null, true);
                 CoapEndpoint.Builder coapBuilder = new CoapEndpoint.Builder();
                 coapBuilder.setConnector(connector);
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 4e1e61a..c2c7bb1 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
@@ -202,10 +202,8 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         keystoreParameters.setPassword("security");
 
         KeyStore keyStore = keystoreParameters.createKeyStore();
-        PrivateKey privateKey =
-            (PrivateKey)keyStore.getKey("service", "security".toCharArray());
-        PublicKey publicKey =
-            keyStore.getCertificate("service").getPublicKey();
+        PrivateKey privateKey = (PrivateKey)keyStore.getKey("service", "security".toCharArray());
+        PublicKey publicKey = keyStore.getCertificate("service").getPublicKey();
 
         KeyStoreParameters keystoreParameters2 = new KeyStoreParameters();
         keystoreParameters2.setResource("selfsigned.jks");
@@ -223,8 +221,12 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         truststoreParameters2.setResource("truststore2.jks");
         truststoreParameters2.setPassword("storepass");
 
-        TrustedRpkStore trustedRpkStore = id -> { return true;};
-        TrustedRpkStore failedTrustedRpkStore = id -> { return false;};
+        TrustedRpkStore trustedRpkStore = id -> {
+            return true;
+        };
+        TrustedRpkStore failedTrustedRpkStore = id -> {
+            return false;
+        };
         KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
         PskStore pskStore = new StaticPskStore("some-identity", keyGenerator.generateKey().getEncoded());
 
@@ -249,87 +251,60 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
             @Override
             public void configure() throws Exception {
 
+                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&" + "keyStoreParameters=#keyParams", PORT).transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&keyStoreParameters=#keyParams", PORT)
-                    .transform(body().prepend("Hello "));
+                fromF("coaps://localhost:%d/TestResource?alias=selfsigned&password=security&" + "keyStoreParameters=#keyParams2", PORT2).transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?alias=selfsigned&password=security&keyStoreParameters=#keyParams2", PORT2)
-                    .transform(body().prepend("Hello "));
+                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&" + "trustStoreParameters=#trustParams&"
+                      + "keyStoreParameters=#keyParams&clientAuthentication=REQUIRE", PORT3).transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&trustStoreParameters=#trustParams&"
-                      + "keyStoreParameters=#keyParams&clientAuthentication=REQUIRE", PORT3)
+                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&" + "keyStoreParameters=#keyParams&cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
                     .transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&keyStoreParameters=#keyParams&cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
-                    .transform(body().prepend("Hello "));
+                fromF("coaps://localhost:%d/TestResource?privateKey=#privateKey&publicKey=#publicKey", PORT5).transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?privateKey=#privateKey&publicKey=#publicKey", PORT5)
+                fromF("coaps://localhost:%d/TestResource?privateKey=#privateKey&publicKey=#publicKey&" + "clientAuthentication=REQUIRE&trustedRpkStore=#trustedRpkStore", PORT6)
                     .transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?privateKey=#privateKey&publicKey=#publicKey&clientAuthentication=REQUIRE&trustedRpkStore=#trustedRpkStore", PORT6)
-                    .transform(body().prepend("Hello "));
+                fromF("coaps://localhost:%d/TestResource?pskStore=#pskStore", PORT7).transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?pskStore=#pskStore", PORT7)
+                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&" + "keyStoreParameters=#keyParams&pskStore=#pskStore", PORT8)
                     .transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&keyStoreParameters=#keyParams&pskStore=#pskStore", PORT8)
-                    .transform(body().prepend("Hello "));
+                from("direct:start").toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams", PORT).to("mock:result");
 
-                from("direct:start")
-                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams", PORT)
-                    .to("mock:result");
+                from("direct:notruststore").toF("coaps://localhost:%d/TestResource", PORT).to("mock:result");
 
-                from("direct:notruststore")
-                    .toF("coaps://localhost:%d/TestResource", PORT)
-                    .to("mock:result");
+                from("direct:failedtrust").toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams2", PORT).to("mock:result");
 
-                from("direct:failedtrust")
-                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams2", PORT)
-                    .to("mock:result");
-
-                from("direct:selfsigned")
-                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#keyParams2", PORT2)
-                    .to("mock:result");
+                from("direct:selfsigned").toF("coaps://localhost:%d/TestResource?trustStoreParameters=#keyParams2", PORT2).to("mock:result");
 
                 from("direct:clientauth")
-                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&keyStoreParameters=#keyParams3&alias=client&password=security", PORT3)
+                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&" + "keyStoreParameters=#keyParams3&alias=client&password=security", PORT3)
                     .to("mock:result");
 
                 from("direct:failedclientauth")
-                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&keyStoreParameters=#keyParams2&alias=selfsigned&password=security", PORT3)
+                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&" + "keyStoreParameters=#keyParams2&alias=selfsigned&password=security", PORT3)
                     .to("mock:result");
 
-                from("direct:ciphersuites")
-                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
+                from("direct:ciphersuites").toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&" + "cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
                     .to("mock:result");
 
-                from("direct:rpk")
-                    .toF("coaps://localhost:%d/TestResource?trustedRpkStore=#trustedRpkStore", PORT5)
-                    .to("mock:result");
+                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: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: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)
+                from("direct:rpkclientauth").toF("coaps://localhost:%d/TestResource?trustedRpkStore=#trustedRpkStore&" + "privateKey=#privateKey&publicKey=#publicKey", PORT6)
                     .to("mock:result");
 
-                from("direct:psk")
-                    .toF("coaps://localhost:%d/TestResource?pskStore=#pskStore", PORT7)
-                    .to("mock:result");
+                from("direct:psk").toF("coaps://localhost:%d/TestResource?pskStore=#pskStore", PORT7).to("mock:result");
 
-                from("direct:pskciphersuite")
-                    .toF("coaps://localhost:%d/TestResource?pskStore=#pskStore&cipherSuites=TLS_PSK_WITH_AES_128_CBC_SHA256", PORT7)
+                from("direct:pskciphersuite").toF("coaps://localhost:%d/TestResource?pskStore=#pskStore&" + "cipherSuites=TLS_PSK_WITH_AES_128_CBC_SHA256", PORT7)
                     .to("mock:result");
 
-                from("direct:pskx509")
-                    .toF("coaps://localhost:%d/TestResource?pskStore=#pskStore&trustStoreParameters=#trustParams", PORT8)
-                    .to("mock:result");
+                from("direct:pskx509").toF("coaps://localhost:%d/TestResource?pskStore=#pskStore&trustStoreParameters=#trustParams", PORT8).to("mock:result");
             }
         };
     }


[camel] 13/21: Supporting pre-shared keys

Posted by co...@apache.org.
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 bafb54369d674858730c63fd9c5eb800d30a7e03
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Fri Apr 26 12:08:13 2019 +0100

    Supporting pre-shared keys
---
 .../camel-coap/src/main/docs/coap-component.adoc   |  3 +-
 .../java/org/apache/camel/coap/CoAPEndpoint.java   | 30 ++++++++++++---
 .../apache/camel/coap/CoAPComponentTLSTest.java    | 43 ++++++++++++++++++++++
 3 files changed, 70 insertions(+), 6 deletions(-)

diff --git a/components/camel-coap/src/main/docs/coap-component.adoc b/components/camel-coap/src/main/docs/coap-component.adoc
index 1c7f280..3cb957b 100644
--- a/components/camel-coap/src/main/docs/coap-component.adoc
+++ b/components/camel-coap/src/main/docs/coap-component.adoc
@@ -50,7 +50,7 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (15 parameters):
+==== Query Parameters (16 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -61,6 +61,7 @@ with the following path and query parameters:
 | *keystore* (common) | Sets the TLS key store. Alternatively, a KeyStoreParameters object can be configured instead. An alias and password should also be configured on the route definition. |  | KeyStore
 | *keyStoreParameters* (common) | The KeyStoreParameters object to use with TLS to configure the keystore. Alternatively, a keystore parameter can be directly configured instead. An alias and password should also be configured on the route definition. |  | KeyStoreParameters
 | *privateKey* (common) | Set the configured private key for use with Raw Public Key. |  | PrivateKey
+| *pskStore* (common) | Set the PskStore to use for pre-shared key. |  | PskStore
 | *publicKey* (common) | Set the configured public key for use with Raw Public Key. |  | PublicKey
 | *trustedRpkStore* (common) | Set the TrustedRpkStore to use to determine trust in raw public keys. |  | TrustedRpkStore
 | *truststore* (common) | Sets the TLS trust store. Alternatively, a trustStoreParameters object can be configured instead. All certificates in the truststore are used to establish trust. |  | KeyStore
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 add9aab..5186a96 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
@@ -43,6 +43,7 @@ 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.pskstore.PskStore;
 import org.eclipse.californium.scandium.dtls.rpkstore.TrustedRpkStore;
 
 /**
@@ -77,6 +78,9 @@ public class CoAPEndpoint extends DefaultEndpoint {
     private TrustedRpkStore trustedRpkStore;
 
     @UriParam
+    private PskStore pskStore;
+
+    @UriParam
     private String alias;
     
     @UriParam(label = "security", javaType = "java.lang.String", secret = true)
@@ -228,7 +232,21 @@ public class CoAPEndpoint extends DefaultEndpoint {
     public void setTrustedRpkStore(TrustedRpkStore trustedRpkStore) {
         this.trustedRpkStore = trustedRpkStore;
     }
-    
+
+    /**
+     * Get the PskStore to use for pre-shared key.
+     */
+    public PskStore getPskStore() {
+        return pskStore;
+    }
+
+    /**
+     * Set the PskStore to use for pre-shared key.
+     */
+    public void setPskStore(PskStore pskStore) {
+        this.pskStore = pskStore;
+    }
+
     /**
      * Get the configured private key for use with Raw Public Key.
      */
@@ -347,22 +365,22 @@ public class CoAPEndpoint extends DefaultEndpoint {
 
         DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
         if (client) {
-            if (trustedRpkStore == null && getTruststore() == null) {
+            if (trustedRpkStore == null && getTruststore() == null && pskStore == null) {
                 throw new IllegalStateException("A truststore must be configured to use TLS");
             }
             
             builder.setClientOnly();
         } else {
-            if (privateKey == null && getKeystore() == null) {
+            if (privateKey == null && getKeystore() == null && pskStore == null) {
                 throw new IllegalStateException("A keystore or private key must be configured to use TLS");
             }
             if (privateKey != null && publicKey == null) {
                 throw new IllegalStateException("A public key must be configured to use a Raw Public Key with TLS");
             }
-            if (privateKey == null && getAlias() == null) {
+            if (privateKey == null && pskStore == null && getAlias() == null) {
                 throw new IllegalStateException("An alias must be configured to use TLS");
             }
-            if (privateKey == null && getPassword() == null) {
+            if (privateKey == null && pskStore == null && getPassword() == null) {
                 throw new IllegalStateException("A password must be configured to use TLS");
             }
             if ((isClientAuthenticationRequired() || isClientAuthenticationWanted())
@@ -383,6 +401,8 @@ public class CoAPEndpoint extends DefaultEndpoint {
                 builder.setIdentity(privateKey, getKeystore().getCertificateChain(getAlias()));
             } else if (privateKey != null) {
                 builder.setIdentity(privateKey, publicKey);
+            } else if (pskStore != null) {
+                builder.setPskStore(pskStore);
             }
 
             // Add all certificates from the truststore
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 b9d6b70..b6bd4ca 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
@@ -20,6 +20,8 @@ import java.security.KeyStore;
 import java.security.PrivateKey;
 import java.security.PublicKey;
 
+import javax.crypto.KeyGenerator;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
@@ -33,6 +35,8 @@ import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.util.jsse.KeyStoreParameters;
 import org.eclipse.californium.core.coap.CoAP;
 import org.eclipse.californium.core.coap.MediaTypeRegistry;
+import org.eclipse.californium.scandium.dtls.pskstore.PskStore;
+import org.eclipse.californium.scandium.dtls.pskstore.StaticPskStore;
 import org.eclipse.californium.scandium.dtls.rpkstore.TrustedRpkStore;
 import org.junit.Test;
 
@@ -44,6 +48,7 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
     protected static final int PORT4 = AvailablePortFinder.getNextAvailable();
     protected static final int PORT5 = AvailablePortFinder.getNextAvailable();
     protected static final int PORT6 = AvailablePortFinder.getNextAvailable();
+    protected static final int PORT7 = AvailablePortFinder.getNextAvailable();
 
     @Produce(uri = "direct:start")
     protected ProducerTemplate sender;
@@ -154,6 +159,28 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         assertMockEndpointsSatisfied();
     }
 
+    @Test
+    public void testPreSharedKey() 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:psk", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testPreSharedKeyCipherSuite() 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:pskciphersuite", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        assertMockEndpointsSatisfied();
+    }
+
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry registry = super.createRegistry();
@@ -186,6 +213,8 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
 
         TrustedRpkStore trustedRpkStore = id -> { return true;};
         TrustedRpkStore failedTrustedRpkStore = id -> { return false;};
+        KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
+        PskStore pskStore = new StaticPskStore("some-identity", keyGenerator.generateKey().getEncoded());
 
         registry.bind("keyParams", keystoreParameters);
         registry.bind("keyParams2", keystoreParameters2);
@@ -196,6 +225,7 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         registry.bind("publicKey", publicKey);
         registry.bind("trustedRpkStore", trustedRpkStore);
         registry.bind("failedTrustedRpkStore", failedTrustedRpkStore);
+        registry.bind("pskStore", pskStore);
 
         return registry;
     }
@@ -233,6 +263,10 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
                     + "trustedRpkStore=#trustedRpkStore", PORT6)
                   .transform(body().prepend("Hello "));
 
+                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
+                    + "pskStore=#pskStore", PORT7)
+                  .transform(body().prepend("Hello "));
+
                 from("direct:start")
                     .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams", PORT)
                     .to("mock:result");
@@ -280,6 +314,15 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
                     .toF("coaps://localhost:%d/TestResource?trustedRpkStore=#trustedRpkStore&"
                          + "privateKey=#privateKey&publicKey=#publicKey", PORT6)
                     .to("mock:result");
+
+                from("direct:psk")
+                    .toF("coaps://localhost:%d/TestResource?pskStore=#pskStore", PORT7)
+                    .to("mock:result");
+
+                from("direct:pskciphersuite")
+                    .toF("coaps://localhost:%d/TestResource?pskStore=#pskStore&"
+                         + "cipherSuites=TLS_PSK_WITH_AES_128_CBC_SHA256", PORT7)
+                    .to("mock:result");
             }
         };
     }


[camel] 08/21: Fixing tests

Posted by co...@apache.org.
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 8671e19b546f88b99dec1c1e90cd2d9cfc745c06
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Fri May 24 18:28:56 2019 +0100

    Fixing tests
---
 .../apache/camel/coap/CoAPComponentTLSTest.java    | 19 ++++++++++++++-----
 .../camel/coap/CoAPRestComponentTLSTest.java       | 22 +++++++++++++++-------
 2 files changed, 29 insertions(+), 12 deletions(-)

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 dfd5664..d515e8e 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
@@ -21,9 +21,10 @@ import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.jsse.KeyStoreParameters;
 import org.eclipse.californium.core.coap.CoAP;
 import org.eclipse.californium.core.coap.MediaTypeRegistry;
 import org.junit.Test;
@@ -32,7 +33,7 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
     
     protected static final int PORT = AvailablePortFinder.getNextAvailable();
 
-    @Produce("direct:start")
+    @Produce(uri = "direct:start")
     protected ProducerTemplate sender;
     
     @Test
@@ -47,7 +48,9 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
     }
 
     @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+
         KeyStoreParameters keystoreParameters = new KeyStoreParameters();
         keystoreParameters.setResource("service.jks");
         keystoreParameters.setPassword("security");
@@ -56,8 +59,14 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         truststoreParameters.setResource("truststore.jks");
         truststoreParameters.setPassword("storepass");
         
-        context.getRegistry().bind("keyParams", keystoreParameters);
-        context.getRegistry().bind("trustParams", truststoreParameters);
+        registry.bind("keyParams", keystoreParameters);
+        registry.bind("trustParams", truststoreParameters);
+
+        return registry;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
         
         return new RouteBuilder() {
             @Override
diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTLSTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTLSTest.java
index 8d94bce..a185c02 100644
--- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTLSTest.java
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTLSTest.java
@@ -22,16 +22,17 @@ import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.jsse.KeyStoreParameters;
 import org.eclipse.californium.core.coap.CoAP;
 import org.junit.Test;
 
 public class CoAPRestComponentTLSTest extends CamelTestSupport {
     protected static final int PORT = AvailablePortFinder.getNextAvailable();
 
-    @Produce("direct:start")
+    @Produce(uri = "direct:start")
     protected ProducerTemplate sender;
     
     @Test
@@ -53,10 +54,11 @@ public class CoAPRestComponentTLSTest extends CamelTestSupport {
         sender.sendBody("");
         assertMockEndpointsSatisfied();
     }
-    
+
     @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+
         KeyStoreParameters keystoreParameters = new KeyStoreParameters();
         keystoreParameters.setResource("service.jks");
         keystoreParameters.setPassword("security");
@@ -65,8 +67,14 @@ public class CoAPRestComponentTLSTest extends CamelTestSupport {
         truststoreParameters.setResource("truststore.jks");
         truststoreParameters.setPassword("storepass");
         
-        context.getRegistry().bind("keystoreParameters", keystoreParameters);
-        context.getRegistry().bind("truststoreParameters", truststoreParameters);
+        registry.bind("keystoreParameters", keystoreParameters);
+        registry.bind("truststoreParameters", truststoreParameters);
+
+        return registry;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
         
         return new RouteBuilder() {
             @Override


[camel] 15/21: Updating the docs

Posted by co...@apache.org.
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 d4d31aefc9b65c92ef8e1fcd1aa44ec8ed8383b7
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon Apr 29 12:39:14 2019 +0100

    Updating the docs
---
 components/camel-coap/src/main/docs/coap-component.adoc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/components/camel-coap/src/main/docs/coap-component.adoc b/components/camel-coap/src/main/docs/coap-component.adoc
index 3cb957b..c86e853 100644
--- a/components/camel-coap/src/main/docs/coap-component.adoc
+++ b/components/camel-coap/src/main/docs/coap-component.adoc
@@ -37,7 +37,10 @@ The CoAP endpoint is configured using URI syntax:
 ----
 coap:uri
 ----
-
+Alternatively, if TLS is being used:
+----
+coaps:uri
+----
 with the following path and query parameters:
 
 ==== Path Parameters (1 parameters):


[camel] 03/21: Avoid writing out Californium.properties

Posted by co...@apache.org.
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 97fd0e7a07c2fafff97a2d37e4eef69067aea3c4
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Wed Apr 10 12:36:46 2019 +0100

    Avoid writing out Californium.properties
---
 .../camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java  | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
index dbd382b..40e2c20 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
@@ -45,6 +45,7 @@ import org.apache.camel.util.URISupport;
 import org.apache.camel.util.jsse.KeyStoreParameters;
 import org.eclipse.californium.core.CoapServer;
 import org.eclipse.californium.core.network.CoapEndpoint;
+import org.eclipse.californium.core.network.config.NetworkConfig;
 import org.eclipse.californium.scandium.DTLSConnector;
 import org.eclipse.californium.scandium.config.DtlsConnectorConfig;
 import org.slf4j.Logger;
@@ -74,7 +75,9 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
         }
         if (server == null) {
             CoapEndpoint.Builder coapBuilder = new CoapEndpoint.Builder();
+            NetworkConfig config = NetworkConfig.createStandardWithoutFile();
             InetSocketAddress address = new InetSocketAddress(port);
+            coapBuilder.setNetworkConfig(config);
             
             if (keyStoreParameters != null) {
                 DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();


[camel] 12/21: Adding more RPK tests

Posted by co...@apache.org.
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 <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 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");
             }
         };
     }


[camel] 14/21: Adding X.509 + PSK tests

Posted by co...@apache.org.
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 189104cd6667db7098cfda0e8c1bf822195c8354
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon Apr 29 12:35:56 2019 +0100

    Adding X.509 + PSK tests
---
 .../java/org/apache/camel/coap/CoAPEndpoint.java   |  4 +-
 .../apache/camel/coap/CoAPComponentTLSTest.java    | 43 +++++++++++++++-------
 2 files changed, 33 insertions(+), 14 deletions(-)

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 5186a96..8d5d394 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
@@ -401,7 +401,9 @@ public class CoAPEndpoint extends DefaultEndpoint {
                 builder.setIdentity(privateKey, getKeystore().getCertificateChain(getAlias()));
             } else if (privateKey != null) {
                 builder.setIdentity(privateKey, publicKey);
-            } else if (pskStore != null) {
+            }
+
+            if (pskStore != null) {
                 builder.setPskStore(pskStore);
             }
 
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 b6bd4ca..815a392 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
@@ -42,13 +42,14 @@ import org.junit.Test;
 
 public class CoAPComponentTLSTest extends CamelTestSupport {
 
-    protected static final int PORT = AvailablePortFinder.getNextAvailable();
-    protected static final int PORT2 = AvailablePortFinder.getNextAvailable();
-    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();
-    protected static final int PORT7 = AvailablePortFinder.getNextAvailable();
+    private static final int PORT = AvailablePortFinder.getNextAvailable();
+    private static final int PORT2 = AvailablePortFinder.getNextAvailable();
+    private static final int PORT3 = AvailablePortFinder.getNextAvailable();
+    private static final int PORT4 = AvailablePortFinder.getNextAvailable();
+    private static final int PORT5 = AvailablePortFinder.getNextAvailable();
+    private static final int PORT6 = AvailablePortFinder.getNextAvailable();
+    private static final int PORT7 = AvailablePortFinder.getNextAvailable();
+    private static final int PORT8 = AvailablePortFinder.getNextAvailable();
 
     @Produce(uri = "direct:start")
     protected ProducerTemplate sender;
@@ -181,6 +182,17 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         assertMockEndpointsSatisfied();
     }
 
+    @Test
+    public void testPreSharedKeyX509() 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:pskx509", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        assertMockEndpointsSatisfied();
+    }
+
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry registry = super.createRegistry();
@@ -254,17 +266,18 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
                     + "keyStoreParameters=#keyParams&cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
                   .transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
-                    + "privateKey=#privateKey&publicKey=#publicKey", PORT5)
+                fromF("coaps://localhost:%d/TestResource?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)
+                fromF("coaps://localhost:%d/TestResource?privateKey=#privateKey&publicKey=#publicKey&"
+                      + "clientAuthentication=REQUIRE&trustedRpkStore=#trustedRpkStore", PORT6)
+                  .transform(body().prepend("Hello "));
+
+                fromF("coaps://localhost:%d/TestResource?pskStore=#pskStore", PORT7)
                   .transform(body().prepend("Hello "));
 
                 fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
-                    + "pskStore=#pskStore", PORT7)
+                    + "keyStoreParameters=#keyParams&pskStore=#pskStore", PORT8)
                   .transform(body().prepend("Hello "));
 
                 from("direct:start")
@@ -323,6 +336,10 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
                     .toF("coaps://localhost:%d/TestResource?pskStore=#pskStore&"
                          + "cipherSuites=TLS_PSK_WITH_AES_128_CBC_SHA256", PORT7)
                     .to("mock:result");
+
+                from("direct:pskx509")
+                    .toF("coaps://localhost:%d/TestResource?pskStore=#pskStore&trustStoreParameters=#trustParams", PORT8)
+                    .to("mock:result");
             }
         };
     }


[camel] 16/21: Removing some whitespace

Posted by co...@apache.org.
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 1adf51742a051e6d241059eb7a2d1c79d5aeb520
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon Apr 29 12:53:58 2019 +0100

    Removing some whitespace
---
 .../camel-coap/src/main/docs/coap-component.adoc   |  5 +-
 .../java/org/apache/camel/coap/CoAPComponent.java  |  4 +-
 .../java/org/apache/camel/coap/CoAPEndpoint.java   | 59 +++++++++++-----------
 .../java/org/apache/camel/coap/CoAPProducer.java   |  2 +-
 .../apache/camel/coap/CoAPComponentTLSTest.java    |  2 +-
 .../camel/coap/CoAPRestComponentTLSTest.java       | 12 ++---
 6 files changed, 40 insertions(+), 44 deletions(-)

diff --git a/components/camel-coap/src/main/docs/coap-component.adoc b/components/camel-coap/src/main/docs/coap-component.adoc
index c86e853..3cb957b 100644
--- a/components/camel-coap/src/main/docs/coap-component.adoc
+++ b/components/camel-coap/src/main/docs/coap-component.adoc
@@ -37,10 +37,7 @@ The CoAP endpoint is configured using URI syntax:
 ----
 coap:uri
 ----
-Alternatively, if TLS is being used:
-----
-coaps:uri
-----
+
 with the following path and query parameters:
 
 ==== Path Parameters (1 parameters):
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
index bf1f515..bfa450c 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
@@ -68,7 +68,7 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
             NetworkConfig config = NetworkConfig.createStandardWithoutFile();
             InetSocketAddress address = new InetSocketAddress(port);
             coapBuilder.setNetworkConfig(config);
-            
+
             // Configure TLS
             if (CoAPEndpoint.enableTLS(endpoint.getUri())) {
                 DTLSConnector connector = endpoint.createDTLSConnector(address, false);
@@ -79,7 +79,7 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
 
             server = new CoapServer();
             server.addEndpoint(coapBuilder.build());
-            
+
             servers.put(port, server);
             if (this.isStarted()) {
                 server.start();
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 8d5d394..6d5e32c 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
@@ -55,16 +55,16 @@ public class CoAPEndpoint extends DefaultEndpoint {
     private URI uri;
     @UriParam(label = "consumer")
     private String coapMethodRestrict;
-    
+
     @UriParam
     private KeyStoreParameters keyStoreParameters;
-    
+
     @UriParam
     private KeyStore keystore;
-    
+
     @UriParam
     private KeyStoreParameters trustStoreParameters;
-    
+
     @UriParam
     private KeyStore truststore;
 
@@ -82,17 +82,17 @@ public class CoAPEndpoint extends DefaultEndpoint {
 
     @UriParam
     private String alias;
-    
+
     @UriParam(label = "security", javaType = "java.lang.String", secret = true)
     private char[] password;
-    
+
     @UriParam
     private String cipherSuites;
-    
+
     private String[] configuredCipherSuites;
-    
+
     private String clientAuthentication;
-        
+
     private CoAPComponent component;
     
     public CoAPEndpoint(String uri, CoAPComponent component) {
@@ -142,9 +142,9 @@ public class CoAPEndpoint extends DefaultEndpoint {
     public CoapServer getCoapServer() {
         return component.getServer(getUri().getPort(), this);
     }
-    
+
     /**
-     * The KeyStoreParameters object to use with TLS to configure the keystore. Alternatively, a "keystore" 
+     * The KeyStoreParameters object to use with TLS to configure the keystore. Alternatively, a "keystore"
      * parameter can be directly configured instead. An alias and password should also be configured on the route definition.
      */
     public KeyStoreParameters getKeyStoreParameters() {
@@ -157,9 +157,9 @@ public class CoAPEndpoint extends DefaultEndpoint {
             this.keystore = keyStoreParameters.createKeyStore();
         }
     }
-    
+
     /**
-     * The KeyStoreParameters object to use with TLS to configure the truststore. Alternatively, a "truststore" 
+     * The KeyStoreParameters object to use with TLS to configure the truststore. Alternatively, a "truststore"
      * object can be directly configured instead. All certificates in the truststore are used to establish trust.
      */
     public KeyStoreParameters getTrustStoreParameters() {
@@ -172,7 +172,7 @@ public class CoAPEndpoint extends DefaultEndpoint {
             this.truststore = trustStoreParameters.createKeyStore();
         }
     }
-    
+
     /**
      * Gets the TLS key store. Alternatively, a KeyStoreParameters object can be configured instead.
      * An alias and password should also be configured on the route definition.
@@ -188,7 +188,7 @@ public class CoAPEndpoint extends DefaultEndpoint {
     public void setKeystore(KeyStore keystore) {
         this.keystore = keystore;
     }
-    
+
     /**
      * Gets the TLS trust store. Alternatively, a "trustStoreParameters" object can be configured instead.
      * All certificates in the truststore are used to establish trust.
@@ -204,7 +204,7 @@ public class CoAPEndpoint extends DefaultEndpoint {
     public void setTruststore(KeyStore truststore) {
         this.truststore = truststore;
     }
-    
+
     /**
      * Gets the alias used to query the KeyStore for the private key and certificate.
      */
@@ -288,7 +288,7 @@ public class CoAPEndpoint extends DefaultEndpoint {
     public void setPassword(char[] password) {
         this.password = password;
     }
-    
+
     /**
      * Gets the cipherSuites String. This is a comma separated String of ciphersuites to configure.
      */
@@ -305,12 +305,11 @@ public class CoAPEndpoint extends DefaultEndpoint {
             configuredCipherSuites = cipherSuites.split(",");
         }
     }
-    
+
     private String[] getConfiguredCipherSuites() {
         return configuredCipherSuites;
     }
-    
-    
+
     /**
      * Gets the configuration options for server-side client-authentication requirements. The value is
      * either null or one of NONE, WANT, REQUIRE.
@@ -322,23 +321,23 @@ public class CoAPEndpoint extends DefaultEndpoint {
     /**
      * Sets the configuration options for server-side client-authentication requirements.
      * The value must be one of NONE, WANT, REQUIRE.
-     * 
+     *
      * @param value the desired configuration options or {@code null} to use the defaults
      */
     public void setClientAuthentication(String clientAuthentication) {
         this.clientAuthentication = clientAuthentication;
     }
-    
+
     private boolean isClientAuthenticationRequired() {
-        return clientAuthentication != null 
+        return clientAuthentication != null
             && ClientAuthentication.valueOf(clientAuthentication) == ClientAuthentication.REQUIRE;
     }
-    
+
     private boolean isClientAuthenticationWanted() {
-        return clientAuthentication != null 
+        return clientAuthentication != null
             && ClientAuthentication.valueOf(clientAuthentication) == ClientAuthentication.WANT;
     }
-    
+
     private Certificate[] getTrustedCerts() throws KeyStoreException {
         if (truststore != null) {
             Enumeration<String> aliases = truststore.aliases();
@@ -356,7 +355,7 @@ public class CoAPEndpoint extends DefaultEndpoint {
         
         return new Certificate[0];
     }
-    
+
     public static boolean enableTLS(URI uri) {
         return "coaps".equals(uri.getScheme());
     }
@@ -368,7 +367,7 @@ public class CoAPEndpoint extends DefaultEndpoint {
             if (trustedRpkStore == null && getTruststore() == null && pskStore == null) {
                 throw new IllegalStateException("A truststore must be configured to use TLS");
             }
-            
+
             builder.setClientOnly();
         } else {
             if (privateKey == null && getKeystore() == null && pskStore == null) {
@@ -387,7 +386,7 @@ public class CoAPEndpoint extends DefaultEndpoint {
                 && (getTruststore() == null && publicKey == null)) {
                 throw new IllegalStateException("A truststore must be configured to support TLS client authentication");
             }
-            
+
             builder.setAddress(address);
             builder.setClientAuthenticationRequired(isClientAuthenticationRequired());
             builder.setClientAuthenticationWanted(isClientAuthenticationWanted());
@@ -396,7 +395,7 @@ public class CoAPEndpoint extends DefaultEndpoint {
         try {
             // Configure the identity if the keystore or privateKey parameter is specified
             if (getKeystore() != null) {
-                PrivateKey privateKey = 
+                PrivateKey privateKey =
                     (PrivateKey)getKeystore().getKey(getAlias(), getPassword());
                 builder.setIdentity(privateKey, getKeystore().getCertificateChain(getAlias()));
             } else if (privateKey != null) {
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
index 46c8f60..5441481 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
@@ -93,7 +93,7 @@ public class CoAPProducer extends DefaultProducer {
                 uri = endpoint.getUri();
             }
             client = new CoapClient(uri);
-            
+
             // Configure TLS
             if (CoAPEndpoint.enableTLS((uri))) {
                 DTLSConnector connector = endpoint.createDTLSConnector(null, true);
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 815a392..aadd2a78 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
@@ -110,7 +110,7 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         sendBodyAndHeader("direct:failedclientauth", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
         assertMockEndpointsSatisfied();
     }
-    
+
     @Test
     public void testCipherSuites() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTLSTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTLSTest.java
index a185c02..e911081 100644
--- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTLSTest.java
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTLSTest.java
@@ -34,7 +34,7 @@ public class CoAPRestComponentTLSTest extends CamelTestSupport {
 
     @Produce(uri = "direct:start")
     protected ProducerTemplate sender;
-    
+
     @Test
     public void testPOST() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
@@ -44,7 +44,7 @@ public class CoAPRestComponentTLSTest extends CamelTestSupport {
         sender.sendBodyAndHeader("Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
         assertMockEndpointsSatisfied();
     }
-    
+
     @Test
     public void testGET() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
@@ -62,7 +62,7 @@ public class CoAPRestComponentTLSTest extends CamelTestSupport {
         KeyStoreParameters keystoreParameters = new KeyStoreParameters();
         keystoreParameters.setResource("service.jks");
         keystoreParameters.setPassword("security");
-        
+
         KeyStoreParameters truststoreParameters = new KeyStoreParameters();
         truststoreParameters.setResource("truststore.jks");
         truststoreParameters.setPassword("storepass");
@@ -75,7 +75,7 @@ public class CoAPRestComponentTLSTest extends CamelTestSupport {
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
-        
+
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
@@ -83,7 +83,7 @@ public class CoAPRestComponentTLSTest extends CamelTestSupport {
                     .endpointProperty("keyStoreParameters", "#keystoreParameters")
                     .endpointProperty("alias", "service")
                     .endpointProperty("password", "security");
-                
+
                 rest("/TestResource")
                     .get().to("direct:get1")
                     .post().to("direct:post1");
@@ -99,7 +99,7 @@ public class CoAPRestComponentTLSTest extends CamelTestSupport {
                         exchange.getOut().setBody("Hello " + exchange.getIn().getBody(String.class));
                     }
                 });
-                
+
                 from("direct:start")
                     .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#truststoreParameters", PORT)
                     .to("mock:result");


[camel] 09/21: Adding more CoAP TLS tests

Posted by co...@apache.org.
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 27b5f7f230a8ecc4e5ef4c28046f99bc784d2cec
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Fri Apr 19 13:04:09 2019 +0100

    Adding more CoAP TLS tests
---
 .../apache/camel/coap/CoAPComponentTLSTest.java    | 137 ++++++++++++++++++++-
 .../camel-coap/src/test/resources/selfsigned.jks   | Bin 0 -> 701 bytes
 .../camel-coap/src/test/resources/truststore2.jks  | Bin 0 -> 717 bytes
 3 files changed, 132 insertions(+), 5 deletions(-)

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 d515e8e..f78bcb5 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
@@ -17,6 +17,8 @@
 package org.apache.camel.coap;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
@@ -30,20 +32,80 @@ import org.eclipse.californium.core.coap.MediaTypeRegistry;
 import org.junit.Test;
 
 public class CoAPComponentTLSTest extends CamelTestSupport {
-    
+
     protected static final int PORT = AvailablePortFinder.getNextAvailable();
+    protected static final int PORT2 = AvailablePortFinder.getNextAvailable();
+    protected static final int PORT3 = AvailablePortFinder.getNextAvailable();
+    protected static final int PORT4 = AvailablePortFinder.getNextAvailable();
 
     @Produce(uri = "direct:start")
     protected ProducerTemplate sender;
+
+    @Test
+    public void testSuccessfulCall() 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:start", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testNoTruststore() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(0);
+        sendBodyAndHeader("direct:notruststore", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testTrustValidationFailed() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(0);
+        sendBodyAndHeader("direct:failedtrust", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testSelfSigned() 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:selfsigned", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testClientAuthentication() 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:clientauth", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testFailedClientAuthentication() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(0);
+        sendBodyAndHeader("direct:failedclientauth", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        assertMockEndpointsSatisfied();
+    }
     
     @Test
-    public void testTLS() throws Exception {
+    public void testCipherSuites() 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());
-        sender.sendBodyAndHeader("Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        sendBodyAndHeader("direct:ciphersuites", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
         assertMockEndpointsSatisfied();
     }
 
@@ -54,13 +116,28 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         KeyStoreParameters keystoreParameters = new KeyStoreParameters();
         keystoreParameters.setResource("service.jks");
         keystoreParameters.setPassword("security");
-        
+
+        KeyStoreParameters keystoreParameters2 = new KeyStoreParameters();
+        keystoreParameters2.setResource("selfsigned.jks");
+        keystoreParameters2.setPassword("security");
+
+        KeyStoreParameters keystoreParameters3 = new KeyStoreParameters();
+        keystoreParameters3.setResource("client.jks");
+        keystoreParameters3.setPassword("security");
+
         KeyStoreParameters truststoreParameters = new KeyStoreParameters();
         truststoreParameters.setResource("truststore.jks");
         truststoreParameters.setPassword("storepass");
-        
+
+        KeyStoreParameters truststoreParameters2 = new KeyStoreParameters();
+        truststoreParameters2.setResource("truststore2.jks");
+        truststoreParameters2.setPassword("storepass");
+
         registry.bind("keyParams", keystoreParameters);
+        registry.bind("keyParams2", keystoreParameters2);
+        registry.bind("keyParams3", keystoreParameters3);
         registry.bind("trustParams", truststoreParameters);
+        registry.bind("trustParams2", truststoreParameters2);
 
         return registry;
     }
@@ -75,10 +152,60 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
                       + "keyStoreParameters=#keyParams", PORT)
                     .transform(body().prepend("Hello "));
 
+                fromF("coaps://localhost:%d/TestResource?alias=selfsigned&password=security&"
+                    + "keyStoreParameters=#keyParams2", PORT2)
+                  .transform(body().prepend("Hello "));
+
+                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
+                    + "trustStoreParameters=#trustParams&"
+                    + "keyStoreParameters=#keyParams&clientAuthentication=REQUIRE", PORT3)
+                  .transform(body().prepend("Hello "));
+
+                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
+                    + "keyStoreParameters=#keyParams&cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
+                  .transform(body().prepend("Hello "));
+
                 from("direct:start")
                     .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams", PORT)
                     .to("mock:result");
+
+                from("direct:notruststore")
+                    .toF("coaps://localhost:%d/TestResource", PORT)
+                    .to("mock:result");
+
+                from("direct:failedtrust")
+                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams2", PORT)
+                    .to("mock:result");
+
+                from("direct:selfsigned")
+                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#keyParams2", PORT2)
+                    .to("mock:result");
+
+                from("direct:clientauth")
+                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&"
+                         + "keyStoreParameters=#keyParams3&alias=client&password=security", PORT3)
+                    .to("mock:result");
+
+                from("direct:failedclientauth")
+                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&"
+                         + "keyStoreParameters=#keyParams2&alias=selfsigned&password=security", PORT3)
+                    .to("mock:result");
+
+                from("direct:ciphersuites")
+                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&"
+                         + "cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
+                    .to("mock:result");
             }
         };
     }
+
+    protected void sendBodyAndHeader(String endpointUri, final Object body, String headerName, String headerValue) {
+        template.send(endpointUri, new Processor() {
+            public void process(Exchange exchange) {
+                Message in = exchange.getIn();
+                in.setBody(body);
+                in.setHeader(headerName, headerValue);
+            }
+        });
+    }
 }
diff --git a/components/camel-coap/src/test/resources/selfsigned.jks b/components/camel-coap/src/test/resources/selfsigned.jks
new file mode 100644
index 0000000..ee745ff
Binary files /dev/null and b/components/camel-coap/src/test/resources/selfsigned.jks differ
diff --git a/components/camel-coap/src/test/resources/truststore2.jks b/components/camel-coap/src/test/resources/truststore2.jks
new file mode 100644
index 0000000..94249d6
Binary files /dev/null and b/components/camel-coap/src/test/resources/truststore2.jks differ


[camel] 20/21: CAMEL-13402 - Fixed Karaf feature after upgrading to Californium 2.x

Posted by co...@apache.org.
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 414f35bceea3e0fbdee2b0ae3df86bec17ffc860
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Apr 30 11:52:33 2019 +0200

    CAMEL-13402 - Fixed Karaf feature after upgrading to Californium 2.x
---
 platforms/karaf/features/src/main/resources/features.xml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index 8bf808c..628db66 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -406,7 +406,9 @@
   </feature>
   <feature name='camel-coap' version='${project.version}' resolver='(obr)' start-level='50'>
     <feature version='${project.version}'>camel-core</feature>
-    <bundle>mvn:org.eclipse.californium/californium-osgi/${californium-version}</bundle>
+    <bundle>wrap:mvn:org.eclipse.californium/californium-core/${californium-version}</bundle>
+    <bundle>wrap:mvn:org.eclipse.californium/element-connector/${californium-version}</bundle>
+    <bundle>wrap:mvn:org.eclipse.californium/scandium/${californium-version}</bundle>
     <bundle>mvn:org.apache.camel/camel-coap/${project.version}</bundle>
   </feature>
   <feature name='camel-cometd' version='${project.version}' resolver='(obr)' start-level='50'>


[camel] 01/21: CAMEL-13402 - Updating to Californium 2.0.x

Posted by co...@apache.org.
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 8c4f27703f54b594ab1d699c67a506b736fa4797
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue Apr 9 14:45:04 2019 +0100

    CAMEL-13402 - Updating to Californium 2.0.x
---
 .../src/test/java/org/apache/camel/coap/CoAPComponentTest.java      | 4 ++--
 .../src/test/java/org/apache/camel/coap/CoAPMethodRestrictTest.java | 2 +-
 .../src/test/java/org/apache/camel/coap/CoAPRestComponentTest.java  | 6 +++---
 parent/pom.xml                                                      | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTest.java
index 15c317b..62d6009 100644
--- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTest.java
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTest.java
@@ -35,8 +35,8 @@ public class CoAPComponentTest extends CoAPTestSupport {
     @Test
     public void testCoAPComponent() throws Exception {
         CoapClient client = createClient("/TestResource");
-        CoapResponse response = client.get();
-        assertEquals("Hello ", response.getResponseText());
+        CoapResponse response = client.post("Camel", MediaTypeRegistry.TEXT_PLAIN);
+        assertEquals("Hello Camel", response.getResponseText());
         
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMinimumMessageCount(1);
diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodRestrictTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodRestrictTest.java
index f9b44f1..6f19767 100644
--- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodRestrictTest.java
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodRestrictTest.java
@@ -54,7 +54,7 @@ public class CoAPMethodRestrictTest extends CoAPTestSupport {
             if (methodRestrict.contains(method)) {
                 assertEquals(expectedResponse, result);
             } else {
-                assertEquals("", result);
+                assertNull(result);
             }
         }
     }
diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTest.java
index 2aa58e9..8b94b1c 100644
--- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTest.java
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTest.java
@@ -46,7 +46,7 @@ public class CoAPRestComponentTest extends CamelTestSupport {
         assertEquals("Hello Ducky: data", rsp.getResponseText());
 
         client = new CoapClient("coap://localhost:" + coapport + "/TestParams?id=Ducky");
-        client.setTimeout(1000000);
+        client.setTimeout(1000000L);
         rsp = client.get();
         assertEquals(ResponseCode.CONTENT, rsp.getCode());
         assertEquals("Hello Ducky", rsp.getResponseText());
@@ -60,7 +60,7 @@ public class CoAPRestComponentTest extends CamelTestSupport {
     public void testCoAPMethodNotAllowedResponse() throws Exception {
         NetworkConfig.createStandardWithoutFile();
         CoapClient client = new CoapClient("coap://localhost:" + coapport + "/TestResource/Ducky");
-        client.setTimeout(1000000);
+        client.setTimeout(1000000L);
         CoapResponse rsp = client.delete();
         assertEquals(ResponseCode.METHOD_NOT_ALLOWED, rsp.getCode());
     }
@@ -69,7 +69,7 @@ public class CoAPRestComponentTest extends CamelTestSupport {
     public void testCoAPNotFoundResponse() throws Exception {
         NetworkConfig.createStandardWithoutFile();
         CoapClient client = new CoapClient("coap://localhost:" + coapport + "/foo/bar/cheese");
-        client.setTimeout(1000000);
+        client.setTimeout(1000000L);
         CoapResponse rsp = client.get();
         assertEquals(ResponseCode.NOT_FOUND, rsp.getCode());
     }
diff --git a/parent/pom.xml b/parent/pom.xml
index d72d95b..5ec7d00 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -103,7 +103,7 @@
     <c3p0-version>0.9.5.3</c3p0-version>
     <c3p0-bundle-version>0.9.5.3_1</c3p0-bundle-version>
     <caffeine-version>2.6.2</caffeine-version>
-    <californium-version>1.0.7</californium-version>
+    <californium-version>2.0.0-M14</californium-version>
     <camel-test-spring-artifactId>camel-test-spring</camel-test-spring-artifactId>
     <cassandra-driver-version>3.6.0</cassandra-driver-version>
     <cassandra-driver-guava-version>19.0</cassandra-driver-guava-version>


[camel] 06/21: Consolidate TLS configuration

Posted by co...@apache.org.
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 8ebae088767b7189d72761a1ea98c40992305144
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Thu Apr 11 13:32:08 2019 +0100

    Consolidate TLS configuration
---
 .../java/org/apache/camel/coap/CoAPComponent.java  | 40 ++------------
 .../java/org/apache/camel/coap/CoAPEndpoint.java   | 63 +++++++++++++++++++---
 .../java/org/apache/camel/coap/CoAPProducer.java   | 35 ++----------
 3 files changed, 61 insertions(+), 77 deletions(-)

diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
index 1a17d94..bf1f515 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
@@ -17,8 +17,6 @@
 package org.apache.camel.coap;
 
 import java.net.InetSocketAddress;
-import java.security.GeneralSecurityException;
-import java.security.PrivateKey;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -40,7 +38,6 @@ import org.eclipse.californium.core.CoapServer;
 import org.eclipse.californium.core.network.CoapEndpoint;
 import org.eclipse.californium.core.network.config.NetworkConfig;
 import org.eclipse.californium.scandium.DTLSConnector;
-import org.eclipse.californium.scandium.config.DtlsConnectorConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -72,40 +69,9 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
             InetSocketAddress address = new InetSocketAddress(port);
             coapBuilder.setNetworkConfig(config);
             
-            if (endpoint.getKeystore() != null) {
-                DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
-                builder.setAddress(address);
-                if (endpoint.getAlias() == null) {
-                    throw new IllegalStateException("An alias must be configured to use TLS");
-                }
-                if (endpoint.getPassword() == null) {
-                    throw new IllegalStateException("A password must be configured to use TLS");
-                }
-                if (endpoint.getTruststore() == null) {
-                    throw new IllegalStateException("A truststore must be configured to use TLS");
-                }
-
-                try {
-                    // Configure the identity
-                    PrivateKey privateKey = 
-                        (PrivateKey)endpoint.getKeystore().getKey(endpoint.getAlias(), endpoint.getPassword());
-                    builder.setIdentity(privateKey, endpoint.getKeystore().getCertificateChain(endpoint.getAlias()));
-
-                    // Add all certificates from the truststore
-                    builder.setTrustStore(endpoint.getTrustedCerts());
-
-                } catch (GeneralSecurityException e) {
-                    throw new IllegalStateException("Error in configuring TLS", e);
-                }
-
-                builder.setClientAuthenticationRequired(endpoint.isClientAuthenticationRequired());
-                builder.setClientAuthenticationWanted(endpoint.isClientAuthenticationWanted());
-
-                if (endpoint.getConfiguredCipherSuites() != null) {
-                    builder.setSupportedCipherSuites(endpoint.getConfiguredCipherSuites());
-                }
-
-                DTLSConnector connector = new DTLSConnector(builder.build());
+            // Configure TLS
+            if (CoAPEndpoint.enableTLS(endpoint.getUri())) {
+                DTLSConnector connector = endpoint.createDTLSConnector(address, false);
                 coapBuilder.setConnector(connector);
             } else {
                 coapBuilder.setInetSocketAddress(address);
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 e0a0b7e..6076cc2 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
@@ -17,6 +17,7 @@
 package org.apache.camel.coap;
 
 import java.io.IOException;
+import java.net.InetSocketAddress;
 import java.net.URI;
 import java.security.GeneralSecurityException;
 import java.security.KeyStore;
@@ -38,6 +39,8 @@ import org.apache.camel.spi.UriPath;
 import org.apache.camel.util.jsse.ClientAuthentication;
 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;
 
 /**
  * The coap component is used for sending and receiving messages from COAP capable devices.
@@ -231,7 +234,7 @@ public class CoAPEndpoint extends DefaultEndpoint {
         }
     }
     
-    public String[] getConfiguredCipherSuites() {
+    private String[] getConfiguredCipherSuites() {
         return configuredCipherSuites;
     }
     
@@ -254,17 +257,17 @@ public class CoAPEndpoint extends DefaultEndpoint {
         this.clientAuthentication = clientAuthentication;
     }
     
-    public boolean isClientAuthenticationRequired() {
+    private boolean isClientAuthenticationRequired() {
         return clientAuthentication != null 
             && ClientAuthentication.valueOf(clientAuthentication) == ClientAuthentication.REQUIRE;
     }
     
-    public boolean isClientAuthenticationWanted() {
+    private boolean isClientAuthenticationWanted() {
         return clientAuthentication != null 
             && ClientAuthentication.valueOf(clientAuthentication) == ClientAuthentication.WANT;
     }
     
-    public Certificate[] getTrustedCerts() throws KeyStoreException {
+    private Certificate[] getTrustedCerts() throws KeyStoreException {
         Enumeration<String> aliases = truststore.aliases();
         List<Certificate> trustCerts = new ArrayList<>();
         while (aliases.hasMoreElements()) {
@@ -277,10 +280,54 @@ public class CoAPEndpoint extends DefaultEndpoint {
         
         return trustCerts.toArray(new Certificate[0]);
     }
+    
+    public static boolean enableTLS(URI uri) {
+        return "coaps".equals(uri.getScheme());
+    }
 
-    /*
-    public DTLSConnector createDTLSConnector() {
-        
+    public DTLSConnector createDTLSConnector(InetSocketAddress address, boolean client) {
+        if (getTruststore() == null) {
+            throw new IllegalStateException("A truststore must be configured to use TLS");
+        }
+        if (!client) {
+            if (getKeystore() == null) {
+                throw new IllegalStateException("A keystore must be configured to use TLS");
+            }
+            if (getAlias() == null) {
+                throw new IllegalStateException("An alias must be configured to use TLS");
+            }
+            if (getPassword() == null) {
+                throw new IllegalStateException("A password must be configured to use TLS");
+            }
+        }
+
+        DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
+        if (client) {
+            builder.setClientOnly();
+        } else {
+            builder.setAddress(address);
+            builder.setClientAuthenticationRequired(isClientAuthenticationRequired());
+            builder.setClientAuthenticationWanted(isClientAuthenticationWanted());
+        }
+
+        try {
+            // Configure the identity if the keystore parameter is specified
+            if (getKeystore() != null) {
+                PrivateKey privateKey = 
+                    (PrivateKey)getKeystore().getKey(getAlias(), getPassword());
+                builder.setIdentity(privateKey, getKeystore().getCertificateChain(getAlias()));
+            }
+    
+            // Add all certificates from the truststore
+            builder.setTrustStore(getTrustedCerts());
+        } catch (GeneralSecurityException e) {
+            throw new IllegalStateException("Error in configuring TLS", e);
+        }
+
+        if (getConfiguredCipherSuites() != null) {
+            builder.setSupportedCipherSuites(getConfiguredCipherSuites());
+        }
+
+        return new DTLSConnector(builder.build());
     }
-    */
 }
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
index 588e429..46c8f60 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
@@ -17,8 +17,6 @@
 package org.apache.camel.coap;
 
 import java.net.URI;
-import java.security.GeneralSecurityException;
-import java.security.PrivateKey;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
@@ -28,7 +26,6 @@ import org.eclipse.californium.core.CoapResponse;
 import org.eclipse.californium.core.coap.MediaTypeRegistry;
 import org.eclipse.californium.core.network.CoapEndpoint;
 import org.eclipse.californium.scandium.DTLSConnector;
-import org.eclipse.californium.scandium.config.DtlsConnectorConfig;
 
 /**
  * The CoAP producer.
@@ -97,35 +94,9 @@ public class CoAPProducer extends DefaultProducer {
             }
             client = new CoapClient(uri);
             
-            if (endpoint.getTruststore() != null) {
-                DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
-                builder.setClientOnly();
-
-                try {
-                    // Configure the identity if the keystore parameter is specified
-                    if (endpoint.getKeystore() != null) {
-                        if (endpoint.getAlias() == null) {
-                            throw new IllegalStateException("An alias must be configured to use TLS");
-                        }
-                        if (endpoint.getPassword() == null) {
-                            throw new IllegalStateException("A password must be configured to use TLS");
-                        }
-                        PrivateKey privateKey = 
-                            (PrivateKey)endpoint.getKeystore().getKey(endpoint.getAlias(), endpoint.getPassword());
-                        builder.setIdentity(privateKey, endpoint.getKeystore().getCertificateChain(endpoint.getAlias()));
-                    }
-
-                    // Add all certificates from the truststore
-                    builder.setTrustStore(endpoint.getTrustedCerts());
-                } catch (GeneralSecurityException e) {
-                    throw new IllegalStateException("Error in configuring TLS", e);
-                }
-
-                if (endpoint.getConfiguredCipherSuites() != null) {
-                    builder.setSupportedCipherSuites(endpoint.getConfiguredCipherSuites());
-                }
-
-                DTLSConnector connector = new DTLSConnector(builder.build());
+            // Configure TLS
+            if (CoAPEndpoint.enableTLS((uri))) {
+                DTLSConnector connector = endpoint.createDTLSConnector(null, true);
                 CoapEndpoint.Builder coapBuilder = new CoapEndpoint.Builder();
                 coapBuilder.setConnector(connector);
 


[camel] 02/21: Adding initial TLS support

Posted by co...@apache.org.
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 7765e80cb011ca15276dcba7cc90b031e6950d0f
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue Apr 9 16:01:30 2019 +0100

    Adding initial TLS support
---
 camel-core/readme.adoc                             | 82 +-----------------
 components/camel-coap/pom.xml                      |  5 ++
 .../camel-coap/src/main/docs/coap-component.adoc   |  3 +-
 .../java/org/apache/camel/coap/CoAPComponent.java  | 66 +++++++++++++--
 .../java/org/apache/camel/coap/CoAPEndpoint.java   | 17 +++-
 .../java/org/apache/camel/coap/CoAPProducer.java   | 46 ++++++++++
 .../services/org/apache/camel/component/coaps      | 18 ++++
 components/readme.adoc                             | 98 +++++++++++++++-------
 .../src/main/resources/camel-connector-schema.json |  2 +-
 .../src/main/resources/camel-connector.json        |  4 +-
 10 files changed, 221 insertions(+), 120 deletions(-)

diff --git a/camel-core/readme.adoc b/camel-core/readme.adoc
index 601cc9a..663462d 100644
--- a/camel-core/readme.adoc
+++ b/camel-core/readme.adoc
@@ -6,90 +6,18 @@ Components
 
 
 // components: START
-Number of Components: 26 in 1 JAR artifacts (1 deprecated)
+Number of Components: 2 in 1 JAR artifacts (1 deprecated)
 
 [width="100%",cols="4,1,5",options="header"]
 |===
 | Component | Available From | Description
 
-| link:src/main/docs/bean-component.adoc[Bean] (camel-core) +
-`bean:beanName` | 1.0 | The bean component is for invoking Java beans from Camel.
-
 | link:src/main/docs/binding-component.adoc[Binding] (camel-core) +
 `binding:bindingName:delegateUri` | 2.11 | *deprecated* The binding component is used for as a of wrapping an Endpoint in a contract with a data format.
 
-| link:src/main/docs/browse-component.adoc[Browse] (camel-core) +
-`browse:name` | 1.3 | The browse component is used for viewing the messages received on endpoints that supports BrowsableEndpoint.
-
-| link:src/main/docs/class-component.adoc[Class] (camel-core) +
-`class:beanName` | 2.4 | The Class Component is for invoking Java Classes (Java beans) from Camel.
-
-| link:src/main/docs/controlbus-component.adoc[Control Bus] (camel-core) +
-`controlbus:command:language` | 2.11 | The controlbus component provides easy management of Camel applications based on the Control Bus EIP pattern.
-
-| link:src/main/docs/dataformat-component.adoc[Data Format] (camel-core) +
-`dataformat:name:operation` | 2.12 | The dataformat component is used for working with Data Formats as if it was a regular Component supporting Endpoints and URIs.
-
-| link:src/main/docs/dataset-component.adoc[Dataset] (camel-core) +
-`dataset:name` | 1.3 | The dataset component provides a mechanism to easily perform load & soak testing of your system.
-
-| link:src/main/docs/direct-component.adoc[Direct] (camel-core) +
-`direct:name` | 1.0 | The direct component provides direct, synchronous call to another endpoint from the same CamelContext.
-
-| link:src/main/docs/direct-vm-component.adoc[Direct VM] (camel-core) +
-`direct-vm:name` | 2.10 | The direct-vm component provides direct, synchronous call to another endpoint from any CamelContext in the same JVM.
-
-| link:src/main/docs/file-component.adoc[File] (camel-core) +
-`file:directoryName` | 1.0 | The file component is used for reading or writing files.
-
-| link:src/main/docs/language-component.adoc[Language] (camel-core) +
-`language:languageName:resourceUri` | 2.5 | The language component allows you to send a message to an endpoint which executes a script by any of the supported Languages in Camel.
-
-| link:src/main/docs/log-component.adoc[Log] (camel-core) +
-`log:loggerName` | 1.1 | The log component logs message exchanges to the underlying logging mechanism.
-
-| link:src/main/docs/mock-component.adoc[Mock] (camel-core) +
-`mock:name` | 1.0 | The mock component is used for testing routes and mediation rules using mocks.
-
-| link:src/main/docs/properties-component.adoc[Properties] (camel-core) +
-`properties:key` | 2.3 | The properties component is used for using property placeholders in endpoint uris.
-
-| link:src/main/docs/ref-component.adoc[Ref] (camel-core) +
-`ref:name` | 1.2 | The ref component is used for lookup of existing endpoints bound in the Registry.
-
-| link:src/main/docs/rest-component.adoc[REST] (camel-core) +
-`rest:method:path:uriTemplate` | 2.14 | The rest component is used for either hosting REST services (consumer) or calling external REST services (producer).
-
-| link:src/main/docs/rest-api-component.adoc[REST API] (camel-core) +
-`rest-api:path/contextIdPattern` | 2.16 | The rest-api component is used for providing Swagger API of the REST services which has been defined using the rest-dsl in Camel.
-
-| link:src/main/docs/saga-component.adoc[Saga] (camel-core) +
-`saga:action` | 2.21 | The saga component provides access to advanced options for managing the flow in the Saga EIP.
-
-| link:src/main/docs/scheduler-component.adoc[Scheduler] (camel-core) +
-`scheduler:name` | 2.15 | The scheduler component is used for generating message exchanges when a scheduler fires.
-
-| link:src/main/docs/seda-component.adoc[SEDA] (camel-core) +
-`seda:name` | 1.1 | The seda component provides asynchronous call to another endpoint from any CamelContext in the same JVM.
-
-| link:src/main/docs/stub-component.adoc[Stub] (camel-core) +
-`stub:name` | 2.10 | The stub component provides a simple way to stub out any physical endpoints while in development or testing.
-
 | link:src/main/docs/test-component.adoc[Test] (camel-core) +
 `test:name` | 1.3 | The test component extends the mock component by on startup to pull messages from another endpoint to set the expected message bodies.
 
-| link:src/main/docs/timer-component.adoc[Timer] (camel-core) +
-`timer:timerName` | 1.0 | The timer component is used for generating message exchanges when a timer fires.
-
-| link:src/main/docs/validator-component.adoc[Validator] (camel-core) +
-`validator:resourceUri` | 1.1 | Validates the payload of a message using XML Schema and JAXP Validation.
-
-| link:src/main/docs/vm-component.adoc[VM] (camel-core) +
-`vm:name` | 1.1 | The vm component provides asynchronous call to another endpoint from the same CamelContext.
-
-| link:src/main/docs/xslt-component.adoc[XSLT] (camel-core) +
-`xslt:resourceUri` | 1.3 | Transforms the message using a XSLT template.
-
 |===
 // components: END
 
@@ -106,7 +34,7 @@ Data Formats
 
 
 // dataformats: START
-Number of Data Formats: 4 in 39 JAR artifacts (5 deprecated)
+Number of Data Formats: 4 in 42 JAR artifacts (6 deprecated)
 
 [width="100%",cols="4,1,5",options="header"]
 |===
@@ -136,14 +64,12 @@ Expression Languages
 
 
 // languages: START
-Number of Languages: 10 in 1 JAR artifacts (0 deprecated)
+Number of Languages: 8 in 1 JAR artifacts (0 deprecated)
 
 [width="100%",cols="4,1,5",options="header"]
 |===
 | Language | Available From | Description
 
-| link:src/main/docs/bean-language.adoc[Bean method] (camel-core) | 1.3 | To use a Java bean (aka method call) in Camel expressions or predicates.
-
 | link:src/main/docs/constant-language.adoc[Constant] (camel-core) | 1.5 | To use a constant value in Camel expressions or predicates.
 
 | link:src/main/docs/exchangeProperty-language.adoc[ExchangeProperty] (camel-core) | 2.0 | To use a Camel Exchange property in expressions or predicates.
@@ -159,8 +85,6 @@ Number of Languages: 10 in 1 JAR artifacts (0 deprecated)
 | link:src/main/docs/tokenize-language.adoc[Tokenize] (camel-core) | 2.0 | To use Camel message body or header with a tokenizer in Camel expressions or predicates.
 
 | link:src/main/docs/xtokenize-language.adoc[XML Tokenize] (camel-core) | 2.14 | To use Camel message body or header with a XML tokenizer in Camel expressions or predicates.
-
-| link:src/main/docs/xpath-language.adoc[XPath] (camel-core) | 1.1 | To use XPath (XML) in Camel expressions or predicates.
 |===
 // languages: END
 
diff --git a/components/camel-coap/pom.xml b/components/camel-coap/pom.xml
index 01d5154..11ebeba 100644
--- a/components/camel-coap/pom.xml
+++ b/components/camel-coap/pom.xml
@@ -47,6 +47,11 @@
       <artifactId>californium-core</artifactId>
       <version>${californium-version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.eclipse.californium</groupId>
+      <artifactId>scandium</artifactId>
+      <version>${californium-version}</version>
+    </dependency>
 
     <!-- logging -->    
     <dependency>
diff --git a/components/camel-coap/src/main/docs/coap-component.adoc b/components/camel-coap/src/main/docs/coap-component.adoc
index 0653f53..1517f4f 100644
--- a/components/camel-coap/src/main/docs/coap-component.adoc
+++ b/components/camel-coap/src/main/docs/coap-component.adoc
@@ -50,12 +50,13 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (5 parameters):
+==== Query Parameters (6 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
+| *keyStoreParameters* (common) | The KeyStoreParameters object to use with TLS |  | KeyStoreParameters
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
 | *coapMethodRestrict* (consumer) | Comma separated list of methods that the CoAP consumer will bind to. The default is to bind to all methods (DELETE, GET, POST, PUT). |  | String
 | *exceptionHandler* (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
index e6d1c85..dbd382b 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
@@ -16,7 +16,17 @@
  */
 package org.apache.camel.coap;
 
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -32,8 +42,11 @@ import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.HostUtils;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
+import org.apache.camel.util.jsse.KeyStoreParameters;
 import org.eclipse.californium.core.CoapServer;
-import org.eclipse.californium.core.network.config.NetworkConfig;
+import org.eclipse.californium.core.network.CoapEndpoint;
+import org.eclipse.californium.scandium.DTLSConnector;
+import org.eclipse.californium.scandium.config.DtlsConnectorConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -54,15 +67,56 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
         super(context, CoAPEndpoint.class);
     }
 
-    public synchronized CoapServer getServer(int port) {
+    public synchronized CoapServer getServer(int port, KeyStoreParameters keyStoreParameters) {
         CoapServer server = servers.get(port);
         if (server == null && port == -1) {
-            server = getServer(DEFAULT_PORT);
+            server = getServer(DEFAULT_PORT, keyStoreParameters);
         }
         if (server == null) {
-            NetworkConfig config = new NetworkConfig();
-            //FIXME- configure the network stuff
-            server = new CoapServer(config, port);
+            CoapEndpoint.Builder coapBuilder = new CoapEndpoint.Builder();
+            InetSocketAddress address = new InetSocketAddress(port);
+            
+            if (keyStoreParameters != null) {
+                DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
+                builder.setAddress(address);
+
+                try {
+                    KeyStore keyStore = keyStoreParameters.createKeyStore();
+                    // TODO
+                    PrivateKey privateKey = (PrivateKey)keyStoreParameters.createKeyStore().getKey("ec", "security".toCharArray());
+                    builder.setIdentity(privateKey, keyStore.getCertificateChain("ec"));
+
+                    // Add all certificates from the truststore
+                    Enumeration<String> aliases = keyStore.aliases();
+                    List<Certificate> trustCerts = new ArrayList<>();
+                    while (aliases.hasMoreElements()) {
+                        String alias = aliases.nextElement();
+                        X509Certificate cert =
+                                (X509Certificate) keyStore.getCertificate(alias);
+                        if (cert != null) {
+                            trustCerts.add(cert);
+                        }
+                    }
+                    builder.setTrustStore(trustCerts.toArray(new Certificate[0]));
+
+                } catch (GeneralSecurityException | IOException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+
+                builder.setClientAuthenticationRequired(false); //TODO
+
+                builder.setSupportedCipherSuites(new String[] {"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"}); //TODO
+
+                DTLSConnector connector = new DTLSConnector(builder.build());
+                coapBuilder.setConnector(connector);
+            } else {
+                coapBuilder.setInetSocketAddress(address);
+            }
+
+            server = new CoapServer();
+            server.addEndpoint(coapBuilder.build());
+            
             servers.put(port, server);
             if (this.isStarted()) {
                 server.start();
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 bc0e2f1..5e989b7 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
@@ -25,6 +25,7 @@ import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriPath;
+import org.apache.camel.util.jsse.KeyStoreParameters;
 import org.eclipse.californium.core.CoapServer;
 
 /**
@@ -36,6 +37,9 @@ public class CoAPEndpoint extends DefaultEndpoint {
     private URI uri;
     @UriParam(label = "consumer")
     private String coapMethodRestrict;
+    
+    @UriParam
+    private KeyStoreParameters keyStoreParameters;
         
     private CoAPComponent component;
     
@@ -84,6 +88,17 @@ public class CoAPEndpoint extends DefaultEndpoint {
     }
 
     public CoapServer getCoapServer() {
-        return component.getServer(getUri().getPort());
+        return component.getServer(getUri().getPort(), keyStoreParameters);
+    }
+    
+    /**
+     * The KeyStoreParameters object to use with TLS
+     */
+    public KeyStoreParameters getKeyStoreParameters() {
+        return keyStoreParameters;
+    }
+
+    public void setKeyStoreParameters(KeyStoreParameters keyStoreParameters) {
+        this.keyStoreParameters = keyStoreParameters;
     }
 }
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
index 4837193..c4bc8c9 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
@@ -16,7 +16,15 @@
  */
 package org.apache.camel.coap;
 
+import java.io.IOException;
 import java.net.URI;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
@@ -24,6 +32,9 @@ import org.apache.camel.impl.DefaultProducer;
 import org.eclipse.californium.core.CoapClient;
 import org.eclipse.californium.core.CoapResponse;
 import org.eclipse.californium.core.coap.MediaTypeRegistry;
+import org.eclipse.californium.core.network.CoapEndpoint;
+import org.eclipse.californium.scandium.DTLSConnector;
+import org.eclipse.californium.scandium.config.DtlsConnectorConfig;
 
 /**
  * The CoAP producer.
@@ -91,6 +102,41 @@ public class CoAPProducer extends DefaultProducer {
                 uri = endpoint.getUri();
             }
             client = new CoapClient(uri);
+            
+            if (endpoint.getKeyStoreParameters() != null) {
+                DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
+                builder.setClientOnly();
+
+                try {
+                    // TODO Add client key config if specified
+                    
+                    KeyStore keyStore = endpoint.getKeyStoreParameters().createKeyStore();
+                    // Add all certificates from the truststore
+                    Enumeration<String> aliases = keyStore.aliases();
+                    List<Certificate> trustCerts = new ArrayList<>();
+                    while (aliases.hasMoreElements()) {
+                        String alias = aliases.nextElement();
+                        X509Certificate cert =
+                                (X509Certificate) keyStore.getCertificate(alias);
+                        if (cert != null) {
+                            trustCerts.add(cert);
+                        }
+                    }
+                    builder.setTrustStore(trustCerts.toArray(new Certificate[0]));
+                } catch (GeneralSecurityException | IOException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+
+                builder.setSupportedCipherSuites(new String[] {"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"}); //TODO
+
+                DTLSConnector connector = new DTLSConnector(builder.build());
+                CoapEndpoint.Builder coapBuilder = new CoapEndpoint.Builder();
+                coapBuilder.setConnector(connector);
+
+                client.setEndpoint(coapBuilder.build());
+            }
+
         }
         return client;
     }
diff --git a/components/camel-coap/src/main/resources/META-INF/services/org/apache/camel/component/coaps b/components/camel-coap/src/main/resources/META-INF/services/org/apache/camel/component/coaps
new file mode 100644
index 0000000..e0129bc
--- /dev/null
+++ b/components/camel-coap/src/main/resources/META-INF/services/org/apache/camel/component/coaps
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.coap.CoAPComponent
diff --git a/components/readme.adoc b/components/readme.adoc
index 6ae13d7..ab2781f 100644
--- a/components/readme.adoc
+++ b/components/readme.adoc
@@ -2,12 +2,15 @@ Components
 ^^^^^^^^^^
 
 // components: START
-Number of Components: 311 in 211 JAR artifacts (24 deprecated)
+Number of Components: 321 in 242 JAR artifacts (24 deprecated)
 
 [width="100%",cols="4,1,5",options="header"]
 |===
 | Component | Available From | Description
 
+| link:camel-activemq/src/main/docs/activemq-component.adoc[ActiveMQ] (camel-activemq) +
+`activemq:destinationType:destinationName` | 1.0 | The activemq component allows messages to be sent to (or consumed from) Apache ActiveMQ. This component extends the Camel JMS component.
+
 | link:camel-ahc/src/main/docs/ahc-component.adoc[AHC] (camel-ahc) +
 `ahc:httpUri` | 2.8 | To call external HTTP services using Async Http Client.
 
@@ -77,6 +80,12 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-aws/src/main/docs/aws-ec2-component.adoc[AWS EC2] (camel-aws) +
 `aws-ec2:label` | 2.16 | The aws-ec2 is used for managing Amazon EC2 instances.
 
+| link:camel-aws-ecs/src/main/docs/aws-ecs-component.adoc[AWS ECS] (camel-aws-ecs) +
+`aws-ecs:label` | 3.0 | The aws-kms is used for managing Amazon ECS
+
+| link:camel-aws-eks/src/main/docs/aws-eks-component.adoc[AWS EKS] (camel-aws-eks) +
+`aws-eks:label` | 3.0 | The aws-kms is used for managing Amazon EKS
+
 | link:camel-aws/src/main/docs/aws-iam-component.adoc[AWS IAM] (camel-aws) +
 `aws-iam:label` | 2.23 | The aws-iam is used for managing Amazon IAM
 
@@ -95,6 +104,9 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-aws/src/main/docs/aws-mq-component.adoc[AWS MQ] (camel-aws) +
 `aws-mq:label` | 2.21 | The aws-mq is used for managing Amazon MQ instances.
 
+| link:camel-aws-msk/src/main/docs/aws-msk-component.adoc[AWS MSK] (camel-aws-msk) +
+`aws-msk:label` | 3.0 | The aws-kms is used for managing Amazon KMS
+
 | link:camel-aws/src/main/docs/aws-s3-component.adoc[AWS S3 Storage Service] (camel-aws) +
 `aws-s3:bucketNameOrArn` | 2.8 | The aws-s3 component is used for storing and retrieving objecct from Amazon S3 Storage Service.
 
@@ -119,7 +131,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-azure/src/main/docs/azure-queue-component.adoc[Azure Storage Queue Service] (camel-azure) +
 `azure-queue:containerAndQueueUri` | 2.19 | The azure-queue component is used for storing and retrieving messages from Azure Storage Queue Service.
 
-| link:../camel-core/src/main/docs/bean-component.adoc[Bean] (camel-core) +
+| link:camel-bean/src/main/docs/bean-component.adoc[Bean] (camel-bean) +
 `bean:beanName` | 1.0 | The bean component is for invoking Java beans from Camel.
 
 | link:camel-bean-validator/src/main/docs/bean-validator-component.adoc[Bean Validator] (camel-bean-validator) +
@@ -140,7 +152,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-braintree/src/main/docs/braintree-component.adoc[Braintree] (camel-braintree) +
 `braintree:apiName/methodName` | 2.17 | The braintree component is used for integrating with the Braintree Payment System.
 
-| link:../camel-core/src/main/docs/browse-component.adoc[Browse] (camel-core) +
+| link:camel-browse/src/main/docs/browse-component.adoc[Browse] (camel-browse) +
 `browse:name` | 1.3 | The browse component is used for viewing the messages received on endpoints that supports BrowsableEndpoint.
 
 | link:camel-caffeine/src/main/docs/caffeine-cache-component.adoc[Caffeine Cache] (camel-caffeine) +
@@ -155,14 +167,17 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-cassandraql/src/main/docs/cql-component.adoc[Cassandra CQL] (camel-cassandraql) +
 `cql:beanRef:hosts:port/keyspace` | 2.15 | The cql component aims at integrating Cassandra 2.0 using the CQL3 API (not the Thrift API).
 
+| link:camel-chatscript/src/main/docs/chatscript-component.adoc[ChatScript] (camel-chatscript) +
+`chatscript:host:port/botname` | 3.0 | Represents a ChatScript endpoint.
+
 | link:camel-chronicle/src/main/docs/chronicle-engine-component.adoc[Chronicle Engine] (camel-chronicle) +
 `chronicle-engine:addresses/path` | 2.18 | *deprecated* The camel chronicle-engine component let you leverage the power of OpenHFT's Chronicle-Engine.
 
 | link:camel-chunk/src/main/docs/chunk-component.adoc[Chunk] (camel-chunk) +
 `chunk:resourceUri` | 2.15 | Transforms the message using a Chunk template.
 
-| link:../camel-core/src/main/docs/class-component.adoc[Class] (camel-core) +
-`class:beanName` | 2.4 | The Class Component is for invoking Java Classes (Java beans) from Camel.
+| link:camel-bean/src/main/docs/class-component.adoc[Class] (camel-bean) +
+`class:beanName` | 2.4 | The class component is for invoking Java classes (Java beans) from Camel.
 
 | link:camel-cm-sms/src/main/docs/cm-sms-component.adoc[CM SMS Gateway] (camel-cm-sms) +
 `cm-sms:host` | 2.18 | The cm-sms component allows to integrate with CM SMS Gateway.
@@ -179,7 +194,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-consul/src/main/docs/consul-component.adoc[Consul] (camel-consul) +
 `consul:apiEndpoint` | 2.18 | The camel consul component allows you to work with Consul, a distributed, highly available, datacenter-aware, service discovery and configuration system.
 
-| link:../camel-core/src/main/docs/controlbus-component.adoc[Control Bus] (camel-core) +
+| link:camel-controlbus/src/main/docs/controlbus-component.adoc[Control Bus] (camel-controlbus) +
 `controlbus:command:language` | 2.11 | The controlbus component provides easy management of Camel applications based on the Control Bus EIP pattern.
 
 | link:camel-corda/src/main/docs/corda-component.adoc[corda] (camel-corda) +
@@ -203,19 +218,22 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-cxf/src/main/docs/cxfrs-component.adoc[CXF-RS] (camel-cxf) +
 `cxfrs:beanId:address` | 2.0 | The cxfrs component is used for JAX-RS REST services using Apache CXF.
 
-| link:../camel-core/src/main/docs/dataformat-component.adoc[Data Format] (camel-core) +
+| link:camel-dataformat/src/main/docs/dataformat-component.adoc[Data Format] (camel-dataformat) +
 `dataformat:name:operation` | 2.12 | The dataformat component is used for working with Data Formats as if it was a regular Component supporting Endpoints and URIs.
 
-| link:../camel-core/src/main/docs/dataset-component.adoc[Dataset] (camel-core) +
+| link:camel-dataset/src/main/docs/dataset-component.adoc[Dataset] (camel-dataset) +
 `dataset:name` | 1.3 | The dataset component provides a mechanism to easily perform load & soak testing of your system.
 
+| link:camel-dataset/src/main/docs/dataset-test-component.adoc[DataSet Test] (camel-dataset) +
+`dataset-test:name` | 1.3 | The dataset-test component extends the mock component by on startup to pull messages from another endpoint to set the expected message bodies.
+
 | link:camel-digitalocean/src/main/docs/digitalocean-component.adoc[DigitalOcean] (camel-digitalocean) +
 `digitalocean:operation` | 2.19 | The DigitalOcean component allows you to manage Droplets and resources within the DigitalOcean cloud.
 
-| link:../camel-core/src/main/docs/direct-component.adoc[Direct] (camel-core) +
+| link:camel-direct/src/main/docs/direct-component.adoc[Direct] (camel-direct) +
 `direct:name` | 1.0 | The direct component provides direct, synchronous call to another endpoint from the same CamelContext.
 
-| link:../camel-core/src/main/docs/direct-vm-component.adoc[Direct VM] (camel-core) +
+| link:camel-directvm/src/main/docs/direct-vm-component.adoc[Direct VM] (camel-directvm) +
 `direct-vm:name` | 2.10 | The direct-vm component provides direct, synchronous call to another endpoint from any CamelContext in the same JVM.
 
 | link:camel-disruptor/src/main/docs/disruptor-component.adoc[Disruptor] (camel-disruptor) +
@@ -269,7 +287,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-fhir/camel-fhir-component/src/main/docs/fhir-component.adoc[FHIR] (camel-fhir) +
 `fhir:apiName/methodName` | 2.23 | The fhir component is used for working with the FHIR protocol (health care).
 
-| link:../camel-core/src/main/docs/file-component.adoc[File] (camel-core) +
+| link:camel-file/src/main/docs/file-component.adoc[File] (camel-file) +
 `file:directoryName` | 1.0 | The file component is used for reading or writing files.
 
 | link:camel-flatpack/src/main/docs/flatpack-component.adoc[Flatpack] (camel-flatpack) +
@@ -488,6 +506,9 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-jolt/src/main/docs/jolt-component.adoc[JOLT] (camel-jolt) +
 `jolt:resourceUri` | 2.16 | The jolt component allows you to process a JSON messages using an JOLT specification (such as JSON-JSON transformation).
 
+| link:camel-jooq/src/main/docs/jooq-component.adoc[JOOQ] (camel-jooq) +
+`jooq:entityType` | 3.0 | The jooq component enables you to store and retrieve entities from databases using JOOQ
+
 | link:camel-jpa/src/main/docs/jpa-component.adoc[JPA] (camel-jpa) +
 `jpa:entityType` | 1.0 | The jpa component enables you to store and retrieve Java objects from databases using JPA.
 
@@ -551,7 +572,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-kubernetes/src/main/docs/kubernetes-services-component.adoc[Kubernetes Services] (camel-kubernetes) +
 `kubernetes-services:masterUrl` | 2.17 | The Kubernetes Service Accounts component provides a producer to execute service operations and a consumer to consume service events.
 
-| link:../camel-core/src/main/docs/language-component.adoc[Language] (camel-core) +
+| link:camel-language/src/main/docs/language-component.adoc[Language] (camel-language) +
 `language:languageName:resourceUri` | 2.5 | The language component allows you to send a message to an endpoint which executes a script by any of the supported Languages in Camel.
 
 | link:camel-ldap/src/main/docs/ldap-component.adoc[LDAP] (camel-ldap) +
@@ -563,7 +584,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-linkedin/camel-linkedin-component/src/main/docs/linkedin-component.adoc[Linkedin] (camel-linkedin) +
 `linkedin:apiName/methodName` | 2.14 | The linkedin component is used for retrieving LinkedIn user profiles, connections, companies, groups, posts, etc.
 
-| link:../camel-core/src/main/docs/log-component.adoc[Log] (camel-core) +
+| link:camel-log/src/main/docs/log-component.adoc[Log] (camel-log) +
 `log:loggerName` | 1.1 | The log component logs message exchanges to the underlying logging mechanism.
 
 | link:camel-lucene/src/main/docs/lucene-component.adoc[Lucene] (camel-lucene) +
@@ -593,7 +614,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-mllp/src/main/docs/mllp-component.adoc[MLLP] (camel-mllp) +
 `mllp:hostname:port` | 2.17 | Provides functionality required by Healthcare providers to communicate with other systems using the MLLP protocol.
 
-| link:../camel-core/src/main/docs/mock-component.adoc[Mock] (camel-core) +
+| link:camel-mock/src/main/docs/mock-component.adoc[Mock] (camel-mock) +
 `mock:name` | 1.0 | The mock component is used for testing routes and mediation rules using mocks.
 
 | link:camel-mongodb/src/main/docs/mongodb-component.adoc[MongoDB] (camel-mongodb) +
@@ -704,7 +725,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-printer/src/main/docs/lpr-component.adoc[Printer] (camel-printer) +
 `lpr:hostname:port/printername` | 2.1 | The printer component is used for sending messages to printers as print jobs.
 
-| link:../camel-core/src/main/docs/properties-component.adoc[Properties] (camel-core) +
+| link:camel-properties/src/main/docs/properties-component.adoc[Properties] (camel-properties) +
 `properties:key` | 2.3 | The properties component is used for using property placeholders in endpoint uris.
 
 | link:camel-pubnub/src/main/docs/pubnub-component.adoc[PubNub] (camel-pubnub) +
@@ -725,13 +746,13 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-reactive-streams/src/main/docs/reactive-streams-component.adoc[Reactive Streams] (camel-reactive-streams) +
 `reactive-streams:stream` | 2.19 | Reactive Camel using reactive streams
 
-| link:../camel-core/src/main/docs/ref-component.adoc[Ref] (camel-core) +
+| link:camel-ref/src/main/docs/ref-component.adoc[Ref] (camel-ref) +
 `ref:name` | 1.2 | The ref component is used for lookup of existing endpoints bound in the Registry.
 
-| link:../camel-core/src/main/docs/rest-component.adoc[REST] (camel-core) +
+| link:camel-rest/src/main/docs/rest-component.adoc[REST] (camel-rest) +
 `rest:method:path:uriTemplate` | 2.14 | The rest component is used for either hosting REST services (consumer) or calling external REST services (producer).
 
-| link:../camel-core/src/main/docs/rest-api-component.adoc[REST API] (camel-core) +
+| link:camel-rest/src/main/docs/rest-api-component.adoc[REST API] (camel-rest) +
 `rest-api:path/contextIdPattern` | 2.16 | The rest-api component is used for providing Swagger API of the REST services which has been defined using the rest-dsl in Camel.
 
 | link:camel-rest-swagger/src/main/docs/rest-swagger-component.adoc[REST Swagger] (camel-rest-swagger) +
@@ -749,7 +770,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-rss/src/main/docs/rss-component.adoc[RSS] (camel-rss) +
 `rss:feedUri` | 2.0 | The rss component is used for consuming RSS feeds.
 
-| link:../camel-core/src/main/docs/saga-component.adoc[Saga] (camel-core) +
+| link:camel-saga/src/main/docs/saga-component.adoc[Saga] (camel-saga) +
 `saga:action` | 2.21 | The saga component provides access to advanced options for managing the flow in the Saga EIP.
 
 | link:camel-salesforce/camel-salesforce-component/src/main/docs/salesforce-component.adoc[Salesforce] (camel-salesforce) +
@@ -758,7 +779,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-sap-netweaver/src/main/docs/sap-netweaver-component.adoc[SAP NetWeaver] (camel-sap-netweaver) +
 `sap-netweaver:url` | 2.12 | The sap-netweaver component integrates with the SAP NetWeaver Gateway using HTTP transports.
 
-| link:../camel-core/src/main/docs/scheduler-component.adoc[Scheduler] (camel-core) +
+| link:camel-scheduler/src/main/docs/scheduler-component.adoc[Scheduler] (camel-scheduler) +
 `scheduler:name` | 2.15 | The scheduler component is used for generating message exchanges when a scheduler fires.
 
 | link:camel-schematron/src/main/docs/schematron-component.adoc[Schematron] (camel-schematron) +
@@ -767,7 +788,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-jsch/src/main/docs/scp-component.adoc[SCP] (camel-jsch) +
 `scp:host:port/directoryName` | 2.10 | To copy files using the secure copy protocol (SCP).
 
-| link:../camel-core/src/main/docs/seda-component.adoc[SEDA] (camel-core) +
+| link:camel-seda/src/main/docs/seda-component.adoc[SEDA] (camel-seda) +
 `seda:name` | 1.1 | The seda component provides asynchronous call to another endpoint from any CamelContext in the same JVM.
 
 | link:camel-service/src/main/docs/service-component.adoc[Service] (camel-service) +
@@ -806,6 +827,9 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-solr/src/main/docs/solr-component.adoc[Solr] (camel-solr) +
 `solr:url` | 2.9 | The solr component allows you to interface with an Apache Lucene Solr server.
 
+| link:camel-soroush/src/main/docs/soroush-component.adoc[Soroush] (camel-soroush) +
+`soroush:endpoint/authorizationToken` | 3.0 | To integrate with the Soroush chat bot.
+
 | link:camel-spark-rest/src/main/docs/spark-rest-component.adoc[Spark Rest] (camel-spark-rest) +
 `spark-rest:verb:path` | 2.14 | The spark-rest component is used for hosting REST services which has been defined using Camel rest-dsl.
 
@@ -851,7 +875,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-stringtemplate/src/main/docs/string-template-component.adoc[String Template] (camel-stringtemplate) +
 `string-template:resourceUri` | 1.2 | Transforms the message using a String template.
 
-| link:../camel-core/src/main/docs/stub-component.adoc[Stub] (camel-core) +
+| link:camel-stub/src/main/docs/stub-component.adoc[Stub] (camel-stub) +
 `stub:name` | 2.10 | The stub component provides a simple way to stub out any physical endpoints while in development or testing.
 
 | link:camel-telegram/src/main/docs/telegram-component.adoc[Telegram] (camel-telegram) +
@@ -866,7 +890,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-tika/src/main/docs/tika-component.adoc[Tika] (camel-tika) +
 `tika:operation` | 2.19 | This component integrates with Apache Tika to extract content and metadata from thousands of file types.
 
-| link:../camel-core/src/main/docs/timer-component.adoc[Timer] (camel-core) +
+| link:camel-timer/src/main/docs/timer-component.adoc[Timer] (camel-timer) +
 `timer:timerName` | 1.0 | The timer component is used for generating message exchanges when a timer fires.
 
 | link:camel-twilio/src/main/docs/twilio-component.adoc[Twilio] (camel-twilio) +
@@ -890,7 +914,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-undertow/src/main/docs/undertow-component.adoc[Undertow] (camel-undertow) +
 `undertow:httpURI` | 2.16 | The undertow component provides HTTP and WebSocket based endpoints for consuming and producing HTTP/WebSocket requests.
 
-| link:../camel-core/src/main/docs/validator-component.adoc[Validator] (camel-core) +
+| link:camel-validator/src/main/docs/validator-component.adoc[Validator] (camel-validator) +
 `validator:resourceUri` | 1.1 | Validates the payload of a message using XML Schema and JAXP Validation.
 
 | link:camel-velocity/src/main/docs/velocity-component.adoc[Velocity] (camel-velocity) +
@@ -899,7 +923,7 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-vertx/src/main/docs/vertx-component.adoc[Vert.x] (camel-vertx) +
 `vertx:address` | 2.12 | The vertx component is used for sending and receive messages from a vertx event bus.
 
-| link:../camel-core/src/main/docs/vm-component.adoc[VM] (camel-core) +
+| link:camel-vm/src/main/docs/vm-component.adoc[VM] (camel-vm) +
 `vm:name` | 1.1 | The vm component provides asynchronous call to another endpoint from the same CamelContext.
 
 | link:camel-weather/src/main/docs/weather-component.adoc[Weather] (camel-weather) +
@@ -908,6 +932,9 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-web3j/src/main/docs/web3j-component.adoc[Web3j Ethereum Blockchain] (camel-web3j) +
 `web3j:nodeAddress` | 2.22 | The web3j component uses the Web3j client API and allows you to add/read nodes to/from a web3j compliant content repositories.
 
+| link:camel-webhook/src/main/docs/webhook-component.adoc[Webhook] (camel-webhook) +
+`webhook:endpointUri` | 3.0 | The webhook component allows other Camel components that can receive push notifications to expose webhook endpoints and automatically register them with their own webhook provider.
+
 | link:camel-wordpress/src/main/docs/wordpress-component.adoc[Wordpress] (camel-wordpress) +
 `wordpress:operationDetail` | 2.21 | Integrates Camel with Wordpress.
 
@@ -926,9 +953,12 @@ Number of Components: 311 in 211 JAR artifacts (24 deprecated)
 | link:camel-saxon/src/main/docs/xquery-component.adoc[XQuery] (camel-saxon) +
 `xquery:resourceUri` | 1.0 | Transforms the message using a XQuery template using Saxon.
 
-| link:../camel-core/src/main/docs/xslt-component.adoc[XSLT] (camel-core) +
+| link:camel-xslt/src/main/docs/xslt-component.adoc[XSLT] (camel-xslt) +
 `xslt:resourceUri` | 1.3 | Transforms the message using a XSLT template.
 
+| link:camel-yql/src/main/docs/yql-component.adoc[Yahoo Query Language] (camel-yql) +
+`yql:query` | 2.21 | The YQL (Yahoo! Query Language) platform enables you to query, filter, and combine data across the web.
+
 | link:camel-yammer/src/main/docs/yammer-component.adoc[Yammer] (camel-yammer) +
 `yammer:function` | 2.12 | The yammer component allows you to interact with the Yammer enterprise social network.
 
@@ -949,7 +979,7 @@ Data Formats
 ^^^^^^^^^^^^
 
 // dataformats: START
-Number of Data Formats: 49 in 39 JAR artifacts (5 deprecated)
+Number of Data Formats: 53 in 42 JAR artifacts (6 deprecated)
 
 [width="100%",cols="4,1,5",options="header"]
 |===
@@ -987,6 +1017,8 @@ Number of Data Formats: 49 in 39 JAR artifacts (5 deprecated)
 
 | link:../camel-core/src/main/docs/gzip-dataformat.adoc[GZip] (camel-core) | 2.0 | The GZip data format is a message compression and de-compression format (which works with the popular gzip/gunzip tools).
 
+| link:camel-zip-deflater/src/main/docs/gzipdeflater-dataformat.adoc[GZip Deflater] (camel-zip-deflater) | 2.0 | The GZip data format is a message compression and de-compression format (which works with the popular gzip/gunzip tools).
+
 | link:camel-hessian/src/main/docs/hessian-dataformat.adoc[Hessian] (camel-hessian) | 2.17 | *deprecated* Hessian data format is used for marshalling and unmarshalling messages using Cauchos Hessian format.
 
 | link:camel-hl7/src/main/docs/hl7-dataformat.adoc[HL7] (camel-hl7) | 2.0 | The HL7 data format can be used to marshal or unmarshal HL7 (Health Care) model objects.
@@ -1011,6 +1043,8 @@ Number of Data Formats: 49 in 39 JAR artifacts (5 deprecated)
 
 | link:camel-xstream/src/main/docs/json-xstream-dataformat.adoc[JSon XStream] (camel-xstream) | 2.0 | JSon data format is used for unmarshal a JSon payload to POJO or to marshal POJO back to JSon payload.
 
+| link:camel-jsonapi/src/main/docs/jsonApi-dataformat.adoc[jsonApi] (camel-jsonapi) | 3.0 | JsonApi data format is used for marshal and unmarshal Json API object.
+
 | link:camel-lzf/src/main/docs/lzf-dataformat.adoc[LZF Deflate Compression] (camel-lzf) | 2.17 | The LZF data format is a message compression and de-compression format (uses the LZF deflate algorithm).
 
 | link:camel-mail/src/main/docs/mime-multipart-dataformat.adoc[MIME Multipart] (camel-mail) | 2.17 | The MIME Multipart data format can marshal a Camel message with attachments into a Camel message having a MIME-Multipart message as message body (and no attachments), and vise-versa when unmarshalling.
@@ -1041,6 +1075,8 @@ Number of Data Formats: 49 in 39 JAR artifacts (5 deprecated)
 
 | link:camel-xmlbeans/src/main/docs/xmlBeans-dataformat.adoc[XML Beans] (camel-xmlbeans) | 1.2 | *deprecated* XML Beans data format is used for unmarshal a XML payload to POJO or to marshal POJO back to XML payload.
 
+| link:camel-xmljson/src/main/docs/xmljson-dataformat.adoc[XML JSon] (camel-xmljson) | 2.10 | *deprecated* XML JSon data format can convert from XML to JSON and vice-versa directly, without stepping through intermediate POJOs.
+
 | link:camel-xmlrpc/src/main/docs/xmlrpc-dataformat.adoc[XML RPC] (camel-xmlrpc) | 2.11 | The XML RPC data format is used for working with the XML RPC protocol.
 
 | link:camel-xmlsecurity/src/main/docs/secureXML-dataformat.adoc[XML Security] (camel-xmlsecurity) | 2.0 | The XML Security data format facilitates encryption and decryption of XML payloads.
@@ -1051,6 +1087,8 @@ Number of Data Formats: 49 in 39 JAR artifacts (5 deprecated)
 
 | link:../camel-core/src/main/docs/zip-dataformat.adoc[Zip Deflate Compression] (camel-core) | 2.12 | Zip Deflate Compression data format is a message compression and de-compression format (not zip files).
 
+| link:camel-zip-deflater/src/main/docs/zipdeflater-dataformat.adoc[Zip Deflate Compression] (camel-zip-deflater) | 2.12 | Zip Deflate Compression data format is a message compression and de-compression format (not zip files).
+
 | link:camel-zipfile/src/main/docs/zipfile-dataformat.adoc[Zip File] (camel-zipfile) | 2.11 | The Zip File data format is a message compression and de-compression format of zip files.
 |===
 // dataformats: END
@@ -1060,13 +1098,13 @@ Expression Languages
 ^^^^^^^^^^^^^^^^^^^^
 
 // languages: START
-Number of Languages: 24 in 12 JAR artifacts (7 deprecated)
+Number of Languages: 24 in 14 JAR artifacts (7 deprecated)
 
 [width="100%",cols="4,1,5",options="header"]
 |===
 | Language | Available From | Description
 
-| link:../camel-core/src/main/docs/bean-language.adoc[Bean method] (camel-core) | 1.3 | To use a Java bean (aka method call) in Camel expressions or predicates.
+| link:camel-bean/src/main/docs/bean-language.adoc[Bean method] (camel-bean) | 1.3 | To use a Java bean (aka method call) in Camel expressions or predicates.
 
 | link:../camel-core/src/main/docs/constant-language.adoc[Constant] (camel-core) | 1.5 | To use a constant value in Camel expressions or predicates.
 
@@ -1110,7 +1148,7 @@ Number of Languages: 24 in 12 JAR artifacts (7 deprecated)
 
 | link:../camel-core/src/main/docs/xtokenize-language.adoc[XML Tokenize] (camel-core) | 2.14 | To use Camel message body or header with a XML tokenizer in Camel expressions or predicates.
 
-| link:../camel-core/src/main/docs/xpath-language.adoc[XPath] (camel-core) | 1.1 | To use XPath (XML) in Camel expressions or predicates.
+| link:camel-xpath/src/main/docs/xpath-language.adoc[XPath] (camel-xpath) | 1.1 | To use XPath (XML) in Camel expressions or predicates.
 
 | link:camel-saxon/src/main/docs/xquery-language.adoc[XQuery] (camel-saxon) | 1.0 | To use XQuery (XML) in Camel expressions or predicates.
 |===
diff --git a/platforms/myfoo-connector/src/main/resources/camel-connector-schema.json b/platforms/myfoo-connector/src/main/resources/camel-connector-schema.json
index 6a1becb..292a6b6 100644
--- a/platforms/myfoo-connector/src/main/resources/camel-connector-schema.json
+++ b/platforms/myfoo-connector/src/main/resources/camel-connector-schema.json
@@ -14,7 +14,7 @@
     "javaType":"org.myfoo.connector.MyFooComponent",
     "groupId":"org.apache.camel",
     "artifactId":"myfoo-connector",
-    "version":"2.24.1-SNAPSHOT"
+    "version":"2.25.0-SNAPSHOT"
   },
   "componentProperties":{
     
diff --git a/platforms/myfoo-connector/src/main/resources/camel-connector.json b/platforms/myfoo-connector/src/main/resources/camel-connector.json
index 27f90c1..70bfe19 100644
--- a/platforms/myfoo-connector/src/main/resources/camel-connector.json
+++ b/platforms/myfoo-connector/src/main/resources/camel-connector.json
@@ -2,14 +2,14 @@
   "baseScheme" : "timer",
   "baseGroupId" : "org.apache.camel",
   "baseArtifactId" : "camel-core",
-  "baseVersion" : "2.24.1-SNAPSHOT",
+  "baseVersion" : "2.25.0-SNAPSHOT",
   "baseJavaType" : "org.apache.camel.component.timer.TimerComponent",
   "name" : "MyFoo",
   "scheme" : "my-foo",
   "javaType" : "org.myfoo.connector.MyFooComponent",
   "groupId" : "org.myfoo",
   "artifactId" : "myfoo-connector",
-  "version" : "2.24.1-SNAPSHOT",
+  "version" : "2.25.0-SNAPSHOT",
   "description" : "Something cool",
   "labels" : [ "foo", "timer" ],
   "pattern" : "From",


[camel] 17/21: Doc change

Posted by co...@apache.org.
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 33edefe5fa8950f0947ec78901a4439ef36e64a6
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon Apr 29 12:55:46 2019 +0100

    Doc change


[camel] 10/21: Updating the certs to use the right curves

Posted by co...@apache.org.
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 8d6374b474e2877f31147be70cb372e18d4b999d
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue Apr 23 17:37:05 2019 +0100

    Updating the certs to use the right curves
---
 components/camel-coap/src/test/resources/client.jks   | Bin 2306 -> 1968 bytes
 .../camel-coap/src/test/resources/selfsigned.jks      | Bin 701 -> 706 bytes
 components/camel-coap/src/test/resources/service.jks  | Bin 2308 -> 1969 bytes
 .../camel-coap/src/test/resources/truststore.jks      | Bin 717 -> 582 bytes
 .../camel-coap/src/test/resources/truststore2.jks     | Bin 717 -> 582 bytes
 5 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/components/camel-coap/src/test/resources/client.jks b/components/camel-coap/src/test/resources/client.jks
index 99c9b86..bbc0cdc 100644
Binary files a/components/camel-coap/src/test/resources/client.jks and b/components/camel-coap/src/test/resources/client.jks differ
diff --git a/components/camel-coap/src/test/resources/selfsigned.jks b/components/camel-coap/src/test/resources/selfsigned.jks
index ee745ff..3c0608f 100644
Binary files a/components/camel-coap/src/test/resources/selfsigned.jks and b/components/camel-coap/src/test/resources/selfsigned.jks differ
diff --git a/components/camel-coap/src/test/resources/service.jks b/components/camel-coap/src/test/resources/service.jks
index 40d24df..52321ad 100644
Binary files a/components/camel-coap/src/test/resources/service.jks and b/components/camel-coap/src/test/resources/service.jks differ
diff --git a/components/camel-coap/src/test/resources/truststore.jks b/components/camel-coap/src/test/resources/truststore.jks
index 2a7c179..44d82a85 100644
Binary files a/components/camel-coap/src/test/resources/truststore.jks and b/components/camel-coap/src/test/resources/truststore.jks differ
diff --git a/components/camel-coap/src/test/resources/truststore2.jks b/components/camel-coap/src/test/resources/truststore2.jks
index 94249d6..9f053de 100644
Binary files a/components/camel-coap/src/test/resources/truststore2.jks and b/components/camel-coap/src/test/resources/truststore2.jks differ


[camel] 11/21: Added initial support for raw public keys

Posted by co...@apache.org.
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 39538df0660bc3fd1935970a25e95e219bd7cb00
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Wed Apr 24 11:52:08 2019 +0100

    Added initial support for raw public keys
---
 .../camel-coap/src/main/docs/coap-component.adoc   |  5 +-
 .../java/org/apache/camel/coap/CoAPEndpoint.java   | 82 +++++++++++++++++++---
 .../apache/camel/coap/CoAPComponentTLSTest.java    | 36 ++++++++++
 3 files changed, 113 insertions(+), 10 deletions(-)

diff --git a/components/camel-coap/src/main/docs/coap-component.adoc b/components/camel-coap/src/main/docs/coap-component.adoc
index 0ac6390..1c7f280 100644
--- a/components/camel-coap/src/main/docs/coap-component.adoc
+++ b/components/camel-coap/src/main/docs/coap-component.adoc
@@ -50,7 +50,7 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (12 parameters):
+==== Query Parameters (15 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -60,6 +60,9 @@ with the following path and query parameters:
 | *cipherSuites* (common) | Sets the cipherSuites String. This is a comma separated String of ciphersuites to configure. |  | String
 | *keystore* (common) | Sets the TLS key store. Alternatively, a KeyStoreParameters object can be configured instead. An alias and password should also be configured on the route definition. |  | KeyStore
 | *keyStoreParameters* (common) | The KeyStoreParameters object to use with TLS to configure the keystore. Alternatively, a keystore parameter can be directly configured instead. An alias and password should also be configured on the route definition. |  | KeyStoreParameters
+| *privateKey* (common) | Set the configured private key for use with Raw Public Key. |  | PrivateKey
+| *publicKey* (common) | Set the configured public key for use with Raw Public Key. |  | PublicKey
+| *trustedRpkStore* (common) | Set the TrustedRpkStore to use to determine trust in raw public keys. |  | TrustedRpkStore
 | *truststore* (common) | Sets the TLS trust store. Alternatively, a trustStoreParameters object can be configured instead. All certificates in the truststore are used to establish trust. |  | KeyStore
 | *trustStoreParameters* (common) | The KeyStoreParameters object to use with TLS to configure the truststore. Alternatively, a truststore object can be directly configured instead. All certificates in the truststore are used to establish trust. |  | KeyStoreParameters
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
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 e2d9dbb..926bc24 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
@@ -23,6 +23,7 @@ import java.security.GeneralSecurityException;
 import java.security.KeyStore;
 import java.security.KeyStoreException;
 import java.security.PrivateKey;
+import java.security.PublicKey;
 import java.security.cert.Certificate;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
@@ -41,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.rpkstore.TrustedRpkStore;
 
 /**
  * The coap component is used for sending and receiving messages from COAP capable devices.
@@ -63,7 +65,16 @@ public class CoAPEndpoint extends DefaultEndpoint {
     
     @UriParam
     private KeyStore truststore;
-    
+
+    @UriParam
+    private PrivateKey privateKey;
+
+    @UriParam
+    private PublicKey publicKey;
+
+    @UriParam
+    private TrustedRpkStore trustedRpkStore;
+
     @UriParam
     private String alias;
     
@@ -202,8 +213,50 @@ public class CoAPEndpoint extends DefaultEndpoint {
     public void setAlias(String alias) {
         this.alias = alias;
     }
+
+    /**
+     * Get the TrustedRpkStore to use to determine trust in raw public keys.
+     */
+    public TrustedRpkStore getTrustedRpkStore() {
+        return trustedRpkStore;
+    }
+
+    /**
+     * Set the TrustedRpkStore to use to determine trust in raw public keys.
+     */
+    public void setTrustedRpkStore(TrustedRpkStore trustedRpkStore) {
+        this.trustedRpkStore = trustedRpkStore;
+    }
     
     /**
+     * Get the configured private key for use with Raw Public Key.
+     */
+    public PrivateKey getPrivateKey() {
+        return privateKey;
+    }
+
+    /**
+     * Set the configured private key for use with Raw Public Key.
+     */
+    public void setPrivateKey(PrivateKey privateKey) {
+        this.privateKey = privateKey;
+    }
+
+    /**
+     * Get the configured public key for use with Raw Public Key.
+     */
+    public PublicKey getPublicKey() {
+        return publicKey;
+    }
+
+    /**
+     * Set the configured public key for use with Raw Public Key.
+     */
+    public void setPublicKey(PublicKey publicKey) {
+        this.publicKey = publicKey;
+    }
+
+    /**
      * Gets the password used to access an aliased {@link PrivateKey} in the KeyStore.
      */
     public char[] getPassword() {
@@ -293,19 +346,22 @@ public class CoAPEndpoint extends DefaultEndpoint {
 
         DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
         if (client) {
-            if (getTruststore() == null) {
+            if (trustedRpkStore == null && getTruststore() == null) {
                 throw new IllegalStateException("A truststore must be configured to use TLS");
             }
             
             builder.setClientOnly();
         } else {
-            if (getKeystore() == null) {
-                throw new IllegalStateException("A keystore must be configured to use TLS");
+            if (privateKey == null && getKeystore() == null) {
+                throw new IllegalStateException("A keystore or private key must be configured to use TLS");
+            }
+            if (privateKey != null && publicKey == null) {
+                throw new IllegalStateException("A public key must be configured to use a Raw Public Key with TLS");
             }
-            if (getAlias() == null) {
+            if (privateKey == null && getAlias() == null) {
                 throw new IllegalStateException("An alias must be configured to use TLS");
             }
-            if (getPassword() == null) {
+            if (privateKey == null && getPassword() == null) {
                 throw new IllegalStateException("A password must be configured to use TLS");
             }
             if ((isClientAuthenticationRequired() || isClientAuthenticationWanted())
@@ -319,15 +375,23 @@ public class CoAPEndpoint extends DefaultEndpoint {
         }
 
         try {
-            // Configure the identity if the keystore parameter is specified
+            // Configure the identity if the keystore or privateKey parameter is specified
             if (getKeystore() != null) {
                 PrivateKey privateKey = 
                     (PrivateKey)getKeystore().getKey(getAlias(), getPassword());
                 builder.setIdentity(privateKey, getKeystore().getCertificateChain(getAlias()));
+            } else if (privateKey != null) {
+                builder.setIdentity(privateKey, publicKey);
             }
-    
+
             // Add all certificates from the truststore
-            builder.setTrustStore(getTrustedCerts());
+            Certificate[] certs = getTrustedCerts();
+            if (certs.length > 0) {
+                builder.setTrustStore(certs);
+            }
+            if (trustedRpkStore != null) {
+                builder.setRpkTrustStore(trustedRpkStore);
+            }
         } catch (GeneralSecurityException e) {
             throw new IllegalStateException("Error in configuring TLS", 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 f78bcb5..146fd1d 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
@@ -16,6 +16,10 @@
  */
 package org.apache.camel.coap;
 
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
@@ -29,6 +33,7 @@ import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.util.jsse.KeyStoreParameters;
 import org.eclipse.californium.core.coap.CoAP;
 import org.eclipse.californium.core.coap.MediaTypeRegistry;
+import org.eclipse.californium.scandium.dtls.rpkstore.TrustedRpkStore;
 import org.junit.Test;
 
 public class CoAPComponentTLSTest extends CamelTestSupport {
@@ -37,6 +42,7 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
     protected static final int PORT2 = AvailablePortFinder.getNextAvailable();
     protected static final int PORT3 = AvailablePortFinder.getNextAvailable();
     protected static final int PORT4 = AvailablePortFinder.getNextAvailable();
+    protected static final int PORT5 = AvailablePortFinder.getNextAvailable();
 
     @Produce(uri = "direct:start")
     protected ProducerTemplate sender;
@@ -109,6 +115,17 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         assertMockEndpointsSatisfied();
     }
 
+    @Test
+    public void testRawPublicKey() 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:rpk", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        assertMockEndpointsSatisfied();
+    }
+
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry registry = super.createRegistry();
@@ -117,6 +134,12 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         keystoreParameters.setResource("service.jks");
         keystoreParameters.setPassword("security");
 
+        KeyStore keyStore = keystoreParameters.createKeyStore();
+        PrivateKey privateKey =
+            (PrivateKey)keyStore.getKey("service", "security".toCharArray());
+        PublicKey publicKey =
+            keyStore.getCertificate("service").getPublicKey();
+
         KeyStoreParameters keystoreParameters2 = new KeyStoreParameters();
         keystoreParameters2.setResource("selfsigned.jks");
         keystoreParameters2.setPassword("security");
@@ -133,11 +156,16 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
         truststoreParameters2.setResource("truststore2.jks");
         truststoreParameters2.setPassword("storepass");
 
+        TrustedRpkStore trustedRpkStore = id -> { return true;};
+
         registry.bind("keyParams", keystoreParameters);
         registry.bind("keyParams2", keystoreParameters2);
         registry.bind("keyParams3", keystoreParameters3);
         registry.bind("trustParams", truststoreParameters);
         registry.bind("trustParams2", truststoreParameters2);
+        registry.bind("privateKey", privateKey);
+        registry.bind("publicKey", publicKey);
+        registry.bind("trustedRpkStore", trustedRpkStore);
 
         return registry;
     }
@@ -165,6 +193,10 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
                     + "keyStoreParameters=#keyParams&cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
                   .transform(body().prepend("Hello "));
 
+                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
+                    + "privateKey=#privateKey&publicKey=#publicKey", PORT5)
+                  .transform(body().prepend("Hello "));
+
                 from("direct:start")
                     .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams", PORT)
                     .to("mock:result");
@@ -195,6 +227,10 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
                     .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&"
                          + "cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
                     .to("mock:result");
+
+                from("direct:rpk")
+                    .toF("coaps://localhost:%d/TestResource?trustedRpkStore=#trustedRpkStore", PORT5)
+                    .to("mock:result");
             }
         };
     }


[camel] 18/21: Cleanup of testcode

Posted by co...@apache.org.
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 9501988a7ecf4cf918e56772d2b66a52717f5c57
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue Apr 30 11:08:13 2019 +0100

    Cleanup of testcode
---
 .../apache/camel/coap/CoAPComponentTLSTest.java    | 50 +++++++++-------------
 1 file changed, 20 insertions(+), 30 deletions(-)

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 aadd2a78..4e1e61a 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
@@ -249,36 +249,31 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
             @Override
             public void configure() throws Exception {
 
-                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
-                      + "keyStoreParameters=#keyParams", PORT)
+
+                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&keyStoreParameters=#keyParams", PORT)
                     .transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?alias=selfsigned&password=security&"
-                    + "keyStoreParameters=#keyParams2", PORT2)
-                  .transform(body().prepend("Hello "));
+                fromF("coaps://localhost:%d/TestResource?alias=selfsigned&password=security&keyStoreParameters=#keyParams2", PORT2)
+                    .transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
-                    + "trustStoreParameters=#trustParams&"
-                    + "keyStoreParameters=#keyParams&clientAuthentication=REQUIRE", PORT3)
-                  .transform(body().prepend("Hello "));
+                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&trustStoreParameters=#trustParams&"
+                      + "keyStoreParameters=#keyParams&clientAuthentication=REQUIRE", PORT3)
+                    .transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
-                    + "keyStoreParameters=#keyParams&cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
-                  .transform(body().prepend("Hello "));
+                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&keyStoreParameters=#keyParams&cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
+                    .transform(body().prepend("Hello "));
 
                 fromF("coaps://localhost:%d/TestResource?privateKey=#privateKey&publicKey=#publicKey", PORT5)
-                  .transform(body().prepend("Hello "));
+                    .transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?privateKey=#privateKey&publicKey=#publicKey&"
-                      + "clientAuthentication=REQUIRE&trustedRpkStore=#trustedRpkStore", PORT6)
-                  .transform(body().prepend("Hello "));
+                fromF("coaps://localhost:%d/TestResource?privateKey=#privateKey&publicKey=#publicKey&clientAuthentication=REQUIRE&trustedRpkStore=#trustedRpkStore", PORT6)
+                    .transform(body().prepend("Hello "));
 
                 fromF("coaps://localhost:%d/TestResource?pskStore=#pskStore", PORT7)
-                  .transform(body().prepend("Hello "));
+                    .transform(body().prepend("Hello "));
 
-                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
-                    + "keyStoreParameters=#keyParams&pskStore=#pskStore", PORT8)
-                  .transform(body().prepend("Hello "));
+                fromF("coaps://localhost:%d/TestResource?alias=service&password=security&keyStoreParameters=#keyParams&pskStore=#pskStore", PORT8)
+                    .transform(body().prepend("Hello "));
 
                 from("direct:start")
                     .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams", PORT)
@@ -297,18 +292,15 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
                     .to("mock:result");
 
                 from("direct:clientauth")
-                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&"
-                         + "keyStoreParameters=#keyParams3&alias=client&password=security", PORT3)
+                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&keyStoreParameters=#keyParams3&alias=client&password=security", PORT3)
                     .to("mock:result");
 
                 from("direct:failedclientauth")
-                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&"
-                         + "keyStoreParameters=#keyParams2&alias=selfsigned&password=security", PORT3)
+                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&keyStoreParameters=#keyParams2&alias=selfsigned&password=security", PORT3)
                     .to("mock:result");
 
                 from("direct:ciphersuites")
-                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&"
-                         + "cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
+                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
                     .to("mock:result");
 
                 from("direct:rpk")
@@ -324,8 +316,7 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
                     .to("mock:result");
 
                 from("direct:rpkclientauth")
-                    .toF("coaps://localhost:%d/TestResource?trustedRpkStore=#trustedRpkStore&"
-                         + "privateKey=#privateKey&publicKey=#publicKey", PORT6)
+                    .toF("coaps://localhost:%d/TestResource?trustedRpkStore=#trustedRpkStore&privateKey=#privateKey&publicKey=#publicKey", PORT6)
                     .to("mock:result");
 
                 from("direct:psk")
@@ -333,8 +324,7 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
                     .to("mock:result");
 
                 from("direct:pskciphersuite")
-                    .toF("coaps://localhost:%d/TestResource?pskStore=#pskStore&"
-                         + "cipherSuites=TLS_PSK_WITH_AES_128_CBC_SHA256", PORT7)
+                    .toF("coaps://localhost:%d/TestResource?pskStore=#pskStore&cipherSuites=TLS_PSK_WITH_AES_128_CBC_SHA256", PORT7)
                     .to("mock:result");
 
                 from("direct:pskx509")


[camel] 07/21: Adding TLS tests

Posted by co...@apache.org.
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 0117334304fc89585acd2638c95affd999cdeba2
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Thu Apr 18 16:46:10 2019 +0100

    Adding TLS tests
---
 .../java/org/apache/camel/coap/CoAPEndpoint.java   |  44 +++++----
 .../apache/camel/coap/CoAPComponentTLSTest.java    |  75 +++++++++++++++
 .../camel/coap/CoAPRestComponentTLSTest.java       | 101 +++++++++++++++++++++
 .../camel-coap/src/test/resources/client.jks       | Bin 0 -> 2306 bytes
 .../camel-coap/src/test/resources/service.jks      | Bin 0 -> 2308 bytes
 .../camel-coap/src/test/resources/truststore.jks   | Bin 0 -> 717 bytes
 6 files changed, 202 insertions(+), 18 deletions(-)

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 6076cc2..e2d9dbb 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
@@ -268,17 +268,21 @@ public class CoAPEndpoint extends DefaultEndpoint {
     }
     
     private Certificate[] getTrustedCerts() throws KeyStoreException {
-        Enumeration<String> aliases = truststore.aliases();
-        List<Certificate> trustCerts = new ArrayList<>();
-        while (aliases.hasMoreElements()) {
-            String alias = aliases.nextElement();
-            X509Certificate cert = (X509Certificate) truststore.getCertificate(alias);
-            if (cert != null) {
-                trustCerts.add(cert);
+        if (truststore != null) {
+            Enumeration<String> aliases = truststore.aliases();
+            List<Certificate> trustCerts = new ArrayList<>();
+            while (aliases.hasMoreElements()) {
+                String alias = aliases.nextElement();
+                X509Certificate cert = (X509Certificate) truststore.getCertificate(alias);
+                if (cert != null) {
+                    trustCerts.add(cert);
+                }
             }
+            
+            return trustCerts.toArray(new Certificate[0]);
         }
         
-        return trustCerts.toArray(new Certificate[0]);
+        return new Certificate[0];
     }
     
     public static boolean enableTLS(URI uri) {
@@ -286,10 +290,15 @@ public class CoAPEndpoint extends DefaultEndpoint {
     }
 
     public DTLSConnector createDTLSConnector(InetSocketAddress address, boolean client) {
-        if (getTruststore() == null) {
-            throw new IllegalStateException("A truststore must be configured to use TLS");
-        }
-        if (!client) {
+
+        DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
+        if (client) {
+            if (getTruststore() == null) {
+                throw new IllegalStateException("A truststore must be configured to use TLS");
+            }
+            
+            builder.setClientOnly();
+        } else {
             if (getKeystore() == null) {
                 throw new IllegalStateException("A keystore must be configured to use TLS");
             }
@@ -299,12 +308,11 @@ public class CoAPEndpoint extends DefaultEndpoint {
             if (getPassword() == null) {
                 throw new IllegalStateException("A password must be configured to use TLS");
             }
-        }
-
-        DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
-        if (client) {
-            builder.setClientOnly();
-        } else {
+            if ((isClientAuthenticationRequired() || isClientAuthenticationWanted())
+                && getTruststore() == null) {
+                throw new IllegalStateException("A truststore must be configured to support TLS client authentication");
+            }
+            
             builder.setAddress(address);
             builder.setClientAuthenticationRequired(isClientAuthenticationRequired());
             builder.setClientAuthenticationWanted(isClientAuthenticationWanted());
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
new file mode 100644
index 0000000..dfd5664
--- /dev/null
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTLSTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+package org.apache.camel.coap;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.eclipse.californium.core.coap.CoAP;
+import org.eclipse.californium.core.coap.MediaTypeRegistry;
+import org.junit.Test;
+
+public class CoAPComponentTLSTest extends CamelTestSupport {
+    
+    protected static final int PORT = AvailablePortFinder.getNextAvailable();
+
+    @Produce("direct:start")
+    protected ProducerTemplate sender;
+    
+    @Test
+    public void testTLS() 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());
+        sender.sendBodyAndHeader("Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        KeyStoreParameters keystoreParameters = new KeyStoreParameters();
+        keystoreParameters.setResource("service.jks");
+        keystoreParameters.setPassword("security");
+        
+        KeyStoreParameters truststoreParameters = new KeyStoreParameters();
+        truststoreParameters.setResource("truststore.jks");
+        truststoreParameters.setPassword("storepass");
+        
+        context.getRegistry().bind("keyParams", keystoreParameters);
+        context.getRegistry().bind("trustParams", truststoreParameters);
+        
+        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 "));
+
+                from("direct:start")
+                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams", PORT)
+                    .to("mock:result");
+            }
+        };
+    }
+}
diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTLSTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTLSTest.java
new file mode 100644
index 0000000..8d94bce
--- /dev/null
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTLSTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+package org.apache.camel.coap;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.eclipse.californium.core.coap.CoAP;
+import org.junit.Test;
+
+public class CoAPRestComponentTLSTest extends CamelTestSupport {
+    protected static final int PORT = AvailablePortFinder.getNextAvailable();
+
+    @Produce("direct:start")
+    protected ProducerTemplate sender;
+    
+    @Test
+    public void testPOST() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMinimumMessageCount(1);
+        mock.expectedBodiesReceived("Hello Camel CoAP");
+        mock.expectedHeaderReceived(CoAPConstants.COAP_RESPONSE_CODE, CoAP.ResponseCode.CONTENT.toString());
+        sender.sendBodyAndHeader("Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+        assertMockEndpointsSatisfied();
+    }
+    
+    @Test
+    public void testGET() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMinimumMessageCount(1);
+        mock.expectedBodiesReceived("Hello user");
+        mock.expectedHeaderReceived(CoAPConstants.COAP_RESPONSE_CODE, CoAP.ResponseCode.CONTENT.toString());
+        sender.sendBody("");
+        assertMockEndpointsSatisfied();
+    }
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        
+        KeyStoreParameters keystoreParameters = new KeyStoreParameters();
+        keystoreParameters.setResource("service.jks");
+        keystoreParameters.setPassword("security");
+        
+        KeyStoreParameters truststoreParameters = new KeyStoreParameters();
+        truststoreParameters.setResource("truststore.jks");
+        truststoreParameters.setPassword("storepass");
+        
+        context.getRegistry().bind("keystoreParameters", keystoreParameters);
+        context.getRegistry().bind("truststoreParameters", truststoreParameters);
+        
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                restConfiguration().component("coap").scheme("coaps").host("localhost").port(PORT)
+                    .endpointProperty("keyStoreParameters", "#keystoreParameters")
+                    .endpointProperty("alias", "service")
+                    .endpointProperty("password", "security");
+                
+                rest("/TestResource")
+                    .get().to("direct:get1")
+                    .post().to("direct:post1");
+
+                from("direct:get1").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getOut().setBody("Hello user");
+                    }
+                });
+
+                from("direct:post1").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getOut().setBody("Hello " + exchange.getIn().getBody(String.class));
+                    }
+                });
+                
+                from("direct:start")
+                    .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#truststoreParameters", PORT)
+                    .to("mock:result");
+            }
+        };
+    }
+}
diff --git a/components/camel-coap/src/test/resources/client.jks b/components/camel-coap/src/test/resources/client.jks
new file mode 100644
index 0000000..99c9b86
Binary files /dev/null and b/components/camel-coap/src/test/resources/client.jks differ
diff --git a/components/camel-coap/src/test/resources/service.jks b/components/camel-coap/src/test/resources/service.jks
new file mode 100644
index 0000000..40d24df
Binary files /dev/null and b/components/camel-coap/src/test/resources/service.jks differ
diff --git a/components/camel-coap/src/test/resources/truststore.jks b/components/camel-coap/src/test/resources/truststore.jks
new file mode 100644
index 0000000..2a7c179
Binary files /dev/null and b/components/camel-coap/src/test/resources/truststore.jks differ


[camel] 04/21: Improving TLS configuration

Posted by co...@apache.org.
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 a7f884d132bc0ace1682d90efdd6e367240f3ab6
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Wed Apr 10 13:48:52 2019 +0100

    Improving TLS configuration
---
 .../camel-coap/src/main/docs/coap-component.adoc   |  10 +-
 .../java/org/apache/camel/coap/CoAPComponent.java  |  53 ++++----
 .../java/org/apache/camel/coap/CoAPEndpoint.java   | 150 ++++++++++++++++++++-
 .../java/org/apache/camel/coap/CoAPProducer.java   |  45 +++----
 4 files changed, 198 insertions(+), 60 deletions(-)

diff --git a/components/camel-coap/src/main/docs/coap-component.adoc b/components/camel-coap/src/main/docs/coap-component.adoc
index 1517f4f..0ac6390 100644
--- a/components/camel-coap/src/main/docs/coap-component.adoc
+++ b/components/camel-coap/src/main/docs/coap-component.adoc
@@ -50,18 +50,24 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (6 parameters):
+==== Query Parameters (12 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *keyStoreParameters* (common) | The KeyStoreParameters object to use with TLS |  | KeyStoreParameters
+| *alias* (common) | Sets the alias used to query the KeyStore for the private key and certificate. |  | String
+| *cipherSuites* (common) | Sets the cipherSuites String. This is a comma separated String of ciphersuites to configure. |  | String
+| *keystore* (common) | Sets the TLS key store. Alternatively, a KeyStoreParameters object can be configured instead. An alias and password should also be configured on the route definition. |  | KeyStore
+| *keyStoreParameters* (common) | The KeyStoreParameters object to use with TLS to configure the keystore. Alternatively, a keystore parameter can be directly configured instead. An alias and password should also be configured on the route definition. |  | KeyStoreParameters
+| *truststore* (common) | Sets the TLS trust store. Alternatively, a trustStoreParameters object can be configured instead. All certificates in the truststore are used to establish trust. |  | KeyStore
+| *trustStoreParameters* (common) | The KeyStoreParameters object to use with TLS to configure the truststore. Alternatively, a truststore object can be directly configured instead. All certificates in the truststore are used to establish trust. |  | KeyStoreParameters
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
 | *coapMethodRestrict* (consumer) | Comma separated list of methods that the CoAP consumer will bind to. The default is to bind to all methods (DELETE, GET, POST, PUT). |  | String
 | *exceptionHandler* (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
 | *exchangePattern* (consumer) | Sets the exchange pattern when the consumer creates an exchange. |  | ExchangePattern
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
+| *password* (security) | Sets the password used to access an aliased PrivateKey in the KeyStore. |  | String
 |===
 // endpoint options: END
 // spring-boot-auto-configure options: START
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
index 40e2c20..13f0c9b 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
@@ -16,17 +16,10 @@
  */
 package org.apache.camel.coap;
 
-import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.security.GeneralSecurityException;
-import java.security.KeyStore;
 import java.security.PrivateKey;
-import java.security.cert.Certificate;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -68,10 +61,10 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
         super(context, CoAPEndpoint.class);
     }
 
-    public synchronized CoapServer getServer(int port, KeyStoreParameters keyStoreParameters) {
+    public synchronized CoapServer getServer(int port, CoAPEndpoint endpoint) {
         CoapServer server = servers.get(port);
         if (server == null && port == -1) {
-            server = getServer(DEFAULT_PORT, keyStoreParameters);
+            server = getServer(DEFAULT_PORT, endpoint);
         }
         if (server == null) {
             CoapEndpoint.Builder coapBuilder = new CoapEndpoint.Builder();
@@ -79,37 +72,37 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
             InetSocketAddress address = new InetSocketAddress(port);
             coapBuilder.setNetworkConfig(config);
             
-            if (keyStoreParameters != null) {
+            if (endpoint.getKeystore() != null) {
                 DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
                 builder.setAddress(address);
+                if (endpoint.getAlias() == null) {
+                    throw new IllegalStateException("An alias must be configured to use TLS");
+                }
+                if (endpoint.getPassword() == null) {
+                    throw new IllegalStateException("A password must be configured to use TLS");
+                }
+                if (endpoint.getTruststore() == null) {
+                    throw new IllegalStateException("A truststore must be configured to use TLS");
+                }
 
                 try {
-                    KeyStore keyStore = keyStoreParameters.createKeyStore();
-                    // TODO
-                    PrivateKey privateKey = (PrivateKey)keyStoreParameters.createKeyStore().getKey("ec", "security".toCharArray());
-                    builder.setIdentity(privateKey, keyStore.getCertificateChain("ec"));
+                    // Configure the identity
+                    PrivateKey privateKey = 
+                        (PrivateKey)endpoint.getKeystore().getKey(endpoint.getAlias(), endpoint.getPassword());
+                    builder.setIdentity(privateKey, endpoint.getKeystore().getCertificateChain(endpoint.getAlias()));
 
                     // Add all certificates from the truststore
-                    Enumeration<String> aliases = keyStore.aliases();
-                    List<Certificate> trustCerts = new ArrayList<>();
-                    while (aliases.hasMoreElements()) {
-                        String alias = aliases.nextElement();
-                        X509Certificate cert =
-                                (X509Certificate) keyStore.getCertificate(alias);
-                        if (cert != null) {
-                            trustCerts.add(cert);
-                        }
-                    }
-                    builder.setTrustStore(trustCerts.toArray(new Certificate[0]));
-
-                } catch (GeneralSecurityException | IOException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
+                    builder.setTrustStore(endpoint.getTrustedCerts());
+
+                } catch (GeneralSecurityException e) {
+                    throw new IllegalStateException("Error in configuring TLS", e);
                 }
 
                 builder.setClientAuthenticationRequired(false); //TODO
 
-                builder.setSupportedCipherSuites(new String[] {"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"}); //TODO
+                if (endpoint.getConfiguredCipherSuites() != null) {
+                    builder.setSupportedCipherSuites(endpoint.getConfiguredCipherSuites());
+                }
 
                 DTLSConnector connector = new DTLSConnector(builder.build());
                 coapBuilder.setConnector(connector);
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 5e989b7..2a3c0ad 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
@@ -16,7 +16,17 @@
  */
 package org.apache.camel.coap;
 
+import java.io.IOException;
 import java.net.URI;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.PrivateKey;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
 
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
@@ -40,6 +50,26 @@ public class CoAPEndpoint extends DefaultEndpoint {
     
     @UriParam
     private KeyStoreParameters keyStoreParameters;
+    
+    @UriParam
+    private KeyStore keystore;
+    
+    @UriParam
+    private KeyStoreParameters trustStoreParameters;
+    
+    @UriParam
+    private KeyStore truststore;
+    
+    @UriParam
+    private String alias;
+    
+    @UriParam(label = "security", javaType = "java.lang.String", secret = true)
+    private char[] password;
+    
+    @UriParam
+    private String cipherSuites;
+    
+    private String[] configuredCipherSuites;
         
     private CoAPComponent component;
     
@@ -88,17 +118,131 @@ public class CoAPEndpoint extends DefaultEndpoint {
     }
 
     public CoapServer getCoapServer() {
-        return component.getServer(getUri().getPort(), keyStoreParameters);
+        return component.getServer(getUri().getPort(), this);
     }
     
     /**
-     * The KeyStoreParameters object to use with TLS
+     * The KeyStoreParameters object to use with TLS to configure the keystore. Alternatively, a "keystore" 
+     * parameter can be directly configured instead. An alias and password should also be configured on the route definition.
      */
     public KeyStoreParameters getKeyStoreParameters() {
         return keyStoreParameters;
     }
 
-    public void setKeyStoreParameters(KeyStoreParameters keyStoreParameters) {
+    public void setKeyStoreParameters(KeyStoreParameters keyStoreParameters) throws GeneralSecurityException, IOException {
         this.keyStoreParameters = keyStoreParameters;
+        if (keyStoreParameters != null) {
+            this.keystore = keyStoreParameters.createKeyStore();
+        }
+    }
+    
+    /**
+     * The KeyStoreParameters object to use with TLS to configure the truststore. Alternatively, a "truststore" 
+     * object can be directly configured instead. All certificates in the truststore are used to establish trust.
+     */
+    public KeyStoreParameters getTrustStoreParameters() {
+        return trustStoreParameters;
+    }
+
+    public void setTrustStoreParameters(KeyStoreParameters trustStoreParameters) throws GeneralSecurityException, IOException {
+        this.trustStoreParameters = trustStoreParameters;
+        if (trustStoreParameters != null) {
+            this.truststore = trustStoreParameters.createKeyStore();
+        }
+    }
+    
+    /**
+     * Gets the TLS key store. Alternatively, a KeyStoreParameters object can be configured instead.
+     * An alias and password should also be configured on the route definition.
+     */
+    public KeyStore getKeystore() {
+        return keystore;
+    }
+
+    /**
+     * Sets the TLS key store. Alternatively, a KeyStoreParameters object can be configured instead.
+     * An alias and password should also be configured on the route definition.
+     */
+    public void setKeystore(KeyStore keystore) {
+        this.keystore = keystore;
+    }
+    
+    /**
+     * Gets the TLS trust store. Alternatively, a "trustStoreParameters" object can be configured instead.
+     * All certificates in the truststore are used to establish trust.
+     */
+    public KeyStore getTruststore() {
+        return truststore;
+    }
+
+    /**
+     * Sets the TLS trust store. Alternatively, a "trustStoreParameters" object can be configured instead.
+     * All certificates in the truststore are used to establish trust.
+     */
+    public void setTruststore(KeyStore truststore) {
+        this.truststore = truststore;
+    }
+    
+    /**
+     * Gets the alias used to query the KeyStore for the private key and certificate.
+     */
+    public String getAlias() {
+        return alias;
+    }
+
+    /**
+     * Sets the alias used to query the KeyStore for the private key and certificate.
+     */
+    public void setAlias(String alias) {
+        this.alias = alias;
+    }
+    
+    /**
+     * Gets the password used to access an aliased {@link PrivateKey} in the KeyStore.
+     */
+    public char[] getPassword() {
+        return password;
+    }
+
+    /**
+     * Sets the password used to access an aliased {@link PrivateKey} in the KeyStore.
+     */
+    public void setPassword(char[] password) {
+        this.password = password;
+    }
+    
+    /**
+     * Gets the cipherSuites String. This is a comma separated String of ciphersuites to configure.
+     */
+    public String getCipherSuites() {
+        return cipherSuites;
+    }
+
+    /**
+     * Sets the cipherSuites String. This is a comma separated String of ciphersuites to configure.
+     */
+    public void setCipherSuites(String cipherSuites) {
+        this.cipherSuites = cipherSuites;
+        if (cipherSuites != null) {
+            configuredCipherSuites = cipherSuites.split(",");
+        }
+    }
+    
+    public String[] getConfiguredCipherSuites() {
+        return configuredCipherSuites;
+    }
+    
+    public Certificate[] getTrustedCerts() throws KeyStoreException {
+        Enumeration<String> aliases = truststore.aliases();
+        List<Certificate> trustCerts = new ArrayList<>();
+        while (aliases.hasMoreElements()) {
+            String alias = aliases.nextElement();
+            X509Certificate cert = (X509Certificate) truststore.getCertificate(alias);
+            if (cert != null) {
+                trustCerts.add(cert);
+            }
+        }
+        
+        return trustCerts.toArray(new Certificate[0]);
     }
 }
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
index c4bc8c9..588e429 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
@@ -16,15 +16,9 @@
  */
 package org.apache.camel.coap;
 
-import java.io.IOException;
 import java.net.URI;
 import java.security.GeneralSecurityException;
-import java.security.KeyStore;
-import java.security.cert.Certificate;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
+import java.security.PrivateKey;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
@@ -103,32 +97,33 @@ public class CoAPProducer extends DefaultProducer {
             }
             client = new CoapClient(uri);
             
-            if (endpoint.getKeyStoreParameters() != null) {
+            if (endpoint.getTruststore() != null) {
                 DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
                 builder.setClientOnly();
 
                 try {
-                    // TODO Add client key config if specified
-                    
-                    KeyStore keyStore = endpoint.getKeyStoreParameters().createKeyStore();
-                    // Add all certificates from the truststore
-                    Enumeration<String> aliases = keyStore.aliases();
-                    List<Certificate> trustCerts = new ArrayList<>();
-                    while (aliases.hasMoreElements()) {
-                        String alias = aliases.nextElement();
-                        X509Certificate cert =
-                                (X509Certificate) keyStore.getCertificate(alias);
-                        if (cert != null) {
-                            trustCerts.add(cert);
+                    // Configure the identity if the keystore parameter is specified
+                    if (endpoint.getKeystore() != null) {
+                        if (endpoint.getAlias() == null) {
+                            throw new IllegalStateException("An alias must be configured to use TLS");
+                        }
+                        if (endpoint.getPassword() == null) {
+                            throw new IllegalStateException("A password must be configured to use TLS");
                         }
+                        PrivateKey privateKey = 
+                            (PrivateKey)endpoint.getKeystore().getKey(endpoint.getAlias(), endpoint.getPassword());
+                        builder.setIdentity(privateKey, endpoint.getKeystore().getCertificateChain(endpoint.getAlias()));
                     }
-                    builder.setTrustStore(trustCerts.toArray(new Certificate[0]));
-                } catch (GeneralSecurityException | IOException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
+
+                    // Add all certificates from the truststore
+                    builder.setTrustStore(endpoint.getTrustedCerts());
+                } catch (GeneralSecurityException e) {
+                    throw new IllegalStateException("Error in configuring TLS", e);
                 }
 
-                builder.setSupportedCipherSuites(new String[] {"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"}); //TODO
+                if (endpoint.getConfiguredCipherSuites() != null) {
+                    builder.setSupportedCipherSuites(endpoint.getConfiguredCipherSuites());
+                }
 
                 DTLSConnector connector = new DTLSConnector(builder.build());
                 CoapEndpoint.Builder coapBuilder = new CoapEndpoint.Builder();


[camel] 21/21: Removing unused import

Posted by co...@apache.org.
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 8c5892335e62402342063bae1913ab8c89373b19
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Fri May 24 20:39:01 2019 +0100

    Removing unused import
---
 .../camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java    | 1 -
 1 file changed, 1 deletion(-)

diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
index bfa450c..e0dc8c6 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
@@ -33,7 +33,6 @@ import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.HostUtils;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
-import org.apache.camel.util.jsse.KeyStoreParameters;
 import org.eclipse.californium.core.CoapServer;
 import org.eclipse.californium.core.network.CoapEndpoint;
 import org.eclipse.californium.core.network.config.NetworkConfig;