【问题标题】:Request to API fails, reason: unable to verify the first certificate (and UNABLE_TO_VERIFY_LEAF_SIGNATURE)对 API 的请求失败,原因:无法验证第一个证书(和 UNABLE_TO_VERIFY_LEAF_SIGNATURE)
【发布时间】:2020-09-20 15:05:42
【问题描述】:

我们有一个 Apollo 服务器,它正在调用一个外部 API(它将 REST API 转换为 GraphQL)。直到几天前,这还运行良好,使用 cross-fetch 调用 API。

周五我们开始收到以下错误(如下)。我已经进行了一些搜索,它似乎与证书有关(例如,参见Error: unable to verify the first certificate in nodejs)。按照这个问题的答案,我尝试使用https://www.npmjs.com/package/ssl-root-cas 并把

require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create();

在我的代码开始时,但这似乎不起作用。

更重要的是,我不清楚自己在做什么。我对证书是什么、它们如何工作有一个一般的概念,但在这种情况下,我不清楚为什么我必须向一个不需要几个的公共 API 提供证书几天前。换句话说,虽然我想解决它,但我也想了解这里发生了什么。

{
  "errors": [
    {
      "message": "request to https://www.someapi.com failed, reason: unable to verify the first certificate",
      "locations": [],
      "path": [
        "someSearch"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "message": "request to https://www.someapi.com failed, reason: unable to verify the first certificate",
          "type": "system",
          "errno": "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
          "code": "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
          "stacktrace": [
            "FetchError: request to https://www.someapi.com failed, reason: unable to verify the first certificate",
            "    at ClientRequest.<anonymous> (/Users/abc/Documents/projects/yaa-interface-new/node_modules/node-fetch/lib/index.js:1455:11)",
            "    at ClientRequest.emit (events.js:210:5)",
            "    at TLSSocket.socketErrorListener (_http_client.js:406:9)",
            "    at TLSSocket.emit (events.js:210:5)",
            "    at emitErrorNT (internal/streams/destroy.js:92:8)",
            "    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)",
            "    at processTicksAndRejections (internal/process/task_queues.js:80:21)"
          ]
        }
      }
    }
  ],
  "data": {
    "someSearch": null
  }
}

【问题讨论】:

    标签: node.js ssl apollo apollo-server


    【解决方案1】:

    我能够让它工作--

    首先我下载了​​链 PEM 证书,灵感来自这里的第四个答案:Unable to verify leaf signature

    然后我用NODE_EXTRA_CA_CERTS,指向下载的PEM文件。

    NODE_EXTRA_CA_CERTS='./something-chain.pem' node index.js

    效果很好。

    【讨论】:

    • 答案的顺序,甚至海报的名字都会随着时间的推移而改变,使得“第四个答案”链接很有可能产生误导。请下次使用可以通过点击具体答案下方的“分享”按钮获得的永久链接。
    猜你喜欢
    • 2021-09-03
    • 2015-07-26
    • 2013-09-30
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 2022-07-27
    • 1970-01-01
    • 2021-10-20
    相关资源
    最近更新 更多