java 如何在 ssl 中使用 activemq
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32696121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to activemq in ssl
提问by Igor Beaufils
I'm trying to send messages via jms (activemq) but I want it to be in ssl protocol. It actuality works in tcp for now.
我正在尝试通过 jms (activemq) 发送消息,但我希望它使用 ssl 协议。它目前在 tcp 中有效。
I use jndi, with a virtual topic and 2 queues. Could somebody help me, I tryed this but I get stuck the server won't start :
我使用 jndi,带有一个虚拟主题和 2 个队列。有人可以帮助我吗,我试过了,但我卡住了,服务器无法启动:
http://activemq.apache.org/how-do-i-use-ssl.html
http://activemq.apache.org/how-do-i-use-ssl.html
thx
谢谢
edit : The log says : "The reference to entity "needClientAuth" must end with the ';' delimiter."
编辑:日志说:“对实体“needClientAuth”的引用必须以';'结尾 分隔符。”
回答by Igor Beaufils
I will answer my own question :
我会回答我自己的问题:
First of all inside ..../apache-activemq-5.11.1/conf/activemq.xml :
首先在 ..../apache-activemq-5.11.1/conf/activemq.xml 中:
<transportConnectors>
<transportConnector name="ssl" uri="ssl://0.0.0.0:61617?trace=true&needClientAuth=true"/>
</transportConnectors>
Don't forget the & amp;(without the space) that's what was blocking on the server side. On activemq page it isn't written. As well don't forget to open your port. Here (61617)
不要忘记& amp; (没有空间)这就是服务器端的阻塞。在activemq页面上没有写。也不要忘记打开你的端口。这里 (61617)
Still inside activemq.xml
还在activemq.xml里面
<sslContext>
<sslContext keyStore="file:${activemq.base}/conf/amq-server.ks"
keyStorePassword="PASSWORD"
trustStore="file:${activemq.base}/conf/amq-server.ts"
trustStorePassword="PASSWORD" />
</sslContext>
Restart JMS; This time it should be OK. Now that your server side is OK Let's go for the client.
重启JMS;这次应该可以了。现在您的服务器端正常了,让我们来看看客户端。
I have done this in activemq ..../apache-activemq-5.11.1/conf : (follow what is asked, names, pass, etc...).
我已经在 activemq ..../apache-activemq-5.11.1/conf 中做到了这一点:(按照要求,姓名,通过等...)。
## Create a keystore for the broker SERVER
$ keytool -genkey -alias amq-server -keyalg RSA -keysize 2048 -validity 90 -keystore amq-server.ks
## Export the broker SERVER certificate from the keystore
$ keytool -export -alias amq-server -keystore amq-server.ks -file amq-server_cert
## Create the CLIENT keystore
$ keytool -genkey -alias amq-client -keyalg RSA -keysize 2048 -validity 90 -keystore amq-client.ks
## Import the previous exported broker's certificate into a CLIENT truststore
$ keytool -import -alias amq-server -keystore amq-client.ts -file amq-server_cert
## If you want to make trusted also the client, you must export the client's certificate from the keystore
$ keytool -export -alias amq-client -keystore amq-client.ks -file amq-client_cert
## Import the client's exported certificate into a broker SERVER truststore
$ keytool -import -alias amq-client -keystore amq-server.ts -file amq-client_cert
Then I downloaded with the help of https://winscp.net/eng/index.phpmy "amq-client.ts" and "amq-client.ks" from my server to my PC (I dev on windows and server on linux).
然后我在https://winscp.net/eng/index.php的帮助下将我的“amq-client.ts”和“amq-client.ks”从我的服务器下载到我的电脑(我在 Windows 上开发,服务器上linux)。
I used this two files as source in eclipse. (I won't explain how to).
我在 eclipse 中使用这两个文件作为源。(我不会解释如何)。
Finally in eclipse I had to change only one thing I had to replace QueueConnectionFactory by ActiveMQSslConnectionFactory:
最后在 Eclipse 中,我只需要更改一件事,我必须用 ActiveMQSslConnectionFactory 替换 QueueConnectionFactory:
So I erased
所以我抹掉了
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx
.lookup("jms/ConnectionFactory");
And in place of that did :
取而代之的是:
ActiveMQSslConnectionFactory connectionFactory = new ActiveMQSslConnectionFactory(url);
try {
connectionFactory.setTrustStore(CLIENT_TS_FILE);
connectionFactory.setTrustStorePassword("PASSWORD asked while TS file made");
connectionFactory.setKeyStore(CLIENT_KS_FILE);
connectionFactory.setKeyStorePassword("PASSWORD asked while KS file made");
} catch (Exception e) {
throw new MotorException(
"JMS Connection Failed (Trust store or key store weren't found) : ",
e);
}
Very little was on internet at least for activemq and ssl it might help someone.
至少对于 activemq 和 ssl 而言,互联网上的内容很少,它可能会对某人有所帮助。