From 7c53855c11e15a856e4df7cb4cb494eb636ca203 Mon Sep 17 00:00:00 2001 From: Howard Gao Date: Wed, 23 May 2018 22:34:01 +0800 Subject: [PATCH] ARTEMIS-1853 Adding Netty OpenSSL provider example Added an example to demonstrate how to configure and use openssl Moved/Added netty-tcnative dependency to artemis-distribution Changed artemis-jms-client-all pom to exclude io.netty from relocation so that the native openssl can be loaded --- artemis-core-client/pom.xml | 5 + .../src/main/assembly/dep.xml | 1 + artemis-jms-client-all/pom.xml | 4 - .../features/standard/netty-openssl/pom.xml | 124 ++++++++++++++++++ .../features/standard/netty-openssl/readme.md | 17 +++ .../artemis/jms/example/OpenSSLExample.java | 85 ++++++++++++ .../server0/activemq.example.keystore | Bin 0 -> 707 bytes .../server0/activemq.example.truststore | Bin 0 -> 572 bytes .../resources/activemq/server0/broker.xml | 60 +++++++++ .../src/main/resources/jndi.properties | 20 +++ pom.xml | 7 + tests/integration-tests/pom.xml | 6 - 12 files changed, 319 insertions(+), 10 deletions(-) create mode 100644 examples/features/standard/netty-openssl/pom.xml create mode 100644 examples/features/standard/netty-openssl/readme.md create mode 100644 examples/features/standard/netty-openssl/src/main/java/org/apache/activemq/artemis/jms/example/OpenSSLExample.java create mode 100644 examples/features/standard/netty-openssl/src/main/resources/activemq/server0/activemq.example.keystore create mode 100644 examples/features/standard/netty-openssl/src/main/resources/activemq/server0/activemq.example.truststore create mode 100644 examples/features/standard/netty-openssl/src/main/resources/activemq/server0/broker.xml create mode 100644 examples/features/standard/netty-openssl/src/main/resources/jndi.properties diff --git a/artemis-core-client/pom.xml b/artemis-core-client/pom.xml index 47b72e2312..092b8c399c 100644 --- a/artemis-core-client/pom.xml +++ b/artemis-core-client/pom.xml @@ -118,6 +118,11 @@ io.netty netty-common + + io.netty + netty-tcnative-boringssl-static + + diff --git a/artemis-distribution/src/main/assembly/dep.xml b/artemis-distribution/src/main/assembly/dep.xml index 09874250f0..2f6999ad16 100644 --- a/artemis-distribution/src/main/assembly/dep.xml +++ b/artemis-distribution/src/main/assembly/dep.xml @@ -81,6 +81,7 @@ org.jboss.logging:jboss-logging org.jboss.slf4j:slf4j-jboss-logmanager io.netty:netty-all + io.netty:netty-tcnative-boringssl-static org.apache.qpid:proton-j org.apache.activemq:activemq-client org.slf4j:slf4j-api diff --git a/artemis-jms-client-all/pom.xml b/artemis-jms-client-all/pom.xml index 653ed312da..0c6fa45f55 100644 --- a/artemis-jms-client-all/pom.xml +++ b/artemis-jms-client-all/pom.xml @@ -116,10 +116,6 @@ org.apache.commons org.apache.activemq.artemis.shaded.org.apache.commons - - io.netty - org.apache.activemq.artemis.shaded.io.netty - org.jboss org.apache.activemq.artemis.shaded.org.jboss diff --git a/examples/features/standard/netty-openssl/pom.xml b/examples/features/standard/netty-openssl/pom.xml new file mode 100644 index 0000000000..5f61a20a12 --- /dev/null +++ b/examples/features/standard/netty-openssl/pom.xml @@ -0,0 +1,124 @@ + + + + + 4.0.0 + + + org.apache.activemq.examples.broker + jms-examples + 2.7.0-SNAPSHOT + + + netty-openssl + jar + ActiveMQ Artemis JMS Netty OpenSSL Example + + + ${project.basedir}/../../../.. + + + + + org.apache.activemq + artemis-jms-client-all + ${project.version} + + + + + + + org.apache.activemq + artemis-maven-plugin + + + create + + create + + + ${noServer} + + + + start + + cli + + + ${noServer} + true + tcp://localhost:61616 + + run + + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.OpenSSLExample + + + + stop + + cli + + + ${noServer} + + stop + + + + + + + org.apache.activemq.examples.broker + netty-openssl + ${project.version} + + + + + org.apache.maven.plugins + maven-clean-plugin + + + + + + release + + + + com.vladsch.flexmark + markdown-page-generator-plugin + + + + + + diff --git a/examples/features/standard/netty-openssl/readme.md b/examples/features/standard/netty-openssl/readme.md new file mode 100644 index 0000000000..2ccb69388b --- /dev/null +++ b/examples/features/standard/netty-openssl/readme.md @@ -0,0 +1,17 @@ +# JMS OpenSSL Example + +To run the example, simply type **mvn verify** from this directory, or **mvn -PnoServer verify** if you want to start and create the broker manually. + +This example shows you how to configure Netty OpenSSL with ActiveMQ Artemis to send and receive message. + +Using SSL can make your messaging applications interact with ActiveMQ Artemis securely. An application can be secured transparently without extra coding effort. +Beside using JDK's implementation, Artemis also supports using native OpenSSL provided by Netty. +To secure your messaging application with Netty's OpenSSL, you need to configure connector and acceptor as follows: + + tcp://localhost:5500?sslEnabled=true;sslProvider=OPENSSL;keyStorePath=activemq.example.keystore;keyStorePassword=secureexample + +In the configuration, the `activemq.example.keystore` is the key store file holding the server's certificate. The `activemq.example.truststore` is the file holding the certificates which the client trusts (i.e. the server's certificate exported from activemq.example.keystore). They are generated via the following commands: + +* `keytool -genkey -keystore activemq.example.keystore -storepass secureexample -keypass secureexample -dname "CN=localhost, OU=Artemis, O=ActiveMQ, L=AMQ, S=AMQ, C=AMQ" -keyalg EC -sigalg SHA256withECDSA +* `keytool -export -keystore activemq.example.keystore -file activemq-jks.cer -storepass secureexample +* `keytool -import -keystore activemq.example.truststore -file activemq-jks.cer -storepass secureexample -keypass secureexample -noprompt diff --git a/examples/features/standard/netty-openssl/src/main/java/org/apache/activemq/artemis/jms/example/OpenSSLExample.java b/examples/features/standard/netty-openssl/src/main/java/org/apache/activemq/artemis/jms/example/OpenSSLExample.java new file mode 100644 index 0000000000..0aaa1bab20 --- /dev/null +++ b/examples/features/standard/netty-openssl/src/main/java/org/apache/activemq/artemis/jms/example/OpenSSLExample.java @@ -0,0 +1,85 @@ +/* + * 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.activemq.artemis.jms.example; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.naming.InitialContext; + +/** + * A simple JMS Queue example that uses netty's OpenSSL secure transport. + */ +public class OpenSSLExample { + + public static void main(final String[] args) throws Exception { + Connection connection = null; + InitialContext initialContext = null; + try { + // Step 1. Create an initial context to perform the JNDI lookup. + initialContext = new InitialContext(); + + // Step 2. Perfom a lookup on the queue + Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); + + // Step 3. Perform a lookup on the Connection Factory + ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); + + // Step 4.Create a JMS Connection + connection = cf.createConnection(); + + // Step 5. Create a JMS Session + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Step 6. Create a JMS Message Producer + MessageProducer producer = session.createProducer(queue); + + // Step 7. Create a Text Message + TextMessage message = session.createTextMessage("This is a text message"); + + System.out.println("Sent message: " + message.getText()); + + // Step 8. Send the Message + producer.send(message); + + // Step 9. Create a JMS Message Consumer + MessageConsumer messageConsumer = session.createConsumer(queue); + + // Step 10. Start the Connection + connection.start(); + + // Step 11. Receive the message + TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000); + + System.out.println("Received message: " + messageReceived.getText()); + + initialContext.close(); + } finally { + // Step 12. Be sure to close our JMS resources! + if (initialContext != null) { + initialContext.close(); + } + if (connection != null) { + connection.close(); + } + } + } +} diff --git a/examples/features/standard/netty-openssl/src/main/resources/activemq/server0/activemq.example.keystore b/examples/features/standard/netty-openssl/src/main/resources/activemq/server0/activemq.example.keystore new file mode 100644 index 0000000000000000000000000000000000000000..0a26208761ee137395d3d5996a3630862fc7ee3e GIT binary patch literal 707 zcmezO_TO6u1_mY|W&~r_+{*0KN+2&u`TW~yK%shrS_3{dE^RhO7Dg>5K}JSa2A1sZ zuNK=mwYEB((=jpM^zp$ozio5hCOZWSHM^L8H&B1m&2~avC1$HwoAleM(|kVn8VB31 z+4)#B-1Wlp;Mq3&}#EIXUoFO#L8e$ zXvky0#l{@U!Y0h@=o<**aiH+nAv{3?evnEoVGhUSlFYJHpmG7AZ-GMG!t9PkC8@cY z#fAz7av%|AVR4uu1*nulaB5LmYLS7QIIp3Ffw7^9fu)gwsZkV|Yi4K!|ut1%`+$ABz}^$OKXLklGIy zNHggxQn9z>P_fVGVnAl5d3kSr1{uT>?EN88!8ycfkc>v#bJsRpi&CKsYPX}MFw)>yoMGA#)c*a zmPQ7qMp0m{nV}JsI}lEaG!SNE2Zst1BQ$uJ8QGbg7+CCFrffazzbn~k z;B=wRbDyLHKP3oG$h_k7(mIuO)yHS*Y|MdN_dawTe0@Q6m&?t0Co1#jAC<6f_`O)s zK;A$W7$UNKEMhDo6GYiVYCl{k{qQAemB%9cJ2NI9V?~V-W={qKHzq}fHSE<%z7g_g zJ%kN+3G`ewsw&^OfNxg2+s>OOo!NGISpbzxe`>3pDCn{`kcC@3w%7dcHipQQ+6m$u iXRjpvJ9D_}1J{e=$^nH_CE2zfVt=o>&TNs&GY$Z0x1e7D literal 0 HcmV?d00001 diff --git a/examples/features/standard/netty-openssl/src/main/resources/activemq/server0/broker.xml b/examples/features/standard/netty-openssl/src/main/resources/activemq/server0/broker.xml new file mode 100644 index 0000000000..87d014799b --- /dev/null +++ b/examples/features/standard/netty-openssl/src/main/resources/activemq/server0/broker.xml @@ -0,0 +1,60 @@ + + + + + + ./data/messaging/bindings + + ./data/messaging/journal + + ./data/messaging/largemessages + + ./data/messaging/paging + + + + + tcp://localhost:5500?sslEnabled=true;sslProvider=OPENSSL;keyStorePath=activemq.example.keystore;keyStorePassword=secureexample + tcp://localhost:61616 + + + + + + + + + + + + + + + + + +
+ + + +
+
+
+
diff --git a/examples/features/standard/netty-openssl/src/main/resources/jndi.properties b/examples/features/standard/netty-openssl/src/main/resources/jndi.properties new file mode 100644 index 0000000000..2358666691 --- /dev/null +++ b/examples/features/standard/netty-openssl/src/main/resources/jndi.properties @@ -0,0 +1,20 @@ +# 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. + +java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory +connectionFactory.ConnectionFactory=tcp://localhost:5500?sslEnabled=true&sslProvider=OPENSSL&trustStorePath=activemq/server0/activemq.example.truststore&trustStorePassword=secureexample +queue.queue/exampleQueue=exampleQueue diff --git a/pom.xml b/pom.xml index 7249c2dfb3..8c50610964 100644 --- a/pom.xml +++ b/pom.xml @@ -92,6 +92,7 @@ 2.4 2.8.47 4.1.24.Final + 2.0.7.Final 0.27.1 3.0.19.Final 1.7.21 @@ -540,6 +541,12 @@ ${netty.version} + + io.netty + netty-tcnative-boringssl-static + ${netty.tcnative.version} + + org.apache.qpid proton-j diff --git a/tests/integration-tests/pom.xml b/tests/integration-tests/pom.xml index ad278643ec..d1c2b33449 100644 --- a/tests/integration-tests/pom.xml +++ b/tests/integration-tests/pom.xml @@ -397,12 +397,6 @@ jgroups - - - io.netty - netty-tcnative-boringssl-static - 2.0.7.Final -