【发布时间】:2020-06-13 13:47:38
【问题描述】:
您好,我通过 eclipse docker 映像创建了一个 mosquitto 代理,最近按照本指南添加了 SSL/TLS 支持:http://www.steves-internet-guide.com/mosquitto-tls/。
当我在运行代理的 VPS 中进行 sshed 时,我可以使用以下命令:
mosquitto_pub -h VPS_NAME -t test/topic -p 8883 --cafile ca.crt -m message -u BROKER_USERNAME -P BROKER_PASSWORD
它发布的一切都很好。但是,当我在本地计算机上运行相同的命令时,出现错误:
'Unable to connect (Lookup error.).
我没有从代理容器中获得任何新日志,所以我认为它甚至没有到达容器。但是当我运行时:
mosquitto_pub -h BROKER_IP_ADRESS -t test/topic -p 8883 --cafile ca.crt -m message -u BROKER_USERNAME -P BROKER_PASSWORD
我确实收到了响应错误:发生 TLS 错误,并且在我的 docker 日志中我得到:
1583004287: New connection from LOCAL_IP_ADDRESS on port 8883.
1583004287: OpenSSL Error: error:14037438:SSL routines:ACCEPT_SR_KEY_EXCH:tlsv1 alert internal error
1583004287: OpenSSL Error: error:140370E5:SSL routines:ACCEPT_SR_KEY_EXCH:ssl handshake failure
1583004287: Socket error on client <unknown>, disconnecting.
当我将 --insecure 命令添加到发布时,我只能获得成功的发布发送,但是我想确保客户端知道它正在与正确的服务器通信,所以我不认为这是正确的解决方案。
最后我想在节点应用程序上运行一个mqtt客户端,我试过这段代码:
const fs = require('fs');
const optionsz = {
ca: [ fs.readFileSync(__dirname + '/ca.pem') ],
host: 'BROKER_IP_ADDRESS',
servername: 'VPS_NAME',
port: 8883,
rejectUnauthorized : false,
username : 'BROKER_USERNAME', // mqtt credentials if these are needed to connect
password : 'BROKER_PASSWORD',
clientId : 'test',
// Necessary only if the server's cert isn't for "localhost".
checkServerIdentity: () => { return null; },
};
class MqttHandler {
constructor() {
this.mqttClient = null;
};
connect() {
// Connect mqtt with credentials (in case of needed, otherwise we can omit 2nd param)
this.mqttClient = mqtt.connect(this.host, optionsz);
...
当我运行它时,我不断收到断开连接事件,并且在我的 docker 日志中我得到:
1583004505: New connection from LOCAL_IP_ADDRESS on port 8883.
1583004505: OpenSSL Error: error:140260FC:SSL routines:ACCEPT_SR_CLNT_HELLO:unknown protocol
1583004505: Socket error on client <unknown>, disconnecting.
我真的很困惑如何解决这个问题,我已经能够连接到没有 SSL/TLS 保护的代理,但我想让我的设备通信更安全。 感谢您的宝贵时间!
【问题讨论】: