ssl - ActiveMQ Artemis “needClientAuth=true” 错误输出“空客户端证书链”。消息(AMQ222208)
问题描述
我有 ActiveMQ Artemis 集群,具有共享存储的主动备份模式,版本 2.17.0。SSL 与此集群一起使用。
我从 Kafka 集群中获取了密钥库/信任库文件,这些文件与 2-way TLS 完全兼容。我将这些文件与 Artemis 一起使用,它也可以正常工作。但是,当我needClientAuth=true
在 URL 字符串中启用时,问题就来了。
这是文档中的内容:
需要ClientAuth
此属性仅适用于
acceptor
. 它告诉连接到此接受器的客户端需要 2-way SSL。有效值为true
或false
。默认为false
。
所以如果我想实现2-way TLS,我必须使用这个选项。然后两者 - 服务器和客户端都必须拥有自己的密钥库/信任库对。在我的情况下,服务器和客户端都是相同的。
当我有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.
正如我所说,提到的密钥库/信任库与 Kafka 配合得很好,没有问题。但是,它不适用于 ActiveMQ Artemis。如果我needClientAuth=true
从acceptor
URL 字符串中删除,一切正常。
这是我生成密钥库/信任库的方式:
# 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 个证书并在代理和客户端上使用该证书。
例如,代理需要在其提供给客户端的密钥库中拥有自己的证书,并且客户端在其信任库中拥有该证书。然后,客户端需要在其密钥库中拥有自己的证书,并将其提供给代理,并且代理拥有的是其信任库。
据我所知,你没有这样做。看一下ssl-enabled-dual-authentication
ActiveMQ Artemis 附带的示例。它包含keytool
使用自签名证书运行所需的所有命令。一旦您使用简单的自签名证书启动并运行它,您就可以继续使用由证书颁发机构签名的证书。
值得注意的是,如果您使用由证书颁发机构签名的证书,您只需将 CA 的根证书导入代理和客户端上的 JVM 信任库,然后您就不需要弄乱任何单独的信任库。客户端和代理将隐式信任由您的 CA 签名的证书。
最后,您在 ActiveMQ Artemis CLI 中使用的 URL 看起来不正确,因为keyStorePath
它引用了 truststore /opt/ssl/truststore.jks
。
推荐阅读
- java - 创建具有附加类型约束的泛型类的构造函数
- powerbi - Power bi 计算包含行不工作
- r - R - 如何过滤数据列以显示特定值
- java - 将菜单栏添加到 JFrame 时遇到问题
- react-native - 反应导航获取类组件内的堆栈导航器标题高度(无挂钩)
- wordpress - 我的 wordpress 网站的移动版本有问题
- ios - 从另一个类中的按钮重新加载 UITableView (Swift)
- xml - 如何在 [alfresco] 表单控件中隐藏/显示集合
- json - Angular 使用 RxJS - 当 JSON 对象具有多个属性时如何映射数据
- performance - 如何渲染仅存在于视觉范围内的折线点