ActiveMQ Artemis“needClientAuth=true”错误为“Empty client certificate chain”消息 (AMQ222208)

问题描述

我有 ActiveMQ Artemis 集群,具有共享存储的主动备份模式,版本 2.17.0。此集群使用 SSL。

我从 Kafka 集群中获取了密钥库/信任库文件,这些文件与 2-way TLS 完全兼容。我在 Artemis 中重复使用这些文件,它也能正常工作。但是,当我在 URL 字符串中启用 needClientAuth=true 时会出现问题。

文档内容如下:

needClientAuth

属性仅适用于 acceptor。它告诉连接到此接受器的客户端需要 2 向 SSL。有效值为 truefalse认值为 false

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


当我在接受者 URL 字符串中有 needClientAuth=true 时,我使用 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.

正如我所说,提到的密钥库/信任库在 Kafka 上运行良好,没有问题。但是,它不适用于 ActiveMQ Artemis。如果我从 needClientAuth=true URL 字符串中删除 acceptor,一切正常。

这是我生成密钥库/信任库的方法

# 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 个证书并在代理和客户端上使用该证书。

例如,代理需要在其密钥库中拥有自己的证书,该证书提供给客户端并且客户端在其信任库中拥有该证书。然后,客户端需要在其密钥库中拥有自己的证书,并将其提供给代理,而代理拥有的就是它的信任库。

据我所知,你没有这样做。查看 ActiveMQ Artemis 附带的 ssl-enabled-dual-authentication 示例。它包含使用自签名证书运行所需的所有 keytool 命令。使用简单的自签名证书启动并运行后,您可以继续使用由证书颁发机构签名的证书。

值得注意的是,如果您使用由证书颁发机构签署的证书,您只需 import the CA's root certificate into the JVM's truststore 在代理和客户端上,然后您就无需与任何个人信任库混为一谈。客户端和代理将隐式信任由您的 CA 签署的证书。

最后,您在 ActiveMQ Artemis CLI 中使用的 URL 看起来不正确,因为 keyStorePath 正在引用信任库 /opt/ssl/truststore.jks