【发布时间】:2019-10-28 08:28:26
【问题描述】:
在我的服务器上,我使用的是基于 node.js 的 mqtt 代理 (mosca),它具有来自 Certbot 的 SSL 证书。
在客户端,我也在使用基于 node.js 的解决方案 (mqtt.js)
现在我的问题是:为了安全连接,我需要拥有rejectUnauthorized: true 属性吗?因为我只有在拥有自签名证书时才能让它工作,这当然不是很安全。在服务器端拥有常规 SSL 证书时,我无法使用 rejectUnauthorized: true,为什么?
我的服务器选项:
const settings = {
port: 8883,
secure: {
keyPath: '/etc/letsencrypt/live/XXX/privkey.pem',
certPath: '/etc/letsencrypt/live/XXX/cert.pem',
},
https: {
port: 443,
bundle: true,
static: './',
},
};
我在客户端的连接选项:
const options = {
host: "XXXXXX",
port: 8883,
protocol: "mqtts",
rejectUnauthorized: true,
username: process.env.USERNAME,
password: process.env.PASSWORD,
};
接收错误:
Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1318:34)
at TLSSocket.emit (events.js:210:5)
at TLSSocket._finishInit (_tls_wrap.js:792:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:606:12) {
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
}
【问题讨论】:
-
编辑问题以在客户端设置中不使用
rejectUnauthorized: true时显示错误。还包括您正在使用的 NodeJS 版本。 -
我会开始检查常规证书上的 fqdn 是否与您服务器上的相匹配,如果您可以发布收到的任何错误消息,都会有帮助。