大网数据广告活动
服务器运维问答

MQTT certificates verification fails

· 52CE 我爱测

I'm been desperately trying to get my MQTT clients to connect to my MQTT broker which is set up with a certificate from a CA (Letsencrypt). To be able to get the CA certificate, I've used the letsencrypt python command ( https://…

问题原文

原帖链接 · user5740843 · CC BY-SA 3.0

I'm been desperately trying to get my MQTT clients to connect to my MQTT broker which is set up with a certificate from a CA (Letsencrypt).

To be able to get the CA certificate, I've used the letsencrypt python command (https://pypi.python.org/pypi/letsencrypt/0.4.1)

./letsencrypt-auto certonly -d www.myserver.com

This has given me:

lrwxrwxrwx 1 root root   41 Mar  6 23:50 cert.pem
lrwxrwxrwx 1 root root   42 Mar  6 23:50 chain.pem
lrwxrwxrwx 1 root root   46 Mar  6 23:50 fullchain.pem
lrwxrwxrwx 1 root root   44 Mar  6 23:50 privkey.pem

These files I am also using for the SSL encryption on my website (apache2) which seems to work just fine as in my conf file:

SSLCertificateFile /etc/letsencrypt/live/www.server.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.server.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf

And when going on my webserver, I see the SSL icon, and it works.

Now, when I put these files inside my /etc/mosquitto/mosquitto.conf:

cafile /etc/letsencrypt/live/www.myserver.com/fullchain.pem
certfile /etc/letsencrypt/live/www.myserver.com/cert.pem
keyfile /etc/letsencrypt/live/www.myserver.com/privkey.pem

And I was able to start the broker, v1.4.8 fine:

[ ok ] mosquitto is running.

and from the log:

1457462631: mosquitto version 1.4.8 (build date Sun, 14 Feb 2016 15:06:55 +0000) starting

Yet, when I try to subscribe to the test topic, to, well, test, using this command from the client:

mosquitto_sub version 1.4.8 running on libmosquitto 1.4.8.

Running command:

root@titan:~# mosquitto_pub -h www.myserver.com -p 8883 -t test --cafile /etc/letsencrypt/live/www.myserver.com/fullchain.pem

It mentions in my command line:

Unable to connect (A TLS error occurred.).

A more curious look inside to mosquitto.log file reveals me:

1463562141: Socket error on client <unknown>, disconnecting.
1463562154: New connection from X.X.X.X on port 8889.

Which gives me surprising little information. A python script I use from a website gives me a little bit more information;

Python script:

import os, subprocess, socket, sys, time, struct import *
import paho.mqtt.client as mqtt

dir = "/etc/letsencrypt/live/www.server.com/"

def on_connect(mqttc, obj, flags, rc):
    if rc != 0:
        exit(rc)
    else:
        mqttc.disconnect()

def on_disconnect(mqttc, obj, rc):
    obj = rc

run = -1
mqttc = mqtt.Client("08-ssl-connect-crt-auth", run)
mqttc.tls_set(dir + "fullchain.pem", dir + "cert.pem", dir + "privkey.pem")
mqttc.on_connect = on_connect
mqttc.on_disconnect = on_disconnect

mqttc.connect("www.server.com", 8889)
while run == -1:
    mqttc.loop()

exit(run)

And this returns me:

ssl.SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

I'm at a loss here. This makes no sense to me! Any help is appreciated!

已采纳解答

原帖链接 · ralight · CC BY-SA 3.0

ssl.SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

This suggests that the hostname you are connecting with doesn't match the hostname in the certificate.

With mosquitto_pub try using the --insecure option.

Alternatively, you've not got the right chain of CA certificates and so the server cert can't be verified by the client.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。