oc-phone-link 2.3.3 → 2.4.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/CHANGELOG.md +38 -1
- package/README.md +14 -13
- package/beacon.mjs +86 -44
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,44 @@ release digests, not the server version.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
-
## [2.
|
|
9
|
+
## [2.4.0] - 2026-11-29
|
|
10
|
+
|
|
11
|
+
Ships with the 2.4.0 app. The app and beacon must be upgraded together.
|
|
12
|
+
|
|
13
|
+
- The shared code is exactly four digits: `pinPattern` is `^\d{4}$` in
|
|
14
|
+
`beacon.mjs` and is used by `setPin`, `/setup` and `/auth`. The panel
|
|
15
|
+
input and its client-side check were updated to match. PBKDF2-SHA256 at
|
|
16
|
+
600,000 iterations and the 16-byte salt are unchanged.
|
|
17
|
+
- Wrong-code rate limiting: `AUTH_FAIL_MAX = 5` wrong PINs per source in
|
|
18
|
+
`AUTH_WINDOW_MS = 5 * 60 * 1000`, then `AUTH_LOCKOUT_MS = 15 * 60 * 1000`
|
|
19
|
+
of lockout, logged once per episode. Only a wrong PIN counts; the old
|
|
20
|
+
double-counting guess path is gone.
|
|
21
|
+
- `GET /info?pair=1` returns LAN `urls` and `agentUrls`, `httpsPort`,
|
|
22
|
+
`proxyPort`, the existing `hosts`/`fingerprint` and `pinRequired`,
|
|
23
|
+
with no code, key, owner or password. Plain `/info` keeps its device-key
|
|
24
|
+
gate, so no auth was weakened beyond the code format.
|
|
25
|
+
- Device keys idle-expire after 180 days (`KEY_TTL`) with a matching 180-day
|
|
26
|
+
cookie `Max-Age`; rotation-on-use, per-device revoke and revoke-all stay as
|
|
27
|
+
they were. `STATE_VERSION` stays 5, so existing keys and the owner token
|
|
28
|
+
survive the upgrade.
|
|
29
|
+
- Discovery self-reports: a `discovery addresses` line at startup and one
|
|
30
|
+
`discovery request <ip> answer on <addresses>` line per PROBE; a source
|
|
31
|
+
outside those addresses is logged once per source as `discovery unexpected
|
|
32
|
+
source`. Diagnostics only; UDP replies are unchanged.
|
|
33
|
+
- Wire changes for a 2.2.0 app: an eight-digit code now gets `pin-invalid`,
|
|
34
|
+
and pre-pair discovery must use `/info?pair=1`. The added `/info` fields
|
|
35
|
+
are ignored by older callers. Key format, headers, ports, `/health`,
|
|
36
|
+
`/auth`, `/setup`, `/request`, `/revoke` and the proxy contract are
|
|
37
|
+
unchanged.
|
|
38
|
+
- `beacon.test.mjs` adds twelve cases: four-digit accept/reject (3, 5, 8),
|
|
39
|
+
rate limit and lockout expiry, the 180-day idle boundary, rotation and
|
|
40
|
+
revoke-fails-closed, both `/info` shapes and the once-per-source discovery
|
|
41
|
+
log.
|
|
42
|
+
|
|
43
|
+
Proof: `node --test beacon.test.mjs` EXIT 0 — 37 tests, 37 pass, 0 fail
|
|
44
|
+
(baseline 25/25). `bun run check` was already EXIT 1 at baseline on the
|
|
45
|
+
unrelated `packages/janua` MCP conformance timeout; the `oc-phone-link`
|
|
46
|
+
workspace portion passes 37/37.
|
|
10
47
|
|
|
11
48
|
## 2.0.11
|
|
12
49
|
|
package/README.md
CHANGED
|
@@ -18,16 +18,16 @@ Use the published [PC plugin 2.3.0](https://www.npmjs.com/package/oc-phone-link/
|
|
|
18
18
|
|
|
19
19
|
The PC plugin and Android app use separate version numbers. The plugin starts the beacon during setup and stops it when the session disposes. There is no tray app, no separate service and no QR code: the beacon is a keyed reverse proxy in front of the OpenCode server your PC already runs.
|
|
20
20
|
|
|
21
|
-
## First use
|
|
21
|
+
## First use — one entry, then automatic
|
|
22
22
|
|
|
23
|
-
1. Connect the PC and Android phone to the same Wi-Fi.
|
|
24
|
-
2. Install the
|
|
25
|
-
3. Open `https://localhost:41338` on the PC. That page is the beacon's own control panel. Set
|
|
26
|
-
4. Open the phone app
|
|
27
|
-
5.
|
|
28
|
-
6.
|
|
23
|
+
1. Connect the PC and Android phone to the same Wi-Fi (or use the tunnel transport).
|
|
24
|
+
2. Install the Android app that ships with this beacon. From 2.4.0 the app and beacon share the four-digit flow; a 2.2.0 app still expects eight digits and cannot pair with this build.
|
|
25
|
+
3. Open `https://localhost:41338` on the PC. That page is the beacon's own control panel. Set a **four-digit** PIN there.
|
|
26
|
+
4. Open the phone app and enter the beacon address once. Before pairing it calls `GET /info?pair=1`, which returns the beacon's LAN URLs, the HTTPS port and `pinRequired` (`true` when no code has been set yet) so no UDP discovery is needed. The code itself is never returned over HTTP. A plain `GET /info` still requires a device key or the owner cookie.
|
|
27
|
+
5. The app shows a short TLS fingerprint. Compare it with the Verify line on the PC page. Enter the four digits **once** after the fingerprints match: the app POSTs them to `/setup` for the first code, or to `/auth` for a later device. A successful call mints a device key.
|
|
28
|
+
6. Every later launch reuses that device key and asks for nothing. The key idle-expires after 180 days and rotates after 45; each use refreshes the idle clock, so weekly use never re-pairs. At most 16 keys are held.
|
|
29
29
|
|
|
30
|
-
The PC page also lists paired devices with issue date, last use and last IP, and can revoke one device, revoke all of them, or reset the PIN.
|
|
30
|
+
The PC page also lists paired devices with issue date, last use and last IP, and can revoke one device, revoke all of them, or reset the PIN. A revoked key fails closed on its next request.
|
|
31
31
|
|
|
32
32
|
Once paired, the phone sends its requests to the beacon on port 41340, which checks the device key and forwards to OpenCode on its own port (28894 by default). The beacon also keeps a loopback port on 41339 for the PC itself and an exposed port on 41341 for setup actions, which it refuses when the request did not come from the local machine.
|
|
33
33
|
|
|
@@ -35,9 +35,9 @@ The phone drives the same server session the PC does. Nothing is uploaded anywhe
|
|
|
35
35
|
|
|
36
36
|
## Troubleshooting
|
|
37
37
|
|
|
38
|
-
- **The phone cannot find the beacon.** Confirm both devices are on the same Wi-Fi and that UDP port 41337 can reach the PC. `OC_PHONE_LINK_NO_UDP=1` disables discovery for pair-by-address setups.
|
|
38
|
+
- **The phone cannot find the beacon.** Confirm both devices are on the same Wi-Fi and that UDP port 41337 can reach the PC. `OC_PHONE_LINK_NO_UDP=1` disables discovery for pair-by-address setups; enter the beacon address and use `GET /info?pair=1` instead. The log writes a `discovery addresses` line at startup and a `discovery request ... answer on` line for each probe, naming the addresses the beacon answers on; a probe from any other source is logged once per source as `discovery unexpected source`. Check `agent.log` before assuming the Wi-Fi is at fault.
|
|
39
39
|
- **The TLS fingerprints differ.** Do not enter the PIN. Confirm the phone is showing this PC's beacon and compare its short fingerprint with the Verify line on the PC page before trying again.
|
|
40
|
-
- **The Android app cannot pair.** The old Android 1.4.1
|
|
40
|
+
- **The Android app cannot pair.** The old Android 1.4.1 and 2.2.0 apps expect eight digits and cannot pair with this beacon. Install the 2.4.0 app that ships with it.
|
|
41
41
|
- **The control panel does not open.** Confirm the plugin loaded after the OpenCode restart. If a port is taken, set `OC_PHONE_LINK_PORT_BASE` to shift the fixed port block.
|
|
42
42
|
|
|
43
43
|
## Development
|
|
@@ -51,10 +51,11 @@ The test file covers PIN derivation, key revoke and rotation, discovery and the
|
|
|
51
51
|
|
|
52
52
|
## Security
|
|
53
53
|
|
|
54
|
-
- **PIN**: exactly
|
|
54
|
+
- **PIN**: exactly four digits (`^\d{4}$` in the panel, `/setup` and `/auth`), stretched with the same PBKDF2-SHA256 at 600,000 iterations and stored salted and hashed. Only the owner's own networks may claim the first PIN.
|
|
55
55
|
- **TLS**: a self-signed certificate is generated on first start and pinned by the phone on first use. The PC page prints the full fingerprint and a short form for comparison.
|
|
56
|
-
- **Keys**: per-device, tagged with the device that minted them. A targeted revoke fails closed and drops only that device's keys; revoke all drops every key.
|
|
57
|
-
- **Lockout**: five
|
|
56
|
+
- **Keys**: per-device, tagged with the device that minted them. A key idle-expires after 180 days (`KEY_TTL`) and rotates after 45 days of age on use; presenting it refreshes the idle clock, so wall-clock age alone never expires a key in use. The cookie carries a matching 180-day `Max-Age`. A targeted revoke fails closed and drops only that device's keys; revoke all drops every key.
|
|
57
|
+
- **Lockout**: at most five wrong PINs from one source IP in five minutes; the fifth arms a 15-minute lockout that is logged once. Constants in `beacon.mjs`: `AUTH_FAIL_MAX = 5`, `AUTH_WINDOW_MS = 5 * 60 * 1000`, `AUTH_LOCKOUT_MS = 15 * 60 * 1000`.
|
|
58
|
+
- **Pre-pair info**: `GET /info?pair=1` exposes only endpoint discovery (LAN URLs, HTTPS port, `pinRequired`); no code, key, owner token or password. Plain `/info` stays gated.
|
|
58
59
|
- **Limits**: ten requests per minute per address, request bodies capped at 4 KB, upstream calls time out after five seconds.
|
|
59
60
|
- **Local only**: no telemetry, no cloud relay, no analytics.
|
|
60
61
|
|
package/beacon.mjs
CHANGED
|
@@ -35,9 +35,9 @@ const REQ_WINDOW_MS = 60 * 1000;
|
|
|
35
35
|
const REQ_MAX = 10;
|
|
36
36
|
const BODY_CAP = 4096;
|
|
37
37
|
const LOG_MAX = 5 * 1024 * 1024;
|
|
38
|
-
const KEY_TTL =
|
|
38
|
+
const KEY_TTL = 180 * 24 * 60 * 60 * 1000; // idle expiry; weekly use never re-pairs
|
|
39
39
|
const KEY_ROTATE_AFTER = 45 * 24 * 60 * 60 * 1000;
|
|
40
|
-
const KEY_COOKIE_MAX_AGE =
|
|
40
|
+
const KEY_COOKIE_MAX_AGE = 180 * 24 * 60 * 60; // matches KEY_TTL
|
|
41
41
|
const KEY_PERSIST_MS = 60 * 1000;
|
|
42
42
|
const KEY_CAP = 16;
|
|
43
43
|
const UPSTREAM_TIMEOUT_MS = 5000;
|
|
@@ -48,11 +48,26 @@ const PASSWORD_NEG_TTL = 30000;
|
|
|
48
48
|
const reqHits = new Map(); // ip -> [ts...] sliding window
|
|
49
49
|
let now = () => Date.now();
|
|
50
50
|
|
|
51
|
-
const AUTH_FAIL_MAX = 5;
|
|
52
|
-
const AUTH_WINDOW_MS =
|
|
51
|
+
const AUTH_FAIL_MAX = 5; // wrong PINs per source before a lockout
|
|
52
|
+
const AUTH_WINDOW_MS = 5 * 60 * 1000; // window those wrong PINs are counted in
|
|
53
|
+
const AUTH_LOCKOUT_MS = 15 * 60 * 1000; // lockout after the fifth wrong PIN
|
|
53
54
|
const AUTH_MAP_MAX = 1024;
|
|
54
55
|
const authFails = new Map(); // ip -> { count, first, until }
|
|
55
56
|
|
|
57
|
+
function capAuthFails(t) {
|
|
58
|
+
if (authFails.size <= AUTH_MAP_MAX) return;
|
|
59
|
+
for (const [key, val] of authFails) if (t - val.first >= AUTH_WINDOW_MS && !val.until) authFails.delete(key);
|
|
60
|
+
if (authFails.size > AUTH_MAP_MAX) {
|
|
61
|
+
let oldestKey = null;
|
|
62
|
+
let oldest = Infinity;
|
|
63
|
+
for (const [key, val] of authFails) {
|
|
64
|
+
const age = val.until || val.first;
|
|
65
|
+
if (age < oldest) { oldest = age; oldestKey = key; }
|
|
66
|
+
}
|
|
67
|
+
if (oldestKey !== null) authFails.delete(oldestKey);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
56
71
|
function authBlocked(ip) {
|
|
57
72
|
const e = authFails.get(ip);
|
|
58
73
|
if (!e) return 0;
|
|
@@ -66,51 +81,30 @@ function authBlocked(ip) {
|
|
|
66
81
|
return 0;
|
|
67
82
|
}
|
|
68
83
|
|
|
84
|
+
// Only a wrong PIN counts as a guess. beginGuess is the in-flight lockout gate;
|
|
85
|
+
// noteAuthFail arms the lockout and logs it exactly once per episode.
|
|
69
86
|
function noteAuthFail(ip) {
|
|
70
87
|
const t = now();
|
|
71
88
|
let e = authFails.get(ip);
|
|
72
89
|
if (!e || (t - e.first >= AUTH_WINDOW_MS && !e.until)) e = { count: 0, first: t, until: 0 };
|
|
73
90
|
e.count += 1;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (authFails.size > AUTH_MAP_MAX) {
|
|
79
|
-
let oldestKey = null;
|
|
80
|
-
let oldest = Infinity;
|
|
81
|
-
for (const [key, val] of authFails) {
|
|
82
|
-
const age = val.until || val.first;
|
|
83
|
-
if (age < oldest) { oldest = age; oldestKey = key; }
|
|
84
|
-
}
|
|
85
|
-
if (oldestKey !== null) authFails.delete(oldestKey);
|
|
86
|
-
}
|
|
91
|
+
let armed = false;
|
|
92
|
+
if (e.count >= AUTH_FAIL_MAX && !e.until) {
|
|
93
|
+
e.until = t + AUTH_LOCKOUT_MS;
|
|
94
|
+
armed = true;
|
|
87
95
|
}
|
|
88
|
-
|
|
96
|
+
authFails.set(ip, e);
|
|
97
|
+
capAuthFails(t);
|
|
98
|
+
if (armed) log("auth lockout", ip, AUTH_FAIL_MAX, "wrong PINs in", (AUTH_WINDOW_MS / 60000) + "m; locked", (AUTH_LOCKOUT_MS / 60000) + "m");
|
|
99
|
+
return armed;
|
|
89
100
|
}
|
|
90
101
|
|
|
91
102
|
function beginGuess(ip) {
|
|
92
103
|
const t = now();
|
|
93
|
-
|
|
104
|
+
const e = authFails.get(ip);
|
|
94
105
|
if (e && e.until) {
|
|
95
106
|
if (t < e.until) return false;
|
|
96
107
|
authFails.delete(ip);
|
|
97
|
-
e = null;
|
|
98
|
-
}
|
|
99
|
-
if (!e || t - e.first >= AUTH_WINDOW_MS) e = { count: 0, first: t, until: 0 };
|
|
100
|
-
e.count += 1;
|
|
101
|
-
if (e.count >= AUTH_FAIL_MAX) e.until = t + AUTH_WINDOW_MS;
|
|
102
|
-
authFails.set(ip, e);
|
|
103
|
-
if (authFails.size > AUTH_MAP_MAX) {
|
|
104
|
-
for (const [key, val] of authFails) if (t - val.first >= AUTH_WINDOW_MS) authFails.delete(key);
|
|
105
|
-
if (authFails.size > AUTH_MAP_MAX) {
|
|
106
|
-
let oldestKey = null;
|
|
107
|
-
let oldest = Infinity;
|
|
108
|
-
for (const [key, val] of authFails) {
|
|
109
|
-
const age = val.until || val.first;
|
|
110
|
-
if (age < oldest) { oldest = age; oldestKey = key; }
|
|
111
|
-
}
|
|
112
|
-
if (oldestKey !== null) authFails.delete(oldestKey);
|
|
113
|
-
}
|
|
114
108
|
}
|
|
115
109
|
return true;
|
|
116
110
|
}
|
|
@@ -185,7 +179,7 @@ function log(...a) {
|
|
|
185
179
|
|
|
186
180
|
const isHex = (s, bytes) => typeof s === "string" && s.length === bytes * 2 && /^[0-9a-f]+$/i.test(s);
|
|
187
181
|
const validPin = (p) => !!p && typeof p === "object" && isHex(p.salt, 16) && isHex(p.hash, 32);
|
|
188
|
-
const pinPattern = /^\d{
|
|
182
|
+
const pinPattern = /^\d{4}$/;
|
|
189
183
|
const validPinClaim = (c) => !!c && typeof c === "object" &&
|
|
190
184
|
typeof c.ip === "string" && c.ip.length > 0 &&
|
|
191
185
|
(typeof c.name === "string" || c.name === null) && Number.isFinite(c.at);
|
|
@@ -247,12 +241,12 @@ function loadState() {
|
|
|
247
241
|
return { ok: false, error: "state is not an object" };
|
|
248
242
|
}
|
|
249
243
|
|
|
250
|
-
// Any pre-v5 state is discarded wholesale: its PIN may be
|
|
244
|
+
// Any pre-v5 state is discarded wholesale: its PIN may be longer than 4
|
|
251
245
|
// digits and its key set may mix untagged keys with plaintext legacy tokens.
|
|
252
246
|
// A fresh, fail-closed state is the only safe migration target.
|
|
253
247
|
if (s.v !== STATE_VERSION) {
|
|
254
248
|
const fresh = blankState();
|
|
255
|
-
log("state migrated: PIN and keys cleared; set
|
|
249
|
+
log("state migrated: PIN and keys cleared; set a 4-digit PIN on the PC, then pair the phone again");
|
|
256
250
|
if (!saveState(fresh)) return { ok: false, error: "state migration not persisted" };
|
|
257
251
|
return { ok: true, state: fresh };
|
|
258
252
|
}
|
|
@@ -518,6 +512,28 @@ function lanAddresses() {
|
|
|
518
512
|
return out;
|
|
519
513
|
}
|
|
520
514
|
|
|
515
|
+
const unexpectedDiscoverySources = new Set();
|
|
516
|
+
const DISCOVERY_SOURCE_CAP = 256;
|
|
517
|
+
|
|
518
|
+
function discoveryAddresses() { return lanAddresses().map((a) => a.address); }
|
|
519
|
+
|
|
520
|
+
// One line per PROBE names the interfaces we answer on; an address outside
|
|
521
|
+
// that set is logged once per source. This is a "check your Wi-Fi" diagnostic,
|
|
522
|
+
// never a change to who UDP replies to.
|
|
523
|
+
function discoveryRequest(rinfo) {
|
|
524
|
+
const addrs = discoveryAddresses();
|
|
525
|
+
const list = addrs.length ? addrs.join(",") : "none";
|
|
526
|
+
const src = String((rinfo && rinfo.address) || "?");
|
|
527
|
+
log("discovery request", src, "answer on", list);
|
|
528
|
+
if (src === "?" || src === "127.0.0.1" || src === "::1" || src === "::ffff:127.0.0.1" || addrs.includes(src)) return;
|
|
529
|
+
if (unexpectedDiscoverySources.has(src)) return;
|
|
530
|
+
unexpectedDiscoverySources.add(src);
|
|
531
|
+
if (unexpectedDiscoverySources.size > DISCOVERY_SOURCE_CAP) {
|
|
532
|
+
unexpectedDiscoverySources.delete(unexpectedDiscoverySources.values().next().value);
|
|
533
|
+
}
|
|
534
|
+
log("discovery unexpected source", src, "answer on", list);
|
|
535
|
+
}
|
|
536
|
+
|
|
521
537
|
function fingerprintOf(pemCert) {
|
|
522
538
|
const body = pemCert.replace(/-----[^-]+-----/g, "").replace(/\s+/g, "");
|
|
523
539
|
return createHash("sha256").update(Buffer.from(body, "base64")).digest("hex");
|
|
@@ -644,6 +660,22 @@ function publicInfo() {
|
|
|
644
660
|
}
|
|
645
661
|
|
|
646
662
|
function privateInfo() { return { ...publicInfo(), devices: state.keys.length }; }
|
|
663
|
+
|
|
664
|
+
// A phone with no device key can call /info?pair=1 to learn every endpoint it
|
|
665
|
+
// needs without UDP discovery. It never returns the PIN, its hash or any key.
|
|
666
|
+
function pairingInfo() {
|
|
667
|
+
const addrs = lanAddresses();
|
|
668
|
+
const proxyUrls = addrs.map((a) => "https://" + a.address + ":" + PROXY_PORT);
|
|
669
|
+
const agentUrls = addrs.map((a) => "https://" + a.address + ":" + HTTPS_PORT);
|
|
670
|
+
return {
|
|
671
|
+
...publicInfo(),
|
|
672
|
+
urls: proxyUrls.length ? proxyUrls : ["https://127.0.0.1:" + PROXY_PORT],
|
|
673
|
+
agentUrls: agentUrls.length ? agentUrls : ["https://127.0.0.1:" + HTTPS_PORT],
|
|
674
|
+
httpsPort: HTTPS_PORT,
|
|
675
|
+
proxyPort: PROXY_PORT,
|
|
676
|
+
pinRequired: !(state.pin && state.pin.hash),
|
|
677
|
+
};
|
|
678
|
+
}
|
|
647
679
|
function payload() { return Buffer.from(JSON.stringify(publicInfo())); }
|
|
648
680
|
|
|
649
681
|
const LOOPBACK_ORIGIN = /^https?:\/\/(127\.0\.0\.1|\[::1\]|localhost)(:\d+)?$/i;
|
|
@@ -724,7 +756,7 @@ function loopPage() {
|
|
|
724
756
|
const pinBlock = hasPin
|
|
725
757
|
? '<p class="dim">PIN set. Enter it once on the phone.</p>'
|
|
726
758
|
: '<p class="dim">No PIN yet. Set one here, then enter the same PIN on the phone.</p>\n' +
|
|
727
|
-
'<p><input id="pin" type="password" inputmode="numeric" autocomplete="new-password" placeholder="
|
|
759
|
+
'<p><input id="pin" type="password" inputmode="numeric" autocomplete="new-password" placeholder="4 digits" size="18">' +
|
|
728
760
|
'<button data-set-pin="1">Set PIN</button></p>';
|
|
729
761
|
const claim = state.pinClaim;
|
|
730
762
|
const claimLine = claim
|
|
@@ -789,7 +821,7 @@ function loopPage() {
|
|
|
789
821
|
' b.onclick = () => {\n' +
|
|
790
822
|
' const el = document.getElementById("pin");\n' +
|
|
791
823
|
' const pin = el ? el.value.trim() : "";\n' +
|
|
792
|
-
' if (!/^\\d{
|
|
824
|
+
' if (!/^\\d{4}$/.test(pin)) { alert("Exactly 4 digits"); return; }\n' +
|
|
793
825
|
' if (confirm("Set this PIN? The phone enters it once.")) post("/setup", { pin });\n' +
|
|
794
826
|
' });\n' +
|
|
795
827
|
' document.querySelectorAll("[data-revoke-all]").forEach((b) =>\n' +
|
|
@@ -1094,8 +1126,8 @@ async function handleAgent(req, res, opts) {
|
|
|
1094
1126
|
return json(req, res, 400, { ok: false, error: "pin-invalid" });
|
|
1095
1127
|
}
|
|
1096
1128
|
if (!await pinMatches(pin)) {
|
|
1097
|
-
|
|
1098
|
-
log("pin rejected", ip
|
|
1129
|
+
noteAuthFail(ip);
|
|
1130
|
+
log("pin rejected", ip);
|
|
1099
1131
|
release();
|
|
1100
1132
|
return json(req, res, 401, { ok: false, error: "bad-pin" });
|
|
1101
1133
|
}
|
|
@@ -1121,6 +1153,9 @@ async function handleAgent(req, res, opts) {
|
|
|
1121
1153
|
release();
|
|
1122
1154
|
return json(req, res, 200, { ok: true, key: key });
|
|
1123
1155
|
}
|
|
1156
|
+
if (url.pathname === "/info" && url.searchParams.has("pair")) {
|
|
1157
|
+
return json(req, res, 200, pairingInfo());
|
|
1158
|
+
}
|
|
1124
1159
|
if (url.pathname === "/" || url.pathname === "/info") {
|
|
1125
1160
|
const why = gate(req, { owner: true });
|
|
1126
1161
|
if (why) return json(req, res, 401, { ok: false, error: why });
|
|
@@ -1278,6 +1313,8 @@ export function startBeacon(opts) {
|
|
|
1278
1313
|
}
|
|
1279
1314
|
}
|
|
1280
1315
|
log("state loaded", "keys:", state.keys.length);
|
|
1316
|
+
const startAddrs = discoveryAddresses();
|
|
1317
|
+
log("discovery addresses", startAddrs.length ? startAddrs.join(",") : "none");
|
|
1281
1318
|
|
|
1282
1319
|
let udp = null;
|
|
1283
1320
|
let udpOk = !NO_UDP;
|
|
@@ -1289,6 +1326,7 @@ export function startBeacon(opts) {
|
|
|
1289
1326
|
udp.on("error", (e) => { udpOk = false; log("udp unavailable", e.code || e.message); });
|
|
1290
1327
|
udp.on("message", (msg, rinfo) => {
|
|
1291
1328
|
if (msg.toString().trim() !== PROBE) return;
|
|
1329
|
+
discoveryRequest(rinfo);
|
|
1292
1330
|
try { udp.send(payload(), rinfo.port, rinfo.address); } catch (e) { log("reply fail", e.message); }
|
|
1293
1331
|
});
|
|
1294
1332
|
udp.bind(UDP_PORT, "0.0.0.0", () => { udp.setBroadcast(true); log("udp listening", UDP_PORT); });
|
|
@@ -1406,7 +1444,7 @@ export const __test = {
|
|
|
1406
1444
|
setState: (s) => { state = s; },
|
|
1407
1445
|
freshState: blankState,
|
|
1408
1446
|
clearLimits: () => {
|
|
1409
|
-
reqHits.clear(); authFails.clear(); setupRefused.clear();
|
|
1447
|
+
reqHits.clear(); authFails.clear(); setupRefused.clear(); unexpectedDiscoverySources.clear();
|
|
1410
1448
|
authInFlight = 0; authInFlightByIp.clear();
|
|
1411
1449
|
},
|
|
1412
1450
|
setClock: (fn) => { now = typeof fn === "function" ? fn : () => Date.now(); },
|
|
@@ -1428,6 +1466,9 @@ export const __test = {
|
|
|
1428
1466
|
ownerToken,
|
|
1429
1467
|
ownerPost,
|
|
1430
1468
|
isPrivatePeer,
|
|
1469
|
+
discoveryAddresses,
|
|
1470
|
+
discoveryRequest,
|
|
1471
|
+
pinPattern: pinPattern.source,
|
|
1431
1472
|
shortFingerprint,
|
|
1432
1473
|
selfPort,
|
|
1433
1474
|
port,
|
|
@@ -1440,5 +1481,6 @@ export const __test = {
|
|
|
1440
1481
|
constants: {
|
|
1441
1482
|
STATE_VERSION, PIN_ITER, DERIVE_MAX, PASSWORD_NEG_TTL, KEY_TTL, KEY_ROTATE_AFTER,
|
|
1442
1483
|
KEY_COOKIE_MAX_AGE, KEY_CAP, UPSTREAM_TIMEOUT_MS, UPSTREAM_PROBE_MS, EXPOSED_PORT,
|
|
1484
|
+
AUTH_FAIL_MAX, AUTH_WINDOW_MS, AUTH_LOCKOUT_MS, DISCOVERY_SOURCE_CAP, HTTPS_PORT, PROXY_PORT, UDP_PORT,
|
|
1443
1485
|
},
|
|
1444
1486
|
};
|
package/package.json
CHANGED