Read SSL Certificates in a Firefox Extension

a 夏天 提交于 2020-01-05 04:28:07

问题


I am working on a Firefox extension that would display the SSL certificate information to the user. The actual information would be the same as the one built in to the browser, but I will be experimenting with layouts and other information for UX.

I've been working with Firefox extensions instead of add ons due to deprecation of add-ons in 2017, but this project will be finished before then.

I was trying the example found here, but the extension seems to stop on the require("chrome").

Next I tried writing simpler code to figure out how the example works, but this code doesn't have a channel attached to the request. My code, minus all sorts of printing statements, is below:

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);
  }
}

with a manifest like this:

  "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"
  }

Am I missing any permissions necessary to have access to the certificate? Is there a better way of grabbing certificate information?


回答1:


The wiki page you linked to refers to APIs available in the addon sdk and bootstrapped extensions. The kind of manifest indicates you're writing a webextensions which are far more limited.



来源:https://stackoverflow.com/questions/39809488/read-ssl-certificates-in-a-firefox-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!