-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +0,0 @@ | ||
var myRootCerts=new Set(); | ||
|
||
function onHeadersReceived(details,securityInfo){ | ||
if( | ||
securityInfo | ||
&& securityInfo.certificates | ||
&& securityInfo.certificates.length | ||
) { | ||
rootCert=securityInfo.certificates[securityInfo.certificates.length-1]; | ||
console.log("Adding",rootCert); | ||
myRootCerts.add(rootCert.fingerprint.sha256); | ||
console.log("Added!",myRootCerts); | ||
} else { | ||
console.log("This page has a bad connection..."); | ||
myRootCerts.add(null); | ||
} | ||
} | ||
|
||
function onCompleted(details){ | ||
let browserActionSpec=new Object(); | ||
|
||
try { | ||
console.log(myRootCerts); | ||
if(myRootCerts.size!=1) throw myRootCerts; | ||
|
||
for(let rootCert of myRootCerts){ | ||
// if(!rootCert.isBuiltInRoot) throw rootCert; | ||
|
||
// fp=rootCert.fingerprint.sha256; | ||
// if(!fp) throw rootCert.fingerprint.sha256; | ||
|
||
rootHost=sha256fp_host[rootCert]; | ||
if(!rootHost) throw fp; | ||
|
||
browserActionSpec.Icon={path:`images/root_icons/${rootHost}.ico`}; | ||
browserActionSpec.BadgeText={text:""}; | ||
browserActionSpec.Title={text:rootHost}; | ||
} | ||
} catch(e) { | ||
//TODO: more edge cases here (self-signed, etc.) | ||
if(myRootCerts.size==0) myRootCerts.add(null); | ||
for(let rootCert of myRootCerts){ | ||
console.warn('Unknown root CA',rootCert); | ||
} | ||
browserActionSpec.Icon={path:"images/Twemoji12_26a0.svg"}; | ||
browserActionSpec.BadgeText={text:"!"}; | ||
browserActionSpec.BadgeBackgroundColor={color:"red"}; | ||
browserActionSpec.Title={text:JSON.stringify(e)}; | ||
} | ||
|
||
console.log(browserActionSpec); | ||
return browserActionSpec; | ||
} | ||
|
||
browser.runtime.onMessage.addListener( | ||
(message) => { | ||
if('onHeadersReceived' in message) { | ||
let details=message.onHeadersReceived.details; | ||
let securityInfo=message.securityInfo; | ||
return onHeadersReceived(details,securityInfo); | ||
} if('onCompleted' in message) { | ||
let details=message.onCompleted.details; | ||
let browserActionSpec=onCompleted(details); | ||
console.log("Returning:",browserActionSpec); | ||
return browserActionSpec;//WHY ISN'T THIS SHOWING UP ON THE OTHER SIDE AAARGH | ||
} else { | ||
return false; | ||
} | ||
} | ||
); | ||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,81 @@ | ||
browser.webRequest.onHeadersReceived.addListener( | ||
async function onHeadersReceivedListener(details) { | ||
// console.log('onHeadersReceived event triggered!',{details:details}); | ||
const rootCertsByTab=new Object(); | ||
|
||
let tabId=details.tabId; | ||
let requestId=details.requestId; | ||
function genBrowserActionSpec(rootCerts){ | ||
let browserActionSpec=new Object(); | ||
for(let rootCert of (rootCerts.size?rootCerts:[null])){ | ||
try { | ||
rootHost=sha256fp_host[rootCert]; | ||
if(!rootHost) throw rootCert; | ||
|
||
let securityInfo = await browser.webRequest.getSecurityInfo(details.requestId,{certificateChain:true}); | ||
// console.log({requestId:requestId,securityInfo:securityInfo}); | ||
browserActionSpec.Icon={path:`images/root_icons/${rootHost}.ico`}; | ||
browserActionSpec.BadgeText={text:""}; | ||
browserActionSpec.Title={title:rootHost}; | ||
} catch(e) { | ||
//TODO: more edge cases here (self-signed, etc.) | ||
browserActionSpec.Icon={path:"images/Twemoji12_26a0.svg"}; | ||
browserActionSpec.BadgeText={text:"!"}; | ||
browserActionSpec.BadgeBackgroundColor={color:"red"}; | ||
browserActionSpec.Title={title:JSON.stringify(e)}; | ||
break; | ||
} | ||
} | ||
|
||
browser.tabs.sendMessage(tabId,{onHeadersReceived:details,securityInfo:securityInfo}); | ||
//console.log(browserActionSpec); | ||
return browserActionSpec; | ||
} | ||
|
||
return {};//TODO: maybe remove this line | ||
function updateTabBrowserAction(tabId){ | ||
let browserActionSpec=genBrowserActionSpec(rootCertsByTab[tabId]); | ||
for(let prop in browserActionSpec){ | ||
let cmd={tabId:tabId}; | ||
Object.assign(cmd,browserActionSpec[prop]); | ||
browser.browserAction['set'+prop](cmd); | ||
} | ||
} | ||
|
||
browser.webRequest.onBeforeRequest.addListener( | ||
//a new frame enters the tab; clear or create its rootCert set | ||
async function onBeforeMainFrameRequestListener(details){ | ||
let tabId=details.tabId; | ||
if(rootCertsByTab[tabId]===undefined) rootCertsByTab[tabId]=new Set(); | ||
else rootCertsByTab[tabId].clear(); | ||
console.log(rootCertsByTab); | ||
//TODO: fix memory leak | ||
}, | ||
{ | ||
types:['main_frame'],//TODO remove this, I just put it in for debugging | ||
types:['main_frame'], | ||
urls:['<all_urls>'] | ||
}, | ||
['blocking'] //this has to be blocking, or getSecurityInfo doesn't work | ||
['blocking'] | ||
); | ||
|
||
browser.webRequest.onCompleted.addListener( | ||
async function browserActionImageUpdate(details) { | ||
console.log("Beginning onCompleted...",{details:details}); | ||
|
||
browser.webRequest.onHeadersReceived.addListener( | ||
//this is the only point we can getSecurityInfo. | ||
//add it to rootCertsByTab | ||
async function onHeadersReceivedListener(details) { | ||
let tabId=details.tabId; | ||
let browserActionSpec=( | ||
await browser.tabs.sendMessage(tabId,{onCompleted:details}) ); | ||
console.log("Tab returned:",browserActionSpec);//WHY IS THIS UNDEFINED AAARGH | ||
let requestId=details.requestId; | ||
|
||
for(let prop in browserActionSpec){ | ||
let cmd={tabId:tabId}; | ||
Object.assign(cmd,browserActionSpec[prop]); | ||
browser.browserAction['set'+prop](cmd); | ||
let securityInfo = await browser.webRequest.getSecurityInfo(details.requestId,{certificateChain:true}); | ||
console.log({tabId:tabId,requestId:requestId,securityInfo:securityInfo}); | ||
|
||
try { | ||
if(!(securityInfo.certificates.length>0)) throw securityInfo; | ||
let rootCert=securityInfo.certificates[securityInfo.certificates.length-1]; | ||
rootCertsByTab[tabId].add(rootCert.fingerprint.sha256||null); | ||
console.log(rootCertsByTab); | ||
} catch(e) { | ||
rootCertsByTab[tabId].add(null); | ||
} | ||
|
||
updateTabBrowserAction(tabId); | ||
|
||
return {};//TODO: maybe remove this line | ||
|
||
}, | ||
{ | ||
types:['main_frame'], | ||
urls: ["<all_urls>"] | ||
} | ||
urls:['<all_urls>'] | ||
}, | ||
['blocking'] //this has to be blocking, or getSecurityInfo doesn't work | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"manifest_version": 2, | ||
"name": "cerdicator", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
|
||
"description": "nice", | ||
|
||
|