【问题标题】:How to import a self-signed certificate in Electron Application如何在 Electron Application 中导入自签名证书
【发布时间】:2019-08-27 14:15:11
【问题描述】:

在我的 Electron 应用程序中,我将访问一个 https RESTFUL 服务器,它已经给了我一个 crt 文件。如何在我的 Electron 应用中导入它并验证它是否安全?

我查看了 Electron 的文档。我找到了证书对象的描述: https://electronjs.org/docs/api/structures/certificate 但是我没有找到任何对象数据的样本以及如何导入和验证它。

现在我正在使用它来绕过它,但它并不安全:

app.on('certificate-error', (event, webContents, url, error, certificate, 
callback) => {
  event.preventDefault();
  callback(true);
});

【问题讨论】:

    标签: javascript node.js electron ssl-certificate


    【解决方案1】:

    您可以在电子的app 上使用importCertificatehttps://electronjs.org/docs/api/app#appimportcertificateoptions-callback-linux

    例如如果你的磁盘上有 crt 文件

    app.importCertificate('/path/my.crt', (result) => {
        if (result == 0) {
            // Success!
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2021-01-03
      • 2014-04-25
      • 2013-01-24
      • 2021-06-19
      • 2012-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多