我正在尝试在 Ubuntu linux 机器上运行 mosquitto_pub 如下:
vbhadra@vbhadra-VirtualBox:~$ mosquitto_pub -h iot.eclipse.org -p 8883 --capath /etc/ssl/certs/ -t house/s1 -m "test message" -d
Client mosqpub/9204-vbhadra-Vi sending CONNECT
Client mosqpub/9204-vbhadra-Vi received CONNACK
Client mosqpub/9204-vbhadra-Vi sending PUBLISH (d0, q0, r0, m1, 'house/s1', ... (12 bytes))
Client mosqpub/9204-vbhadra-Vi sending DISCONNECT
可以看出 mosquitto_pub 作品文件。现在我想尝试手动下载 iot.eclipse.org 证书,然后将其与 mosquitto_pub 一起使用,而不是使用 Ubuntus /etc/ssl/certs/ 证书。
所以我做了以下事情:
ex +'/BEGIN CERTIFICATE/,/END CERTIFICATE/p' <(echo | openssl s_client -showcerts -connect iot.eclipse.org:8883) -scq > file.crt
将 file.crt 保存在一个位置:/home/vbhadra/remote_certificate/。
现在,我再次尝试以下操作:
mosquitto_pub -h iot.eclipse.org -p 8883 --capath /home/vbhadra/remote_certificate/ -t house/s1 -m "test message" -d
但是上面的方法很失败。通过捕获 tcpdump,我可以在 Wireshark 中看到我的 Ubuntu 客户端正在将“致命:未知 CA”发送回 iot.eclipse.org。
到目前为止,根据我的一点理解,我可以认为该证书没有由任何 CA 签名,因此 mosquitto 客户端拒绝了它。我一直试图弄清楚如何才能获得证书签名(自签名??),但到目前为止还没有任何线索。
我尝试使用 openssl verify 验证我保存的 file.crt 的证书文件,如下所示:
openssl verify -CApath /home/vbhadra/remote_certs/ /home/vbhadra/remote_certs/file2.crt
/home/vbhadra/remote_certs/file2.crt: CN = iot.eclipse.org
error 20 at 0 depth lookup:unable to get local issuer certificate
在这一点上,我有点失落。人们似乎建议将 .pem 证书文件与 openssl verify 一起使用,但不知道该怎么做,基本上我迷路了。请帮助任何指针以进一步研究。
当您运行echo | openssl s_client -showcerts -connect iot.eclipse.org:8883
命令并查看输出时,它包含多个证书,我认为这可能是您使用 ex 拆分它的方式的问题。
您将需要这两个证书来提供完整的证书链,以验证 iot.eclipse.org 的最终用户证书。
您是否还在包含 ca 文件的目录中运行了 ca_rehash(或 ubuntu 上的 c_rehash)?
--capath
定义包含受信任的 PEM 编码 CA 证书的目录的路径。用于启用 SSL 通信。
要使 --capath 正常工作,证书文件必须以“.crt”作为文件结尾,并且每次添加/删除证书时都必须运行“c_rehash”。
我必须重命名文件以结尾.pem
(因为这实际上是它们)并将DST_Root_CA_X3.pem
文件也从 /etc/ssl/certs复制到 ca 目录中。
此外,如果您想使用自己的私有 CA,那么使用--cafile
可能会更简单一些。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句