dsh-lan-share 0.2.0: LAN/relay sharing with QR pairing
This commit is contained in:
16 files changed
+5940
No files matched your search
@@ -0,0 +1,244 @@
|
||||
# @local/dsh-lan-share
|
||||
|
||||
Share the DSH Desktop Web GUI over the local network or through a public relay so a tablet can drive the
|
||||
same Session: send messages, answer approvals, use the terminal, and read or
|
||||
edit workspace files. Pairing is a one-time QR code; paired devices are
|
||||
revocable and survive a Desktop restart.
|
||||
|
||||
The plugin does not modify DSH core. It adds one LAN listener inside the
|
||||
Desktop Host process and proxies it to the Host's loopback Web server, keeping
|
||||
the Host's own browser cookie out of the tablet.
|
||||
|
||||
Repository: `ssh://git@git.realmanual.ru:2022/pub/dsh-lan-share.git`
|
||||
(web page: `https://git.realmanual.ru/pub/dsh-lan-share`).
|
||||
|
||||
## Requirements
|
||||
|
||||
- DSH Desktop 0.2.2-rc.1 (the tested release) or a compatible build.
|
||||
- The tablet and the computer on the same network (no client isolation).
|
||||
- macOS may ask for incoming-connection permission the first time the listener
|
||||
starts. Allow the DSH application.
|
||||
|
||||
## Install into the Desktop profile
|
||||
|
||||
Clone the repository next to the other shared local plugins; the profile links
|
||||
to that folder, so an app update does not delete it:
|
||||
|
||||
git clone ssh://git@git.realmanual.ru:2022/pub/dsh-lan-share.git \
|
||||
"$DSH_HOME/plugins/lan-share"
|
||||
cd "$DSH_HOME/profiles/desktop"
|
||||
pnpm add "link:$DSH_HOME/plugins/lan-share"
|
||||
|
||||
Then add the package to dsh.profile.bundles in
|
||||
$DSH_HOME/profiles/desktop/package.json:
|
||||
|
||||
"dsh": {
|
||||
"profile": {
|
||||
"bundles": [
|
||||
"@deepseek-ai/dsh-base",
|
||||
"@deepseek-ai/dsh-web-app",
|
||||
"@local/dsh-lan-share"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Restart DSH Desktop. The client half is served by the normal plugin graph; a
|
||||
running process is not hot-patched by this installation.
|
||||
|
||||
If pnpm refuses with ERR_PNPM_UNEXPECTED_STORE (a profile installed from a
|
||||
different global store), create the link by hand; it is equivalent for the
|
||||
Loader:
|
||||
|
||||
ln -sfn "$DSH_HOME/plugins/lan-share" \
|
||||
"$DSH_HOME/profiles/desktop/node_modules/@local/dsh-lan-share"
|
||||
|
||||
Then add the dependency and bundle entry to package.json as shown above. This
|
||||
is how the copy on this machine was installed because its profile was created
|
||||
with a different pnpm store.
|
||||
|
||||
## Use
|
||||
|
||||
- In a Session header press **Share** (Поделиться).
|
||||
- The dialog opens with a **"Нажмите, чтобы показать QR-код"** placeholder.
|
||||
Tap it to create and show a one-time QR; its timer is 60 seconds. The code is
|
||||
refreshed in the background while the dialog stays open; the next tap shows
|
||||
the waiting code (or a fresh one when it has aged).
|
||||
- Scan the QR with a tablet camera on the same Wi-Fi. The scan does **not**
|
||||
create the device immediately: the host shows a confirmation card with the
|
||||
device label, IP and User-Agent. The tablet waits on a loading page. Press
|
||||
**Подтвердить** to create the device and release the tablet; **Отклонить**
|
||||
returns a denial page. The pending request expires after 2 minutes.
|
||||
- The **Settings → LAN access** page shows the listening address, paired
|
||||
devices, and the same tap-to-show QR. On a paired tablet it shows the
|
||||
pairing and a "Disconnect this tablet" action instead.
|
||||
- The URL row has an icon-only copy button; "New code" is not needed because
|
||||
the hidden code is refreshed each minute.
|
||||
|
||||
Each QR code is single-use and expires after 60 seconds. A paired device gets
|
||||
a revocable cookie; it is not asked for a QR again until it is disconnected or
|
||||
its lifetime (7 days by default) ends. The desktop confirmation is the second
|
||||
factor: scanning alone creates only a pending request.
|
||||
|
||||
## Internet relay
|
||||
|
||||
The same host can publish itself through the separate dsh-relay container
|
||||
(see https://git.realmanual.ru/bildme/dsh-relay). The Desktop dials the relay
|
||||
over WSS, so its dynamic address and NAT do not matter. The relay only carries
|
||||
bytes to the LAN listener; pairing, device cookies, and approvals stay here.
|
||||
|
||||
Configure the plugin in $DSH_HOME/profiles/desktop/cordis.patch.yml:
|
||||
|
||||
- id: lan-share
|
||||
name: '@local/dsh-lan-share'
|
||||
config:
|
||||
relay:
|
||||
enabled: true
|
||||
url: wss://dsh.bildme.ru/tunnel
|
||||
token: <AGENT_TOKEN from the relay .env>
|
||||
publicOrigin: https://dsh.bildme.ru
|
||||
|
||||
- publicOrigin is optional: the plugin uses the relay hello when it is absent.
|
||||
- The token is sent in the WebSocket subprotocol, not in a URL. Keep the
|
||||
profile file owner-only.
|
||||
- relay.token must match the relay's AGENT_TOKEN character for character. A
|
||||
mismatch rejects the WSS handshake and surfaces as websocket-error; check the
|
||||
relay log for tunnel authentication failed.
|
||||
- Environment overrides: DSH_RELAY_ENABLED, DSH_RELAY_URL, DSH_RELAY_TOKEN,
|
||||
DSH_RELAY_PUBLIC_ORIGIN, DSH_RELAY_AGENT_ID.
|
||||
- If the relay is enabled but offline, ticket creation returns relay-offline
|
||||
and the Share dialog shows it. Set relay.fallbackToLan: true to fall back to
|
||||
a LAN QR instead.
|
||||
- A QR minted while the relay is connected contains
|
||||
https://dsh.bildme.ru/s/<ticket>. The tablet opens it over the internet; the
|
||||
relay routes it to the one connected Desktop (or by ticket/cookie when
|
||||
several are connected).
|
||||
- Restart DSH Desktop after changing the relay config.
|
||||
|
||||
## Configuration table (relay fields)
|
||||
|
||||
| Field | Default | Meaning |
|
||||
|---|---|---|
|
||||
| relay.enabled | false | Dial the relay. |
|
||||
| relay.url | null | wss://.../tunnel. |
|
||||
| relay.token | null | Shared AGENT_TOKEN. |
|
||||
| relay.publicOrigin | null | Public HTTPS origin used for QR codes. |
|
||||
| relay.agentId | null | Optional log identity. |
|
||||
| relay.fallbackToLan | false | Mint a LAN QR when the relay is offline. |
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
Defaults are compiled in. Override them in
|
||||
$DSH_HOME/profiles/desktop/cordis.patch.yml by targeting the inserted row:
|
||||
|
||||
- id: lan-share
|
||||
name: '@local/dsh-lan-share'
|
||||
config:
|
||||
host: 192.168.1.20
|
||||
port: 47820
|
||||
ticketTtlSeconds: 60
|
||||
deviceTtlDays: 7
|
||||
maxDevices: 16
|
||||
tls:
|
||||
certFile: /path/to/cert.pem
|
||||
keyFile: /path/to/key.pem
|
||||
|
||||
| Field | Default | Meaning |
|
||||
|---|---|---|
|
||||
| enabled | true | Start the listener. |
|
||||
| host | auto | LAN IP literal to bind, or 0.0.0.0 with publicHost. Auto prefers RFC 1918 (192.168/10/172.16) and ignores Tailscale/CGNAT 100.64/10 default routes. |
|
||||
| publicHost | host | Address written into QR codes; a DNS name is allowed. |
|
||||
| port | 47820 | LAN port. If busy, one fallback to an OS-assigned port is reported in the UI. |
|
||||
| ticketTtlSeconds | 60 | One-time QR lifetime. |
|
||||
| deviceTtlDays | 7 | How long a paired device stays valid. |
|
||||
| maxDevices | 16 | Rejects new pairings beyond this count. |
|
||||
| stateFile | $DSH_HOME/lan-share/devices.json | Device registry; mode 0600. |
|
||||
| tls | null | Optional certificate and key for the LAN listener. |
|
||||
|
||||
## Security model
|
||||
|
||||
- The Host Web server stays loopback-only. The LAN listener is a separate
|
||||
authenticated reverse proxy.
|
||||
- The tablet never receives the Host's browser cookie. The proxy mints that
|
||||
cookie internally through the Host launch URL, keeps it warm, and re-mints it
|
||||
when the port changes or the Host answers 401.
|
||||
- A tablet authenticates with its own dsh-lan-device cookie. Only a SHA-256
|
||||
digest of its secret is written to stateFile; the cookie itself is HttpOnly,
|
||||
SameSite=Lax, and host-only.
|
||||
- A one-time ticket is 32 random bytes, stored only as a digest, valid for one
|
||||
GET, and consumed atomically.
|
||||
- Paired devices have full owner authority over this DSH instance. Pair only
|
||||
people and devices you trust, and disconnect devices you stop using.
|
||||
- Plain HTTP over a local network exposes the device cookie to anyone who can
|
||||
observe the network. Configure tls with a certificate the tablet trusts when
|
||||
that matters.
|
||||
- Management routes (/api/lan-share/ticket, /revoke, /state) exist only on the
|
||||
Host's loopback server. The LAN listener refuses them with 403.
|
||||
|
||||
## How it works
|
||||
|
||||
Tablet ──HTTP/WS──▶ LAN listener :47820 ──▶ 127.0.0.1:<host port>
|
||||
│ device cookie + header rewrite
|
||||
└─ minted Host browser cookie
|
||||
|
||||
The proxy rewrites requests the same way the Electron shell's dsh-app://app
|
||||
forwarding does: Host names the upstream authority, Origin is removed for HTTP
|
||||
and set to the upstream origin for WebSocket upgrades, and the minted cookie is
|
||||
attached. Streaming responses, SSE, range requests, and upgrades are passed
|
||||
through without buffering.
|
||||
|
||||
## Files
|
||||
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| index.js | Cordis wiring and the loopback-only control API. |
|
||||
| config.js | Config validation, LAN address detection, authority helpers. |
|
||||
| store.js | Device registry (durable, digest-only) and one-time tickets. |
|
||||
| proxy.js | LAN listener, authentication, HTTP/WebSocket proxy. |
|
||||
| qr.js | Byte-mode QR encoder (ECC M, versions 1–10). |
|
||||
| client.js | Share dialog, Settings page, paired-tablet Session sync. |
|
||||
|
||||
## Tests
|
||||
|
||||
cd "$DSH_HOME/plugins/lan-share"
|
||||
node --test test/
|
||||
|
||||
The suite covers the QR encoder (including a spec-derived decoder and
|
||||
Reed-Solomon checks), device/ticket lifetimes, header rewriting, one-time
|
||||
pairing, cookies, streaming, redirects, WebSocket upgrades, revocation, and
|
||||
the 401 re-mint path against a fake Host.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- Not listening / no LAN address: auto now prefers a real RFC 1918 LAN address. On a VPN-only machine
|
||||
automatic discovery may pick the wrong interface.
|
||||
- Port busy: the UI reports the fallback port. Fix port or stop the other
|
||||
process.
|
||||
- Tablet cannot connect: check that both devices are on the same network, the
|
||||
router does not isolate clients, and the macOS firewall allows DSH.
|
||||
- Code expired or already used: create a new code; a QR is one-time.
|
||||
- Tablet shows "Pairing required" after a restart: its device lifetime ended
|
||||
or it was disconnected. Pair again.
|
||||
- A native folder picker opened on the computer: the desktop composition uses
|
||||
the OS picker, which runs on the Host. This is a known limitation of remote
|
||||
use; prefer existing Workspaces.
|
||||
|
||||
## Known limitations
|
||||
|
||||
- This is Session sharing, not screen mirroring: the tablet sees the same Web
|
||||
GUI and Session, not pixels of the desktop window.
|
||||
- A paired device has owner authority; there is no read-only viewer tier.
|
||||
- The native directory picker and "open in app" actions execute on the Host.
|
||||
- Multiple Desktop instances are not supported; the second one falls back to an
|
||||
OS-assigned LAN port, and the device registry is last-writer-wins.
|
||||
- The LAN address is part of the device cookie scope; changing networks (and
|
||||
therefore the address) requires pairing again.
|
||||
- No mDNS name, certificate provisioning, or PWA install flow.
|
||||
|
||||
## Uninstall
|
||||
|
||||
cd "$DSH_HOME/profiles/desktop"
|
||||
pnpm remove @local/dsh-lan-share
|
||||
|
||||
Remove @local/dsh-lan-share from dsh.profile.bundles, restart DSH, then delete
|
||||
$DSH_HOME/lan-share/ if the device registry is no longer needed.
|
||||
Reference in new issue
Block a user