我正在尝试设置一个在自定义本地域上使用 API 的项目(本地 DNS 服务器将自定义 tld 重定向到 localhost)。在我的计算机上,我有一个带有 mkcert 证书的 nginx 反向代理,该证书已在 Firefox、Chrome 和 Curl 中加载并运行(证书已安装并运行)。我正在运行archlinux,如果这是相关的。
当我尝试使用 Electron 应用程序时,我收到消息“证书链中的自签名证书”。
有什么办法可以解决这个问题?我已经尝试使用 nodejs 的 env var 禁用 ssl 验证并使用 syswidecas npm 包,但没有运气。
最佳答案
这不是 Node.js 的问题,而是嵌入在 Electron 中的 Chromium 的问题。要真正信任 Chromium 拒绝的每个证书,您可以使用 Electron documentation 中的以下示例中的代码。 :
// in your main process, having Electron's `app` imported
app.on ("certificate-error", (event, webContents, url, error, cert, callback) => {
// Do some verification based on the URL to not allow potentially malicious certs:
if (url.startsWith ("https://yourdomain.tld")) {
// Hint: For more security, you may actually perform some checks against
// the passed certificate (parameter "cert") right here
event.preventDefault (); // Stop Chromium from rejecting the certificate
callback (true); // Trust this certificate
} else callback (false); // Let Chromium do its thing
});
关于node.js - Electron 中的自签名证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63923644/