forked from mdn/webextensions-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
38 lines (34 loc) · 1 KB
/
Copy pathbackground.js
File metadata and controls
38 lines (34 loc) · 1 KB
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
"use strict";
var rootCertStats = {};
/*
On an onHeadersReceived event, if there was a successful TLS connection
established, fetch the root cert and look at its subject.
If we haven't seen this subject before, add it. If we have, increment its stats.
*/
async function logRootCert(details) {
try {
let securityInfo = await browser.webRequest.getSecurityInfo(
details.requestId,
{"certificateChain": true}
);
if ((securityInfo.state == "secure" || securityInfo.state == "weak") &&
!securityInfo.isUntrusted) {
let rootName = securityInfo.certificates[securityInfo.certificates.length - 1].subject;
if (rootCertStats[rootName] === undefined) {
rootCertStats[rootName] = 1;
} else {
rootCertStats[rootName] = rootCertStats[rootName] + 1;
}
}
}
catch(error) {
console.error(error);
}
}
/*
Listen for all onHeadersReceived events.
*/
browser.webRequest.onHeadersReceived.addListener(logRootCert,
{urls: ["<all_urls>"]},
["blocking"]
);