如何信任来自电子应用程序的自签名证书? [英] How do I trust a self signed certificate from an electron app?
本文介绍了如何信任来自电子应用程序的自签名证书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个电子应用程序,它与我在 https://XXX.XX 拥有的服务器同步.XX.XXX:port 具有自签名证书.我如何信任来自我的电子应用程序的证书?
I have an electron app that syncs with a server I own at a https://XXX.XX.XX.XXX:port that has a self signed certificate. How can I trust that certificate from my electron app?
现在我得到:
Failed to load resource: net::ERR_INSECURE_RESPONSE
推荐答案
您需要将以下代码放入您的shell"中;(核心电子初始化)文件:
You need to put the following code into your "shell" (core electron init) file:
// SSL/TSL: this is the self signed certificate support
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
// On certificate error we disable default behaviour (stop loading the page)
// and we then say "it is all fine - true" to the callback
event.preventDefault();
callback(true);
});
这将允许不安全(无效)的证书,如自签名证书.
This would allow insecure (invalid) certificates like self-signed one.
⚠ 请注意,这不是连接服务器的安全方式.
欲了解更多,请查看文档:
https://electron.atom.io/docs/api/app/#event-certificate-error
For more, check the documentation:
https://electron.atom.io/docs/api/app/#event-certificate-error
这篇关于如何信任来自电子应用程序的自签名证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文