diff options
Diffstat (limited to 'background.js')
-rw-r--r-- | background.js | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/background.js b/background.js index f619df2..59c6c2b 100644 --- a/background.js +++ b/background.js @@ -1,5 +1,7 @@ // Based on https://github.com/mdn/webextensions-examples/blob/main/root-cert-stats/background.js +let certs = []; + // On header receive, inspect cert and update app icon as required async function onHeaderReceive(details) { try { @@ -26,9 +28,12 @@ async function certInspectUpdate(requestId) { // root is last in the array cert chain let rootCA = securityInfo.certificates[securityInfo.certificates.length - 1]; - if (rootCA.subject.includes("CN=GlobalSign Root CA")) { - setIcon("nope"); - return; + + for (let cert of certs) { + if (rootCA.subject.includes(cert)) { + setIcon("nope"); + return; + } } setIcon("ok"); @@ -38,13 +43,23 @@ function setIcon(icon) { browser.browserAction.setIcon({ path: "icons/" + icon + ".png" }); } -// Listen for all header receive events, which contain the cert details we want -browser.webRequest.onHeadersReceived.addListener( - onHeaderReceive, - { - urls: ["<all_urls>"] - }, - [ - "blocking" - ] -);
\ No newline at end of file +function onReady() { + // Listen for all header receive events, which contain the cert details we want + browser.webRequest.onHeadersReceived.addListener( + onHeaderReceive, + { + urls: ["<all_urls>"] + }, + [ + "blocking" + ] + ); +} + +// Fetch config for certs list +const getting = browser.storage.sync.get("certs"); +getting.then(saved => { + certs = saved.certs; + console.log("certs=" + certs) + onReady(); +}, console.error);
\ No newline at end of file |