Use compressed connection codes in the transfer panel
Offers and answers now go through the HC1 codec: the sender creates a ref per session and the answer must echo it, so pasting an offer as the answer or an answer for another code is rejected with a specific message while the live offer stays usable. Pasted input may be a full link. webrtc.ts drops its Base64 JSON signaling and exchanges validated SDP only; identity hellos travel in the code envelope. Tests, the browser check, compare-ice and the docs follow the new format. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
da2999ed5d
commit
8bd37ac8b1
10 files changed
+68
-89
No files matched your search
+2
-2
@@ -1,7 +1,7 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { randomBytes } from 'node:crypto';
|
||||
import { CODE_PREFIX, MAX_CODE_LENGTH, codeFromText, codeLink, createRef, decodeCode, encodeCode, type Signal } from '../src/lib/codes.ts';
|
||||
import { CODE_PREFIX, MAX_CODE_LENGTH, MAX_INPUT_LENGTH, codeFromText, codeLink, createRef, decodeCode, encodeCode, type Signal } from '../src/lib/codes.ts';
|
||||
const fingerprint = Array.from({ length: 32 }, (_, i) => i.toString(16).padStart(2, '0')).join(':');
|
||||
const sdp = `v=0\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\na=fingerprint:sha-256 ${fingerprint}\r\n`;
|
||||
const identity = { key: '04' + 'ab'.repeat(64), nonce: 'cd'.repeat(32) };
|
||||
@@ -67,7 +67,7 @@ test('malformed, old and unexpected payloads are rejected', async () => {
|
||||
|
||||
test('oversized codes and decompression bombs are rejected', async () => {
|
||||
await assert.rejects(decodeCode(CODE_PREFIX + 'A'.repeat(MAX_CODE_LENGTH)), /too large/);
|
||||
await assert.rejects(decodeCode('x'.repeat(MAX_CODE_LENGTH * 2 + 1)), /too large/);
|
||||
await assert.rejects(decodeCode('x'.repeat(MAX_INPUT_LENGTH + 1)), /too large/);
|
||||
// 32 MiB of zeros deflate to about 32 KiB, which fits the code length limit.
|
||||
const bomb = CODE_PREFIX + base64url(await deflate(new Uint8Array(32 * 1024 * 1024)));
|
||||
assert.ok(bomb.length < MAX_CODE_LENGTH);
|
||||
|
||||
+7
-23
@@ -1,6 +1,6 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { iceConfiguration, validateDescription, getFingerprints, signalIdentity, encodeSignal, decodeSignal, waitForIceComplete, waitForBufferDrain, MAX_SIGNAL_LENGTH, MAX_BUFFERED } from '../src/lib/webrtc.ts';
|
||||
import { iceConfiguration, validateDescription, getFingerprints, waitForIceComplete, waitForBufferDrain, MAX_SIGNAL_LENGTH, MAX_BUFFERED } from '../src/lib/webrtc.ts';
|
||||
const fingerprint = Array.from({ length: 32 }, (_, i) => i.toString(16).padStart(2, '0')).join(':');
|
||||
const sdp = `v=0\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\na=fingerprint:sha-256 ${fingerprint}\r\n`;
|
||||
|
||||
@@ -15,8 +15,8 @@ test('TURN is absent by default and dormant credentials cannot enable it', () =>
|
||||
|
||||
test('remote relay candidates require local explicit opt-in', () => {
|
||||
const relayed = sdp + 'a=candidate:1 1 udp 10 192.0.2.1 5000 typ relay raddr 0.0.0.0 rport 0\r\n';
|
||||
assert.throws(() => decodeSignal(encodeSignal(relayed)), /explicitly enable TURN/);
|
||||
assert.equal(decodeSignal(encodeSignal(relayed), { allowTurn: true }), relayed);
|
||||
assert.throws(() => validateDescription(relayed), /explicitly enable TURN/);
|
||||
assert.equal(validateDescription(relayed, { allowTurn: true }), validateDescription(sdp));
|
||||
});
|
||||
|
||||
test('fingerprints show all 32 bytes and reject ambiguous descriptions', () => {
|
||||
@@ -28,12 +28,10 @@ test('fingerprints show all 32 bytes and reject ambiguous descriptions', () => {
|
||||
assert.throws(() => validateDescription(sdp + 'm=audio 9 UDP/TLS/RTP/SAVPF 111\r\n'));
|
||||
});
|
||||
|
||||
test('signals round-trip but reject legacy, malformed and oversized codes', () => {
|
||||
assert.equal(decodeSignal(encodeSignal(sdp)), sdp);
|
||||
assert.throws(() => decodeSignal(btoa(sdp)));
|
||||
assert.throws(() => decodeSignal('bad!'));
|
||||
assert.throws(() => decodeSignal('a'.repeat(MAX_SIGNAL_LENGTH + 1)));
|
||||
assert.throws(() => decodeSignal(btoa(JSON.stringify({ version: 2, sdp }))));
|
||||
test('descriptions are bounded and printable', () => {
|
||||
assert.throws(() => validateDescription(sdp + 'a'.repeat(MAX_SIGNAL_LENGTH)), /Invalid connection description/);
|
||||
assert.throws(() => validateDescription(sdp + 'a=x:\u00e9\r\n'), /Invalid connection description/);
|
||||
assert.throws(() => validateDescription(42), /Invalid connection description/);
|
||||
});
|
||||
|
||||
class Peer extends EventTarget { iceGatheringState: RTCIceGatheringState = 'gathering'; connectionState: RTCPeerConnectionState = 'new'; }
|
||||
@@ -62,17 +60,3 @@ test('buffer wait resolves when already drained and rejects close or cancellatio
|
||||
const cancelled = waitForBufferDrain(channel, { signal: controller.signal }); controller.abort();
|
||||
await assert.rejects(cancelled, /interrupted/);
|
||||
});
|
||||
|
||||
|
||||
test('identity signaling is versioned, bounded, and optional for temporary sessions', () => {
|
||||
const identity = { key: '04' + 'ab'.repeat(64), nonce: 'cd'.repeat(32) };
|
||||
const code = encodeSignal(sdp, identity);
|
||||
assert.equal(JSON.parse(atob(code)).version, 4);
|
||||
assert.equal(decodeSignal(code), sdp);
|
||||
assert.deepEqual(signalIdentity(code), identity);
|
||||
assert.equal(signalIdentity(encodeSignal(sdp)), undefined);
|
||||
assert.equal(JSON.parse(atob(encodeSignal(sdp))).version, 3);
|
||||
assert.throws(() => decodeSignal(btoa(JSON.stringify({ version: 4, sdp }))));
|
||||
assert.throws(() => decodeSignal(btoa(JSON.stringify({ version: 4, sdp, identity: { ...identity, nonce: 'bad' } }))));
|
||||
assert.throws(() => decodeSignal(btoa(JSON.stringify({ version: 5, sdp, identity }))));
|
||||
});
|
||||
Reference in new issue
Block a user