From d538892da62ce2614b9493e64b79f8bac1438fb6 Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Wed, 22 Feb 2023 20:47:39 +0100 Subject: Somewhat working options page Need to fix per tab thing --- background.js | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'background.js') 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: [""] - }, - [ - "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: [""] + }, + [ + "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 -- cgit