ssl - ActiveMQ Artemis "needClientAuth=true"错误输出 "Empty client certificate chain."消息 (AMQ222208)

标签 ssl keystore activemq-artemis jks truststore

我有 ActiveMQ Artemis 集群,具有共享存储的主动备份模式,版本 2.17.0。 SSL 与此集群一起使用。
我从 Kafka 集群中获取了 keystore /信任库文件,这些文件与 2-way TLS 完全兼容。我将这些文件与 Artemis 一起使用,它也可以正常工作。但是,当我启用 needClientAuth=true 时,问题就来了在 URL 字符串中。
这是文档中的内容:

needClientAuth

This property is only for an acceptor. It tells a client connecting to this acceptor that 2-way SSL is required. Valid values are true or false. Default is false.


所以如果我想实现2-way TLS,我必须使用这个选项。然后两者 - 服务器和客户端都必须拥有自己的 keystore /信任库对。在我的情况下,服务器和客户端都是相同的。

当我有 needClientAuth=true在接受器 URL 字符串中,我使用 Artemis CLI 连接到 Artemis 集群,这就是我在 CLI 输出中得到的:
Connection failed::Failed to create session factory
这就是 Artemis 实例所说的:
WARN  [org.apache.activemq.artemis.core.server] AMQ222208: SSL handshake failed for client from /123.123.123.123:36788: javax.net.ssl.SSLHandshakeException: Empty client certificate chain.

正如我所说,提到的 keystore /信任库与 Kafka 配合得很好,没有问题。但是,它不适用于 ActiveMQ Artemis。如果我删除 needClientAuth=true来自 acceptor URL 字符串,一切正常。
这是我生成 keystore /信任库的方式:
# Generate private key and CSR
openssl req -new -newkey rsa:2048 -nodes -days 365 -subj '/CN=something.com/OU=XXX/O=Company/L=City/ST=City/C=XX' -keyout private.key -out mycsr.csr

# Upload CSR to magic website, get back CA and signed certificate.
# ...

# Since CA is chain, and you cannot import chain into keystore/truststore, split into multiple files: ca1.cer and ca2.cer.
# ...

# Create truststore.jks
keytool -importcert -noprompt -alias ca1 -file ca1.cer -keystore truststore.jks
keytool -importcert -noprompt -alias ca2 -file ca2.cer -keystore truststore.jks

# Because it's impossible to create JKS keystore out of private key, first generate PKCS12 keystore:
openssl pkcs12 -inkey private.key -in certificate.cer -export -out keystore.p12

# Now convert PKCS12 keystore to JKS keystore:
keytool -importkeystore -srckeystore keystore.p12 -srcstoretype pkcs12 -destkeystore keystore.jks -deststoretype jks

# Since above command added only a private key, we also need to add an issued certificate:
keytool -importcert -noprompt -alias certificate -file certificate.cer -keystore keystore.jks

# Some client's (in Kafka) does not work if CA is not added to keystore, so add it:
keytool -importcert -noprompt -alias ca1 -file ca1.cer -keystore keystore.jks
keytool -importcert -noprompt -alias ca2 -file ca2.cer -keystore keystore.jks

# End up with the following files:
keystore.jks
truststore.jks
---------
ca.cer
certificate.cer
private.key
接受者 URL(带有 needClientAuth=true ):
tcp://server.com:1234?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;amqpMinLargeMessageSize=102400;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true;sslEnabled=true;needClientAuth=true;keyStorePath=/opt/ssl/keystore.jks;keyStorePassword=123;trustStorePath=/opt/ssl/truststore.jks;trustStorePassword=123
使用 ActiveMQ Artemis CLI 连接时,我传递了这个 URL:
tcp://server.com:1234?sslEnabled=true;keyStorePath=/opt/ssl/truststore.jks;keyStorePassword=123;trustStorePath=/opt/ssl/truststore.jks;trustStorePassword=123
我错过了什么?

最佳答案

经纪人和客户都需要有自己的证书。您似乎只创建了 1 个证书并在代理和客户端上使用该证书。
例如,代理需要在其提供给客户端的 keystore 中拥有自己的证书,并且客户端在其信任库中拥有该证书。然后,客户端需要在其 keystore 中拥有自己的证书,并将其提供给代理,并且代理拥有的是其信任库。
据我所知,你没有这样做。看看 ssl-enabled-dual-authentication ActiveMQ Artemis 附带的示例。它包含所有 keytool您需要使用自签名证书运行的命令。一旦您使用简单的自签名证书启动并运行它,您就可以继续使用由证书颁发机构签名的证书。
值得注意的是,如果您使用的是由证书颁发机构签署的证书,您只需 import the CA's root certificate into the JVM's truststore在代理和客户端上,然后你就不需要弄乱任何单独的信任库了。客户端和代理将隐式信任由您的 CA 签名的证书。
最后,您在 ActiveMQ Artemis CLI 中使用的 URL 看起来不正确,因为 keyStorePath正在引用信任库 /opt/ssl/truststore.jks .

关于ssl - ActiveMQ Artemis "needClientAuth=true"错误输出 "Empty client certificate chain."消息 (AMQ222208),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67279673/

相关文章:

java - Thorntail JMS 到远程 ActiveMQ 服务器?

Web 服务客户端的 SSL 证书

.net - WCF maxReceivedMessageSize 无法通过 HTTPS 工作

java - 在 Java 6(GlassFish 3 服务器)中设置 SSL

Tomcat:在 Windows 上创建本地 keystore 的问题

javamail java.io.IOException : Invalid keystore format

java - junit 或 spock 的 JMS 测试实用程序

android - AsyncHttpClient 和 org.apache.http.client 在 SSL 站点上失败,而标准 Android 方法运行良好

java - 在哪里放置 SSL keystore (.jks) 以及如何从 .jar 访问它?

java - 通过 jConsole/JMX 的 Activemq Artemis