summaryrefslogtreecommitdiff
path: root/background.js
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2023-02-22 20:47:39 +0100
committerNicholas Tay <nick@windblume.net>2023-02-22 20:47:39 +0100
commitd538892da62ce2614b9493e64b79f8bac1438fb6 (patch)
tree316841b4773e04721bfc530c574a1421ac153ec3 /background.js
parent79d89b63e0a75f94d88d55e41fc123c5bf46e38c (diff)
downloadcertain-d538892da62ce2614b9493e64b79f8bac1438fb6.tar.gz
certain-d538892da62ce2614b9493e64b79f8bac1438fb6.tar.bz2
certain-d538892da62ce2614b9493e64b79f8bac1438fb6.zip
Somewhat working options page
Need to fix per tab thing
Diffstat (limited to 'background.js')
-rw-r--r--background.js41
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