Reintroduce Firefox support
This commit is contained in:
parent
b95c60972f
commit
a26a92f6bd
|
@ -28,11 +28,25 @@ let certDB = null;
|
||||||
let localCert = null;
|
let localCert = null;
|
||||||
|
|
||||||
// Utilities
|
// Utilities
|
||||||
function getCertificateChecksum(cert) {
|
function getCertificateChecksumFromSDP(desc) {
|
||||||
let fp = cert.getFingerprints().reduce((res, curr) =>
|
let fp = desc.sdp.split('\n').reduce((res, curr) =>
|
||||||
curr.algorithm === 'sha-256' ? curr : res, null);
|
curr.startsWith('a=fingerprint:sha-256 ') ? curr : res, null);
|
||||||
console.assert(fp !== null, 'Certificate does not have a sha256sum');
|
console.assert(fp !== null, 'Description does not have a sha256sum');
|
||||||
return fp.value.split(':').join('');
|
return fp.trim().split(' ')[1].split(':').join('').toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getCertificateChecksum(cert) {
|
||||||
|
if (cert.getFingerprints) {
|
||||||
|
let fp = cert.getFingerprints().reduce((res, curr) =>
|
||||||
|
curr.algorithm === 'sha-256' ? curr : res, null);
|
||||||
|
console.assert(fp !== null, 'Certificate does not have a sha256sum');
|
||||||
|
return fp.value.split(':').join('');
|
||||||
|
} else { // Firefox shim
|
||||||
|
let testConn = new RTCPeerConnection({certificates: [cert]});
|
||||||
|
let desc = await testConn.createOffer();
|
||||||
|
testConn.close();
|
||||||
|
return getCertificateChecksumFromSDP(desc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IndexedDB
|
// IndexedDB
|
||||||
|
@ -87,8 +101,10 @@ function onLoadCert() {
|
||||||
loadCertificate(certDB,
|
loadCertificate(certDB,
|
||||||
cert => {
|
cert => {
|
||||||
if (cert !== null) {
|
if (cert !== null) {
|
||||||
console.log('Loaded certificate:', getCertificateChecksum(cert));
|
getCertificateChecksum(cert).then(fp => {
|
||||||
console.log('Expires:', cert.expires);
|
let ts = new Date(cert.expires).toISOString();
|
||||||
|
console.log(`Loaded certificate (expires ${ts}): ${fp}`);
|
||||||
|
});
|
||||||
localCert = cert;
|
localCert = cert;
|
||||||
setCertStatusDisplay('Loaded');
|
setCertStatusDisplay('Loaded');
|
||||||
setButtonClickable('certUpload', true);
|
setButtonClickable('certUpload', true);
|
||||||
|
@ -128,8 +144,10 @@ function onNewCert() {
|
||||||
hash: 'SHA-256',
|
hash: 'SHA-256',
|
||||||
namedCurve: 'P-256',
|
namedCurve: 'P-256',
|
||||||
}).then(cert => {
|
}).then(cert => {
|
||||||
console.log('Generated new certificate:', getCertificateChecksum(cert));
|
getCertificateChecksum(cert).then(fp => {
|
||||||
console.log('Expires:', cert.expires);
|
let ts = new Date(cert.expires).toISOString();
|
||||||
|
console.log(`Generated new certificate (expires ${ts}): ${fp}`);
|
||||||
|
});
|
||||||
localCert = cert;
|
localCert = cert;
|
||||||
setCertStatusDisplay('Available');
|
setCertStatusDisplay('Available');
|
||||||
setButtonClickable('certUpload', true);
|
setButtonClickable('certUpload', true);
|
||||||
|
@ -142,50 +160,53 @@ function onNewCert() {
|
||||||
// Upload Button
|
// Upload Button
|
||||||
function onUploadCert() {
|
function onUploadCert() {
|
||||||
console.assert(localCert !== null, 'No local certificate available');
|
console.assert(localCert !== null, 'No local certificate available');
|
||||||
fetch('/keys', {
|
getCertificateChecksum(localCert).then(fp => {
|
||||||
method: 'POST',
|
fetch('/keys', {
|
||||||
headers: {
|
method: 'POST',
|
||||||
'Accept': 'application/json',
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Accept': 'application/json',
|
||||||
},
|
'Content-Type': 'application/json',
|
||||||
body: JSON.stringify({
|
},
|
||||||
'key': getCertificateChecksum(localCert),
|
body: JSON.stringify({
|
||||||
'expires': localCert.expires,
|
'key': fp,
|
||||||
}),
|
'expires': localCert.expires,
|
||||||
}).then(res => {
|
}),
|
||||||
if (res.status === 200) {
|
}).then(res => {
|
||||||
setCertStatusDisplay('Uploaded');
|
if (res.status === 200) {
|
||||||
} else {
|
setCertStatusDisplay('Uploaded');
|
||||||
res.json().then(res => {
|
} else {
|
||||||
setCertStatusDisplay(`Upload Failed (${res.status})`);
|
res.json().then(res => {
|
||||||
})
|
setCertStatusDisplay(`Upload Failed (${res.status})`);
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear Button
|
// Clear Button
|
||||||
function onClearCert() {
|
function onClearCert() {
|
||||||
console.assert(localCert !== null, 'No local certificate available');
|
console.assert(localCert !== null, 'No local certificate available');
|
||||||
let fp = getCertificateChecksum(localCert);
|
getCertificateChecksum(localCert).then(fp => {
|
||||||
fetch(`/keys/${fp}`, {
|
fetch(`/keys/${fp}`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
setCertStatusDisplay('Cleared');
|
setCertStatusDisplay('Cleared');
|
||||||
localCert = null;
|
localCert = null;
|
||||||
setButtonClickable('certUpload', false);
|
setButtonClickable('certUpload', false);
|
||||||
setButtonClickable('certClear', false);
|
setButtonClickable('certClear', false);
|
||||||
setButtonClickable('certSave', false);
|
setButtonClickable('certSave', false);
|
||||||
setButtonClickable('chatJoin', false);
|
setButtonClickable('chatJoin', false);
|
||||||
} else {
|
} else {
|
||||||
res.json().then(res => {
|
res.json().then(res => {
|
||||||
setCertStatusDisplay(`Delete Failed (${res.status})`);
|
setCertStatusDisplay(`Delete Failed (${res.status})`);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,13 +223,6 @@ function setChatStatusDisplay(status) {
|
||||||
document.getElementById('chatStatus').innerText = status;
|
document.getElementById('chatStatus').innerText = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCertificateChecksumFromSDP(desc) {
|
|
||||||
let fp = desc.sdp.split('\n').reduce((res, curr) =>
|
|
||||||
curr.startsWith('a=fingerprint:sha-256 ') ? curr : res, null);
|
|
||||||
console.assert(fp !== null, 'Description does not have a sha256sum');
|
|
||||||
return fp.trim().split(' ')[1].split(':').join('').toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
function verifyFingerprint(desc) {
|
function verifyFingerprint(desc) {
|
||||||
let fp = getCertificateChecksumFromSDP(desc);
|
let fp = getCertificateChecksumFromSDP(desc);
|
||||||
fetch(`/keys/${fp}`, {
|
fetch(`/keys/${fp}`, {
|
||||||
|
@ -319,6 +333,9 @@ function onRTCConnectionStateChange(event) {
|
||||||
let state = connection.connectionState;
|
let state = connection.connectionState;
|
||||||
|
|
||||||
console.log('WebRTC connection state update:', state);
|
console.log('WebRTC connection state update:', state);
|
||||||
|
if (state === 'failed') {
|
||||||
|
onLeaveChat();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join Button
|
// Join Button
|
||||||
|
|
Loading…
Reference in New Issue