【问题标题】:Nodejs Safe MQTT ConnectionNodejs 安全 MQTT 连接
【发布时间】: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 是否与您服务器上的相匹配,如果您可以发布收到的任何错误消息,都会有帮助。

标签: node.js ssl mqtt


【解决方案1】:

更新您的服务器端设置以指向 fullchain.pem 而不是 cert.pem 文件

这将在服务器呈现的内容中包含完整的信任链,然后应该包含根 CA 证书,该证书将位于嵌入到 NodeJS 中的受信任集中。

【讨论】:

    猜你喜欢
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 2020-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    相关资源
    最近更新 更多