@johnhenry/wsh 0.48.0 → 0.50.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 +156 -30
- package/package.json +21 -3
- package/spec/capabilities.md +175 -0
- package/spec/capabilities.vectors.json +200 -0
- package/spec/duplex-binding.md +86 -0
- package/spec/key-options.vectors.json +248 -0
- package/spec/message-matrix.md +259 -0
- package/spec/wsh-v1.md +1607 -0
- package/spec/wsh-v1.yaml +2783 -0
- package/src/auth.mjs +3 -34
- package/src/capabilities.d.ts +53 -0
- package/src/capabilities.mjs +69 -0
- package/src/duplex.d.ts +69 -0
- package/src/duplex.mjs +208 -0
- package/src/gateway-errors.mjs +45 -0
- package/src/identity.d.ts +61 -0
- package/src/identity.mjs +194 -0
- package/src/index.d.ts +11 -0
- package/src/index.mjs +1 -0
- package/src/key-names.mjs +115 -0
- package/src/key-options.mjs +5 -0
- package/src/mcp-duplex.mjs +184 -0
- package/src/memory-host.d.ts +5 -0
- package/src/memory-host.mjs +3 -2
- package/src/objects-core.mjs +31 -8
- package/src/objects.d.ts +18 -5
- package/src/objects.mjs +4 -1
- package/src/page-host.d.ts +46 -2
- package/src/page-host.mjs +10 -2
- package/src/server/connection.mjs +15 -7
- package/src/server/gateway-core.mjs +4 -4
- package/src/server/socket.mjs +5 -2
- package/src/testing-doubles.mjs +115 -0
- package/src/testing.d.ts +44 -0
- package/src/testing.mjs +3 -0
- package/src/transport.mjs +1 -1
- package/src/webmcp.mjs +8 -4
package/spec/wsh-v1.yaml
ADDED
|
@@ -0,0 +1,2783 @@
|
|
|
1
|
+
# wsh Protocol Specification — v1
|
|
2
|
+
# This file is the single source of truth for all message types.
|
|
3
|
+
# Run: npm run codegen (node spec/codegen.mjs, from the repository root)
|
|
4
|
+
|
|
5
|
+
protocol:
|
|
6
|
+
name: wsh
|
|
7
|
+
version: "wsh-v1"
|
|
8
|
+
wire_format: cbor
|
|
9
|
+
framing: length_prefixed_be32
|
|
10
|
+
|
|
11
|
+
enums:
|
|
12
|
+
ChannelKind:
|
|
13
|
+
type: string
|
|
14
|
+
values: [pty, exec, meta, file, tcp, udp, job, rpc]
|
|
15
|
+
value_descriptions:
|
|
16
|
+
pty: "Interactive pseudo-terminal session with resize support"
|
|
17
|
+
exec: "One-shot command execution without a PTY"
|
|
18
|
+
meta: "Control metadata channel (session management)"
|
|
19
|
+
file: "File transfer channel (upload or download)"
|
|
20
|
+
tcp: "Gateway-proxied TCP stream to an external host:port"
|
|
21
|
+
udp: "Gateway-proxied UDP datagram socket to an external host:port"
|
|
22
|
+
job: "Background automation job channel for structured task execution"
|
|
23
|
+
rpc: "Typed object-mode channel (wsh #85): Open.command names the protocol, the data stream is a CBOR sequence of JSON-RPC 2.0 messages; offered only when ServerHello.features lists rpc and rpc-protocol:<name>"
|
|
24
|
+
AuthMethod:
|
|
25
|
+
type: string
|
|
26
|
+
values: [pubkey, password]
|
|
27
|
+
SessionDataMode:
|
|
28
|
+
type: string
|
|
29
|
+
values: [stream, virtual]
|
|
30
|
+
value_descriptions:
|
|
31
|
+
stream: "Session uses transport-opened byte streams"
|
|
32
|
+
virtual: "Session uses message-framed SessionData payloads"
|
|
33
|
+
FileEntryType:
|
|
34
|
+
# wsh #59: previously each implementation invented this set privately
|
|
35
|
+
# (the JS SDK's WshFileListEntry.type union) while FileResult.metadata
|
|
36
|
+
# stayed an untyped `json` bag. Generated into both languages now so a
|
|
37
|
+
# directory listing can't describe a symlink as a plain file in one
|
|
38
|
+
# implementation and not the other.
|
|
39
|
+
type: string
|
|
40
|
+
values: [file, directory, symlink, device, pipe, socket]
|
|
41
|
+
value_descriptions:
|
|
42
|
+
file: "Regular file"
|
|
43
|
+
directory: "Directory"
|
|
44
|
+
symlink: "Symbolic link -- see FileEntry.symlink_target for its target"
|
|
45
|
+
device: "Block or character device node"
|
|
46
|
+
pipe: "Named pipe (FIFO)"
|
|
47
|
+
socket: "Unix domain socket"
|
|
48
|
+
|
|
49
|
+
messages:
|
|
50
|
+
handshake:
|
|
51
|
+
Hello:
|
|
52
|
+
code: 0x01
|
|
53
|
+
description: >
|
|
54
|
+
First message sent by the client to initiate a connection.
|
|
55
|
+
Contains the protocol version, username, requested features,
|
|
56
|
+
and preferred authentication method.
|
|
57
|
+
fields:
|
|
58
|
+
version:
|
|
59
|
+
type: string
|
|
60
|
+
required: true
|
|
61
|
+
username:
|
|
62
|
+
type: string
|
|
63
|
+
required: true
|
|
64
|
+
features:
|
|
65
|
+
type: "string[]"
|
|
66
|
+
default: "[]"
|
|
67
|
+
auth_method:
|
|
68
|
+
type: AuthMethod
|
|
69
|
+
required: false
|
|
70
|
+
|
|
71
|
+
ServerHello:
|
|
72
|
+
code: 0x02
|
|
73
|
+
description: >
|
|
74
|
+
Server response to Hello. Assigns a session_id, advertises
|
|
75
|
+
server features, and lists authorized key fingerprints.
|
|
76
|
+
fields:
|
|
77
|
+
session_id:
|
|
78
|
+
type: string
|
|
79
|
+
required: true
|
|
80
|
+
features:
|
|
81
|
+
type: "string[]"
|
|
82
|
+
default: "[]"
|
|
83
|
+
fingerprints:
|
|
84
|
+
type: "string[]"
|
|
85
|
+
default: "[]"
|
|
86
|
+
description: >
|
|
87
|
+
Fingerprints of the keys THIS SERVER currently authorizes for
|
|
88
|
+
login (its ~/.wsh/authorized_keys, not this server's own
|
|
89
|
+
identity). wsh #59 audit: the Rust client's KnownHosts TOFU
|
|
90
|
+
check (crates/wsh-client/src/client.rs verify_host_key) reads
|
|
91
|
+
fingerprints[0] as if it were a stable per-server host identity
|
|
92
|
+
-- it is not; it is whichever authorized client key happens to
|
|
93
|
+
load first, which can differ per user, per config edit, or be
|
|
94
|
+
empty. That is a pre-existing latent gap, not introduced here.
|
|
95
|
+
Use host_fingerprint (below) for actual host identity.
|
|
96
|
+
host_fingerprint:
|
|
97
|
+
type: string
|
|
98
|
+
required: false
|
|
99
|
+
description: >
|
|
100
|
+
wsh #59: the formal host-identity record. SHA-256 fingerprint
|
|
101
|
+
(hex, per crypto.fingerprint) of the server's own persistent
|
|
102
|
+
Ed25519 host identity key -- what TOFU should actually pin,
|
|
103
|
+
distinct from `fingerprints` above. Optional because minting
|
|
104
|
+
and persisting a server host keypair is a separate, security-
|
|
105
|
+
sensitive feature this spec change does not implement; no
|
|
106
|
+
wsh-server release populates it yet. A TOFU-capable client MUST
|
|
107
|
+
treat an absent/empty host_fingerprint as "this server does not
|
|
108
|
+
support host verification" and must NOT fall back to
|
|
109
|
+
fingerprints[0] to fabricate one.
|
|
110
|
+
|
|
111
|
+
Challenge:
|
|
112
|
+
code: 0x03
|
|
113
|
+
description: >
|
|
114
|
+
Sent by the server with a random nonce for the client to sign
|
|
115
|
+
with its private key (pubkey auth) or as part of password auth.
|
|
116
|
+
Carries session_id directly so the auth transcript never depends
|
|
117
|
+
on the client having already received (and processed) ServerHello
|
|
118
|
+
first -- ServerHello and Challenge can arrive in either order, or
|
|
119
|
+
ServerHello can be skipped entirely, with no effect on the
|
|
120
|
+
transcript's correctness.
|
|
121
|
+
fields:
|
|
122
|
+
nonce:
|
|
123
|
+
type: bytes
|
|
124
|
+
required: true
|
|
125
|
+
session_id:
|
|
126
|
+
type: string
|
|
127
|
+
required: true
|
|
128
|
+
|
|
129
|
+
AuthMethods:
|
|
130
|
+
code: 0x04
|
|
131
|
+
description: >
|
|
132
|
+
Sent by the server to advertise which authentication methods
|
|
133
|
+
are available (pubkey, password, or both).
|
|
134
|
+
fields:
|
|
135
|
+
methods:
|
|
136
|
+
type: "AuthMethod[]"
|
|
137
|
+
required: true
|
|
138
|
+
|
|
139
|
+
Auth:
|
|
140
|
+
code: 0x05
|
|
141
|
+
description: >
|
|
142
|
+
Client authentication response. Contains the method and
|
|
143
|
+
either a signature+public_key (pubkey) or password (password).
|
|
144
|
+
|
|
145
|
+
The pubkey signature is over the transcript
|
|
146
|
+
SHA-256("wsh-v1\0" || lp(username) || lp(session_id) || nonce || channel_binding)
|
|
147
|
+
(lp = 4-byte big-endian length prefix). channel_binding (wsh #119)
|
|
148
|
+
is empty unless both ends agree to bind it, which makes the
|
|
149
|
+
signature specific to the connection it was made over, so an
|
|
150
|
+
intermediary that relays a genuine challenge to the host cannot use
|
|
151
|
+
the signature it gets back. It is
|
|
152
|
+
SHA-256("wsh-channel-binding-v1\0" || lp(kind) || lp(value) ...)
|
|
153
|
+
over the kinds present, in this order, with these values:
|
|
154
|
+
cert-hash the 32-byte SHA-256 of the WebTransport certificate
|
|
155
|
+
pinned through serverCertificateHashes (a client
|
|
156
|
+
with exactly one pinned hash; a host serving a
|
|
157
|
+
self-signed certificate)
|
|
158
|
+
host the raw 32-byte Ed25519 host key that proved
|
|
159
|
+
possession in ServerHello (host-key features), so a
|
|
160
|
+
relay presenting its own host key binds to ITS key
|
|
161
|
+
tls-exporter 32 bytes of TLS keying material, label
|
|
162
|
+
"EXPORTER-wsh-channel-binding", empty context
|
|
163
|
+
(RFC 5705 / RFC 8446 7.5), where both ends can
|
|
164
|
+
compute it (Node over wss:// served by the process
|
|
165
|
+
itself; never a browser, never behind a
|
|
166
|
+
TLS-terminating proxy)
|
|
167
|
+
Negotiation is by feature string only: a host lists
|
|
168
|
+
"channel-binding:<kind>" in ServerHello.features for each kind it
|
|
169
|
+
can bind and "channel-binding-required" when it will accept no
|
|
170
|
+
login without one; a client binds every kind the host offers and it
|
|
171
|
+
can supply and signs that; the host accepts the signature over any
|
|
172
|
+
non-empty combination of the kinds it offered (the empty binding
|
|
173
|
+
only when it does not require one, and it requires the kinds it
|
|
174
|
+
names). With no kind the binding is the empty byte string, exactly
|
|
175
|
+
the transcript released peers sign, so they keep working. A client
|
|
176
|
+
that must not authenticate unbound refuses when it ends up with no
|
|
177
|
+
kind -- which also defeats an intermediary stripping the offer.
|
|
178
|
+
|
|
179
|
+
Test vectors (channel_binding = SHA-256 of the layout above, kinds
|
|
180
|
+
filled with one repeated byte, 32 bytes each):
|
|
181
|
+
host = 0x22*32
|
|
182
|
+
266d39f1ffe60713ab836382fa8373407c8facaa88a3ddaf80c1cd5433e80dcc
|
|
183
|
+
cert-hash = 0x11*32, host = 0x22*32, tls-exporter = 0x33*32
|
|
184
|
+
dc2256bcbd4bff249870321a14390d305147a1e4e6dc701c0a3fc3dfff750da7
|
|
185
|
+
fields:
|
|
186
|
+
method:
|
|
187
|
+
type: AuthMethod
|
|
188
|
+
required: true
|
|
189
|
+
signature:
|
|
190
|
+
type: bytes
|
|
191
|
+
required: false
|
|
192
|
+
public_key:
|
|
193
|
+
type: bytes
|
|
194
|
+
required: false
|
|
195
|
+
password:
|
|
196
|
+
type: string
|
|
197
|
+
required: false
|
|
198
|
+
|
|
199
|
+
AuthOk:
|
|
200
|
+
code: 0x06
|
|
201
|
+
description: >
|
|
202
|
+
Sent by the server on successful authentication. Contains
|
|
203
|
+
the session_id, an opaque connection token, and the connection
|
|
204
|
+
lifetime. Neither field is a credential: token and ttl are kept
|
|
205
|
+
on the wire only because released peers require them (they are
|
|
206
|
+
not optional in 0.35 / rust-v0.6.0 clients).
|
|
207
|
+
fields:
|
|
208
|
+
session_id:
|
|
209
|
+
type: string
|
|
210
|
+
required: true
|
|
211
|
+
token:
|
|
212
|
+
type: bytes
|
|
213
|
+
required: true
|
|
214
|
+
description: >
|
|
215
|
+
An opaque per-connection value. It carries no authority: no
|
|
216
|
+
message accepts it back (Resume and Attach use the per-session
|
|
217
|
+
token from OpenOk, never this one), a host MUST NOT treat it as
|
|
218
|
+
a credential, and a client MUST NOT present it as one. Before
|
|
219
|
+
wsh 0.36 this text called it "a signed session token"; the
|
|
220
|
+
Rust host still sends an HMAC there, which nothing verifies.
|
|
221
|
+
ttl:
|
|
222
|
+
type: u64
|
|
223
|
+
required: true
|
|
224
|
+
description: >
|
|
225
|
+
Seconds this host will keep the connection before it ends it;
|
|
226
|
+
0 means no limit is promised. A host that sends a non-zero ttl
|
|
227
|
+
MUST end the connection when it elapses (the client reconnects
|
|
228
|
+
and authenticates again); the JS host does so when started
|
|
229
|
+
with connectionTtlMs, and sends 0 otherwise. Before wsh 0.36 the
|
|
230
|
+
JS host sent a fixed 3600 it never enforced, and the Rust
|
|
231
|
+
host sends its session_ttl setting (default 86400) likewise
|
|
232
|
+
unenforced -- a client must not rely on a non-zero ttl from a
|
|
233
|
+
host that does not advertise otherwise.
|
|
234
|
+
|
|
235
|
+
AuthFail:
|
|
236
|
+
code: 0x07
|
|
237
|
+
description: >
|
|
238
|
+
Sent by the server when authentication fails.
|
|
239
|
+
fields:
|
|
240
|
+
reason:
|
|
241
|
+
type: string
|
|
242
|
+
required: true
|
|
243
|
+
|
|
244
|
+
channel:
|
|
245
|
+
Open:
|
|
246
|
+
code: 0x10
|
|
247
|
+
description: >
|
|
248
|
+
Request to open a new channel (PTY, exec, meta, or file).
|
|
249
|
+
The server replies with OpenOk or OpenFail.
|
|
250
|
+
fields:
|
|
251
|
+
kind:
|
|
252
|
+
type: ChannelKind
|
|
253
|
+
required: true
|
|
254
|
+
command:
|
|
255
|
+
type: string
|
|
256
|
+
required: false
|
|
257
|
+
cols:
|
|
258
|
+
type: u16
|
|
259
|
+
required: false
|
|
260
|
+
rows:
|
|
261
|
+
type: u16
|
|
262
|
+
required: false
|
|
263
|
+
env:
|
|
264
|
+
type: "map<string,string>"
|
|
265
|
+
required: false
|
|
266
|
+
stdio:
|
|
267
|
+
type: string
|
|
268
|
+
required: false
|
|
269
|
+
description: >
|
|
270
|
+
Only for `exec` channels. `"pipes"` asks the host to run the
|
|
271
|
+
command on plain pipes instead of a PTY: no echo, no terminal
|
|
272
|
+
rewriting of input, stdout and stderr kept apart, and an EOF
|
|
273
|
+
signal for stdin (a zero-length SessionData from the client).
|
|
274
|
+
Send it only to a host that advertises the `exec-pipes` feature
|
|
275
|
+
in ServerHello.features; an older host rejects the unknown field.
|
|
276
|
+
Omitted (or `"pty"`) is the historical PTY behaviour.
|
|
277
|
+
target:
|
|
278
|
+
type: string
|
|
279
|
+
required: false
|
|
280
|
+
description: >
|
|
281
|
+
Which of the host's execution targets (a container, a VM, a
|
|
282
|
+
worker, a sandbox) this channel runs on or reads from. Send it
|
|
283
|
+
only to a host that advertises the `targets` feature in
|
|
284
|
+
ServerHello.features; an older host rejects the unknown field.
|
|
285
|
+
Omitted: the host's own default, exactly as before. A host that
|
|
286
|
+
does not know the name, or does not allow the caller on it,
|
|
287
|
+
answers OpenFail with the same reason for both (the answer does
|
|
288
|
+
not reveal which targets exist); it never runs the channel
|
|
289
|
+
somewhere else. Discover the names with ListTargets.
|
|
290
|
+
|
|
291
|
+
OpenOk:
|
|
292
|
+
code: 0x11
|
|
293
|
+
description: >
|
|
294
|
+
Sent by the server to confirm a channel was opened successfully.
|
|
295
|
+
Contains the assigned channel_id and any associated stream_ids.
|
|
296
|
+
fields:
|
|
297
|
+
channel_id:
|
|
298
|
+
type: u32
|
|
299
|
+
required: true
|
|
300
|
+
stream_ids:
|
|
301
|
+
type: "u32[]"
|
|
302
|
+
default: "[]"
|
|
303
|
+
data_mode:
|
|
304
|
+
type: SessionDataMode
|
|
305
|
+
default: '"stream"'
|
|
306
|
+
capabilities:
|
|
307
|
+
type: "string[]"
|
|
308
|
+
default: "[]"
|
|
309
|
+
session_id:
|
|
310
|
+
type: string
|
|
311
|
+
required: false
|
|
312
|
+
description: >
|
|
313
|
+
Present only for pty/exec channels (session-bearing kinds; omitted
|
|
314
|
+
for file channels, which have no Attach/Resume-able session).
|
|
315
|
+
The server-assigned session_id this channel belongs to -- pass it
|
|
316
|
+
to Attach/Resume from another connection, or discover it later via
|
|
317
|
+
SessionList.
|
|
318
|
+
token:
|
|
319
|
+
type: bytes
|
|
320
|
+
required: false
|
|
321
|
+
description: >
|
|
322
|
+
Present only alongside session_id. An HMAC-SHA256 credential
|
|
323
|
+
(see wsh-core's token module) scoped to this specific session_id,
|
|
324
|
+
minted at Open time. Resume requires presenting this exact token
|
|
325
|
+
back; Attach accepts it as an alternative to (not a replacement
|
|
326
|
+
for) ownership/ACL-grant authorization -- see Attach's
|
|
327
|
+
description for the reasoning.
|
|
328
|
+
stderr_channel_id:
|
|
329
|
+
type: u32
|
|
330
|
+
required: false
|
|
331
|
+
description: >
|
|
332
|
+
Present only when the host granted `Open.stdio = "pipes"`. The
|
|
333
|
+
command's stderr arrives as SessionData on this channel id (the
|
|
334
|
+
channel_id field itself carries stdout), always before the
|
|
335
|
+
channel's Exit. The OpenOk then also lists `stdin-eof` in
|
|
336
|
+
`capabilities`: a zero-length SessionData from the client on
|
|
337
|
+
`channel_id` closes the command's stdin. stderr is not retained
|
|
338
|
+
for Attach/Resume replay.
|
|
339
|
+
|
|
340
|
+
OpenFail:
|
|
341
|
+
code: 0x12
|
|
342
|
+
description: >
|
|
343
|
+
Sent by the server when a channel open request fails.
|
|
344
|
+
fields:
|
|
345
|
+
reason:
|
|
346
|
+
type: string
|
|
347
|
+
required: true
|
|
348
|
+
|
|
349
|
+
SessionData:
|
|
350
|
+
code: 0x17
|
|
351
|
+
description: >
|
|
352
|
+
Bidirectional data frame for sessions that use virtual message-backed
|
|
353
|
+
transport instead of transport-opened byte streams.
|
|
354
|
+
fields:
|
|
355
|
+
channel_id:
|
|
356
|
+
type: u32
|
|
357
|
+
required: true
|
|
358
|
+
data:
|
|
359
|
+
type: bytes
|
|
360
|
+
required: true
|
|
361
|
+
|
|
362
|
+
Resize:
|
|
363
|
+
code: 0x13
|
|
364
|
+
description: >
|
|
365
|
+
Sent by the client to resize a PTY channel's terminal dimensions.
|
|
366
|
+
fields:
|
|
367
|
+
channel_id:
|
|
368
|
+
type: u32
|
|
369
|
+
required: true
|
|
370
|
+
cols:
|
|
371
|
+
type: u16
|
|
372
|
+
required: true
|
|
373
|
+
rows:
|
|
374
|
+
type: u16
|
|
375
|
+
required: true
|
|
376
|
+
|
|
377
|
+
Signal:
|
|
378
|
+
code: 0x14
|
|
379
|
+
description: >
|
|
380
|
+
Sent by the client to deliver a signal to the process group
|
|
381
|
+
associated with a channel (e.g. SIGINT, SIGTERM).
|
|
382
|
+
fields:
|
|
383
|
+
channel_id:
|
|
384
|
+
type: u32
|
|
385
|
+
required: true
|
|
386
|
+
signal:
|
|
387
|
+
type: string
|
|
388
|
+
required: true
|
|
389
|
+
|
|
390
|
+
Exit:
|
|
391
|
+
code: 0x15
|
|
392
|
+
description: >
|
|
393
|
+
Sent by the server when the process in a channel exits.
|
|
394
|
+
Contains the exit code of the terminated process.
|
|
395
|
+
fields:
|
|
396
|
+
channel_id:
|
|
397
|
+
type: u32
|
|
398
|
+
required: true
|
|
399
|
+
code:
|
|
400
|
+
type: i32
|
|
401
|
+
required: true
|
|
402
|
+
|
|
403
|
+
Close:
|
|
404
|
+
code: 0x16
|
|
405
|
+
description: >
|
|
406
|
+
Sent by either side to close a channel and release its resources.
|
|
407
|
+
fields:
|
|
408
|
+
channel_id:
|
|
409
|
+
type: u32
|
|
410
|
+
required: true
|
|
411
|
+
|
|
412
|
+
transport:
|
|
413
|
+
Error:
|
|
414
|
+
code: 0x20
|
|
415
|
+
description: >
|
|
416
|
+
Generic error message sent by either side. Contains a numeric
|
|
417
|
+
code and human-readable message.
|
|
418
|
+
fields:
|
|
419
|
+
code:
|
|
420
|
+
type: u32
|
|
421
|
+
required: true
|
|
422
|
+
message:
|
|
423
|
+
type: string
|
|
424
|
+
required: true
|
|
425
|
+
|
|
426
|
+
Ping:
|
|
427
|
+
code: 0x21
|
|
428
|
+
description: >
|
|
429
|
+
Keepalive ping. The peer must reply with Pong using the same id.
|
|
430
|
+
fields:
|
|
431
|
+
id:
|
|
432
|
+
type: u64
|
|
433
|
+
required: true
|
|
434
|
+
|
|
435
|
+
Pong:
|
|
436
|
+
code: 0x22
|
|
437
|
+
description: >
|
|
438
|
+
Keepalive pong. Echoes the id from the corresponding Ping.
|
|
439
|
+
fields:
|
|
440
|
+
id:
|
|
441
|
+
type: u64
|
|
442
|
+
required: true
|
|
443
|
+
|
|
444
|
+
session:
|
|
445
|
+
Attach:
|
|
446
|
+
code: 0x30
|
|
447
|
+
description: >
|
|
448
|
+
Attach to an existing session. The server replays the ring buffer
|
|
449
|
+
and broadcasts Presence.
|
|
450
|
+
|
|
451
|
+
Authorization is satisfied by EITHER a valid session token OR the
|
|
452
|
+
caller already owning/having been granted access to the session
|
|
453
|
+
(see the server's check_session_access) -- token is optional and,
|
|
454
|
+
if present but invalid, does not by itself cause rejection as long
|
|
455
|
+
as ownership/ACL access checks out. This lets a principal who was
|
|
456
|
+
granted access via SessionGrant (and so never received the
|
|
457
|
+
session's token -- only its owner does, from OpenOk) attach without
|
|
458
|
+
one, while still letting a token holder attach even without an
|
|
459
|
+
explicit ACL grant (e.g. the owner reconnecting from a fresh
|
|
460
|
+
connection that hasn't otherwise proven ownership yet). Compare
|
|
461
|
+
Resume, which requires the token unconditionally -- Resume is for
|
|
462
|
+
the specific case of the original credentialed connection coming
|
|
463
|
+
back, where demanding proof of that exact credential is meaningful;
|
|
464
|
+
Attach is the general "some authorized principal wants in" case,
|
|
465
|
+
where check_session_access is already the authoritative check.
|
|
466
|
+
fields:
|
|
467
|
+
session_id:
|
|
468
|
+
type: string
|
|
469
|
+
required: true
|
|
470
|
+
token:
|
|
471
|
+
type: bytes
|
|
472
|
+
required: false
|
|
473
|
+
mode:
|
|
474
|
+
type: string
|
|
475
|
+
default: '"control"'
|
|
476
|
+
device_label:
|
|
477
|
+
type: string
|
|
478
|
+
required: false
|
|
479
|
+
description: "Human-readable device/platform label (e.g. 'Chrome/macOS', 'wsh-cli/Linux')"
|
|
480
|
+
|
|
481
|
+
Resume:
|
|
482
|
+
code: 0x31
|
|
483
|
+
description: >
|
|
484
|
+
Resume a session from a specific sequence number. Like Attach
|
|
485
|
+
but replays only output after last_seq for efficient reconnection.
|
|
486
|
+
|
|
487
|
+
seq is the cumulative number of session OUTPUT BYTES: the host
|
|
488
|
+
counts every byte it produces for the session (stream data or
|
|
489
|
+
SessionData alike) from 0, and a client counts the bytes it has
|
|
490
|
+
received. No per-frame field is needed. A host that keeps a
|
|
491
|
+
bounded history replays from last_seq, and refuses a last_seq
|
|
492
|
+
older than its oldest retained byte (Error naming the gap -- fall
|
|
493
|
+
back to Attach) or newer than it has produced. Hosts that retain
|
|
494
|
+
the whole ring and ignore last_seq remain conformant, replaying
|
|
495
|
+
more than was asked for (both the Node host and the Rust wsh-server
|
|
496
|
+
honour it).
|
|
497
|
+
|
|
498
|
+
The Presence that answers a successful Attach/Resume carries, on
|
|
499
|
+
the entry for the caller, the channel_id assigned on this
|
|
500
|
+
connection and the seq of the first byte that will arrive on it
|
|
501
|
+
(see AttachmentInfo); the replay and the live output follow as
|
|
502
|
+
SessionData on that channel.
|
|
503
|
+
|
|
504
|
+
Unlike Attach, token is required and unconditionally verified --
|
|
505
|
+
Resume is specifically the "the credentialed connection that
|
|
506
|
+
received this exact token (from OpenOk, when it opened the
|
|
507
|
+
session) is coming back" case, so demanding proof of that
|
|
508
|
+
credential is the whole point. A principal who only has
|
|
509
|
+
ACL/ownership access but never held the token should use Attach
|
|
510
|
+
instead.
|
|
511
|
+
fields:
|
|
512
|
+
session_id:
|
|
513
|
+
type: string
|
|
514
|
+
required: true
|
|
515
|
+
token:
|
|
516
|
+
type: bytes
|
|
517
|
+
required: true
|
|
518
|
+
last_seq:
|
|
519
|
+
type: u64
|
|
520
|
+
required: true
|
|
521
|
+
description: >
|
|
522
|
+
The cumulative number of session OUTPUT BYTES the client has
|
|
523
|
+
already received for this session (its `seq`): the host counts
|
|
524
|
+
every byte it produces for a session -- on a stream, or in
|
|
525
|
+
SessionData -- from 0, and the client, which sees each of them,
|
|
526
|
+
counts what arrived. The host replays only the bytes at and
|
|
527
|
+
after that position. 0 means "from the start". A host that
|
|
528
|
+
keeps a bounded history refuses a last_seq older than the
|
|
529
|
+
oldest byte it still has (an Error naming the gap; fall back to
|
|
530
|
+
Attach) or newer than it has produced. Hosts that retain the
|
|
531
|
+
whole ring and ignore last_seq are conformant but replay more
|
|
532
|
+
than was asked for (the Node and Rust hosts both honour it).
|
|
533
|
+
|
|
534
|
+
Rename:
|
|
535
|
+
code: 0x32
|
|
536
|
+
description: >
|
|
537
|
+
Rename a session. Sent by the client to assign a human-readable
|
|
538
|
+
name to the session.
|
|
539
|
+
fields:
|
|
540
|
+
session_id:
|
|
541
|
+
type: string
|
|
542
|
+
required: true
|
|
543
|
+
name:
|
|
544
|
+
type: string
|
|
545
|
+
required: true
|
|
546
|
+
|
|
547
|
+
IdleWarning:
|
|
548
|
+
code: 0x33
|
|
549
|
+
description: >
|
|
550
|
+
Sent by the server when a session is approaching its idle
|
|
551
|
+
timeout. The expires_in field indicates seconds remaining.
|
|
552
|
+
fields:
|
|
553
|
+
expires_in:
|
|
554
|
+
type: u64
|
|
555
|
+
required: true
|
|
556
|
+
|
|
557
|
+
Shutdown:
|
|
558
|
+
code: 0x34
|
|
559
|
+
description: >
|
|
560
|
+
Sent by the server on graceful shutdown (SIGTERM). Clients
|
|
561
|
+
should save state and optionally retry after retry_after seconds.
|
|
562
|
+
fields:
|
|
563
|
+
reason:
|
|
564
|
+
type: string
|
|
565
|
+
required: true
|
|
566
|
+
retry_after:
|
|
567
|
+
type: u64
|
|
568
|
+
required: false
|
|
569
|
+
|
|
570
|
+
Snapshot:
|
|
571
|
+
code: 0x35
|
|
572
|
+
description: >
|
|
573
|
+
EXPERIMENTAL, not yet functional: intended to mark a named
|
|
574
|
+
position in the session recording for time-travel. The Rust
|
|
575
|
+
server currently accepts and authorizes this message but only
|
|
576
|
+
logs it -- RecordingEvent::Snapshot (and every other
|
|
577
|
+
RecordingEvent variant besides Start) is never actually
|
|
578
|
+
constructed, so nothing is written to the recording. No JS
|
|
579
|
+
client support exists.
|
|
580
|
+
fields:
|
|
581
|
+
label:
|
|
582
|
+
type: string
|
|
583
|
+
required: true
|
|
584
|
+
|
|
585
|
+
Presence:
|
|
586
|
+
code: 0x36
|
|
587
|
+
description: >
|
|
588
|
+
Broadcast to all attached clients when attachments change.
|
|
589
|
+
Lists all currently attached sessions with their access modes.
|
|
590
|
+
fields:
|
|
591
|
+
attachments:
|
|
592
|
+
type: "AttachmentInfo[]"
|
|
593
|
+
required: true
|
|
594
|
+
|
|
595
|
+
ControlChanged:
|
|
596
|
+
code: 0x37
|
|
597
|
+
description: >
|
|
598
|
+
Broadcast when the controlling client of a session changes.
|
|
599
|
+
fields:
|
|
600
|
+
new_controller:
|
|
601
|
+
type: string
|
|
602
|
+
required: true
|
|
603
|
+
|
|
604
|
+
Metrics:
|
|
605
|
+
code: 0x38
|
|
606
|
+
description: >
|
|
607
|
+
Server metrics snapshot (CPU, memory, session count, RTT).
|
|
608
|
+
Sent in response to MetricsRequest.
|
|
609
|
+
fields:
|
|
610
|
+
cpu:
|
|
611
|
+
type: f64
|
|
612
|
+
required: false
|
|
613
|
+
memory:
|
|
614
|
+
type: u64
|
|
615
|
+
required: false
|
|
616
|
+
sessions:
|
|
617
|
+
type: u32
|
|
618
|
+
required: false
|
|
619
|
+
rtt:
|
|
620
|
+
type: u64
|
|
621
|
+
required: false
|
|
622
|
+
|
|
623
|
+
Clipboard:
|
|
624
|
+
code: 0x39
|
|
625
|
+
description: >
|
|
626
|
+
Clipboard sync message for OSC 52 support. The server detects
|
|
627
|
+
OSC 52 escape sequences in PTY output, extracts the base64
|
|
628
|
+
payload, and sends this message to the client. The client may
|
|
629
|
+
also send this message to set the server-side clipboard.
|
|
630
|
+
fields:
|
|
631
|
+
direction:
|
|
632
|
+
type: string
|
|
633
|
+
required: true
|
|
634
|
+
description: '"server_to_client" or "client_to_server"'
|
|
635
|
+
data:
|
|
636
|
+
type: string
|
|
637
|
+
required: true
|
|
638
|
+
description: "Base64-encoded clipboard content"
|
|
639
|
+
|
|
640
|
+
RecordingExport:
|
|
641
|
+
code: 0x3a
|
|
642
|
+
description: >
|
|
643
|
+
Request or deliver a session recording export. When sent by client,
|
|
644
|
+
requests the recording. When sent by server, delivers the JSONL data.
|
|
645
|
+
fields:
|
|
646
|
+
session_id:
|
|
647
|
+
type: string
|
|
648
|
+
required: true
|
|
649
|
+
format:
|
|
650
|
+
type: string
|
|
651
|
+
default: '"jsonl"'
|
|
652
|
+
description: '"jsonl" or "asciicast"'
|
|
653
|
+
data:
|
|
654
|
+
type: string
|
|
655
|
+
required: false
|
|
656
|
+
description: "Recording content (only in server response)"
|
|
657
|
+
|
|
658
|
+
CommandJournal:
|
|
659
|
+
code: 0x3b
|
|
660
|
+
description: >
|
|
661
|
+
Structured shell command history entry with metadata.
|
|
662
|
+
fields:
|
|
663
|
+
session_id:
|
|
664
|
+
type: string
|
|
665
|
+
required: true
|
|
666
|
+
command:
|
|
667
|
+
type: string
|
|
668
|
+
required: true
|
|
669
|
+
exit_code:
|
|
670
|
+
type: i32
|
|
671
|
+
required: false
|
|
672
|
+
duration_ms:
|
|
673
|
+
type: u64
|
|
674
|
+
required: false
|
|
675
|
+
cwd:
|
|
676
|
+
type: string
|
|
677
|
+
required: false
|
|
678
|
+
timestamp:
|
|
679
|
+
type: u64
|
|
680
|
+
required: true
|
|
681
|
+
|
|
682
|
+
MetricsRequest:
|
|
683
|
+
code: 0x3c
|
|
684
|
+
description: >
|
|
685
|
+
Client request for server metrics.
|
|
686
|
+
fields: {}
|
|
687
|
+
|
|
688
|
+
SuspendSession:
|
|
689
|
+
code: 0x3d
|
|
690
|
+
description: >
|
|
691
|
+
Suspend or resume a session's PTY process (SIGSTOP/SIGCONT).
|
|
692
|
+
fields:
|
|
693
|
+
session_id:
|
|
694
|
+
type: string
|
|
695
|
+
required: true
|
|
696
|
+
action:
|
|
697
|
+
type: string
|
|
698
|
+
required: true
|
|
699
|
+
description: '"suspend" or "resume"'
|
|
700
|
+
|
|
701
|
+
RestartPty:
|
|
702
|
+
code: 0x3e
|
|
703
|
+
description: >
|
|
704
|
+
Restart the PTY shell without killing the session.
|
|
705
|
+
Preserves session metadata and ring buffer.
|
|
706
|
+
fields:
|
|
707
|
+
session_id:
|
|
708
|
+
type: string
|
|
709
|
+
required: true
|
|
710
|
+
command:
|
|
711
|
+
type: string
|
|
712
|
+
required: false
|
|
713
|
+
description: "New command to run (default: user shell)"
|
|
714
|
+
|
|
715
|
+
SessionListRequest:
|
|
716
|
+
code: 0x3f
|
|
717
|
+
description: >
|
|
718
|
+
Request a list of sessions visible to the authenticated user.
|
|
719
|
+
The server replies with SessionList.
|
|
720
|
+
fields: {}
|
|
721
|
+
|
|
722
|
+
SessionList:
|
|
723
|
+
code: 0x5f
|
|
724
|
+
description: >
|
|
725
|
+
Server response to SessionListRequest. Contains summarized
|
|
726
|
+
metadata for each visible session.
|
|
727
|
+
fields:
|
|
728
|
+
sessions:
|
|
729
|
+
type: "SessionSummary[]"
|
|
730
|
+
required: true
|
|
731
|
+
|
|
732
|
+
Detach:
|
|
733
|
+
code: 0x60
|
|
734
|
+
description: >
|
|
735
|
+
Detach the current client from a specific session.
|
|
736
|
+
fields:
|
|
737
|
+
session_id:
|
|
738
|
+
type: string
|
|
739
|
+
required: true
|
|
740
|
+
|
|
741
|
+
DetachOk:
|
|
742
|
+
code: 0x61
|
|
743
|
+
description: >
|
|
744
|
+
Server acknowledgment for a successful detach operation.
|
|
745
|
+
fields:
|
|
746
|
+
session_id:
|
|
747
|
+
type: string
|
|
748
|
+
required: true
|
|
749
|
+
|
|
750
|
+
DetachFail:
|
|
751
|
+
code: 0x62
|
|
752
|
+
description: >
|
|
753
|
+
Server response when detaching from a session fails.
|
|
754
|
+
fields:
|
|
755
|
+
reason:
|
|
756
|
+
type: string
|
|
757
|
+
required: true
|
|
758
|
+
|
|
759
|
+
mcp:
|
|
760
|
+
McpDiscover:
|
|
761
|
+
code: 0x40
|
|
762
|
+
description: >
|
|
763
|
+
Request the list of available MCP tools from the server.
|
|
764
|
+
The server replies with McpTools.
|
|
765
|
+
fields: {}
|
|
766
|
+
|
|
767
|
+
McpTools:
|
|
768
|
+
code: 0x41
|
|
769
|
+
description: >
|
|
770
|
+
Server response to McpDiscover. Lists all available MCP tools
|
|
771
|
+
with their names, descriptions, and parameter schemas.
|
|
772
|
+
fields:
|
|
773
|
+
tools:
|
|
774
|
+
type: "McpToolSpec[]"
|
|
775
|
+
required: true
|
|
776
|
+
|
|
777
|
+
McpCall:
|
|
778
|
+
code: 0x42
|
|
779
|
+
description: >
|
|
780
|
+
Invoke an MCP tool by name with JSON arguments.
|
|
781
|
+
The server replies with McpResult carrying the same call_id.
|
|
782
|
+
fields:
|
|
783
|
+
tool:
|
|
784
|
+
type: string
|
|
785
|
+
required: true
|
|
786
|
+
arguments:
|
|
787
|
+
type: json
|
|
788
|
+
required: true
|
|
789
|
+
call_id:
|
|
790
|
+
type: string
|
|
791
|
+
required: false
|
|
792
|
+
description: >
|
|
793
|
+
Correlates this call with its McpResult. Optional for
|
|
794
|
+
backward compatibility with peers predating it: when absent,
|
|
795
|
+
a client with more than one call in flight cannot tell the
|
|
796
|
+
replies apart and may return one call's result to another.
|
|
797
|
+
Senders SHOULD always set it.
|
|
798
|
+
|
|
799
|
+
McpResult:
|
|
800
|
+
code: 0x43
|
|
801
|
+
description: >
|
|
802
|
+
Result of an MCP tool invocation. Contains the tool's
|
|
803
|
+
JSON response.
|
|
804
|
+
fields:
|
|
805
|
+
result:
|
|
806
|
+
type: json
|
|
807
|
+
required: true
|
|
808
|
+
call_id:
|
|
809
|
+
type: string
|
|
810
|
+
required: false
|
|
811
|
+
description: >
|
|
812
|
+
Echoed verbatim from the McpCall this answers. Responders
|
|
813
|
+
MUST echo it when the call carried one; omitting it forces
|
|
814
|
+
the caller back on type-only matching.
|
|
815
|
+
|
|
816
|
+
McpCancel:
|
|
817
|
+
code: 0x44
|
|
818
|
+
description: >
|
|
819
|
+
Ask the server to stop an in-flight McpCall (the caller aborted).
|
|
820
|
+
Only sent to a server advertising the `mcp-cancel` feature, which
|
|
821
|
+
also advertises `mcp-call-id`: McpCancelPayload is
|
|
822
|
+
deny_unknown_fields on the Rust side, so an older server would
|
|
823
|
+
reject it. Best effort and idempotent -- a call that already
|
|
824
|
+
finished, or an unknown call_id, is ignored. The server aborts the
|
|
825
|
+
tool handler's signal and still answers the call with an McpResult
|
|
826
|
+
(a failure), which a caller that gave up simply discards.
|
|
827
|
+
fields:
|
|
828
|
+
call_id:
|
|
829
|
+
type: string
|
|
830
|
+
required: true
|
|
831
|
+
description: The call_id of the McpCall to stop.
|
|
832
|
+
|
|
833
|
+
reverse:
|
|
834
|
+
ReverseRegister:
|
|
835
|
+
code: 0x50
|
|
836
|
+
description: >
|
|
837
|
+
Register as a reverse peer so other clients can connect to
|
|
838
|
+
this client through the server. Includes the public key for
|
|
839
|
+
fingerprint derivation and advertised capabilities.
|
|
840
|
+
|
|
841
|
+
seq/record_signature form a self-certifying signed peer record
|
|
842
|
+
(libp2p RFC 0002/0003 pattern): the peer signs a domain-separated
|
|
843
|
+
transcript of its own registration fields with its identity key
|
|
844
|
+
(buildPeerRecordTranscript/signPeerRecord in auth.mjs -- a
|
|
845
|
+
distinct signing domain from the auth challenge transcript, even
|
|
846
|
+
though both use the same Ed25519 key). The server verifies this
|
|
847
|
+
against the connection's own authenticated fingerprint (closing
|
|
848
|
+
the impersonation surface where a client could otherwise claim
|
|
849
|
+
someone else's public_key) before accepting registration, and
|
|
850
|
+
forwards the same signed fields in PeerInfo so operators can
|
|
851
|
+
verify a peer's record themselves -- independent of trusting the
|
|
852
|
+
relay -- rather than trusting server-computed fields blindly.
|
|
853
|
+
seq is the signing peer's own monotonic counter (in practice
|
|
854
|
+
current-time-millis); a server/operator MUST reject a record
|
|
855
|
+
whose seq is not greater than the last one accepted for that
|
|
856
|
+
fingerprint, so a compromised or malicious relay can't replay a
|
|
857
|
+
stale (e.g. revoked-capability) record over a newer one.
|
|
858
|
+
fields:
|
|
859
|
+
username:
|
|
860
|
+
type: string
|
|
861
|
+
required: true
|
|
862
|
+
capabilities:
|
|
863
|
+
type: "string[]"
|
|
864
|
+
default: "[]"
|
|
865
|
+
peer_type:
|
|
866
|
+
type: string
|
|
867
|
+
default: '"host"'
|
|
868
|
+
shell_backend:
|
|
869
|
+
type: string
|
|
870
|
+
default: '"pty"'
|
|
871
|
+
supports_attach:
|
|
872
|
+
type: bool
|
|
873
|
+
default: false
|
|
874
|
+
supports_replay:
|
|
875
|
+
type: bool
|
|
876
|
+
default: false
|
|
877
|
+
supports_echo:
|
|
878
|
+
type: bool
|
|
879
|
+
default: false
|
|
880
|
+
supports_term_sync:
|
|
881
|
+
type: bool
|
|
882
|
+
default: false
|
|
883
|
+
public_key:
|
|
884
|
+
type: bytes
|
|
885
|
+
required: true
|
|
886
|
+
seq:
|
|
887
|
+
type: u64
|
|
888
|
+
required: true
|
|
889
|
+
record_signature:
|
|
890
|
+
type: bytes
|
|
891
|
+
required: true
|
|
892
|
+
|
|
893
|
+
ReverseList:
|
|
894
|
+
code: 0x51
|
|
895
|
+
description: >
|
|
896
|
+
Request the list of registered reverse peers.
|
|
897
|
+
The server replies with ReversePeers.
|
|
898
|
+
fields: {}
|
|
899
|
+
|
|
900
|
+
ReversePeers:
|
|
901
|
+
code: 0x52
|
|
902
|
+
description: >
|
|
903
|
+
Server response to ReverseList. Contains information about
|
|
904
|
+
all currently registered reverse peers.
|
|
905
|
+
fields:
|
|
906
|
+
peers:
|
|
907
|
+
type: "PeerInfo[]"
|
|
908
|
+
required: true
|
|
909
|
+
|
|
910
|
+
ReverseConnect:
|
|
911
|
+
code: 0x53
|
|
912
|
+
description: >
|
|
913
|
+
Connect to a registered reverse peer by fingerprint.
|
|
914
|
+
The server forwards the request to the target peer.
|
|
915
|
+
from_fingerprint identifies the requesting operator and MUST be
|
|
916
|
+
set by the server from the operator's own authenticated identity
|
|
917
|
+
when forwarding to the target -- never trust a client-supplied
|
|
918
|
+
value for this field, since the whole point is telling the
|
|
919
|
+
target who is actually asking. Before this field existed, a
|
|
920
|
+
target peer's onReverseConnect handler had no reliable way to
|
|
921
|
+
know who was requesting the connection at all.
|
|
922
|
+
fields:
|
|
923
|
+
target_fingerprint:
|
|
924
|
+
type: string
|
|
925
|
+
required: true
|
|
926
|
+
username:
|
|
927
|
+
type: string
|
|
928
|
+
required: true
|
|
929
|
+
from_fingerprint:
|
|
930
|
+
type: string
|
|
931
|
+
required: true
|
|
932
|
+
features:
|
|
933
|
+
type: "string[]"
|
|
934
|
+
required: false
|
|
935
|
+
description: >
|
|
936
|
+
What the OPERATOR can do, stated by the operator and bounded and
|
|
937
|
+
copied by the relay: "operator-proof" says it answers a
|
|
938
|
+
ReverseChallenge with a ReverseProof (see ReverseChallenge). An
|
|
939
|
+
operator states it only when the relay's ServerHello lists
|
|
940
|
+
"operator-proof" -- a relay that predates the field (a Rust relay,
|
|
941
|
+
which rejects unknown fields) would drop the connection on it.
|
|
942
|
+
Absent: the peer must not send a ReverseChallenge.
|
|
943
|
+
|
|
944
|
+
ReverseAccept:
|
|
945
|
+
code: 0x54
|
|
946
|
+
description: >
|
|
947
|
+
Sent by the target peer after it has created a reverse peer context
|
|
948
|
+
and is ready to receive channel open requests.
|
|
949
|
+
fields:
|
|
950
|
+
target_fingerprint:
|
|
951
|
+
type: string
|
|
952
|
+
required: true
|
|
953
|
+
username:
|
|
954
|
+
type: string
|
|
955
|
+
required: true
|
|
956
|
+
capabilities:
|
|
957
|
+
type: "string[]"
|
|
958
|
+
default: "[]"
|
|
959
|
+
peer_type:
|
|
960
|
+
type: string
|
|
961
|
+
default: '"host"'
|
|
962
|
+
shell_backend:
|
|
963
|
+
type: string
|
|
964
|
+
default: '"pty"'
|
|
965
|
+
supports_attach:
|
|
966
|
+
type: bool
|
|
967
|
+
default: false
|
|
968
|
+
supports_replay:
|
|
969
|
+
type: bool
|
|
970
|
+
default: false
|
|
971
|
+
supports_echo:
|
|
972
|
+
type: bool
|
|
973
|
+
default: false
|
|
974
|
+
supports_term_sync:
|
|
975
|
+
type: bool
|
|
976
|
+
default: false
|
|
977
|
+
features:
|
|
978
|
+
type: "string[]"
|
|
979
|
+
required: false
|
|
980
|
+
description: >
|
|
981
|
+
Features of the bridged host itself, in the vocabulary of
|
|
982
|
+
ServerHello.features (e.g. file-write, file-rename,
|
|
983
|
+
mcp-call-id). A relay's own ServerHello says nothing about the
|
|
984
|
+
host behind a bridge, so the operator reads these instead once
|
|
985
|
+
the bridge is up. Empty or absent means "not stated": an
|
|
986
|
+
operator then falls back to what it knows (the relay's
|
|
987
|
+
features). The relay forwards the field after bounding it; it
|
|
988
|
+
is the peer's own claim, as everything else in this message.
|
|
989
|
+
|
|
990
|
+
One feature is addressed to the relay rather than the operator:
|
|
991
|
+
"relay-multi-operator" says this peer serves several operators at
|
|
992
|
+
once -- it addresses its replies with RelayForward.to_fingerprint
|
|
993
|
+
and understands ReverseClose. Only then does a relay configured
|
|
994
|
+
for more than one operator per peer admit a second one.
|
|
995
|
+
|
|
996
|
+
ReverseReject:
|
|
997
|
+
code: 0x55
|
|
998
|
+
description: >
|
|
999
|
+
Sent by the target peer when it cannot accept a pending reverse
|
|
1000
|
+
connection request.
|
|
1001
|
+
fields:
|
|
1002
|
+
target_fingerprint:
|
|
1003
|
+
type: string
|
|
1004
|
+
required: true
|
|
1005
|
+
username:
|
|
1006
|
+
type: string
|
|
1007
|
+
required: true
|
|
1008
|
+
reason:
|
|
1009
|
+
type: string
|
|
1010
|
+
required: true
|
|
1011
|
+
|
|
1012
|
+
ReverseClose:
|
|
1013
|
+
code: 0x57
|
|
1014
|
+
description: >
|
|
1015
|
+
Sent by the relay to a PEER that serves several operators, when one
|
|
1016
|
+
of them leaves (its connection ended, or it was dropped): the peer
|
|
1017
|
+
should end that operator's bridge and clean up what belongs to it
|
|
1018
|
+
(its channels, processes and trusted-sender entry) while the others
|
|
1019
|
+
carry on. target_fingerprint is the departed operator's key. A relay
|
|
1020
|
+
sends this only to a peer that stated "relay-multi-operator" in
|
|
1021
|
+
ReverseAccept.features and only when it is configured for more than
|
|
1022
|
+
one operator per peer; otherwise the old rule holds -- when the
|
|
1023
|
+
bridge ends the relay closes the peer's connection, and no
|
|
1024
|
+
ReverseClose is sent. It is not forwardable and travels only
|
|
1025
|
+
relay -> peer.
|
|
1026
|
+
fields:
|
|
1027
|
+
target_fingerprint:
|
|
1028
|
+
type: string
|
|
1029
|
+
required: true
|
|
1030
|
+
reason:
|
|
1031
|
+
type: string
|
|
1032
|
+
required: false
|
|
1033
|
+
|
|
1034
|
+
ReverseChallenge:
|
|
1035
|
+
code: 0x58
|
|
1036
|
+
description: >
|
|
1037
|
+
Peer -> operator, between a ReverseConnect and the peer's
|
|
1038
|
+
ReverseAccept/Reject (wsh #117): the peer asks the operator to prove
|
|
1039
|
+
its identity to the PEER, instead of the peer taking the identity
|
|
1040
|
+
the relay stamped on ReverseConnect.from_fingerprint on trust. Sent
|
|
1041
|
+
only to an operator that stated "operator-proof" in
|
|
1042
|
+
ReverseConnect.features, over a relay that lists "operator-proof"
|
|
1043
|
+
in its ServerHello; the relay carries it to the operator with
|
|
1044
|
+
target_fingerprint set to the answering peer, and does nothing else
|
|
1045
|
+
with it. The peer SIGNS the challenge so the operator knows whom it
|
|
1046
|
+
is about to prove itself to and that the peer saw the operator's own
|
|
1047
|
+
fingerprint (a relay that rewrote from_fingerprint shows up here).
|
|
1048
|
+
|
|
1049
|
+
signature (by the peer's Ed25519 identity key, public_key) covers
|
|
1050
|
+
"wsh-reverse-challenge-v1\0" || lp(public_key) || lp(operator_fingerprint)
|
|
1051
|
+
|| lp(nonce) || lp(session_id)
|
|
1052
|
+
where lp() is a 4-byte big-endian length prefix, operator_fingerprint
|
|
1053
|
+
is the from_fingerprint the peer received, nonce is 32 random bytes
|
|
1054
|
+
chosen by the peer for this request alone, and session_id is a fresh
|
|
1055
|
+
random string the peer chose for the bridge (it is also the
|
|
1056
|
+
session_id of a sealed bridge's KeyExchange). The operator verifies
|
|
1057
|
+
the signature, that the fingerprint of public_key is the peer it
|
|
1058
|
+
asked for, and that operator_fingerprint is its own; a peer accepts
|
|
1059
|
+
each nonce once, within seconds.
|
|
1060
|
+
fields:
|
|
1061
|
+
target_fingerprint:
|
|
1062
|
+
type: string
|
|
1063
|
+
required: true
|
|
1064
|
+
public_key:
|
|
1065
|
+
type: bytes
|
|
1066
|
+
required: true
|
|
1067
|
+
operator_fingerprint:
|
|
1068
|
+
type: string
|
|
1069
|
+
required: true
|
|
1070
|
+
nonce:
|
|
1071
|
+
type: bytes
|
|
1072
|
+
required: true
|
|
1073
|
+
session_id:
|
|
1074
|
+
type: string
|
|
1075
|
+
required: true
|
|
1076
|
+
signature:
|
|
1077
|
+
type: bytes
|
|
1078
|
+
required: true
|
|
1079
|
+
|
|
1080
|
+
ReverseProof:
|
|
1081
|
+
code: 0x59
|
|
1082
|
+
description: >
|
|
1083
|
+
Operator -> peer, answering a ReverseChallenge (wsh #117). The
|
|
1084
|
+
operator signs, with its Ed25519 identity key (public_key) that is
|
|
1085
|
+
also its login key at the relay,
|
|
1086
|
+
"wsh-operator-proof-v1\0" || lp(peer_public_key) || lp(public_key)
|
|
1087
|
+
|| lp(username) || lp(nonce) || lp(session_id)
|
|
1088
|
+
so the signature names the peer it is for (peer_public_key is the
|
|
1089
|
+
raw key from the verified ReverseChallenge), the operator's own key,
|
|
1090
|
+
the username it claims, and the peer's nonce and session id: it
|
|
1091
|
+
cannot be replayed to another peer, at another time, or for another
|
|
1092
|
+
bridge. The peer verifies it BEFORE its accept callback runs, takes
|
|
1093
|
+
the operator's identity from public_key (not from the relay's
|
|
1094
|
+
from_fingerprint) and refuses if the two differ. The relay stamps
|
|
1095
|
+
from_fingerprint on what it delivers; it is advisory here. A peer
|
|
1096
|
+
that requires operator proof refuses an operator that does not send
|
|
1097
|
+
one, and from then on acts only on traffic sealed under a key
|
|
1098
|
+
exchange both sides signed (see KeyExchange.signature), because a
|
|
1099
|
+
relay can stamp any from_fingerprint on a plain message.
|
|
1100
|
+
fields:
|
|
1101
|
+
target_fingerprint:
|
|
1102
|
+
type: string
|
|
1103
|
+
required: true
|
|
1104
|
+
public_key:
|
|
1105
|
+
type: bytes
|
|
1106
|
+
required: true
|
|
1107
|
+
username:
|
|
1108
|
+
type: string
|
|
1109
|
+
required: true
|
|
1110
|
+
nonce:
|
|
1111
|
+
type: bytes
|
|
1112
|
+
required: true
|
|
1113
|
+
session_id:
|
|
1114
|
+
type: string
|
|
1115
|
+
required: true
|
|
1116
|
+
signature:
|
|
1117
|
+
type: bytes
|
|
1118
|
+
required: true
|
|
1119
|
+
from_fingerprint:
|
|
1120
|
+
type: string
|
|
1121
|
+
required: false
|
|
1122
|
+
|
|
1123
|
+
RelayForward:
|
|
1124
|
+
code: 0x56
|
|
1125
|
+
description: >
|
|
1126
|
+
Wraps a message the relay is forwarding between two peers over an
|
|
1127
|
+
established reverse connection (post-handshake channel/session/
|
|
1128
|
+
tool traffic -- Open, Close, McpCall, SessionData, etc; see each
|
|
1129
|
+
message's relay_forwardable flag for the full set). from_fingerprint
|
|
1130
|
+
is the ORIGINATING peer's authenticated identity, set by the relay
|
|
1131
|
+
server -- never trust a client-supplied value. inner is the
|
|
1132
|
+
complete CBOR-encoded envelope bytes of the forwarded message,
|
|
1133
|
+
opaque at this layer (decode it as a normal envelope once
|
|
1134
|
+
from_fingerprint has been checked against the receiving client's
|
|
1135
|
+
own set of peers it has an accepted reverse-connection with, and
|
|
1136
|
+
the decoded inner message's type has been checked against the
|
|
1137
|
+
relay_forwardable allowlist). Introduced to close two gaps:
|
|
1138
|
+
forwarded traffic previously carried no sender identity at all,
|
|
1139
|
+
and the client/server relay_forwardable allowlists had drifted
|
|
1140
|
+
out of sync because each was hand-maintained separately instead
|
|
1141
|
+
of generated from one source of truth.
|
|
1142
|
+
fields:
|
|
1143
|
+
from_fingerprint:
|
|
1144
|
+
type: string
|
|
1145
|
+
required: true
|
|
1146
|
+
inner:
|
|
1147
|
+
type: bytes
|
|
1148
|
+
required: true
|
|
1149
|
+
to_fingerprint:
|
|
1150
|
+
type: string
|
|
1151
|
+
required: false
|
|
1152
|
+
description: >
|
|
1153
|
+
The operator a PEER's RelayForward is addressed to (peer -> relay
|
|
1154
|
+
only). Needed only when the peer serves several operators at once
|
|
1155
|
+
(the relay is then configured with maxOperatorsPerPeer > 1, and
|
|
1156
|
+
the peer stated "relay-multi-operator" in ReverseAccept.features):
|
|
1157
|
+
the relay routes the forward to that operator's connection and
|
|
1158
|
+
re-wraps it with from_fingerprint set to the peer. Absent: the
|
|
1159
|
+
peer's only operator, which is what every peer wrote before this
|
|
1160
|
+
field existed. The relay never sets it on what it delivers (the
|
|
1161
|
+
receiver already knows who it is), and an operator's RelayForward
|
|
1162
|
+
never needs it (an operator has one bridge, to one peer). A relay
|
|
1163
|
+
or peer that predates the field may reject a RelayForward carrying
|
|
1164
|
+
it, so a peer sends it only after the relay has admitted a second
|
|
1165
|
+
operator -- in practice only to a relay that was configured to.
|
|
1166
|
+
|
|
1167
|
+
# ── Gateway subsystem ────────────────────────────────────────────────
|
|
1168
|
+
# The gateway subsystem allows clients to tunnel TCP/UDP connections and
|
|
1169
|
+
# DNS lookups through the server, which acts as a network proxy. Clients
|
|
1170
|
+
# open outbound connections or listeners, and the server relays data
|
|
1171
|
+
# between the client's wsh channels and the external network. All
|
|
1172
|
+
# gateway messages share the 0x70-0x7f opcode range and use a
|
|
1173
|
+
# client-assigned gateway_id or listener_id to correlate requests with
|
|
1174
|
+
# responses.
|
|
1175
|
+
gateway:
|
|
1176
|
+
OpenTcp:
|
|
1177
|
+
code: 0x70
|
|
1178
|
+
description: >
|
|
1179
|
+
Sent by the client to request a TCP connection through the gateway.
|
|
1180
|
+
The server resolves the host, opens a TCP socket, and replies with
|
|
1181
|
+
GatewayOk on success or GatewayFail on error.
|
|
1182
|
+
fields:
|
|
1183
|
+
gateway_id:
|
|
1184
|
+
type: u32
|
|
1185
|
+
required: true
|
|
1186
|
+
host:
|
|
1187
|
+
type: string
|
|
1188
|
+
required: true
|
|
1189
|
+
port:
|
|
1190
|
+
type: u16
|
|
1191
|
+
required: true
|
|
1192
|
+
|
|
1193
|
+
OpenUdp:
|
|
1194
|
+
code: 0x71
|
|
1195
|
+
description: >
|
|
1196
|
+
Sent by the client to request a UDP socket through the gateway.
|
|
1197
|
+
The server binds a local UDP socket for relaying datagrams to the
|
|
1198
|
+
specified host:port and replies with GatewayOk or GatewayFail.
|
|
1199
|
+
The flow is to ONE destination, fixed here: replies are accepted
|
|
1200
|
+
only from that address and port, so it is never a relay to
|
|
1201
|
+
arbitrary peers.
|
|
1202
|
+
|
|
1203
|
+
Payloads travel as GatewayData (one per datagram) on the control
|
|
1204
|
+
stream, unless the transport is WebTransport and BOTH ends listed
|
|
1205
|
+
the feature "gateway-datagram" (the client in Hello.features, the
|
|
1206
|
+
host in ServerHello.features). Then each payload is a WebTransport
|
|
1207
|
+
datagram instead: the whole datagram is the 4-byte big-endian
|
|
1208
|
+
gateway_id of the flow followed by the UDP payload (no other
|
|
1209
|
+
header). Such a flow is not metered by GatewayCredit and nothing
|
|
1210
|
+
is retransmitted; a datagram that names an unknown gateway_id, or
|
|
1211
|
+
is shorter than 4 bytes, is dropped. A payload that does not fit
|
|
1212
|
+
the transport's maxDatagramSize minus 4 is sent as GatewayData on
|
|
1213
|
+
the control stream instead (a host may be configured to drop it).
|
|
1214
|
+
GatewayOk, GatewayFail and GatewayClose always use the control
|
|
1215
|
+
stream.
|
|
1216
|
+
fields:
|
|
1217
|
+
gateway_id:
|
|
1218
|
+
type: u32
|
|
1219
|
+
required: true
|
|
1220
|
+
host:
|
|
1221
|
+
type: string
|
|
1222
|
+
required: true
|
|
1223
|
+
port:
|
|
1224
|
+
type: u16
|
|
1225
|
+
required: true
|
|
1226
|
+
|
|
1227
|
+
ResolveDns:
|
|
1228
|
+
code: 0x72
|
|
1229
|
+
description: >
|
|
1230
|
+
Sent by the client to perform a DNS lookup through the gateway.
|
|
1231
|
+
The server resolves the given hostname and replies with DnsResult
|
|
1232
|
+
containing the resolved addresses, or GatewayFail on error.
|
|
1233
|
+
fields:
|
|
1234
|
+
gateway_id:
|
|
1235
|
+
type: u32
|
|
1236
|
+
required: true
|
|
1237
|
+
name:
|
|
1238
|
+
type: string
|
|
1239
|
+
required: true
|
|
1240
|
+
record_type:
|
|
1241
|
+
type: string
|
|
1242
|
+
default: '"A"'
|
|
1243
|
+
|
|
1244
|
+
GatewayOk:
|
|
1245
|
+
code: 0x73
|
|
1246
|
+
description: >
|
|
1247
|
+
Sent by the server to confirm that an OpenTcp or OpenUdp
|
|
1248
|
+
request succeeded. The gateway_id echoes the client's
|
|
1249
|
+
original request. resolved_addr contains the IP address
|
|
1250
|
+
the server connected to.
|
|
1251
|
+
fields:
|
|
1252
|
+
gateway_id:
|
|
1253
|
+
type: u32
|
|
1254
|
+
required: true
|
|
1255
|
+
resolved_addr:
|
|
1256
|
+
type: string
|
|
1257
|
+
required: false
|
|
1258
|
+
|
|
1259
|
+
GatewayFail:
|
|
1260
|
+
code: 0x74
|
|
1261
|
+
description: >
|
|
1262
|
+
Sent by the server when a gateway request (OpenTcp, OpenUdp,
|
|
1263
|
+
or ResolveDns) fails. The gateway_id echoes the client's
|
|
1264
|
+
original request so it can match the failure. ListenRequest
|
|
1265
|
+
failures use ListenFail instead.
|
|
1266
|
+
fields:
|
|
1267
|
+
gateway_id:
|
|
1268
|
+
type: u32
|
|
1269
|
+
required: true
|
|
1270
|
+
code:
|
|
1271
|
+
type: u32
|
|
1272
|
+
required: true
|
|
1273
|
+
description: >
|
|
1274
|
+
Machine-readable failure reason. Known values:
|
|
1275
|
+
1=CONNECTION_REFUSED, 2=HOST_UNREACHABLE, 3=DNS_FAILED,
|
|
1276
|
+
4=POLICY_DENIED, 5=GATEWAY_DISABLED, 6=CLOSED, 7=QUEUE_FULL.
|
|
1277
|
+
KNOWN INCONSISTENCY (documentation only, behaviour unchanged):
|
|
1278
|
+
the Rust wsh-server sends 5 for a disabled gateway, while the
|
|
1279
|
+
Node gateway (@johnhenry/wsh/server, the page and memory hosts)
|
|
1280
|
+
sends 5 for a timeout (TIMEOUT), and @johnhenry/browsermesh-netway
|
|
1281
|
+
names 5 TIMEOUT. A client that reads 5 should treat it as "timed
|
|
1282
|
+
out or disabled". 6 and 7 are sent by the Node gateway (the Rust
|
|
1283
|
+
server sends 7 for a full queue). The table is exported as data
|
|
1284
|
+
from @johnhenry/wsh (GATEWAY_FAIL_TABLE).
|
|
1285
|
+
message:
|
|
1286
|
+
type: string
|
|
1287
|
+
required: true
|
|
1288
|
+
|
|
1289
|
+
GatewayClose:
|
|
1290
|
+
code: 0x75
|
|
1291
|
+
description: >
|
|
1292
|
+
Sent by either side to close an open gateway channel. The client
|
|
1293
|
+
sends it to tear down a proxied connection; the server sends it
|
|
1294
|
+
when the remote peer disconnects or the connection is reset.
|
|
1295
|
+
fields:
|
|
1296
|
+
gateway_id:
|
|
1297
|
+
type: u32
|
|
1298
|
+
required: true
|
|
1299
|
+
reason:
|
|
1300
|
+
type: string
|
|
1301
|
+
required: false
|
|
1302
|
+
|
|
1303
|
+
InboundOpen:
|
|
1304
|
+
code: 0x76
|
|
1305
|
+
description: >
|
|
1306
|
+
Sent by the server when a new inbound connection arrives on an
|
|
1307
|
+
active listener. The client must reply with InboundAccept to
|
|
1308
|
+
accept the connection or InboundReject to refuse it.
|
|
1309
|
+
fields:
|
|
1310
|
+
listener_id:
|
|
1311
|
+
type: u32
|
|
1312
|
+
required: true
|
|
1313
|
+
channel_id:
|
|
1314
|
+
type: u32
|
|
1315
|
+
required: true
|
|
1316
|
+
peer_addr:
|
|
1317
|
+
type: string
|
|
1318
|
+
required: true
|
|
1319
|
+
peer_port:
|
|
1320
|
+
type: u16
|
|
1321
|
+
required: true
|
|
1322
|
+
|
|
1323
|
+
InboundAccept:
|
|
1324
|
+
code: 0x77
|
|
1325
|
+
description: >
|
|
1326
|
+
Sent by the client in response to InboundOpen to accept the
|
|
1327
|
+
inbound connection. After this, data flows over the channel
|
|
1328
|
+
identified by channel_id.
|
|
1329
|
+
fields:
|
|
1330
|
+
channel_id:
|
|
1331
|
+
type: u32
|
|
1332
|
+
required: true
|
|
1333
|
+
gateway_id:
|
|
1334
|
+
type: u32
|
|
1335
|
+
required: false
|
|
1336
|
+
|
|
1337
|
+
InboundReject:
|
|
1338
|
+
code: 0x78
|
|
1339
|
+
description: >
|
|
1340
|
+
Sent by the client in response to InboundOpen to refuse the
|
|
1341
|
+
inbound connection. The server closes the remote socket and
|
|
1342
|
+
releases the channel_id.
|
|
1343
|
+
fields:
|
|
1344
|
+
channel_id:
|
|
1345
|
+
type: u32
|
|
1346
|
+
required: true
|
|
1347
|
+
reason:
|
|
1348
|
+
type: string
|
|
1349
|
+
required: false
|
|
1350
|
+
|
|
1351
|
+
DnsResult:
|
|
1352
|
+
code: 0x79
|
|
1353
|
+
description: >
|
|
1354
|
+
Sent by the server in response to ResolveDns with the resolved
|
|
1355
|
+
addresses. Contains one or more IP address strings and an
|
|
1356
|
+
optional TTL from the DNS response.
|
|
1357
|
+
fields:
|
|
1358
|
+
gateway_id:
|
|
1359
|
+
type: u32
|
|
1360
|
+
required: true
|
|
1361
|
+
addresses:
|
|
1362
|
+
type: "string[]"
|
|
1363
|
+
required: true
|
|
1364
|
+
ttl:
|
|
1365
|
+
type: u32
|
|
1366
|
+
required: false
|
|
1367
|
+
|
|
1368
|
+
ListenRequest:
|
|
1369
|
+
code: 0x7a
|
|
1370
|
+
description: >
|
|
1371
|
+
Sent by the client to ask the server to open a listening socket
|
|
1372
|
+
on the given port and bind address. The server replies with
|
|
1373
|
+
ListenOk (including the actual bound port) or ListenFail.
|
|
1374
|
+
Reverse tunnels are policy-controlled by the host: off unless the
|
|
1375
|
+
operator enables them, bound to an address the OPERATOR chooses
|
|
1376
|
+
(loopback by default; bind_addr is a request the host may ignore),
|
|
1377
|
+
and limited to an allowed set of ports (a port below 1024 only if
|
|
1378
|
+
listed). Each inbound connection is announced with InboundOpen
|
|
1379
|
+
(peer_addr and peer_port are the remote end) and, once the client
|
|
1380
|
+
answers InboundAccept{gateway_id}, flows as GatewayData /
|
|
1381
|
+
GatewayCredit / GatewayClose on that gateway_id. A host that
|
|
1382
|
+
serves this lists "gateway" in ServerHello.features.
|
|
1383
|
+
fields:
|
|
1384
|
+
listener_id:
|
|
1385
|
+
type: u32
|
|
1386
|
+
required: true
|
|
1387
|
+
port:
|
|
1388
|
+
type: u16
|
|
1389
|
+
required: true
|
|
1390
|
+
bind_addr:
|
|
1391
|
+
type: string
|
|
1392
|
+
default: '"0.0.0.0"'
|
|
1393
|
+
|
|
1394
|
+
ListenOk:
|
|
1395
|
+
code: 0x7b
|
|
1396
|
+
description: >
|
|
1397
|
+
Sent by the server to confirm that a ListenRequest succeeded.
|
|
1398
|
+
The actual_port may differ from the requested port when the
|
|
1399
|
+
client requested port 0 (ephemeral port assignment).
|
|
1400
|
+
fields:
|
|
1401
|
+
listener_id:
|
|
1402
|
+
type: u32
|
|
1403
|
+
required: true
|
|
1404
|
+
actual_port:
|
|
1405
|
+
type: u16
|
|
1406
|
+
required: true
|
|
1407
|
+
|
|
1408
|
+
ListenFail:
|
|
1409
|
+
code: 0x7c
|
|
1410
|
+
description: >
|
|
1411
|
+
Sent by the server when a ListenRequest fails, for example
|
|
1412
|
+
because the port is already in use or policy denies the bind.
|
|
1413
|
+
fields:
|
|
1414
|
+
listener_id:
|
|
1415
|
+
type: u32
|
|
1416
|
+
required: true
|
|
1417
|
+
reason:
|
|
1418
|
+
type: string
|
|
1419
|
+
required: true
|
|
1420
|
+
|
|
1421
|
+
ListenClose:
|
|
1422
|
+
code: 0x7d
|
|
1423
|
+
description: >
|
|
1424
|
+
Sent by the client to stop listening on a previously opened
|
|
1425
|
+
listener. The server closes the bound socket and releases
|
|
1426
|
+
the listener_id.
|
|
1427
|
+
fields:
|
|
1428
|
+
listener_id:
|
|
1429
|
+
type: u32
|
|
1430
|
+
required: true
|
|
1431
|
+
|
|
1432
|
+
GatewayData:
|
|
1433
|
+
code: 0x7e
|
|
1434
|
+
description: >
|
|
1435
|
+
Bidirectional data relay for an active gateway connection. Sent by
|
|
1436
|
+
either side to forward payload bytes through a proxied TCP/UDP
|
|
1437
|
+
channel identified by gateway_id.
|
|
1438
|
+
fields:
|
|
1439
|
+
gateway_id:
|
|
1440
|
+
type: u32
|
|
1441
|
+
required: true
|
|
1442
|
+
data:
|
|
1443
|
+
type: bytes
|
|
1444
|
+
required: true
|
|
1445
|
+
|
|
1446
|
+
GatewayCredit:
|
|
1447
|
+
code: 0x7f
|
|
1448
|
+
description: >
|
|
1449
|
+
Per-connection flow control for GatewayData (feature
|
|
1450
|
+
"gateway-credit"). Sent by the RECEIVER of a gateway connection's
|
|
1451
|
+
data to tell the sender it may send `bytes` more payload bytes of
|
|
1452
|
+
GatewayData on gateway_id. Each direction of each connection has its
|
|
1453
|
+
own credit, which starts at 262144 bytes when the connection is
|
|
1454
|
+
established (the host's GatewayOk, or the client's InboundAccept) and
|
|
1455
|
+
is topped up by GatewayCredit as the receiver consumes data (the Node
|
|
1456
|
+
host: when the origin socket has taken it; a client: when the
|
|
1457
|
+
application has read it). A sender never has more than the credit
|
|
1458
|
+
it holds in flight; a receiver closes a connection whose peer
|
|
1459
|
+
overruns the credit it granted. Both peers use it only when the
|
|
1460
|
+
client listed "gateway-credit" in Hello.features AND the host listed
|
|
1461
|
+
it in ServerHello.features; otherwise neither sends it and GatewayData
|
|
1462
|
+
is unmetered as before (the host then bounds its buffering with
|
|
1463
|
+
byte caps instead and closes a connection that exceeds them).
|
|
1464
|
+
|
|
1465
|
+
The same message meters an rpc channel in virtual data mode (feature
|
|
1466
|
+
"rpc-virtual": the channel's CBOR sequence rides SessionData, and
|
|
1467
|
+
EncryptedFrame on a sealed session). Its credit has a number space of
|
|
1468
|
+
its own: `gateway_id` is 0x80000000 OR the rpc channel's channel_id,
|
|
1469
|
+
a flag no gateway id carries. Each direction starts with 262144 bytes
|
|
1470
|
+
and is topped up as the receiver takes the bytes in; a peer that sends
|
|
1471
|
+
more than it was granted has the channel closed. It is sent only on a
|
|
1472
|
+
connection where the host stated "rpc-virtual".
|
|
1473
|
+
fields:
|
|
1474
|
+
gateway_id:
|
|
1475
|
+
type: u32
|
|
1476
|
+
required: true
|
|
1477
|
+
bytes:
|
|
1478
|
+
type: u32
|
|
1479
|
+
required: true
|
|
1480
|
+
|
|
1481
|
+
OpenUnix:
|
|
1482
|
+
code: 0x63
|
|
1483
|
+
description: >
|
|
1484
|
+
Sent by the client to ask the host to connect to a unix-domain
|
|
1485
|
+
socket at `path` on the HOST's file system (OpenSSH streamlocal,
|
|
1486
|
+
`-L ...:/remote.sock`). Only to a host that listed "gateway-unix" in
|
|
1487
|
+
ServerHello.features. Answered by GatewayOk or GatewayFail; the data
|
|
1488
|
+
then flows as GatewayData / GatewayCredit / GatewayClose on
|
|
1489
|
+
gateway_id exactly as for OpenTcp. `path` is absolute; a leading "@"
|
|
1490
|
+
names a Linux abstract-namespace socket. The host refuses (code
|
|
1491
|
+
4=POLICY_DENIED) any path its policy does not list.
|
|
1492
|
+
fields:
|
|
1493
|
+
gateway_id:
|
|
1494
|
+
type: u32
|
|
1495
|
+
required: true
|
|
1496
|
+
path:
|
|
1497
|
+
type: string
|
|
1498
|
+
required: true
|
|
1499
|
+
|
|
1500
|
+
OpenEndpoint:
|
|
1501
|
+
code: 0x64
|
|
1502
|
+
description: >
|
|
1503
|
+
Sent by the client to open the host's NAMED VIRTUAL ENDPOINT `name`:
|
|
1504
|
+
an in-process handler the host's embedder registered (a host with no
|
|
1505
|
+
file system, such as a browser tab, offers these instead of unix
|
|
1506
|
+
sockets). Only to a host that listed "gateway-endpoints" in
|
|
1507
|
+
ServerHello.features. Answered by GatewayOk or GatewayFail (4 for a
|
|
1508
|
+
name that is not registered); the data then flows as for OpenUnix.
|
|
1509
|
+
It is a separate message rather than a reserved OpenUnix path so
|
|
1510
|
+
that a name can never be confused with a file-system path (or an
|
|
1511
|
+
abstract-namespace name) and so a host's file-system policy is not
|
|
1512
|
+
consulted for it.
|
|
1513
|
+
fields:
|
|
1514
|
+
gateway_id:
|
|
1515
|
+
type: u32
|
|
1516
|
+
required: true
|
|
1517
|
+
name:
|
|
1518
|
+
type: string
|
|
1519
|
+
required: true
|
|
1520
|
+
target:
|
|
1521
|
+
type: string
|
|
1522
|
+
required: false
|
|
1523
|
+
description: >
|
|
1524
|
+
The execution target whose endpoint `name` is meant, as for
|
|
1525
|
+
Open.target (only to a host that advertises `targets`). Omitted:
|
|
1526
|
+
the host's own endpoints. A host with targets answers GatewayFail
|
|
1527
|
+
(4) for a target it does not know or does not allow the caller on.
|
|
1528
|
+
|
|
1529
|
+
ListenUnix:
|
|
1530
|
+
code: 0x65
|
|
1531
|
+
description: >
|
|
1532
|
+
Sent by the client to ask the host to LISTEN on a unix-domain socket
|
|
1533
|
+
at `path` on the host's file system and hand each connection to the
|
|
1534
|
+
client (OpenSSH `-R /remote.sock:...`). Only to a host that listed
|
|
1535
|
+
"gateway-unix". Answered by ListenOk (actual_port is 0) or ListenFail.
|
|
1536
|
+
Each accepted connection is announced with InboundOpen
|
|
1537
|
+
(peer_addr "unix" and peer_port 0, as both implementations send) and, once the client answers
|
|
1538
|
+
InboundAccept{gateway_id}, flows as GatewayData / GatewayCredit /
|
|
1539
|
+
GatewayClose on that gateway_id. ListenClose stops it. The host
|
|
1540
|
+
creates the socket with mode 0600 and removes it when the listener
|
|
1541
|
+
closes or the connection ends. An existing socket file at `path` is
|
|
1542
|
+
replaced only when `replace` is true AND the host's policy allows
|
|
1543
|
+
replacing AND nothing is accepting connections on it.
|
|
1544
|
+
fields:
|
|
1545
|
+
listener_id:
|
|
1546
|
+
type: u32
|
|
1547
|
+
required: true
|
|
1548
|
+
path:
|
|
1549
|
+
type: string
|
|
1550
|
+
required: true
|
|
1551
|
+
replace:
|
|
1552
|
+
type: bool
|
|
1553
|
+
required: false
|
|
1554
|
+
|
|
1555
|
+
# ── Guest sessions ──────────────────────────────────────────────────
|
|
1556
|
+
# Ephemeral guest sessions allow session owners to create short-lived
|
|
1557
|
+
# share links. A guest invite produces a single-use token that a
|
|
1558
|
+
# guest can present via GuestJoin to attach with limited permissions.
|
|
1559
|
+
guest:
|
|
1560
|
+
GuestInvite:
|
|
1561
|
+
code: 0x80
|
|
1562
|
+
description: >
|
|
1563
|
+
Sent by the session owner to create an ephemeral guest token.
|
|
1564
|
+
The server generates a short-lived token, stores it, and returns
|
|
1565
|
+
a GuestInvite reply with the token in the session_id field so
|
|
1566
|
+
the owner can share it with guests.
|
|
1567
|
+
fields:
|
|
1568
|
+
session_id:
|
|
1569
|
+
type: string
|
|
1570
|
+
required: true
|
|
1571
|
+
ttl:
|
|
1572
|
+
type: u64
|
|
1573
|
+
required: true
|
|
1574
|
+
description: "Token lifetime in seconds"
|
|
1575
|
+
permissions:
|
|
1576
|
+
type: "string[]"
|
|
1577
|
+
default: '["read"]'
|
|
1578
|
+
description: '"read", "write", or "control"'
|
|
1579
|
+
|
|
1580
|
+
GuestJoin:
|
|
1581
|
+
code: 0x81
|
|
1582
|
+
description: >
|
|
1583
|
+
Sent by a guest to join a session using an ephemeral token.
|
|
1584
|
+
On success the server replies with Presence; on failure AuthFail.
|
|
1585
|
+
fields:
|
|
1586
|
+
token:
|
|
1587
|
+
type: string
|
|
1588
|
+
required: true
|
|
1589
|
+
device_label:
|
|
1590
|
+
type: string
|
|
1591
|
+
required: false
|
|
1592
|
+
|
|
1593
|
+
GuestRevoke:
|
|
1594
|
+
code: 0x82
|
|
1595
|
+
description: >
|
|
1596
|
+
Sent by the session owner to revoke an outstanding guest token.
|
|
1597
|
+
fields:
|
|
1598
|
+
token:
|
|
1599
|
+
type: string
|
|
1600
|
+
required: true
|
|
1601
|
+
reason:
|
|
1602
|
+
type: string
|
|
1603
|
+
required: false
|
|
1604
|
+
|
|
1605
|
+
# ── Session sharing ─────────────────────────────────────────────────
|
|
1606
|
+
# Multi-attach read-only URL sharing. A session owner creates a
|
|
1607
|
+
# share link that allows others to attach in read-only mode.
|
|
1608
|
+
sharing:
|
|
1609
|
+
ShareSession:
|
|
1610
|
+
code: 0x83
|
|
1611
|
+
description: >
|
|
1612
|
+
Sent by the session owner to create a shareable read-only link.
|
|
1613
|
+
The server generates a share_id and returns it for URL construction.
|
|
1614
|
+
fields:
|
|
1615
|
+
session_id:
|
|
1616
|
+
type: string
|
|
1617
|
+
required: true
|
|
1618
|
+
mode:
|
|
1619
|
+
type: string
|
|
1620
|
+
default: '"read"'
|
|
1621
|
+
description: '"read" or "write"'
|
|
1622
|
+
ttl:
|
|
1623
|
+
type: u64
|
|
1624
|
+
required: true
|
|
1625
|
+
description: "Share link lifetime in seconds"
|
|
1626
|
+
|
|
1627
|
+
ShareRevoke:
|
|
1628
|
+
code: 0x84
|
|
1629
|
+
description: >
|
|
1630
|
+
Sent by the session owner to revoke an active share link.
|
|
1631
|
+
fields:
|
|
1632
|
+
share_id:
|
|
1633
|
+
type: string
|
|
1634
|
+
required: true
|
|
1635
|
+
reason:
|
|
1636
|
+
type: string
|
|
1637
|
+
required: false
|
|
1638
|
+
|
|
1639
|
+
# ── Stream compression ──────────────────────────────────────────────
|
|
1640
|
+
# Negotiate per-connection compression. Either side may propose
|
|
1641
|
+
# compression; the peer accepts or rejects. After CompressAck with
|
|
1642
|
+
# accepted=true, all subsequent frames are compressed.
|
|
1643
|
+
compression:
|
|
1644
|
+
CompressBegin:
|
|
1645
|
+
code: 0x85
|
|
1646
|
+
description: >
|
|
1647
|
+
Propose stream compression. Sent by either side before data
|
|
1648
|
+
transfer begins (or after renegotiation).
|
|
1649
|
+
fields:
|
|
1650
|
+
algorithm:
|
|
1651
|
+
type: string
|
|
1652
|
+
required: true
|
|
1653
|
+
description: '"zstd", "lz4", or "deflate"'
|
|
1654
|
+
level:
|
|
1655
|
+
type: u32
|
|
1656
|
+
default: 3
|
|
1657
|
+
description: "Compression level (algorithm-specific)"
|
|
1658
|
+
|
|
1659
|
+
CompressAck:
|
|
1660
|
+
code: 0x86
|
|
1661
|
+
description: >
|
|
1662
|
+
Accept or reject a compression proposal.
|
|
1663
|
+
fields:
|
|
1664
|
+
algorithm:
|
|
1665
|
+
type: string
|
|
1666
|
+
required: true
|
|
1667
|
+
accepted:
|
|
1668
|
+
type: bool
|
|
1669
|
+
required: true
|
|
1670
|
+
|
|
1671
|
+
# ── Rate control ────────────────────────────────────────────────────
|
|
1672
|
+
# Per-attachment flow control for slow consumers. When an attached
|
|
1673
|
+
# client falls behind, the server can drop or pause output delivery.
|
|
1674
|
+
ratecontrol:
|
|
1675
|
+
RateControl:
|
|
1676
|
+
code: 0x87
|
|
1677
|
+
description: >
|
|
1678
|
+
Set per-attachment rate limits. Sent by either side to configure
|
|
1679
|
+
the maximum data rate for the session.
|
|
1680
|
+
fields:
|
|
1681
|
+
session_id:
|
|
1682
|
+
type: string
|
|
1683
|
+
required: true
|
|
1684
|
+
max_bytes_per_sec:
|
|
1685
|
+
type: u64
|
|
1686
|
+
required: true
|
|
1687
|
+
policy:
|
|
1688
|
+
type: string
|
|
1689
|
+
default: '"pause"'
|
|
1690
|
+
description: '"pause" (backpressure) or "drop" (discard excess)'
|
|
1691
|
+
|
|
1692
|
+
RateWarning:
|
|
1693
|
+
code: 0x88
|
|
1694
|
+
description: >
|
|
1695
|
+
Sent by the server when a client is falling behind.
|
|
1696
|
+
fields:
|
|
1697
|
+
session_id:
|
|
1698
|
+
type: string
|
|
1699
|
+
required: true
|
|
1700
|
+
queued_bytes:
|
|
1701
|
+
type: u64
|
|
1702
|
+
required: true
|
|
1703
|
+
action:
|
|
1704
|
+
type: string
|
|
1705
|
+
required: true
|
|
1706
|
+
description: '"ok", "pausing", or "dropping"'
|
|
1707
|
+
|
|
1708
|
+
# ── Cross-session linking ────────────────────────────────────────────
|
|
1709
|
+
# Jump host support — link one session to another server so data
|
|
1710
|
+
# flows through the first server as a hop.
|
|
1711
|
+
linking:
|
|
1712
|
+
SessionLink:
|
|
1713
|
+
code: 0x89
|
|
1714
|
+
description: >
|
|
1715
|
+
Request a cross-session link (jump host). The server opens a
|
|
1716
|
+
new wsh connection to target_host and bridges the two sessions.
|
|
1717
|
+
fields:
|
|
1718
|
+
source_session:
|
|
1719
|
+
type: string
|
|
1720
|
+
required: true
|
|
1721
|
+
target_host:
|
|
1722
|
+
type: string
|
|
1723
|
+
required: true
|
|
1724
|
+
target_port:
|
|
1725
|
+
type: u16
|
|
1726
|
+
required: true
|
|
1727
|
+
target_user:
|
|
1728
|
+
type: string
|
|
1729
|
+
required: false
|
|
1730
|
+
|
|
1731
|
+
SessionUnlink:
|
|
1732
|
+
code: 0x8a
|
|
1733
|
+
description: >
|
|
1734
|
+
Tear down a cross-session link.
|
|
1735
|
+
fields:
|
|
1736
|
+
link_id:
|
|
1737
|
+
type: string
|
|
1738
|
+
required: true
|
|
1739
|
+
reason:
|
|
1740
|
+
type: string
|
|
1741
|
+
required: false
|
|
1742
|
+
|
|
1743
|
+
# ── AI co-pilot ─────────────────────────────────────────────────────
|
|
1744
|
+
# Read-only AI observer mode. An AI model attaches to a session,
|
|
1745
|
+
# observes terminal output, and can offer suggestions without
|
|
1746
|
+
# directly controlling the session.
|
|
1747
|
+
copilot:
|
|
1748
|
+
CopilotAttach:
|
|
1749
|
+
code: 0x8b
|
|
1750
|
+
description: >
|
|
1751
|
+
Sent by an AI agent to attach as a read-only co-pilot observer.
|
|
1752
|
+
fields:
|
|
1753
|
+
session_id:
|
|
1754
|
+
type: string
|
|
1755
|
+
required: true
|
|
1756
|
+
model:
|
|
1757
|
+
type: string
|
|
1758
|
+
required: true
|
|
1759
|
+
description: "Model identifier (e.g. 'claude-sonnet', 'gpt-4')"
|
|
1760
|
+
context_window:
|
|
1761
|
+
type: u64
|
|
1762
|
+
required: false
|
|
1763
|
+
description: "Model context window size in tokens"
|
|
1764
|
+
|
|
1765
|
+
CopilotSuggest:
|
|
1766
|
+
code: 0x8c
|
|
1767
|
+
description: >
|
|
1768
|
+
Sent by the co-pilot to offer a suggestion to the session user.
|
|
1769
|
+
fields:
|
|
1770
|
+
session_id:
|
|
1771
|
+
type: string
|
|
1772
|
+
required: true
|
|
1773
|
+
suggestion:
|
|
1774
|
+
type: string
|
|
1775
|
+
required: true
|
|
1776
|
+
confidence:
|
|
1777
|
+
type: f64
|
|
1778
|
+
required: false
|
|
1779
|
+
description: "Confidence score 0.0-1.0"
|
|
1780
|
+
|
|
1781
|
+
CopilotDetach:
|
|
1782
|
+
code: 0x8d
|
|
1783
|
+
description: >
|
|
1784
|
+
Sent by either side to end the co-pilot attachment.
|
|
1785
|
+
fields:
|
|
1786
|
+
session_id:
|
|
1787
|
+
type: string
|
|
1788
|
+
required: true
|
|
1789
|
+
reason:
|
|
1790
|
+
type: string
|
|
1791
|
+
required: false
|
|
1792
|
+
|
|
1793
|
+
# ── E2E encryption (EXPERIMENTAL) ─────────────────────────────────────
|
|
1794
|
+
# Inner encryption layer intended for end-to-end confidentiality: after
|
|
1795
|
+
# key exchange, session data is protected so the server cannot read
|
|
1796
|
+
# session content. Status per side of the wire:
|
|
1797
|
+
# WshClient.initiateE2E() performs a real X25519 ECDH exchange
|
|
1798
|
+
# (optionally hybrid with ML-KEM-768, see below) and derives an
|
|
1799
|
+
# AES-256-GCM key (src/client.mjs); as of this JS library's
|
|
1800
|
+
# EncryptedFrame support (wsh #19), that key is used to seal/open
|
|
1801
|
+
# virtual-mode session data (discrete SessionData control messages
|
|
1802
|
+
# swapped 1:1 for EncryptedFrame) via WshSession.enableE2E()
|
|
1803
|
+
# (src/session.mjs, src/e2e-frame.mjs). As of wsh #22 (PR 1 of a
|
|
1804
|
+
# 3-PR rollout), the same key/enableE2E() call also covers
|
|
1805
|
+
# stream-mode sessions (raw byte streams, no message boundaries):
|
|
1806
|
+
# sealed chunks are framed *inline in the raw stream itself* --
|
|
1807
|
+
# [4-byte big-endian length][12-byte nonce][ciphertext + 16-byte GCM
|
|
1808
|
+
# tag] -- reusing the exact same sealFrame/openFrame primitives and
|
|
1809
|
+
# nonce scheme as EncryptedFrame, just without a CBOR envelope. This
|
|
1810
|
+
# inline chunk framing is invisible to this control-message spec: it
|
|
1811
|
+
# lives entirely inside the byte stream a session's data plane already
|
|
1812
|
+
# carries, so it introduces no new message type here (see
|
|
1813
|
+
# src/stream-frame.mjs for the framing/reassembly implementation).
|
|
1814
|
+
# The Rust client (clawser's wsh-client crate) does have KeyExchange/
|
|
1815
|
+
# initiate_e2e support, but does not yet construct or consume
|
|
1816
|
+
# EncryptedFrame or stream-mode chunk framing -- that AEAD sealing is
|
|
1817
|
+
# tracked as a separate follow-up in that repo (wsh #22's PR 2/PR 3).
|
|
1818
|
+
# The Rust server only relays both message types (and raw stream
|
|
1819
|
+
# bytes) opaquely between session participants (correct for true E2E,
|
|
1820
|
+
# but doesn't imply either side actually encrypts). Do not rely on
|
|
1821
|
+
# this for confidentiality against a peer that hasn't actually called
|
|
1822
|
+
# enableE2E()/opened an EncryptedFrame-sealing (or stream chunk
|
|
1823
|
+
# framing) equivalent.
|
|
1824
|
+
e2e:
|
|
1825
|
+
KeyExchange:
|
|
1826
|
+
code: 0x8e
|
|
1827
|
+
description: >
|
|
1828
|
+
Key exchange for establishing a shared secret, X25519 or hybrid
|
|
1829
|
+
X25519+ML-KEM-768. See the e2e section note above for which
|
|
1830
|
+
peers currently wire the derived secret to actual encryption.
|
|
1831
|
+
|
|
1832
|
+
Classical mode ("X25519"): both sides send only public_key
|
|
1833
|
+
(their ephemeral X25519 public key); the shared secret is
|
|
1834
|
+
derived via ECDH directly.
|
|
1835
|
+
|
|
1836
|
+
Hybrid mode ("X25519+ML-KEM-768"): round 1 is the same as
|
|
1837
|
+
classical, plus both sides also send kem_public_key (a fresh
|
|
1838
|
+
ML-KEM-768 public key). After round 1, each side deterministically
|
|
1839
|
+
derives the same "encapsulator"/"decapsulator" role assignment by
|
|
1840
|
+
comparing the two exchanged X25519 public_key values byte-lexico-
|
|
1841
|
+
graphically (the lower one is the encapsulator) -- this needs no
|
|
1842
|
+
extra round trip since both sides already have both values. The
|
|
1843
|
+
encapsulator then encapsulates against the decapsulator's
|
|
1844
|
+
kem_public_key and sends a second KeyExchange carrying only
|
|
1845
|
+
kem_ciphertext (no public_key/kem_public_key); the decapsulator
|
|
1846
|
+
decapsulates it. Both sides combine the X25519 ECDH output and
|
|
1847
|
+
the ML-KEM-768 shared secret via HKDF-SHA256 into the final
|
|
1848
|
+
AES-256-GCM key. A peer that doesn't echo kem_public_key back in
|
|
1849
|
+
its own round-1 message doesn't support hybrid mode -- fall back
|
|
1850
|
+
to classical X25519-only rather than failing the exchange
|
|
1851
|
+
(algorithm agility, not a hard cutover).
|
|
1852
|
+
fields:
|
|
1853
|
+
algorithm:
|
|
1854
|
+
type: string
|
|
1855
|
+
required: true
|
|
1856
|
+
description: '"X25519" or "X25519+ML-KEM-768"'
|
|
1857
|
+
public_key:
|
|
1858
|
+
type: bytes
|
|
1859
|
+
required: false
|
|
1860
|
+
description: "Ephemeral X25519 public key. Omitted only on the hybrid round-2 (kem_ciphertext-only) message."
|
|
1861
|
+
session_id:
|
|
1862
|
+
type: string
|
|
1863
|
+
required: true
|
|
1864
|
+
kem_public_key:
|
|
1865
|
+
type: bytes
|
|
1866
|
+
required: false
|
|
1867
|
+
description: "Hybrid mode round 1 only: a fresh ML-KEM-768 public key (1184 bytes)."
|
|
1868
|
+
kem_ciphertext:
|
|
1869
|
+
type: bytes
|
|
1870
|
+
required: false
|
|
1871
|
+
description: "Hybrid mode round 2 only, encapsulator -> decapsulator: the ML-KEM-768 ciphertext (1088 bytes)."
|
|
1872
|
+
signature:
|
|
1873
|
+
type: bytes
|
|
1874
|
+
required: false
|
|
1875
|
+
description: >
|
|
1876
|
+
Round 1 only, optional: an Ed25519 signature by the sender's
|
|
1877
|
+
long-term identity key, which authenticates the sender's half of
|
|
1878
|
+
an otherwise unauthenticated exchange. It covers the label
|
|
1879
|
+
"wsh-e2e-keyexchange-v1", the session_id, the algorithm, and both
|
|
1880
|
+
sides' ephemeral X25519 public keys (initiator's first, then
|
|
1881
|
+
responder's), each length-prefixed -- so a relay cannot substitute
|
|
1882
|
+
either key without the signer's key. A reverse host signs its
|
|
1883
|
+
reply (it is the responder); the initiating operator verifies it
|
|
1884
|
+
against the host key it connected to (WshClient.initiateE2E
|
|
1885
|
+
{ verifyPeer }). A peer that does not sign is simply
|
|
1886
|
+
unauthenticated, as before; a recipient that requires it rejects
|
|
1887
|
+
the exchange. Peers older than this field ignore it (JS) or may
|
|
1888
|
+
reject a KeyExchange carrying it (an older Rust build), so a host
|
|
1889
|
+
signs by default and offers e2e.sign: false for such a relay.
|
|
1890
|
+
|
|
1891
|
+
The INITIATOR may sign its round-1 message too (wsh #117), so
|
|
1892
|
+
that both halves are authenticated. Its signature is over the
|
|
1893
|
+
label "wsh-e2e-keyexchange-init-v1\0" (a different label, so it
|
|
1894
|
+
can never be taken for a responder signature), the session_id,
|
|
1895
|
+
the algorithm, its own ephemeral X25519 key and the responder's
|
|
1896
|
+
raw identity key, each length-prefixed -- the responder's
|
|
1897
|
+
reply, signed as above, then covers both ephemeral keys. The
|
|
1898
|
+
responder verifies it against the operator key it already
|
|
1899
|
+
proved in a ReverseProof (a host that states "e2e-sealed" in
|
|
1900
|
+
ReverseAccept.features does), and a host that requires operator
|
|
1901
|
+
proof refuses an unsigned or badly signed initiator half. An
|
|
1902
|
+
initiator signs only after the host stated "e2e-sealed": an
|
|
1903
|
+
older host would ignore the signature and a Rust one may reject
|
|
1904
|
+
it.
|
|
1905
|
+
|
|
1906
|
+
"e2e-sealed" also means the bridge itself can be sealed: a
|
|
1907
|
+
KeyExchange whose session_id is the ReverseChallenge.session_id
|
|
1908
|
+
of the bridge, sent right after ReverseAccept, establishes a key
|
|
1909
|
+
for the whole bridge. From then on every message that would
|
|
1910
|
+
cross it (the relay forwardable list, KeyExchange aside) travels
|
|
1911
|
+
as an EncryptedFrame with channel_id 0 and that session_id,
|
|
1912
|
+
sealed with the same AES-256-GCM framing as session data
|
|
1913
|
+
(counters, role tags, session_id as AAD), the CBOR of the
|
|
1914
|
+
message as plaintext. A peer or operator that sealed the bridge
|
|
1915
|
+
drops every plaintext message it receives over it. Nothing that
|
|
1916
|
+
names a command, a path or a session is sent before the key
|
|
1917
|
+
exists.
|
|
1918
|
+
|
|
1919
|
+
EncryptedFrame:
|
|
1920
|
+
code: 0x8f
|
|
1921
|
+
description: >
|
|
1922
|
+
An encrypted payload carrying virtual-mode session data, once
|
|
1923
|
+
KeyExchange's derived secret is wired to real encryption via
|
|
1924
|
+
WshSession.enableE2E() (see the e2e section note above).
|
|
1925
|
+
Virtual-mode only -- stream-mode sessions never send this
|
|
1926
|
+
message type; their sealed data instead travels as inline
|
|
1927
|
+
length-prefixed chunks inside the raw byte stream itself (see
|
|
1928
|
+
the e2e section note above and src/stream-frame.mjs), since a
|
|
1929
|
+
stream-mode session has no control-message channel to carry a
|
|
1930
|
+
CBOR envelope like this one through. Sent
|
|
1931
|
+
using AES-256-GCM AEAD, matching the cipher
|
|
1932
|
+
WshClient.initiateE2E() derives a key for (src/client.mjs) --
|
|
1933
|
+
picked over the ChaCha20-Poly1305 this field previously
|
|
1934
|
+
described because it's natively supported by SubtleCrypto in
|
|
1935
|
+
every shipping browser, matching this library's zero-runtime-
|
|
1936
|
+
dependency, Web-Crypto-native design; ChaCha20-Poly1305 has no
|
|
1937
|
+
native browser support and would require bundling a JS
|
|
1938
|
+
implementation. The nonce is 8 bytes of big-endian monotonic
|
|
1939
|
+
send counter followed by a 4-byte fixed per-sender role tag
|
|
1940
|
+
(see src/e2e-frame.mjs); session_id is bound as AEAD additional
|
|
1941
|
+
authenticated data so a relay can't splice ciphertext across
|
|
1942
|
+
sessions.
|
|
1943
|
+
fields:
|
|
1944
|
+
channel_id:
|
|
1945
|
+
type: u32
|
|
1946
|
+
required: true
|
|
1947
|
+
description: "Which channel (session) this frame belongs to -- same routing role as SessionData.channel_id."
|
|
1948
|
+
nonce:
|
|
1949
|
+
type: bytes
|
|
1950
|
+
required: true
|
|
1951
|
+
description: "12-byte AEAD nonce"
|
|
1952
|
+
ciphertext:
|
|
1953
|
+
type: bytes
|
|
1954
|
+
required: true
|
|
1955
|
+
session_id:
|
|
1956
|
+
type: string
|
|
1957
|
+
required: true
|
|
1958
|
+
|
|
1959
|
+
# ── Predictive local echo ────────────────────────────────────────────
|
|
1960
|
+
# Mosh-style local echo. The client speculatively renders keystrokes
|
|
1961
|
+
# and the server confirms via EchoAck. EchoState carries cursor
|
|
1962
|
+
# position so the client can reconcile predictions.
|
|
1963
|
+
echo:
|
|
1964
|
+
EchoAck:
|
|
1965
|
+
code: 0x90
|
|
1966
|
+
description: >
|
|
1967
|
+
Sent by the server to confirm that input up to echo_seq has
|
|
1968
|
+
been processed and rendered. The client can retire predictions
|
|
1969
|
+
up to this sequence number.
|
|
1970
|
+
fields:
|
|
1971
|
+
channel_id:
|
|
1972
|
+
type: u32
|
|
1973
|
+
required: true
|
|
1974
|
+
echo_seq:
|
|
1975
|
+
type: u64
|
|
1976
|
+
required: true
|
|
1977
|
+
|
|
1978
|
+
EchoState:
|
|
1979
|
+
code: 0x91
|
|
1980
|
+
description: >
|
|
1981
|
+
Sent by the server with current terminal cursor state so the
|
|
1982
|
+
client can reconcile local predictions with actual state.
|
|
1983
|
+
fields:
|
|
1984
|
+
channel_id:
|
|
1985
|
+
type: u32
|
|
1986
|
+
required: true
|
|
1987
|
+
echo_seq:
|
|
1988
|
+
type: u64
|
|
1989
|
+
required: true
|
|
1990
|
+
cursor_x:
|
|
1991
|
+
type: u16
|
|
1992
|
+
required: true
|
|
1993
|
+
cursor_y:
|
|
1994
|
+
type: u16
|
|
1995
|
+
required: true
|
|
1996
|
+
pending:
|
|
1997
|
+
type: u32
|
|
1998
|
+
required: true
|
|
1999
|
+
description: "Number of unacknowledged input bytes on server"
|
|
2000
|
+
|
|
2001
|
+
# ── Terminal diff sync ───────────────────────────────────────────────
|
|
2002
|
+
# True mosh replacement — instead of streaming raw bytes, the server
|
|
2003
|
+
# maintains a virtual terminal framebuffer and sends diffs. The
|
|
2004
|
+
# client applies patches to its local copy.
|
|
2005
|
+
termsync:
|
|
2006
|
+
TermSync:
|
|
2007
|
+
code: 0x92
|
|
2008
|
+
description: >
|
|
2009
|
+
Full terminal state synchronization point. The server sends
|
|
2010
|
+
a state_hash so the client can verify consistency. If the
|
|
2011
|
+
client's hash differs, it requests a full resync.
|
|
2012
|
+
fields:
|
|
2013
|
+
channel_id:
|
|
2014
|
+
type: u32
|
|
2015
|
+
required: true
|
|
2016
|
+
frame_seq:
|
|
2017
|
+
type: u64
|
|
2018
|
+
required: true
|
|
2019
|
+
state_hash:
|
|
2020
|
+
type: bytes
|
|
2021
|
+
required: true
|
|
2022
|
+
description: "SHA-256 of the current framebuffer state"
|
|
2023
|
+
|
|
2024
|
+
TermDiff:
|
|
2025
|
+
code: 0x93
|
|
2026
|
+
description: >
|
|
2027
|
+
Incremental screen diff. Contains a binary patch that transforms
|
|
2028
|
+
the framebuffer from base_seq state to frame_seq state.
|
|
2029
|
+
fields:
|
|
2030
|
+
channel_id:
|
|
2031
|
+
type: u32
|
|
2032
|
+
required: true
|
|
2033
|
+
frame_seq:
|
|
2034
|
+
type: u64
|
|
2035
|
+
required: true
|
|
2036
|
+
base_seq:
|
|
2037
|
+
type: u64
|
|
2038
|
+
required: true
|
|
2039
|
+
patch:
|
|
2040
|
+
type: bytes
|
|
2041
|
+
required: true
|
|
2042
|
+
description: "Binary diff patch (run-length encoded cell changes)"
|
|
2043
|
+
|
|
2044
|
+
# ── Horizontal scaling (EXPERIMENTAL, incomplete) ────────────────────
|
|
2045
|
+
# Multi-node cluster support. Nodes announce themselves and can
|
|
2046
|
+
# redirect clients to less-loaded peers. Stateless session tokens
|
|
2047
|
+
# (HMAC-based) allow any node to validate without shared state.
|
|
2048
|
+
# Currently: the Rust server records NodeAnnounce into a registry
|
|
2049
|
+
# (garbage-collected on a timer) but never reads it back for any
|
|
2050
|
+
# routing decision, and nothing anywhere ever constructs a
|
|
2051
|
+
# NodeRedirect -- there is no load-aware routing today, only inert
|
|
2052
|
+
# bookkeeping. No JS client support exists at all.
|
|
2053
|
+
scaling:
|
|
2054
|
+
NodeAnnounce:
|
|
2055
|
+
code: 0x94
|
|
2056
|
+
description: >
|
|
2057
|
+
Sent between cluster nodes to announce presence and load.
|
|
2058
|
+
Used for load-aware routing decisions.
|
|
2059
|
+
fields:
|
|
2060
|
+
node_id:
|
|
2061
|
+
type: string
|
|
2062
|
+
required: true
|
|
2063
|
+
endpoint:
|
|
2064
|
+
type: string
|
|
2065
|
+
required: true
|
|
2066
|
+
description: "WebSocket/WebTransport URL for this node"
|
|
2067
|
+
load:
|
|
2068
|
+
type: f64
|
|
2069
|
+
required: true
|
|
2070
|
+
description: "Current load factor 0.0-1.0"
|
|
2071
|
+
capacity:
|
|
2072
|
+
type: u32
|
|
2073
|
+
required: true
|
|
2074
|
+
description: "Max concurrent sessions"
|
|
2075
|
+
|
|
2076
|
+
NodeRedirect:
|
|
2077
|
+
code: 0x95
|
|
2078
|
+
description: >
|
|
2079
|
+
Sent by a node to redirect a client to a different node.
|
|
2080
|
+
The client should reconnect to target_endpoint and present
|
|
2081
|
+
its session token (which is valid across all cluster nodes).
|
|
2082
|
+
fields:
|
|
2083
|
+
target_node:
|
|
2084
|
+
type: string
|
|
2085
|
+
required: true
|
|
2086
|
+
target_endpoint:
|
|
2087
|
+
type: string
|
|
2088
|
+
required: true
|
|
2089
|
+
session_id:
|
|
2090
|
+
type: string
|
|
2091
|
+
required: true
|
|
2092
|
+
reason:
|
|
2093
|
+
type: string
|
|
2094
|
+
required: false
|
|
2095
|
+
|
|
2096
|
+
# ── Cross-principal session sharing ──────────────────────────────────
|
|
2097
|
+
# Allow session owners to grant access to other authenticated users
|
|
2098
|
+
# (principals). This enables collaborative multi-user sessions.
|
|
2099
|
+
principals:
|
|
2100
|
+
SessionGrant:
|
|
2101
|
+
code: 0x96
|
|
2102
|
+
description: >
|
|
2103
|
+
Grant another principal access to a session. The principal
|
|
2104
|
+
must be an authenticated user on the server.
|
|
2105
|
+
fields:
|
|
2106
|
+
session_id:
|
|
2107
|
+
type: string
|
|
2108
|
+
required: true
|
|
2109
|
+
principal:
|
|
2110
|
+
type: string
|
|
2111
|
+
required: true
|
|
2112
|
+
description: "Username or fingerprint of the grantee"
|
|
2113
|
+
permissions:
|
|
2114
|
+
type: "string[]"
|
|
2115
|
+
default: '["read"]'
|
|
2116
|
+
description: '"read", "write", or "control"'
|
|
2117
|
+
|
|
2118
|
+
SessionRevoke:
|
|
2119
|
+
code: 0x97
|
|
2120
|
+
description: >
|
|
2121
|
+
Revoke a previously granted session access.
|
|
2122
|
+
fields:
|
|
2123
|
+
session_id:
|
|
2124
|
+
type: string
|
|
2125
|
+
required: true
|
|
2126
|
+
principal:
|
|
2127
|
+
type: string
|
|
2128
|
+
required: true
|
|
2129
|
+
reason:
|
|
2130
|
+
type: string
|
|
2131
|
+
required: false
|
|
2132
|
+
|
|
2133
|
+
# ── Structured file channel ──────────────────────────────────────────
|
|
2134
|
+
# SFTP replacement — structured file operations over wsh channels.
|
|
2135
|
+
# Supports stat, list, read, write, mkdir, remove, rename.
|
|
2136
|
+
filechannel:
|
|
2137
|
+
FileOp:
|
|
2138
|
+
code: 0x98
|
|
2139
|
+
description: >
|
|
2140
|
+
Request a file operation (stat, list, read, write, mkdir,
|
|
2141
|
+
remove, rename).
|
|
2142
|
+
fields:
|
|
2143
|
+
channel_id:
|
|
2144
|
+
type: u32
|
|
2145
|
+
required: true
|
|
2146
|
+
op:
|
|
2147
|
+
type: string
|
|
2148
|
+
required: true
|
|
2149
|
+
description: '"stat", "list", "read", "write", "mkdir", "remove", "rename"'
|
|
2150
|
+
path:
|
|
2151
|
+
type: string
|
|
2152
|
+
required: true
|
|
2153
|
+
offset:
|
|
2154
|
+
type: u64
|
|
2155
|
+
required: false
|
|
2156
|
+
description: "Byte offset for read/write"
|
|
2157
|
+
length:
|
|
2158
|
+
type: u64
|
|
2159
|
+
required: false
|
|
2160
|
+
description: "Byte count for read"
|
|
2161
|
+
target:
|
|
2162
|
+
type: string
|
|
2163
|
+
required: false
|
|
2164
|
+
description: >
|
|
2165
|
+
The execution target whose files this operation is about, as for
|
|
2166
|
+
Open.target (only to a host that advertises `targets`). Omitted:
|
|
2167
|
+
the host's own default files.
|
|
2168
|
+
|
|
2169
|
+
FileResult:
|
|
2170
|
+
code: 0x99
|
|
2171
|
+
description: >
|
|
2172
|
+
Result of a file operation. Success with optional metadata,
|
|
2173
|
+
or failure with error message.
|
|
2174
|
+
fields:
|
|
2175
|
+
channel_id:
|
|
2176
|
+
type: u32
|
|
2177
|
+
required: true
|
|
2178
|
+
success:
|
|
2179
|
+
type: bool
|
|
2180
|
+
required: true
|
|
2181
|
+
metadata:
|
|
2182
|
+
type: json
|
|
2183
|
+
default: "{}"
|
|
2184
|
+
description: >
|
|
2185
|
+
Untyped result payload for ops whose shape genuinely varies by
|
|
2186
|
+
op (stat's single-entry metadata is not currently typed either
|
|
2187
|
+
-- see wsh #59's type:json audit in the PR description for why
|
|
2188
|
+
that one is still open rather than fixed here). For "list",
|
|
2189
|
+
use `entries` instead of this field.
|
|
2190
|
+
entries:
|
|
2191
|
+
type: "FileEntry[]"
|
|
2192
|
+
default: "[]"
|
|
2193
|
+
description: >
|
|
2194
|
+
wsh #59: directory entries for a "list" op, generated into both
|
|
2195
|
+
languages so a symlink can't be reported as a plain file in one
|
|
2196
|
+
implementation and not the other. Previously this arrived only
|
|
2197
|
+
in `metadata` (untyped json), and only in the JS SDK's private
|
|
2198
|
+
`ls -la`-over-exec parsing -- never over this message at all.
|
|
2199
|
+
error_message:
|
|
2200
|
+
type: string
|
|
2201
|
+
required: false
|
|
2202
|
+
|
|
2203
|
+
FileChunk:
|
|
2204
|
+
code: 0x9a
|
|
2205
|
+
description: >
|
|
2206
|
+
Data chunk for file read/write transfers -- the single wire scheme
|
|
2207
|
+
for moving file bytes, replacing the old raw-stream length-prefixed
|
|
2208
|
+
header (WshClient.upload/download) and WshFileTransfer's ad-hoc
|
|
2209
|
+
Open.path/Open.size fields. Sent as an ordinary control-channel
|
|
2210
|
+
message over a 'file'-kind channel (Open/OpenOk first), so it works
|
|
2211
|
+
identically whether the channel's data_mode is stream or virtual --
|
|
2212
|
+
it never depends on a real second multiplexed stream existing.
|
|
2213
|
+
total_size lets a receiver detect a truncated transfer: for a
|
|
2214
|
+
well-formed transfer, the chunk with is_final=true always has
|
|
2215
|
+
offset + len(data) == total_size, and if the channel closes before
|
|
2216
|
+
such a chunk arrives, the transfer is known-truncated rather than
|
|
2217
|
+
silently short.
|
|
2218
|
+
fields:
|
|
2219
|
+
channel_id:
|
|
2220
|
+
type: u32
|
|
2221
|
+
required: true
|
|
2222
|
+
offset:
|
|
2223
|
+
type: u64
|
|
2224
|
+
required: true
|
|
2225
|
+
data:
|
|
2226
|
+
type: bytes
|
|
2227
|
+
required: true
|
|
2228
|
+
is_final:
|
|
2229
|
+
type: bool
|
|
2230
|
+
required: true
|
|
2231
|
+
description: "True if this is the last chunk"
|
|
2232
|
+
total_size:
|
|
2233
|
+
type: u64
|
|
2234
|
+
required: true
|
|
2235
|
+
description: "Total transfer size in bytes, constant across every chunk in the sequence"
|
|
2236
|
+
|
|
2237
|
+
# ── Authorized-key management ─────────────────────────────────────────
|
|
2238
|
+
# wsh #59: `wsh copy-id` previously installed a key by building and
|
|
2239
|
+
# running a remote shell command (crates/wsh-cli/src/commands/copy_id.rs)
|
|
2240
|
+
# -- CLI-only, and a quoting question nobody wanted two answers to. A
|
|
2241
|
+
# connection that has already completed AUTH_OK can already do anything
|
|
2242
|
+
# an equivalent `exec`/FileOp write could do to this same file (this
|
|
2243
|
+
# server grants a fully-authenticated connection unsandboxed filesystem
|
|
2244
|
+
# and shell access -- see FileOp/Open<ChannelKind::Exec> -- so this
|
|
2245
|
+
# message adds no new privilege boundary); it only removes the
|
|
2246
|
+
# shell-quoting hazard and makes key installation reachable from
|
|
2247
|
+
# implementations with no shell channel to build a command string for,
|
|
2248
|
+
# starting with the browser SDK.
|
|
2249
|
+
keys:
|
|
2250
|
+
AuthorizedKeyAdd:
|
|
2251
|
+
code: 0x9f
|
|
2252
|
+
description: >
|
|
2253
|
+
Install a public key into the authenticated user's
|
|
2254
|
+
~/.wsh/authorized_keys, idempotently (a key already present is
|
|
2255
|
+
left as-is, reported via AuthorizedKeyResult.added = false).
|
|
2256
|
+
fields:
|
|
2257
|
+
public_key:
|
|
2258
|
+
type: bytes
|
|
2259
|
+
required: true
|
|
2260
|
+
description: "Raw 32-byte Ed25519 public key (same encoding as Auth.public_key / PeerInfo.public_key)"
|
|
2261
|
+
comment:
|
|
2262
|
+
type: string
|
|
2263
|
+
required: false
|
|
2264
|
+
description: 'Trailing comment for the authorized_keys line, e.g. "user@host"'
|
|
2265
|
+
|
|
2266
|
+
AuthorizedKeyResult:
|
|
2267
|
+
code: 0xa0
|
|
2268
|
+
description: >
|
|
2269
|
+
Result of an AuthorizedKeyAdd request.
|
|
2270
|
+
fields:
|
|
2271
|
+
success:
|
|
2272
|
+
type: bool
|
|
2273
|
+
required: true
|
|
2274
|
+
added:
|
|
2275
|
+
type: bool
|
|
2276
|
+
default: false
|
|
2277
|
+
description: "True if the key was newly appended; false if it was already present"
|
|
2278
|
+
error_message:
|
|
2279
|
+
type: string
|
|
2280
|
+
required: false
|
|
2281
|
+
|
|
2282
|
+
# ── Policy engine ────────────────────────────────────────────────────
|
|
2283
|
+
# OPA-like enterprise policy enforcement. Actions are evaluated
|
|
2284
|
+
# against policy rules before execution. Policies can be updated
|
|
2285
|
+
# at runtime without server restart.
|
|
2286
|
+
policy:
|
|
2287
|
+
PolicyEval:
|
|
2288
|
+
code: 0x9b
|
|
2289
|
+
description: >
|
|
2290
|
+
Request policy evaluation for an action. The server checks
|
|
2291
|
+
the action against loaded policy rules and returns a decision.
|
|
2292
|
+
fields:
|
|
2293
|
+
request_id:
|
|
2294
|
+
type: string
|
|
2295
|
+
required: true
|
|
2296
|
+
action:
|
|
2297
|
+
type: string
|
|
2298
|
+
required: true
|
|
2299
|
+
description: '"open_pty", "exec", "file_write", "gateway", etc.'
|
|
2300
|
+
principal:
|
|
2301
|
+
type: string
|
|
2302
|
+
required: true
|
|
2303
|
+
context:
|
|
2304
|
+
type: json
|
|
2305
|
+
default: "{}"
|
|
2306
|
+
description: "Additional context (IP, time, session metadata)"
|
|
2307
|
+
|
|
2308
|
+
PolicyResult:
|
|
2309
|
+
code: 0x9c
|
|
2310
|
+
description: >
|
|
2311
|
+
Policy evaluation result.
|
|
2312
|
+
fields:
|
|
2313
|
+
request_id:
|
|
2314
|
+
type: string
|
|
2315
|
+
required: true
|
|
2316
|
+
allowed:
|
|
2317
|
+
type: bool
|
|
2318
|
+
required: true
|
|
2319
|
+
reason:
|
|
2320
|
+
type: string
|
|
2321
|
+
required: false
|
|
2322
|
+
|
|
2323
|
+
PolicyUpdate:
|
|
2324
|
+
code: 0x9d
|
|
2325
|
+
description: >
|
|
2326
|
+
Push a policy update. The server reloads policy rules from
|
|
2327
|
+
the provided document.
|
|
2328
|
+
fields:
|
|
2329
|
+
policy_id:
|
|
2330
|
+
type: string
|
|
2331
|
+
required: true
|
|
2332
|
+
rules:
|
|
2333
|
+
type: json
|
|
2334
|
+
required: true
|
|
2335
|
+
description: "Policy document (JSON rule set)"
|
|
2336
|
+
version:
|
|
2337
|
+
type: u64
|
|
2338
|
+
required: true
|
|
2339
|
+
|
|
2340
|
+
# ── Terminal frontend ────────────────────────────────────────────────
|
|
2341
|
+
# Negotiate terminal frontend configuration. Allows the client to
|
|
2342
|
+
# specify which terminal emulator to use (ghostty-web, xterm.js, etc.)
|
|
2343
|
+
# and pass frontend-specific options.
|
|
2344
|
+
terminal:
|
|
2345
|
+
TerminalConfig:
|
|
2346
|
+
code: 0x9e
|
|
2347
|
+
description: >
|
|
2348
|
+
Sent by the client to configure the terminal frontend for a
|
|
2349
|
+
channel. The server may use this to adjust PTY behavior
|
|
2350
|
+
(e.g., TERM environment variable, color depth).
|
|
2351
|
+
fields:
|
|
2352
|
+
channel_id:
|
|
2353
|
+
type: u32
|
|
2354
|
+
required: true
|
|
2355
|
+
frontend:
|
|
2356
|
+
type: string
|
|
2357
|
+
required: true
|
|
2358
|
+
description: '"ghostty-web", "xterm.js", "hterm", or custom'
|
|
2359
|
+
options:
|
|
2360
|
+
type: json
|
|
2361
|
+
default: "{}"
|
|
2362
|
+
description: "Frontend-specific options (font, theme, keybindings)"
|
|
2363
|
+
|
|
2364
|
+
# ── Operator-side shared folders (#159) ──────────────────────────────
|
|
2365
|
+
# A host with no disk of its own (a browser tab) sometimes needs files that
|
|
2366
|
+
# live on the OPERATOR's machine (`docker run -v $PWD:/app` reached through
|
|
2367
|
+
# `wsh -L sock:endpoint=docker`). The operator's client OFFERS named
|
|
2368
|
+
# directories (`wsh --share NAME=/abs/dir[:ro|:rw]`); the host asks for file
|
|
2369
|
+
# operations on them, one bounded request at a time, and the client answers.
|
|
2370
|
+
#
|
|
2371
|
+
# Negotiation: a host that can use shares lists the feature "shares" in
|
|
2372
|
+
# ServerHello.features. A client that has shares to offer and sees the
|
|
2373
|
+
# feature sends ONE ShareOffer after authentication. A host that does not
|
|
2374
|
+
# list the feature never receives a ShareOffer; a client without shares
|
|
2375
|
+
# never sends one, so a released peer is unaffected either way.
|
|
2376
|
+
#
|
|
2377
|
+
# Direction: unlike every other request in wsh, these are HOST-initiated: the
|
|
2378
|
+
# host sends ShareRequest, the client answers each with exactly one
|
|
2379
|
+
# ShareReply carrying the same request_id. The client is the file server and
|
|
2380
|
+
# treats every request as untrusted input (it serves only what its operator
|
|
2381
|
+
# named on the command line; nothing a host sends can add or widen a share).
|
|
2382
|
+
#
|
|
2383
|
+
# Paths: relative to the share root, "/"-separated; a leading "/" means the
|
|
2384
|
+
# root; empty and "." components are ignored; ".." is refused (EINVAL); at
|
|
2385
|
+
# most 4096 bytes and 128 components, each at most 255 bytes. A symlink is
|
|
2386
|
+
# never followed: every operation sees a symlink as a symlink (type
|
|
2387
|
+
# "symlink"), and a symlink in the middle of a path is ELOOP. Sockets,
|
|
2388
|
+
# devices and FIFOs do not exist for the host (ENOENT, and they are left out
|
|
2389
|
+
# of listings).
|
|
2390
|
+
#
|
|
2391
|
+
# Attr (a map): {type: "file" | "directory" | "symlink", size, mode
|
|
2392
|
+
# (permission bits, 0o777 at most), mtime_ms, atime_ms, ctime_ms, nlink, ino}.
|
|
2393
|
+
# Errors: ShareReply.ok=false with `errno` one of ENOENT, EEXIST, ENOTDIR,
|
|
2394
|
+
# EISDIR, ENOTEMPTY, EACCES, EPERM, EROFS, EINVAL, EBADF, ELOOP,
|
|
2395
|
+
# ENAMETOOLONG, ENOSPC, EMFILE, EBUSY, EAGAIN, EXDEV, EFBIG, ENOTSUP, ESTALE,
|
|
2396
|
+
# EIO, and a short `message` for a person (never a path outside the share).
|
|
2397
|
+
#
|
|
2398
|
+
# Flow control: ShareOffer.max_inflight is the number of requests the host
|
|
2399
|
+
# may have unanswered at once (more get EAGAIN); ShareOffer.max_bytes is the
|
|
2400
|
+
# most data one request may carry or ask for (a bigger `length` is clamped, a
|
|
2401
|
+
# bigger `data` is EINVAL). A ShareReply is at most max_bytes of
|
|
2402
|
+
# data plus a bounded listing. This is the same bounded-window idea as
|
|
2403
|
+
# GatewayCredit, expressed in requests because each reply is the answer to
|
|
2404
|
+
# one of them. Everything rides the connection's normal framing, so a sealed
|
|
2405
|
+
# session (EncryptedFrame) protects it with no extra crypto.
|
|
2406
|
+
shares:
|
|
2407
|
+
ShareOffer:
|
|
2408
|
+
code: 0xa8
|
|
2409
|
+
description: >
|
|
2410
|
+
Sent once by the client after authentication to a host that listed
|
|
2411
|
+
"shares", naming the directories it serves. `writable` lists the names
|
|
2412
|
+
among `shares` that accept writes (everything else is read-only).
|
|
2413
|
+
The host may use any subset; it never learns more than the names.
|
|
2414
|
+
fields:
|
|
2415
|
+
shares:
|
|
2416
|
+
type: "string[]"
|
|
2417
|
+
required: true
|
|
2418
|
+
description: 'Share names ([A-Za-z0-9][A-Za-z0-9._-]{0,63}); at most 16'
|
|
2419
|
+
writable:
|
|
2420
|
+
type: "string[]"
|
|
2421
|
+
default: "[]"
|
|
2422
|
+
max_inflight:
|
|
2423
|
+
type: u32
|
|
2424
|
+
required: true
|
|
2425
|
+
description: "Requests the host may have unanswered at once"
|
|
2426
|
+
max_bytes:
|
|
2427
|
+
type: u32
|
|
2428
|
+
required: true
|
|
2429
|
+
description: "Largest data payload of one request or reply"
|
|
2430
|
+
paths:
|
|
2431
|
+
type: "string[]"
|
|
2432
|
+
required: false
|
|
2433
|
+
description: >
|
|
2434
|
+
Optional, parallel to `shares`: each share's root directory on the operator's machine, as the operator
|
|
2435
|
+
typed it, made absolute and lexically tidied (no "//", "." or trailing "/"). ADVISORY: the host cannot
|
|
2436
|
+
verify it and the client still serves only the directory it opened. A client that does not want to reveal
|
|
2437
|
+
paths omits the field (`wsh --share-hide-path`). A host uses it only when it is an array as long as
|
|
2438
|
+
`shares` and the entry is an absolute string of at most 4096 bytes without NUL; anything else is
|
|
2439
|
+
ignored, never an error. Older peers that do not know the field keep working.
|
|
2440
|
+
|
|
2441
|
+
ShareRequest:
|
|
2442
|
+
code: 0xa9
|
|
2443
|
+
description: >
|
|
2444
|
+
Sent by the HOST to ask the client for one file operation on a share.
|
|
2445
|
+
`op` selects the operation; the fields it uses:
|
|
2446
|
+
stat, lstat (path) -> attr;
|
|
2447
|
+
readdir (path, cursor?, length? = most entries) -> entries (each an
|
|
2448
|
+
Attr plus `name`, sorted by name) and `cursor` when more remain: one
|
|
2449
|
+
round trip lists a directory WITH attributes;
|
|
2450
|
+
readlink (path) -> target;
|
|
2451
|
+
open (path, flags, length?) -> handle, attr, and, when the file is
|
|
2452
|
+
no bigger than `length` (clamped to max_bytes) and opened for
|
|
2453
|
+
reading ONLY, its whole content in `data` with eof=true and NO
|
|
2454
|
+
handle (there is nothing left to read or close: a small file costs
|
|
2455
|
+
one round trip); flags are any of
|
|
2456
|
+
"read" "write" "create" "excl" "trunc" (a write is at an explicit
|
|
2457
|
+
offset: there is no append mode); "create", "write" and "trunc"
|
|
2458
|
+
need a writable share; `mode` applies to a created file;
|
|
2459
|
+
create (path, mode?) -> handle, attr: a NEW file (EEXIST if the name
|
|
2460
|
+
is taken, even by a symlink), opened for writing; use open with
|
|
2461
|
+
"create" to open-or-create;
|
|
2462
|
+
read (handle, offset, length) -> data, eof;
|
|
2463
|
+
write (handle, offset, data) -> written;
|
|
2464
|
+
close (handle);
|
|
2465
|
+
mkdir (path, mode?) -> attr; unlink (path); rmdir (path);
|
|
2466
|
+
rename (path, to);
|
|
2467
|
+
setattr (path, or handle, and attr with any of mode, atime_ms,
|
|
2468
|
+
mtime_ms, size) -> attr: a new size is a truncate.
|
|
2469
|
+
A host should close what it opens; the client bounds the open handles
|
|
2470
|
+
(EMFILE) and drops them all when the connection ends.
|
|
2471
|
+
fields:
|
|
2472
|
+
request_id:
|
|
2473
|
+
type: u32
|
|
2474
|
+
required: true
|
|
2475
|
+
share:
|
|
2476
|
+
type: string
|
|
2477
|
+
required: true
|
|
2478
|
+
op:
|
|
2479
|
+
type: string
|
|
2480
|
+
required: true
|
|
2481
|
+
path:
|
|
2482
|
+
type: string
|
|
2483
|
+
required: false
|
|
2484
|
+
to:
|
|
2485
|
+
type: string
|
|
2486
|
+
required: false
|
|
2487
|
+
handle:
|
|
2488
|
+
type: u32
|
|
2489
|
+
required: false
|
|
2490
|
+
offset:
|
|
2491
|
+
type: u64
|
|
2492
|
+
required: false
|
|
2493
|
+
length:
|
|
2494
|
+
type: u32
|
|
2495
|
+
required: false
|
|
2496
|
+
mode:
|
|
2497
|
+
type: u32
|
|
2498
|
+
required: false
|
|
2499
|
+
flags:
|
|
2500
|
+
type: "string[]"
|
|
2501
|
+
default: "[]"
|
|
2502
|
+
cursor:
|
|
2503
|
+
type: string
|
|
2504
|
+
required: false
|
|
2505
|
+
attr:
|
|
2506
|
+
type: json
|
|
2507
|
+
default: "{}"
|
|
2508
|
+
description: "setattr: the changes ({mode, atime_ms, mtime_ms, size})"
|
|
2509
|
+
data:
|
|
2510
|
+
type: bytes
|
|
2511
|
+
required: false
|
|
2512
|
+
|
|
2513
|
+
ShareReply:
|
|
2514
|
+
code: 0xaa
|
|
2515
|
+
description: >
|
|
2516
|
+
The client's answer to one ShareRequest. ok=false carries `errno` (and
|
|
2517
|
+
a `message`); ok=true carries what the operation returns (see
|
|
2518
|
+
ShareRequest). Only the fields an operation returns are present.
|
|
2519
|
+
fields:
|
|
2520
|
+
request_id:
|
|
2521
|
+
type: u32
|
|
2522
|
+
required: true
|
|
2523
|
+
ok:
|
|
2524
|
+
type: bool
|
|
2525
|
+
required: true
|
|
2526
|
+
errno:
|
|
2527
|
+
type: string
|
|
2528
|
+
required: false
|
|
2529
|
+
message:
|
|
2530
|
+
type: string
|
|
2531
|
+
required: false
|
|
2532
|
+
attr:
|
|
2533
|
+
type: json
|
|
2534
|
+
default: "{}"
|
|
2535
|
+
entries:
|
|
2536
|
+
type: json
|
|
2537
|
+
default: "[]"
|
|
2538
|
+
cursor:
|
|
2539
|
+
type: string
|
|
2540
|
+
required: false
|
|
2541
|
+
handle:
|
|
2542
|
+
type: u32
|
|
2543
|
+
required: false
|
|
2544
|
+
data:
|
|
2545
|
+
type: bytes
|
|
2546
|
+
required: false
|
|
2547
|
+
eof:
|
|
2548
|
+
type: bool
|
|
2549
|
+
required: false
|
|
2550
|
+
written:
|
|
2551
|
+
type: u32
|
|
2552
|
+
required: false
|
|
2553
|
+
target:
|
|
2554
|
+
type: string
|
|
2555
|
+
required: false
|
|
2556
|
+
|
|
2557
|
+
# ── Execution targets (wsh #121) ─────────────────────────────────────
|
|
2558
|
+
# A host that fronts several execution targets (containers, VMs, workers,
|
|
2559
|
+
# sandboxes) says so with the `targets` feature in ServerHello.features.
|
|
2560
|
+
# Open, FileOp and OpenEndpoint then take an optional `target`, and a client
|
|
2561
|
+
# may ask what it can reach. Nothing is on by default: a host without the
|
|
2562
|
+
# feature knows no targets, and a client must not send `target` to it (an
|
|
2563
|
+
# older host rejects the unknown field; one that knows the field and has no
|
|
2564
|
+
# targets answers OpenFail, FileResult(success=false) or GatewayFail).
|
|
2565
|
+
# What a key may see is the host's decision: TargetList lists the targets the
|
|
2566
|
+
# caller is allowed on, not every target the host has.
|
|
2567
|
+
targets:
|
|
2568
|
+
ListTargets:
|
|
2569
|
+
code: 0xab
|
|
2570
|
+
description: >
|
|
2571
|
+
Sent by the client to a host that listed "targets" to ask which
|
|
2572
|
+
execution targets it may use. Answered with TargetList.
|
|
2573
|
+
fields: {}
|
|
2574
|
+
|
|
2575
|
+
TargetList:
|
|
2576
|
+
code: 0xac
|
|
2577
|
+
description: >
|
|
2578
|
+
The host's answer to ListTargets: the targets the caller is allowed
|
|
2579
|
+
on (the host decides what to reveal per key), in the host's order.
|
|
2580
|
+
fields:
|
|
2581
|
+
targets:
|
|
2582
|
+
type: "TargetInfo[]"
|
|
2583
|
+
required: true
|
|
2584
|
+
|
|
2585
|
+
nested_types:
|
|
2586
|
+
TargetInfo:
|
|
2587
|
+
fields:
|
|
2588
|
+
name:
|
|
2589
|
+
type: string
|
|
2590
|
+
required: true
|
|
2591
|
+
description: "The value to put in Open.target (and FileOp.target, OpenEndpoint.target)"
|
|
2592
|
+
description:
|
|
2593
|
+
type: string
|
|
2594
|
+
required: false
|
|
2595
|
+
description: "A human line about the target (what it is); not for parsing"
|
|
2596
|
+
capabilities:
|
|
2597
|
+
type: "string[]"
|
|
2598
|
+
default: "[]"
|
|
2599
|
+
description: 'What the caller can do on it: any of "exec", "pty", "file", "endpoint" (a hint; the host decides on each request)'
|
|
2600
|
+
|
|
2601
|
+
FileEntry:
|
|
2602
|
+
# wsh #59: the shape of a directory entry, formalized from the JS SDK's
|
|
2603
|
+
# previously-private WshFileListEntry (name, size, modified, type) so
|
|
2604
|
+
# it is generated into both languages instead of invented once. Used
|
|
2605
|
+
# by FileResult.entries for a "list" op.
|
|
2606
|
+
fields:
|
|
2607
|
+
name:
|
|
2608
|
+
type: string
|
|
2609
|
+
required: true
|
|
2610
|
+
description: "Entry name (not a full path) within the listed directory"
|
|
2611
|
+
size:
|
|
2612
|
+
type: u64
|
|
2613
|
+
required: true
|
|
2614
|
+
description: "Size in bytes (0 for directories and most non-regular-file types)"
|
|
2615
|
+
modified:
|
|
2616
|
+
type: u64
|
|
2617
|
+
required: true
|
|
2618
|
+
description: "Last-modified time, Unix epoch seconds (UTC)"
|
|
2619
|
+
type:
|
|
2620
|
+
type: FileEntryType
|
|
2621
|
+
required: true
|
|
2622
|
+
symlink_target:
|
|
2623
|
+
type: string
|
|
2624
|
+
required: false
|
|
2625
|
+
description: "Present only when type == symlink: the link's target path, unresolved"
|
|
2626
|
+
|
|
2627
|
+
AttachmentInfo:
|
|
2628
|
+
fields:
|
|
2629
|
+
session_id:
|
|
2630
|
+
type: string
|
|
2631
|
+
required: true
|
|
2632
|
+
mode:
|
|
2633
|
+
type: string
|
|
2634
|
+
required: true
|
|
2635
|
+
username:
|
|
2636
|
+
type: string
|
|
2637
|
+
required: false
|
|
2638
|
+
channel_id:
|
|
2639
|
+
type: u32
|
|
2640
|
+
required: false
|
|
2641
|
+
description: >
|
|
2642
|
+
Only in the Presence that answers this connection's own
|
|
2643
|
+
Attach/Resume, on the entry describing that attachment: the
|
|
2644
|
+
channel id the host assigned on this connection. The replay and
|
|
2645
|
+
the live output follow as SessionData with this channel_id (the
|
|
2646
|
+
channel is always message-backed, whatever data_mode the session
|
|
2647
|
+
was opened with), and Exit/Close end it. Absent from roster
|
|
2648
|
+
broadcasts, where the entry is someone else's.
|
|
2649
|
+
seq:
|
|
2650
|
+
type: u64
|
|
2651
|
+
required: false
|
|
2652
|
+
description: >
|
|
2653
|
+
Alongside channel_id: the session output position (cumulative
|
|
2654
|
+
bytes, see Resume.last_seq) of the first byte that will be
|
|
2655
|
+
delivered on that channel -- the requested last_seq for Resume,
|
|
2656
|
+
the oldest retained byte for Attach. A client adds the length of
|
|
2657
|
+
each SessionData it receives to this to know its own position.
|
|
2658
|
+
|
|
2659
|
+
PeerInfo:
|
|
2660
|
+
fields:
|
|
2661
|
+
fingerprint:
|
|
2662
|
+
type: string
|
|
2663
|
+
required: true
|
|
2664
|
+
fingerprint_short:
|
|
2665
|
+
type: string
|
|
2666
|
+
required: true
|
|
2667
|
+
username:
|
|
2668
|
+
type: string
|
|
2669
|
+
required: true
|
|
2670
|
+
capabilities:
|
|
2671
|
+
type: "string[]"
|
|
2672
|
+
default: "[]"
|
|
2673
|
+
peer_type:
|
|
2674
|
+
type: string
|
|
2675
|
+
default: '"host"'
|
|
2676
|
+
shell_backend:
|
|
2677
|
+
type: string
|
|
2678
|
+
default: '"pty"'
|
|
2679
|
+
source:
|
|
2680
|
+
type: string
|
|
2681
|
+
default: '"wsh-relay"'
|
|
2682
|
+
supports_attach:
|
|
2683
|
+
type: bool
|
|
2684
|
+
default: false
|
|
2685
|
+
supports_replay:
|
|
2686
|
+
type: bool
|
|
2687
|
+
default: false
|
|
2688
|
+
supports_echo:
|
|
2689
|
+
type: bool
|
|
2690
|
+
default: false
|
|
2691
|
+
supports_term_sync:
|
|
2692
|
+
type: bool
|
|
2693
|
+
default: false
|
|
2694
|
+
last_seen:
|
|
2695
|
+
type: u64
|
|
2696
|
+
required: false
|
|
2697
|
+
public_key:
|
|
2698
|
+
type: bytes
|
|
2699
|
+
required: false
|
|
2700
|
+
seq:
|
|
2701
|
+
type: u64
|
|
2702
|
+
required: false
|
|
2703
|
+
record_signature:
|
|
2704
|
+
type: bytes
|
|
2705
|
+
required: false
|
|
2706
|
+
|
|
2707
|
+
McpToolSpec:
|
|
2708
|
+
fields:
|
|
2709
|
+
name:
|
|
2710
|
+
type: string
|
|
2711
|
+
required: true
|
|
2712
|
+
description:
|
|
2713
|
+
type: string
|
|
2714
|
+
required: true
|
|
2715
|
+
parameters:
|
|
2716
|
+
type: json
|
|
2717
|
+
default: "{}"
|
|
2718
|
+
|
|
2719
|
+
SessionSummary:
|
|
2720
|
+
fields:
|
|
2721
|
+
session_id:
|
|
2722
|
+
type: string
|
|
2723
|
+
required: true
|
|
2724
|
+
name:
|
|
2725
|
+
type: string
|
|
2726
|
+
required: false
|
|
2727
|
+
username:
|
|
2728
|
+
type: string
|
|
2729
|
+
required: true
|
|
2730
|
+
fingerprint_short:
|
|
2731
|
+
type: string
|
|
2732
|
+
required: true
|
|
2733
|
+
created_at_secs:
|
|
2734
|
+
type: u64
|
|
2735
|
+
required: true
|
|
2736
|
+
idle_secs:
|
|
2737
|
+
type: u64
|
|
2738
|
+
required: true
|
|
2739
|
+
attached_count:
|
|
2740
|
+
type: u32
|
|
2741
|
+
required: true
|
|
2742
|
+
|
|
2743
|
+
crypto:
|
|
2744
|
+
auth_transcript:
|
|
2745
|
+
algorithm: SHA-256
|
|
2746
|
+
formula: 'SHA-256(PROTOCOL_VERSION || "\0" || lp(username) || lp(session_id) || nonce)'
|
|
2747
|
+
note: "lp() is a 4-byte big-endian length prefix, applied to username and session_id since both are variable-length strings that would otherwise be ambiguous when concatenated. username binds the transcript to a specific identity so a signature can't be replayed under a different username. channelBinding can be appended but defaults to empty (no server host-identity binding exists in the protocol yet)."
|
|
2748
|
+
fingerprint:
|
|
2749
|
+
algorithm: SHA-256
|
|
2750
|
+
input: raw_ed25519_public_key_32_bytes
|
|
2751
|
+
output: hex_encoded_64_chars
|
|
2752
|
+
session_token:
|
|
2753
|
+
format: "[8B expiry_be][32B HMAC-SHA256(secret, session_id || expiry)]"
|
|
2754
|
+
total_bytes: 40
|
|
2755
|
+
key_type: Ed25519
|
|
2756
|
+
ssh_wire_format: '[4B len]["ssh-ed25519"][4B len][32B raw_key]'
|
|
2757
|
+
|
|
2758
|
+
transport:
|
|
2759
|
+
webtransport:
|
|
2760
|
+
description: "QUIC streams as channels. 1 bidi = control. Per channel: 1 bidi + optional uni."
|
|
2761
|
+
websocket:
|
|
2762
|
+
framing: "[1B frame_type][4B stream_id][payload]"
|
|
2763
|
+
frame_types:
|
|
2764
|
+
control: 0x01
|
|
2765
|
+
data: 0x02
|
|
2766
|
+
open_stream: 0x03
|
|
2767
|
+
close_stream: 0x04
|
|
2768
|
+
note: "Stream 0 carries length-prefixed CBOR control messages (frameEncode/FrameDecoder); other stream IDs carry raw data bytes with no extra framing. See src/transport-ws.mjs for the reference implementation."
|
|
2769
|
+
|
|
2770
|
+
relay:
|
|
2771
|
+
# Single source of truth for which message types a relay may forward
|
|
2772
|
+
# inside a RelayForward wrapper. Generated into JS (RELAY_FORWARDABLE,
|
|
2773
|
+
# a Set) and Rust (is_relay_forwardable(), a match) by codegen.mjs, so
|
|
2774
|
+
# the two implementations can no longer drift out of sync the way the
|
|
2775
|
+
# hand-maintained allowlists did before RelayForward existed.
|
|
2776
|
+
#
|
|
2777
|
+
# KeyExchange and EncryptedFrame are on the list so two endpoints can run
|
|
2778
|
+
# E2E through a bridge: the relay carries the CBOR of an EncryptedFrame as
|
|
2779
|
+
# opaque bytes and holds no key. KeyExchange is an UNAUTHENTICATED ephemeral
|
|
2780
|
+
# exchange, so it protects against a relay that only observes, not one that
|
|
2781
|
+
# substitutes keys; peers who need that must authenticate the derived key
|
|
2782
|
+
# themselves (see the README's Security model).
|
|
2783
|
+
forwardable: [Open, OpenOk, OpenFail, Close, Exit, Resize, Signal, SessionData, GatewayData, GatewayCredit, GatewayOk, GatewayFail, GatewayClose, McpDiscover, McpTools, McpCall, McpResult, McpCancel, ReverseAccept, ReverseReject, GuestJoin, GuestRevoke, CopilotAttach, CopilotDetach, FileOp, FileResult, FileChunk, PolicyEval, EchoAck, EchoState, TermSync, TermDiff, KeyExchange, EncryptedFrame]
|