Confirm reconnect pairings and add connection discovery settings
Setup now waits for both IndexedDB writes: the acceptor acknowledges its write, a failure on either side is reported to both people, and the proposer removes its copy if the acceptor could not save. Every session that authenticates the paired device compares a check value derived from the stored pairing, so a one-sided pairing (interrupted setup, or Turn off reconnect on one device) is turned off on the other side too. The tracker is chosen under Network settings > Connection discovery (manual, default from VITE_TRACKER_URL, or custom), stored per browser and editable during a session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3659956967
commit
acba97a7e1
10 files changed
+309
-55
No files matched your search
+24
-1
@@ -3,6 +3,7 @@ import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import ConnectionWorkspace from './components/ConnectionWorkspace.vue';
|
||||
import AppDialog from './components/AppDialog.vue';
|
||||
import { addConnection, CONNECTION_LIMIT, emptyConnection, loadConnections, removeConnection, saveConnection, updateConnection, type ConnectionUpdate, type SavedConnection } from './lib/connections.ts';
|
||||
import type { ReconnectPairing } from './lib/reconnect.ts';
|
||||
import { asError } from './lib/validation.ts';
|
||||
|
||||
const logoUrl = `${import.meta.env.BASE_URL}HellNet_alt.png`;
|
||||
@@ -104,6 +105,28 @@ function update(id: string, change: ConnectionUpdate) {
|
||||
} finally { pending--; if (!pending && refreshRequested) void refresh(); }
|
||||
});
|
||||
}
|
||||
// Pairing setup needs the committed write, rather than the optimistic update
|
||||
// used by ordinary settings, before either browser reports success. null
|
||||
// removes a pairing the peer could not store or does not share.
|
||||
function saveReconnect(id: string, reconnect: ReconnectPairing | null): Promise<void> {
|
||||
if (!persistent) {
|
||||
if (reconnect) return Promise.reject(new Error('Reconnect needs saved connection storage in this browser.'));
|
||||
update(id, { reconnect }); return Promise.resolve();
|
||||
}
|
||||
pending++;
|
||||
const operation = writes.then(async () => {
|
||||
try {
|
||||
const records = await saveConnection(id, { reconnect });
|
||||
if (pending === 1) applyRecords(records);
|
||||
updates?.postMessage('changed');
|
||||
} catch (err) {
|
||||
refreshRequested = true;
|
||||
throw err;
|
||||
} finally { pending--; if (!pending && refreshRequested) void refresh(); }
|
||||
});
|
||||
writes = operation.catch(() => {});
|
||||
return operation;
|
||||
}
|
||||
// Connection setup re-reads the record so trust forgotten in another tab is
|
||||
// never reused from this tab's copy. A failed read stops setup.
|
||||
async function trust(id: string) {
|
||||
@@ -190,7 +213,7 @@ async function remove() {
|
||||
<p v-if="error" class="storage-error" role="alert">{{ error }}</p>
|
||||
<template v-for="item in connections" :key="item.id">
|
||||
<KeepAlive>
|
||||
<ConnectionWorkspace v-if="selected === item.id" :connection="item" :load-trust="trust"
|
||||
<ConnectionWorkspace v-if="selected === item.id" :connection="item" :load-trust="trust" :save-reconnect="saveReconnect"
|
||||
@status="setStatus" @update="update" />
|
||||
</KeepAlive>
|
||||
</template>
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
import { ref } from 'vue';
|
||||
import TransferPanel from './TransferPanel.vue';
|
||||
import type { SavedConnection, ConnectionUpdate } from '../lib/connections.ts';
|
||||
const props = defineProps<{ connection: SavedConnection; loadTrust: (id: string) => Promise<SavedConnection> }>();
|
||||
import type { ReconnectPairing } from '../lib/reconnect.ts';
|
||||
const props = defineProps<{ connection: SavedConnection; loadTrust: (id: string) => Promise<SavedConnection>; saveReconnect: (id: string, reconnect: ReconnectPairing | null) => Promise<void> }>();
|
||||
const emit = defineEmits<{
|
||||
status: [id: string, state: 'ready' | 'connecting' | 'connected'];
|
||||
update: [id: string, change: ConnectionUpdate];
|
||||
@@ -28,7 +29,7 @@ function navigate(next: 'send' | 'receive') {
|
||||
<button :disabled="sessionActive && !connected" :class="{ active: (connected ? direction : mode) === 'send' }" :aria-pressed="(connected ? direction : mode) === 'send'" @click="navigate('send')">Send</button>
|
||||
<button :disabled="sessionActive && !connected" :class="{ active: (connected ? direction : mode) === 'receive' }" :aria-pressed="(connected ? direction : mode) === 'receive'" @click="navigate('receive')">Receive</button>
|
||||
</div>
|
||||
<TransferPanel ref="panel" :key="mode" :sending="mode === 'send'" :connection="connection" :load-trust="() => loadTrust(connection.id)"
|
||||
<TransferPanel ref="panel" :key="mode" :sending="mode === 'send'" :connection="connection" :load-trust="() => loadTrust(connection.id)" :save-reconnect="reconnect => saveReconnect(connection.id, reconnect)"
|
||||
@session-change="sessionActive = $event; status()" @connected-change="connected = $event; direction = mode; status()"
|
||||
@update="emit('update', connection.id, $event)" />
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import type { IceOptions, NetworkSettings } from '../lib/webrtc.ts';
|
||||
import { STUN_PROVIDERS } from '../lib/webrtc.ts';
|
||||
import type { DiscoverySettings } from '../lib/reconnect.ts';
|
||||
const settings = defineModel<NetworkSettings>({ required: true });
|
||||
defineProps<{ disabled?: boolean; managedCredentials?: IceOptions | null }>();
|
||||
// Discovery stays editable while connected: reconnect is set up over a live session.
|
||||
const discovery = defineModel<DiscoverySettings>('discovery', { required: true });
|
||||
defineProps<{ disabled?: boolean; managedCredentials?: IceOptions | null; defaultTracker: string }>();
|
||||
const iceEndpoint = import.meta.env.VITE_ICE_ENDPOINT || '';
|
||||
const host = (url: string) => { try { return new URL(url).host; } catch { return url; } };
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -33,4 +37,15 @@ const iceEndpoint = import.meta.env.VITE_ICE_ENDPOINT || '';
|
||||
</template>
|
||||
</template>
|
||||
</fieldset>
|
||||
<fieldset class="network-settings">
|
||||
<legend>Connection discovery</legend>
|
||||
<label for="discovery">Find paired devices with</label>
|
||||
<select id="discovery" v-model="discovery.choice" class="stun-select">
|
||||
<option value="manual">Manual codes only</option>
|
||||
<option v-if="defaultTracker" value="default">Default tracker ({{ host(defaultTracker) }})</option>
|
||||
<option value="custom">Custom tracker…</option>
|
||||
</select>
|
||||
<input v-if="discovery.choice === 'custom'" id="tracker-url" v-model="discovery.custom" class="stun-input" aria-label="Custom tracker address" placeholder="wss://tracker.example" autocomplete="off" spellcheck="false" />
|
||||
<p class="status">A WebTorrent tracker lets paired devices find each other, so both people press Reconnect instead of exchanging codes. Its operator sees your IP addresses and when your devices meet, not your codes or files. This applies to new reconnect setups; existing ones keep their tracker.</p>
|
||||
</fieldset>
|
||||
</template>
|
||||
@@ -2,7 +2,7 @@
|
||||
import { asError } from '../lib/validation.ts';
|
||||
import type { Fingerprints, IceOptions, NetworkSettings as NetworkSettingsModel } from '../lib/webrtc.ts';
|
||||
import type { FileMetadata, TransferState, FileDestination } from '../lib/transfer.ts';
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { computed, onActivated, 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';
|
||||
@@ -13,7 +13,7 @@ import { FileSession, QUEUE_LIMIT, type QueueItem } from '../lib/session.ts';
|
||||
import { ConnectionDiagnostics } from '../lib/connection-diagnostics.ts';
|
||||
import { createDownloadDestination, supportsStreamingDownload } from '../lib/download.ts';
|
||||
import type { ConnectionUpdate, SavedConnection } from '../lib/connections.ts';
|
||||
import { derivePairing, discoveryId, pairingNonce, parseNonce, signalingKey, trackerUrl } from '../lib/reconnect.ts';
|
||||
import { derivePairing, discoveryId, discoveryTracker, loadDiscovery, pairingCheck, pairingNonce, parseCheck, parseNonce, saveDiscovery, signalingKey, trackerUrl, type ReconnectPairing } from '../lib/reconnect.ts';
|
||||
import { ReconnectAttempt } from '../lib/tracker.ts';
|
||||
import type { Identity } from '../lib/identity.ts';
|
||||
|
||||
@@ -37,7 +37,7 @@ interface Session {
|
||||
timer?: ReturnType<typeof setTimeout>;
|
||||
}
|
||||
|
||||
const props = defineProps<{ sending?: boolean; connection: SavedConnection; loadTrust: () => Promise<SavedConnection> }>();
|
||||
const props = defineProps<{ sending?: boolean; connection: SavedConnection; loadTrust: () => Promise<SavedConnection>; saveReconnect: (reconnect: ReconnectPairing | null) => Promise<void> }>();
|
||||
const devices = ref<InstanceType<typeof DeviceSettings> | null>(null);
|
||||
const identityStatus = ref('');
|
||||
// Offered on the verification step whenever the verified peer would change
|
||||
@@ -82,6 +82,12 @@ const iceEndpoint = import.meta.env.VITE_ICE_ENDPOINT || '';
|
||||
const defaultStun = import.meta.env.VITE_STUN_URL || '';
|
||||
const settings = ref<NetworkSettingsModel>({ stunChoice: defaultStun ? 'custom' : 'pagequit', customStun: defaultStun, allowTurn: false, managedTurn: !!iceEndpoint, turnUrl: '', username: '', credential: '' });
|
||||
const managedCredentials = ref<IceOptions | null>(null);
|
||||
// Shared by all connections in this browser; reloaded when a cached workspace
|
||||
// returns, since another connection may have changed it.
|
||||
const defaultTracker = import.meta.env.VITE_TRACKER_URL || '';
|
||||
const discovery = ref(loadDiscovery(defaultTracker));
|
||||
watch(discovery, saveDiscovery, { deep: true });
|
||||
onActivated(() => { discovery.value = loadDiscovery(defaultTracker); });
|
||||
// Every size is received the same way: streamed to Downloads where supported, otherwise
|
||||
// through the native save picker, otherwise buffered in memory (capped) and saved on completion.
|
||||
const receiveMethod = computed(() => {
|
||||
@@ -99,9 +105,16 @@ let reconnectRun = 0;
|
||||
const discoveryHost = ref(''), discoveryPeers = ref(0);
|
||||
// Reconnect setup over a session whose peer proved the paired device key.
|
||||
const authenticatedPeer = ref('');
|
||||
const pairingState = ref<'' | 'proposed' | 'incoming' | 'accepted' | 'done'>(''), pairingError = ref('');
|
||||
const proposedTracker = ref(import.meta.env.VITE_TRACKER_URL || ''), incomingTracker = ref('');
|
||||
let pairingSetup: { tracker: string; proposer: string; acceptor?: string; key?: CryptoKey } | null = null;
|
||||
const pairingState = ref<'' | 'proposed' | 'incoming' | 'accepted' | 'saving' | 'awaiting-stored' | 'done'>(''), pairingError = ref('');
|
||||
// Set when the peer's stored pairing matched this one during this session.
|
||||
const pairingConfirmed = ref(false);
|
||||
const incomingTracker = ref('');
|
||||
let pairingSetup: { tracker: string; proposer: string; acceptor?: string; key?: CryptoKey; stored?: boolean } | null = null;
|
||||
const pairingBusy = () => ['proposed', 'accepted', 'saving', 'awaiting-stored'].includes(pairingState.value);
|
||||
const selectedTracker = computed(() => {
|
||||
try { return { url: discoveryTracker(discovery.value, defaultTracker), error: '' }; }
|
||||
catch (err) { return { url: '', error: asError(err).message }; }
|
||||
});
|
||||
const canPair = computed(() => connected.value && !!authenticatedPeer.value && authenticatedPeer.value === props.connection.peerKey);
|
||||
const trackerHost = (url: string) => { try { return new URL(url).host; } catch { return url; } };
|
||||
let copyTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
@@ -140,7 +153,7 @@ function dispose() {
|
||||
if (incoming.value && receiveState.value && !['done', 'closed'].includes(receiveState.value)) receiveState.value = 'closed';
|
||||
}
|
||||
active = null; connected.value = false; queuedFiles.value = []; emit('sessionChange', false);
|
||||
authenticatedPeer.value = ''; pairingState.value = ''; pairingError.value = ''; pairingSetup = null;
|
||||
authenticatedPeer.value = ''; pairingState.value = ''; pairingError.value = ''; pairingSetup = null; pairingConfirmed.value = false;
|
||||
managedCredentials.value = null; settings.value.allowTurn = false;
|
||||
if (!old) return;
|
||||
clearTimeout(old.timer);
|
||||
@@ -222,6 +235,7 @@ function attach(session: Session, channel: RTCDataChannel) {
|
||||
if (session.expected === key) { identityStatus.value = 'Paired device authenticated for this connection.'; authenticatedPeer.value = key; }
|
||||
else if (rememberPeer.value) { emit('update', { peerKey: key }); identityStatus.value = `Device proof checked. Remembered for ${props.connection.name}.`; authenticatedPeer.value = key; }
|
||||
else identityStatus.value = 'Device proof checked. This device was not remembered.';
|
||||
if (authenticatedPeer.value) void sendPairingCheck(session);
|
||||
}
|
||||
// Files chosen before connecting join the queue once the session is ready,
|
||||
// so a replaced reconnect peer never takes them along.
|
||||
@@ -518,16 +532,38 @@ function derivePairingKey(session: Session, setup: { tracker: string; proposer:
|
||||
offerFingerprint: context.offerFingerprint, answerFingerprint: context.answerFingerprint, tracker: setup.tracker,
|
||||
});
|
||||
}
|
||||
function storePairing(session: Session, tracker: string, key: CryptoKey) {
|
||||
emit('update', { reconnect: { version: 1, trackers: [tracker], key, localKey: session.localHello!.key, peerKey: session.remoteHello!.key } });
|
||||
async function storePairing(session: Session, setup: NonNullable<typeof pairingSetup>, key: CryptoKey) {
|
||||
await props.saveReconnect({ version: 1, trackers: [setup.tracker], key, localKey: session.localHello!.key, peerKey: session.remoteHello!.key });
|
||||
setup.stored = true;
|
||||
}
|
||||
// Each authenticated session compares stored pairings, so an interrupted setup,
|
||||
// a failed write or Turn off reconnect on one side is noticed on the other.
|
||||
async function sendPairingCheck(session: Session) {
|
||||
const pairing = props.connection.reconnect;
|
||||
try {
|
||||
const value = pairing && pairing.peerKey === authenticatedPeer.value ? await pairingCheck(pairing.key) : '';
|
||||
if (active === session) session.transfer?.sendPairing({ step: 'check', value });
|
||||
} catch { /* the session ended */ }
|
||||
}
|
||||
async function receivePairingCheck(session: Session, value: string) {
|
||||
const pairing = props.connection.reconnect;
|
||||
if (!pairing || !authenticatedPeer.value || pairing.peerKey !== authenticatedPeer.value) return;
|
||||
const matches = value === await pairingCheck(pairing.key);
|
||||
if (active !== session || pairingBusy() || props.connection.reconnect !== pairing) return;
|
||||
if (matches) { pairingConfirmed.value = true; return; }
|
||||
await props.saveReconnect(null);
|
||||
if (active === session) pairingError.value = 'Your peer’s device has no matching reconnect settings, so reconnect was turned off here as well. Set it up again to use it.';
|
||||
}
|
||||
// The proposer suggests a tracker; the peer sees it and accepts before anything
|
||||
// is stored or contacted. Both contribute a nonce; the proposer stores first.
|
||||
// is stored or contacted. Both contribute a nonce; the proposer stores first,
|
||||
// and the acceptor's write is acknowledged before either reports success. If
|
||||
// the peer's write fails, the proposer removes its own copy again.
|
||||
function proposePairing() {
|
||||
const session = active;
|
||||
if (!session?.transfer || !canPair.value || pairingState.value === 'proposed' || pairingState.value === 'accepted') return;
|
||||
if (!session?.transfer || !canPair.value || pairingBusy()) return;
|
||||
try {
|
||||
pairingSetup = { tracker: trackerUrl(proposedTracker.value), proposer: pairingNonce() };
|
||||
if (!selectedTracker.value.url) throw new Error(selectedTracker.value.error || 'Choose a tracker under Network settings → Connection discovery.');
|
||||
pairingSetup = { tracker: selectedTracker.value.url, proposer: pairingNonce() };
|
||||
session.transfer.sendPairing({ step: 'propose', tracker: pairingSetup.tracker, nonce: pairingSetup.proposer });
|
||||
pairingState.value = 'proposed'; pairingError.value = '';
|
||||
} catch (err) { pairingError.value = asError(err).message; }
|
||||
@@ -551,7 +587,7 @@ async function receivePairing(session: Session, message: Record<string, unknown>
|
||||
if (active !== session) return;
|
||||
try {
|
||||
if (message.step === 'propose') {
|
||||
if (pairingState.value === 'proposed' || pairingState.value === 'accepted') throw new Error('You both proposed reconnect at once. Let one person set it up.');
|
||||
if (pairingBusy()) throw new Error('You both proposed reconnect at once. Let one person set it up.');
|
||||
if (!canPair.value) {
|
||||
session.transfer?.sendPairing({ step: 'decline' });
|
||||
throw new Error('Your peer proposed tracker reconnect, but this connection has not remembered their device.');
|
||||
@@ -563,17 +599,43 @@ async function receivePairing(session: Session, message: Record<string, unknown>
|
||||
setup.acceptor = parseNonce(message.nonce);
|
||||
const key = await derivePairingKey(session, setup, true);
|
||||
if (active !== session || pairingSetup !== setup) return;
|
||||
storePairing(session, setup.tracker, key);
|
||||
pairingState.value = 'saving';
|
||||
await storePairing(session, setup, key);
|
||||
if (active !== session || pairingSetup !== setup) return;
|
||||
session.transfer?.sendPairing({ step: 'done' });
|
||||
pairingState.value = 'done';
|
||||
pairingState.value = 'awaiting-stored';
|
||||
} else if (message.step === 'done' && pairingState.value === 'accepted' && pairingSetup?.key) {
|
||||
storePairing(session, pairingSetup.tracker, pairingSetup.key);
|
||||
pairingState.value = 'done';
|
||||
} else if (message.step === 'decline') {
|
||||
if (pairingState.value === 'proposed' || pairingState.value === 'accepted') pairingError.value = 'Your peer declined tracker reconnect.';
|
||||
const setup = pairingSetup;
|
||||
const key = setup.key!;
|
||||
pairingState.value = 'saving';
|
||||
await storePairing(session, setup, key);
|
||||
if (active !== session || pairingSetup !== setup) return;
|
||||
session.transfer?.sendPairing({ step: 'stored' });
|
||||
pairingState.value = 'done'; pairingConfirmed.value = true;
|
||||
} else if (message.step === 'stored' && pairingState.value === 'awaiting-stored' && pairingSetup) {
|
||||
pairingState.value = 'done'; pairingConfirmed.value = true;
|
||||
} else if (message.step === 'error') {
|
||||
// Without a setup in progress, this side already reported its own error.
|
||||
const setup = pairingSetup;
|
||||
if (!setup) return;
|
||||
pairingState.value = ''; pairingSetup = null;
|
||||
pairingError.value = 'Your peer could not finish reconnect setup. Check their browser storage and try again.';
|
||||
if (setup.stored) {
|
||||
try { await props.saveReconnect(null); }
|
||||
catch (err) { pairingError.value = `Your peer could not finish reconnect setup, and turning it off here failed too: ${asError(err).message}`; }
|
||||
}
|
||||
} else if (message.step === 'decline') {
|
||||
if (pairingBusy()) pairingError.value = 'Your peer declined tracker reconnect.';
|
||||
pairingState.value = ''; pairingSetup = null;
|
||||
} else if (message.step === 'check') {
|
||||
await receivePairingCheck(session, parseCheck(message.value));
|
||||
} else throw new Error('Unexpected reconnect setup message.');
|
||||
} catch (err) { if (active === session) { pairingState.value = ''; pairingSetup = null; pairingError.value = asError(err).message; } }
|
||||
} catch (err) { if (active === session) {
|
||||
if (pairingSetup && message.step !== 'error') {
|
||||
try { session.transfer?.sendPairing({ step: 'error' }); } catch { /* the session ended */ }
|
||||
}
|
||||
pairingState.value = ''; pairingSetup = null; pairingError.value = asError(err).message;
|
||||
} }
|
||||
}
|
||||
async function acceptFile() {
|
||||
const session = active, destination = receiveMethod.value;
|
||||
@@ -641,7 +703,7 @@ onBeforeUnmount(() => { stopAttempt(); dispose(); revokeDownload(); clearTimeout
|
||||
<DeviceSettings ref="devices" :paired="connection.peerKey" :remember="connection.rememberDevice" :reconnect="connection.reconnect ? trackerHost(connection.reconnect.trackers[0]!) : ''" :disabled="busy || connected" @update="emit('update', $event)" />
|
||||
<details class="config-details">
|
||||
<summary>Network settings</summary>
|
||||
<NetworkSettings v-model="settings" :disabled="busy || connected" :managed-credentials="managedCredentials" />
|
||||
<NetworkSettings v-model="settings" v-model:discovery="discovery" :disabled="busy || connected" :managed-credentials="managedCredentials" :default-tracker="defaultTracker" />
|
||||
</details>
|
||||
<template v-if="connection.reconnect && !connected">
|
||||
<button class="primary" :disabled="busy" @click="reconnect">Reconnect</button>
|
||||
@@ -707,13 +769,18 @@ onBeforeUnmount(() => { stopAttempt(); dispose(); revokeDownload(); clearTimeout
|
||||
<button @click="declinePairing">Decline</button>
|
||||
</div>
|
||||
</template>
|
||||
<p v-else-if="pairingState === 'saving'" class="status" role="status">Saving reconnect settings…</p>
|
||||
<p v-else-if="pairingState === 'awaiting-stored'" class="status" role="status">Waiting for your peer to save reconnect settings…</p>
|
||||
<p v-else-if="pairingState === 'proposed' || pairingState === 'accepted'" class="status" role="status">Waiting for your peer to confirm…</p>
|
||||
<p v-else-if="pairingState === 'done'" class="status" role="status">Reconnect is set up. Next time, both people open {{ connection.name }} and press Reconnect.</p>
|
||||
<p v-else-if="pairingState === 'done'" class="status" role="status">Reconnect is set up on both devices. Next time, both people open {{ connection.name }} and press Reconnect.</p>
|
||||
<template v-else>
|
||||
<p class="status">Next time, both people press Reconnect instead of exchanging codes. A WebTorrent tracker introduces your browsers: it sees IP addresses and timing, not files or codes. Your peer confirms the tracker first.</p>
|
||||
<label class="step" for="tracker-url">Tracker address</label>
|
||||
<input id="tracker-url" v-model="proposedTracker" class="stun-input" placeholder="wss://tracker.example" autocomplete="off" spellcheck="false" />
|
||||
<button :disabled="!proposedTracker.trim()" @click="proposePairing">{{ connection.reconnect ? 'Set up reconnect again' : 'Set up reconnect' }}</button>
|
||||
<p v-if="connection.reconnect" class="status">Reconnect through <strong>{{ trackerHost(connection.reconnect.trackers[0]!) }}</strong> is set up{{ pairingConfirmed ? ' on both devices' : '' }}.</p>
|
||||
<template v-if="selectedTracker.url">
|
||||
<p class="status">Next time, both people press Reconnect instead of exchanging codes. <strong>{{ trackerHost(selectedTracker.url) }}</strong> introduces your browsers: it sees IP addresses and timing, not files or codes. Your peer confirms the tracker first.</p>
|
||||
<button @click="proposePairing">{{ connection.reconnect ? 'Set up reconnect again' : 'Set up reconnect' }}</button>
|
||||
</template>
|
||||
<p v-else-if="selectedTracker.error" class="error">{{ selectedTracker.error }} Fix the tracker under Network settings → Connection discovery.</p>
|
||||
<p v-else-if="!connection.reconnect" class="status">To reconnect without exchanging codes next time, choose a tracker under Network settings → Connection discovery.</p>
|
||||
</template>
|
||||
<p v-if="pairingError" class="error" role="alert">{{ pairingError }}</p>
|
||||
</section>
|
||||
|
||||
@@ -111,6 +111,41 @@ export async function openSignal(key: CryptoKey, route: SignalRoute, text: unkno
|
||||
return data.code;
|
||||
}
|
||||
|
||||
// Compared over each authenticated session, so a pairing stored or turned off
|
||||
// on only one side is noticed. It travels only inside the encrypted session.
|
||||
export async function pairingCheck(key: CryptoKey) {
|
||||
return hex(new Uint8Array(await crypto.subtle.deriveBits({ name: 'HKDF', hash: 'SHA-256', salt: new Uint8Array(), info: label('check') }, key, 128)));
|
||||
}
|
||||
export function parseCheck(value: unknown) {
|
||||
if (value === '') return value;
|
||||
unhex(value, 16);
|
||||
return value as string;
|
||||
}
|
||||
|
||||
// Connection discovery: a per-browser preference for new reconnect setups.
|
||||
// Existing pairings keep the tracker they were set up with.
|
||||
export type DiscoveryChoice = 'manual' | 'default' | 'custom';
|
||||
export interface DiscoverySettings { choice: DiscoveryChoice; custom: string }
|
||||
const DISCOVERY_STORAGE = 'hellcon-discovery';
|
||||
export function loadDiscovery(defaultTracker: string): DiscoverySettings {
|
||||
const fallback: DiscoverySettings = { choice: defaultTracker ? 'default' : 'manual', custom: '' };
|
||||
try {
|
||||
const data: unknown = JSON.parse(localStorage.getItem(DISCOVERY_STORAGE) ?? 'null');
|
||||
if (!isRecord(data) || !['manual', 'default', 'custom'].includes(data.choice as string) || typeof data.custom !== 'string') return fallback;
|
||||
const choice = data.choice === 'default' && !defaultTracker ? 'manual' : data.choice as DiscoveryChoice;
|
||||
return { choice, custom: data.custom.slice(0, 1024) };
|
||||
} catch { return fallback; }
|
||||
}
|
||||
export function saveDiscovery(settings: DiscoverySettings) {
|
||||
try { localStorage.setItem(DISCOVERY_STORAGE, JSON.stringify({ choice: settings.choice, custom: settings.custom })); }
|
||||
catch { /* the preference lasts for this page */ }
|
||||
}
|
||||
// The concrete tracker a new pairing would use, or '' for manual codes.
|
||||
export function discoveryTracker(settings: DiscoverySettings, defaultTracker: string) {
|
||||
if (settings.choice === 'manual') return '';
|
||||
return trackerUrl(settings.choice === 'default' ? defaultTracker : settings.custom);
|
||||
}
|
||||
|
||||
// Storage validation: an unusable pairing is dropped rather than failing the record.
|
||||
export function parsePairing(value: unknown, peerKey: string): ReconnectPairing | null {
|
||||
if (!isRecord(value) || value.version !== RECONNECT_VERSION || !peerKey || value.peerKey !== peerKey) return null;
|
||||
|
||||
Reference in new issue
Block a user