-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
101 lines (86 loc) · 2.27 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"use strict";
const kexes = [];
function summarize(data) {
const pq = data.pq.length;
const npq = data.nonpq.length;
const unk = data.unknown.length;
const tot = pq + npq + unk;
const cached = data.cache.length;
if (pq == 0 && npq == 0 && unk == 0) {
if (cached > 0)
return ["unk", "all from cache"];
return ["unk", "No resources"];
}
if (pq > 0 && npq == 0 && unk == 0) {
return ["yes", "⚛️ post-quantum encrypted"];
}
if (pq == 0) {
return ["no", "❌ not post-quantum encrypted"];
}
if (pq > 0 && npq > 0) {
return ["warn", "⚠️ partially post-quantum encrypted (" + pq + "/" + tot + ")"];
}
return ["unk", "❓ unknown"];
}
function classify(kex) {
switch (kex) {
case "xyber768d00":
return "pq";
case "x25519":
case "P256":
case "P384":
case "P521":
return "nonpq";
default:
return "unknown";
}
}
async function logKex(details) {
const tid = details.tabId;
if (tid < 0) return;
if (details.type === "beacon")
return;
const info = await browser.webRequest.getSecurityInfo(
details.requestId,
{},
);
if (details.type === "main_frame" || !kexes[tid])
kexes[tid] = {
summary: null,
pq: [],
nonpq: [],
unknown: [],
cache: [],
};
let kex = info.keaGroupName;
let tp;
if (info.state === "insecure") {
tp = "nonpq";
kex = "no encryption";
} else {
tp = classify(kex);
}
if (details.fromCache)
tp = "cache";
kexes[tid][tp].push([kex, details.type, details.url]);
const [icon, summary] = summarize(kexes[tid]);
kexes[tid].summary = summary;
browser.browserAction.setIcon({
tabId: tid,
path: {
32: "icons/" + icon + ".png",
}
});
}
browser.webRequest.onHeadersReceived.addListener(logKex,
{urls: ["*://*/*"]},
["blocking"]
);
browser.tabs.onRemoved.addListener(function(tid, info) {
delete kexes[tid];
});
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "pqspy") {
sendResponse(kexes[message.tabId]);
}
});