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:
1 parent
ae871a2647
commit
ae1e3bef9b
5 files changed
+205
-38
No files matched your search
+72
-2
@@ -291,9 +291,9 @@ async function connect(mode: string, sender: Page, receiver: Page, source: strin
|
||||
if (mode === 'tracker') return proven(sender, receiver);
|
||||
|
||||
const check = (page: Page, side: string) => page.locator(`#check-${side}`).textContent();
|
||||
// Each side shows ? until it has that fingerprint, the remote one can come after the local one.
|
||||
// The check shows up once both are connected, which can take a while.
|
||||
for (const side of ['local', 'remote']) {
|
||||
await expect(sender.locator(`#check-${side}`)).toHaveText(/^([0-9A-F]{2} ){7}[0-9A-F]{2}$/, {
|
||||
await expect(sender.locator(`#check-${side}`)).toHaveText(/^([0-9A-F]{2} ){15}[0-9A-F]{2}$/, {
|
||||
timeout: 45_000,
|
||||
});
|
||||
}
|
||||
@@ -383,6 +383,33 @@ async function payload(content: Buffer, name = 'payload.bin') {
|
||||
return source;
|
||||
}
|
||||
|
||||
// Where a man in the middle of the manual exchange may put the a=fingerprint line it claims beside
|
||||
// its own: a parser may read the claimed one where the browser reads the own one. With the own one
|
||||
// on a line of its own the browser connects to the middle. Or the own one where a parser may miss
|
||||
// it: Chromium and Firefox don't read it there and don't connect, a browser that did must not get
|
||||
// the sender's code either.
|
||||
const HIDDEN: Record<string, { connects: boolean; place: (own: string, claimed: string) => string }> = {
|
||||
'a line before': { connects: true, place: (own, claimed) => `${claimed}\r\n${own}` },
|
||||
'a candidate line': {
|
||||
connects: true,
|
||||
place: (own, claimed) => `a=candidate:1 1 udp 1 127.0.0.1 9 typ host ${claimed}\r\n${own}`,
|
||||
},
|
||||
'another attribute': { connects: true, place: (own, claimed) => `a=x-decoy:${claimed}\r\n${own}` },
|
||||
'a line after a bare CR': { connects: true, place: (own, claimed) => `a=x-decoy:\r${claimed}\r\n${own}` },
|
||||
'an indented own line': { connects: false, place: (own, claimed) => `${claimed}\r\n ${own}` },
|
||||
'an own line after a bare CR': { connects: false, place: (own, claimed) => `${claimed}\r\na=x-decoy:\r${own}` },
|
||||
};
|
||||
|
||||
// The security code of the manual exchange for these fingerprints, like securityCheck in src/core.ts.
|
||||
const manualCode = (fingerprints: string[]) =>
|
||||
createHash('sha256')
|
||||
.update(JSON.stringify(fingerprints))
|
||||
.digest('hex')
|
||||
.slice(0, 32)
|
||||
.toUpperCase()
|
||||
.match(/../g)!
|
||||
.join(' ');
|
||||
|
||||
// Interoperability and data integrity between every pair, with no server involved.
|
||||
for (const from of Object.keys(BROWSERS)) {
|
||||
for (const to of Object.keys(BROWSERS)) {
|
||||
@@ -759,6 +786,49 @@ for (const name of Object.keys(BROWSERS)) {
|
||||
});
|
||||
});
|
||||
|
||||
// A man in the middle of the manual exchange hands the receiver an offer of its own, claiming the
|
||||
// certificate the sender would name beside its own one, see HIDDEN. However the browser takes that,
|
||||
// the receiver never shows the sender's code: it doesn't connect, or its code covers the middle's
|
||||
// certificate. Where it connects, the browser accepted the middle's, so without the check the
|
||||
// middle would get the file.
|
||||
for (const [variant, { connects, place }] of Object.entries(HIDDEN)) {
|
||||
test(`check: ${name} manual exchange shows other codes for a certificate claimed in ${variant}`, async () => {
|
||||
const [middle, receiver] = await Promise.all([open(name), open(name)]);
|
||||
const claimed = `sha-256 ${Array.from(randomBytes(32), (byte) => byte.toString(16).padStart(2, '0')).join(':')}`;
|
||||
|
||||
await withLogs(middle, receiver, async () => {
|
||||
for (const page of [middle, receiver]) await page.uncheck('#stun');
|
||||
await middle.setInputFiles('input[type=file]', await payload(randomBytes(1000)));
|
||||
await middle.click('#send-manual summary');
|
||||
await middle.click('#create-offer');
|
||||
await expect(middle.locator('#offer')).toHaveValue(/.+/);
|
||||
const sdp = Buffer.from(await middle.inputValue('#offer'), 'base64').toString();
|
||||
const tampered = sdp.replace(/^a=fingerprint:[^\r\n]*/gm, (line) =>
|
||||
place(line, `a=fingerprint:${claimed.toUpperCase()}`),
|
||||
);
|
||||
expect(tampered).not.toBe(sdp);
|
||||
|
||||
await receiver.click('#receive-manual summary');
|
||||
await receiver.fill('#offer-input', Buffer.from(tampered).toString('base64'));
|
||||
await receiver.click('#create-answer');
|
||||
const remote = receiver.locator('#check-remote');
|
||||
const failed = (page: Page) => page.locator('#send-error, #receive-error').filter({ hasText: /.+/ });
|
||||
await expect(receiver.locator('#answer').or(failed(receiver))).toBeVisible({ timeout: 15_000 });
|
||||
if (!(await failed(receiver).count())) {
|
||||
await middle.fill('#answer-input', await receiver.inputValue('#answer'));
|
||||
await middle.click('#accept-answer');
|
||||
// The middle may take the answer or not, the receiver connects or not.
|
||||
const settled = async () =>
|
||||
(await remote.count()) + (await failed(receiver).count()) + (await failed(middle).count());
|
||||
await expect.poll(settled, { timeout: 15_000 }).toBeGreaterThan(0);
|
||||
}
|
||||
|
||||
if (connects) await expect(remote).toBeVisible();
|
||||
if (await remote.count()) await expect(remote).not.toHaveText(manualCode([claimed]));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
test(`protocol: ${name} manual exchange reports a broken offer and answer`, async () => {
|
||||
const [sender, receiver] = await Promise.all([open(name), open(name)]);
|
||||
await sender.setInputFiles('input[type=file]', await payload(randomBytes(1000)));
|
||||
|
||||
Reference in new issue
Block a user