node:internal/tls/secure-context:70
    context.setCert(cert);
            ^

Error: error:0A00018E:SSL routines::ca md too weak
    at node:internal/tls/secure-context:70:13
    at Array.forEach (<anonymous>)
    at setCerts (node:internal/tls/secure-context:68:3)
    at configSecureContext (node:internal/tls/secure-context:157:5)
    at Object.createSecureContext (node:_tls_common:117:3)
    at Object.connect (node:_tls_wrap:1641:48)
    at Object.buildStream (/Users/dev/heytz_node_api/heytz_knob_api/node_modules/mqtt/build/lib/connect/tls.js:19:38)
    at MqttClient.wrapper [as streamBuilder] (/Users/dev/heytz_node_api/heytz_knob_api/node_modules/mqtt/build/lib/connect/index.js:127:40)
    at MqttClient.connect (/Users/dev/heytz_node_api/heytz_knob_api/node_modules/mqtt/build/lib/client.js:217:28)
    at new MqttClient (/Users/dev/heytz_node_api/heytz_knob_api/node_modules/mqtt/build/lib/client.js:193:18) {
  library: 'SSL routines',
  reason: 'ca md too weak',
  code: 'ERR_SSL_CA_MD_TOO_WEAK'
}

这个是我遇到的问题,我在网上找相关的文章也没有是关于mqtt连接上的,但是有一些报错跟这个是一样的,方法有两种

一、降低node版本

由于我的node版本是18.17.1,属于高版本,对于加密以及安全验证肯定是比低版本要严格,秘钥加密长度最少要达到2048,而我的密钥文件长度只有1024,所以会报这个md弱错误,只需要将node 版本降到较低版本就好,我的是降到14.17.4

由于我用的是mac,在这里我只说mac降低node版本的操作

首先要到官网下载较低的相应版本,如果不会,自己网上找,一找一大把连接出来,将node版本安装好后,只需要在终端或者在vsCode 终端输入 

n  回车,就可以看到如下图已安装node版本,上下选择自己想要的版本,回车就替换好了,然后在运行子的mqtt服务器就能够正常连接上了

二、将密钥文件加密长度达到2048,这个我没试验过,网上有挺多帖子是这么说的,可以尝试下。

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐