diff --git a/CHANGELOG.md b/CHANGELOG.md index 072eaef..3610b5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,12 @@ longer read. - Upgrade connection/session framing to v3 with per-file identifiers. Both peers must update; v2 codes are rejected before connection setup. +- Connection codes are compressed to roughly half their length (`HC1.` plus + Base64url of deflated JSON). Each code states whether it is an offer or an + answer and carries a reference shared by both, so a pasted offer in the + answer field, or an answer to a different code, is rejected with a clear + message while the live offer stays valid. Codes may be pasted as part of a + link. Earlier 0.0.5 drafts' codes are rejected. - New device identity private keys are non-extractable. - Replace the receive-storage choice with a single **Accept file** button that treats every file size the same: stream to Downloads where supported, else diff --git a/README.md b/README.md index ca7ae17..f08eda3 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,9 @@ Keep both tabs open. Switching browser tabs or apps does not explicitly cancel the session, although browsers and mobile operating systems can suspend pages. Pending verification/acceptance expires after five minutes; stalled transfers expire after one minute. Idle verified sessions stay open. Lost connections need -fresh codes. File transfers use protocol **v3**; pre-v3 connection codes are -rejected before connecting. +fresh codes. File transfers use protocol **v3**; codes from older builds are +rejected before connecting. Pasting the wrong kind of code (an offer as answer, +or an answer for a different code) is reported without discarding a live offer. If an answer is rejected as invalid, correct the pasted answer and click Connect again; the sender keeps its existing offer while it is still awaiting an answer. @@ -160,9 +161,9 @@ avoids contacting a configured STUN provider; direct connectivity depends on addresses, routing, browser policy and firewalls, not simply whether peers share one network. A VPN is not automatically a guarantee against address disclosure. -Connection codes are **Base64-encoded, not encrypted**. They contain SDP, -including candidate addresses, temporary ICE credentials and certificate -fingerprints. Peers and anyone who sees these codes (including the messaging +Connection codes are **compressed and Base64url-encoded, not encrypted** +(`HC1.` followed by deflated JSON). They contain SDP, including candidate +addresses, temporary ICE credentials and certificate fingerprints. Peers and anyone who sees these codes (including the messaging service used to exchange them) may learn connection details. Local addresses may be obscured by the browser, but this app does not provide anonymity. Treat codes as private session information; do not publish them. diff --git a/docs/device-identities.md b/docs/device-identities.md index 17b0eb2..8725eda 100644 --- a/docs/device-identities.md +++ b/docs/device-identities.md @@ -7,9 +7,10 @@ independent cryptographic audit. ## Authentication transcript -A device has an ECDSA P-256 key pair. An identity-enabled connection code uses -signaling envelope version 4 with a public key (65-byte uncompressed point, -lowercase hex) and a fresh 32-byte cryptographically random nonce. Both local +A device has an ECDSA P-256 key pair. An identity-enabled connection code +(see `src/lib/codes.ts` for the `HC1.` encoding) uses signaling envelope +version 4 with a public key (65-byte uncompressed point, lowercase hex) and a +fresh 32-byte cryptographically random nonce. Both local and remote SDP fingerprints continue to be validated as full SHA-256 values. Temporary codes use version 3. Old builds reject version 4 before connecting. Current builds accept both; if either participant uses a temporary identity, diff --git a/scripts/browser-check.ts b/scripts/browser-check.ts index f7b83c5..56c70bd 100644 --- a/scripts/browser-check.ts +++ b/scripts/browser-check.ts @@ -1,6 +1,7 @@ // Dependency-free Chromium integration check. Run after `bun run build`. import { Readable, Writable } from 'node:stream'; import { installBrowserContext, forceRelay, relayCandidateTypes, simulateSlowDisk } from './browser-context.ts'; +import { CODE_PREFIX, decodeCode } from '../src/lib/codes.ts'; import assert from 'node:assert/strict'; import { spawn } from 'node:child_process'; import { createServer } from 'node:http'; @@ -144,6 +145,7 @@ async function connect(sender: string, receiver: string, size: number, changedId if (turn) { await enableTurn(sender); await enableTurn(receiver); } await click(sender, 'Create code'); await wait(sender, () => !!document.querySelector('#output-code')); const offer = await evaluate(sender, () => window.__hellcon.element('#output-code').value); + assert.ok(offer.startsWith(CODE_PREFIX)); await input(receiver, '#offer-input', 'invalid-code!'); await click(receiver, 'Accept & create answer'); await wait(receiver, () => !!document.querySelector('[role=alert]')); @@ -152,8 +154,8 @@ async function connect(sender: string, receiver: string, size: number, changedId await input(receiver, '#offer-input', offer); await click(receiver, 'Accept & create answer'); await wait(receiver, () => !!document.querySelector('#output-code')); const answer = await evaluate(receiver, () => window.__hellcon.element('#output-code').value); - await input(sender, '#answer-input', 'invalid-answer!'); await click(sender, 'Connect'); - await wait(sender, () => !!document.querySelector('[role=alert]')); + await input(sender, '#answer-input', offer); await click(sender, 'Connect'); + await wait(sender, () => document.querySelector('[role=alert]')?.textContent?.includes('not an answer')); assert.equal(await evaluate(sender, () => window.__hellcon.element('#output-code')?.value), offer); assert.equal(await evaluate(sender, () => window.__hellcon.element('#answer-input').disabled), false); await input(sender, '#answer-input', answer); await click(sender, 'Connect'); @@ -517,7 +519,7 @@ try { await evaluate(identitySender, () => window.__hellcon.chooseFile(4096, 'remembered.bin')); await click(identitySender, 'Create code'); await wait(identitySender, () => !!document.querySelector('#output-code')); const offer = await evaluate(identitySender, () => window.__hellcon.element('#output-code').value); - assert.equal(JSON.parse(atob(offer)).version, 4); + assert.ok((await decodeCode(offer)).identity); await input(identityReceiver, '#offer-input', offer); await click(identityReceiver, 'Accept & create answer'); await wait(identityReceiver, () => !!document.querySelector('#output-code')); const answer = await evaluate(identityReceiver, () => window.__hellcon.element('#output-code').value); @@ -621,7 +623,7 @@ try { await input(denied, '#stun-provider', 'none'); await click(denied, 'Create code'); await wait(denied, () => !!document.querySelector('#output-code')); const temporary = await evaluate(denied, () => window.__hellcon.element('#output-code').value); - assert.equal(JSON.parse(atob(temporary)).version, 3); + assert.equal((await decodeCode(temporary)).identity, undefined); await click(denied, 'Cancel connection'); console.log('PASS: denied identity storage still allows temporary v3 connection setup.'); diff --git a/scripts/compare-ice.mjs b/scripts/compare-ice.mjs index e394652..8738e57 100644 --- a/scripts/compare-ice.mjs +++ b/scripts/compare-ice.mjs @@ -40,8 +40,8 @@ async function run(mode) { dc.onopen = () => { log('sender channel open'); dc.send('exact-file-bytes'); }; b.ondatachannel = e => { e.channel.onmessage = e => { received = e.data === 'exact-file-bytes'; log('receiver bytes '+received); }; }; try { - const offer = await api.createOfferCode(a); - let sdp = api.decodeSignal(offer); + // The original helpers exchange encoded codes; current helpers exchange SDP. + let sdp = mode === 'original' ? api.decodeSignal(await api.createOfferCode(a)) : await api.createOffer(a); // Deliberately unusable advertised ports: only sender-initiated checks // after the answer can discover the real sender. No host firewall changes. if(rewritePorts) sdp = sdp.split('\r\n').filter(l=>!/^a=candidate:.* tcp /i.test(l)).map(l=>{ @@ -49,11 +49,11 @@ async function run(mode) { const fields=l.split(' '); fields[5]='9'; return fields.join(' '); }).join('\r\n'); log('offer ready; end-of-candidates='+sdp.includes('a=end-of-candidates')); - const answer = await api.createAnswerCode(b, api.encodeSignal(sdp)); + const answer = mode === 'original' ? await api.createAnswerCode(b, api.encodeSignal(sdp)) : await api.createAnswer(b, sdp); log('answer ready'); await new Promise(r=>setTimeout(r,20000)); log('apply answer'); - await api.acceptAnswerCode(a,answer); + await (mode === 'original' ? api.acceptAnswerCode(a,answer) : api.acceptAnswer(a,answer)); await new Promise(r=>setTimeout(r,12000)); return {mode,received,events}; } catch { return {mode,received,events,error:'Signaling failed; raw browser error omitted'}; } diff --git a/src/components/TransferPanel.vue b/src/components/TransferPanel.vue index c56933b..2d9db1c 100644 --- a/src/components/TransferPanel.vue +++ b/src/components/TransferPanel.vue @@ -6,7 +6,8 @@ import { computed, onBeforeUnmount, ref, watch } from 'vue'; import DeviceSettings from './DeviceSettings.vue'; import { hello, signIdentity, verifyIdentity, type IdentityState, type IdentityHello, type IdentityContext } from '../lib/identity.ts'; import NetworkSettings from './NetworkSettings.vue'; -import { acceptAnswerCode, createAnswerCode, createOfferCode, createPeerConnection, fetchTurnOptions, iceConfiguration, getFingerprints, decodeSignal, signalIdentity, MAX_SIGNAL_LENGTH, STUN_PROVIDERS } from '../lib/webrtc.ts'; +import { acceptAnswer, createAnswer, createOffer, createPeerConnection, fetchTurnOptions, iceConfiguration, getFingerprints, STUN_PROVIDERS } from '../lib/webrtc.ts'; +import { createRef, decodeCode, encodeCode, MAX_INPUT_LENGTH } from '../lib/codes.ts'; import { MEMORY_LIMIT, validateMetadata } from '../lib/transfer.ts'; import { FileSession, QUEUE_LIMIT, type QueueItem } from '../lib/session.ts'; import { ConnectionDiagnostics } from '../lib/connection-diagnostics.ts'; @@ -25,6 +26,8 @@ interface Session { identityContext?: IdentityContext; identity?: IdentityState['identity']; expected?: string; + // Shared by this session's offer and answer codes. + ref?: string; timer?: ReturnType; } @@ -289,10 +292,14 @@ async function createCode() { if (active !== session) return; session.pc.setConfiguration(iceConfiguration(configured)); managedCredentials.value = session.options.allowTurn && session.options.managedTurn ? configured : null; - if (!props.sending) { decodeSignal(pasted, session.options); session.remoteHello = signalIdentity(pasted); } - const options = { ...session.options, signal: session.controller.signal, identity: session.localHello }; + const offer = props.sending ? null : await decodeCode(pasted, { type: 'offer', allowTurn: session.options.allowTurn }); + if (active !== session) return; + session.ref = offer ? offer.ref : createRef(); session.remoteHello = offer?.identity; + const options = { ...session.options, signal: session.controller.signal }; if (props.sending) attach(session, session.pc.createDataChannel('hellcon-v3')); - const code = props.sending ? await createOfferCode(session.pc, options) : await createAnswerCode(session.pc, pasted, options); + const sdp = offer ? await createAnswer(session.pc, offer.sdp, options) : await createOffer(session.pc, options); + if (active !== session) return; + const code = await encodeCode({ type: props.sending ? 'offer' : 'answer', ref: session.ref, sdp, identity: session.localHello }); if (active !== session) return; outputCode.value = code; session.diagnostics.record(props.sending ? 'offer ready' : 'answer ready'); @@ -311,9 +318,10 @@ async function useAnswer() { error.value = ''; step.value = 'verification'; try { - decodeSignal(inputCode.value, session.options); - session.remoteHello = signalIdentity(inputCode.value); - await acceptAnswerCode(session.pc, inputCode.value, session.options); + const answer = await decodeCode(inputCode.value, { type: 'answer', ref: session.ref, allowTurn: session.options.allowTurn }); + if (active !== session) return; + session.remoteHello = answer.identity; + await acceptAnswer(session.pc, answer.sdp, session.options); if (active !== session) return; session.diagnostics.record('answer applied'); session.diagnostics.descriptions(); @@ -439,7 +447,7 @@ onBeforeUnmount(() => { dispose(); revokeDownload(); clearTimeout(copyTimer); })

Exchange codes privately. They contain your IP address and connection details.