在 Firefox 扩展中读取 SSL 证书
Read SSL Certificates in a Firefox Extension
我正在开发一个可以向用户显示 SSL 证书信息的 Firefox 扩展。实际信息与浏览器内置的信息相同,但我将尝试使用布局和其他用户体验信息。
由于 2017 年附加组件的弃用,我一直在使用 Firefox 扩展而不是附加组件,但该项目将在此之前完成。
我正在尝试找到 here 的示例,但扩展似乎在 require("chrome")
上停止了。
接下来,我尝试编写更简单的代码来了解示例的工作原理,但此代码没有附加到请求的通道。我的代码,减去各种打印语句,如下:
document.getElementById("click_button").addEventListener("click",
function(e) {
var url = "https://secure-website-example.google.com";
xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.addEventListener("error",
function(e) {
dumpSecurityInfo(xhr, -1);
}, false);
xhr.onload = function(e) {
dumpSecurityInfo(xhr);
};
xhr.send();
});
function dumpSecurityInfo(xhr, error) {
var channel = xhr.channel;
try {
console.log("Connection status:");
if (!error) { console.log("Succeeded"); }
else { console.log("Failed :("); }
var securityInfo = channel.securityInfo;
} catch(err) {
alert(err);
}
}
清单如下:
"manifest_version": 2,
"name": "Certificate Browser",
"version": "1.0",
...
"permissions": [
"activeTab",
"webRequest",
"https://secure-website-example.google.com/*"
],
"browser_action": {
...
"default_popup": "popup/certificate_information.html"
}
我是否缺少访问证书所需的任何权限?有没有更好的抓取证书信息的方法?
您链接到的 wiki 页面引用了 addon sdk and bootstrapped extensions. The kind of manifest indicates you're writing a webextensions 中可用的 API,这些 API 非常有限。
我正在开发一个可以向用户显示 SSL 证书信息的 Firefox 扩展。实际信息与浏览器内置的信息相同,但我将尝试使用布局和其他用户体验信息。
由于 2017 年附加组件的弃用,我一直在使用 Firefox 扩展而不是附加组件,但该项目将在此之前完成。
我正在尝试找到 here 的示例,但扩展似乎在 require("chrome")
上停止了。
接下来,我尝试编写更简单的代码来了解示例的工作原理,但此代码没有附加到请求的通道。我的代码,减去各种打印语句,如下:
document.getElementById("click_button").addEventListener("click",
function(e) {
var url = "https://secure-website-example.google.com";
xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.addEventListener("error",
function(e) {
dumpSecurityInfo(xhr, -1);
}, false);
xhr.onload = function(e) {
dumpSecurityInfo(xhr);
};
xhr.send();
});
function dumpSecurityInfo(xhr, error) {
var channel = xhr.channel;
try {
console.log("Connection status:");
if (!error) { console.log("Succeeded"); }
else { console.log("Failed :("); }
var securityInfo = channel.securityInfo;
} catch(err) {
alert(err);
}
}
清单如下:
"manifest_version": 2,
"name": "Certificate Browser",
"version": "1.0",
...
"permissions": [
"activeTab",
"webRequest",
"https://secure-website-example.google.com/*"
],
"browser_action": {
...
"default_popup": "popup/certificate_information.html"
}
我是否缺少访问证书所需的任何权限?有没有更好的抓取证书信息的方法?
您链接到的 wiki 页面引用了 addon sdk and bootstrapped extensions. The kind of manifest indicates you're writing a webextensions 中可用的 API,这些 API 非常有限。