Lengthen codes and keep going after a failed security check

The security check compares 8 instead of 5 fingerprint bytes, too many to
brute force matching certificates. The tracker code has 8 digits, making
collisions between concurrent senders 100x less likely.

A "Codes don't match" button, or a peer leaving before the transfer
starts, ends that connection without ending the share: the tracker sender
answers the next (or a queued) offer, the receiver replaces its used up
offers. Both codes are aligned below each other.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SchluffeandClaude Opus 5.5 committed 2026-10-23 01:01:45 +02:00
1 parent 9282865a8c
commit 08b9f659c2
4 files changed
+228 -54

No files matched your search

+57 -2
View File
@@ -46,7 +46,7 @@ const MODES: Record<string, (sender: Page, receiver: Page) => Promise<void>> = {
},
async tracker(sender, receiver) {
await sender.click('#share');
await expect(sender.locator('#send-code')).toHaveText(/^\d{6}$/);
await expect(sender.locator('#send-code')).toHaveText(/^\d{8}$/);
await expect(sender.locator('#log')).toContainText('waiting on');
await receiver.fill('#receive-code', (await sender.locator('#send-code').textContent())!);
await receiver.click('#receive');
@@ -190,7 +190,7 @@ async function connect(mode: string, sender: Page, receiver: Page, source: strin
await MODES[mode]!(sender, receiver);
const check = (page: Page, side: string) => page.locator(`#check-${side}`).textContent();
await expect(sender.locator('#check-local')).toHaveText(/^([0-9A-F]{2} ){4}[0-9A-F]{2}$/, {
await expect(sender.locator('#check-local')).toHaveText(/^([0-9A-F]{2} ){7}[0-9A-F]{2}$/, {
timeout: 45_000,
});
await expect(receiver.locator('#check-remote')).toHaveText((await check(sender, 'local'))!);
@@ -357,6 +357,61 @@ for (const name of Object.keys(BROWSERS)) {
});
});
// A peer that guessed the code, or got the same one by chance, takes the sender's turn first.
test(`check: ${name} sender shares on after a mismatch`, async () => {
const [sender, intruder, receiver] = await Promise.all([open(name, []), open(name, []), open(name, [])]);
const source = test.info().outputPath('payload.bin');
await writeFile(source, randomBytes(SIZE));
await withLogs(sender!, receiver!, async () => {
await connect('tracker', sender!, intruder!, source);
await receiver!.fill('#receive-code', (await sender!.locator('#send-code').textContent())!);
await receiver!.click('#receive');
await expect(receiver!.locator('#log')).toContainText('looking on');
await sender!.click('#reject');
await intruder!.context().close();
await expect(sender!.locator('#log')).toContainText('waiting for the next receiver');
await expect(receiver!.locator('#check-local')).toBeVisible({ timeout: 45_000 });
await expect(sender!.locator('#check-local')).toHaveText((await receiver!.locator('#check-remote').textContent())!);
await expect(sender!.locator('#check-remote')).toHaveText((await receiver!.locator('#check-local').textContent())!);
const started = downloadStarts(receiver!);
await sender!.click('#confirm');
await receiver!.click('#confirm');
const { download } = await started;
expect(await hash(await download.path())).toBe(await hash(source));
await expect(sender!.locator('#log')).toContainText('delivered');
});
});
test(`check: ${name} both sides go on after the receiver rejected`, async () => {
const [sender, receiver] = await Promise.all([open(name, []), open(name, [])]);
const source = test.info().outputPath('payload.bin');
await writeFile(source, randomBytes(SIZE));
await withLogs(sender!, receiver!, async () => {
await connect('tracker', sender!, receiver!, source);
const first = await receiver!.locator('#check-local').textContent();
// Retrying still has to work for a side that already confirmed.
await sender!.click('#confirm');
await receiver!.click('#reject');
await expect(receiver!.locator('#log')).toContainText('looking again');
// The sender notices the receiver left, Chromium only once the connection counts as failed.
await expect(sender!.locator('#log')).toContainText('waiting for the next receiver', { timeout: 30_000 });
await expect(receiver!.locator('#check-local')).toHaveText(new RegExp(`^(?!${first}$)([0-9A-F]{2} ){7}[0-9A-F]{2}$`), {
timeout: 45_000,
});
await expect(sender!.locator('#check-remote')).toHaveText((await receiver!.locator('#check-local').textContent())!);
const started = downloadStarts(receiver!);
await sender!.click('#confirm');
await receiver!.click('#confirm');
const { download } = await started;
expect(await hash(await download.path())).toBe(await hash(source));
await expect(sender!.locator('#log')).toContainText('delivered');
});
});
test(`disconnect: ${name} fails the download when the sender vanishes`, async () => {
const [sender, receiver] = await Promise.all([open(name, []), open(name, [])]);
const source = test.info().outputPath('payload.bin');