mirror of
https://github.com/DarrylNixon/CrowdTLS
synced 2024-04-22 06:17:20 -07:00
Initial MVP. Not optimal.
This commit is contained in:
parent
6115e56171
commit
329a71c5b7
3 changed files with 15 additions and 10 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
**/.DS_Store
|
|
@ -22,7 +22,8 @@
|
||||||
"default_popup": "crowdtls.html"
|
"default_popup": "crowdtls.html"
|
||||||
},
|
},
|
||||||
"host_permissions": [
|
"host_permissions": [
|
||||||
"https://crowdtls.mips.uk/api/*",
|
"https://crowdtls.mips.uk/api/v1/*",
|
||||||
|
"http://127.0.0.1:8000/api/v1/*",
|
||||||
"https://*/*"
|
"https://*/*"
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
|
|
19
worker.js
19
worker.js
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const API_BASE = "https://crowdtls.mips.uk/api/v1";
|
// const API_BASE = "https://crowdtls.mips.uk/api/v1";
|
||||||
|
const API_BASE = "http://127.0.0.1:8000/api/v1";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the given request details to extract and log security information.
|
* Processes the given request details to extract and log security information.
|
||||||
|
@ -21,6 +22,7 @@ const API_BASE = "https://crowdtls.mips.uk/api/v1";
|
||||||
*/
|
*/
|
||||||
async function process_request(details) {
|
async function process_request(details) {
|
||||||
try {
|
try {
|
||||||
|
let hostname = (new URL(details.url)).hostname;
|
||||||
let securityInfo = await browser.webRequest.getSecurityInfo(details.requestId, { certificateChain: true, rawDER: true });
|
let securityInfo = await browser.webRequest.getSecurityInfo(details.requestId, { certificateChain: true, rawDER: true });
|
||||||
if (securityInfo.state !== "insecure") {
|
if (securityInfo.state !== "insecure") {
|
||||||
const fingerprint = securityInfo.certificates[0].fingerprint.sha256;
|
const fingerprint = securityInfo.certificates[0].fingerprint.sha256;
|
||||||
|
@ -44,7 +46,7 @@ async function process_request(details) {
|
||||||
fpData.lastCheck = currentTime;
|
fpData.lastCheck = currentTime;
|
||||||
localStorage.setItem(fingerprint, JSON.stringify(fpData));
|
localStorage.setItem(fingerprint, JSON.stringify(fpData));
|
||||||
|
|
||||||
await check_fingerprint(securityInfo.certificates);
|
await check_fingerprint(hostname, securityInfo.certificates);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -57,16 +59,17 @@ async function process_request(details) {
|
||||||
*
|
*
|
||||||
* @async
|
* @async
|
||||||
* @function
|
* @function
|
||||||
|
* @param {string} hostname - The hostname of the website.
|
||||||
* @param {Array} certificates - The list of certificates.
|
* @param {Array} certificates - The list of certificates.
|
||||||
*/
|
*/
|
||||||
async function check_fingerprint(certificates) {
|
async function check_fingerprint(hostname, certificates) {
|
||||||
try {
|
try {
|
||||||
const fingerprints = certificates.map(cert => cert.fingerprint.sha256);
|
const fingerprints = certificates.map(cert => cert.fingerprint.sha256);
|
||||||
|
|
||||||
const response = await fetch(`${API_BASE}/check`, {
|
const response = await fetch(`${API_BASE}/check`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ fps: fingerprints }),
|
body: JSON.stringify({ host: hostname, fps: fingerprints }),
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -79,7 +82,7 @@ async function check_fingerprint(certificates) {
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
if (data["send"] === true) {
|
if (data["send"] === true) {
|
||||||
send_certificate_chain(certificates);
|
send_certificate_chain(hostname, certificates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,23 +96,23 @@ async function check_fingerprint(certificates) {
|
||||||
*
|
*
|
||||||
* @async
|
* @async
|
||||||
* @function
|
* @function
|
||||||
|
* @param {string} hostname - The hostname of the website.
|
||||||
* @param {Array} certificates - The list of certificates.
|
* @param {Array} certificates - The list of certificates.
|
||||||
* @throws Will log an error to the console if the request fails.
|
* @throws Will log an error to the console if the request fails.
|
||||||
*/
|
*/
|
||||||
async function send_certificate_chain(certificates) {
|
async function send_certificate_chain(hostname, certificates) {
|
||||||
try {
|
try {
|
||||||
let chain = {};
|
let chain = {};
|
||||||
certificates.forEach(cert => {
|
certificates.forEach(cert => {
|
||||||
chain[cert.fingerprint.sha256] = cert.rawDER;
|
chain[cert.fingerprint.sha256] = cert.rawDER;
|
||||||
});
|
});
|
||||||
console.log(JSON.stringify(chain));
|
|
||||||
|
|
||||||
const response = await fetch(`${API_BASE}/new`, {
|
const response = await fetch(`${API_BASE}/new`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify(chain),
|
body: JSON.stringify({ host: hostname, certs: chain }),
|
||||||
timeout: 10000
|
timeout: 10000
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue