diff options
author | Nicholas Tay <nick@windblume.net> | 2023-02-22 20:47:39 +0100 |
---|---|---|
committer | Nicholas Tay <nick@windblume.net> | 2023-02-22 20:47:39 +0100 |
commit | d538892da62ce2614b9493e64b79f8bac1438fb6 (patch) | |
tree | 316841b4773e04721bfc530c574a1421ac153ec3 | |
parent | 79d89b63e0a75f94d88d55e41fc123c5bf46e38c (diff) | |
download | certain-d538892da62ce2614b9493e64b79f8bac1438fb6.tar.gz certain-d538892da62ce2614b9493e64b79f8bac1438fb6.tar.bz2 certain-d538892da62ce2614b9493e64b79f8bac1438fb6.zip |
Somewhat working options page
Need to fix per tab thing
-rw-r--r-- | background.js | 41 | ||||
-rw-r--r-- | manifest.json | 10 | ||||
-rw-r--r-- | options.html | 26 | ||||
-rw-r--r-- | options.js | 41 |
4 files changed, 103 insertions, 15 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 diff --git a/manifest.json b/manifest.json index acfa2fd..b685674 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "description": "Keep an eye on your certs, because who can be certain what they are.", "author": "Nicholas Tay <nick@windblume.net>", "version": "0.1.0", - "permissions": ["webRequest", "webRequestBlocking", "<all_urls>"], + "permissions": [ "webRequest", "webRequestBlocking", "<all_urls>", "storage" ], "background": { "scripts": [ "background.js" ] }, @@ -18,7 +18,13 @@ }, "browser_specific_settings": { "gecko": { - "strict_min_version": "62.0b5" + "strict_min_version": "62.0b5", + "id": "certain@nick.windblume.net" } + }, + "options_ui": { + "page": "options.html", + "open_in_tab": true, + "browser_style": false } } diff --git a/options.html b/options.html new file mode 100644 index 0000000..f04166d --- /dev/null +++ b/options.html @@ -0,0 +1,26 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8" /> +</head> +<body> + <h1>c/ertain</h1> + <h3>Extension settings</h3> + + <p> + Set up the issuer info for CAs you want to mark as insecure here (as matching substrings). Erase field and save to remove. + </p> + <p> + As per MDN: <i>For example: "CN=DigiCert SHA2 Secure Server CA,O=DigiCert Inc,C=US".</i> + </p> + <hr> + + <p> + <button id="addCert">+</button> + <ul id="certs"></ul> + <button id="save">Save</button> + </p> + + <script src="options.js"></script> +</body> +</html> diff --git a/options.js b/options.js new file mode 100644 index 0000000..2d42932 --- /dev/null +++ b/options.js @@ -0,0 +1,41 @@ +function addCertField() { + let elem = document.getElementById("certs"); + elem.insertAdjacentHTML("beforeend", `<li><input type="text"></li>`) +} + +function saveOptions() { + let certs = []; + for (let child of document.getElementById("certs").children) { + let cert = child.children[0].value; + if (!cert) + continue; + certs.push(cert); + } + browser.storage.sync.set({ + certs: certs + }).then(() => { + restoreOptions(); // reload list + alert("Saved"); + }); +} + +function restoreOptions() { + let getting = browser.storage.sync.get("certs"); + getting.then(saved => { + let certs = saved.certs || []; + let elem = document.getElementById("certs"); + elem.innerHTML = ""; + for (let cert of certs) { + let li = document.createElement("li"); + let input = document.createElement("input"); + input.type = "text"; + input.value = cert; + li.appendChild(input); + elem.appendChild(li); + } + }, console.error); +} + +document.addEventListener("DOMContentLoaded", restoreOptions); +document.getElementById("save").addEventListener("click", saveOptions); +document.getElementById("addCert").addEventListener("click", addCertField)
\ No newline at end of file |