Nat*_*n J 4 ssl certificate self-signed node.js electron
我正在尝试设置一个在自定义本地域上使用 API 的项目(本地 DNS 服务器将自定义 tld 重定向到本地主机)。在我的计算机上,我有一个带有 mkcert 证书的 nginx 反向代理,该证书已加载并在 Firefox、Chrome 和 Curl 中运行(证书已安装并运行)。我正在运行 archlinux,如果这相关的话。
当我尝试使用电子应用程序时,我收到消息“证书链中的自签名证书”。
有办法解决这个问题吗?我已经尝试使用 nodejs 的 env var 禁用 ssl 验证并使用syswidecas npm 包,但没有成功。
这不是 Node.js 的问题,而是 Electron 中嵌入的 Chromium 的问题。要真正信任Chromium 拒绝的每个证书,您可以使用Electron 文档中的以下示例代码:
// 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
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5645 次 |
| 最近记录: |