@linxin666/dsh-remote-bridge 0.4.13 → 0.4.15
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.i18n.yaml +2 -2
- package/README.md +17 -12
- package/README.zh.md +17 -12
- package/lib/client.js +160 -109
- package/lib/client.js.map +1 -1
- package/lib/index.js +3053 -4804
- package/lib/types/client/PairPanel.d.ts +13 -1
- package/lib/types/client/locales.d.ts +18 -10
- package/lib/types/client/pair-token.d.ts +7 -0
- package/lib/types/core/connection.d.ts +41 -0
- package/lib/types/core/devices.d.ts +60 -7
- package/lib/types/core/pair-address.d.ts +25 -0
- package/lib/types/core/protocol.d.ts +22 -0
- package/lib/types/core/push.d.ts +19 -1
- package/lib/types/host/relay-bridge-connector.d.ts +19 -0
- package/lib/types/host/relay-connector.d.ts +4 -0
- package/lib/types/host/relay-control.d.ts +77 -6
- package/lib/types/host/relay-registry.d.ts +12 -3
- package/lib/types/host/relay-secondary.d.ts +209 -0
- package/lib/types/host/relay.d.ts +1 -1
- package/lib/types/host/routes.d.ts +5 -0
- package/lib/types/index.d.ts +65 -3
- package/package.json +16 -16
- package/src/client/PairEntry.tsx +1 -0
- package/src/client/PairPanel.tsx +44 -5
- package/src/client/locales.ts +25 -15
- package/src/client/pair-token.ts +17 -2
- package/src/client/panel.module.css +32 -0
- package/src/core/connection.ts +110 -0
- package/src/core/devices.ts +141 -17
- package/src/core/pair-address.ts +50 -0
- package/src/core/protocol.ts +24 -0
- package/src/core/push.ts +20 -1
- package/src/host/relay-bridge-connector.ts +68 -2
- package/src/host/relay-connector.ts +9 -2
- package/src/host/relay-control.ts +98 -7
- package/src/host/relay-registry.ts +17 -5
- package/src/host/relay-secondary.ts +478 -0
- package/src/host/relay.ts +1 -1
- package/src/host/routes.ts +22 -5
- package/src/index.ts +270 -35
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# node scripts/verify-docs.mjs --write <dir>
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: ce70588a1ac33a05084dd22daaf15f62be8d0f62
|
|
6
|
+
README.zh.md: 8bad871cc6d2021b108e1d07807caaa6daa59f12
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ English | [中文](README.zh.md)
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<img src="https://img.shields.io/npm/v/@linxin666/dsh-remote-bridge?style=flat-square" alt="Version">
|
|
7
7
|
|
|
8
|
-
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.
|
|
8
|
+
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.1-4c6ef5?style=flat-square&labelColor=454a54" alt="DSH">
|
|
9
9
|
|
|
10
10
|
<img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
|
|
11
11
|
</p>
|
|
@@ -31,7 +31,7 @@ The package publishes one protocol and, beside it, one small browser surface. Wh
|
|
|
31
31
|
- **A subscription, not a poll.** `session.snapshot` opens the harness follow stream and keeps it, so the baseline and every later increment arrive over the same socket.
|
|
32
32
|
- **Approvals reach the client, and a reconnecting phone is handed the ones still waiting.** A tool that asks for permission arrives as an `approval.request` event and is answered with `approval.resolve`; a request nobody answers is rejected, and a connection that declared `approvals.v1` receives every unsettled approval again after its handshake.
|
|
33
33
|
- **Pairing.** A one-time bootstrap token plus a P-256 challenge-response mint a revocable device token; an unpaired connection reaches three methods only.
|
|
34
|
-
- **A pairing panel.** The same plugin row declares a `dsh.client` browser half: a QR code icon at the bottom of the sidebar (aria-label "Pair
|
|
34
|
+
- **A pairing panel.** The same plugin row declares a `dsh.client` browser half: a QR code icon at the bottom of the sidebar (aria-label "Pair an iPhone") that opens a modal displaying a 30 s single-use pairing QR code and a "New code" action.
|
|
35
35
|
- **No relay change.** The protocol rides whatever origin the instance already publishes, and the relay hop forwards it exactly as it forwards everything else.
|
|
36
36
|
|
|
37
37
|
## Transport
|
|
@@ -181,9 +181,9 @@ The device token rides the WebSocket upgrade as `Authorization: Bearer <deviceTo
|
|
|
181
181
|
|
|
182
182
|
### Bootstrap token
|
|
183
183
|
|
|
184
|
-
The pairing entry is a QR code icon at the bottom of the sidebar, with the accessible label "Pair
|
|
184
|
+
The pairing entry is a QR code icon at the bottom of the sidebar, with the accessible label "Pair an iPhone". Clicking it opens the pairing panel. The panel is strictly available on localhost: its token route `GET /remote-bridge/pair/token` is guarded by a two-condition loopback gate where both the socket address and the `Host` header must name this machine (remote or tunneled requests return 403).
|
|
185
185
|
|
|
186
|
-
The pairing code is single-use and valid for 30 seconds (`BOOTSTRAP_TOKEN_TTL_MS = 30_000`), consumed immediately upon the first `pair.begin`; clicking "New code" in the panel voids the previous code and mints a fresh one. There is no "Stop" button and no action to revoke all connected devices. The link is printed to the host log,
|
|
186
|
+
The pairing code is single-use and valid for 30 seconds (`BOOTSTRAP_TOKEN_TTL_MS = 30_000`), consumed immediately upon the first `pair.begin`; clicking "New code" in the panel voids the previous code and mints a fresh one. There is no "Stop" button and no action to revoke all connected devices. The machine-local link is printed to the host log as `pair a device with <ws link>`, and that line is followed only by the kind of phone-facing address: `(phone: lan)` when the host calls the origin a LAN address or the literal itself answers only inside the network this page is already on, `(phone: public)` in every other case, and no suffix when the host found no address at all. The code itself renders in the pairing panel for scanning.
|
|
187
187
|
|
|
188
188
|
```sh
|
|
189
189
|
curl -s http://127.0.0.1:3080/remote-bridge/pair/token
|
|
@@ -198,7 +198,7 @@ When this machine can determine a public or LAN origin — from live relay lease
|
|
|
198
198
|
"expiresAt": 1760000030000,
|
|
199
199
|
"url": "ws://127.0.0.1:3080/ios/v1?token=...",
|
|
200
200
|
"origin": "wss://<id>.dsh-market.com",
|
|
201
|
-
"originSource": "
|
|
201
|
+
"originSource": "realtime",
|
|
202
202
|
"pairingUrl": "wss://<id>.dsh-market.com/ios/v1?token=..."
|
|
203
203
|
}
|
|
204
204
|
```
|
|
@@ -240,7 +240,7 @@ Two consequences follow from that hop. It sees the request URL, so a `?token=` c
|
|
|
240
240
|
## Ingress stack and security model
|
|
241
241
|
|
|
242
242
|
`@linxin666/dsh-remote-bridge` owns the complete public and local network ingress stack for remote access:
|
|
243
|
-
- **Relay identity and leases**: `relay-registry` persists the relay ID and secret under `$DSH_HOME/remote-web-ui-registry/<profile>.json`; changing relay config remounts the plugin row. When mounting with `relay=false` and an on-disk identity already exists, it unregisters the previous registration row and releases its lease once via `pair.release()` (best-effort, logging any errors; unmounting neither releases nor unregisters, preserving bookmarked origins for server-side GC; mounting with `relay=false` never mints a new identity and has zero side effects if no identity file exists).
|
|
243
|
+
- **Relay identity and leases**: `relay-registry` persists the relay ID and secret under `$DSH_HOME/remote-web-ui-registry/<profile>.json`; changing relay config remounts the plugin row. When no tunnel is configured (`tunnel.mode === 'off'`) and no remote device is paired yet, the bridge stays idle at startup without minting an identity or claiming a relay lease; lease claiming is armed on demand once the roster loads a paired device, a local pairing token is requested, a device finishes pairing, or a tunnel is enabled (while suppressing transient `idle`/`claiming`/`dialing` state logs and deduplicating repeated identical failure lines). When mounting with `relay=false` and an on-disk identity already exists, it unregisters the previous registration row and releases its lease once via `pair.release()` (best-effort, logging any errors; unmounting neither releases nor unregisters, preserving bookmarked origins for server-side GC; mounting with `relay=false` never mints a new identity and has zero side effects if no identity file exists).
|
|
244
244
|
- **Relay connectors**: `relay-connector` manages quick and named tunnel connectors side by side, and `relay-bridge-connector` connects to the Cloudflare Durable Object meeting point over WSS, recording connection state in `$DSH_HOME/remote-web-ui-relay-bridge.json` (state file writing is verified behaviorally, defaulting to `$DSH_HOME` when unspecified, not checked via source text assertions).
|
|
245
245
|
- **Tunnel lifecycle**: `tunnel`, `tunnel-plan`, and `tunnel-orphan` manage platform `cloudflared` child processes with exponential backoff and reap orphaned processes left behind by crashes.
|
|
246
246
|
- **Ingress sync**: `ingress-sync` converges Cloudflare named tunnel ingress rules to the local gate port when the host listens on a different port.
|
|
@@ -249,7 +249,7 @@ Two consequences follow from that hop. It sees the request URL, so a `?token=` c
|
|
|
249
249
|
The security model enforces strict whitelisting across all external ingress paths:
|
|
250
250
|
- **Internal ingress gate (`src/host/ingress-gate.ts`)**: binds exclusively to `127.0.0.1` and forwards only WebSocket upgrades to `/ios/v1` to the host's own protocol port, rewriting the `Host` header to the loopback authority. Every other plain HTTP request and non-whitelisted upgrade is answered immediately with `404 {"error":"not-found"}` and closed without opening any upstream connection.
|
|
251
251
|
- **Tunnel target is the ingress gate, not the webServer**: cloudflared quick and named tunnels target the dynamic loopback port bound by `ingress-gate`, never the harness `webServer` port. A request routed through the tunnel cannot reach webServer routes, internal APIs, or other plugins.
|
|
252
|
-
- **Relay registration and public exposure**: the relay registration row only writes the quick tunnel URL, which points to the ingress gate, so the public internet still only sees /ios/v1. When the plan is quick and the tunnel is running, the gate URL is announced to the relay Worker (proxying `<id>.dsh-market.com`
|
|
252
|
+
- **Relay registration and public exposure**: the relay registration row only writes the quick tunnel URL, which points to the ingress gate, so the public internet still only sees /ios/v1. When the plan is quick and the tunnel is running, the gate URL is announced to the relay Worker (proxying the stable subdomain to this machine; endpoints and suffix are determined by configuration, defaulting to `<id>.dsh-market.com`); plugin disposal clears local references without withdrawing the row. QR public address selection is decided by `livePublicOriginOf`: bridge or named leases prioritize the stable subdomain; quick leases fall back to the tunnel running URL while registration is unconfirmed; no lease uses the tunnel URL; none returns no address. Fallbacks then check `DSH_REMOTE_PUBLIC_BASE_URL`, and the LAN fallback provides an address only when the LAN forwarder is actually listening using its snapshot's bound address and port (never guessing the first IP in the address list, returning no address when stopped; the disk registry row fallback has been completely removed, eliminating the last data dependency on legacy data files).
|
|
253
253
|
- **LAN forwarder target is the ingress gate**: the LAN forwarder listens on the machine's LAN IPv4 address and re-issues traffic exclusively to the `ingress-gate` port, so local network reachability is also constrained strictly to `/ios/v1`.
|
|
254
254
|
- **Relay bridge connector whitelist**: the Durable Object multiplexer in `relay-bridge-connector.ts` applies the same whitelist. Non-`/ios/v1` HTTP streams receive `404 {"error":"not-found"}`, and non-whitelisted WebSocket upgrades return `ws-fail 404 {"error":"not-found"}`, establishing no upstream connection.
|
|
255
255
|
- **Historical spelling retention and coexistence caveat**: the registry directory `$DSH_HOME/remote-web-ui-registry/` and state file `remote-web-ui-relay-bridge.json` intentionally retain their historical names so existing profiles maintain identity continuity and previously paired devices keep their credentials across upgrades. **Known risk and coexistence caveat**: never enable relay concurrently on both this plugin and the deprecated `dsh-remote-web-ui` in the same profile — both share the same identity file per profile; mounting the bridge with `relay=false` withdraws the registration row and releases the lease for that shared identity, breaking the legacy plugin's active relay, while running both with relay enabled causes bridge connectors to compete over the same Durable Object connection (or quick tunnel registrations to overwrite each other). This cleanup behavior is intentional.
|
|
@@ -261,7 +261,9 @@ The plugin is configured through profile YAML (`cordis.patch.yml` or profile con
|
|
|
261
261
|
|
|
262
262
|
| Key | Type | Default | Description |
|
|
263
263
|
| --- | --- | --- | --- |
|
|
264
|
-
| `relay` | boolean | `true` | Whether to claim relay leases. Enabled by default;
|
|
264
|
+
| `relay` | boolean | `true` | Whether to claim relay leases. Enabled by default; when no tunnel is configured, leases are claimed on demand once a device is paired or pairing is requested. |
|
|
265
|
+
| `relayControlUrl` | string | `'https://dsh-market.com/api/relay'` | Relay control-plane base URL; claim, release, register, and unregister endpoints are all derived from it. |
|
|
266
|
+
| `relayPublicSuffix` | string | `'.dsh-market.com'` | Stable hostname suffix. |
|
|
265
267
|
| `autoTunnel` | boolean | `false` | Whether to start a Cloudflare quick tunnel targeting the ingress gate. |
|
|
266
268
|
| `lanBind` | boolean | `undefined` (off) | Whether to start the LAN-edge forwarder listening on the machine's local IPv4 address. |
|
|
267
269
|
| `tunnelToken` | string | `undefined` | Cloudflare named tunnel token for running named tunnels. |
|
|
@@ -278,11 +280,13 @@ The browser half exists so that an operator who never opens a terminal still has
|
|
|
278
280
|
|
|
279
281
|
The panel has one job — put the live one-time code in front of the operator, in one reading order:
|
|
280
282
|
|
|
281
|
-
- **
|
|
283
|
+
- **Header and subtitle set the scope.** Title "iOS app pairing"; subtitle "Scan the QR code with the iOS app (beta) to connect an iPhone to this computer. The code is shown only on this machine.", stating the target and security boundary.
|
|
284
|
+
- **The QR symbol is the code.** It encodes either the bare 43-character base64url token or, when the host can name its own public origin, the `{token,url}` document one scan turns into a fully configured iPhone. A URL the host did not vouch for would let the app's own parser rewrite its origin onto this machine's loopback address, which is precisely the address an iPhone cannot reach. The encoded string is mirrored once, as the `data-dsh-qr-value` attribute on the symbol's part, so a UI check can compare it without decoding anything; it is never rendered as text.
|
|
282
285
|
- **One status line under the symbol.** A live code counts its 30 s window down beside a progress bar; an expired code states the expiry in the same fixed box, so only the sentence changes.
|
|
283
|
-
- **One address line.**
|
|
284
|
-
- **One single-use note.** The code is
|
|
286
|
+
- **One address line.** A located origin is stated as a kind rather than printed: "The QR code carries the public address: the iPhone connects to this computer as soon as it scans". The one-time code burns 30 seconds after it appears, while a durable public hostname, once rendered as text, outlives every screenshot it appears in; the symbol already carries the address the phone needs, and Copy hands over the same `{token,url}` string either way. A LAN literal is not that fact, and the line names it — "The QR code points at the LAN address {origin}: the iPhone must be on the same network" — when the host calls the origin a LAN address or when the literal itself answers only inside the network this page is already on. With no located address the line says outright "No public address found: set the connection address in the app to your public relay first, then scan. {host} (this page) is reachable only from this machine."
|
|
287
|
+
- **One single-use note.** The code is single-use: pairing spends it, and a new code voids the previous one.
|
|
285
288
|
- **One action row.** Copy puts the very string the symbol encodes on the clipboard, and **New code** mints a fresh token and voids the previous one; both are one library control at one size, so their states never diverge. Once the code expires, mint-again is the only way back to a scannable symbol: copy is disabled and the symbol is dimmed in place instead of resized or removed.
|
|
289
|
+
- **One beta entry.** Provides "[The iOS app is in beta. Come talk to us on Discord](https://discord.gg/nBy28kjun)", clickable across the entire line.
|
|
286
290
|
- **A refusal is never silent.** The read is the same loopback-only route an operator would curl: a `403` renders as "this page is not open on this machine" and offers nothing to press, a request that never arrives renders as its own unreachable state with a retry, and an unexpected answer names the status it got.
|
|
287
291
|
|
|
288
292
|
Opening and closing are one motion in both directions: the card stays mounted and plays the dialog's own enter fade backwards, and the reduced-motion path keeps that lifecycle as one short opacity fade rather than dropping the exit. Geometry is held across every state — the symbol's box, the status row, the address line and the copy label keep their height and width — so a countdown, an expiry and a copy confirmation never move their neighbours.
|
|
@@ -342,13 +346,14 @@ The bridge is mounted like any other host plugin row. It carries no user-facing
|
|
|
342
346
|
|
|
343
347
|
- **Pairing is a full-control credential.** A paired device reaches the harness in-process: sessions, prompts, approvals. Only pair devices you control, and revoke by removing the roster row and restarting the host.
|
|
344
348
|
- **In-process calls speak for the owner, only behind this bridge's own gate.** Since DSH 0.2.1 the harness gateway requires every call to name the peer it speaks for, and the bridge answers with one in-process owner peer (`{kind:'owner'}`) that it mints itself at mount and attaches to every gateway call. That claim is safe because it is exercised only after the bridge's own pairing check — an unpaired connection is refused before any gateway call exists — and no field of a protocol frame can set a principal: a client that names one in its payload is ignored. The peer takes no forwarded-event interactions, so it never receives forwarded Host events either.
|
|
345
|
-
- **The token endpoint is loopback-only, on two conditions.** The socket address must be loopback and the `Host` header must name this machine. A tunneled request is terminated by the tunnel client on this same host, so the socket address alone reads `127.0.0.1` for a request the whole internet can reach, while the relay and a plain tunnel rewrite `Host` to the public name; failing either condition is a 403. The token is memory-only, expires in 30 s, is spent by one `pair.begin`, and the
|
|
349
|
+
- **The token endpoint is loopback-only, on two conditions.** The socket address must be loopback and the `Host` header must name this machine. A tunneled request is terminated by the tunnel client on this same host, so the socket address alone reads `127.0.0.1` for a request the whole internet can reach, while the relay and a plain tunnel rewrite `Host` to the public name; failing either condition is a 403. The token is memory-only, expires in 30 s, is spent by one `pair.begin`, and the machine-local link is written to the host log — treat that log line as a live secret. The phone's side of that line is the kind of address alone (`(phone: public)` or `(phone: lan)`, no suffix when there is none): this pairing line is the one an operator pastes elsewhere, and a public hostname or a LAN literal in it would outlive the code it belongs to.
|
|
346
350
|
- **The pairing panel renders a live secret and nothing more.** It reads the same loopback-gated route over a same-origin request, so it is reachable exactly where the `curl` form is, and nowhere else. It cannot mint a device token, spend one, list the roster or revoke a device: `pair.begin` stays the phone's call, and revocation stays a roster edit plus a host restart. The QR carries either the bare token or the host's own `{token,url}` answer, so the page's `127.0.0.1` origin is never handed to the phone.
|
|
347
351
|
- **An unpaired connection has a three-method whitelist.** `hello`, `pair.begin` and `pair.finish`; every other method answers `unpaired` before dispatch, so no session, approval or roster surface is reachable without a device token.
|
|
348
352
|
- **Device tokens are stored as hashes only.** The roster keeps the public key and its SHA-256 fingerprint, never the token, so the file is not a credential store. A lost, rotated or rejected token means pairing again — a routine flow, not an exception path (a fresh bootstrap link, or a re-scan of the desktop pairing flow), and it never requires editing the roster by hand.
|
|
349
353
|
- **The token comparison does not leak length.** It is a fixed-length comparison rather than an early-exit one, so a wrong token cannot be narrowed byte by byte.
|
|
350
354
|
- **Approvals fail closed while a client is connected.** The bridge claims a tool's permission request only while at least one paired client is connected; with none, the request goes to the next answerer rather than stalling. A claimed request that nobody answers normalizes to `unavailable`, which the harness treats as a rejection: silence from the phone is never consent.
|
|
351
355
|
- **The header is the safer carrier.** `Authorization: Bearer <deviceToken>` keeps the credential out of the URL; `?token=` exists for clients that cannot set handshake headers, and the relay, the edge and the access log all see a URL that authenticates as that device.
|
|
356
|
+
- **Relay tier routing and grant credential boundaries.** The device roster (`devices.json`) schema upgrades from 3 to 4, adding an optional `relay: {grant, receivedAt}` to each device row. That `grant` is a 30-day HS256 credential signed by the account service, handed from the phone to the host over an **authenticated, paired connection**; the host merely passes it verbatim in the claim request body. The host therefore still does not know who the account is or what tier it holds: it only knows whether it holds a lease admitted by the relay. Tier evaluation occurs in a single loopback request between the self-hosted relay and the account service; the relay writes quotas into the lease row without recording any user identifier. The `hello.relay` announcement, capability identifier `relay.tier.v1`, and the `relay.grant` frame **exist only when a second meeting point is configured**; without configuration, the handshake is byte-for-byte identical to today, and that frame answers `unknown-method`. The two configuration keys are `relaySecondaryControlUrl` and `relaySecondaryPublicSuffix`, both unconfigured by default.
|
|
352
357
|
|
|
353
358
|
## Known limitations
|
|
354
359
|
|
package/README.zh.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<img src="https://img.shields.io/npm/v/@linxin666/dsh-remote-bridge?style=flat-square" alt="Version">
|
|
7
7
|
|
|
8
|
-
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.
|
|
8
|
+
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.1-4c6ef5?style=flat-square&labelColor=454a54" alt="DSH">
|
|
9
9
|
|
|
10
10
|
<img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
|
|
11
11
|
</p>
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
- **订阅而非轮询。** `session.snapshot` 打开宿主的 follow 流并保持它,基线与其后的每一条增量都走同一条 socket。
|
|
31
31
|
- **审批直达客户端,重连的手机还能拿回仍悬着的那些。** 需要授权的工具以 `approval.request` 事件到达,客户端用 `approval.resolve` 作答;无人应答的请求按拒绝处理,而声明了 `approvals.v1` 的连接会在握手之后再次收到所有未结算的审批。
|
|
32
32
|
- **配对。** 一次性 bootstrap token 加 P-256 挑战应答产出可吊销的设备令牌;未配对连接只能触达三个方法。
|
|
33
|
-
- **一个配对面板。** 同一插件行声明 `dsh.client` 浏览器半区:侧栏底部一个二维码图标(aria-label
|
|
33
|
+
- **一个配对面板。** 同一插件行声明 `dsh.client` 浏览器半区:侧栏底部一个二维码图标(aria-label 为「配对 iPhone」),点开弹窗展示 30 秒有效的一次性配对二维码与「重新取码」动作。
|
|
34
34
|
- **中继无需改动。** 协议搭在实例本来就发布的那个 origin 上,中继这一跳照原样转发它,与其他所有请求无异。
|
|
35
35
|
|
|
36
36
|
## 传输
|
|
@@ -178,9 +178,9 @@ fork 的方法同样什么都不解释。`session.fork` 把 `sessionId` 与客
|
|
|
178
178
|
|
|
179
179
|
### Bootstrap token
|
|
180
180
|
|
|
181
|
-
配对入口位于侧栏底部的二维码图标,按钮的 aria-label
|
|
181
|
+
配对入口位于侧栏底部的二维码图标,按钮的 aria-label 为「配对 iPhone」。点击后打开配对面板。该面板只在本机可用:令牌路由 `GET /remote-bridge/pair/token` 受回环门控保护,来源地址与 `Host` header 必须均为本机(非本机或经隧道访问一律返回 403)。
|
|
182
182
|
|
|
183
|
-
配对码一次性有效且具备 30 秒时效(`BOOTSTRAP_TOKEN_TTL_MS = 30_000`),被首次 `pair.begin`
|
|
183
|
+
配对码一次性有效且具备 30 秒时效(`BOOTSTRAP_TOKEN_TTL_MS = 30_000`),被首次 `pair.begin` 用掉即失效;在面板中点击「重新取码」会使上一张配对码作废并生成新码。面板中没有「停止」按钮,也没有「吊销所有已连接设备」的操作。本机链接会以 `pair a device with <ws 链接>` 打印到宿主日志,而这一行后面只跟手机侧地址的种类:宿主把这个 origin 叫作局域网地址、或者该字面量本身就只在当前网络内可达时是 `(phone: lan)`,其余情形是 `(phone: public)`,一个地址都没有时不带后缀。配对码本身则渲染在配对面板中供扫码。
|
|
184
184
|
|
|
185
185
|
```sh
|
|
186
186
|
curl -s http://127.0.0.1:3080/remote-bridge/pair/token
|
|
@@ -195,7 +195,7 @@ curl -s http://127.0.0.1:3080/remote-bridge/pair/token
|
|
|
195
195
|
"expiresAt": 1760000030000,
|
|
196
196
|
"url": "ws://127.0.0.1:3080/ios/v1?token=...",
|
|
197
197
|
"origin": "wss://<id>.dsh-market.com",
|
|
198
|
-
"originSource": "
|
|
198
|
+
"originSource": "realtime",
|
|
199
199
|
"pairingUrl": "wss://<id>.dsh-market.com/ios/v1?token=..."
|
|
200
200
|
}
|
|
201
201
|
```
|
|
@@ -237,7 +237,7 @@ curl -s http://127.0.0.1:3080/remote-bridge/pair/token
|
|
|
237
237
|
## 接入栈与安全模型
|
|
238
238
|
|
|
239
239
|
`@linxin666/dsh-remote-bridge` 拥有完整的公网与局域网接入栈:
|
|
240
|
-
- **中继身份与租约**:`relay-registry` 在 `$DSH_HOME/remote-web-ui-registry/<profile>.json` 下持久化中继身份(id 与 secret);改 relay
|
|
240
|
+
- **中继身份与租约**:`relay-registry` 在 `$DSH_HOME/remote-web-ui-registry/<profile>.json` 下持久化中继身份(id 与 secret);改 relay 配置会重挂载插件行。在未配置隧道(`tunnel.mode === 'off'`)且尚无已配对设备时,插件启动保持静默,不铸造身份也不申领租约;仅当名册读出已配对设备、本机打开配对面板取码、新设备完成配对或开启隧道时才按需触发申领(同时过滤 `idle`/`claiming`/`dialing` 过渡态日志并对连续相同的失败日志去重)。当以 `relay=false` 挂载且盘上存在身份时,挂载时撤销上一次留下的注册行并 `pair.release()` 释放租约各一次(失败各记一行;卸载时不释放也不撤行,保留手机收藏地址由服务端 GC 回收;`relay=false` 挂载绝不铸造新身份,盘上无身份时零副作用、不写盘)。
|
|
241
241
|
- **中继连接器**:`relay-connector` 并行维护快速隧道与命名隧道连接器;`relay-bridge-connector` 经 WSS 连接 Cloudflare Durable Object 会合点,并将连接状态记录在 `$DSH_HOME/remote-web-ui-relay-bridge.json`(状态文件写入经行为级验证,缺省落到 `$DSH_HOME`,非源码文本断言)。
|
|
242
242
|
- **隧道生命周期**:`tunnel`、`tunnel-plan` 与 `tunnel-orphan` 管理平台原生 `cloudflared` 子进程,具备指数退避重启机制并自动清理崩溃遗留的孤儿进程。
|
|
243
243
|
- **命名隧道端口同步**:`ingress-sync` 在宿主监听端口变化时,把 Cloudflare 命名隧道的 ingress 规则原子收敛到本机闸门端口。
|
|
@@ -246,7 +246,7 @@ curl -s http://127.0.0.1:3080/remote-bridge/pair/token
|
|
|
246
246
|
本包的安全模型对所有外部接入入口实施严格的白名单隔离:
|
|
247
247
|
- **入站网关(`src/host/ingress-gate.ts`)**:仅绑定 `127.0.0.1`,且仅将 `/ios/v1` 的 WebSocket 升级转发到本机协议端口,同时将 `Host` 头改写为回环权威。其余任何普通 HTTP 请求与非白名单升级一律直接返回 `404 {"error":"not-found"}` 并关闭连接,绝不建立上游连接。
|
|
248
248
|
- **隧道的目标是入站网关而非 webServer 端口**:cloudflared 快速隧道与命名隧道的目标均指向 `ingress-gate` 的动态回环端口,绝不直连 `webServer` 端口。外界经隧道传入的请求无法触达 webServer 路由、内部 API 或其他插件。
|
|
249
|
-
- **中继注册行与公网暴露面**:中继注册行只写入快速隧道的 URL,也就是入站闸门,公网因此只看得见 /ios/v1。计划为 quick 且隧道 running 时把闸门 URL 注册给中继 Worker
|
|
249
|
+
- **中继注册行与公网暴露面**:中继注册行只写入快速隧道的 URL,也就是入站闸门,公网因此只看得见 /ios/v1。计划为 quick 且隧道 running 时把闸门 URL 注册给中继 Worker(代理稳定子域名到本机,端点与后缀由配置决定、缺省为 `<id>.dsh-market.com`);卸载时只清本地引用不撤行。二维码公网地址由 `livePublicOriginOf` 裁定:bridge 或 named 租约优先稳定子域名;quick 租约在注册未成功时退回隧道 running URL;无租约用隧道 URL;皆无则无地址。其后退回 `DSH_REMOTE_PUBLIC_BASE_URL`,局域网兜底仅当局域网转发器真的在监听时才按实际绑定的 address 与 port 给出(不猜地址列表首项,转发器停止即无兜底;已彻底移除磁盘 registry 行作为兜底地址,消除了对老插件数据文件的最后一处依赖)。
|
|
250
250
|
- **局域网转发器的目标同样是入站网关**:局域网转发器监听本机局域网 IPv4 地址,并将请求严格转发至 `ingress-gate` 端口,因此局域网入口的暴露面同样仅有 `/ios/v1`。
|
|
251
251
|
- **中继桥会合点白名单**:`relay-bridge-connector.ts` 对 Durable Object 汇聚的入站流执行完全相同的白名单检查,非 `/ios/v1` 的 HTTP 流直接应答 `404 {"error":"not-found"}`,非白名单 WebSocket 升级直接回复 `ws-fail 404 {"error":"not-found"}`,两条路都不建立上游连接。
|
|
252
252
|
- **身份目录沿用历史拼写与并存禁忌**:中继身份目录 `$DSH_HOME/remote-web-ui-registry/` 与状态文件 `remote-web-ui-relay-bridge.json` 有意沿用历史拼写,确保既有 profile 保持身份连续性,已配对设备升级后无需重新配对。**已知风险与并存禁忌**:同一 profile 切勿同时启用本插件与已弃用的 `dsh-remote-web-ui` 的中继——两者按 profile 共用同一份身份文件;若新桥以 `relay=false` 挂载,会撤销该身份下的注册行并释放租约,从而打断老插件正在使用的公网中继;若两侧 relay 同时开启,bridge 传输下两个连接器会拿同一凭据竞争同一个 Durable Object 连接互相顶掉,quick 传输下后注册者覆盖前者。该收尾行为是有意设计的。
|
|
@@ -258,7 +258,9 @@ curl -s http://127.0.0.1:3080/remote-bridge/pair/token
|
|
|
258
258
|
|
|
259
259
|
| 配置项 | 类型 | 默认值 | 说明 |
|
|
260
260
|
| --- | --- | --- | --- |
|
|
261
|
-
| `relay` | boolean | `true` | 是否申领 relay
|
|
261
|
+
| `relay` | boolean | `true` | 是否申领 relay 租约。默认开启;无隧道时在已有配对设备或发起配对时按需 claim 租约。 |
|
|
262
|
+
| `relayControlUrl` | string | `'https://dsh-market.com/api/relay'` | 中继控制面基址,claim/release/register/unregister 都从它派生。 |
|
|
263
|
+
| `relayPublicSuffix` | string | `'.dsh-market.com'` | 稳定主机名后缀。 |
|
|
262
264
|
| `autoTunnel` | boolean | `false` | 是否启动指向入站网关的 Cloudflare 快速隧道。 |
|
|
263
265
|
| `lanBind` | boolean | `undefined`(关) | 是否启动监听本机局域网 IPv4 地址的局域网转发器。 |
|
|
264
266
|
| `tunnelToken` | string | `undefined` | 运行 Cloudflare 命名隧道所需的隧道令牌。 |
|
|
@@ -275,11 +277,13 @@ curl -s http://127.0.0.1:3080/remote-bridge/pair/token
|
|
|
275
277
|
|
|
276
278
|
面板只做一件事——把活着的那个一次性配对码摆到操作者面前,且只有这一个阅读顺序:
|
|
277
279
|
|
|
278
|
-
-
|
|
280
|
+
- **卡头与副标题说明目标。** 标题为「iOS App 配对」,副标题「用 iOS App(内测)扫描二维码,把 iPhone 连到这台电脑上。配对码只在本机显示。」,说明操作对象与安全边界。
|
|
281
|
+
- **二维码本身就是那个码。** 它要么装 43 个 base64url 字符的裸 token,要么在宿主说得出自己公网地址时装 `{token,url}` 文档,扫一次就把 iPhone 配好。若放一个宿主没背书过的 URL,App 端的解析器会顺手把 origin 改写成这台机器的 loopback 地址,而那恰恰是 iPhone 够不到的地址。编码串只在二维码部件的 `data-dsh-qr-value` 属性里留一份镜像,供 UI 检查不必解码就比对;它从不以文字形式渲染。
|
|
279
282
|
- **二维码下方只有一条状态行。** 活着的码在进度条旁倒数那 30 秒;过期的码在同一个固定高度里直说过期,变的只有那句话。
|
|
280
|
-
- **一条地址说明。**
|
|
281
|
-
- **一条一次性说明。**
|
|
283
|
+
- **一条地址说明。** 定位到的公网地址只交代种类,不写成文字:「二维码已包含公网地址,扫码后 iPhone 自动连上这台电脑」。一次性配对码 30 秒即焚,而持久公网主机名一旦以文字渲染,会比它出现的每张截图活得久;二维码本身已带手机需要的地址,「复制配对码」交出的仍是同一个 `{token,url}` 串。局域网字面量不属于这一类事实:当宿主把这个 origin 叫作局域网地址,或者该字面量本身就只在当前网络内可达时,这一行都点名它——「二维码指向局域网地址 {origin},iPhone 需与本机在同一网络」。定位不到地址时,它直说「没有找到公网地址:先在 App 里把连接地址填成你的公网中继,再扫码。本页的 {host} 只有本机能连。」。
|
|
284
|
+
- **一条一次性说明。** 配对码一次性有效:iPhone 一开始配对就作废,重新取码也会作废上一张。
|
|
282
285
|
- **一行动作。** 复制把二维码里那个字符串原样放进剪贴板,「重新取码」签发新 token 并作废上一张;两者都是同一个库控件、同一个尺寸,交互态不会各走一套。码一旦过期,回到可扫状态的唯一路径就是重新取码:复制被禁用,二维码原地降级变暗,而不是缩小或被移除。
|
|
286
|
+
- **一行内测入口。** 提供「[iOS App 还在内测,欢迎来 Discord 交流](https://discord.gg/nBy28kjun)」,整行可点击打开。
|
|
283
287
|
- **失败不静默。** 取码走的就是操作者本可以用 curl 打的那条仅 loopback 路由:`403` 渲染成「这个页面不是从本机打开的」且不给出可点的动作;请求没到达则渲染成它自己的不可达状态并给出重试;宿主回了别的状态就把那个状态码说出来。
|
|
284
288
|
|
|
285
289
|
开与关是同一段动效的两条腿:卡片保持挂载,把弹窗自己的进场淡入反向播完才卸载;reduced-motion 下这条生命周期换成一段短淡出,而不是干脆没有出场。几何在每种状态里都钉住——二维码的盒子、状态行、地址说明与复制标签都不改高度和宽度——所以倒计时、过期与复制确认都不会挪动它们旁边的元素。
|
|
@@ -339,13 +343,14 @@ dsh plugin --profile web add link:$(pwd)/packages/dsh-remote-bridge
|
|
|
339
343
|
|
|
340
344
|
- **配对即完全控制凭据。** 已配对设备在同一进程内触达宿主:会话、发言、审批。只配对你掌控的设备,吊销方式是移除名册那一行并重启宿主。
|
|
341
345
|
- **进程内调用以 owner 身份发言,且只在桥自己的门禁之后。** 自 DSH 0.2.1 起,宿主网关要求每次调用都指明代表谁发言,桥的回答是自己在挂载时铸造的一个进程内 owner peer(`{kind:'owner'}`),挂到每一次网关调用上。这个声明之所以安全,是因为它只在桥自己的配对检查之后才会被用到——未配对连接在任何网关调用存在之前即被拒——且协议帧的任何字段都不能设定 principal:客户端在载荷里自报的身份会被忽略。该 peer 不接收转发事件交互,因此它也永远收不到宿主转发事件。
|
|
342
|
-
- **token 端点仅 loopback 可达,且看两个条件。** 来源地址必须是 loopback,且 `Host` header 必须写本机。经隧道的请求由本机的隧道客户端终结,所以对一条全互联网可达的请求,来源地址也读作 `127.0.0.1`;而中继与普通隧道都会把 `Host` 改写成公网名。任一条件不成立即 403。token 只存内存、30 秒过期、被一次 `pair.begin`
|
|
346
|
+
- **token 端点仅 loopback 可达,且看两个条件。** 来源地址必须是 loopback,且 `Host` header 必须写本机。经隧道的请求由本机的隧道客户端终结,所以对一条全互联网可达的请求,来源地址也读作 `127.0.0.1`;而中继与普通隧道都会把 `Host` 改写成公网名。任一条件不成立即 403。token 只存内存、30 秒过期、被一次 `pair.begin` 用掉即焚,本机链接还会写进宿主日志——把那一行日志当作活着的密钥。那一行里手机侧只有地址种类(`(phone: public)` 或 `(phone: lan)`,没有地址时不带后缀):这一行配对日志正是操作者会粘贴到别处的那一行,公网主机名或局域网字面量写在里面,就会比它对应的配对码活得更久。
|
|
343
347
|
- **配对面板渲染的是一份活密钥,也仅止于此。** 它用同源请求读同一条仅 loopback 门禁的路由,所以在 `curl` 够得到的地方它才够得到,别处都不行。它不能签发设备令牌、不能消耗配对码、不能列名册、不能吊销设备:`pair.begin` 始终是手机那一侧的动作,吊销始终是改名册加重启宿主。二维码里装的是裸 token 或宿主自己那份 `{token,url}` 应答,因此本页的 `127.0.0.1` origin 永远不会被交给手机。
|
|
344
348
|
- **未配对连接只有三个方法的白名单。** `hello`、`pair.begin`、`pair.finish`;其余方法在分发前即回 `unpaired`,因此没有设备令牌就够不到会话面、审批面与名册面。
|
|
345
349
|
- **设备令牌只存哈希。** 名册保留公钥及其 SHA-256 指纹,从不存令牌本身,所以该文件不是凭据库。令牌丢失、轮换或被拒的处置就是重新配对——这是常规流程而非异常路径(重新签发一条 bootstrap 链接,或在桌面配对流程里重扫),且从不需要手工改名册。
|
|
346
350
|
- **令牌比对不泄漏长度。** 用的是定长比较而非提前返回的比较,因此错误令牌无法被逐字节逼近。
|
|
347
351
|
- **审批在客户端在线时 fail closed。** 只要还有一个已配对客户端在线,桥才认领工具的权限请求;一个都没有时,请求交给下一个应答者而不是卡住。已认领而无人应答的审批会被归一为 `unavailable`,宿主按拒绝处理:手机沉默永远不等于同意。
|
|
348
352
|
- **header 是更安全的载体。** `Authorization: Bearer <deviceToken>` 让凭据不进入 URL;`?token=` 是给无法设置握手 header 的客户端的,此时中继、边缘与访问日志都会看到一条以该设备身份鉴权的 URL。
|
|
353
|
+
- **中继档位分流与授权凭据边界。** 名册(`devices.json`)schema 3 → 4,每台设备行新增可选的 `relay: {grant, receivedAt}`。那枚 `grant` 是账号服务签发的 30 天 HS256 凭据,经**已配对的加密连接**由手机交给宿主,宿主只把它原样放进 claim 请求体。宿主因此仍然不知道账号是谁、也不知道档位:它只知道「我有没有一份被中继承认的租约」。档位判定发生在自建中继与账号服务之间的一次回环请求里,中继只把额度写进租约行,不落任何用户标识。`hello.relay`、能力名 `relay.tier.v1`、`relay.grant` 这一帧**只在配置了第二个会合点时才存在**;不配置时握手逐字节等于今天,那一帧回 `unknown-method`。两个配置项名:`relaySecondaryControlUrl` 与 `relaySecondaryPublicSuffix`,缺省都不配置。
|
|
349
354
|
|
|
350
355
|
## 已知限制
|
|
351
356
|
|