【问题标题】:Installing custom SSL certificate in Node (UNABLE_TO_VERIFY_LEAF_SIGNATURE)在 Node (UNABLE_TO_VERIFY_LEAF_SIGNATURE) 中安装自定义 SSL 证书
【发布时间】:2023-03-09 15:47:01
【问题描述】:

我正在尝试访问 API,但出现以下错误:

{ FetchError: request to https://www.cryptopia.co.nz/api/GetMarkets failed, reason: unable to verify the first certificate
    at ClientRequest.<anonymous> (.../node_modules/node-fetch/index.js:133:11)
    at ClientRequest.emit (events.js:159:13)
    at TLSSocket.socketErrorListener (_http_client.js:389:9)
    at TLSSocket.emit (events.js:159:13)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at process._tickCallback (internal/process/next_tick.js:152:19)
  name: 'FetchError',
  message: 'request to https://www.cryptopia.co.nz/api/GetMarkets failed, reason: unable to verify the first certificate',
  type: 'system',
  errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
  code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }

我尝试使用ssl-root-cas 并尝试使用NODE_EXTRA_CA_CERTS 手动添加证书。这些都不起作用。

API 用于加密货币交换。我可以使用 Chrome 连接到它。我使用了一些 SSL 扫描程序,我得到“此服务器的证书链不完整”。以下是其中一台扫描仪的结果:https://www.ssllabs.com/ssltest/analyze.html?d=www.cryptopia.co.nz

经过一番谷歌搜索,该错误似乎是由于 Node 未下载中间证书引起的。 Chrome 下载了它,所以 Chrome 运行良好。我使用 Chrome 将证书下载为 .cer 文件,使用 OpenSSL 将其转换为 .pem 文件,然后使用 Node 的 NODE_EXTRA_CA_CERTS 加载它,但它没有做任何事情。

我该如何解决这个问题?

我无法更改服务器。我联系了 Cryptopia,但他们可能需要数周时间才能回复。很明显,我不会禁用严格的 SSL,因为我要处理金钱问题。

【问题讨论】:

  • 有人知道为什么 NODE_EXTRA_CA_CERTS 没有效果吗??

标签: javascript node.js ssl https


【解决方案1】:

您需要向您的应用程序提供整个 CA 链,即缺​​少的中间 CA 证书和根证书:

options=require('url').parse('https://www.cryptopia.co.nz/api/GetMarkets');
options.ca = require('fs').readFileSync('myca.pem');
require('https').get(options, (r) => { 
   console.log(r.headers) 
});

myca.pem 是中间“COMODO RSA 扩展验证安全服务器 CA”和根“COMODO RSA 证书颁发机构”证书的 PEM 表示形式的串联。我已将其作为 pastebin here 提供。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 2017-03-05
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    相关资源
    最近更新 更多