Hash all fingerprints into the manual security check

The manual check used to show the first 8 bytes of the first fingerprint
each SDP named, so an interposer could add its own certificate beside the
claimed one and the codes still matched. Now each code is the first 16
bytes of a SHA-256 over every fingerprint the SDP names, also ones hidden
in other lines, so whatever the browser uses changes the code. Without a
fingerprint on either side the connection ends. End-to-end tests try a
claimed certificate in several hiding places.

The README says that a working connection isn't necessarily direct and what
the meeting tracker sees, TODO.md lists hardening from a security review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SchluffeandClaude Opus 5.5 committed 2026-10-29 00:23:04 +01:00
1 parent ae871a2647
commit ae1e3bef9b
5 files changed
+205 -38

No files matched your search

+40 -19
View File
@@ -442,24 +442,39 @@ const BLOCKED = 'a network in between, e.g. a VPN or firewall, may block direct
const host = (url: string) => URL.parse(url)?.host || url;
// Anti-MITM check: the first 8 bytes of both DTLS certificate fingerprints, fewer an interposer can
// brute force with matching certificates. My local code must equal the peer's remote code and vice
// versa, otherwise someone interposed on the signaling.
export function securityCheck(pc: RTCPeerConnection) {
const short = (sdp = '') =>
sdp
.match(/a=fingerprint:\S+ ([0-9A-F:]+)/i)?.[1]
?.toUpperCase()
.split(':')
.slice(0, 8)
.join(' ') ?? '?';
return { local: short(pc.localDescription?.sdp), remote: short(pc.remoteDescription?.sdp) };
}
// Every fingerprint the SDP names, in full: one added beside the real one changes the result too.
// Browsers may move them between session and media level, so each counts once.
// Browsers may move them between session and media level, so each counts once. Any a=fingerprint
// counts, also one hidden in another line: one the browser ignores only makes the result differ,
// one missed that the browser uses would let an interposer through. So nothing depends on how a
// browser splits lines.
export const fingerprints = (sdp: string) =>
[...new Set([...sdp.matchAll(/^a=fingerprint:(.+)$/gim)].map(([, line]) => line!.trim().toLowerCase()))].sort();
[
...new Set(
[...sdp.matchAll(/a=fingerprint:([^\n]*)/gi)].map(([, fingerprint]) =>
fingerprint!.trim().replace(/\s+/g, ' ').toLowerCase(),
),
),
].sort();
// Anti-MITM check of the manual exchange: the first 16 bytes of a SHA-256 over all DTLS
// certificate fingerprints of each side. An interposer can try one cheaply, it only has to vary a
// line the browser ignores, so it takes that many to be out of its reach. My local code must equal
// the peer's remote code and vice versa, otherwise someone interposed on the signaling. All of them
// count, like in prove: one certificate may be named by several hash functions, and a browser may
// accept a certificate by any of them. Without one on either side there is nothing to check:
// undefined.
export async function securityCheck(pc: RTCPeerConnection) {
const short = async (sdp = '') => {
const list = fingerprints(sdp);
if (!list.length) return;
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(JSON.stringify(list)));
return Array.from(new Uint8Array(digest, 0, 16), (byte) => byte.toString(16).padStart(2, '0'))
.join(' ')
.toUpperCase();
};
const [local, remote] = await Promise.all([short(pc.localDescription?.sdp), short(pc.remoteDescription?.sdp)]);
if (local && remote) return { local, remote };
}
// The security check of tracker signaling, resolves once the peer proved the code. Each side signs its
// role, its SDP type, and the fingerprints of both certificates as it sees them. The peer checks that
@@ -522,7 +537,6 @@ function connected(
events.log(`connected via ${via}`);
events.log('waiting for the security check');
if (key) events.status('start', 'Connected, checking the code');
else events.status('wait', `Compare the security codes above with the ${peer}`);
let done = false;
const end = (reason: string) => {
if (done) return;
@@ -541,8 +555,15 @@ function connected(
return {
checked: key
? prove(pc, channel, key, end).then(() => events.log('security check passed'))
: new Promise((resolve) =>
events.check({ ...securityCheck(pc), confirm: resolve, reject: () => end('security check failed') }),
: securityCheck(pc).then(
(codes) =>
new Promise<void>((resolve) => {
// The peer may have left while the codes were computed.
if (done) return;
if (!codes) return end('no certificate to check');
events.check({ ...codes, confirm: resolve, reject: () => end('security check failed') });
events.status('wait', `Compare the security codes above with the ${peer}`);
}),
),
start: () => (done = true),
end,