【发布时间】:2018-07-07 18:05:56
【问题描述】:
我似乎无法找到任何关于 webviews 的文档。有没有办法从 webview 获取 ssl 证书信息?
【问题讨论】:
标签: javascript node.js electron chromium
我似乎无法找到任何关于 webviews 的文档。有没有办法从 webview 获取 ssl 证书信息?
【问题讨论】:
标签: javascript node.js electron chromium
浏览器 API 或 Electron 都没有内置函数。但是你可以在主进程中通过node.js获取证书。例如使用“https”模块。
const https = require('https');
const options = {
hostname: 'nodejs.org',
agent: false,
ciphers: "ALL",
rejectUnauthorized: false
};
new Promise(function (resolve, reject) {
https.get(options, function (res) {
var certificate = res.socket.getPeerCertificate();
if(typeof (certificate) === 'undefined' || certificate === null) {
reject({message: 'The website did not provide a certificate'});
} else {
resolve(certificate);
}
});
}).then(function(certificate) {
console.log(certificate)
});
【讨论】: