Compare commits
2
Commits
58c3e2af86
...
a73b3075b6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a73b3075b6 | ||
|
|
5f8c6a1916 |
No files matched your search
+25
-4
@@ -1,12 +1,18 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## Unreleased
|
## [0.0.5] - Draft (unreleased)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Add a messenger-style workspace with a connections sidebar, editable slot
|
||||||
|
names, session status, and a persistent activity timeline per connection.
|
||||||
|
- Preserve live sessions and file selections while switching slots. Save names,
|
||||||
|
paired-device associations, and the last 50 transfer results locally; keep
|
||||||
|
manual reconnection with fresh codes. Add collapsible mobile navigation.
|
||||||
- Add opt-in hosted device identities and saved contacts, with fresh mutual
|
- Add opt-in hosted device identities and saved contacts, with fresh mutual
|
||||||
signatures bound to both connection fingerprints before remembered verification.
|
signatures bound to both connection fingerprints before remembered verification.
|
||||||
- Add contact removal, identity reset, and password-encrypted backup/restore.
|
- Add contact removal and identity reset.
|
||||||
Identity-enabled signaling uses v4; temporary v3 sessions remain available.
|
Identity-enabled signaling uses v4; temporary v3 sessions remain available.
|
||||||
|
|
||||||
- Keep verified sessions open for “Send another file”, with separate acceptance
|
- Keep verified sessions open for “Send another file”, with separate acceptance
|
||||||
and storage for each file.
|
and storage for each file.
|
||||||
- Preserve the previous memory download until the next file is accepted.
|
- Preserve the previous memory download until the next file is accepted.
|
||||||
@@ -15,9 +21,24 @@
|
|||||||
- Add explicit Disconnect and live Send/Receive navigation. The initial receiver
|
- Add explicit Disconnect and live Send/Receive navigation. The initial receiver
|
||||||
can use Send to add files without reconnecting. Disconnect
|
can use Send to add files without reconnecting. Disconnect
|
||||||
aborts unfinished writes while preserving the last completed memory download.
|
aborts unfinished writes while preserving the last completed memory download.
|
||||||
|
- Document the hosted-first, serverless UX roadmap.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Each connection now remembers its own device instead of picking from a global
|
||||||
|
contact list. Opt in per connection; after manual fingerprint comparison,
|
||||||
|
“Remember this device for …” (ticked by default) pairs the verified peer.
|
||||||
|
A changed key is only replaced on explicit choice. Saved contacts are no
|
||||||
|
longer read.
|
||||||
- Upgrade connection/session framing to v3 with per-file identifiers. Both peers
|
- Upgrade connection/session framing to v3 with per-file identifiers. Both peers
|
||||||
must update; v2 codes are rejected before connection setup.
|
must update; v2 codes are rejected before connection setup.
|
||||||
- Document the hosted-first, serverless UX roadmap.
|
- New device identity private keys are non-extractable.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- The downloadable single-file HTML app (`hellcon-local.html`), its
|
||||||
|
**Download app for local use** link, and `file://` support. Serve the `dist/`
|
||||||
|
build over HTTPS or open it on localhost instead.
|
||||||
|
|
||||||
## [0.0.4] - 2026-10-16
|
## [0.0.4] - 2026-10-16
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# HellCon
|
# HellCon
|
||||||
|
|
||||||
Current version: **0.0.4**. See the [changelog](CHANGELOG.md) for release notes
|
Current version: **0.0.5** (draft). See the [changelog](CHANGELOG.md) for release notes
|
||||||
and compatibility changes.
|
and compatibility changes.
|
||||||
|
|
||||||
Browser-to-browser file sharing with Vue 3 and WebRTC. No accounts, signaling
|
Browser-to-browser file sharing with Vue 3 and WebRTC. No accounts, signaling
|
||||||
@@ -8,6 +8,35 @@ backend, or server-side file storage. You exchange connection codes manually.
|
|||||||
Direct connections are the default. TURN relaying is optional and requires
|
Direct connections are the default. TURN relaying is optional and requires
|
||||||
explicit opt-in by both people; no relay is configured automatically.
|
explicit opt-in by both people; no relay is configured automatically.
|
||||||
|
|
||||||
|
## Connections workspace
|
||||||
|
|
||||||
|
The sidebar holds your connections, starting with **Con 1**. Use **Add connection**
|
||||||
|
for another empty slot. Edit the name directly in the header; it saves when you
|
||||||
|
leave the field or press Enter. Empty names revert to the previous name.
|
||||||
|
Use **Remove** beside the name to open a confirmation dialog. Confirming removal
|
||||||
|
ends that slot's sessions in open tabs and forgets its remembered device;
|
||||||
|
downloaded files and your device identity remain. Removing the last slot leaves a fresh **Con 1**.
|
||||||
|
Each slot has its own setup, live session, and activity timeline. Switching slots
|
||||||
|
keeps active transfers and selected files alive while this tab stays open.
|
||||||
|
On small screens, **Show connections** opens the sidebar.
|
||||||
|
|
||||||
|
Connection names, remembered devices, and the last 50 transfer results
|
||||||
|
per slot are saved in this browser. History includes filenames, sizes, directions,
|
||||||
|
times, and completion/decline/interruption results. It does not save file contents,
|
||||||
|
connection codes, or relay credentials. **Reset** clears the current session but
|
||||||
|
keeps the slot and history. Closing or reloading the page ends live sessions and
|
||||||
|
discards selected files; reconnect by exchanging fresh codes. The sidebar reports
|
||||||
|
this tab's session status, not remote device presence.
|
||||||
|
|
||||||
|
Each slot can remember one device. Under **Remembered device**, create the
|
||||||
|
browser's device identity once, then opt each slot in. After the first manual
|
||||||
|
fingerprint comparison, **Remember this device for …** (ticked by default) pairs
|
||||||
|
the verified peer with that slot; later sessions on it authenticate the peer
|
||||||
|
automatically. The slot name is the device's name. **Forget device** unpairs it.
|
||||||
|
The same device may be paired with several slots. Clearing site data removes saved
|
||||||
|
connections and trust. Storage failures are shown explicitly; temporary sessions
|
||||||
|
remain available. Up to 100 connection slots are supported.
|
||||||
|
|
||||||
## How it works
|
## How it works
|
||||||
|
|
||||||
1. The person starting the connection selects one or more files and configures STUN (PageQuit by default, Google,
|
1. The person starting the connection selects one or more files and configures STUN (PageQuit by default, Google,
|
||||||
@@ -63,7 +92,7 @@ the session, although browsers and mobile operating systems can suspend pages.
|
|||||||
Pending verification/acceptance expires after five minutes; stalled transfers
|
Pending verification/acceptance expires after five minutes; stalled transfers
|
||||||
expire after one minute. Idle verified sessions stay open. Lost connections need
|
expire after one minute. Idle verified sessions stay open. Lost connections need
|
||||||
fresh codes. File transfers use protocol **v3**; pre-v3 connection codes are
|
fresh codes. File transfers use protocol **v3**; pre-v3 connection codes are
|
||||||
rejected before connecting. The local HTML supports the same manual flow.
|
rejected before connecting.
|
||||||
|
|
||||||
If an answer is rejected as invalid, correct the pasted answer and click Connect
|
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.
|
again; the sender keeps its existing offer while it is still awaiting an answer.
|
||||||
@@ -97,30 +126,29 @@ TURN credentials or public STUN service are required.
|
|||||||
|
|
||||||
## Remembered devices
|
## Remembered devices
|
||||||
|
|
||||||
On the hosted app, expand **Remembered devices** and choose **Create device
|
On the hosted app, expand **Remembered device** and choose **Create device
|
||||||
identity** on both browsers. Enable **Use my device identity for this connection**,
|
identity** on both browsers; this also enables **Use my device identity on this
|
||||||
exchange codes, and compare both full fingerprints for the first pairing. Once
|
connection** for the current slot. Exchange codes and compare both full
|
||||||
connected, give the peer a local nickname and choose **Remember device**.
|
fingerprints for the first pairing. Leave **Remember this device for …** ticked
|
||||||
|
before confirming, and the verified peer is paired with this connection.
|
||||||
|
|
||||||
For later connections, enable your identity and select the **Expected device**
|
Later sessions on that connection need no extra steps: HellCon checks fresh
|
||||||
on each side before exchanging fresh codes. HellCon checks fresh signed proofs
|
signed proofs bound to both device keys and both connection fingerprints. A
|
||||||
bound to both device keys and both connection fingerprints. A matching saved key
|
matching paired key replaces manual fingerprint comparison; file acceptance is
|
||||||
can replace manual fingerprint comparison; file acceptance is still required.
|
still required. A changed or missing identity requires manual comparison and
|
||||||
A changed or missing identity requires manual comparison and never overwrites a
|
only replaces the paired device if you tick **Replace the paired device**.
|
||||||
saved contact. Nicknames stay local. Public identities in codes can link sessions.
|
Connection names stay local. Public identities in codes can link sessions.
|
||||||
|
|
||||||
Use **Forget** to remove a contact, or explicitly delete your identity and contacts.
|
Use **Forget device** to unpair a connection, or explicitly delete your identity.
|
||||||
Encrypted backup/restore includes both, protected by a password of at least 12
|
Clearing site data loses saved trust and requires pairing again. Browser-stored
|
||||||
characters. Keep that password separately. Clearing site data loses saved trust;
|
keys remain usable by trusted app code and are not protection against a malicious
|
||||||
restoring a backup on another browser gives it the same identity. Browser-stored
|
host. Each connection keeps its own opt-in; new connections start without it.
|
||||||
keys remain accessible to trusted app code and are not protection against a
|
Storage failure leaves temporary connections available.
|
||||||
malicious host. Identity use defaults off after reload. Storage failure leaves
|
|
||||||
temporary connections available; downloaded local HTML stays manual.
|
|
||||||
|
|
||||||
Identity-enabled codes use signaling version **4** and require the new build.
|
Identity-enabled codes use signaling version **4** and require the new build.
|
||||||
Temporary codes retain version **3**. If only one peer enables identity, the
|
Temporary codes retain version **3**. If only one peer enables identity, the
|
||||||
current build uses manual comparison without remembering that connection.
|
current build uses manual comparison without remembering that connection.
|
||||||
See [the identity protocol and backup format](docs/device-identities.md).
|
See [the identity protocol and storage](docs/device-identities.md).
|
||||||
|
|
||||||
## Network privacy and optional TURN
|
## Network privacy and optional TURN
|
||||||
|
|
||||||
@@ -207,28 +235,12 @@ policies must permit same-origin workers and frames. No third-party helper,
|
|||||||
download backend, or additional hosting service is required. Closing/resetting
|
download backend, or additional hosting service is required. Closing/resetting
|
||||||
an unfinished transfer aborts it; interrupted transfers must restart.
|
an unfinished transfer aborts it; interrupted transfers must restart.
|
||||||
|
|
||||||
## Download and run locally
|
## Build and self-host
|
||||||
|
|
||||||
Run `bun run build`, then open `dist/hellcon-local.html` directly in a browser.
|
From a clone of the repository, run `bun install --frozen-lockfile` and
|
||||||
This single HTML file includes the app code, styles, and icon. A hosted production
|
`bun run build`. Serve the whole `dist/` directory, including `assets/` and
|
||||||
build also offers **Download app for local use**. Download that file instead of
|
`download/`, using a static web server over HTTPS. For local build inspection,
|
||||||
using the browser's **Save Page As** command, which may save only the hosted page
|
run `bun run preview` and open the printed localhost URL.
|
||||||
without its required assets. You can share the downloaded HTML file with the
|
|
||||||
other participant; both can open it from disk. No web server is needed to load
|
|
||||||
the app itself.
|
|
||||||
|
|
||||||
The app still needs network access to connect peers on different machines, and
|
|
||||||
the selected STUN or TURN servers must be reachable. A `file://` copy cannot use
|
|
||||||
the host's managed TURN credential endpoint; enter your own relay details when
|
|
||||||
needed. Service-worker downloads are **disabled for `file://` copies**; there is
|
|
||||||
no hosted helper dependency in the local version. For large local transfers,
|
|
||||||
use desktop Chrome with its native save picker and select **Choose destination
|
|
||||||
& receive to disk**. Brave may disable that API even though it is Chromium-based.
|
|
||||||
Native disk access still depends on browser settings and platform support.
|
|
||||||
The 64 MiB in-memory receive option remains available.
|
|
||||||
|
|
||||||
To self-host the regular multi-file build, serve the whole `dist/` directory,
|
|
||||||
including `assets/`. Serve it over HTTPS for access from other machines.
|
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
@@ -325,6 +337,7 @@ bun run typecheck
|
|||||||
bun run test
|
bun run test
|
||||||
bun run build
|
bun run build
|
||||||
bun run test:browser # local Chromium integration checks against dist/
|
bun run test:browser # local Chromium integration checks against dist/
|
||||||
|
bun run test:browser --connections # sidebar, persistence, live switching, and mobile layout
|
||||||
bun run test:download # real hosted downloads, including 120 MiB, with native picker disabled
|
bun run test:download # real hosted downloads, including 120 MiB, with native picker disabled
|
||||||
bun run test:cross-browser # Brave sender → Firefox receiver
|
bun run test:cross-browser # Brave sender → Firefox receiver
|
||||||
bun run preview # local build inspection only
|
bun run preview # local build inspection only
|
||||||
|
|||||||
+35
-38
@@ -1,7 +1,7 @@
|
|||||||
# Remembered-device protocol and storage
|
# Remembered-device protocol and storage
|
||||||
|
|
||||||
Phase 3 adds optional hosted-browser identities. Temporary sessions still use
|
Phase 3 adds optional hosted-browser identities. Temporary sessions still use
|
||||||
manual fingerprint comparison. The local HTML never opens identity storage.
|
manual fingerprint comparison.
|
||||||
This is an application protocol design and implementation review, not an
|
This is an application protocol design and implementation review, not an
|
||||||
independent cryptographic audit.
|
independent cryptographic audit.
|
||||||
|
|
||||||
@@ -34,56 +34,53 @@ fresh contributions from both peers prevent replay into a new connection.
|
|||||||
The signed fingerprints bind the identity to the encrypted transport. A proof
|
The signed fingerprints bind the identity to the encrypted transport. A proof
|
||||||
from another connection cannot authenticate an attacker-controlled DTLS peer.
|
from another connection cannot authenticate an attacker-controlled DTLS peer.
|
||||||
|
|
||||||
A local user either compares both full fingerprints or explicitly selects an
|
Each connection opts in separately and trusts at most one public key, its paired
|
||||||
expected saved public key. A nickname alone has no protocol meaning. A matching
|
device. A local user either compares both full fingerprints or connects on a
|
||||||
expected key permits local verification to proceed automatically, but metadata
|
paired connection. A connection name has no protocol meaning. A matching paired
|
||||||
and file data stay gated until the peer's fresh signature verifies. Unknown,
|
key permits local verification to proceed automatically, but metadata and file
|
||||||
changed, missing, or downgraded identities require manual fingerprint comparison.
|
data stay gated until the peer's fresh signature verifies. Unknown, changed,
|
||||||
A changed key never replaces a saved contact automatically. An invalid or missing
|
missing, or downgraded identities require manual fingerprint comparison.
|
||||||
|
A changed key never replaces a paired device automatically: replacing it is an
|
||||||
|
explicit, unticked choice on the verification step. An invalid or missing
|
||||||
signature in a negotiated identity session closes the session. Each file still
|
signature in a negotiated identity session closes the session. Each file still
|
||||||
requires acceptance. The session receive queue is bounded to 2 MiB while signature
|
requires acceptance. The session receive queue is bounded to 2 MiB while signature
|
||||||
verification is pending and throughout transfers; the existing 1 MiB send windows
|
verification is pending and throughout transfers; the existing 1 MiB send windows
|
||||||
remain unchanged.
|
remain unchanged.
|
||||||
|
|
||||||
Contacts may only be saved after both peers' ready frames pass verification.
|
A peer key is only saved to a connection after both peers' ready frames pass
|
||||||
Manual first pairing therefore authenticates the keys through the compared
|
verification, and only if the user left **Remember this device** ticked on the
|
||||||
transport fingerprints and proofs. Public identities in codes are linkable;
|
verification step. Manual first pairing therefore authenticates the keys through
|
||||||
the UI makes this explicit before opt-in. No identities or nicknames are added
|
the compared transport fingerprints and proofs. Public identities in codes are
|
||||||
to diagnostic logs, and nicknames are not sent to peers.
|
linkable; the UI makes this explicit before opt-in. No identities or connection
|
||||||
|
names are added to diagnostic logs, and connection names are not sent to peers.
|
||||||
|
|
||||||
## Storage and recovery
|
## Storage and recovery
|
||||||
|
|
||||||
IndexedDB holds a CryptoKey private key, the public key, and at most 100 contacts.
|
The `hellcon-devices` IndexedDB store holds one CryptoKey private key and its
|
||||||
Keys are extractable to support user-requested backups. Browser storage does not
|
public key, shared by all connections. Each record in `hellcon-connections`
|
||||||
protect against compromised app code, a hostile host, or compromised browser.
|
holds its own opt-in flag and paired public key. New private keys are
|
||||||
The identity-use checkbox defaults off after page load. Clearing site data loses
|
non-extractable; existing stored keys remain usable.
|
||||||
identity and contacts; an empty store never creates trust automatically. Storage
|
Browser storage does not protect against compromised app code, a hostile host,
|
||||||
errors leave temporary sessions available. Unreadable storage can be explicitly
|
or compromised browser: app code can still use a stored key to sign.
|
||||||
cleared before restoring a backup. Atomic revision checks reject stale writes
|
New connections are not opted in. Creating an identity opts in the connection it
|
||||||
from other tabs instead of overwriting a newer identity or contact list. Controls for deletion/restoration
|
was created from. Clearing site data loses the identity and pairings; an empty
|
||||||
require explicit replacement consent and are disabled during a session.
|
store never creates trust automatically. Storage errors leave temporary sessions
|
||||||
Before each identity-enabled connection, settings are read again from storage.
|
available. Unreadable identity storage can be explicitly cleared before creating
|
||||||
A contact forgotten in another tab loses automatic verification on the next
|
a new identity and pairing again. Atomic revision checks reject stale identity
|
||||||
connection; a replaced or deleted local identity requires opting in again.
|
writes from other tabs; connection records are read and written in single
|
||||||
|
transactions. Identity deletion requires explicit consent, keeps paired devices,
|
||||||
|
and is disabled during a session. Removing a connection forgets its device.
|
||||||
|
Before each identity-enabled connection, the connection record and identity are
|
||||||
|
read again from storage. A device forgotten in another tab loses automatic
|
||||||
|
verification on the next connection, and a replaced local identity is picked up.
|
||||||
A failed refresh stops setup instead of using cached trust.
|
A failed refresh stops setup instead of using cached trust.
|
||||||
|
|
||||||
The v1 backup is JSON containing `format: "hellcon-identity"`, `version: 1`,
|
There is no central revocation service. Peers must forget a compromised key.
|
||||||
`iterations: 600000`, a 16-byte random salt, 12-byte random IV, and ciphertext.
|
|
||||||
Salt, IV, and ciphertext use lowercase hex. PBKDF2-HMAC-SHA-256 with 600,000
|
|
||||||
iterations derives an AES-256-GCM key from the password (12–1024 characters,
|
|
||||||
UTF-8 without normalization). AES-GCM uses the default 128-bit authentication
|
|
||||||
tag and additional authenticated data `HellCon backup v1`. The encrypted JSON
|
|
||||||
contains the private JWK, public key, and contacts. Passwords are cleared from
|
|
||||||
the UI after operations and are never stored. Backup input is capped at 100 KB;
|
|
||||||
unsupported versions/iteration counts, malformed fields, wrong passwords, failed
|
|
||||||
authentication tags, invalid contacts, and mismatched private/public keys are
|
|
||||||
rejected before replacing stored data. Restoring a backup clones that identity;
|
|
||||||
there is no central revocation service. Contacts must forget a compromised key.
|
|
||||||
|
|
||||||
Review checks: both role directions, substitution of either identity, alteration
|
Review checks: both role directions, substitution of either identity, alteration
|
||||||
of either nonce or fingerprint, forged signatures, replay into fresh contexts,
|
of either nonce or fingerprint, forged signatures, replay into fresh contexts,
|
||||||
metadata gating during asynchronous verification, backup tampering and incorrect
|
metadata gating during asynchronous verification, non-extractable private keys,
|
||||||
passwords, and persistence/reconnection with real browser CryptoKeys. These
|
and persistence/reconnection with real browser CryptoKeys. These
|
||||||
checks do not replace an independent protocol review.
|
checks do not replace an independent protocol review.
|
||||||
|
|
||||||
Web Crypto algorithm and key-storage reference:
|
Web Crypto algorithm and key-storage reference:
|
||||||
|
|||||||
+32
-16
@@ -1,9 +1,25 @@
|
|||||||
# Serverless UX roadmap
|
# Serverless UX roadmap
|
||||||
|
|
||||||
The hosted HTTPS app is the primary experience. The downloadable HTML must keep
|
The app runs over HTTPS or on localhost. No signaling backend, peer presence
|
||||||
working for basic manual connection and file transfer; it need not match hosted
|
service, automatic offline-peer reconnection, or silent TURN fallback is in scope.
|
||||||
conveniences. No signaling backend, peer presence service, automatic offline-peer
|
|
||||||
reconnection, or silent TURN fallback is in scope.
|
## Connection workspace — implemented
|
||||||
|
|
||||||
|
The app title and connection list live in a sidebar. The first slot is **Con 1**;
|
||||||
|
users add subsequent slots explicitly and can rename them. Selecting a slot opens
|
||||||
|
its setup, transfer controls, and persistent activity timeline. Cached workspaces
|
||||||
|
keep live sessions and file selections intact while navigating between slots.
|
||||||
|
The sidebar collapses on mobile; network configuration is expandable.
|
||||||
|
|
||||||
|
IndexedDB stores slot names, paired devices, and up to 50 transfer
|
||||||
|
results per slot. Each result includes its direction, filename, size, timestamp,
|
||||||
|
and completion/decline/interruption status. File contents and connection codes
|
||||||
|
are never stored. Slot mutations are transactional and other tabs refresh their
|
||||||
|
lists after changes. Storage failures show an explicit warning.
|
||||||
|
|
||||||
|
Disconnect and Reset retain history. Reloading ends live sessions and requires
|
||||||
|
fresh codes; a slot's paired device is authenticated by fresh signed proofs, and
|
||||||
|
setup re-reads it from storage so a device forgotten elsewhere is not trusted.
|
||||||
|
|
||||||
## 1. Send another file on a verified connection — implemented first
|
## 1. Send another file on a verified connection — implemented first
|
||||||
|
|
||||||
@@ -43,26 +59,26 @@ survive disconnect until Reset or the next acceptance.
|
|||||||
Protocol v3 rejects old connection codes before setup. Tests cover simultaneous
|
Protocol v3 rejects old connection codes before setup. Tests cover simultaneous
|
||||||
queues, empty files, separate acceptance, removal, decline, stale IDs/receipts,
|
queues, empty files, separate acceptance, removal, decline, stale IDs/receipts,
|
||||||
queue caps, storage cancellation, and verification gates. Browser checks exercise
|
queue caps, storage cancellation, and verification gates. Browser checks exercise
|
||||||
both directions, real bytes, accessibility, streaming downloads, and the local HTML.
|
both directions, real bytes, accessibility, and streaming downloads.
|
||||||
|
|
||||||
## 3. Remember trusted devices — implemented
|
## 3. Remember trusted devices — implemented
|
||||||
|
|
||||||
The hosted app offers opt-in device identities and up to 100 named contacts in
|
The hosted app offers an opt-in device identity, and each connection slot can
|
||||||
browser storage. First pairing requires manual fingerprint comparison; contacts
|
remember one paired device. First pairing requires manual fingerprint comparison;
|
||||||
can be saved only after successful mutual verification. Later connections can
|
a slot is paired only after successful mutual verification. Later sessions on a
|
||||||
select an expected saved public key and verify fresh signed proofs bound to both
|
paired slot verify fresh signed proofs bound to both keys, both nonces, both DTLS
|
||||||
keys, both nonces, both DTLS fingerprints, and participant roles. Nicknames and
|
fingerprints, and participant roles. Slot names and saved codes never
|
||||||
saved codes never authenticate a peer. Changed or missing identities require
|
authenticate a peer. Changed or missing identities require manual comparison and
|
||||||
manual comparison and never replace saved contacts automatically.
|
never replace a paired device automatically.
|
||||||
|
|
||||||
Temporary sessions remain the default, and every file still requires acceptance.
|
Temporary sessions remain the default, and every file still requires acceptance.
|
||||||
Contact removal, identity deletion, encrypted backup/restore, storage failure
|
Forgetting devices, identity deletion, storage failure
|
||||||
fallback, unreadable-storage recovery, and conflicting-tab write protection are
|
fallback, unreadable-storage recovery, and conflicting-tab write protection are
|
||||||
implemented. The local HTML remains manual. Identity-enabled signaling uses v4;
|
implemented. Identity-enabled signaling uses v4;
|
||||||
temporary connections retain v3. Browser keys remain accessible to app code.
|
temporary connections retain v3. Browser keys remain accessible to app code.
|
||||||
|
|
||||||
Tests cover proof forgery and replay, altered session bindings, metadata gating,
|
Tests cover proof forgery and replay, altered session bindings, metadata gating,
|
||||||
wrong backup passwords and tampering, persistence across reload, changed identities,
|
persistence across reload, changed identities,
|
||||||
storage denial/recovery, and protocol-version validation. Design and review notes
|
storage denial/recovery, and protocol-version validation. Design and review notes
|
||||||
are in [the device identity protocol](device-identities.md); this is not an
|
are in [the device identity protocol](device-identities.md); this is not an
|
||||||
independent cryptographic audit.
|
independent cryptographic audit.
|
||||||
@@ -79,7 +95,7 @@ exchange remains necessary. Keep pasteable codes as the universal fallback.
|
|||||||
Bound and validate payloads, handle stale/incompatible links, and test practical
|
Bound and validate payloads, handle stale/incompatible links, and test practical
|
||||||
URL limits across messengers and mobile browsers. Do not promise a short link
|
URL limits across messengers and mobile browsers. Do not promise a short link
|
||||||
without a storage service. Consider compressed payloads and QR only after checking
|
without a storage service. Consider compressed payloads and QR only after checking
|
||||||
real payload sizes and decoding limits. Local HTML only needs manual codes.
|
real payload sizes and decoding limits.
|
||||||
|
|
||||||
## 5. Guided connection flow
|
## 5. Guided connection flow
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "hellcon",
|
"name": "hellcon",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
"turn:up": "docker compose --env-file .env.development up -d",
|
"turn:up": "docker compose --env-file .env.development up -d",
|
||||||
"turn:down": "docker compose --env-file .env.development down",
|
"turn:down": "docker compose --env-file .env.development down",
|
||||||
"test:turn": "node scripts/browser-check.ts --turn",
|
"test:turn": "node scripts/browser-check.ts --turn",
|
||||||
"build": "vue-tsc --noEmit && vite build && node scripts/build-local.ts",
|
"build": "vue-tsc --noEmit && vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"test": "node --test tests/*.test.ts",
|
"test": "node --test tests/*.test.ts",
|
||||||
"test:browser": "node scripts/browser-check.ts",
|
"test:browser": "node scripts/browser-check.ts",
|
||||||
|
|||||||
+211
-63
@@ -4,17 +4,19 @@ import { installBrowserContext, forceRelay, relayCandidateTypes, simulateSlowDis
|
|||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { spawn } from 'node:child_process';
|
import { spawn } from 'node:child_process';
|
||||||
import { createServer } from 'node:http';
|
import { createServer } from 'node:http';
|
||||||
import { mkdtemp, mkdir, readFile, rm, stat } from 'node:fs/promises';
|
import { mkdtemp, mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
||||||
import { createReadStream } from 'node:fs';
|
import { createReadStream } from 'node:fs';
|
||||||
import { tmpdir } from 'node:os';
|
import { tmpdir } from 'node:os';
|
||||||
import { dirname, extname, join, resolve } from 'node:path';
|
import { dirname, extname, join, resolve } from 'node:path';
|
||||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||||
const axeSource = await readFile(join(root, 'node_modules/axe-core/axe.min.js'), 'utf8');
|
const axeSource = await readFile(join(root, 'node_modules/axe-core/axe.min.js'), 'utf8');
|
||||||
const provider = process.argv.includes('--default-network') ? 'pagequit' : 'none';
|
const provider = process.argv.includes('--default-network') ? 'pagequit' : 'none';
|
||||||
const turn = process.argv.includes('--turn');
|
const turn = process.argv.includes('--turn');
|
||||||
const transport = process.argv.includes('--tcp') ? 'tcp' : 'udp';
|
const transport = process.argv.includes('--tcp') ? 'tcp' : 'udp';
|
||||||
const streaming = process.argv.includes('--stream-download');
|
const streaming = process.argv.includes('--stream-download');
|
||||||
|
const connections = process.argv.includes('--connections');
|
||||||
|
const screenshotDirectory = process.env.BROWSER_SCREENSHOT_DIR || (process.argv.includes('--screenshots') ? join(tmpdir(), 'hellcon-layout') : '');
|
||||||
const vite = turn ? await (await import('vite')).createServer({ server: { middlewareMode: true }, appType: 'spa' }) : null;
|
const vite = turn ? await (await import('vite')).createServer({ server: { middlewareMode: true }, appType: 'spa' }) : null;
|
||||||
const profile = await mkdtemp(join(tmpdir(), 'hellcon-browser-'));
|
const profile = await mkdtemp(join(tmpdir(), 'hellcon-browser-'));
|
||||||
const server = createServer(async (req, res) => {
|
const server = createServer(async (req, res) => {
|
||||||
@@ -38,6 +40,11 @@ const browser = spawn(process.env.CHROMIUM_PATH || '/usr/bin/chromium', [
|
|||||||
'--no-first-run', '--no-default-browser-check', `--user-data-dir=${profile}`, '--remote-debugging-pipe', 'about:blank',
|
'--no-first-run', '--no-default-browser-check', `--user-data-dir=${profile}`, '--remote-debugging-pipe', 'about:blank',
|
||||||
], { stdio: ['ignore', 'ignore', 'pipe', 'pipe', 'pipe'] });
|
], { stdio: ['ignore', 'ignore', 'pipe', 'pipe', 'pipe'] });
|
||||||
interface ProtocolResults {
|
interface ProtocolResults {
|
||||||
|
'Emulation.setDeviceMetricsOverride': object;
|
||||||
|
'Emulation.setFocusEmulationEnabled': object;
|
||||||
|
'Page.captureScreenshot': { data: string };
|
||||||
|
'Page.bringToFront': object;
|
||||||
|
'Input.dispatchKeyEvent': object;
|
||||||
'Browser.setDownloadBehavior': object;
|
'Browser.setDownloadBehavior': object;
|
||||||
'Target.createTarget': { targetId: string };
|
'Target.createTarget': { targetId: string };
|
||||||
'Target.attachToTarget': { sessionId: string };
|
'Target.attachToTarget': { sessionId: string };
|
||||||
@@ -96,6 +103,8 @@ async function page(url = origin) {
|
|||||||
const { sessionId } = await call('Target.attachToTarget', { targetId, flatten: true });
|
const { sessionId } = await call('Target.attachToTarget', { targetId, flatten: true });
|
||||||
await call('Runtime.enable', {}, sessionId);
|
await call('Runtime.enable', {}, sessionId);
|
||||||
await call('Page.enable', {}, sessionId);
|
await call('Page.enable', {}, sessionId);
|
||||||
|
// Background tabs otherwise skip focus/blur events, which the name editor relies on.
|
||||||
|
await call('Emulation.setFocusEmulationEnabled', { enabled: true }, sessionId);
|
||||||
await call('Page.addScriptToEvaluateOnNewDocument', { source: `(${installBrowserContext.toString()})()` }, sessionId);
|
await call('Page.addScriptToEvaluateOnNewDocument', { source: `(${installBrowserContext.toString()})()` }, sessionId);
|
||||||
if (streaming) await call('Page.addScriptToEvaluateOnNewDocument', { source: 'window.showSaveFilePicker = undefined;' }, sessionId);
|
if (streaming) await call('Page.addScriptToEvaluateOnNewDocument', { source: 'window.showSaveFilePicker = undefined;' }, sessionId);
|
||||||
if (turn) await call('Page.addScriptToEvaluateOnNewDocument', { source: `(${forceRelay.toString()})(${JSON.stringify(transport)})` }, sessionId);
|
if (turn) await call('Page.addScriptToEvaluateOnNewDocument', { source: `(${forceRelay.toString()})(${JSON.stringify(transport)})` }, sessionId);
|
||||||
@@ -150,11 +159,19 @@ async function connect(sender: string, receiver: string, size: number, changedId
|
|||||||
const rf = await evaluate(receiver, () => [...document.querySelectorAll('.fp-row code')].map(e => e.textContent));
|
const rf = await evaluate(receiver, () => [...document.querySelectorAll('.fp-row code')].map(e => e.textContent));
|
||||||
assert.equal(sf[0], rf[1]); assert.equal(sf[1], rf[0]); assert.equal(sf[0]?.split(' ').length, 32);
|
assert.equal(sf[0], rf[1]); assert.equal(sf[1], rf[0]); assert.equal(sf[0]?.split(' ').length, 32);
|
||||||
assert.equal(await evaluate(receiver, () => !!document.querySelector('.incoming')), false);
|
assert.equal(await evaluate(receiver, () => !!document.querySelector('.incoming')), false);
|
||||||
if (changedIdentity) assert.ok(await evaluate(sender, () => document.body.textContent?.includes('Device identity differs from the expected contact')));
|
if (changedIdentity) {
|
||||||
|
// The receiver still trusts the unchanged sender and verifies automatically;
|
||||||
|
// the sender must compare manually and is not offered a silent replacement.
|
||||||
|
assert.ok(await evaluate(sender, () => document.body.textContent?.includes('Device identity differs from the paired device')));
|
||||||
|
assert.equal(await evaluate(sender, () => [...document.querySelectorAll('.fingerprint label')].find(el => el.textContent?.includes('Replace the paired device'))?.querySelector('input')?.checked), false);
|
||||||
|
await wait(receiver, () => document.body.textContent?.includes('Verification submitted'));
|
||||||
|
await click(sender, 'Both fingerprints match — confirm');
|
||||||
|
} else {
|
||||||
await click(sender, 'Both fingerprints match — confirm');
|
await click(sender, 'Both fingerprints match — confirm');
|
||||||
await new Promise(resolve => setTimeout(resolve, 100));
|
await new Promise(resolve => setTimeout(resolve, 100));
|
||||||
assert.equal(await evaluate(receiver, () => !!document.querySelector('.incoming')), false);
|
assert.equal(await evaluate(receiver, () => !!document.querySelector('.incoming')), false);
|
||||||
await click(receiver, 'Both fingerprints match — confirm');
|
await click(receiver, 'Both fingerprints match — confirm');
|
||||||
|
}
|
||||||
await wait(receiver, () => !!document.querySelector('.incoming'));
|
await wait(receiver, () => !!document.querySelector('.incoming'));
|
||||||
if (turn) {
|
if (turn) {
|
||||||
for (const session of [sender, receiver]) {
|
for (const session of [sender, receiver]) {
|
||||||
@@ -164,7 +181,147 @@ async function connect(sender: string, receiver: string, size: number, changedId
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (streaming) {
|
if (connections) {
|
||||||
|
const sender = await page(), receiver = await page(origin.replace('127.0.0.1', 'localhost'));
|
||||||
|
const selectConnection = (session: string, name: string) => evaluate(session, (name: string) => {
|
||||||
|
const button = [...document.querySelectorAll<HTMLButtonElement>('.connection-link')].find(item => item.querySelector('.connection-name')?.textContent === name);
|
||||||
|
if (!button) throw new Error('Missing connection: ' + name);
|
||||||
|
button.click();
|
||||||
|
}, name);
|
||||||
|
const screenshot = async (session: string, name: string) => {
|
||||||
|
if (!screenshotDirectory) return;
|
||||||
|
await mkdir(screenshotDirectory, { recursive: true });
|
||||||
|
await call('Page.bringToFront', {}, session);
|
||||||
|
const { data } = await call('Page.captureScreenshot', { format: 'png', captureBeyondViewport: false }, session);
|
||||||
|
await writeFile(join(screenshotDirectory, name + '.png'), Buffer.from(data, 'base64'));
|
||||||
|
};
|
||||||
|
await call('Emulation.setDeviceMetricsOverride', { width: 1440, height: 1000, deviceScaleFactor: 1, mobile: false }, sender);
|
||||||
|
assert.equal(await evaluate(sender, () => document.querySelector('.title-line h1')?.textContent), 'Con 1');
|
||||||
|
await checkAccessibility(sender, 'Connections desktop');
|
||||||
|
await screenshot(sender, 'connections-desktop');
|
||||||
|
await evaluate(sender, () => window.__hellcon.element<HTMLInputElement>('#connection-name').focus());
|
||||||
|
await input(sender, '#connection-name', 'Work laptop');
|
||||||
|
await evaluate(sender, () => window.__hellcon.element<HTMLInputElement>('#connection-name').blur());
|
||||||
|
await wait(sender, () => document.querySelector('.connection-name')?.textContent === 'Work laptop');
|
||||||
|
await evaluate(sender, () => window.__hellcon.element<HTMLInputElement>('#connection-name').focus());
|
||||||
|
await input(sender, '#connection-name', ' ');
|
||||||
|
await evaluate(sender, () => window.__hellcon.element<HTMLInputElement>('#connection-name').blur());
|
||||||
|
assert.equal(await evaluate(sender, () => window.__hellcon.element<HTMLInputElement>('#connection-name').value), 'Work laptop');
|
||||||
|
await evaluate(sender, () => window.__hellcon.element<HTMLInputElement>('#connection-name').focus());
|
||||||
|
await input(sender, '#connection-name', 'Work laptop ');
|
||||||
|
await call('Input.dispatchKeyEvent', { type: 'keyDown', key: 'Enter', code: 'Enter', windowsVirtualKeyCode: 13 }, sender);
|
||||||
|
await call('Input.dispatchKeyEvent', { type: 'keyUp', key: 'Enter', code: 'Enter', windowsVirtualKeyCode: 13 }, sender);
|
||||||
|
assert.equal(await evaluate(sender, () => window.__hellcon.element<HTMLInputElement>('#connection-name').value), 'Work laptop');
|
||||||
|
assert.equal(await evaluate(sender, () => document.activeElement?.id === 'connection-name'), false);
|
||||||
|
await click(receiver, 'Receive');
|
||||||
|
await connect(sender, receiver, 4097);
|
||||||
|
const fingerprints = await evaluate(sender, () => [...document.querySelectorAll('.fp-row code')].map(item => item.textContent));
|
||||||
|
await click(sender, 'Add connection');
|
||||||
|
await wait(sender, () => document.querySelector('.title-line h1')?.textContent === 'Con 2');
|
||||||
|
assert.equal(await evaluate(sender, () => !!document.querySelector('.fingerprint')), false);
|
||||||
|
await click(receiver, 'Receive in memory (up to 64 MiB)');
|
||||||
|
await wait(sender, () => document.querySelector('.connection-link .connection-preview')?.textContent === 'browser-test.bin');
|
||||||
|
assert.equal(await evaluate(sender, () => document.querySelectorAll('.activity-item').length), 0, 'Hidden session activity must stay in its own slot');
|
||||||
|
await selectConnection(sender, 'Work laptop');
|
||||||
|
await wait(sender, () => document.querySelector('.session-badge')?.textContent?.includes('Connected'));
|
||||||
|
assert.deepEqual(await evaluate(sender, () => [...document.querySelectorAll('.fp-row code')].map(item => item.textContent)), fingerprints);
|
||||||
|
await evaluate(sender, () => window.__hellcon.chooseFile(1234, 'after-switch.bin'));
|
||||||
|
await wait(receiver, () => document.querySelector('.incoming')?.textContent?.includes('after-switch.bin'));
|
||||||
|
await click(receiver, 'Receive in memory (up to 64 MiB)');
|
||||||
|
await wait(sender, () => document.querySelectorAll('.activity-item').length === 2);
|
||||||
|
const received = await evaluate(receiver, async () => {
|
||||||
|
const bytes = new Uint8Array(await (await fetch(window.__hellcon.element<HTMLAnchorElement>('a.download').href)).arrayBuffer());
|
||||||
|
return { size: bytes.length, valid: bytes.every(byte => byte === 123) };
|
||||||
|
});
|
||||||
|
assert.deepEqual(received, { size: 1234, valid: true });
|
||||||
|
await click(sender, 'Disconnect'); await click(sender, 'Reset');
|
||||||
|
assert.equal(await evaluate(sender, () => document.querySelectorAll('.activity-item').length), 2, 'Reset must preserve slot history');
|
||||||
|
await checkAccessibility(sender, 'Connections with history');
|
||||||
|
await screenshot(sender, 'connections-history');
|
||||||
|
await selectConnection(sender, 'Con 2');
|
||||||
|
await evaluate(sender, () => window.__hellcon.chooseFile(10, 'draft.bin'));
|
||||||
|
await selectConnection(sender, 'Work laptop'); await selectConnection(sender, 'Con 2');
|
||||||
|
assert.equal(await evaluate(sender, () => [...document.querySelectorAll('.panel li')].some(item => item.textContent?.includes('draft.bin'))), true, 'Selected file state survives slot switching');
|
||||||
|
await call('Page.navigate', { url: origin }, sender);
|
||||||
|
await wait(sender, () => document.querySelectorAll('.activity-item').length === 2);
|
||||||
|
assert.equal(await evaluate(sender, () => document.querySelector('.title-line h1')?.textContent), 'Work laptop');
|
||||||
|
assert.equal(await evaluate(sender, () => document.querySelector('.session-badge')?.textContent), 'Ready to connect');
|
||||||
|
await selectConnection(sender, 'Con 2');
|
||||||
|
assert.equal(await evaluate(sender, () => document.querySelectorAll('.activity-item').length), 0);
|
||||||
|
assert.equal(await evaluate(sender, () => document.querySelector<HTMLInputElement>('#file-input')?.files?.length), 0, 'File contents must not persist after reload');
|
||||||
|
console.log('PASS: connections retain names and separate histories across reload; switching preserves live transfers and drafts; Reset preserves history.');
|
||||||
|
|
||||||
|
const other = await page();
|
||||||
|
await Promise.all([click(sender, 'Add connection'), click(other, 'Add connection')]);
|
||||||
|
await wait(sender, () => document.querySelectorAll('.connection-link').length === 4);
|
||||||
|
await wait(other, () => document.querySelectorAll('.connection-link').length === 4);
|
||||||
|
assert.deepEqual(await evaluate(sender, () => [...document.querySelectorAll('.connection-name')].map(item => item.textContent)), ['Work laptop', 'Con 2', 'Con 3', 'Con 4']);
|
||||||
|
console.log('PASS: concurrent tabs add distinct connection slots and synchronize their sidebars.');
|
||||||
|
|
||||||
|
await call('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: false }, sender);
|
||||||
|
await selectConnection(sender, 'Work laptop');
|
||||||
|
await checkAccessibility(sender, 'Connections mobile');
|
||||||
|
assert.equal(await evaluate(sender, () => document.documentElement.scrollWidth <= innerWidth), true, 'Mobile workspace must not overflow horizontally');
|
||||||
|
await screenshot(sender, 'connections-mobile');
|
||||||
|
await click(sender, 'Remove');
|
||||||
|
await wait(sender, () => !!document.querySelector('dialog[open]'));
|
||||||
|
await checkAccessibility(sender, 'Removal dialog mobile');
|
||||||
|
await screenshot(sender, 'connections-mobile-dialog');
|
||||||
|
await click(sender, 'Close dialog');
|
||||||
|
await wait(sender, () => !document.querySelector('dialog[open]'));
|
||||||
|
await click(sender, 'Show connections');
|
||||||
|
await checkAccessibility(sender, 'Connections mobile sidebar');
|
||||||
|
assert.equal(await evaluate(sender, () => getComputedStyle(window.__hellcon.element('.sidebar')).display), 'flex');
|
||||||
|
await screenshot(sender, 'connections-mobile-sidebar');
|
||||||
|
await selectConnection(sender, 'Con 2');
|
||||||
|
assert.equal(await evaluate(sender, () => getComputedStyle(window.__hellcon.element('.sidebar')).display), 'none');
|
||||||
|
console.log('PASS: mobile navigation opens and closes, fits the viewport, and passes accessibility checks.');
|
||||||
|
await call('Emulation.setDeviceMetricsOverride', { width: 1440, height: 1000, deviceScaleFactor: 1, mobile: false }, sender);
|
||||||
|
await selectConnection(sender, 'Work laptop');
|
||||||
|
await click(receiver, 'Reset');
|
||||||
|
await connect(sender, receiver, 1024);
|
||||||
|
await selectConnection(sender, 'Con 2');
|
||||||
|
await selectConnection(other, 'Work laptop');
|
||||||
|
await evaluate(other, () => window.__hellcon.element<HTMLButtonElement>('.header-action').focus());
|
||||||
|
await click(other, 'Remove');
|
||||||
|
await wait(other, () => !!document.querySelector('dialog[open]'));
|
||||||
|
assert.equal(await evaluate(other, () => document.activeElement?.textContent?.trim()), 'Keep connection', 'Dialog starts on its non-destructive action');
|
||||||
|
await checkAccessibility(other, 'Remove connection confirmation');
|
||||||
|
await screenshot(other, 'connections-remove-dialog');
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
await call('Input.dispatchKeyEvent', { type: 'keyDown', key: 'Tab', code: 'Tab', windowsVirtualKeyCode: 9 }, other);
|
||||||
|
await call('Input.dispatchKeyEvent', { type: 'keyUp', key: 'Tab', code: 'Tab', windowsVirtualKeyCode: 9 }, other);
|
||||||
|
assert.equal(await evaluate(other, () => !!document.querySelector('dialog[open]')?.contains(document.activeElement)), true, 'Tab stays within the modal');
|
||||||
|
}
|
||||||
|
await call('Input.dispatchKeyEvent', { type: 'keyDown', key: 'Escape', code: 'Escape', windowsVirtualKeyCode: 27 }, other);
|
||||||
|
await call('Input.dispatchKeyEvent', { type: 'keyUp', key: 'Escape', code: 'Escape', windowsVirtualKeyCode: 27 }, other);
|
||||||
|
await wait(other, () => !document.querySelector('dialog[open]'));
|
||||||
|
assert.equal(await evaluate(other, () => document.activeElement?.classList.contains('header-action')), true, 'Dialog restores focus to the opener');
|
||||||
|
await click(other, 'Remove');
|
||||||
|
await click(other, 'Keep connection');
|
||||||
|
assert.equal(await evaluate(other, () => document.querySelectorAll('.connection-link').length), 4);
|
||||||
|
await click(other, 'Remove'); await click(other, 'Remove connection');
|
||||||
|
await wait(other, () => document.querySelectorAll('.connection-link').length === 3);
|
||||||
|
await wait(sender, () => document.querySelectorAll('.connection-link').length === 3);
|
||||||
|
await wait(receiver, () => !document.querySelector('.incoming'));
|
||||||
|
await call('Page.navigate', { url: origin }, sender);
|
||||||
|
await wait(sender, () => !!document.querySelector('#stun-provider'));
|
||||||
|
assert.equal(await evaluate(sender, () => [...document.querySelectorAll('.connection-name')].some(item => item.textContent === 'Work laptop')), false);
|
||||||
|
for (let count = 3; count > 0; count--) {
|
||||||
|
const oldName = await evaluate(sender, () => document.querySelector('.title-line h1')?.textContent);
|
||||||
|
await click(sender, 'Remove'); await click(sender, 'Remove connection');
|
||||||
|
await wait(sender, () => !document.querySelector('dialog[open]'));
|
||||||
|
assert.equal(await evaluate(sender, () => document.querySelectorAll('.connection-link').length), Math.max(1, count - 1));
|
||||||
|
assert.notEqual(await evaluate(sender, () => document.querySelector('.title-line h1')?.textContent), oldName);
|
||||||
|
}
|
||||||
|
assert.equal(await evaluate(sender, () => document.querySelector('.title-line h1')?.textContent), 'Con 1');
|
||||||
|
assert.equal(await evaluate(sender, () => document.querySelectorAll('.activity-item').length), 0);
|
||||||
|
await call('Page.navigate', { url: origin }, sender);
|
||||||
|
await wait(sender, () => !!document.querySelector('#stun-provider'));
|
||||||
|
assert.deepEqual(await evaluate(sender, () => [...document.querySelectorAll('.connection-name')].map(item => item.textContent)), ['Con 1']);
|
||||||
|
console.log('PASS: removal can be cancelled, persists across reload, closes cached sessions in other tabs, and replaces the last slot with a fresh Con 1.');
|
||||||
|
assert.deepEqual(browserErrors, []);
|
||||||
|
} else if (streaming) {
|
||||||
const downloads = join(profile, 'downloads');
|
const downloads = join(profile, 'downloads');
|
||||||
await mkdir(downloads);
|
await mkdir(downloads);
|
||||||
await call('Browser.setDownloadBehavior', { behavior: 'allow', downloadPath: downloads });
|
await call('Browser.setDownloadBehavior', { behavior: 'allow', downloadPath: downloads });
|
||||||
@@ -202,25 +359,6 @@ try {
|
|||||||
if (!turn) {
|
if (!turn) {
|
||||||
assert.equal(await evaluate(sender, () => document.querySelector<HTMLSelectElement>('#stun-provider')?.value), 'pagequit');
|
assert.equal(await evaluate(sender, () => document.querySelector<HTMLSelectElement>('#stun-provider')?.value), 'pagequit');
|
||||||
}
|
}
|
||||||
if (!turn) {
|
|
||||||
const localUrl = pathToFileURL(join(root, 'dist/hellcon-local.html')).href;
|
|
||||||
const localReceiver = await page(localUrl);
|
|
||||||
assert.equal(await evaluate(localReceiver, () => document.querySelector<HTMLSelectElement>('#stun-provider')?.value), 'pagequit');
|
|
||||||
assert.equal(await evaluate(localReceiver, () => document.querySelector('h1')?.textContent), 'HellCon');
|
|
||||||
await click(localReceiver, 'Receive');
|
|
||||||
assert.equal(await evaluate(localReceiver, () => !!document.querySelector('#offer-input')), true);
|
|
||||||
const localSender = await page(localUrl);
|
|
||||||
await connect(localSender, localReceiver, 1024);
|
|
||||||
assert.equal(await evaluate(localReceiver, () => [...document.querySelectorAll('button')].some(button => button.textContent?.includes('Receive as download'))), false, 'file:// must not offer service-worker downloads');
|
|
||||||
await click(localReceiver, 'Receive in memory (up to 64 MiB)');
|
|
||||||
await wait(localReceiver, () => !!document.querySelector('a.download'));
|
|
||||||
const data = await evaluate(localReceiver, async () => {
|
|
||||||
const bytes = new Uint8Array(await (await fetch(document.querySelector<HTMLAnchorElement>('a.download')!.href)).arrayBuffer());
|
|
||||||
return { length: bytes.length, valid: bytes.every(byte => byte === 123) };
|
|
||||||
});
|
|
||||||
assert.deepEqual(data, { length: 1024, valid: true });
|
|
||||||
console.log('PASS: standalone HTML opens from file:// and transfers a file between two local copies.');
|
|
||||||
}
|
|
||||||
await click(receiver, 'Receive');
|
await click(receiver, 'Receive');
|
||||||
await checkAccessibility(sender, 'Send');
|
await checkAccessibility(sender, 'Send');
|
||||||
await checkAccessibility(receiver, 'Receive');
|
await checkAccessibility(receiver, 'Receive');
|
||||||
@@ -327,38 +465,44 @@ try {
|
|||||||
console.log('PASS: fresh code exchange after a failed transfer succeeds without reloading either page.');
|
console.log('PASS: fresh code exchange after a failed transfer succeeds without reloading either page.');
|
||||||
if (!turn) {
|
if (!turn) {
|
||||||
const identitySender = await page();
|
const identitySender = await page();
|
||||||
const identityReceiver = await page(origin.replace('127.0.0.1', 'localhost'));
|
const receiverOrigin = origin.replace('127.0.0.1', 'localhost');
|
||||||
|
const identityReceiver = await page(receiverOrigin);
|
||||||
await click(identityReceiver, 'Receive');
|
await click(identityReceiver, 'Receive');
|
||||||
|
const pairedKey = (session: string) => evaluate(session, () => document.querySelector('.device-settings code')?.textContent || '');
|
||||||
|
// Clears the paired device directly in storage, so this tab is not notified.
|
||||||
|
const forgetQuietly = (session: string) => evaluate(session, async () => {
|
||||||
|
const db = await new Promise<IDBDatabase>((resolve, reject) => { const request = indexedDB.open('hellcon-connections', 1); request.onsuccess = () => resolve(request.result); request.onerror = () => reject(request.error); });
|
||||||
|
await new Promise<void>((resolve, reject) => {
|
||||||
|
const tx = db.transaction('connections', 'readwrite'), store = tx.objectStore('connections'), request = store.getAll();
|
||||||
|
request.onsuccess = () => { for (const record of request.result) store.put({ ...record, peerKey: '' }); };
|
||||||
|
tx.oncomplete = () => resolve(); tx.onabort = () => reject(tx.error);
|
||||||
|
}); db.close();
|
||||||
|
});
|
||||||
for (const session of [identitySender, identityReceiver]) {
|
for (const session of [identitySender, identityReceiver]) {
|
||||||
await evaluate(session, () => { const details = [...document.querySelectorAll('details')].find(el => el.querySelector('summary')?.textContent === 'Remembered devices'); if (details) details.open = true; });
|
await evaluate(session, () => { const details = [...document.querySelectorAll('details')].find(el => el.querySelector('summary')?.textContent === 'Remembered device'); if (details) details.open = true; });
|
||||||
await wait(session, () => [...document.querySelectorAll('button')].some(button => button.textContent === 'Create device identity' && !button.disabled));
|
await wait(session, () => [...document.querySelectorAll('button')].some(button => button.textContent === 'Create device identity' && !button.disabled));
|
||||||
await click(session, 'Create device identity');
|
await click(session, 'Create device identity');
|
||||||
await wait(session, () => document.querySelector<HTMLInputElement>('#use-device-identity')?.checked);
|
await wait(session, () => document.querySelector<HTMLInputElement>('#remember-device')?.checked);
|
||||||
}
|
}
|
||||||
await connect(identitySender, identityReceiver, 2048);
|
await connect(identitySender, identityReceiver, 2048);
|
||||||
for (const session of [identitySender, identityReceiver]) {
|
for (const session of [identitySender, identityReceiver]) {
|
||||||
await wait(session, () => !!document.querySelector('#contact-name'));
|
await wait(session, () => document.body.textContent?.includes('Remembered for Con 1'));
|
||||||
await input(session, '#contact-name', 'Paired device');
|
await wait(session, () => !!document.querySelector('.device-settings code'));
|
||||||
await click(session, 'Remember device');
|
|
||||||
await wait(session, () => !document.querySelector('#contact-name'));
|
|
||||||
}
|
}
|
||||||
await checkAccessibility(identitySender, 'remembered identity');
|
await checkAccessibility(identitySender, 'remembered identity');
|
||||||
await click(identityReceiver, 'Receive in memory (up to 64 MiB)');
|
await click(identityReceiver, 'Receive in memory (up to 64 MiB)');
|
||||||
await wait(identitySender, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
|
await wait(identitySender, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
|
||||||
await click(identitySender, 'Disconnect');
|
await click(identitySender, 'Disconnect');
|
||||||
await wait(identityReceiver, () => [...document.querySelectorAll('button')].some(button => button.textContent === 'Reset'));
|
await wait(identityReceiver, () => [...document.querySelectorAll('button')].some(button => button.textContent === 'Reset'));
|
||||||
// Reload both pages to exercise persisted CryptoKeys and contacts.
|
// Reload both pages to exercise persisted CryptoKeys and paired connections.
|
||||||
for (const [session, url] of [[identitySender, origin], [identityReceiver, origin.replace('127.0.0.1', 'localhost')]]) {
|
for (const [session, url] of [[identitySender, origin], [identityReceiver, receiverOrigin]]) {
|
||||||
await call('Page.navigate', { url }, session);
|
await call('Page.navigate', { url }, session);
|
||||||
await wait(session, () => !!document.querySelector('#stun-provider'));
|
await wait(session, () => !!document.querySelector('#stun-provider'));
|
||||||
}
|
}
|
||||||
await click(identityReceiver, 'Receive');
|
await click(identityReceiver, 'Receive');
|
||||||
for (const session of [identitySender, identityReceiver]) {
|
for (const session of [identitySender, identityReceiver]) {
|
||||||
await wait(session, () => !!document.querySelector('#use-device-identity'));
|
await wait(session, () => !!document.querySelector('.device-settings code'));
|
||||||
assert.equal(await evaluate(session, () => document.querySelector<HTMLInputElement>('#use-device-identity')!.checked), false, 'Reload defaults to a temporary connection');
|
assert.equal(await evaluate(session, () => !!document.querySelector('#remember-device')), false, 'A paired connection shows its device instead of the opt-in');
|
||||||
await evaluate(session, () => document.querySelector<HTMLInputElement>('#use-device-identity')!.click());
|
|
||||||
const key = await evaluate(session, () => document.querySelector<HTMLSelectElement>('#expected-device')!.options[1]!.value);
|
|
||||||
await input(session, '#expected-device', key);
|
|
||||||
await input(session, '#stun-provider', 'none');
|
await input(session, '#stun-provider', 'none');
|
||||||
}
|
}
|
||||||
await evaluate(identitySender, () => window.__hellcon.chooseFile(4096, 'remembered.bin'));
|
await evaluate(identitySender, () => window.__hellcon.chooseFile(4096, 'remembered.bin'));
|
||||||
@@ -370,24 +514,21 @@ try {
|
|||||||
const answer = await evaluate(identityReceiver, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
|
const answer = await evaluate(identityReceiver, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
|
||||||
await input(identitySender, '#answer-input', answer); await click(identitySender, 'Connect');
|
await input(identitySender, '#answer-input', answer); await click(identitySender, 'Connect');
|
||||||
await wait(identityReceiver, () => !!document.querySelector('.incoming'));
|
await wait(identityReceiver, () => !!document.querySelector('.incoming'));
|
||||||
for (const session of [identitySender, identityReceiver]) assert.ok(await evaluate(session, () => document.body.textContent?.includes('Remembered device authenticated')));
|
for (const session of [identitySender, identityReceiver]) assert.ok(await evaluate(session, () => document.body.textContent?.includes('Paired device authenticated')));
|
||||||
await click(identityReceiver, 'Receive in memory (up to 64 MiB)');
|
await click(identityReceiver, 'Receive in memory (up to 64 MiB)');
|
||||||
await wait(identitySender, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
|
await wait(identitySender, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
|
||||||
const rememberedBytes = await evaluate(identityReceiver, async () => { const bytes = new Uint8Array(await (await fetch(window.__hellcon.element<HTMLAnchorElement>('a.download').href)).arrayBuffer()); return { length: bytes.length, valid: bytes.every(byte => byte === 123) }; });
|
const rememberedBytes = await evaluate(identityReceiver, async () => { const bytes = new Uint8Array(await (await fetch(window.__hellcon.element<HTMLAnchorElement>('a.download').href)).arrayBuffer()); return { length: bytes.length, valid: bytes.every(byte => byte === 123) }; });
|
||||||
assert.deepEqual(rememberedBytes, { length: 4096, valid: true });
|
assert.deepEqual(rememberedBytes, { length: 4096, valid: true });
|
||||||
console.log('PASS: identities and contacts persist across reload; fresh mutual proofs authenticate remembered devices and transfer exact bytes without manual reconfirmation.');
|
console.log('PASS: identities and paired connections persist across reload; fresh mutual proofs authenticate the paired device and transfer exact bytes without manual reconfirmation.');
|
||||||
|
|
||||||
await click(identitySender, 'Disconnect');
|
await click(identitySender, 'Disconnect');
|
||||||
await wait(identityReceiver, () => !document.querySelector('.incoming'));
|
await wait(identityReceiver, () => !document.querySelector('.incoming'));
|
||||||
await click(identitySender, 'Reset'); await click(identityReceiver, 'Reset');
|
await click(identitySender, 'Reset'); await click(identityReceiver, 'Reset');
|
||||||
for (const forgottenSide of [identitySender, identityReceiver]) {
|
for (const forgottenSide of [identitySender, identityReceiver]) {
|
||||||
const editor = await page(forgottenSide === identitySender ? origin : origin.replace('127.0.0.1', 'localhost'));
|
await forgetQuietly(forgottenSide);
|
||||||
await wait(editor, () => !!document.querySelector('#expected-device'));
|
assert.ok(await pairedKey(forgottenSide), 'Original tab still shows the stale paired device before connection setup');
|
||||||
await click(editor, 'Forget');
|
|
||||||
await wait(editor, () => document.querySelector<HTMLSelectElement>('#expected-device')?.options.length === 1);
|
|
||||||
assert.ok(await evaluate(forgottenSide, () => document.querySelector<HTMLSelectElement>('#expected-device')!.value), 'Original tab still has the stale expected contact before connection setup');
|
|
||||||
|
|
||||||
await evaluate(identitySender, () => window.__hellcon.chooseFile(128, 'forgotten-contact.bin'));
|
await evaluate(identitySender, () => window.__hellcon.chooseFile(128, 'forgotten-device.bin'));
|
||||||
await click(identitySender, 'Create code'); await wait(identitySender, () => !!document.querySelector('#output-code'));
|
await click(identitySender, 'Create code'); await wait(identitySender, () => !!document.querySelector('#output-code'));
|
||||||
const freshOffer = await evaluate(identitySender, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
|
const freshOffer = await evaluate(identitySender, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
|
||||||
await input(identityReceiver, '#offer-input', freshOffer); await click(identityReceiver, 'Accept & create answer');
|
await input(identityReceiver, '#offer-input', freshOffer); await click(identityReceiver, 'Accept & create answer');
|
||||||
@@ -395,22 +536,19 @@ try {
|
|||||||
const freshAnswer = await evaluate(identityReceiver, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
|
const freshAnswer = await evaluate(identityReceiver, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
|
||||||
await input(identitySender, '#answer-input', freshAnswer); await click(identitySender, 'Connect');
|
await input(identitySender, '#answer-input', freshAnswer); await click(identitySender, 'Connect');
|
||||||
await wait(forgottenSide, () => document.body.textContent?.includes('New device. Compare both fingerprints manually'));
|
await wait(forgottenSide, () => document.body.textContent?.includes('New device. Compare both fingerprints manually'));
|
||||||
assert.equal(await evaluate(forgottenSide, () => document.querySelector<HTMLSelectElement>('#expected-device')!.value), '');
|
assert.equal(await pairedKey(forgottenSide), '', 'Connection setup re-reads the forgotten pairing');
|
||||||
assert.equal(await evaluate(forgottenSide, () => document.querySelector<HTMLSelectElement>('#expected-device')!.options.length), 1);
|
assert.equal(await evaluate(forgottenSide, () => [...document.querySelectorAll('.fingerprint label')].find(el => el.textContent?.includes('Remember this device for Con 1'))?.querySelector('input')?.checked), true);
|
||||||
assert.equal(await evaluate(identityReceiver, () => !!document.querySelector('.incoming')), false, 'Forgotten trust must not release file metadata');
|
assert.equal(await evaluate(identityReceiver, () => !!document.querySelector('.incoming')), false, 'Forgotten trust must not release file metadata');
|
||||||
await click(forgottenSide, 'Both fingerprints match — confirm');
|
await click(forgottenSide, 'Both fingerprints match — confirm');
|
||||||
await wait(identityReceiver, () => !!document.querySelector('.incoming'));
|
await wait(identityReceiver, () => !!document.querySelector('.incoming'));
|
||||||
|
await wait(forgottenSide, () => !!document.querySelector('.device-settings code'));
|
||||||
await click(identityReceiver, 'Receive in memory (up to 64 MiB)');
|
await click(identityReceiver, 'Receive in memory (up to 64 MiB)');
|
||||||
await wait(identitySender, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
|
await wait(identitySender, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
|
||||||
await input(forgottenSide, '#contact-name', 'Paired device'); await click(forgottenSide, 'Remember device');
|
|
||||||
await wait(forgottenSide, () => !document.querySelector('#contact-name'));
|
|
||||||
await click(identitySender, 'Disconnect');
|
await click(identitySender, 'Disconnect');
|
||||||
await wait(identityReceiver, () => !document.querySelector('.incoming'));
|
await wait(identityReceiver, () => !document.querySelector('.incoming'));
|
||||||
await click(identitySender, 'Reset'); await click(identityReceiver, 'Reset');
|
await click(identitySender, 'Reset'); await click(identityReceiver, 'Reset');
|
||||||
const key = await evaluate(forgottenSide, () => document.querySelector<HTMLSelectElement>('#expected-device')!.options[1]!.value);
|
|
||||||
await input(forgottenSide, '#expected-device', key);
|
|
||||||
}
|
}
|
||||||
console.log('PASS: forgetting a device in another tab removes stale trust before either role reconnects; manual confirmation gates metadata and permits pairing again.');
|
console.log('PASS: forgetting a device in another tab removes stale trust before either role reconnects; manual confirmation gates metadata and pairs the connection again.');
|
||||||
|
|
||||||
await evaluate(identitySender, () => { indexedDB.open = () => { throw new DOMException('Storage denied during refresh', 'SecurityError'); }; });
|
await evaluate(identitySender, () => { indexedDB.open = () => { throw new DOMException('Storage denied during refresh', 'SecurityError'); }; });
|
||||||
await evaluate(identitySender, () => window.__hellcon.chooseFile(1, 'storage-failure.bin'));
|
await evaluate(identitySender, () => window.__hellcon.chooseFile(1, 'storage-failure.bin'));
|
||||||
@@ -419,23 +557,32 @@ try {
|
|||||||
assert.equal(await evaluate(identitySender, () => !!document.querySelector('#output-code')), false, 'Failed storage refresh must not use cached trust');
|
assert.equal(await evaluate(identitySender, () => !!document.querySelector('#output-code')), false, 'Failed storage refresh must not use cached trust');
|
||||||
await evaluate(identitySender, () => { Reflect.deleteProperty(indexedDB, 'open'); });
|
await evaluate(identitySender, () => { Reflect.deleteProperty(indexedDB, 'open'); });
|
||||||
await click(identitySender, 'Reset');
|
await click(identitySender, 'Reset');
|
||||||
console.log('PASS: unreadable storage during connection setup cannot reuse a cached identity or contact.');
|
console.log('PASS: unreadable storage during connection setup cannot reuse a cached identity or paired device.');
|
||||||
|
|
||||||
|
const senderPaired = await pairedKey(identitySender);
|
||||||
await evaluate(identityReceiver, () => {
|
await evaluate(identityReceiver, () => {
|
||||||
const label = [...document.querySelectorAll('label')].find(el => el.textContent?.includes('Replace or delete'));
|
const label = [...document.querySelectorAll('label')].find(el => el.textContent?.includes('Delete this browser’s device identity'));
|
||||||
label?.querySelector<HTMLInputElement>('input')?.click();
|
label?.querySelector<HTMLInputElement>('input')?.click();
|
||||||
});
|
});
|
||||||
await click(identityReceiver, 'Delete identity and contacts');
|
await click(identityReceiver, 'Delete device identity');
|
||||||
await wait(identityReceiver, () => [...document.querySelectorAll('button')].some(button => button.textContent === 'Create device identity'));
|
await wait(identityReceiver, () => [...document.querySelectorAll('button')].some(button => button.textContent === 'Create device identity'));
|
||||||
await click(identityReceiver, 'Create device identity');
|
await click(identityReceiver, 'Create device identity');
|
||||||
await wait(identityReceiver, () => document.querySelector<HTMLInputElement>('#use-device-identity')?.checked);
|
await wait(identityReceiver, () => !!document.querySelector('.device-settings code'));
|
||||||
await connect(identitySender, identityReceiver, 512, true);
|
await connect(identitySender, identityReceiver, 512, true);
|
||||||
await click(identityReceiver, 'Receive in memory (up to 64 MiB)');
|
await click(identityReceiver, 'Receive in memory (up to 64 MiB)');
|
||||||
await wait(identitySender, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
|
await wait(identitySender, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
|
||||||
assert.equal(await evaluate(identitySender, () => document.querySelector<HTMLSelectElement>('#expected-device')!.options.length), 2, 'Changed identity must not replace or append saved contacts automatically');
|
assert.ok(await evaluate(identitySender, () => document.body.textContent?.includes('This device was not remembered.')));
|
||||||
console.log('PASS: replaced peer identity requires manual comparison and preserves the original saved contact.');
|
assert.equal(await pairedKey(identitySender), senderPaired, 'Changed identity must not replace the paired device automatically');
|
||||||
|
console.log('PASS: replaced peer identity requires manual comparison and preserves the paired device.');
|
||||||
|
await click(identitySender, 'Disconnect');
|
||||||
|
await wait(identityReceiver, () => !document.querySelector('.incoming'));
|
||||||
|
await click(identitySender, 'Reset'); await click(identityReceiver, 'Reset');
|
||||||
const stale = await page();
|
const stale = await page();
|
||||||
await wait(stale, () => !!document.querySelector('#use-device-identity'));
|
await wait(stale, () => !!document.querySelector('.device-settings code'));
|
||||||
|
await click(stale, 'Forget device');
|
||||||
|
await wait(stale, () => document.querySelector<HTMLInputElement>('#remember-device')?.checked);
|
||||||
|
await wait(identitySender, () => document.querySelector<HTMLInputElement>('#remember-device')?.checked);
|
||||||
|
console.log('PASS: Forget device keeps the per-connection opt-in and reaches other tabs.');
|
||||||
await evaluate(stale, async () => {
|
await evaluate(stale, async () => {
|
||||||
const db = await new Promise<IDBDatabase>((resolve, reject) => { const request = indexedDB.open('hellcon-devices', 1); request.onsuccess = () => resolve(request.result); request.onerror = () => reject(request.error); });
|
const db = await new Promise<IDBDatabase>((resolve, reject) => { const request = indexedDB.open('hellcon-devices', 1); request.onsuccess = () => resolve(request.result); request.onerror = () => reject(request.error); });
|
||||||
await new Promise<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
@@ -444,18 +591,19 @@ try {
|
|||||||
tx.oncomplete = () => resolve(); tx.onabort = () => reject(tx.error);
|
tx.oncomplete = () => resolve(); tx.onabort = () => reject(tx.error);
|
||||||
}); db.close();
|
}); db.close();
|
||||||
});
|
});
|
||||||
await click(stale, 'Forget');
|
await evaluate(stale, () => [...document.querySelectorAll('label')].find(el => el.textContent?.includes('Delete this browser’s device identity'))?.querySelector<HTMLInputElement>('input')?.click());
|
||||||
|
await click(stale, 'Delete device identity');
|
||||||
await wait(stale, () => document.body.textContent?.includes('Device settings changed in another tab'));
|
await wait(stale, () => document.body.textContent?.includes('Device settings changed in another tab'));
|
||||||
await evaluate(stale, async () => {
|
await evaluate(stale, async () => {
|
||||||
const db = await new Promise<IDBDatabase>(resolve => { const request = indexedDB.open('hellcon-devices', 1); request.onsuccess = () => resolve(request.result); });
|
const db = await new Promise<IDBDatabase>(resolve => { const request = indexedDB.open('hellcon-devices', 1); request.onsuccess = () => resolve(request.result); });
|
||||||
await new Promise<void>(resolve => { const tx = db.transaction('settings', 'readwrite'); tx.objectStore('settings').put({ identity: null, contacts: 'broken', revision: 'broken' }, 'state'); tx.oncomplete = () => resolve(); }); db.close();
|
await new Promise<void>(resolve => { const tx = db.transaction('settings', 'readwrite'); tx.objectStore('settings').put({ identity: { publicKey: 'broken' }, revision: 'broken' }, 'state'); tx.oncomplete = () => resolve(); }); db.close();
|
||||||
});
|
});
|
||||||
await call('Page.navigate', { url: origin }, stale);
|
await call('Page.navigate', { url: origin }, stale);
|
||||||
await wait(stale, () => document.body.textContent?.includes('Invalid contact list'));
|
await wait(stale, () => document.body.textContent?.includes('Invalid device identity'));
|
||||||
await evaluate(stale, () => [...document.querySelectorAll('label')].find(label => label.textContent?.includes('Delete unreadable device storage'))?.querySelector<HTMLInputElement>('input')?.click());
|
await evaluate(stale, () => [...document.querySelectorAll('label')].find(label => label.textContent?.includes('Delete unreadable device storage'))?.querySelector<HTMLInputElement>('input')?.click());
|
||||||
await click(stale, 'Clear device storage');
|
await click(stale, 'Clear device storage');
|
||||||
await wait(stale, () => [...document.querySelectorAll('button')].some(button => button.textContent === 'Create device identity' && !button.disabled));
|
await wait(stale, () => [...document.querySelectorAll('button')].some(button => button.textContent === 'Create device identity' && !button.disabled));
|
||||||
console.log('PASS: stale contact edits cannot overwrite newer settings; unreadable storage can be cleared with explicit consent.');
|
console.log('PASS: stale identity edits cannot overwrite newer settings; unreadable storage can be cleared with explicit consent.');
|
||||||
const denied = await page();
|
const denied = await page();
|
||||||
await call('Page.addScriptToEvaluateOnNewDocument', { source: "indexedDB.open = () => { throw new DOMException('Storage denied', 'SecurityError'); };" }, denied);
|
await call('Page.addScriptToEvaluateOnNewDocument', { source: "indexedDB.open = () => { throw new DOMException('Storage denied', 'SecurityError'); };" }, denied);
|
||||||
await call('Page.navigate', { url: origin }, denied);
|
await call('Page.navigate', { url: origin }, denied);
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ export function installBrowserContext() {
|
|||||||
aborted: false,
|
aborted: false,
|
||||||
releaseWrite: undefined as (() => void) | undefined,
|
releaseWrite: undefined as (() => void) | undefined,
|
||||||
click(label: string) {
|
click(label: string) {
|
||||||
const button = [...document.querySelectorAll('button')].find(button => button.textContent?.trim() === label);
|
const button = [...document.querySelectorAll('button')].find(button => {
|
||||||
|
const content = button.cloneNode(true) as HTMLButtonElement;
|
||||||
|
content.querySelectorAll('[aria-hidden="true"]').forEach(item => item.remove());
|
||||||
|
return button.getAttribute('aria-label') === label || content.textContent?.trim() === label;
|
||||||
|
});
|
||||||
if (!button || button.disabled) throw new Error(`Unavailable button: ${label}`);
|
if (!button || button.disabled) throw new Error(`Unavailable button: ${label}`);
|
||||||
button.click();
|
button.click();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
import { readFile, writeFile } from 'node:fs/promises';
|
|
||||||
import { dirname, join, resolve } from 'node:path';
|
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
|
|
||||||
const dist = resolve(dirname(fileURLToPath(import.meta.url)), '../dist');
|
|
||||||
let html = await readFile(join(dist, 'index.html'), 'utf8');
|
|
||||||
|
|
||||||
const scriptTag = /<script type="module"(?: [^>]*)? src="(\.\/assets\/[^"<>]+\.js)"><\/script>/;
|
|
||||||
const scriptPath = html.match(scriptTag)?.[1];
|
|
||||||
if (!scriptPath) throw new Error('Expected a Vite JavaScript asset in dist/index.html');
|
|
||||||
|
|
||||||
const [javascript, icon] = await Promise.all([
|
|
||||||
readFile(join(dist, scriptPath)),
|
|
||||||
readFile(join(dist, 'HellNet_alt.png')),
|
|
||||||
]);
|
|
||||||
const js = javascript.toString('utf8');
|
|
||||||
if (/<\/script/i.test(js)) throw new Error('Built JavaScript contains an unsafe inline closing tag');
|
|
||||||
|
|
||||||
html = html.replace(scriptTag, '');
|
|
||||||
html = html.replace('href="./HellNet_alt.png"', `href="data:image/png;base64,${icon.toString('base64')}"`);
|
|
||||||
html = html.replace('</body>', () => ` <script>${js}</script>\n </body>`);
|
|
||||||
if (/src="\.\/assets\/|href="\.\/assets\/|href="\.\/HellNet_alt\.png"/.test(html)) {
|
|
||||||
throw new Error('Standalone HTML still references external build assets');
|
|
||||||
}
|
|
||||||
await writeFile(join(dist, 'hellcon-local.html'), html);
|
|
||||||
+164
-41
@@ -1,50 +1,173 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue';
|
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||||
import TransferPanel from './components/TransferPanel.vue';
|
import ConnectionWorkspace from './components/ConnectionWorkspace.vue';
|
||||||
|
import AppDialog from './components/AppDialog.vue';
|
||||||
|
import EditableName from './components/EditableName.vue';
|
||||||
|
import { addConnection, CONNECTION_LIMIT, emptyConnection, loadConnections, removeConnection, saveConnection, updateConnection, type ConnectionActivity, type ConnectionUpdate, type SavedConnection } from './lib/connections.ts';
|
||||||
|
import { asError } from './lib/validation.ts';
|
||||||
|
|
||||||
const mode = ref<'send' | 'receive'>('send');
|
const logoUrl = `${import.meta.env.BASE_URL}HellNet_alt.png`;
|
||||||
const sessionActive = ref(false);
|
const connections = ref<SavedConnection[]>([]), selected = ref('');
|
||||||
const connected = ref(false);
|
const states = ref<Record<string, 'ready' | 'connecting' | 'connected'>>({});
|
||||||
const direction = ref<'send' | 'receive'>('send');
|
const current = computed(() => connections.value.find(item => item.id === selected.value));
|
||||||
const panel = ref<InstanceType<typeof TransferPanel> | null>(null);
|
const sidebarOpen = ref(false), adding = ref(false);
|
||||||
function navigate(next: 'send' | 'receive') {
|
const confirmingRemoval = ref(false), removing = ref(false);
|
||||||
if (connected.value) { direction.value = next; panel.value?.focusDirection(next); }
|
const error = ref(''), removalError = ref('');
|
||||||
else if (!sessionActive.value) mode.value = next;
|
const heading = ref<HTMLElement | null>(null);
|
||||||
|
let persistent = true, pending = 0, writes = Promise.resolve(), refreshRequested = false;
|
||||||
|
let updates: BroadcastChannel | undefined;
|
||||||
|
function select(id: string) {
|
||||||
|
selected.value = id; confirmingRemoval.value = false; sidebarOpen.value = false;
|
||||||
|
void nextTick(() => heading.value?.focus());
|
||||||
|
}
|
||||||
|
function applyRecords(records: SavedConnection[]) {
|
||||||
|
connections.value = records;
|
||||||
|
for (const id of Object.keys(states.value)) if (!records.some(item => item.id === id)) delete states.value[id];
|
||||||
|
if (!records.some(item => item.id === selected.value)) select(records[0]!.id);
|
||||||
|
}
|
||||||
|
function setStatus(id: string, state: 'ready' | 'connecting' | 'connected') {
|
||||||
|
if (connections.value.some(item => item.id === id)) states.value[id] = state;
|
||||||
|
}
|
||||||
|
function statusLabel(id: string) { return states.value[id] === 'connected' ? 'Connected' : states.value[id] === 'connecting' ? 'Connecting' : 'Ready to connect'; }
|
||||||
|
async function refresh() {
|
||||||
|
if (!persistent) return;
|
||||||
|
if (pending || removing.value) { refreshRequested = true; return; }
|
||||||
|
refreshRequested = false;
|
||||||
|
try { const records = await loadConnections(); if (!pending && !removing.value) applyRecords(records); else refreshRequested = true; }
|
||||||
|
catch (err) { error.value = asError(err).message; }
|
||||||
|
}
|
||||||
|
onMounted(async () => {
|
||||||
|
try { connections.value = await loadConnections(); }
|
||||||
|
catch (err) {
|
||||||
|
persistent = false; connections.value = [emptyConnection()];
|
||||||
|
error.value = `${asError(err).message} Connections and activity will only last for this tab.`;
|
||||||
|
}
|
||||||
|
selected.value = connections.value[0]!.id;
|
||||||
|
if (typeof BroadcastChannel !== 'undefined') {
|
||||||
|
updates = new BroadcastChannel('hellcon-connections');
|
||||||
|
updates.onmessage = () => { void refresh(); };
|
||||||
|
}
|
||||||
|
window.addEventListener('focus', refresh);
|
||||||
|
});
|
||||||
|
onBeforeUnmount(() => { updates?.close(); window.removeEventListener('focus', refresh); });
|
||||||
|
async function add() {
|
||||||
|
if (adding.value || removing.value || connections.value.length >= CONNECTION_LIMIT) return;
|
||||||
|
adding.value = true;
|
||||||
|
try {
|
||||||
|
await writes;
|
||||||
|
if (persistent) connections.value = await addConnection();
|
||||||
|
else connections.value.push(emptyConnection(Math.max(...connections.value.map(item => item.number)) + 1));
|
||||||
|
select(connections.value.at(-1)!.id); updates?.postMessage('changed');
|
||||||
|
} catch (err) { error.value = asError(err).message; }
|
||||||
|
finally { adding.value = false; }
|
||||||
|
}
|
||||||
|
function update(id: string, change: ConnectionUpdate) {
|
||||||
|
const index = connections.value.findIndex(item => item.id === id);
|
||||||
|
if (index < 0) return;
|
||||||
|
try { connections.value[index] = updateConnection(connections.value[index]!, change); }
|
||||||
|
catch (err) { error.value = asError(err).message; return; }
|
||||||
|
if (!persistent) return;
|
||||||
|
pending++;
|
||||||
|
writes = writes.then(async () => {
|
||||||
|
try {
|
||||||
|
const records = await saveConnection(id, change);
|
||||||
|
if (pending === 1) applyRecords(records);
|
||||||
|
updates?.postMessage('changed');
|
||||||
|
} catch (err) {
|
||||||
|
// Keep this tab's activity usable without pretending it reached storage.
|
||||||
|
error.value = `${asError(err).message} Your latest changes may be lost when this tab closes.`;
|
||||||
|
refreshRequested = true;
|
||||||
|
} finally { pending--; if (!pending && refreshRequested) void refresh(); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function record(id: string, activity: ConnectionActivity) { update(id, { activity }); }
|
||||||
|
// 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) {
|
||||||
|
await writes;
|
||||||
|
const records = persistent ? await loadConnections() : connections.value;
|
||||||
|
const record = records.find(item => item.id === id);
|
||||||
|
if (!record) throw new Error('This connection is no longer saved. Reload the page.');
|
||||||
|
if (persistent && !pending && !removing.value) applyRecords(records);
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
async function remove() {
|
||||||
|
if (!current.value || removing.value || adding.value) return;
|
||||||
|
const id = current.value.id;
|
||||||
|
removing.value = true; removalError.value = '';
|
||||||
|
try {
|
||||||
|
await writes;
|
||||||
|
const records = persistent ? await removeConnection(id) : connections.value.filter(item => item.id !== id);
|
||||||
|
applyRecords(records.length ? records : [emptyConnection()]);
|
||||||
|
confirmingRemoval.value = false;
|
||||||
|
updates?.postMessage('changed');
|
||||||
|
} catch (err) { removalError.value = asError(err).message; }
|
||||||
|
finally { removing.value = false; if (refreshRequested) void refresh(); }
|
||||||
}
|
}
|
||||||
const isLocal = location.protocol === 'file:';
|
|
||||||
const canDownloadApp = import.meta.env.PROD && !isLocal;
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<a class="skip-link" href="#main-content">Skip to main content</a>
|
<a class="skip-link" href="#main-content">Skip to main content</a>
|
||||||
<main id="main-content" tabindex="-1">
|
<div class="app-shell" :class="{ 'sidebar-open': sidebarOpen }">
|
||||||
<h1>HellCon</h1>
|
<aside id="connections-sidebar" class="sidebar" aria-label="Connections sidebar">
|
||||||
<p class="subtitle">
|
<header class="brand">
|
||||||
Browser-to-browser file sharing. No account or file-hosting backend.
|
<img :src="logoUrl" width="38" height="38" alt="" />
|
||||||
Direct WebRTC connections, with an optional relay you explicitly enable.
|
<div><span class="brand-name">HellCon</span><p>Direct file sharing</p></div>
|
||||||
</p>
|
</header>
|
||||||
<a v-if="canDownloadApp" class="app-download" href="./hellcon-local.html" download="HellCon.html">Download app for local use</a>
|
<div class="sidebar-section-heading"><h2>Connections</h2><span>{{ connections.length }}</span></div>
|
||||||
|
<nav class="connection-nav" aria-label="Connections">
|
||||||
<p v-if="canDownloadApp || isLocal" class="status">For large files in the downloaded local version, use desktop Chrome on the receiving machine and choose “Choose destination & receive to disk”.</p>
|
<button v-for="item in connections" :key="item.id" class="connection-link" :class="{ selected: selected === item.id }"
|
||||||
|
:aria-current="selected === item.id ? 'page' : undefined" @click="select(item.id)">
|
||||||
<div class="tabs" role="group" :aria-label="connected ? 'Transfer sections' : 'Connection setup'">
|
<span class="connection-avatar" aria-hidden="true">{{ item.name.slice(0, 1).toUpperCase() }}</span>
|
||||||
<button :disabled="sessionActive && !connected" :class="{ active: (connected ? direction : mode) === 'send' }" :aria-pressed="(connected ? direction : mode) === 'send'" @click="navigate('send')">Send</button>
|
<span class="connection-label"><span class="connection-name">{{ item.name }}</span><span class="connection-preview">{{ item.history.at(-1)?.name || (item.peerKey ? 'Remembered device' : 'No activity yet') }}</span></span>
|
||||||
<button :disabled="sessionActive && !connected" :class="{ active: (connected ? direction : mode) === 'receive' }" :aria-pressed="(connected ? direction : mode) === 'receive'" @click="navigate('receive')">Receive</button>
|
<span class="connection-dot" :class="states[item.id] || 'ready'" :aria-label="statusLabel(item.id)"></span>
|
||||||
</div>
|
</button>
|
||||||
|
</nav>
|
||||||
<p v-if="connected" class="status">Connected — either person can send files. Send and Receive jump to those sections without interrupting transfers.</p>
|
<button class="add-connection" :disabled="adding || removing || !connections.length || connections.length >= CONNECTION_LIMIT" @click="add"><span aria-hidden="true">+</span> Add connection</button>
|
||||||
<p v-else-if="sessionActive" class="status">Finish connecting and verifying first. Then either person can send and receive.</p>
|
<footer class="sidebar-footer">
|
||||||
<TransferPanel ref="panel" :key="mode" :sending="mode === 'send'" @session-change="sessionActive = $event" @connected-change="connected = $event; direction = mode" />
|
<span class="sidebar-tag">Browser to browser</span>
|
||||||
</main>
|
<p>No accounts. Your connections stay on this device.</p>
|
||||||
|
<details class="privacy-details">
|
||||||
<footer>
|
<summary>About privacy & connections</summary>
|
||||||
<p>
|
<p>Files travel over encrypted WebRTC data channels. Compare full fingerprints on first pairing, or let a connection authenticate its remembered device. Reconnect by exchanging fresh codes.</p>
|
||||||
Files travel over encrypted WebRTC data channels (SCTP over DTLS).
|
<p>Trust your browser and the app’s host: its code can read selected files and use your device identity. HTTPS protects delivery. A TURN relay is used only after opt-in.</p>
|
||||||
Compare both full fingerprints on first pairing, or authenticate an expected remembered device. This requires trusted
|
<p>Clearing site data removes saved connections, identities, and history.</p>
|
||||||
browsers, a trusted copy of this app, and an authenticated comparison
|
</details>
|
||||||
channel. The website host supplies JavaScript that can read your selected
|
|
||||||
file; HTTPS protects delivery but cannot protect you from a malicious host.
|
|
||||||
A TURN relay is used only after opt-in and carries encrypted traffic.
|
|
||||||
</p>
|
|
||||||
</footer>
|
</footer>
|
||||||
|
</aside>
|
||||||
|
<main id="main-content" class="main-pane" tabindex="-1">
|
||||||
|
<header class="connection-header">
|
||||||
|
<button class="sidebar-toggle" :aria-expanded="sidebarOpen" aria-controls="connections-sidebar" @click="sidebarOpen = !sidebarOpen">{{ sidebarOpen ? 'Hide connections' : 'Show connections' }}</button>
|
||||||
|
<template v-if="current">
|
||||||
|
<div class="connection-title">
|
||||||
|
<p class="eyebrow">Connection</p>
|
||||||
|
<div class="title-line">
|
||||||
|
<h1 ref="heading" class="sr-only" tabindex="-1">{{ current.name }}</h1>
|
||||||
|
<EditableName :key="current.id" :name="current.name" :disabled="removing" @rename="update(current!.id, { name: $event })" />
|
||||||
|
<button class="header-action" :disabled="adding || removing" @click="removalError = ''; confirmingRemoval = true"><span class="header-action-icon" aria-hidden="true">✕</span> Remove</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span class="session-badge" :class="states[current.id] || 'ready'"><span class="connection-dot" :class="states[current.id] || 'ready'" aria-hidden="true"></span>{{ statusLabel(current.id) }}</span>
|
||||||
|
</template>
|
||||||
|
</header>
|
||||||
|
<div class="workspace-scroll">
|
||||||
|
<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" @status="setStatus" @activity="record" @update="update" />
|
||||||
|
</KeepAlive>
|
||||||
|
</template>
|
||||||
|
<p v-if="!current" class="status">Opening your connections…</p>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
<AppDialog v-model="confirmingRemoval" :title="`Remove ${current?.name || 'connection'}?`" :busy="removing">
|
||||||
|
<p>This ends its session and deletes its saved activity and remembered device. Saved files and your device identity are kept.</p>
|
||||||
|
<p v-if="connections.length === 1">A fresh Con 1 will replace your last connection.</p>
|
||||||
|
<p v-if="removalError" class="error" role="alert">{{ removalError }}</p>
|
||||||
|
<template #actions="{ close }">
|
||||||
|
<button :disabled="removing" autofocus @click="close">Keep connection</button>
|
||||||
|
<button class="danger" :disabled="removing" @click="remove">{{ removing ? 'Removing…' : 'Remove connection' }}</button>
|
||||||
|
</template>
|
||||||
|
</AppDialog>
|
||||||
</template>
|
</template>
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { onBeforeUnmount, onMounted, ref, useId, watch } from 'vue';
|
||||||
|
|
||||||
|
const open = defineModel<boolean>({ default: false });
|
||||||
|
const props = defineProps<{ title: string; busy?: boolean }>();
|
||||||
|
const dialog = ref<HTMLDialogElement | null>(null);
|
||||||
|
const titleId = useId(), bodyId = useId();
|
||||||
|
function close() { if (!props.busy) open.value = false; }
|
||||||
|
function closed() { if (!dialog.value?.open) open.value = false; }
|
||||||
|
// showModal() makes the page inert but lets Tab leave for the browser UI; wrap instead.
|
||||||
|
function trap(event: KeyboardEvent) {
|
||||||
|
const items = [...dialog.value?.querySelectorAll<HTMLElement>('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])') ?? []]
|
||||||
|
.filter(item => !item.matches(':disabled') && item.offsetParent !== null);
|
||||||
|
const first = items[0], last = items.at(-1);
|
||||||
|
if (!first || !last) { event.preventDefault(); return; }
|
||||||
|
const active = document.activeElement;
|
||||||
|
if (event.shiftKey && (active === first || !dialog.value?.contains(active))) { event.preventDefault(); last.focus(); }
|
||||||
|
else if (!event.shiftKey && (active === last || !dialog.value?.contains(active))) { event.preventDefault(); first.focus(); }
|
||||||
|
}
|
||||||
|
function sync() {
|
||||||
|
if (open.value && !dialog.value?.open) dialog.value?.showModal();
|
||||||
|
else if (!open.value && dialog.value?.open) dialog.value.close();
|
||||||
|
}
|
||||||
|
watch(open, sync, { flush: 'post' });
|
||||||
|
onMounted(sync);
|
||||||
|
onBeforeUnmount(() => dialog.value?.close());
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Teleport to="body">
|
||||||
|
<dialog ref="dialog" class="app-dialog" :aria-labelledby="titleId" :aria-describedby="bodyId" :aria-busy="busy || undefined"
|
||||||
|
@cancel.prevent="close" @close="closed" @keydown.tab="trap">
|
||||||
|
<header class="dialog-header">
|
||||||
|
<h2 :id="titleId">{{ title }}</h2>
|
||||||
|
<button class="dialog-close" type="button" aria-label="Close dialog" :disabled="busy" @click="close"><span aria-hidden="true">×</span></button>
|
||||||
|
</header>
|
||||||
|
<div :id="bodyId" class="dialog-body"><slot :close="close" /></div>
|
||||||
|
<div v-if="$slots.actions" class="dialog-actions"><slot name="actions" :close="close" /></div>
|
||||||
|
</dialog>
|
||||||
|
</Teleport>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import TransferPanel from './TransferPanel.vue';
|
||||||
|
import type { SavedConnection, ConnectionActivity, ConnectionUpdate } from '../lib/connections.ts';
|
||||||
|
const props = defineProps<{ connection: SavedConnection; loadTrust: (id: string) => Promise<SavedConnection> }>();
|
||||||
|
const emit = defineEmits<{
|
||||||
|
status: [id: string, state: 'ready' | 'connecting' | 'connected'];
|
||||||
|
activity: [id: string, item: ConnectionActivity];
|
||||||
|
update: [id: string, change: ConnectionUpdate];
|
||||||
|
}>();
|
||||||
|
const mode = ref<'send' | 'receive'>('send');
|
||||||
|
const sessionActive = ref(false), connected = ref(false);
|
||||||
|
const direction = ref<'send' | 'receive'>('send');
|
||||||
|
const panel = ref<InstanceType<typeof TransferPanel> | null>(null);
|
||||||
|
function status() { emit('status', props.connection.id, connected.value ? 'connected' : sessionActive.value ? 'connecting' : 'ready'); }
|
||||||
|
function navigate(next: 'send' | 'receive') {
|
||||||
|
if (connected.value) { direction.value = next; panel.value?.focusDirection(next); }
|
||||||
|
else if (!sessionActive.value) mode.value = next;
|
||||||
|
}
|
||||||
|
function sizeLabel(size: number) {
|
||||||
|
if (size < 1024) return `${size} B`;
|
||||||
|
const index = Math.min(5, Math.floor(Math.log(size) / Math.log(1024)));
|
||||||
|
return `${(size / 1024 ** index).toFixed(1)} ${['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'][index]}`;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="connection-workspace">
|
||||||
|
<div class="session-column">
|
||||||
|
<div class="workspace-intro">
|
||||||
|
<h2>{{ connected ? 'Share files' : 'Start a session' }}</h2>
|
||||||
|
<p>{{ connected ? 'Your connection is ready.' : 'Exchange connection codes with your peer to start sharing.' }} Each direction sends one file at a time; both people can send on this connection.</p>
|
||||||
|
</div>
|
||||||
|
<div class="tabs" role="group" :aria-label="connected ? 'Transfer sections' : 'Connection setup'">
|
||||||
|
<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)"
|
||||||
|
@session-change="sessionActive = $event; status()" @connected-change="connected = $event; direction = mode; status()"
|
||||||
|
@activity="emit('activity', connection.id, $event)" @update="emit('update', connection.id, $event)" />
|
||||||
|
</div>
|
||||||
|
<aside class="activity-panel" aria-labelledby="activity-heading">
|
||||||
|
<div class="activity-heading"><h2 id="activity-heading">Activity</h2><span>{{ connection.history.length }}</span></div>
|
||||||
|
<div v-if="!connection.history.length" class="empty-activity">
|
||||||
|
<span class="empty-activity-icon" aria-hidden="true">↔</span>
|
||||||
|
<h3>A fresh connection</h3>
|
||||||
|
<p>Files you share here will appear in this timeline.</p>
|
||||||
|
<p class="activity-note">History stays in this browser. File contents aren’t kept here.</p>
|
||||||
|
</div>
|
||||||
|
<ol v-else class="activity-list" aria-label="Recent file results">
|
||||||
|
<li v-for="item in [...connection.history].reverse()" :key="item.id" class="activity-item">
|
||||||
|
<span class="activity-icon" aria-hidden="true">{{ item.direction === 'send' ? '↗' : '↙' }}</span>
|
||||||
|
<div>
|
||||||
|
<p class="activity-filename">{{ item.name }}</p>
|
||||||
|
<p class="activity-meta">{{ item.direction === 'send' ? 'Outgoing' : 'Incoming' }} · {{ sizeLabel(item.size) }}</p>
|
||||||
|
<p class="activity-result">{{ item.result === 'complete' ? 'Transfer complete' : item.result === 'declined' ? 'Declined' : 'Interrupted' }}</p>
|
||||||
|
<time :datetime="new Date(item.time).toISOString()">{{ new Date(item.time).toLocaleString([], { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }) }}</time>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
<p v-if="connection.history.length" class="activity-note">Last 50 transfers · Saved in this browser</p>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -1,107 +1,78 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onBeforeUnmount, onMounted, ref, shallowRef, watch } from 'vue';
|
import { onActivated, onMounted, ref, shallowRef } from 'vue';
|
||||||
import { clearIdentityStorage, createIdentity, loadIdentityState, saveIdentityState, exportBackup, importBackup, type IdentityState } from '../lib/identity.ts';
|
import { clearIdentityStorage, createIdentity, loadIdentityState, saveIdentityState, type IdentityState } from '../lib/identity.ts';
|
||||||
|
import type { ConnectionUpdate } from '../lib/connections.ts';
|
||||||
import { asError } from '../lib/validation.ts';
|
import { asError } from '../lib/validation.ts';
|
||||||
const props = defineProps<{ disabled: boolean }>();
|
const props = defineProps<{ disabled: boolean; paired: string; remember: boolean }>();
|
||||||
const emit = defineEmits<{ change: [state: IdentityState, enabled: boolean, expected: string] }>();
|
const emit = defineEmits<{ update: [change: ConnectionUpdate] }>();
|
||||||
const supported = (() => { try { return location.protocol !== 'file:' && isSecureContext && !!crypto.subtle && !!window.indexedDB; } catch { return false; } })();
|
const supported = (() => { try { return isSecureContext && !!crypto.subtle && !!window.indexedDB; } catch { return false; } })();
|
||||||
const state = shallowRef<IdentityState>({ identity: null, contacts: [] });
|
const state = shallowRef<IdentityState>({ identity: null });
|
||||||
const enabled = ref(false), expected = ref(''), working = ref(false), loaded = ref(false);
|
const working = ref(false), loaded = ref(false);
|
||||||
const error = ref(''), password = ref(''), confirmReplace = ref(false);
|
const error = ref(''), confirmDelete = ref(false);
|
||||||
const backupUrl = ref('');
|
|
||||||
onBeforeUnmount(() => { if (backupUrl.value) URL.revokeObjectURL(backupUrl.value); });
|
|
||||||
watch([state, enabled, expected], () => emit('change', state.value, enabled.value, expected.value));
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (!supported) return;
|
if (!supported) return;
|
||||||
try { state.value = await loadIdentityState(); loaded.value = true; }
|
try { state.value = await loadIdentityState(); loaded.value = true; }
|
||||||
catch (err) { error.value = asError(err).message; }
|
catch (err) { error.value = asError(err).message; }
|
||||||
});
|
});
|
||||||
async function store(next: IdentityState) {
|
onActivated(async () => {
|
||||||
state.value = await saveIdentityState(next, state.value.revision);
|
// Another slot may have replaced the shared identity while this workspace
|
||||||
if (backupUrl.value) { URL.revokeObjectURL(backupUrl.value); backupUrl.value = ''; }
|
// was cached. Never interrupt an active session to refresh it.
|
||||||
}
|
if (!loaded.value || props.disabled) return;
|
||||||
|
try {
|
||||||
|
const next = await loadIdentityState();
|
||||||
|
if (props.disabled) return;
|
||||||
|
if (next.revision !== state.value.revision) confirmDelete.value = false;
|
||||||
|
state.value = next;
|
||||||
|
} catch (err) { error.value = asError(err).message; }
|
||||||
|
});
|
||||||
async function run(action: () => Promise<void>) {
|
async function run(action: () => Promise<void>) {
|
||||||
if (props.disabled || working.value) return;
|
if (props.disabled || working.value) return;
|
||||||
working.value = true; error.value = '';
|
working.value = true; error.value = '';
|
||||||
try { await action(); } catch (err) { error.value = asError(err).message; }
|
try { await action(); } catch (err) { error.value = asError(err).message; }
|
||||||
finally { working.value = false; password.value = ''; }
|
finally { working.value = false; }
|
||||||
}
|
}
|
||||||
function recover() { void run(async () => { if (!confirmReplace.value) return; await clearIdentityStorage(); state.value = { identity: null, contacts: [] }; loaded.value = true; confirmReplace.value = false; }); }
|
function recover() { void run(async () => { if (!confirmDelete.value) return; await clearIdentityStorage(); state.value = { identity: null }; loaded.value = true; confirmDelete.value = false; }); }
|
||||||
function create() { void run(async () => { await store({ identity: await createIdentity(), contacts: [] }); enabled.value = true; }); }
|
// Creating an identity from a connection opts that connection in.
|
||||||
function remove(key: string) { void run(async () => { await store({ ...state.value, contacts: state.value.contacts.filter(item => item.key !== key) }); if (expected.value === key) expected.value = ''; }); }
|
function create() { void run(async () => { state.value = await saveIdentityState({ identity: await createIdentity() }, state.value.revision); emit('update', { rememberDevice: true }); }); }
|
||||||
function reset() { void run(async () => { if (!confirmReplace.value) return; await store({ identity: null, contacts: [] }); enabled.value = false; expected.value = ''; confirmReplace.value = false; }); }
|
function reset() { void run(async () => { if (!confirmDelete.value) return; state.value = await saveIdentityState({ identity: null }, state.value.revision); confirmDelete.value = false; }); }
|
||||||
function backup() { void run(async () => {
|
function toggle(event: Event) { if (!props.disabled && event.target instanceof HTMLInputElement) emit('update', { rememberDevice: event.target.checked }); }
|
||||||
const data = await exportBackup(state.value, password.value);
|
function forget() { if (!props.disabled) emit('update', { peerKey: '' }); }
|
||||||
if (backupUrl.value) URL.revokeObjectURL(backupUrl.value);
|
async function refreshIdentity() {
|
||||||
backupUrl.value = URL.createObjectURL(new Blob([data], { type: 'application/json' }));
|
|
||||||
}); }
|
|
||||||
function restore(event: Event) {
|
|
||||||
const input = event.target as HTMLInputElement, file = input.files?.[0]; input.value = '';
|
|
||||||
if (!file) return;
|
|
||||||
void run(async () => {
|
|
||||||
if (state.value.identity && !confirmReplace.value) throw new Error('Confirm replacement before restoring a backup.');
|
|
||||||
if (file.size > 100000) throw new Error('Backup is too large.');
|
|
||||||
const next = await importBackup(await file.text(), password.value);
|
|
||||||
await store(next); enabled.value = false; expected.value = ''; confirmReplace.value = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
async function remember(key: string, name: string) {
|
|
||||||
if (!state.value.identity) throw new Error('Create a local identity first.');
|
|
||||||
const next = { ...state.value, contacts: [...state.value.contacts.filter(item => item.key !== key), { key, name }] };
|
|
||||||
await store(next);
|
|
||||||
}
|
|
||||||
async function refreshForConnection() {
|
|
||||||
if (working.value) throw new Error('Wait for the device settings operation to finish before connecting.');
|
if (working.value) throw new Error('Wait for the device settings operation to finish before connecting.');
|
||||||
if (!supported || !enabled.value) return { identity: null, expected: '' };
|
if (!supported) return null;
|
||||||
try {
|
try {
|
||||||
const next = await loadIdentityState();
|
const next = await loadIdentityState();
|
||||||
if (next.identity?.publicKey !== state.value.identity?.publicKey) {
|
if (next.revision !== state.value.revision) confirmDelete.value = false;
|
||||||
enabled.value = false; expected.value = '';
|
|
||||||
}
|
|
||||||
if (!next.contacts.some(contact => contact.key === expected.value)) expected.value = '';
|
|
||||||
if (next.revision !== state.value.revision) {
|
|
||||||
if (backupUrl.value) URL.revokeObjectURL(backupUrl.value);
|
|
||||||
backupUrl.value = ''; confirmReplace.value = false; password.value = '';
|
|
||||||
}
|
|
||||||
state.value = next; loaded.value = true; error.value = '';
|
state.value = next; loaded.value = true; error.value = '';
|
||||||
return { identity: enabled.value ? next.identity : null, expected: expected.value };
|
return next.identity;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error.value = asError(err).message;
|
error.value = asError(err).message;
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defineExpose({ remember, refreshForConnection });
|
defineExpose({ refreshIdentity });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<details v-if="supported">
|
<details v-if="supported">
|
||||||
<summary>Remembered devices</summary>
|
<summary>Remembered device</summary>
|
||||||
<p class="status">Opt in to a device identity stored in this browser. Temporary connections remain available. Clearing site data loses your identity and contacts. Trusted app code is required: it can use and export this identity.</p>
|
<p class="status">Optionally remember the device on this connection, so later sessions verify it automatically. This uses a device identity stored in this browser and shared by all connections. Clearing site data loses it. Trusted app code is required: it can use this identity.</p>
|
||||||
<fieldset class="device-settings" :disabled="disabled || working || !loaded">
|
<fieldset class="device-settings" :disabled="disabled || working || !loaded">
|
||||||
<button v-if="!state.identity" @click="create">Create device identity</button>
|
<button v-if="!state.identity" @click="create">Create device identity</button>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<label><input id="use-device-identity" v-model="enabled" type="checkbox" /> Use my device identity for this connection</label>
|
<template v-if="paired">
|
||||||
<p class="status">Your public identity is included in connection codes when enabled and can link your sessions.</p>
|
<p class="status">Paired device <code>{{ paired.slice(-12) }}</code>. Later sessions verify it automatically.</p>
|
||||||
<label for="expected-device">Expected device</label>
|
<button @click="forget">Forget device</button>
|
||||||
<select id="expected-device" v-model="expected" :disabled="!enabled">
|
</template>
|
||||||
<option value="">New device — compare fingerprints manually</option>
|
<label v-else><input id="remember-device" :checked="remember" type="checkbox" @change="toggle" /> Use my device identity on this connection</label>
|
||||||
<option v-for="contact in state.contacts" :key="contact.key" :value="contact.key">{{ contact.name }} ({{ contact.key.slice(-12) }})</option>
|
<p class="status">When enabled, your public identity is included in this connection’s codes and can link your sessions.</p>
|
||||||
</select>
|
<label><input v-model="confirmDelete" type="checkbox" /> Delete this browser’s device identity</label>
|
||||||
<ul aria-label="Remembered devices"><li v-for="contact in state.contacts" :key="contact.key">{{ contact.name }} <button @click="remove(contact.key)" :aria-label="'Forget ' + contact.name">Forget</button></li></ul>
|
<button :disabled="!confirmDelete" @click="reset">Delete device identity</button>
|
||||||
</template>
|
</template>
|
||||||
<label for="backup-password">Backup password (at least 12 characters)</label>
|
|
||||||
<input id="backup-password" v-model="password" type="password" autocomplete="new-password" maxlength="1024" />
|
|
||||||
<button :disabled="!state.identity || password.length < 12" @click="backup">Create encrypted backup</button>
|
|
||||||
<a v-if="backupUrl" :href="backupUrl" download="hellcon-device-backup.json">Save encrypted backup</a>
|
|
||||||
<p class="status">A backup contains your identity and contacts. Keep its password separately. Restoring the same backup on another browser gives that browser the same identity.</p>
|
|
||||||
<label v-if="state.identity"><input v-model="confirmReplace" type="checkbox" /> Replace or delete this browser’s identity and contacts</label>
|
|
||||||
<label for="restore-identity">Restore encrypted backup</label>
|
|
||||||
<input id="restore-identity" type="file" accept="application/json,.json" :disabled="password.length < 12 || (!!state.identity && !confirmReplace)" @change="restore" />
|
|
||||||
<button v-if="state.identity" :disabled="!confirmReplace" @click="reset">Delete identity and contacts</button>
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<div v-if="!loaded && error">
|
<div v-if="!loaded && error">
|
||||||
<label><input v-model="confirmReplace" type="checkbox" :disabled="disabled || working" /> Delete unreadable device storage, including identity and contacts</label>
|
<label><input v-model="confirmDelete" type="checkbox" :disabled="disabled || working" /> Delete unreadable device storage</label>
|
||||||
<button :disabled="disabled || working || !confirmReplace" @click="recover">Clear device storage</button>
|
<button :disabled="disabled || working || !confirmDelete" @click="recover">Clear device storage</button>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="error" role="alert" class="error">{{ error }}</p>
|
<p v-if="error" role="alert" class="error">{{ error }}</p>
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, watch } from 'vue';
|
||||||
|
const props = defineProps<{ name: string; disabled?: boolean }>();
|
||||||
|
const emit = defineEmits<{ rename: [name: string] }>();
|
||||||
|
const draft = ref(props.name), editing = ref(false);
|
||||||
|
watch(() => props.name, value => { if (!editing.value) draft.value = value; });
|
||||||
|
function save() {
|
||||||
|
editing.value = false;
|
||||||
|
const name = draft.value.trim();
|
||||||
|
draft.value = name || props.name;
|
||||||
|
if (name && name !== props.name) emit('rename', name);
|
||||||
|
}
|
||||||
|
function finish(event: KeyboardEvent) { (event.target as HTMLInputElement).blur(); }
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="editable-name">
|
||||||
|
<label class="sr-only" for="connection-name">Connection name</label>
|
||||||
|
<input id="connection-name" v-model="draft" :size="Math.max(5, Math.min(draft.length + 2, 24))" :disabled="disabled" maxlength="80" autocomplete="off" spellcheck="false"
|
||||||
|
aria-describedby="connection-name-hint" @focus="editing = true" @blur="save" @keydown.enter.prevent="finish" />
|
||||||
|
<span class="name-edit-icon" aria-hidden="true">✎</span>
|
||||||
|
<span id="connection-name-hint" class="sr-only">Edit the name. Changes save when you leave this field.</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -3,7 +3,7 @@ import type { IceOptions, NetworkSettings } from '../lib/webrtc.ts';
|
|||||||
import { STUN_PROVIDERS } from '../lib/webrtc.ts';
|
import { STUN_PROVIDERS } from '../lib/webrtc.ts';
|
||||||
const settings = defineModel<NetworkSettings>({ required: true });
|
const settings = defineModel<NetworkSettings>({ required: true });
|
||||||
defineProps<{ disabled?: boolean; managedCredentials?: IceOptions | null }>();
|
defineProps<{ disabled?: boolean; managedCredentials?: IceOptions | null }>();
|
||||||
const iceEndpoint = location.protocol === 'file:' ? '' : import.meta.env.VITE_ICE_ENDPOINT || '';
|
const iceEndpoint = import.meta.env.VITE_ICE_ENDPOINT || '';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import TransferPanel from './TransferPanel.vue';
|
|
||||||
</script>
|
|
||||||
<template><TransferPanel /></template>
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import TransferPanel from './TransferPanel.vue';
|
|
||||||
</script>
|
|
||||||
<template><TransferPanel sending /></template>
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
import { asError } from '../lib/validation.ts';
|
import { asError } from '../lib/validation.ts';
|
||||||
import type { Fingerprints, IceOptions, NetworkSettings as NetworkSettingsModel } from '../lib/webrtc.ts';
|
import type { Fingerprints, IceOptions, NetworkSettings as NetworkSettingsModel } from '../lib/webrtc.ts';
|
||||||
import type { FileMetadata, TransferState, FileDestination } from '../lib/transfer.ts';
|
import type { FileMetadata, TransferState, FileDestination } from '../lib/transfer.ts';
|
||||||
import { computed, onBeforeUnmount, ref, shallowRef, watch } from 'vue';
|
import { computed, onBeforeUnmount, ref, watch } from 'vue';
|
||||||
import DeviceSettings from './DeviceSettings.vue';
|
import DeviceSettings from './DeviceSettings.vue';
|
||||||
import { hello, signIdentity, verifyIdentity, type IdentityState, type IdentityHello, type IdentityContext } from '../lib/identity.ts';
|
import { hello, signIdentity, verifyIdentity, type IdentityState, type IdentityHello, type IdentityContext } from '../lib/identity.ts';
|
||||||
import NetworkSettings from './NetworkSettings.vue';
|
import NetworkSettings from './NetworkSettings.vue';
|
||||||
@@ -11,6 +11,7 @@ import { MEMORY_LIMIT, validateMetadata } from '../lib/transfer.ts';
|
|||||||
import { FileSession, QUEUE_LIMIT, type QueueItem } from '../lib/session.ts';
|
import { FileSession, QUEUE_LIMIT, type QueueItem } from '../lib/session.ts';
|
||||||
import { ConnectionDiagnostics } from '../lib/connection-diagnostics.ts';
|
import { ConnectionDiagnostics } from '../lib/connection-diagnostics.ts';
|
||||||
import { createDownloadDestination, supportsStreamingDownload } from '../lib/download.ts';
|
import { createDownloadDestination, supportsStreamingDownload } from '../lib/download.ts';
|
||||||
|
import type { ConnectionActivity, ConnectionUpdate, SavedConnection } from '../lib/connections.ts';
|
||||||
|
|
||||||
type Step = 'session-ready' | 'idle' | 'gathering' | 'offer-ready' | 'answer-ready' | TransferState;
|
type Step = 'session-ready' | 'idle' | 'gathering' | 'offer-ready' | 'answer-ready' | TransferState;
|
||||||
interface Session {
|
interface Session {
|
||||||
@@ -27,20 +28,12 @@ interface Session {
|
|||||||
timer?: ReturnType<typeof setTimeout>;
|
timer?: ReturnType<typeof setTimeout>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<{ sending?: boolean }>();
|
const props = defineProps<{ sending?: boolean; connection: SavedConnection; loadTrust: () => Promise<SavedConnection> }>();
|
||||||
const devices = ref<InstanceType<typeof DeviceSettings> | null>(null);
|
const devices = ref<InstanceType<typeof DeviceSettings> | null>(null);
|
||||||
const deviceState = shallowRef<IdentityState>({ identity: null, contacts: [] });
|
const identityStatus = ref('');
|
||||||
const identityStatus = ref(''), contactName = ref('');
|
// Offered on the verification step whenever the verified peer would change
|
||||||
const canRemember = ref(false), savingContact = ref(false);
|
// this connection's paired device: 'new' starts ticked, 'replace' does not.
|
||||||
function deviceChange(state: IdentityState) { deviceState.value = state; }
|
const pairing = ref<'' | 'new' | 'replace'>(''), rememberPeer = ref(false);
|
||||||
async function saveContact() {
|
|
||||||
const session = active;
|
|
||||||
if (!session?.remoteHello || !connected.value || !canRemember.value || savingContact.value) return;
|
|
||||||
savingContact.value = true;
|
|
||||||
try { await devices.value?.remember(session.remoteHello.key, contactName.value.trim()); canRemember.value = false; contactName.value = ''; }
|
|
||||||
catch (err) { error.value = asError(err).message; }
|
|
||||||
finally { savingContact.value = false; }
|
|
||||||
}
|
|
||||||
const file = ref<File | null>(null);
|
const file = ref<File | null>(null);
|
||||||
const selectedFiles = ref<File[]>([]);
|
const selectedFiles = ref<File[]>([]);
|
||||||
const queuedFiles = ref<QueueItem[]>([]);
|
const queuedFiles = ref<QueueItem[]>([]);
|
||||||
@@ -49,8 +42,7 @@ const receiveState = ref<TransferState | null>(null);
|
|||||||
const outgoing = ref<FileMetadata | null>(null);
|
const outgoing = ref<FileMetadata | null>(null);
|
||||||
const receiveProgress = ref(0);
|
const receiveProgress = ref(0);
|
||||||
const lastDirection = ref<'send' | 'receive'>('send');
|
const lastDirection = ref<'send' | 'receive'>('send');
|
||||||
const history = ref<string[]>([]);
|
const emit = defineEmits<{ sessionChange: [active: boolean]; connectedChange: [connected: boolean]; activity: [item: ConnectionActivity]; update: [change: ConnectionUpdate] }>();
|
||||||
const emit = defineEmits<{ sessionChange: [active: boolean]; connectedChange: [connected: boolean] }>();
|
|
||||||
const inputCode = ref('');
|
const inputCode = ref('');
|
||||||
const outputCode = ref('');
|
const outputCode = ref('');
|
||||||
const step = ref<Step>('idle');
|
const step = ref<Step>('idle');
|
||||||
@@ -77,8 +69,8 @@ const choosing = ref(false);
|
|||||||
const dragover = ref(false);
|
const dragover = ref(false);
|
||||||
const diagnosticLines = ref<string[]>([]);
|
const diagnosticLines = ref<string[]>([]);
|
||||||
let latestDiagnostics: ConnectionDiagnostics | null = null;
|
let latestDiagnostics: ConnectionDiagnostics | null = null;
|
||||||
const iceEndpoint = location.protocol === 'file:' ? '' : import.meta.env.VITE_ICE_ENDPOINT || '';
|
const iceEndpoint = import.meta.env.VITE_ICE_ENDPOINT || '';
|
||||||
const defaultStun = location.protocol === 'file:' ? '' : import.meta.env.VITE_STUN_URL || '';
|
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 settings = ref<NetworkSettingsModel>({ stunChoice: defaultStun ? 'custom' : 'pagequit', customStun: defaultStun, allowTurn: false, managedTurn: !!iceEndpoint, turnUrl: '', username: '', credential: '' });
|
||||||
const managedCredentials = ref<IceOptions | null>(null);
|
const managedCredentials = ref<IceOptions | null>(null);
|
||||||
const canSaveToDisk = typeof window.showSaveFilePicker === 'function';
|
const canSaveToDisk = typeof window.showSaveFilePicker === 'function';
|
||||||
@@ -110,6 +102,10 @@ function revokeDownload() {
|
|||||||
}
|
}
|
||||||
function dispose() {
|
function dispose() {
|
||||||
const old = active;
|
const old = active;
|
||||||
|
if (old) {
|
||||||
|
if (outgoing.value && sendState.value && !['done', 'closed'].includes(sendState.value)) { remember('send', outgoing.value, 'interrupted'); sendState.value = 'closed'; }
|
||||||
|
if (incoming.value && receiveState.value && !['done', 'closed'].includes(receiveState.value)) { remember('receive', incoming.value, 'interrupted'); receiveState.value = 'closed'; }
|
||||||
|
}
|
||||||
active = null; connected.value = false; queuedFiles.value = []; emit('sessionChange', false);
|
active = null; connected.value = false; queuedFiles.value = []; emit('sessionChange', false);
|
||||||
managedCredentials.value = null; settings.value.allowTurn = false;
|
managedCredentials.value = null; settings.value.allowTurn = false;
|
||||||
if (!old) return;
|
if (!old) return;
|
||||||
@@ -129,11 +125,11 @@ function reset(keepNetwork = false) {
|
|||||||
managedCredentials.value = null;
|
managedCredentials.value = null;
|
||||||
if (!keepNetwork) settings.value.allowTurn = false;
|
if (!keepNetwork) settings.value.allowTurn = false;
|
||||||
inputCode.value = outputCode.value = error.value = '';
|
inputCode.value = outputCode.value = error.value = '';
|
||||||
identityStatus.value = ''; canRemember.value = false; contactName.value = '';
|
identityStatus.value = ''; pairing.value = ''; rememberPeer.value = false;
|
||||||
fps.value = incoming.value = null;
|
fps.value = incoming.value = null;
|
||||||
verified.value = copied.value = choosing.value = false;
|
verified.value = copied.value = choosing.value = false;
|
||||||
progress.value = 0; receiveProgress.value = 0; step.value = 'idle'; streamedDownload.value = false;
|
progress.value = 0; receiveProgress.value = 0; step.value = 'idle'; streamedDownload.value = false;
|
||||||
sendState.value = receiveState.value = null; outgoing.value = null; history.value = [];
|
sendState.value = receiveState.value = null; outgoing.value = null;
|
||||||
}
|
}
|
||||||
function fail(session: Session, err: unknown) {
|
function fail(session: Session, err: unknown) {
|
||||||
if (active !== session) return;
|
if (active !== session) return;
|
||||||
@@ -165,7 +161,9 @@ function pickFiles(event: Event) {
|
|||||||
if (event.target instanceof HTMLInputElement) event.target.value = '';
|
if (event.target instanceof HTMLInputElement) event.target.value = '';
|
||||||
}
|
}
|
||||||
function removeQueued(id: number) { active?.transfer?.remove(id); }
|
function removeQueued(id: number) { active?.transfer?.remove(id); }
|
||||||
function remember(message: string) { history.value = [...history.value.slice(-49), message]; }
|
function remember(direction: ConnectionActivity['direction'], meta: FileMetadata, result: ConnectionActivity['result']) {
|
||||||
|
emit('activity', { id: crypto.randomUUID(), time: Date.now(), direction, name: meta.name, size: meta.size, result });
|
||||||
|
}
|
||||||
function disconnect() {
|
function disconnect() {
|
||||||
dispose(); step.value = 'closed';
|
dispose(); step.value = 'closed';
|
||||||
if (sendState.value && sendState.value !== 'done') sendState.value = 'closed';
|
if (sendState.value && sendState.value !== 'done') sendState.value = 'closed';
|
||||||
@@ -181,9 +179,12 @@ function attach(session: Session, channel: RTCDataChannel) {
|
|||||||
session.transfer = new FileSession(channel, !!props.sending, {
|
session.transfer = new FileSession(channel, !!props.sending, {
|
||||||
onReady: () => { if (active === session) {
|
onReady: () => { if (active === session) {
|
||||||
connected.value = true; step.value = 'session-ready'; clearTimeout(session.timer);
|
connected.value = true; step.value = 'session-ready'; clearTimeout(session.timer);
|
||||||
if (session.identityContext) {
|
// Ready implies both fresh proofs verified, so the key may now be saved.
|
||||||
identityStatus.value = session.expected === session.remoteHello?.key ? 'Remembered device authenticated for this connection.' : 'Device proof checked. You can remember this manually verified device.';
|
if (session.identityContext && session.remoteHello) {
|
||||||
canRemember.value = !deviceState.value.contacts.some(contact => contact.key === session.remoteHello?.key);
|
const key = session.remoteHello.key;
|
||||||
|
if (session.expected === key) identityStatus.value = 'Paired device authenticated for this connection.';
|
||||||
|
else if (rememberPeer.value) { emit('update', { peerKey: key }); identityStatus.value = `Device proof checked. Remembered for ${props.connection.name}.`; }
|
||||||
|
else identityStatus.value = 'Device proof checked. This device was not remembered.';
|
||||||
}
|
}
|
||||||
} },
|
} },
|
||||||
onQueue: items => { if (active === session) queuedFiles.value = items; },
|
onQueue: items => { if (active === session) queuedFiles.value = items; },
|
||||||
@@ -203,14 +204,14 @@ function attach(session: Session, channel: RTCDataChannel) {
|
|||||||
onComplete: (direction, { blob, meta }) => {
|
onComplete: (direction, { blob, meta }) => {
|
||||||
if (active !== session) return;
|
if (active !== session) return;
|
||||||
if (direction === 'send') progress.value = 100; else receiveProgress.value = 100;
|
if (direction === 'send') progress.value = 100; else receiveProgress.value = 100;
|
||||||
remember(`${direction === 'send' ? 'Sent' : 'Received'}: ${meta.name}`);
|
remember(direction, meta, 'complete');
|
||||||
void session.diagnostics.capture();
|
void session.diagnostics.capture();
|
||||||
if (blob) { revokeDownload(); downloadUrl.value = URL.createObjectURL(blob); downloadName.value = meta.name; }
|
if (blob) { revokeDownload(); downloadUrl.value = URL.createObjectURL(blob); downloadName.value = meta.name; }
|
||||||
},
|
},
|
||||||
onDecline: (direction, meta) => {
|
onDecline: (direction, meta) => {
|
||||||
if (active !== session) return;
|
if (active !== session) return;
|
||||||
if (direction === 'send') sendState.value = null; else { receiveState.value = null; incoming.value = null; }
|
if (direction === 'send') sendState.value = null; else { receiveState.value = null; incoming.value = null; }
|
||||||
remember(`Declined: ${meta.name}`);
|
remember(direction, meta, 'declined');
|
||||||
if (lastDirection.value === direction) {
|
if (lastDirection.value === direction) {
|
||||||
const other = direction === 'send' ? receiveState.value : sendState.value;
|
const other = direction === 'send' ? receiveState.value : sendState.value;
|
||||||
step.value = other && other !== 'done' ? other : 'session-ready';
|
step.value = other && other !== 'done' ? other : 'session-ready';
|
||||||
@@ -265,11 +266,13 @@ async function createCode() {
|
|||||||
}
|
}
|
||||||
session = start();
|
session = start();
|
||||||
// Re-read saved trust for each connection; another tab may have forgotten
|
// Re-read saved trust for each connection; another tab may have forgotten
|
||||||
// the expected peer or replaced the local identity since this page loaded.
|
// the paired peer or replaced the local identity since this page loaded.
|
||||||
const device = await devices.value?.refreshForConnection();
|
if (props.connection.rememberDevice) {
|
||||||
|
const trust = await props.loadTrust();
|
||||||
|
const identity = trust.rememberDevice ? await devices.value?.refreshIdentity() : null;
|
||||||
if (active !== session) return;
|
if (active !== session) return;
|
||||||
if (device?.identity) {
|
if (trust.rememberDevice) session.expected = trust.peerKey;
|
||||||
session.identity = device.identity; session.localHello = hello(device.identity); session.expected = device.expected;
|
if (identity) { session.identity = identity; session.localHello = hello(identity); }
|
||||||
}
|
}
|
||||||
const configured = await fetchTurnOptions(session.options, iceEndpoint, { signal: session.controller.signal });
|
const configured = await fetchTurnOptions(session.options, iceEndpoint, { signal: session.controller.signal });
|
||||||
if (active !== session) return;
|
if (active !== session) return;
|
||||||
@@ -284,7 +287,7 @@ async function createCode() {
|
|||||||
session.diagnostics.record(props.sending ? 'offer ready' : 'answer ready');
|
session.diagnostics.record(props.sending ? 'offer ready' : 'answer ready');
|
||||||
session.diagnostics.descriptions();
|
session.diagnostics.descriptions();
|
||||||
void session.diagnostics.capture();
|
void session.diagnostics.capture();
|
||||||
if (!props.sending) { fps.value = getFingerprints(session.pc, options); configureIdentity(session); }
|
if (!props.sending) { fps.value = getFingerprints(session.pc, options); offerPairing(session); configureIdentity(session); }
|
||||||
step.value = props.sending ? 'offer-ready' : 'answer-ready';
|
step.value = props.sending ? 'offer-ready' : 'answer-ready';
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (session) fail(session, err);
|
if (session) fail(session, err);
|
||||||
@@ -305,6 +308,7 @@ async function useAnswer() {
|
|||||||
session.diagnostics.descriptions();
|
session.diagnostics.descriptions();
|
||||||
void session.diagnostics.capture();
|
void session.diagnostics.capture();
|
||||||
fps.value = getFingerprints(session.pc, session.options);
|
fps.value = getFingerprints(session.pc, session.options);
|
||||||
|
offerPairing(session);
|
||||||
configureIdentity(session);
|
configureIdentity(session);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (active !== session) return;
|
if (active !== session) return;
|
||||||
@@ -316,11 +320,16 @@ async function useAnswer() {
|
|||||||
} else fail(session, err);
|
} else fail(session, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function offerPairing(session: Session) {
|
||||||
|
const key = session.localHello && session.remoteHello?.key;
|
||||||
|
pairing.value = !key || key === session.expected ? '' : session.expected ? 'replace' : 'new';
|
||||||
|
rememberPeer.value = pairing.value === 'new';
|
||||||
|
}
|
||||||
function configureIdentity(session: Session) {
|
function configureIdentity(session: Session) {
|
||||||
if (!fps.value || !session.transfer || session.identityContext) return;
|
if (!fps.value || !session.transfer || session.identityContext) return;
|
||||||
if (!session.identity || !session.localHello || !session.remoteHello) {
|
if (!session.identity || !session.localHello || !session.remoteHello) {
|
||||||
if (session.expected) identityStatus.value = 'Expected device identity is missing. Compare both fingerprints manually; saved trust is not being used.';
|
if (session.expected) identityStatus.value = 'A device identity is missing. Compare both fingerprints manually; the paired device is not being used.';
|
||||||
else if (session.localHello || session.remoteHello) identityStatus.value = 'Both people must enable device identity to remember each other. Compare fingerprints manually for this connection.';
|
else if (session.localHello || session.remoteHello) identityStatus.value = 'Both people must use their device identity to remember each other. Compare fingerprints manually for this connection.';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const initiator = !!props.sending;
|
const initiator = !!props.sending;
|
||||||
@@ -334,9 +343,9 @@ function configureIdentity(session: Session) {
|
|||||||
const identity = session.identity;
|
const identity = session.identity;
|
||||||
session.transfer.authenticate({ sign: () => signIdentity(identity, context, initiator), verify: proof => verifyIdentity(proof, context, !initiator) });
|
session.transfer.authenticate({ sign: () => signIdentity(identity, context, initiator), verify: proof => verifyIdentity(proof, context, !initiator) });
|
||||||
if (session.expected === session.remoteHello.key) {
|
if (session.expected === session.remoteHello.key) {
|
||||||
identityStatus.value = 'Checking the remembered device’s fresh proof…'; verify();
|
identityStatus.value = 'Checking the paired device’s fresh proof…'; verify();
|
||||||
} else {
|
} else {
|
||||||
identityStatus.value = session.expected ? 'Device identity differs from the expected contact. Compare both fingerprints manually before continuing. The saved contact will not be replaced.' : 'New device. Compare both fingerprints manually before remembering it.';
|
identityStatus.value = session.expected ? 'Device identity differs from the paired device. Compare both fingerprints manually before continuing. The paired device is only replaced if you choose to.' : 'New device. Compare both fingerprints manually before remembering it.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function verify() {
|
function verify() {
|
||||||
@@ -402,7 +411,7 @@ onBeforeUnmount(() => { dispose(); revokeDownload(); clearTimeout(copyTimer); })
|
|||||||
<h2 id="send-heading" class="step">Send files</h2>
|
<h2 id="send-heading" class="step">Send files</h2>
|
||||||
<label class="step" for="file-input">{{ connected ? 'Add files to send' : 'Choose files' }}</label>
|
<label class="step" for="file-input">{{ connected ? 'Add files to send' : 'Choose files' }}</label>
|
||||||
<div class="dropzone" :class="{ dragover }" @dragover.prevent="dragover = true" @dragleave="dragover = false" @drop.prevent="dragover = false; pickFiles($event)">
|
<div class="dropzone" :class="{ dragover }" @dragover.prevent="dragover = true" @dragleave="dragover = false" @drop.prevent="dragover = false; pickFiles($event)">
|
||||||
<p>Choose or drop files. Each direction sends one file at a time; both people can send on this connection.</p>
|
<p>Choose or drop files.</p>
|
||||||
<input id="file-input" type="file" multiple @change="pickFiles" />
|
<input id="file-input" type="file" multiple @change="pickFiles" />
|
||||||
</div>
|
</div>
|
||||||
<p v-if="!connected && selectedFiles.length" class="status">{{ selectedFiles.length }} file(s) selected</p>
|
<p v-if="!connected && selectedFiles.length" class="status">{{ selectedFiles.length }} file(s) selected</p>
|
||||||
@@ -411,9 +420,12 @@ onBeforeUnmount(() => { dispose(); revokeDownload(); clearTimeout(copyTimer); })
|
|||||||
<p v-if="outgoing" class="status">Sending: {{ outgoing.name }} — {{ stateLabel(sendState) }} ({{ progress }}%)</p>
|
<p v-if="outgoing" class="status">Sending: {{ outgoing.name }} — {{ stateLabel(sendState) }} ({{ progress }}%)</p>
|
||||||
<div v-if="outgoing" class="progress" role="progressbar" :aria-valuenow="progress" aria-valuemin="0" aria-valuemax="100" aria-label="Sending progress"><div :style="{ width: progress + '%' }"></div></div>
|
<div v-if="outgoing" class="progress" role="progressbar" :aria-valuenow="progress" aria-valuemin="0" aria-valuemax="100" aria-label="Sending progress"><div :style="{ width: progress + '%' }"></div></div>
|
||||||
</section>
|
</section>
|
||||||
<DeviceSettings ref="devices" :disabled="busy || connected || savingContact" @change="deviceChange" />
|
<DeviceSettings ref="devices" :paired="connection.peerKey" :remember="connection.rememberDevice" :disabled="busy || connected" @update="emit('update', $event)" />
|
||||||
|
<details class="network-details">
|
||||||
|
<summary>Network settings</summary>
|
||||||
<NetworkSettings v-model="settings" :disabled="busy || connected" :managed-credentials="managedCredentials" />
|
<NetworkSettings v-model="settings" :disabled="busy || connected" :managed-credentials="managedCredentials" />
|
||||||
<p class="status">Connection codes are not encrypted: they can reveal your IP address and connection details to anyone who sees them. Exchange them privately with your intended peer.</p>
|
</details>
|
||||||
|
<p v-if="!connected" class="status">Exchange codes privately. They contain your IP address and connection details.</p>
|
||||||
<template v-if="!sending">
|
<template v-if="!sending">
|
||||||
<label class="step" for="offer-input">Paste the sender’s connection code</label>
|
<label class="step" for="offer-input">Paste the sender’s connection code</label>
|
||||||
<textarea id="offer-input" v-model="inputCode" :maxlength="MAX_SIGNAL_LENGTH" :disabled="busy" />
|
<textarea id="offer-input" v-model="inputCode" :maxlength="MAX_SIGNAL_LENGTH" :disabled="busy" />
|
||||||
@@ -435,13 +447,9 @@ onBeforeUnmount(() => { dispose(); revokeDownload(); clearTimeout(copyTimer); })
|
|||||||
<div class="fp-row"><span>Your fingerprint</span><code>{{ fps.local }}</code></div>
|
<div class="fp-row"><span>Your fingerprint</span><code>{{ fps.local }}</code></div>
|
||||||
<div class="fp-row"><span>Their fingerprint</span><code>{{ fps.remote }}</code></div>
|
<div class="fp-row"><span>Their fingerprint</span><code>{{ fps.remote }}</code></div>
|
||||||
<p class="status">Compare every byte over an authenticated channel an attacker cannot alter (for example, an in-person comparison). Your fingerprint must match their “Their fingerprint”, and vice versa. If either differs, cancel. Both people must confirm before the filename or contents are sent.</p>
|
<p class="status">Compare every byte over an authenticated channel an attacker cannot alter (for example, an in-person comparison). Your fingerprint must match their “Their fingerprint”, and vice versa. If either differs, cancel. Both people must confirm before the filename or contents are sent.</p>
|
||||||
|
<label v-if="pairing"><input v-model="rememberPeer" type="checkbox" :disabled="verified" /> {{ pairing === 'new' ? `Remember this device for ${connection.name}` : `Replace the paired device of ${connection.name}` }}</label>
|
||||||
<button class="primary" :disabled="verified || step === 'done'" @click="verify">{{ verified ? 'Verification submitted' : 'Both fingerprints match — confirm' }}</button>
|
<button class="primary" :disabled="verified || step === 'done'" @click="verify">{{ verified ? 'Verification submitted' : 'Both fingerprints match — confirm' }}</button>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="connected && canRemember">
|
|
||||||
<label for="contact-name">Remember this device as</label>
|
|
||||||
<input id="contact-name" v-model="contactName" maxlength="80" />
|
|
||||||
<button :disabled="!contactName.trim() || savingContact" @click="saveContact">Remember device</button>
|
|
||||||
</div>
|
|
||||||
<section v-if="connected || incoming || downloadUrl" ref="receiveSection" class="transfer-section" tabindex="-1" aria-labelledby="receive-heading">
|
<section v-if="connected || incoming || downloadUrl" ref="receiveSection" class="transfer-section" tabindex="-1" aria-labelledby="receive-heading">
|
||||||
<h2 id="receive-heading" class="step">Receive files</h2>
|
<h2 id="receive-heading" class="step">Receive files</h2>
|
||||||
<p v-if="!incoming" class="status">Waiting for your peer to send a file. You can send files yourself using Send above.</p>
|
<p v-if="!incoming" class="status">Waiting for your peer to send a file. You can send files yourself using Send above.</p>
|
||||||
@@ -470,7 +478,6 @@ onBeforeUnmount(() => { dispose(); revokeDownload(); clearTimeout(copyTimer); })
|
|||||||
</details>
|
</details>
|
||||||
<p v-if="!connected && step === 'done'" class="status">Connection ended. Exchange fresh codes to send more files.</p>
|
<p v-if="!connected && step === 'done'" class="status">Connection ended. Exchange fresh codes to send more files.</p>
|
||||||
<p v-if="connected" class="status">Connection verified. Either person can add files. Keep both tabs open.</p>
|
<p v-if="connected" class="status">Connection verified. Either person can add files. Keep both tabs open.</p>
|
||||||
<ul v-if="history.length" aria-label="Recent file results"><li v-for="(entry, index) in history" :key="index">{{ entry }}</li></ul>
|
|
||||||
<button v-if="connected || busy" @click="disconnect">Disconnect</button>
|
<button v-if="connected || busy" @click="disconnect">Disconnect</button>
|
||||||
<button v-if="step !== 'idle'" @click="reset()">{{ busy ? 'Cancel connection' : 'Reset' }}</button>
|
<button v-if="step !== 'idle'" @click="reset()">{{ busy ? 'Cancel connection' : 'Reset' }}</button>
|
||||||
<p class="status">Before connecting, Send/Receive chooses who starts. Once connected, use either button to jump between sending and receiving without disconnecting. You can switch to your messenger to copy and paste codes; keep this page open until receipt is confirmed.</p>
|
<p class="status">Before connecting, Send/Receive chooses who starts. Once connected, use either button to jump between sending and receiving without disconnecting. You can switch to your messenger to copy and paste codes; keep this page open until receipt is confirmed.</p>
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
import { isRecord } from './validation.ts';
|
||||||
|
|
||||||
|
export const CONNECTION_LIMIT = 100;
|
||||||
|
export const HISTORY_LIMIT = 50;
|
||||||
|
export interface ConnectionActivity {
|
||||||
|
id: string;
|
||||||
|
time: number;
|
||||||
|
direction: 'send' | 'receive';
|
||||||
|
name: string;
|
||||||
|
size: number;
|
||||||
|
result: 'complete' | 'declined' | 'interrupted';
|
||||||
|
}
|
||||||
|
export interface SavedConnection {
|
||||||
|
id: string;
|
||||||
|
number: number;
|
||||||
|
name: string;
|
||||||
|
// The peer this connection trusts. Only set after mutual verification.
|
||||||
|
peerKey: string;
|
||||||
|
// Per-connection opt-in to include this browser's identity in codes.
|
||||||
|
rememberDevice: boolean;
|
||||||
|
history: ConnectionActivity[];
|
||||||
|
}
|
||||||
|
export type ConnectionUpdate = { name: string } | { peerKey: string } | { rememberDevice: boolean } | { activity: ConnectionActivity };
|
||||||
|
export function connectionName(value: string) {
|
||||||
|
const name = value.trim();
|
||||||
|
if (!name || name.length > 80) throw new Error('Use a connection name between 1 and 80 characters.');
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
export function updateConnection(current: SavedConnection, update: ConnectionUpdate): SavedConnection {
|
||||||
|
if ('name' in update) return { ...current, name: connectionName(update.name) };
|
||||||
|
if ('peerKey' in update) {
|
||||||
|
if (update.peerKey && !/^04[0-9a-f]{128}$/.test(update.peerKey)) throw new Error('Invalid paired device.');
|
||||||
|
return { ...current, peerKey: update.peerKey };
|
||||||
|
}
|
||||||
|
if ('rememberDevice' in update) return { ...current, rememberDevice: update.rememberDevice === true };
|
||||||
|
const item = update.activity;
|
||||||
|
if (typeof item.id !== 'string' || !item.id || !Number.isSafeInteger(item.time) || item.time < 0 || item.time > 8640000000000000 ||
|
||||||
|
typeof item.name !== 'string' || !item.name || item.name.length > 255 ||
|
||||||
|
!Number.isSafeInteger(item.size) || item.size < 0 || !['send', 'receive'].includes(item.direction) ||
|
||||||
|
!['complete', 'declined', 'interrupted'].includes(item.result)) throw new Error('Invalid connection activity.');
|
||||||
|
return { ...current, history: [...current.history.filter(previous => previous.id !== item.id), item].sort((a, b) => a.time - b.time).slice(-HISTORY_LIMIT) };
|
||||||
|
}
|
||||||
|
export function emptyConnection(number = 1): SavedConnection {
|
||||||
|
return { id: crypto.randomUUID(), number, name: `Con ${number}`, peerKey: '', rememberDevice: false, history: [] };
|
||||||
|
}
|
||||||
|
function validateConnection(value: unknown): SavedConnection {
|
||||||
|
if (!isRecord(value) || typeof value.id !== 'string' || !value.id || !Number.isSafeInteger(value.number) || (value.number as number) < 1 ||
|
||||||
|
typeof value.name !== 'string' || typeof value.peerKey !== 'string' || !Array.isArray(value.history) || value.history.length > HISTORY_LIMIT) throw new Error('Saved connections are unreadable.');
|
||||||
|
let record: SavedConnection = { id: value.id, number: value.number as number, name: connectionName(value.name), peerKey: '', rememberDevice: value.rememberDevice === true, history: [] };
|
||||||
|
record = updateConnection(record, { peerKey: value.peerKey });
|
||||||
|
for (const item of value.history) {
|
||||||
|
if (!isRecord(item)) throw new Error('Saved activity is unreadable.');
|
||||||
|
record = updateConnection(record, { activity: item as unknown as ConnectionActivity });
|
||||||
|
}
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
async function database() {
|
||||||
|
return new Promise<IDBDatabase>((resolve, reject) => {
|
||||||
|
const request = indexedDB.open('hellcon-connections', 1);
|
||||||
|
request.onupgradeneeded = () => request.result.createObjectStore('connections', { keyPath: 'id' });
|
||||||
|
request.onsuccess = () => { request.result.onversionchange = () => request.result.close(); resolve(request.result); };
|
||||||
|
request.onerror = () => reject(new Error('Connection storage is unavailable.'));
|
||||||
|
request.onblocked = () => reject(new Error('Close other HellCon tabs to open connection storage.'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Read and write within one transaction so other tabs cannot overwrite a rename,
|
||||||
|
// paired device, or history entry with a stale copy of the entire record.
|
||||||
|
async function change(action: (records: SavedConnection[], store: IDBObjectStore) => void) {
|
||||||
|
const db = await database();
|
||||||
|
try {
|
||||||
|
return await new Promise<SavedConnection[]>((resolve, reject) => {
|
||||||
|
const tx = db.transaction('connections', 'readwrite'), store = tx.objectStore('connections');
|
||||||
|
let records: SavedConnection[] = [], failure: unknown;
|
||||||
|
const read = store.getAll();
|
||||||
|
read.onsuccess = () => {
|
||||||
|
try {
|
||||||
|
records = read.result.map(validateConnection).sort((a, b) => a.number - b.number);
|
||||||
|
action(records, store);
|
||||||
|
} catch (error) { failure = error; tx.abort(); }
|
||||||
|
};
|
||||||
|
tx.oncomplete = () => resolve(records);
|
||||||
|
tx.onabort = tx.onerror = () => reject(failure || new Error('Could not save connections.'));
|
||||||
|
});
|
||||||
|
} finally { db.close(); }
|
||||||
|
}
|
||||||
|
export function loadConnections() {
|
||||||
|
return change((records, store) => {
|
||||||
|
if (!records.length) { const first = emptyConnection(); store.add(first); records.push(first); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export async function addConnection() {
|
||||||
|
const records = await change((records, store) => {
|
||||||
|
if (records.length >= CONNECTION_LIMIT) throw new Error(`Keep up to ${CONNECTION_LIMIT} connections.`);
|
||||||
|
const record = emptyConnection(Math.max(0, ...records.map(item => item.number)) + 1);
|
||||||
|
store.add(record); records.push(record);
|
||||||
|
});
|
||||||
|
return records;
|
||||||
|
}
|
||||||
|
export function saveConnection(id: string, update: ConnectionUpdate) {
|
||||||
|
return change((records, store) => {
|
||||||
|
const index = records.findIndex(item => item.id === id);
|
||||||
|
if (index < 0) throw new Error('This connection is no longer saved. Reload the page.');
|
||||||
|
const record = updateConnection(records[index]!, update);
|
||||||
|
store.put(record); records[index] = record;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export function removeConnection(id: string) {
|
||||||
|
return change((records, store) => {
|
||||||
|
const index = records.findIndex(item => item.id === id);
|
||||||
|
if (index >= 0) { store.delete(id); records.splice(index, 1); }
|
||||||
|
if (!records.length) { const first = emptyConnection(); store.add(first); records.push(first); }
|
||||||
|
});
|
||||||
|
}
|
||||||
+7
-50
@@ -2,8 +2,7 @@ import { isRecord } from './validation.ts';
|
|||||||
|
|
||||||
export interface Identity { publicKey: string; privateKey: CryptoKey }
|
export interface Identity { publicKey: string; privateKey: CryptoKey }
|
||||||
export interface IdentityHello { key: string; nonce: string }
|
export interface IdentityHello { key: string; nonce: string }
|
||||||
export interface Contact { key: string; name: string }
|
export interface IdentityState { revision?: string; identity: Identity | null }
|
||||||
export interface IdentityState { revision?: string; identity: Identity | null; contacts: Contact[] }
|
|
||||||
export interface IdentityContext { offer: IdentityHello; answer: IdentityHello; offerFingerprint: string; answerFingerprint: string }
|
export interface IdentityContext { offer: IdentityHello; answer: IdentityHello; offerFingerprint: string; answerFingerprint: string }
|
||||||
const curve = { name: 'ECDSA', namedCurve: 'P-256' };
|
const curve = { name: 'ECDSA', namedCurve: 'P-256' };
|
||||||
const signing = { name: 'ECDSA', hash: 'SHA-256' };
|
const signing = { name: 'ECDSA', hash: 'SHA-256' };
|
||||||
@@ -20,9 +19,9 @@ export function parseHello(value: unknown): IdentityHello {
|
|||||||
return { key: value.key as string, nonce: value.nonce as string };
|
return { key: value.key as string, nonce: value.nonce as string };
|
||||||
}
|
}
|
||||||
export async function createIdentity(): Promise<Identity> {
|
export async function createIdentity(): Promise<Identity> {
|
||||||
// Extractable for explicit password-encrypted backups. Stored as a CryptoKey,
|
// Store the private key as a non-extractable CryptoKey. Same-origin JavaScript
|
||||||
// never plaintext JSON. Same-origin JavaScript can still use/export this key.
|
// can still use it to sign, so the app code must remain trusted.
|
||||||
const pair = await crypto.subtle.generateKey(curve, true, ['sign', 'verify']);
|
const pair = await crypto.subtle.generateKey(curve, false, ['sign', 'verify']);
|
||||||
return { publicKey: hex(await crypto.subtle.exportKey('raw', pair.publicKey)), privateKey: pair.privateKey };
|
return { publicKey: hex(await crypto.subtle.exportKey('raw', pair.publicKey)), privateKey: pair.privateKey };
|
||||||
}
|
}
|
||||||
export function hello(identity: Identity): IdentityHello {
|
export function hello(identity: Identity): IdentityHello {
|
||||||
@@ -42,17 +41,6 @@ export async function verifyIdentity(proof: unknown, context: IdentityContext, i
|
|||||||
const key = await crypto.subtle.importKey('raw', unhex((initiator ? context.offer : context.answer).key, 65), curve, false, ['verify']);
|
const key = await crypto.subtle.importKey('raw', unhex((initiator ? context.offer : context.answer).key, 65), curve, false, ['verify']);
|
||||||
if (!await crypto.subtle.verify(signing, key, unhex(proof, 64), transcript(context, initiator))) throw new Error('Device proof failed. Disconnect and verify fresh codes.');
|
if (!await crypto.subtle.verify(signing, key, unhex(proof, 64), transcript(context, initiator))) throw new Error('Device proof failed. Disconnect and verify fresh codes.');
|
||||||
}
|
}
|
||||||
export function validateContacts(value: unknown): Contact[] {
|
|
||||||
if (!Array.isArray(value) || value.length > 100) throw new Error('Invalid contact list.');
|
|
||||||
const keys = new Set<string>();
|
|
||||||
return value.map(item => {
|
|
||||||
if (!isRecord(item) || typeof item.name !== 'string' || !item.name.trim() || item.name.length > 80) throw new Error('Invalid contact name.');
|
|
||||||
unhex(item.key, 65);
|
|
||||||
const key = item.key as string;
|
|
||||||
if (keys.has(key)) throw new Error('Duplicate contact identity.');
|
|
||||||
keys.add(key); return { key, name: item.name.trim() };
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function database() {
|
async function database() {
|
||||||
return new Promise<IDBDatabase>((resolve, reject) => {
|
return new Promise<IDBDatabase>((resolve, reject) => {
|
||||||
@@ -71,17 +59,15 @@ export async function loadIdentityState(): Promise<IdentityState> {
|
|||||||
const request = tx.objectStore('settings').get('state');
|
const request = tx.objectStore('settings').get('state');
|
||||||
tx.oncomplete = () => resolve(request.result); tx.onabort = tx.onerror = () => reject(new Error('Could not read device storage.'));
|
tx.oncomplete = () => resolve(request.result); tx.onabort = tx.onerror = () => reject(new Error('Could not read device storage.'));
|
||||||
});
|
});
|
||||||
if (!state) return { identity: null, contacts: [] };
|
if (!state) return { identity: null };
|
||||||
validateContacts(state.contacts);
|
|
||||||
if (state.identity) {
|
if (state.identity) {
|
||||||
unhex(state.identity.publicKey, 65);
|
unhex(state.identity.publicKey, 65);
|
||||||
if (!(state.identity.privateKey instanceof CryptoKey) || state.identity.privateKey.type !== 'private') throw new Error('Stored identity is invalid. Reset it or restore a backup.');
|
if (!(state.identity.privateKey instanceof CryptoKey) || state.identity.privateKey.type !== 'private') throw new Error('Stored identity is invalid. Clear device storage and create a new identity.');
|
||||||
}
|
}
|
||||||
return state;
|
return { revision: state.revision, identity: state.identity ?? null };
|
||||||
} finally { db.close(); }
|
} finally { db.close(); }
|
||||||
}
|
}
|
||||||
export async function saveIdentityState(state: IdentityState, expectedRevision = state.revision): Promise<IdentityState> {
|
export async function saveIdentityState(state: IdentityState, expectedRevision = state.revision): Promise<IdentityState> {
|
||||||
validateContacts(state.contacts);
|
|
||||||
const db = await database();
|
const db = await database();
|
||||||
const next = { ...state, revision: crypto.randomUUID() };
|
const next = { ...state, revision: crypto.randomUUID() };
|
||||||
try {
|
try {
|
||||||
@@ -110,32 +96,3 @@ export async function clearIdentityStorage() {
|
|||||||
});
|
});
|
||||||
} finally { db.close(); }
|
} finally { db.close(); }
|
||||||
}
|
}
|
||||||
const iterations = 600000;
|
|
||||||
async function backupKey(password: string, salt: Uint8Array<ArrayBuffer>) {
|
|
||||||
if (password.length < 12 || password.length > 1024) throw new Error('Use a backup password between 12 and 1024 characters.');
|
|
||||||
const material = await crypto.subtle.importKey('raw', bytes(password), 'PBKDF2', false, ['deriveKey']);
|
|
||||||
return crypto.subtle.deriveKey({ name: 'PBKDF2', hash: 'SHA-256', salt, iterations }, material, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
|
|
||||||
}
|
|
||||||
export async function exportBackup(state: IdentityState, password: string) {
|
|
||||||
if (!state.identity) throw new Error('Create a device identity first.');
|
|
||||||
const salt = crypto.getRandomValues(new Uint8Array(16)), iv = crypto.getRandomValues(new Uint8Array(12));
|
|
||||||
const data = bytes(JSON.stringify({ key: await crypto.subtle.exportKey('jwk', state.identity.privateKey), publicKey: state.identity.publicKey, contacts: validateContacts(state.contacts) }));
|
|
||||||
const encrypted = await crypto.subtle.encrypt({ name: 'AES-GCM', iv, additionalData: bytes('HellCon backup v1') }, await backupKey(password, salt), data);
|
|
||||||
return JSON.stringify({ format: 'hellcon-identity', version: 1, iterations, salt: hex(salt), iv: hex(iv), data: hex(encrypted) });
|
|
||||||
}
|
|
||||||
export async function importBackup(text: string, password: string): Promise<IdentityState> {
|
|
||||||
if (text.length > 100000) throw new Error('Backup is too large.');
|
|
||||||
try {
|
|
||||||
const value: unknown = JSON.parse(text);
|
|
||||||
if (!isRecord(value) || value.format !== 'hellcon-identity' || value.version !== 1 || value.iterations !== iterations || typeof value.data !== 'string' || value.data.length < 32) throw new Error();
|
|
||||||
const decrypted = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: unhex(value.iv, 12), additionalData: bytes('HellCon backup v1') }, await backupKey(password, unhex(value.salt, 16)), unhex(value.data, value.data.length / 2));
|
|
||||||
const payload: unknown = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(decrypted));
|
|
||||||
if (!isRecord(payload) || !isRecord(payload.key)) throw new Error();
|
|
||||||
const publicKey = payload.publicKey as string;
|
|
||||||
const pub = await crypto.subtle.importKey('raw', unhex(publicKey, 65), curve, false, ['verify']);
|
|
||||||
const privateKey = await crypto.subtle.importKey('jwk', payload.key, curve, true, ['sign']);
|
|
||||||
const challenge = crypto.getRandomValues(new Uint8Array(32));
|
|
||||||
if (!await crypto.subtle.verify(signing, pub, await crypto.subtle.sign(signing, privateKey, challenge), challenge)) throw new Error();
|
|
||||||
return { identity: { publicKey, privateKey }, contacts: validateContacts(payload.contacts) };
|
|
||||||
} catch { throw new Error('Could not restore backup. Check the password and backup file.'); }
|
|
||||||
}
|
|
||||||
+132
-41
@@ -6,7 +6,7 @@
|
|||||||
--accent: #ff9b3d;
|
--accent: #ff9b3d;
|
||||||
--accent-soft: rgba(255, 155, 61, 0.15);
|
--accent-soft: rgba(255, 155, 61, 0.15);
|
||||||
--text: #e8eaf0;
|
--text: #e8eaf0;
|
||||||
--muted: #8b91a3;
|
--muted: #a0a7b8;
|
||||||
}
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
@@ -20,27 +20,14 @@ body {
|
|||||||
font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
|
font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
#app {
|
#app { height: 100dvh; min-height: 420px; }
|
||||||
min-height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
padding-inline: 0.9rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
main {
|
|
||||||
width: 100%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.skip-link {
|
.skip-link {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0.9rem;
|
left: 0.9rem;
|
||||||
top: 0.5rem;
|
top: 0.5rem;
|
||||||
transform: translateY(-200%);
|
transform: translateY(-200%);
|
||||||
z-index: 1;
|
z-index: 10;
|
||||||
padding: 0.55rem 0.8rem;
|
padding: 0.55rem 0.8rem;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background: var(--accent);
|
background: var(--accent);
|
||||||
@@ -54,18 +41,17 @@ main {
|
|||||||
|
|
||||||
.panel {
|
.panel {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 680px;
|
|
||||||
background: var(--panel);
|
background: var(--panel);
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
padding: 1.5rem;
|
padding: 1.25rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 0.9rem;
|
gap: 0.9rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
margin: 2rem 0 0.25rem;
|
margin: 0;
|
||||||
font-family: ui-monospace, 'Cascadia Code', monospace;
|
font-family: ui-monospace, 'Cascadia Code', monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,18 +61,11 @@ h1 {
|
|||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.app-download {
|
|
||||||
color: var(--accent);
|
|
||||||
margin: -0.5rem 0 1.5rem;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tabs {
|
.tabs {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 680px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.tabs button {
|
.tabs button {
|
||||||
@@ -236,20 +215,6 @@ a.download {
|
|||||||
margin: 0.2rem 0 0;
|
margin: 0.2rem 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
footer {
|
|
||||||
max-width: 680px;
|
|
||||||
width: 100%;
|
|
||||||
margin: 1.5rem 0 2.5rem;
|
|
||||||
padding: 0 0.25rem;
|
|
||||||
color: var(--muted);
|
|
||||||
font-size: 0.78rem;
|
|
||||||
line-height: 1.55;
|
|
||||||
}
|
|
||||||
|
|
||||||
footer p {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stun-select,
|
.stun-select,
|
||||||
.stun-input {
|
.stun-input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -296,4 +261,130 @@ p.stun-hint {
|
|||||||
.transfer-section:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: 4px; }
|
.transfer-section:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: 4px; }
|
||||||
|
|
||||||
.device-settings { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; border: 1px solid var(--border); border-radius: 8px; }
|
.device-settings { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; border: 1px solid var(--border); border-radius: 8px; }
|
||||||
.device-settings input:not([type=checkbox]), .device-settings select, #contact-name { box-sizing: border-box; max-width: 100%; padding: 0.6rem; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
|
.device-settings input:not([type=checkbox]) { box-sizing: border-box; max-width: 100%; padding: 0.6rem; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
|
||||||
|
|
||||||
|
/* The connection shell stays in place while each workspace scrolls. */
|
||||||
|
.app-shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); height: 100%; }
|
||||||
|
.sidebar { display: flex; flex-direction: column; gap: 1.25rem; background: #13161e; border-right: 1px solid var(--border); padding: 1.6rem 1rem 1rem; min-height: 0; overflow-y: auto; }
|
||||||
|
.brand { display: flex; align-items: center; gap: 0.8rem; padding: 0 0.5rem 1.25rem; }
|
||||||
|
.brand img { object-fit: contain; }
|
||||||
|
.brand-name { display: block; font-family: ui-monospace, monospace; font-weight: 700; font-size: 1.45rem; letter-spacing: -0.05em; }
|
||||||
|
.brand p { font-size: 0.75rem; color: var(--muted); margin: 0.25rem 0 0; }
|
||||||
|
.sidebar-section-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 0.65rem; }
|
||||||
|
.sidebar-section-heading h2, .eyebrow { text-transform: uppercase; font-size: 0.68rem; letter-spacing: 0.12em; color: var(--muted); margin: 0; font-weight: 650; }
|
||||||
|
.sidebar-section-heading > span { font-size: 0.72rem; color: var(--muted); }
|
||||||
|
.connection-nav { display: flex; flex-direction: column; gap: 0.35rem; }
|
||||||
|
.connection-link { display: flex; align-items: center; gap: 0.7rem; width: 100%; text-align: left; background: transparent; border: 1px solid transparent; padding: 0.75rem 0.6rem; border-radius: 9px; }
|
||||||
|
.connection-link.selected { background: var(--accent-soft); border-color: #65472e; }
|
||||||
|
.connection-avatar { flex: 0 0 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: #252a36; font-size: 0.88rem; color: var(--muted); }
|
||||||
|
.selected .connection-avatar { color: var(--accent); background: #473022; }
|
||||||
|
.connection-label { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; flex: 1; }
|
||||||
|
.connection-name { font-size: 0.87rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
|
.connection-preview { font-size: 0.72rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
|
.connection-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #7c8495; flex-shrink: 0; }
|
||||||
|
.connection-dot.connected { background: #69d6a4; }
|
||||||
|
.connection-dot.connecting { background: var(--accent); }
|
||||||
|
.add-connection { display: flex; align-items: center; justify-content: center; gap: 0.5rem; font-size: 0.82rem; background: transparent; border-style: dashed; }
|
||||||
|
.add-connection > span { font-size: 1.1rem; }
|
||||||
|
.sidebar-footer { margin-top: auto; padding: 1.5rem 0.65rem 0.25rem; color: var(--muted); font-size: 0.72rem; line-height: 1.65; }
|
||||||
|
.sidebar-tag { font-weight: 600; color: var(--text); }
|
||||||
|
.sidebar-footer p { margin: 0.5rem 0 1rem; }
|
||||||
|
summary { cursor: pointer; color: var(--muted); font-size: 0.83rem; padding: 0.4rem 0; }
|
||||||
|
summary:hover { color: var(--text); }
|
||||||
|
summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
|
||||||
|
.privacy-details summary { font-size: 0.72rem; }
|
||||||
|
.main-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
|
||||||
|
.connection-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 80px; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); background: #141720; }
|
||||||
|
.connection-title { min-width: 0; flex: 1; }
|
||||||
|
.title-line { display: flex; align-items: center; gap: 1rem; margin-top: 0.4rem; }
|
||||||
|
.title-line h1 { margin: 0; font-size: 1.35rem; font-weight: 600; font-family: inherit; overflow-wrap: anywhere; }
|
||||||
|
.header-action { font-size: 0.72rem; padding: 0.3rem 0.5rem; color: var(--muted); background: transparent; border-color: transparent; }
|
||||||
|
.header-action-icon { margin-right: 0.15rem; opacity: 0.65; }
|
||||||
|
.header-action:hover:not(:disabled), .header-action:focus-visible { color: #ff9185; }
|
||||||
|
.header-action:hover:not(:disabled) .header-action-icon, .header-action:focus-visible .header-action-icon { opacity: 1; }
|
||||||
|
.session-badge { display: inline-flex; align-items: center; gap: 0.45rem; color: var(--muted); font-size: 0.74rem; white-space: nowrap; border: 1px solid var(--border); border-radius: 20px; padding: 0.45rem 0.7rem; }
|
||||||
|
.session-badge.connected { color: #8ddbb6; border-color: #315344; }
|
||||||
|
.workspace-scroll { flex: 1; overflow-y: auto; padding: 2rem 2.25rem; }
|
||||||
|
.connection-workspace { display: grid; grid-template-columns: minmax(0, 720px) minmax(240px, 320px); gap: 2rem; max-width: 1200px; margin-inline: auto; align-items: start; }
|
||||||
|
.session-column { min-width: 0; }
|
||||||
|
.workspace-intro { margin-bottom: 1.4rem; }
|
||||||
|
.workspace-intro h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 0.4rem; }
|
||||||
|
.workspace-intro p { font-size: 0.85rem; color: var(--muted); line-height: 1.6; margin: 0; }
|
||||||
|
.tabs { width: fit-content; padding: 4px; gap: 4px; background: #1b1f2a; border: 1px solid var(--border); border-radius: 10px; }
|
||||||
|
.tabs button { padding: 0.45rem 1.5rem; font-size: 0.85rem; border: none; background: transparent; }
|
||||||
|
.tabs button.active { background: #3e3025; color: #ffb575; }
|
||||||
|
.panel { box-shadow: 0 6px 28px #00000012; }
|
||||||
|
.panel > .status { line-height: 1.6; margin: 0.1rem 0; }
|
||||||
|
.panel > button { align-self: start; font-size: 0.88rem; }
|
||||||
|
.dropzone { padding: 1.35rem 1rem; background: #141720; border-color: #414858; }
|
||||||
|
.dropzone p { font-size: 0.85rem; line-height: 1.65; margin: 0 0 1rem; }
|
||||||
|
input[type=file] { max-width: 100%; font-size: 0.8rem; }
|
||||||
|
input[type=file]::file-selector-button { border: 1px solid #505667; border-radius: 6px; padding: 0.45rem 0.65rem; margin-right: 0.6rem; background: #242a36; color: var(--text); cursor: pointer; }
|
||||||
|
.network-details > fieldset { margin-top: 0.65rem; }
|
||||||
|
.activity-panel { min-width: 0; border-left: 1px solid var(--border); padding-left: 1.5rem; }
|
||||||
|
.activity-heading { display: flex; align-items: center; gap: 0.6rem; }
|
||||||
|
.activity-heading h2 { font-size: 0.9rem; font-weight: 600; margin: 0; }
|
||||||
|
.activity-heading > span { font-size: 0.68rem; color: var(--muted); border-radius: 5px; padding: 0.15rem 0.35rem; background: #242936; }
|
||||||
|
.empty-activity { padding: 3.5rem 0.25rem; text-align: center; }
|
||||||
|
.empty-activity-icon { font-size: 1.6rem; display: grid; place-items: center; margin: 0 auto 1rem; width: 54px; height: 54px; border-radius: 16px; border: 1px solid var(--border); color: var(--muted); }
|
||||||
|
.empty-activity h3 { font-size: 0.88rem; font-weight: 500; margin: 0 0 0.6rem; }
|
||||||
|
.empty-activity p { font-size: 0.8rem; line-height: 1.7; color: var(--muted); }
|
||||||
|
p.activity-note { font-size: 0.7rem; color: var(--muted); line-height: 1.6; }
|
||||||
|
.empty-activity .activity-note { margin-top: 1.5rem; }
|
||||||
|
.activity-list { list-style: none; padding: 0; margin: 1.25rem 0; }
|
||||||
|
.activity-item { display: flex; gap: 0.7rem; padding: 1rem 0; border-bottom: 1px solid var(--border); font-size: 0.78rem; }
|
||||||
|
.activity-item > div { min-width: 0; }
|
||||||
|
.activity-icon { color: var(--accent); padding-top: 0.1rem; font-size: 1rem; }
|
||||||
|
.activity-filename { margin: 0; overflow-wrap: anywhere; font-weight: 500; }
|
||||||
|
.activity-meta, .activity-result { color: var(--muted); margin: 0.4rem 0; font-size: 0.72rem; }
|
||||||
|
.activity-item time { font-size: 0.68rem; color: var(--muted); }
|
||||||
|
.storage-error { color: #ffb4a9; background: #422725; border: 1px solid #8e5147; border-radius: 8px; padding: 1rem; font-size: 0.85rem; line-height: 1.6; }
|
||||||
|
.sidebar-toggle { display: none; }
|
||||||
|
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
|
||||||
|
@media (max-width: 1150px) {
|
||||||
|
.app-shell { grid-template-columns: 230px minmax(0, 1fr); }
|
||||||
|
.connection-workspace { grid-template-columns: minmax(0, 1fr); gap: 2rem; }
|
||||||
|
.activity-panel { border-left: 0; border-top: 1px solid var(--border); padding: 1.5rem 0 0; }
|
||||||
|
.empty-activity { padding: 1.5rem 0; }
|
||||||
|
.connection-header { padding-inline: 1.5rem; }
|
||||||
|
.workspace-scroll { padding: 1.5rem; }
|
||||||
|
}
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
#app { height: auto; min-height: 100dvh; }
|
||||||
|
.app-shell { display: flex; flex-direction: column; min-height: 100dvh; }
|
||||||
|
.sidebar { display: none; border-right: 0; border-bottom: 1px solid var(--border); max-height: 60dvh; }
|
||||||
|
.sidebar-open .sidebar { display: flex; }
|
||||||
|
.brand { padding-bottom: 0; }
|
||||||
|
.sidebar-footer { padding-top: 0; }
|
||||||
|
.connection-header { flex-wrap: wrap; padding: 1rem; min-height: 0; gap: 0.75rem; }
|
||||||
|
.sidebar-toggle { display: block; flex-basis: 100%; font-size: 0.8rem; text-align: left; background: transparent; padding: 0.5rem; }
|
||||||
|
.workspace-scroll { padding: 1.25rem 1rem; overflow: visible; }
|
||||||
|
.title-line { gap: 0.4rem; }
|
||||||
|
.title-line h1 { font-size: 1.15rem; }
|
||||||
|
.panel { padding: 1rem; }
|
||||||
|
.session-badge { font-size: 0.65rem; padding: 0.35rem 0.5rem; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.title-line { flex-wrap: wrap; column-gap: 0.6rem; }
|
||||||
|
|
||||||
|
.editable-name { display: inline-flex; position: relative; max-width: min(100%, 26rem); min-width: 0; }
|
||||||
|
.editable-name input { width: 100%; min-width: 0; max-width: 100%; border: 1px solid transparent; border-radius: 7px; padding: 0.12rem 1.65rem 0.12rem 0.4rem; margin-left: -0.4rem; font: inherit; font-size: 1.35rem; font-weight: 600; color: var(--text); background: #ffffff03; text-overflow: ellipsis; transition: border-color 120ms, background 120ms; }
|
||||||
|
.editable-name input:hover { border-color: var(--border); background: #ffffff06; }
|
||||||
|
.editable-name input:focus { border-color: var(--accent); outline: none; background: var(--bg); }
|
||||||
|
.name-edit-icon { position: absolute; right: 0.65rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 0.9rem; pointer-events: none; opacity: 0.65; }
|
||||||
|
.editable-name:focus-within .name-edit-icon { color: var(--accent); opacity: 1; }
|
||||||
|
.app-dialog { width: min(460px, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); margin: auto; padding: 1.5rem; border: 1px solid #414858; border-radius: 14px; color: var(--text); background: var(--panel); box-shadow: 0 24px 100px #0009; overflow-y: auto; }
|
||||||
|
.app-dialog::backdrop { background: #080b12b8; backdrop-filter: blur(4px); }
|
||||||
|
.dialog-header { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
|
||||||
|
.dialog-header h2 { margin: 0; font-size: 1.15rem; font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
|
||||||
|
.dialog-close { flex-shrink: 0; border-color: transparent; background: transparent; color: var(--muted); padding: 0 0.4rem; font-size: 1.4rem; line-height: 1.2; }
|
||||||
|
.dialog-body { color: var(--muted); font-size: 0.88rem; line-height: 1.7; margin-block: 1rem 1.5rem; }
|
||||||
|
.dialog-body p { margin: 0.75rem 0; }
|
||||||
|
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.6rem; }
|
||||||
|
.dialog-actions button { font-size: 0.85rem; }
|
||||||
|
button.danger { border-color: #b84d42; background: #672f2b; color: #ffe3df; }
|
||||||
|
button.danger:hover:not(:disabled) { border-color: #ff9185; background: #813b34; }
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
.editable-name input { font-size: 1.15rem; }
|
||||||
|
.app-dialog { padding: 1.2rem; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import test from 'node:test';
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { emptyConnection, updateConnection, HISTORY_LIMIT, type ConnectionActivity } from '../src/lib/connections.ts';
|
||||||
|
|
||||||
|
test('renaming and pairing preserve a slot identity and its activity', () => {
|
||||||
|
const initial = emptyConnection(2);
|
||||||
|
const activity: ConnectionActivity = { id: 'transfer', time: 1, direction: 'send', name: 'example.txt', size: 123, result: 'complete' };
|
||||||
|
const withHistory = updateConnection(initial, { activity });
|
||||||
|
const renamed = updateConnection(withHistory, { name: ' Work laptop ' });
|
||||||
|
const remembering = updateConnection(renamed, { rememberDevice: true });
|
||||||
|
const paired = updateConnection(remembering, { peerKey: '04' + 'a'.repeat(128) });
|
||||||
|
assert.equal(initial.name, 'Con 2');
|
||||||
|
assert.equal(initial.rememberDevice, false);
|
||||||
|
assert.equal(paired.rememberDevice, true);
|
||||||
|
assert.equal(updateConnection(paired, { peerKey: '' }).rememberDevice, true, 'Forgetting a device keeps the opt-in');
|
||||||
|
assert.equal(paired.id, initial.id);
|
||||||
|
assert.equal(paired.name, 'Work laptop');
|
||||||
|
assert.deepEqual(paired.history, [activity]);
|
||||||
|
assert.equal(initial.history.length, 0);
|
||||||
|
assert.throws(() => updateConnection(paired, { name: ' ' }));
|
||||||
|
assert.throws(() => updateConnection(paired, { name: 'a'.repeat(81) }));
|
||||||
|
assert.throws(() => updateConnection(paired, { peerKey: 'invalid' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('history is bounded, ordered, and does not duplicate an event', () => {
|
||||||
|
let connection = emptyConnection();
|
||||||
|
for (let i = 0; i < HISTORY_LIMIT + 10; i++) {
|
||||||
|
connection = updateConnection(connection, { activity: { id: String(i), time: i, direction: 'receive', name: 'file', size: 0, result: 'declined' } });
|
||||||
|
}
|
||||||
|
const last = connection.history.at(-1)!;
|
||||||
|
connection = updateConnection(connection, { activity: last });
|
||||||
|
assert.equal(connection.history.length, HISTORY_LIMIT);
|
||||||
|
assert.equal(connection.history[0]!.time, 10);
|
||||||
|
assert.throws(() => updateConnection(connection, { activity: { ...last, size: -1 } }));
|
||||||
|
assert.throws(() => updateConnection(connection, { activity: { ...last, direction: 'invalid' as 'send' } }));
|
||||||
|
});
|
||||||
+8
-21
@@ -1,6 +1,6 @@
|
|||||||
import test from 'node:test';
|
import test from 'node:test';
|
||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { createIdentity, hello, signIdentity, verifyIdentity, exportBackup, importBackup, parseHello, validateContacts, type IdentityContext } from '../src/lib/identity.ts';
|
import { createIdentity, hello, signIdentity, verifyIdentity, parseHello, type IdentityContext } from '../src/lib/identity.ts';
|
||||||
const fingerprint = (byte: string) => Array(32).fill(byte).join(' ');
|
const fingerprint = (byte: string) => Array(32).fill(byte).join(' ');
|
||||||
async function setup() {
|
async function setup() {
|
||||||
const first = await createIdentity(), second = await createIdentity();
|
const first = await createIdentity(), second = await createIdentity();
|
||||||
@@ -22,28 +22,15 @@ test('device proof binds both keys, fresh nonces, roles, and both DTLS fingerpri
|
|||||||
await assert.rejects(signIdentity(imposter, context, true));
|
await assert.rejects(signIdentity(imposter, context, true));
|
||||||
await assert.rejects(verifyIdentity('00'.repeat(64), context, true));
|
await assert.rejects(verifyIdentity('00'.repeat(64), context, true));
|
||||||
});
|
});
|
||||||
test('identity input is bounded and contacts cannot supply duplicate identities', async () => {
|
test('identity input is bounded', async () => {
|
||||||
const identity = await createIdentity();
|
const identity = await createIdentity();
|
||||||
assert.throws(() => parseHello({ key: identity.publicKey, nonce: 'bad' }));
|
assert.throws(() => parseHello({ key: identity.publicKey, nonce: 'bad' }));
|
||||||
assert.throws(() => parseHello({ key: 'ff'.repeat(65), nonce: '00'.repeat(32) }));
|
assert.throws(() => parseHello({ key: 'ff'.repeat(65), nonce: '00'.repeat(32) }));
|
||||||
assert.throws(() => validateContacts([{ key: identity.publicKey, name: ' ' }]));
|
|
||||||
assert.throws(() => validateContacts(Array(101).fill({ key: identity.publicKey, name: 'friend' })));
|
|
||||||
assert.throws(() => validateContacts(Array(2).fill({ key: identity.publicKey, name: 'friend' })));
|
|
||||||
});
|
});
|
||||||
test('encrypted backup restores signing identity and contacts; wrong password and tampering fail', async () => {
|
test('device private keys cannot be extracted and still sign after storage cloning', async () => {
|
||||||
const { first, second, context } = await setup();
|
const { first, context } = await setup();
|
||||||
const state = { identity: first, contacts: [{ key: second.publicKey, name: 'Other device' }] };
|
const stored = structuredClone(first);
|
||||||
const password = 'a long private backup passphrase';
|
assert.equal(stored.privateKey.extractable, false);
|
||||||
const backup = await exportBackup(state, password);
|
await assert.rejects(crypto.subtle.exportKey('jwk', stored.privateKey));
|
||||||
assert.doesNotMatch(backup, /Other device|privateKey/);
|
await verifyIdentity(await signIdentity(stored, context, true), context, true);
|
||||||
const restored = await importBackup(backup, password);
|
|
||||||
assert.deepEqual(restored.contacts, state.contacts);
|
|
||||||
assert.equal(restored.identity!.publicKey, first.publicKey);
|
|
||||||
await verifyIdentity(await signIdentity(restored.identity!, context, true), context, true);
|
|
||||||
await assert.rejects(importBackup(backup, 'the incorrect password'));
|
|
||||||
const damaged = JSON.parse(backup); damaged.data = (damaged.data.startsWith('00') ? 'ff' : '00') + damaged.data.slice(2);
|
|
||||||
await assert.rejects(importBackup(JSON.stringify(damaged), password));
|
|
||||||
damaged.iterations = 1; await assert.rejects(importBackup(JSON.stringify(damaged), password));
|
|
||||||
await assert.rejects(importBackup('x'.repeat(100001), password));
|
|
||||||
await assert.rejects(exportBackup(state, 'short'));
|
|
||||||
});
|
});
|
||||||
@@ -7,7 +7,6 @@ export default defineConfig(({ mode }) => {
|
|||||||
const env = { ...loadEnv(mode, process.cwd(), ''), ...process.env };
|
const env = { ...loadEnv(mode, process.cwd(), ''), ...process.env };
|
||||||
return {
|
return {
|
||||||
base: './',
|
base: './',
|
||||||
build: { rollupOptions: { output: { format: 'iife' } } },
|
|
||||||
server: { host: '127.0.0.1' },
|
server: { host: '127.0.0.1' },
|
||||||
plugins: [vue(), {
|
plugins: [vue(), {
|
||||||
name: 'local-turn-credentials',
|
name: 'local-turn-credentials',
|
||||||
|
|||||||
Reference in new issue
Block a user