@johnhenry/wsh 0.36.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +345 -11
- package/package.json +5 -1
- package/src/bridge-seal.mjs +77 -0
- package/src/channel-binding.mjs +124 -0
- package/src/client.mjs +348 -40
- package/src/e2e-exchange.mjs +51 -1
- package/src/forward-node.mjs +118 -0
- package/src/gateway-channel.mjs +250 -0
- package/src/gateway-client.mjs +252 -0
- package/src/host.d.ts +3 -3
- package/src/index.d.ts +114 -0
- package/src/index.mjs +13 -0
- package/src/memory-host.d.ts +17 -3
- package/src/memory-host.mjs +31 -7
- package/src/messages.gen.mjs +59 -7
- package/src/operator-proof.mjs +135 -0
- package/src/pipe-relay.d.ts +49 -0
- package/src/pipe-relay.mjs +274 -0
- package/src/reverse-host.d.ts +2 -2
- package/src/reverse-host.mjs +126 -15
- package/src/server/address-guard.mjs +164 -0
- package/src/server/client-env.mjs +60 -0
- package/src/server/connection.mjs +65 -12
- package/src/server/gateway-core.mjs +188 -0
- package/src/server/gateway.mjs +483 -80
- package/src/server/index.d.ts +97 -5
- package/src/server/index.mjs +23 -2
- package/src/server/pty.mjs +1 -0
- package/src/server/relay.mjs +45 -2
- package/src/server/unix-policy.mjs +120 -0
- package/src/server/webtransport.mjs +2 -0
- package/src/transport-ws.mjs +16 -0
- package/src/transport.mjs +11 -0
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ Or via CDN:
|
|
|
66
66
|
- **MCP bridge** -- discover and invoke remote MCP tools through the control channel
|
|
67
67
|
- **Session recording** -- own JSON schema (asciicast-v2-shaped, not a playable asciicast file -- see note below) recording and playback with seek/pause/resume
|
|
68
68
|
- **Key management** -- IndexedDB storage with OPFS encrypted backup (PBKDF2 + AES-256-GCM)
|
|
69
|
-
- **
|
|
69
|
+
- **105 message types** -- handshake, channel, gateway, guest sharing, compression negotiation, copilot, policy, authorized-key management, and more
|
|
70
70
|
|
|
71
71
|
> **Session recording is asciicast-v2-shaped, but not an asciicast file.**
|
|
72
72
|
> The JS `SessionRecorder.toJSON()` export borrows asciicast v2's vocabulary --
|
|
@@ -229,12 +229,100 @@ restricted host with no shell. `fs.root` confines every path: `..`, absolute
|
|
|
229
229
|
paths and symlinks pointing out of it are refused -- for `write` and `rename`
|
|
230
230
|
(both paths) exactly as for `read`.
|
|
231
231
|
|
|
232
|
+
**Client environment (`clientEnv`).** A client may ask for environment
|
|
233
|
+
variables with `openSession({ env })`. Since 0.36 the host accepts only
|
|
234
|
+
`TERM`, `COLORTERM`, `LANG`, `LANGUAGE` and `LC_*` by default (the shape of
|
|
235
|
+
sshd's `AcceptEnv`); `PATH`, `LD_PRELOAD`, `BASH_ENV` and the like are dropped,
|
|
236
|
+
because they change what a shell or a restricted runner executes. Set
|
|
237
|
+
`exec: { clientEnv: true }` to accept everything (the old behaviour),
|
|
238
|
+
`false` for nothing, a list (`['TERM', 'LC_*', 'MY_APP_TOKEN']`, replacing the
|
|
239
|
+
default list) or a predicate `(name, value) => boolean`; `pty: { clientEnv }`
|
|
240
|
+
takes the same. At most 64 variables of at most 4096 bytes with plain names
|
|
241
|
+
are looked at. **This is a breaking default** for a host that relied on clients
|
|
242
|
+
setting arbitrary variables.
|
|
243
|
+
|
|
244
|
+
**Connection lifetime (`connectionTtlMs`).** `AuthOk` carries a `token` and a
|
|
245
|
+
`ttl`. The token is an opaque per-connection value that nothing accepts back
|
|
246
|
+
(session resume uses its own per-session token); it stays on the wire because
|
|
247
|
+
released clients require the field. `ttl` is now true: `connectionTtlMs: n`
|
|
248
|
+
ends every authenticated connection `n` ms after login and advertises it
|
|
249
|
+
(`client.authTtl`, whole seconds, rounded up); without it the host promises no
|
|
250
|
+
limit and sends `ttl: 0`. Before 0.36 it sent an unenforced 3600. The Rust
|
|
251
|
+
`wsh-server` still sends its `session_ttl` setting unenforced.
|
|
252
|
+
|
|
232
253
|
### Gateway (TCP and DNS egress from the host)
|
|
233
254
|
|
|
234
|
-
`gateway: { allow: ['broker.lan:1883'], socks: '127.0.0.1:9050' }` makes the Node server
|
|
235
|
-
client (a browser tab via netway's `GatewayBackend`) can open TCP
|
|
236
|
-
deny; `allow` takes `"*"`, `"host"` or `"host:port"`. `socks` routes
|
|
237
|
-
unresolved.
|
|
255
|
+
`gateway: { allow: ['broker.lan:1883'], allowPrivate: ['10.0.0.0/8'], socks: '127.0.0.1:9050' }` makes the Node server
|
|
256
|
+
answer the gateway opcodes, so a client (a browser tab via netway's `GatewayBackend`, or `client.openTcp()`) can open TCP
|
|
257
|
+
connections and resolve names from the host. Default deny; `allow` takes `"*"`, `"host"` or `"host:port"`. `socks` routes
|
|
258
|
+
every dial through a SOCKS5 proxy (Tor) with the name unresolved. TCP reverse tunnels are refused. `OpenUdp` is served
|
|
259
|
+
(`client.openUdp(host, port)`: one chunk is one datagram, same destination policy, idle flows closed after `udpIdleMs`,
|
|
260
|
+
default 60 s, not available through `socks`), but over the reliable control stream: it is ordered and retransmitted, and a
|
|
261
|
+
datagram the client cannot take fast enough is dropped by the host. **WebTransport datagrams (the real UDP semantics) are
|
|
262
|
+
not implemented yet (#124).**
|
|
263
|
+
|
|
264
|
+
**The address is checked, not just the name.** The host resolves a name once, refuses every resolved address that is not
|
|
265
|
+
globally routable (loopback, private, link-local, CGNAT, ULA, multicast, reserved, and IPv4 addresses wrapped as
|
|
266
|
+
IPv4-mapped, NAT64 or 6to4 IPv6), and connects to the address it checked, so a name that resolves to something else a
|
|
267
|
+
moment later cannot redirect the connection. Reaching private space is an explicit rule: `allowPrivate` (CIDR blocks or
|
|
268
|
+
addresses) for names and `"*"`, or an `allow` entry that is itself an IP literal (`"127.0.0.1:1883"`), which permits
|
|
269
|
+
exactly that address. `ResolveDns` answers are filtered with the same rule. Through `socks` the proxy resolves the name,
|
|
270
|
+
so only IP literals can be checked there. See the Security model below and the CHANGELOG (this is a behaviour change).
|
|
271
|
+
|
|
272
|
+
**Flow control.** Gateway data is metered in both directions when both ends offer the `gateway-credit` feature: each
|
|
273
|
+
direction of each connection starts with 256 KiB of credit that the receiver tops up (`GatewayCredit`) as its
|
|
274
|
+
application consumes data, so a slow reader stops its peer (the origin socket is paused, `write()` results and `drain`
|
|
275
|
+
are honoured) instead of making the host buffer. Against a peer without the feature the host still holds the origin back
|
|
276
|
+
by the transport's own backpressure and bounds what a client can make it hold with `maxBufferedBytes` (default 4 MiB per
|
|
277
|
+
connection) and `maxClientBufferedBytes` (default 32 MiB per client), closing a connection that exceeds them.
|
|
278
|
+
|
|
279
|
+
#### Unix-domain sockets (streamlocal) and named endpoints
|
|
280
|
+
|
|
281
|
+
Modelled on OpenSSH's streamlocal forwarding. Off unless configured:
|
|
282
|
+
|
|
283
|
+
```js
|
|
284
|
+
createWshServer({ auth, gateway: {
|
|
285
|
+
allow: [],
|
|
286
|
+
unix: {
|
|
287
|
+
connect: ['/var/run/docker.sock'], // OpenUnix: a client may connect to these (exact path, or "/dir/" prefix, or "@abstract")
|
|
288
|
+
listen: ['/run/user/1000/wsh/'], // ListenUnix: a client may ask the host to create sockets under here
|
|
289
|
+
replaceStale: false, // a client may replace a STALE socket file only if it asks AND this is true
|
|
290
|
+
},
|
|
291
|
+
endpoints: { ping: async (duplex, who) => { /* ... */ } }, // named virtual endpoints, below
|
|
292
|
+
} });
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Paths are checked after `realpath` of the parent directory (so `/var/run` and `/private/var/run` agree and a symlinked
|
|
296
|
+
directory cannot lead out of an allowed one), a `..` segment is refused, and the file must be a socket and not a symlink.
|
|
297
|
+
The abstract namespace (`@name`) is refused unless listed. Sockets the host creates are mode `0600` (the umask is
|
|
298
|
+
tightened while binding) and are unlinked when the listener closes or the connection ends; an existing socket file is
|
|
299
|
+
replaced only when the request says `replace` AND `replaceStale` is on AND nothing accepts connections on it, and a file
|
|
300
|
+
that is not a socket is never touched. Allow only directories no other local user can write to: the check cannot close
|
|
301
|
+
the instant between it and the connect.
|
|
302
|
+
|
|
303
|
+
```js
|
|
304
|
+
const duplex = await client.openUnix('/var/run/docker.sock'); // web streams with backpressure
|
|
305
|
+
await duplex.writable.getWriter().write(new TextEncoder().encode('GET /containers/json HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n'));
|
|
306
|
+
// Node: ssh -L / -R shapes, unix and TCP ends mixed
|
|
307
|
+
await client.forwardUnix({ local: '127.0.0.1:2375', remote: '/var/run/docker.sock' }); // -L 127.0.0.1:2375:/var/run/docker.sock
|
|
308
|
+
await client.forwardUnix({ local: '/tmp/docker.sock', remote: '/var/run/docker.sock' });
|
|
309
|
+
await client.forwardUnix({ reverse: true, remote: '/run/user/1000/wsh/app.sock', local: '127.0.0.1:8080' }); // -R
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
**Named virtual endpoints** are for a host with no file system (the memory host, a browser tab):
|
|
313
|
+
`endpoints: { docker: (duplex, who) => ... }` registers handlers and a client reaches one with `client.openEndpoint('docker')`.
|
|
314
|
+
It is its own message (`OpenEndpoint { name }`) rather than a reserved `OpenUnix` path so that a name can never be
|
|
315
|
+
mistaken for (or smuggled as) a file-system path or an abstract-namespace name, and so a host's file-system policy is not
|
|
316
|
+
consulted for it; the registered names are an allow-list by construction. `who` is the authenticated
|
|
317
|
+
`{ username, fingerprint }`, so the embedder can authorise per call (throw to refuse, or `{ open, authorize(who) }`).
|
|
318
|
+
|
|
319
|
+
**Rust side: JS only for now.** `wsh-server` does not advertise `gateway-unix`, `gateway-endpoints` or `gateway-credit`,
|
|
320
|
+
and `wsh` has no `-L` / `-R` with unix sockets yet. What it must implement: `OpenUnix { gateway_id, path }` and
|
|
321
|
+
`ListenUnix { listener_id, path, replace? }` (answer with the existing `GatewayOk`/`GatewayFail` and `ListenOk` with
|
|
322
|
+
`actual_port: 0`/`ListenFail`; accepted connections announced with `InboundOpen` and answered by `InboundAccept`'s
|
|
323
|
+
`gateway_id`), the same path policy and `0600`/unlink rules, `GatewayCredit` (256 KiB initial credit per direction when
|
|
324
|
+
the client's `Hello.features` lists `gateway-credit`), and in the CLI `-L [bind:]port:/remote.sock`,
|
|
325
|
+
`-L /local.sock:/remote.sock`, `-R /remote.sock:host:port` and `-R /remote.sock:/local.sock`.
|
|
238
326
|
|
|
239
327
|
### TLS (`wss://`) and host extensions
|
|
240
328
|
|
|
@@ -280,7 +368,9 @@ session.onData = (d) => console.log(new TextDecoder().decode(d)); // "ran hi"
|
|
|
280
368
|
It is the real connection handler speaking QMux over an in-memory socket pair, so the client code you test is the code
|
|
281
369
|
you ship. `host.createClient()` / `host.WebSocket` / `host.accept(socket)` / `createSocketPair()` are the lower-level pieces.
|
|
282
370
|
Supported: `auth`, `exec` (a function; there is no shell), `pty`, `fs` and `hostKey` (injected, below), `mcp`,
|
|
283
|
-
`extensions`, `rpc
|
|
371
|
+
`extensions`, `rpc`, `sessions` (below) and `endpoints` ([named virtual endpoints](#unix-domain-sockets-streamlocal-and-named-endpoints):
|
|
372
|
+
`endpoints: { api: (duplex, who) => ... }`, reached with `client.openEndpoint('api')`, with flow control). Not available
|
|
373
|
+
in memory: the TCP, DNS, UDP and unix-socket parts of `gateway`, `relay`, WebTransport, `exec: true` and
|
|
284
374
|
`fs: { root }` (they need Node) and the `wsh-host` / `wsh-fs` rpc built-ins (use `@johnhenry/wsh/server`).
|
|
285
375
|
|
|
286
376
|
**Injected backends**, shaped like the Node host's, so a page can be a real host (#114):
|
|
@@ -607,6 +697,101 @@ const s = await client.openSession({ type: 'exec', command: 'echo hello' });
|
|
|
607
697
|
there): against such a relay or operator, set `reportFeatures: false` on the
|
|
608
698
|
host (and use `ReverseAccept` without the field in your own peers).
|
|
609
699
|
|
|
700
|
+
#### Operator proof and sealed bridges (#117)
|
|
701
|
+
|
|
702
|
+
Out of the box the relay tells the host who the operator is (`from_fingerprint`,
|
|
703
|
+
set from the operator's login at the relay) and the host's `accept` trusts it:
|
|
704
|
+
fine for a relay you run, not for a shared one. Two opt-ins close that, and both
|
|
705
|
+
are negotiated by feature strings so every released peer keeps working
|
|
706
|
+
(the Rust relay never lists `operator-proof`, so the operator simply does not
|
|
707
|
+
offer it there):
|
|
708
|
+
|
|
709
|
+
```js
|
|
710
|
+
// host: do not take the operator's identity from the relay.
|
|
711
|
+
createReverseHost({ url, username, keyPair, exec: true,
|
|
712
|
+
requireOperatorProof: true,
|
|
713
|
+
accept: ({ fingerprint, username, proven, publicKey }) => fingerprint === aliceFingerprint });
|
|
714
|
+
// operator: prove yourself, and seal the bridge (nothing naming a command is sent before the key exists).
|
|
715
|
+
await client.reverseConnect(hostFingerprint, 10_000, { sealed: true, requirePeerProof: true });
|
|
716
|
+
```
|
|
717
|
+
|
|
718
|
+
1. **Operator proof.** After `ReverseConnect` the host sends a signed
|
|
719
|
+
`ReverseChallenge` (its key, the operator fingerprint it saw, a nonce it chose and a
|
|
720
|
+
session id); the operator checks the host's signature, that the key is the host it asked for and that
|
|
721
|
+
the host saw the operator's *own* fingerprint (so a relay that rewrote `from_fingerprint` shows
|
|
722
|
+
up here), and answers with a `ReverseProof`: an Ed25519 signature over the host's key, its own key, the
|
|
723
|
+
username it claims, and the host's nonce and session id. The host verifies it **before `accept` runs**, takes
|
|
724
|
+
the identity from the proof and refuses when it differs from what the relay asserted. `accept` receives
|
|
725
|
+
`{ fingerprint, username, proven, publicKey }`; by default the proof is requested whenever the relay
|
|
726
|
+
and operator can do it and merely *reported* (`proven`).
|
|
727
|
+
2. **Sealed bridge.** A proof is a point in time, and a relay can stamp any
|
|
728
|
+
`from_fingerprint` on a plain message afterwards (an injected `Open`), so a host with
|
|
729
|
+
`requireOperatorProof` also requires the bridge to be sealed: the operator opens it with a
|
|
730
|
+
`KeyExchange` that **both** sides sign (the operator's half covers the session id, algorithm, its
|
|
731
|
+
ephemeral key and the host's identity; the host's reply covers both ephemeral keys), hybrid
|
|
732
|
+
X25519+ML-KEM-768 by default, and from then on every message that would cross the relay (`Open`, `OpenOk`,
|
|
733
|
+
`SessionData`, `FileOp`, `McpCall` ...) travels as an `EncryptedFrame` on channel 0 with a strict counter.
|
|
734
|
+
The host acts on nothing else. The only plaintext before the key exists is the key exchange itself (ephemeral
|
|
735
|
+
public keys, signatures); before this change `Open` -- the command, the environment, the working size --
|
|
736
|
+
and `OpenOk` with its resume token crossed the relay in the clear until a per-session `initiateE2E`.
|
|
737
|
+
|
|
738
|
+
What a relay can and cannot do, with and without these (a relay always sees who connects to whom, when, and how
|
|
739
|
+
many bytes):
|
|
740
|
+
|
|
741
|
+
| The relay can ... | Plain bridge (default) | + operator proof | + `requireOperatorProof` (sealed) |
|
|
742
|
+
|---|---|---|---|
|
|
743
|
+
| read commands, output, files, MCP calls | yes, until a per-session `initiateE2E` | yes | **no** (ciphertext; metadata and sizes only) |
|
|
744
|
+
| make the host think an operator it chose is connecting | yes (it stamps `from_fingerprint`) | **no**: the host verifies the operator's own signature before `accept` | no |
|
|
745
|
+
| replay an old operator's login to the host | n/a | **no**: the nonce is the host's, single use, signed over the host's key and the session | no |
|
|
746
|
+
| swap the operator's key or the host's ephemeral key | n/a | no (signature does not verify) | no (both halves are signed) |
|
|
747
|
+
| inject an `Open` / `SessionData` stamped as the operator | **yes** | **yes** (a proof is a point in time) | **no** (plain messages are dropped) |
|
|
748
|
+
| replay or reorder a sealed frame | n/a | n/a | **no** (strict counter and role tag) |
|
|
749
|
+
| drop, delay or truncate traffic, or end the bridge | yes | yes | yes (a denial of service is always open to a relay) |
|
|
750
|
+
| tell the host the operator is *absent* when it is present (`ReverseClose`) | yes | yes | yes |
|
|
751
|
+
| learn the operator's and host's keys, usernames, and the sizes and timing of traffic | yes | yes | yes |
|
|
752
|
+
|
|
753
|
+
Not covered: an operator or host that skips the checks (the options are opt-in on both
|
|
754
|
+
sides; a host that does not require proof is exactly as exposed as before), the Rust `wsh-server` relay and
|
|
755
|
+
`wsh` client (they neither carry nor send these messages), and a compromised *operator* key (it proves the key, not the
|
|
756
|
+
person). A relay can still refuse service by dropping the challenge.
|
|
757
|
+
|
|
758
|
+
#### A pipe relay (`@johnhenry/wsh/pipe-relay`, #118)
|
|
759
|
+
|
|
760
|
+
When you do not want the relay to be a party at all, use a pipe: the host dials the relay, the operator dials the
|
|
761
|
+
relay, the relay matches them by an unguessable rendezvous id and copies bytes. **There is no relay-asserted identity**:
|
|
762
|
+
the host runs the ordinary handshake and verifies the operator's own signature (`authorize`, `authorizedKeys`,
|
|
763
|
+
channel binding, ...) exactly as on a direct connection, and the operator can pin the host key.
|
|
764
|
+
|
|
765
|
+
```js
|
|
766
|
+
import { createPipeRelay, newRendezvousId, pipeUrl } from '@johnhenry/wsh/pipe-relay';
|
|
767
|
+
const relay = createPipeRelay({ idleTimeoutMs: 300_000, maxWaiting: 1024 });
|
|
768
|
+
const { port } = await relay.listen({ port: 8443 }); // or relay.accept(socket, { id, role }) from your own HTTP server
|
|
769
|
+
|
|
770
|
+
const id = newRendezvousId(); // 128 bits; hand it to both sides out of band
|
|
771
|
+
// host (behind NAT): dial out, wait for the socket to open, serve it like any accepted connection
|
|
772
|
+
const ws = new WebSocket(pipeUrl('wss://relay.example', id, 'host'));
|
|
773
|
+
await new Promise((r) => ws.addEventListener('open', r, { once: true }));
|
|
774
|
+
await server.accept(ws); // createWshServer / createMemoryHost
|
|
775
|
+
// operator: the stock client, any URL form
|
|
776
|
+
await client.connect(pipeUrl('wss://relay.example', id), { username, keyPair, expectHostKey });
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
The module imports nothing that can execute code or read files (a test walks its module graph); it does not parse wsh.
|
|
780
|
+
Bounds, all with defaults: `maxWaiting`, `rendezvousTimeoutMs`, `idleTimeoutMs`, `maxLifetimeMs`, `maxBytes`,
|
|
781
|
+
`maxMessageBytes`, `earlyBytes`, `highWaterBytes` (a receiver that is not draining pauses the sender; a socket that
|
|
782
|
+
cannot pause is closed). **Trust difference:** relay mode has the relay vouch for the operator; a pipe relay vouches
|
|
783
|
+
for nothing, and the rendezvous id is the only thing standing between the host's socket and whoever dials first --
|
|
784
|
+
an impostor that reaches the id first is still a stranger to the operator, who must pin the host key
|
|
785
|
+
(`expectHostKey`) to notice; and the host still authenticates every operator. A pipe relay terminates the TLS of each leg, so what it copies -- the wsh
|
|
786
|
+
handshake and the session traffic -- is readable by it unless the two ends seal it themselves
|
|
787
|
+
(per-session `initiateE2E`); it cannot forge the operator's signature or the host's. It can drop, delay or
|
|
788
|
+
cut a connection, and it sees who dials which id and how much they send.
|
|
789
|
+
|
|
790
|
+
*CLI side (not built here).* The Rust `wsh` client always dials `wss://<host>/` (#136), so it cannot dial
|
|
791
|
+
`/r/<id>` yet. It needs either `wsh --via wss://relay/r/<id> user@host`, or to keep the URL path and query it is
|
|
792
|
+
given; the JS client already does. The host side is any process that can open a WebSocket to `pipeUrl(..., 'host')`
|
|
793
|
+
and hand it to `accept`.
|
|
794
|
+
|
|
610
795
|
### Sessions: attach / resume / detach
|
|
611
796
|
|
|
612
797
|
By default a pty/exec session dies with the connection that opened it. Pass
|
|
@@ -800,6 +985,41 @@ client.onHostKey = (hk) => confirm(`Trust ${hk.fingerprint}?`); // or per call
|
|
|
800
985
|
ServerHello and then read or alter the rest. Pinning keeps you from talking
|
|
801
986
|
to the wrong host; confidentiality still needs `wss://` or a link you trust.
|
|
802
987
|
|
|
988
|
+
### Channel binding (tie the login to the connection)
|
|
989
|
+
|
|
990
|
+
A host key proves who the host is; it does not stop an intermediary from
|
|
991
|
+
passing a genuine challenge through to the host and getting your login
|
|
992
|
+
signature back. With binding, the signature also covers what the two ends of
|
|
993
|
+
*this* connection share, so a relayed signature is worthless to the host:
|
|
994
|
+
|
|
995
|
+
```js
|
|
996
|
+
// host: accept a key login only when it is bound (requires hostKey for `host`; wss served by this process for `tls-exporter`)
|
|
997
|
+
createWshServer({ auth, hostKey: { file }, requireChannelBinding: true }); // or ['host', 'tls-exporter']
|
|
998
|
+
// client: refuse to sign a login that cannot be bound
|
|
999
|
+
await client.connect(url, { username, keyPair, requireChannelBinding: true });
|
|
1000
|
+
client.channelBinding; // ['host'] -- which kinds this login's signature covered
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
| Kind | Bound to | Who can supply it |
|
|
1004
|
+
|---|---|---|
|
|
1005
|
+
| `host` | the Ed25519 host key that proved possession in `ServerHello` | a host with `hostKey`; any client that checked the proof (so a relay presenting its own key binds to *its* key) |
|
|
1006
|
+
| `cert-hash` | the SHA-256 of the pinned WebTransport certificate | a `selfSigned` WebTransport host; a client with exactly one `serverCertificateHashes` entry |
|
|
1007
|
+
| `tls-exporter` | 32 bytes of TLS keying material (RFC 5705/8446, label `EXPORTER-wsh-channel-binding`) | Node on both ends over `wss://` served by the process itself (the client must use the `ws` package, e.g. `new WebSocketTransport({ WebSocket })`; Node's global `WebSocket` and every browser expose no exporter) |
|
|
1008
|
+
|
|
1009
|
+
It is negotiated with feature strings (`channel-binding:<kind>`,
|
|
1010
|
+
`channel-binding-required`), so released clients and hosts keep working: a
|
|
1011
|
+
host that does not require binding still accepts an unbound login, and a
|
|
1012
|
+
client binds whatever the host offers. A host that requires it refuses an
|
|
1013
|
+
unbound signature with a reason. **What it does not do:** it protects only
|
|
1014
|
+
what you require. An intermediary that strips the host's offer gets an unbound
|
|
1015
|
+
signature from a client that did not set `requireChannelBinding`, and a host
|
|
1016
|
+
that does not require binding accepts it -- set the option on whichever side
|
|
1017
|
+
you control (a host protects every client; a client protects itself).
|
|
1018
|
+
`tls-exporter` fails behind a TLS-terminating proxy by design. Password logins
|
|
1019
|
+
are not bound (nothing is signed). The Rust `wsh-server` and `wsh` CLI do not
|
|
1020
|
+
offer or compute a binding yet, so against them a client with
|
|
1021
|
+
`requireChannelBinding` refuses to log in.
|
|
1022
|
+
|
|
803
1023
|
### Password auth
|
|
804
1024
|
|
|
805
1025
|
```js
|
|
@@ -1122,7 +1342,7 @@ so options the platform gains later need no change here.
|
|
|
1122
1342
|
|
|
1123
1343
|
| Export | Description |
|
|
1124
1344
|
|--------|-------------|
|
|
1125
|
-
| `MSG` |
|
|
1345
|
+
| `MSG` | 105 message type constants (hex opcodes) |
|
|
1126
1346
|
| `CHANNEL_KIND` | Channel types: `pty`, `exec`, `meta`, `file`, `tcp`, `udp`, `job` |
|
|
1127
1347
|
| `AUTH_METHOD` | Auth methods: `pubkey`, `password` |
|
|
1128
1348
|
| `cborEncode` / `cborDecode` | CBOR codec (maps, arrays, strings, ints, bytes, bools, null, floats) |
|
|
@@ -1146,7 +1366,7 @@ instead of dragging its own toolchain and CI job into an unrelated
|
|
|
1146
1366
|
browser-app repo. It was previously deleted from clawser by accident
|
|
1147
1367
|
(2026-03-14) and restored (2026-07-05) before this move.
|
|
1148
1368
|
|
|
1149
|
-
Four crates, workspace-versioned (currently `0.
|
|
1369
|
+
Four crates, workspace-versioned (currently `0.7.0`):
|
|
1150
1370
|
|
|
1151
1371
|
| Crate | Kind | Description |
|
|
1152
1372
|
|-------|------|--------------|
|
|
@@ -1155,6 +1375,22 @@ Four crates, workspace-versioned (currently `0.5.0`):
|
|
|
1155
1375
|
| `wsh-cli` | binary (`wsh`) | SSH-like CLI: connect, exec, scp-style copy, reverse tunnels, key management |
|
|
1156
1376
|
| `wsh-server` | binary (`wsh-server`) | Server: WebTransport/WebSocket listener, real PTY sessions (`portable-pty`), relay/reverse-connect, WISP bridging |
|
|
1157
1377
|
|
|
1378
|
+
### Running a command with `wsh`
|
|
1379
|
+
|
|
1380
|
+
```sh
|
|
1381
|
+
wsh alice@host ls -l # dials https://host:4422, then wss://host:4422
|
|
1382
|
+
wsh -t ws -p 8443 alice@host ls -l # wss:// only, on port 8443
|
|
1383
|
+
wsh wss://host:8443/rendezvous/ab12 ls -l # a full URL, dialled exactly as written (path and query kept)
|
|
1384
|
+
printf 'a\nb\n' | wsh alice@host sort # stdin is forwarded; its end reaches the command as EOF
|
|
1385
|
+
wsh --tty alice@host top # a terminal for the command: raw keys, resizes forwarded
|
|
1386
|
+
```
|
|
1387
|
+
|
|
1388
|
+
stdout and stderr stay separate where the host offers `exec-pipes`; the exit status is the command's.
|
|
1389
|
+
SIGINT, SIGTERM and SIGHUP sent to `wsh` are forwarded to the command, and the same signal twice
|
|
1390
|
+
disconnects. `wsh connect` ends when the remote session does. Diagnostics go to stderr (`-v` for more),
|
|
1391
|
+
never into the command's stdout. TLS uses the platform trust store, and `SSL_CERT_FILE` points it at another certificate (how a self-signed host is trusted); a plain
|
|
1392
|
+
`ws://` URL is accepted only for a loopback host.
|
|
1393
|
+
|
|
1158
1394
|
### Capability matrix: JS SDK vs Rust CLI/client
|
|
1159
1395
|
|
|
1160
1396
|
Two implementations of one protocol will always have *some* asymmetry --
|
|
@@ -1170,12 +1406,22 @@ than left to be found.
|
|
|
1170
1406
|
| Install an authorized key | `WshClient.addAuthorizedKey()` | `wsh_client::WshClient::add_authorized_key()`, `wsh copy-id` | **Wire-unified** (wsh #59): `AuthorizedKeyAdd`/`AuthorizedKeyResult`, replacing a Rust-CLI-only shell command with a message every implementation can send |
|
|
1171
1407
|
| Host identity / TOFU | `WshKnownHosts` (localStorage-backed) | `KnownHosts`/`HostStatus` (`~/.wsh/known_hosts`-backed) | **Record unified, policy is not** (wsh #59): both pin `ServerHello.host_fingerprint`, which `@johnhenry/wsh/server` populates (with a proof of possession, [Host key](#host-key-fingerprint--tofu)) but no Rust `wsh-server` release does yet (see [Security](#security-model)). *When* to trust, prompt, or persist is deliberately left per-implementation -- a browser and a CLI have different UX for "first time seeing this host" |
|
|
1172
1408
|
| Typed RPC channels (`openRpc`, `rpc` sessions; `wsh-host`, `wsh-fs`, `mcp`) | `WshClient.openRpc()`, `RpcChannel` | Rust `wsh-server` (`rust-v0.4.0`+): `wsh-host`, and `wsh-fs` when `[rpc] fs_root` is set; no client yet in `wsh-client` | **No wire change**: `Open { kind: 'rpc', command: <protocol> }` plus `rpc*` `ServerHello` features, negotiated so it fails fast elsewhere; the Rust server serves it on WebSocket/QMux only |
|
|
1173
|
-
| Exec stdin + EOF, separate stderr | `exec({ stdin })`, `session.closeStdin()`, `session.onStderr` |
|
|
1409
|
+
| Exec stdin + EOF, separate stderr | `exec({ stdin })`, `session.closeStdin()`, `session.onStderr` | `SessionOpts { stdio: Some("pipes") }`, `WshSession::read_stderr()` / `close_stdin()`; `wsh host command` uses them whenever its stdin is a pipe or a file and the host offers `exec-pipes` | **Wire-unified, negotiated** (#105): `Open.stdio = "pipes"` + `OpenOk.stderr_channel_id` + zero-length `SessionData` as EOF, offered by the `exec-pipes` `ServerHello` feature. `@johnhenry/wsh/server` needs none of it (stream-mode EOF); the Rust `wsh-server` (`rust-v0.5.0`+) runs such an exec on pipes, everything else on the PTY. Against a host without `exec-pipes` the CLI still forwards stdin, but cannot tell the command it ended |
|
|
1410
|
+
| Signals and resize for a one-off command | `session.signal()`, `session.resize()` | `wsh host command` forwards SIGINT/SIGTERM/SIGHUP (the same signal twice disconnects); `wsh --tty host command` also forwards terminal resizes | **Wire-unified** (`Signal`, `Resize`). **Not everywhere honoured**: the Rust `wsh-server` currently only logs `Signal`, so a forwarded signal does not stop the command there |
|
|
1411
|
+
| Dial target | a URL | `wsh [user@]host` (dials `https://` then `wss://` on `--port`), or a full URL: `wsh wss://host:8443/rendezvous/ab12 command`, `ws://127.0.0.1:PORT/` | **CLI-only convenience**: a URL is dialled exactly as given (no transport fallback; `--port` and `--transport` do not apply). Plain `ws://` is accepted only to a loopback host |
|
|
1174
1412
|
| Host that runs in a browser page (`createMemoryHost`, `@johnhenry/wsh/reverse`) | yes, with injected `pty` / `fs` / `hostKey` | no (a Rust host is a process) | **JS-only**. A Rust *client* can operate such a host only with `dataStreams: false` (#132): the released Rust client over WebSocket cannot open QMux data streams, and says nothing in `Hello` that a host could use to decide. Its `scp` download also reads a raw stream, not the `FileChunk` messages this host sends, so `wsh scp` from such a host does not work (`wsh ls` and exec do) |
|
|
1175
1413
|
| Interactive shell UI | none -- this SDK is a protocol client, not a terminal emulator; pair with xterm.js/ghostty-web | `wsh connect`, `wsh sftp` (line-oriented REPL) | **Deliberately not unified** -- a browser embeds a terminal widget the host page owns; a CLI process owns its own TTY |
|
|
1176
1414
|
| Attach / resume | `attachSession()`, `resumeSession()`, `WshSession.seq` | `attach_session()`, `resume_session()` | **Wire-unified** (`Attach`/`Resume`/`Presence`); `seq` = cumulative output bytes. `@johnhenry/wsh/server` honours `last_seq` (bounded ring, gap errors) and answers Presence with `channel_id`/`seq`; the Rust `wsh-server` does the same (`rust-v0.2.0`+; fixed 256 KiB ring) |
|
|
1177
1415
|
| Reverse-connect / relay peer | `connectReverse()`, `trustRelayPeer()`; `@johnhenry/wsh/server`: `relay` option and `createReverseHost()` | `wsh reverse`, `wsh agent` (persistent, with startup-unit install) | **Wire-unified** (registration, discovery, signed peer records); **daemonization is CLI-only** -- a browser tab cannot be a background OS service. The Node relay is default-deny and bridges one operator per peer unless `maxOperatorsPerPeer` is raised (`busy:` reasons say so); E2E and bridged feature gates need `rust-v0.3.0`+ on the Rust side; several operators per peer and the signed `KeyExchange` are JS-relay only for now |
|
|
1178
1416
|
| Post-quantum E2E (experimental) | `initiateE2E()` (WebCrypto ML-KEM-768 or `@noble/post-quantum` fallback) | `E2eKeyExchange` (`ml-kem` crate) | **Wire-unified** algorithm and transcript; key material backends differ by platform necessity |
|
|
1417
|
+
| Unix-domain socket forwarding, both directions; named endpoints (#120) | `client.openUnix()`, `listenUnix()`, `forwardUnix()` (Node: `-L`/`-R` shapes with unix and TCP ends mixed), `openEndpoint()`; host: `gateway: { unix, endpoints }`, `createMemoryHost({ endpoints })` | none yet (`wsh -L` / `-R` with sockets are not implemented) | **JS only for now.** Wire: `OpenUnix`, `OpenEndpoint`, `ListenUnix` behind the `gateway-unix` / `gateway-endpoints` host features; the Rust server and CLI must implement them (message handling, the path policy, `-L`/`-R` flags) as described under [Gateway](#unix-domain-sockets-streamlocal-and-named-endpoints) |
|
|
1418
|
+
| Gateway flow control (#123) | credit per connection (`GatewayCredit`, feature `gateway-credit`); host caps for peers without it | none: the Rust forwarder has bounded in-process queues but no per-connection credit and no per-client byte cap | **JS only for now** (negotiated, so a Rust peer on either side keeps today's unmetered behaviour) |
|
|
1419
|
+
| Gateway destination policy by resolved address | `@johnhenry/wsh/server` `gateway`: resolved address checked, `allowPrivate` | fixed in the Rust release after `rust-v0.6.0`: a loopback/private/link-local/ULA/CGNAT/unspecified/multicast address is refused after resolution unless a rule names it, and the server connects to the address it checked | **Same rule on both sides** (a Rust server released before that still has the name-only check) |
|
|
1420
|
+
| Operator proof to the peer, sealed bridge, signed initiator half (#117) | `reverseConnect(.., { sealed, requirePeerProof })`; host `createReverseHost({ requireOperatorProof })`; relay lists `operator-proof` | none: the Rust relay neither carries `ReverseChallenge`/`ReverseProof` nor lists the feature, and the Rust agent/client send and answer neither | **Wire-unified, negotiated** (`ReverseConnect.features`, `operator-proof`, `e2e-sealed`); the Rust types are regenerated (and `ReverseConnect.features` is `None` there) but no Rust peer implements it yet |
|
|
1421
|
+
| Channel binding of the login signature (#119) | `requireChannelBinding` (client and server); kinds `host`, `cert-hash`, `tls-exporter` | none: no Rust host offers one and the Rust client signs with an empty binding | **Wire-unified, negotiated** (`channel-binding:<kind>` features); a Rust client logging in to a JS host that requires it is refused |
|
|
1422
|
+
| Pipe relay (#118) | `@johnhenry/wsh/pipe-relay` | none; the `wsh` CLI always dials `wss://<host>/` (#136), so it cannot reach `/r/<id>` -- it needs `--via` or to keep the URL path | **Deliberately a relay without wsh parsing** -- nothing to unify on the wire |
|
|
1423
|
+
| `AuthOk.ttl` enforced, `token` opaque (#125) | `connectionTtlMs`; `client.authTtl` | `wsh-server` sends `session_ttl` (default 86400) and an HMAC token, neither enforced or checked | **Wire-compatible**: both fields are still sent (released peers require them); the JS host sends `ttl: 0` unless a limit is set |
|
|
1424
|
+
| `clientEnv` allow-list (#126) | default `TERM`, `COLORTERM`, `LANG`, `LANGUAGE`, `LC_*` | the Rust server applies whatever environment the client sends | **JS host only**; wire unchanged |
|
|
1179
1425
|
| Session recording/replay | `SessionRecorder`/`SessionPlayer` (asciicast-v2-shaped JSON) | none | **JS-only** -- no current Rust consumer needs playback; the vocabulary is asciicast v2's, so a Rust port could share it |
|
|
1180
1426
|
| Self-signed cert pinning | `serverCertificateHashes` (WebTransport option) | N/A -- Rust dials a cert its own TLS stack already trusts, or `--generate-cert`'s self-signed cert out of band | **Deliberately not unified** -- this is a browser-specific WebTransport API shape, not a wire-protocol concept |
|
|
1181
1427
|
|
|
@@ -1245,7 +1491,28 @@ out explicitly below rather than left to be discovered.
|
|
|
1245
1491
|
- **Auth transcript binding.** Challenge signatures cover
|
|
1246
1492
|
`SHA-256("wsh-v1\0" || lp(username) || lp(session_id) || nonce || channel_binding)`,
|
|
1247
1493
|
so a signature can't be replayed against a different session or relabeled
|
|
1248
|
-
to a different username.
|
|
1494
|
+
to a different username. `channel_binding` is empty unless both ends agree
|
|
1495
|
+
on one (wsh #119): then it also names the connection (host key, pinned
|
|
1496
|
+
certificate, TLS exporter), so a relaying intermediary cannot reuse a
|
|
1497
|
+
signature -- but only against a host that requires it or a client that
|
|
1498
|
+
does; see [Channel binding](#channel-binding-tie-the-login-to-the-connection).
|
|
1499
|
+
- **A relay need not be believed about who the operator is (opt-in).** With
|
|
1500
|
+
`requireOperatorProof` on the host and `sealed` on the operator, the host
|
|
1501
|
+
verifies the operator's own signature before `accept`, and acts only on
|
|
1502
|
+
sealed traffic, so a relay cannot stamp an identity, replay a login or inject
|
|
1503
|
+
an `Open`; see the table under
|
|
1504
|
+
[Operator proof and sealed bridges](#operator-proof-and-sealed-bridges-117).
|
|
1505
|
+
Not default, not available through the Rust relay, and no defence against a
|
|
1506
|
+
relay that drops traffic.
|
|
1507
|
+
- **A pipe relay vouches for nothing.** With `createPipeRelay` the host
|
|
1508
|
+
authenticates the operator itself (see [A pipe relay](#a-pipe-relay-johnhenrywshpipe-relay-118)).
|
|
1509
|
+
- **`AuthOk.ttl` and `token`.** The token is an opaque per-connection value
|
|
1510
|
+
with no authority; `ttl` is enforced when `connectionTtlMs` is set (else 0:
|
|
1511
|
+
no limit) -- do not read either as a session credential.
|
|
1512
|
+
- **Client environment is an allow-list** (`clientEnv`, default `TERM`,
|
|
1513
|
+
`COLORTERM`, `LANG`, `LANGUAGE`, `LC_*`): a client cannot set `PATH`,
|
|
1514
|
+
`LD_PRELOAD` or `BASH_ENV` for a command your host runs through a shell
|
|
1515
|
+
unless you say so.
|
|
1249
1516
|
- **E2E through a relay is opt-in.** The relay carries `KeyExchange` /
|
|
1250
1517
|
`EncryptedFrame` between a bridged operator and peer without being able to
|
|
1251
1518
|
read the sealed frames. `KeyExchange` is unauthenticated unless the peer signs
|
|
@@ -1258,8 +1525,25 @@ out explicitly below rather than left to be discovered.
|
|
|
1258
1525
|
entry client-side and reports a `verified` boolean, independent of
|
|
1259
1526
|
trusting the relay.
|
|
1260
1527
|
|
|
1528
|
+
- **The Node gateway checks where a connection goes, not only what it was called.** `gateway.allow` matches the name a
|
|
1529
|
+
client sent, and then the address it resolves to must be globally routable (or permitted by `allowPrivate` or an
|
|
1530
|
+
IP-literal rule); the connection is made to that checked address, and `ResolveDns` answers are filtered the same way.
|
|
1531
|
+
Unix-domain sockets (`gateway.unix`) and named endpoints (`gateway.endpoints`) are off unless configured, are listed
|
|
1532
|
+
paths or names only, and sockets the host creates are `0600`.
|
|
1533
|
+
|
|
1261
1534
|
**What is still yours:**
|
|
1262
1535
|
|
|
1536
|
+
- **What the gateway does NOT protect against.** A name that resolves to a *public* address is dialled as the client
|
|
1537
|
+
asked, so `allow: ['*']` is an open proxy to the internet for every authorized client. Through `socks` the proxy
|
|
1538
|
+
resolves the name, so the host cannot check the address (only IP literals are checked) and the proxy's own network
|
|
1539
|
+
is the egress. The path check for unix sockets is made just before the connect: a local user who can write to an
|
|
1540
|
+
allowed directory can still swap a path between the two, so list only directories that are not writable by others.
|
|
1541
|
+
A client may open any listed socket as the host's user; a socket that speaks a powerful API (the Docker socket is
|
|
1542
|
+
root on the host) is exactly as powerful for every authorized client, so list it only for clients you would give that
|
|
1543
|
+
access. Named endpoints run embedder code with the caller's identity (`who`) but the handler decides what that
|
|
1544
|
+
identity may do. A `wsh-server` built before the Rust release that followed `rust-v0.6.0` only matches the name, not the
|
|
1545
|
+
resolved address (see the Rust defaults above): do not expose such a binary with a `"*"` allow list.
|
|
1546
|
+
|
|
1263
1547
|
- **Hybrid post-quantum E2E is experimental and not fully wired (in
|
|
1264
1548
|
progress).** `initiateE2E(sessionId, 'X25519+ML-KEM-768')` combines
|
|
1265
1549
|
X25519 ECDH with ML-KEM-768 via HKDF-SHA256, preferring native WebCrypto
|
|
@@ -1305,7 +1589,57 @@ out explicitly below rather than left to be discovered.
|
|
|
1305
1589
|
above), but nothing in this protocol or client stops a non-browser
|
|
1306
1590
|
caller (Node, the Rust CLI) from dialing `ws://` directly. Prefer pubkey
|
|
1307
1591
|
auth, or make sure the transport is actually encrypted, before sending a
|
|
1308
|
-
password.
|
|
1592
|
+
password. (The Rust `wsh` CLI refuses a plain `ws://` URL unless the host is
|
|
1593
|
+
loopback.)
|
|
1594
|
+
|
|
1595
|
+
### Rust `wsh-server`: what is off until you turn it on
|
|
1596
|
+
|
|
1597
|
+
An authorized key is a login, not a licence to use the machine as a network
|
|
1598
|
+
position. From the Rust release after `rust-v0.6.0` the server's defaults are:
|
|
1599
|
+
|
|
1600
|
+
- **The gateway is off** (`[gateway] enabled = false`), and `gateway` is not
|
|
1601
|
+
advertised. Turning it on allows **no destination** until `allowed_destinations`
|
|
1602
|
+
lists some. `"*"` means any *public* destination: an address that is loopback,
|
|
1603
|
+
link-local (including `169.254.169.254`), private (RFC 1918), unique-local
|
|
1604
|
+
(`fc00::/7`), carrier-grade NAT (`100.64.0.0/10`), unspecified or multicast is
|
|
1605
|
+
refused **after the name is resolved**, whichever rule matched the name, unless
|
|
1606
|
+
a rule names that host (`"db.internal:5432"`) or address/range
|
|
1607
|
+
(`"10.1.0.0/16:5432"`, `"127.0.0.1:8080"`). The server connects to the address it
|
|
1608
|
+
checked, so a name cannot pass the check as one address and connect as another.
|
|
1609
|
+
`ResolveDns` follows the same rule and does not return internal answers.
|
|
1610
|
+
- **Reverse listeners are off** (`enable_reverse_tunnels = false`) and, when on,
|
|
1611
|
+
bind to `reverse_bind_addr` (default `127.0.0.1`). The client's own `bind_addr`
|
|
1612
|
+
in `ListenRequest` (its wire default is `0.0.0.0`) is ignored.
|
|
1613
|
+
- **Password login is off** (`[auth] allow_password = false`). Stored hashes are
|
|
1614
|
+
Argon2id PHC strings with a per-user salt (`printf '%s' "$PW" | wsh-server
|
|
1615
|
+
--hash-password`), compared in constant time; an unknown user and a wrong password
|
|
1616
|
+
cost the same and fail with the same message. Old unsalted `sha256:` entries are
|
|
1617
|
+
**refused** (logged at start-up, naming the user) unless `allow_legacy_sha256 = true`,
|
|
1618
|
+
which accepts them with a warning at every start-up. Refusing, not warning, is the
|
|
1619
|
+
default because a warning nobody reads leaves the weak hash live on every
|
|
1620
|
+
deployment that is not watched; the edit that turns password login back on is the
|
|
1621
|
+
natural moment to rehash.
|
|
1622
|
+
|
|
1623
|
+
What this does **not** protect against:
|
|
1624
|
+
|
|
1625
|
+
- **A rule you write is trusted.** A hostname rule (`"db.internal"`) allows that name
|
|
1626
|
+
to resolve to anything, including a restricted address; only the wildcard is
|
|
1627
|
+
held to public addresses. An address range or literal address rule allows
|
|
1628
|
+
exactly what it says.
|
|
1629
|
+
- **It is not per-key.** Every authorized key gets the same gateway. A key that
|
|
1630
|
+
should not have it should not be in `authorized_keys`.
|
|
1631
|
+
- **There is no bandwidth or request-rate limit** beyond `max_connections`
|
|
1632
|
+
(default 100 concurrent connections and listeners together), and a listener's
|
|
1633
|
+
port is chosen by the client within what the server's user may bind.
|
|
1634
|
+
- **Hashing protects the stored file, not the wire.** The password still travels
|
|
1635
|
+
inside the auth message (see above); only use password login over `wss://` or
|
|
1636
|
+
WebTransport. The per-address auth rate limit bounds how fast one address can
|
|
1637
|
+
make the server run Argon2id (19 MiB each); it is not a defence against many
|
|
1638
|
+
addresses.
|
|
1639
|
+
- **The dev certificate from `--generate-cert` is not a certificate a TLS client
|
|
1640
|
+
can verify** (it is flagged as a CA); clients dial it with
|
|
1641
|
+
`WSH_INSECURE_LOOPBACK_TLS=1`, which disables verification and is for loopback
|
|
1642
|
+
testing only.
|
|
1309
1643
|
|
|
1310
1644
|
- **A host that lives in a page (`createMemoryHost`, `@johnhenry/wsh/reverse`) is only as trustworthy as the page.** A
|
|
1311
1645
|
non-extractable host key or client key keeps the private key from being *read*, not from being *used*: any script that
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnhenry/wsh",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Web Shell \u2014 browser-native remote command execution over WebTransport and WebSocket with Ed25519 authentication",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"types": "./src/server/index.d.ts",
|
|
14
14
|
"import": "./src/server/index.mjs"
|
|
15
15
|
},
|
|
16
|
+
"./pipe-relay": {
|
|
17
|
+
"types": "./src/pipe-relay.d.ts",
|
|
18
|
+
"import": "./src/pipe-relay.mjs"
|
|
19
|
+
},
|
|
16
20
|
"./memory": {
|
|
17
21
|
"types": "./src/memory-host.d.ts",
|
|
18
22
|
"import": "./src/memory-host.mjs"
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A sealed bridge (wsh #117): everything two endpoints say to each other across a relay, sealed under a key they
|
|
3
|
+
* agreed with a signed `KeyExchange` whose `session_id` is the bridge's, so the relay carries ciphertext it cannot
|
|
4
|
+
* read, forge, replay or reorder -- and, because a relay can stamp any `from_fingerprint` on a PLAIN message, cannot
|
|
5
|
+
* make a peer act for an operator that is not there.
|
|
6
|
+
*
|
|
7
|
+
* Each message that would cross the bridge is CBOR-encoded and sealed with the same AES-256-GCM framing as session
|
|
8
|
+
* data (`e2e-frame.mjs`: a strict send counter, a role tag per direction, `session_id` as AAD) into an
|
|
9
|
+
* `EncryptedFrame` with `channel_id` 0 (real channels start at 1). The receiver opens it and handles the inner
|
|
10
|
+
* message as if it had arrived plain; a plain message on a sealed bridge is dropped.
|
|
11
|
+
*
|
|
12
|
+
* Browser-safe: Web Crypto and the CBOR codec only.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { sealFrame, openFrame, ROLE_TAGS } from './e2e-frame.mjs';
|
|
16
|
+
import { cborEncode, cborDecode } from './cbor.mjs';
|
|
17
|
+
import { encryptedFrame, MSG, isRelayForwardable } from './messages.gen.mjs';
|
|
18
|
+
|
|
19
|
+
/** `EncryptedFrame.channel_id` of a bridge-level frame. */
|
|
20
|
+
export const BRIDGE_CHANNEL_ID = 0;
|
|
21
|
+
|
|
22
|
+
export class SealedBridge {
|
|
23
|
+
#key;
|
|
24
|
+
#sessionId;
|
|
25
|
+
#sendTag;
|
|
26
|
+
#recvTag;
|
|
27
|
+
#sendCounter = 0;
|
|
28
|
+
#recvCounter = 0;
|
|
29
|
+
#outChain = Promise.resolve();
|
|
30
|
+
#inChain = Promise.resolve();
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {{ key: CryptoKey, sessionId: string, role: 'initiator' | 'responder' }} p - `initiator` is the operator
|
|
34
|
+
*/
|
|
35
|
+
constructor({ key, sessionId, role }) {
|
|
36
|
+
if (role !== 'initiator' && role !== 'responder') throw new TypeError("SealedBridge: role must be 'initiator' or 'responder'");
|
|
37
|
+
this.#key = key;
|
|
38
|
+
this.#sessionId = sessionId;
|
|
39
|
+
this.#sendTag = ROLE_TAGS[role];
|
|
40
|
+
this.#recvTag = ROLE_TAGS[role === 'initiator' ? 'responder' : 'initiator'];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get sessionId() { return this.#sessionId; }
|
|
44
|
+
|
|
45
|
+
/** Is `msg` a bridge-level frame of this bridge? */
|
|
46
|
+
isFrame(msg) {
|
|
47
|
+
return msg?.type === MSG.ENCRYPTED_FRAME && msg.channel_id === BRIDGE_CHANNEL_ID && msg.session_id === this.#sessionId;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Seal one message; calls are sealed (and so must be sent) in call order. @returns {Promise<object>} an `EncryptedFrame` */
|
|
51
|
+
seal(msg) {
|
|
52
|
+
const counter = this.#sendCounter++;
|
|
53
|
+
const run = this.#outChain.then(async () => {
|
|
54
|
+
const { nonce, ciphertext } = await sealFrame(this.#key, this.#sessionId, this.#sendTag, counter, cborEncode(msg));
|
|
55
|
+
return encryptedFrame({ channelId: BRIDGE_CHANNEL_ID, nonce, ciphertext, sessionId: this.#sessionId });
|
|
56
|
+
});
|
|
57
|
+
this.#outChain = run.catch(() => {});
|
|
58
|
+
return run;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Open one frame. A replayed, reordered, forged or foreign frame throws and does not consume a counter.
|
|
63
|
+
* @returns {Promise<object>} the inner message, which is always one a relay may forward
|
|
64
|
+
*/
|
|
65
|
+
open(frame) {
|
|
66
|
+
const run = this.#inChain.then(async () => {
|
|
67
|
+
if (!this.isFrame(frame)) throw new Error('not a frame of this bridge');
|
|
68
|
+
const plain = await openFrame(this.#key, this.#sessionId, this.#recvCounter, { nonce: frame.nonce, ciphertext: frame.ciphertext, expectedRoleTag: this.#recvTag });
|
|
69
|
+
this.#recvCounter += 1;
|
|
70
|
+
const inner = cborDecode(plain);
|
|
71
|
+
if (!inner || typeof inner.type !== 'number' || inner.type === MSG.RELAY_FORWARD || !isRelayForwardable(inner.type)) throw new Error('sealed message of a type that may not cross a bridge');
|
|
72
|
+
return inner;
|
|
73
|
+
});
|
|
74
|
+
this.#inChain = run.catch(() => {});
|
|
75
|
+
return run;
|
|
76
|
+
}
|
|
77
|
+
}
|