@songsid/agend 2.3.5-alpha.10 → 2.3.5-alpha.11
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/dist/accounts-view.d.ts +14 -0
- package/dist/accounts-view.js +22 -6
- package/dist/accounts-view.js.map +1 -1
- package/dist/agent-cli-instructions.md +2 -2
- package/dist/auth-api.d.ts +48 -16
- package/dist/auth-api.js +99 -32
- package/dist/auth-api.js.map +1 -1
- package/dist/authority/settings-role.d.ts +56 -0
- package/dist/authority/settings-role.js +48 -0
- package/dist/authority/settings-role.js.map +1 -0
- package/dist/backend/claude-code.d.ts +2 -0
- package/dist/backend/claude-code.js +16 -3
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/cli-env-probe.js +6 -2
- package/dist/backend/cli-env-probe.js.map +1 -1
- package/dist/backend/codex.d.ts +5 -3
- package/dist/backend/codex.js +31 -13
- package/dist/backend/codex.js.map +1 -1
- package/dist/backend/credential-profile.d.ts +2 -0
- package/dist/backend/credential-profile.js +2 -0
- package/dist/backend/credential-profile.js.map +1 -1
- package/dist/backend/kiro.js +1 -1
- package/dist/backend/kiro.js.map +1 -1
- package/dist/backend/types.d.ts +5 -1
- package/dist/backend/types.js.map +1 -1
- package/dist/backend-availability.d.ts +15 -0
- package/dist/backend-availability.js +37 -1
- package/dist/backend-availability.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/bundled-tmux-guard.d.ts +4 -0
- package/dist/bundled-tmux-guard.js +7 -0
- package/dist/bundled-tmux-guard.js.map +1 -1
- package/dist/claude-auth-status.d.ts +20 -8
- package/dist/claude-auth-status.js +38 -22
- package/dist/claude-auth-status.js.map +1 -1
- package/dist/cli-audited.d.ts +60 -0
- package/dist/cli-audited.js +84 -0
- package/dist/cli-audited.js.map +1 -0
- package/dist/cli-capability.d.ts +36 -5
- package/dist/cli-capability.js +2 -2
- package/dist/cli-capability.js.map +1 -1
- package/dist/cli-caps-module.d.ts +5 -1
- package/dist/cli-caps-module.js +4 -2
- package/dist/cli-caps-module.js.map +1 -1
- package/dist/cli-registry-check.js +16 -2
- package/dist/cli-registry-check.js.map +1 -1
- package/dist/cli-registry.d.ts +56 -4
- package/dist/cli-registry.js +1 -1
- package/dist/cli-registry.js.map +1 -1
- package/dist/cli-spec-antigravity.d.ts +12 -1
- package/dist/cli-spec-antigravity.js +13 -1
- package/dist/cli-spec-antigravity.js.map +1 -1
- package/dist/cli-spec-claude-code.d.ts +9 -0
- package/dist/cli-spec-claude-code.js +4 -2
- package/dist/cli-spec-claude-code.js.map +1 -1
- package/dist/cli-spec-codex.d.ts +10 -1
- package/dist/cli-spec-codex.js +5 -3
- package/dist/cli-spec-codex.js.map +1 -1
- package/dist/cli-spec-grok.d.ts +5 -0
- package/dist/cli-spec-grok.js +6 -1
- package/dist/cli-spec-grok.js.map +1 -1
- package/dist/cli-spec-kiro-cli.d.ts +7 -1
- package/dist/cli-spec-kiro-cli.js +7 -3
- package/dist/cli-spec-kiro-cli.js.map +1 -1
- package/dist/cli-spec-muse.d.ts +2 -0
- package/dist/cli-spec-muse.js +3 -1
- package/dist/cli-spec-muse.js.map +1 -1
- package/dist/cli-spec-opencode.d.ts +11 -1
- package/dist/cli-spec-opencode.js +7 -2
- package/dist/cli-spec-opencode.js.map +1 -1
- package/dist/cli.js +28 -1
- package/dist/cli.js.map +1 -1
- package/dist/daemon.d.ts +3 -0
- package/dist/daemon.js +17 -2
- package/dist/daemon.js.map +1 -1
- package/dist/fleet-context.d.ts +5 -1
- package/dist/fleet-manager.d.ts +337 -69
- package/dist/fleet-manager.js +1247 -355
- package/dist/fleet-manager.js.map +1 -1
- package/dist/fleet-process-handlers.d.ts +1 -1
- package/dist/fleet-process-handlers.js +3 -2
- package/dist/fleet-process-handlers.js.map +1 -1
- package/dist/general-knowledge/skills/concepts/SKILL.md +21 -14
- package/dist/general-knowledge/skills/credential-profiles/SKILL.md +9 -8
- package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +9 -1
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +27 -20
- package/dist/instance-lifecycle.js +4 -2
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/instructions.js +29 -6
- package/dist/instructions.js.map +1 -1
- package/dist/locale.js +119 -75
- package/dist/locale.js.map +1 -1
- package/dist/login-manager.d.ts +2 -2
- package/dist/login-manager.js +3 -2
- package/dist/login-manager.js.map +1 -1
- package/dist/native-model-catalog.d.ts +20 -0
- package/dist/native-model-catalog.js +107 -2
- package/dist/native-model-catalog.js.map +1 -1
- package/dist/public-web-gateway.js +1 -1
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/runtime-api.d.ts +1 -1
- package/dist/runtime-api.js +104 -12
- package/dist/runtime-api.js.map +1 -1
- package/dist/runtime-autostart.d.ts +61 -0
- package/dist/runtime-autostart.js +161 -0
- package/dist/runtime-autostart.js.map +1 -0
- package/dist/runtime-background.d.ts +200 -0
- package/dist/runtime-background.js +480 -0
- package/dist/runtime-background.js.map +1 -0
- package/dist/runtime-build-info.js +5 -5
- package/dist/runtime-build-info.js.map +1 -1
- package/dist/runtime-cli-background.d.ts +92 -0
- package/dist/runtime-cli-background.js +336 -0
- package/dist/runtime-cli-background.js.map +1 -0
- package/dist/runtime-cli-install.d.ts +148 -8
- package/dist/runtime-cli-install.js +253 -59
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/runtime-cli.d.ts +8 -1
- package/dist/runtime-cli.js +206 -44
- package/dist/runtime-cli.js.map +1 -1
- package/dist/runtime-client-store.d.ts +11 -0
- package/dist/runtime-client-store.js +20 -5
- package/dist/runtime-client-store.js.map +1 -1
- package/dist/runtime-client.d.ts +23 -1
- package/dist/runtime-client.js +92 -6
- package/dist/runtime-client.js.map +1 -1
- package/dist/runtime-connection.d.ts +1 -1
- package/dist/runtime-connection.js +1 -1
- package/dist/runtime-connection.js.map +1 -1
- package/dist/runtime-coordinator.d.ts +95 -1
- package/dist/runtime-coordinator.js +344 -10
- package/dist/runtime-coordinator.js.map +1 -1
- package/dist/runtime-enroll-notice.d.ts +4 -0
- package/dist/runtime-enroll-notice.js +21 -0
- package/dist/runtime-enroll-notice.js.map +1 -0
- package/dist/runtime-enrollment.d.ts +21 -0
- package/dist/runtime-enrollment.js +52 -0
- package/dist/runtime-enrollment.js.map +1 -0
- package/dist/runtime-pane-native.js +4 -4
- package/dist/runtime-pane-native.js.map +1 -1
- package/dist/runtime-protocol.d.ts +78 -1
- package/dist/runtime-protocol.js +95 -5
- package/dist/runtime-protocol.js.map +1 -1
- package/dist/runtime-remote-accounts.d.ts +12 -0
- package/dist/runtime-remote-accounts.js +56 -5
- package/dist/runtime-remote-accounts.js.map +1 -1
- package/dist/runtime-remote-setup.d.ts +4 -1
- package/dist/runtime-remote-setup.js +4 -1
- package/dist/runtime-remote-setup.js.map +1 -1
- package/dist/runtime-update-controller.d.ts +11 -0
- package/dist/runtime-update-controller.js +56 -4
- package/dist/runtime-update-controller.js.map +1 -1
- package/dist/settings-api.d.ts +13 -1
- package/dist/settings-api.js +39 -3
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.d.ts +5 -13
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-confirmation.d.ts +11 -13
- package/dist/settings-confirmation.js +2 -6
- package/dist/settings-confirmation.js.map +1 -1
- package/dist/settings-effect.d.ts +5 -0
- package/dist/settings-effect.js +76 -10
- package/dist/settings-effect.js.map +1 -1
- package/dist/settings-http-confirmation.d.ts +8 -1
- package/dist/settings-http-confirmation.js +39 -13
- package/dist/settings-http-confirmation.js.map +1 -1
- package/dist/settings-request-capability.d.ts +7 -0
- package/dist/settings-request-capability.js +3 -1
- package/dist/settings-request-capability.js.map +1 -1
- package/dist/setup-i18n.js +4 -4
- package/dist/setup-i18n.js.map +1 -1
- package/dist/subagent-records.d.ts +45 -0
- package/dist/subagent-records.js +214 -0
- package/dist/subagent-records.js.map +1 -0
- package/dist/subagent-service.d.ts +27 -0
- package/dist/subagent-service.js +199 -0
- package/dist/subagent-service.js.map +1 -0
- package/dist/tmux-manager.d.ts +2 -2
- package/dist/tmux-manager.js +5 -3
- package/dist/tmux-manager.js.map +1 -1
- package/dist/ui/account-identity.js +7 -5
- package/dist/ui/accounts-keepalive.js +17 -17
- package/dist/ui/accounts-manage.js +34 -34
- package/dist/ui/accounts-view.js +63 -21
- package/dist/ui/agent-runtime-settings.js +1 -1
- package/dist/ui/backend-signin.js +67 -67
- package/dist/ui/chat-msg-actions.js +50 -4
- package/dist/ui/chat-quote.js +256 -0
- package/dist/ui/chat-store.js +9 -4
- package/dist/ui/cli-caps.js +7 -7
- package/dist/ui/credential-profile-select.js +4 -4
- package/dist/ui/general-location.js +1 -1
- package/dist/ui/host-install.js +290 -0
- package/dist/ui/hub-company-join-strings.js +3 -0
- package/dist/ui/hub-company-join.js +20 -2
- package/dist/ui/hub-owner-strings.js +5 -4
- package/dist/ui/hub-pairing-progress-strings.js +1 -1
- package/dist/ui/hub-quick-strings.js +4 -4
- package/dist/ui/machine-signin.js +4 -4
- package/dist/ui/model-picker.js +68 -0
- package/dist/ui/panel-chat.js +73 -13
- package/dist/ui/panel-fleet.js +1 -1
- package/dist/ui/panel-hub.js +8 -4
- package/dist/ui/panel-needs.js +2 -2
- package/dist/ui/panel-runtimes.js +232 -33
- package/dist/ui/panel-windows-cli.js +1 -1
- package/dist/ui/runtime-cli-install.js +99 -20
- package/dist/ui/runtime-commands.d.ts +2 -0
- package/dist/ui/runtime-commands.js +34 -1
- package/dist/ui/runtime-update-status.js +2 -2
- package/dist/ui/search-dialog.js +1 -0
- package/dist/ui/settings-access-strings.js +1 -1
- package/dist/ui/settings-catalog.js +19 -3
- package/dist/ui/settings-confirm.js +2 -2
- package/dist/ui/settings-devices.js +59 -25
- package/dist/ui/settings-dialogs.js +12 -13
- package/dist/ui/settings-guests.js +1 -1
- package/dist/ui/settings-hub-company-join.js +10 -7
- package/dist/ui/settings-hub-connection.js +121 -0
- package/dist/ui/settings-hub-membership.js +1 -1
- package/dist/ui/settings-hub-run.js +5 -6
- package/dist/ui/settings-hub-section.js +3 -6
- package/dist/ui/settings-hub.js +12 -7
- package/dist/ui/settings-layout.js +6 -6
- package/dist/ui/settings-outside.js +87 -19
- package/dist/ui/settings-registry.js +2 -1
- package/dist/ui/settings-revoke-strings.js +28 -0
- package/dist/ui/settings-strings.js +19 -19
- package/dist/ui/settings-web-authority.js +11 -4
- package/dist/ui/shared/accounts.css +11 -1
- package/dist/ui/shared/agend-auth.js +8 -1
- package/dist/ui/shared/app-i18n.js +10 -12
- package/dist/ui/shared/app-session.js +13 -16
- package/dist/ui/shared/app-shell.js +36 -36
- package/dist/ui/shared/app.css +35 -2
- package/dist/ui/shared/chat-strings.js +4 -4
- package/dist/ui/shared/device-roles.js +27 -0
- package/dist/ui/shared/host-install.css +10 -0
- package/dist/ui/shared/hub-owner.css +6 -0
- package/dist/ui/shared/model-picker.css +21 -0
- package/dist/ui/shared/runtime-install.css +26 -1
- package/dist/ui/shared/setup-host-text.js +4 -4
- package/dist/ui/shared/signin-authenticator.js +60 -0
- package/dist/ui/shared/signin.js +45 -25
- package/dist/ui/shared/subagent-row.css +15 -0
- package/dist/ui/shared/usage-dialog.js +1 -1
- package/dist/ui/shared/view-strings.js +7 -7
- package/dist/ui/shared/web-authorize.js +53 -3
- package/dist/ui/signin-authenticator.html +60 -0
- package/dist/ui/structured-signin.js +30 -30
- package/dist/ui/subagent-row.js +72 -0
- package/dist/ui/web-terminal/terminal.js +9 -9
- package/dist/update-launch.js +4 -1
- package/dist/update-launch.js.map +1 -1
- package/dist/update-npm-env.d.ts +70 -0
- package/dist/update-npm-env.js +128 -0
- package/dist/update-npm-env.js.map +1 -0
- package/dist/usage/providers.js +2 -2
- package/dist/usage/providers.js.map +1 -1
- package/dist/web-api.d.ts +33 -4
- package/dist/web-api.js +312 -18
- package/dist/web-api.js.map +1 -1
- package/dist/web-auth.js +1 -1
- package/dist/web-auth.js.map +1 -1
- package/dist/web-channel-echo.js +3 -1
- package/dist/web-channel-echo.js.map +1 -1
- package/dist/web-commands.d.ts +9 -1
- package/dist/web-commands.js +7 -1
- package/dist/web-commands.js.map +1 -1
- package/dist/web-host-install.d.ts +127 -0
- package/dist/web-host-install.js +165 -0
- package/dist/web-host-install.js.map +1 -0
- package/dist/web-remote-access.d.ts +126 -11
- package/dist/web-remote-access.js +267 -34
- package/dist/web-remote-access.js.map +1 -1
- package/dist/web-session.d.ts +11 -3
- package/dist/web-session.js.map +1 -1
- package/dist/web-signin-device.d.ts +16 -0
- package/dist/web-signin-device.js +81 -0
- package/dist/web-signin-device.js.map +1 -0
- package/dist/web-update.js +3 -1
- package/dist/web-update.js.map +1 -1
- package/dist/windows-cli-api.js +2 -1
- package/dist/windows-cli-api.js.map +1 -1
- package/dist/windows-cli-worker.d.ts +14 -0
- package/dist/windows-cli-worker.js +145 -1
- package/dist/windows-cli-worker.js.map +1 -1
- package/dist/windows-cli.d.ts +4 -0
- package/dist/windows-cli.js +9 -1
- package/dist/windows-cli.js.map +1 -1
- package/launcher/agend-install.cjs +16 -3
- package/package.json +1 -1
- package/templates/runtime-install/install.ps1 +219 -12
|
@@ -16,6 +16,39 @@ export declare const TOTP_WRONG_LIMIT = 5;
|
|
|
16
16
|
/** The first wait; #3008 C(b): each further one doubles, up to TOTP_PAUSE_MAX_MS. A correct code resets it. */
|
|
17
17
|
export declare const TOTP_PAUSE_MS: number;
|
|
18
18
|
export declare const TOTP_PAUSE_MAX_MS: number;
|
|
19
|
+
/**
|
|
20
|
+
* #3486 (new-device sign-in with an admin's own authenticator): the wrong-code limits of that sign-in, which are NOT the
|
|
21
|
+
* confirmation limiter above — an unauthenticated route must not be able to pause the confirmations of admins already signed in.
|
|
22
|
+
* Four layers, so that one person's typos stop only that person, and the shared ones are only ceilings:
|
|
23
|
+
* 1. **this browser** (first to trip): SIGNIN_BROWSER_WRONG_LIMIT wrong codes pause that browser alone — 5 minutes, doubling up to
|
|
24
|
+
* an hour. Memory only; it counts every failure the same, whatever name was typed;
|
|
25
|
+
* 2. **the admin**, 3. **the name typed** (a name that is no admin's is counted exactly like one that is: nothing tells them apart)
|
|
26
|
+
* and 4. **the whole sign-in**: shared ceilings (SIGNIN_WRONG_LIMIT, SIGNIN_WRONG_LIMIT, SIGNIN_FLEET_WRONG_LIMIT wrong codes →
|
|
27
|
+
* 15 minutes, doubling up to a day). A browser the admin already signed in from (its "known device" mark) is not held by these.
|
|
28
|
+
* A shared count forgets after a day of no wrong codes (this browser's after an hour), and the doubling level steps down once a day has
|
|
29
|
+
* passed without one. A browser with a valid known-device mark is counted by the mark instead of its cookie id (so shedding cookies
|
|
30
|
+
* resets nothing) and, with every other attempt carrying a mark for the same admin, in a fifth limiter (SIGNIN_KNOWN_WRONG_LIMIT).
|
|
31
|
+
* Half-way through the admin's count (and the whole sign-in's) the admins are told once per cycle.
|
|
32
|
+
*/
|
|
33
|
+
export declare const SIGNIN_BROWSER_WRONG_LIMIT = 5;
|
|
34
|
+
export declare const SIGNIN_BROWSER_PAUSE_MS: number;
|
|
35
|
+
export declare const SIGNIN_BROWSER_PAUSE_MAX_MS: number;
|
|
36
|
+
export declare const SIGNIN_WRONG_LIMIT = 10;
|
|
37
|
+
export declare const SIGNIN_FLEET_WRONG_LIMIT = 50;
|
|
38
|
+
/** A shared wrong-code count is forgotten after this long without one (a slow guesser must not escape by pacing); the doubling level drops one step per SIGNIN_LEVEL_QUIET_MS without one. */
|
|
39
|
+
export declare const SIGNIN_COUNT_QUIET_MS: number;
|
|
40
|
+
/** This browser's own count forgets sooner: it only holds that browser. */
|
|
41
|
+
export declare const SIGNIN_BROWSER_QUIET_MS: number;
|
|
42
|
+
/** Attempts that carry a valid known-device mark of one admin count together in one more limiter, whatever cookies they send. */
|
|
43
|
+
export declare const SIGNIN_KNOWN_WRONG_LIMIT = 30;
|
|
44
|
+
export declare const SIGNIN_LEVEL_QUIET_MS: number;
|
|
45
|
+
/**
|
|
46
|
+
* #3486: whether a chat fleet's admin may sign a new browser in with their own authenticator over a PUBLIC link too (the
|
|
47
|
+
* quick or named link). The one place that says so — the owner may veto it at acceptance: set this to `false` and a sign-in over
|
|
48
|
+
* a link is refused (404, as if the route were not there) while direct connections (LAN, tailnet, the owner's own proxy) keep
|
|
49
|
+
* working. A web-only fleet's link is another thing: only the outside link the owner opened with "Allow connections from outside".
|
|
50
|
+
*/
|
|
51
|
+
export declare const TOTP_SIGNIN_OVER_PUBLIC_LINK = true;
|
|
19
52
|
/** #3008 review (Prism P2 1): a state that could not be saved is written again this often until it is. */
|
|
20
53
|
export declare const OUTSIDE_SAVE_RETRY_MS = 30000;
|
|
21
54
|
/** How long a secret being set up waits for its first code. */
|
|
@@ -38,6 +71,12 @@ export declare function matchTotp(secret: Uint8Array, code: string, nowMs: numbe
|
|
|
38
71
|
export declare function totpSkew(secret: Uint8Array, code: string, nowMs: number): number | null;
|
|
39
72
|
/** The `otpauth://` URI an authenticator app reads from the QR code (or the key typed in by hand). */
|
|
40
73
|
export declare function otpauthUri(secretBase32: string, account: string): string;
|
|
74
|
+
/** The host operator's key (a web-only fleet's one admin; also a chat fleet's host session). */
|
|
75
|
+
export declare const HOST_ADMIN_KEY = "host\0operator";
|
|
76
|
+
/** An admin's key: their connection and their account on it (ids are per platform). */
|
|
77
|
+
export declare const adminKey: (adapterId: string, userId: string) => string;
|
|
78
|
+
/** At most this many admins have an authenticator (a chat fleet's admin lists are short). */
|
|
79
|
+
export declare const ADMIN_AUTHENTICATORS_MAX = 64;
|
|
41
80
|
/** How many sessions from outside one generation remembers (each is a sign-in with a code; older ones read as revoked). */
|
|
42
81
|
export declare const OUTSIDE_HANDLES_MAX = 64;
|
|
43
82
|
export type TotpVerdict = {
|
|
@@ -69,32 +108,79 @@ export type TotpVerdict = {
|
|
|
69
108
|
export interface RemoteAccessStatus {
|
|
70
109
|
enrolled: boolean;
|
|
71
110
|
enrolledAt: number | null;
|
|
111
|
+
/** This admin's own "ask for my code to confirm from other devices" switch. */
|
|
112
|
+
strict: boolean;
|
|
72
113
|
outside: boolean;
|
|
73
114
|
/** A wait in force now (ms left), else 0. */
|
|
74
115
|
pausedForMs: number;
|
|
75
116
|
}
|
|
117
|
+
/** Whose shared limit a wrong code started, for the Notices (never part of an answer): `fleet`, or `admin` (their own or the name typed, when it is a real admin's). */
|
|
118
|
+
export interface SignInBegan {
|
|
119
|
+
fleet: boolean;
|
|
120
|
+
admin: boolean;
|
|
121
|
+
waitMs: number; /** Half-way through the whole sign-in's / a real admin's count, first time this cycle: the admins are told once. */
|
|
122
|
+
halfFleet: boolean;
|
|
123
|
+
halfAdmin: boolean;
|
|
124
|
+
}
|
|
125
|
+
export type SignInVerdict = {
|
|
126
|
+
kind: "ok";
|
|
127
|
+
}
|
|
128
|
+
/** `skewSteps`: for a real admin, the code would have matched that many steps out — this computer's clock is likely off (logged, never answered). */
|
|
129
|
+
| {
|
|
130
|
+
kind: "wrong";
|
|
131
|
+
skewSteps?: number;
|
|
132
|
+
began: SignInBegan;
|
|
133
|
+
}
|
|
134
|
+
/** A wait is in force (or this wrong code started one): the same answer for every name. */
|
|
135
|
+
| {
|
|
136
|
+
kind: "paused";
|
|
137
|
+
retryAfterMs: number;
|
|
138
|
+
began: SignInBegan;
|
|
139
|
+
}
|
|
140
|
+
/** Right, but the step it used could not be saved: refused (else a restart would let it be used again). */
|
|
141
|
+
| {
|
|
142
|
+
kind: "unavailable";
|
|
143
|
+
};
|
|
76
144
|
export declare class WebRemoteAccess {
|
|
77
145
|
private readonly path;
|
|
78
146
|
private readonly log;
|
|
79
147
|
private readonly now;
|
|
80
148
|
private readonly monotonic;
|
|
81
149
|
private state;
|
|
150
|
+
/** Set-ups waiting for their first code, per session handle: one session's start never replaces another's. */
|
|
82
151
|
private pending;
|
|
83
152
|
private warned;
|
|
84
153
|
/** The state in memory is not on disk yet (a write failed): written again, by the next change or the retry timer. */
|
|
85
154
|
private dirty;
|
|
86
155
|
private retry;
|
|
156
|
+
/** #3486: the limiter of each browser (memory only; bounded). Key: the caller's hash of its cookie id and address. */
|
|
157
|
+
private browserLim;
|
|
158
|
+
/** #3486: what a sign-in for an identifier that is no admin's is compared with — a secret nobody has, so the work done is the same. */
|
|
159
|
+
private readonly decoySecret;
|
|
87
160
|
constructor(path: string, log: {
|
|
88
161
|
warn(obj: object, msg?: string): void;
|
|
89
162
|
}, now?: () => number, monotonic?: () => number);
|
|
90
|
-
|
|
163
|
+
/** The keys (adminKey) of the chat admins that have an authenticator — never shown to anyone; the sign-in resolves a typed name among them. */
|
|
164
|
+
get adminKeys(): string[];
|
|
165
|
+
/** One admin's record (the host operator's by default). */
|
|
166
|
+
private rec;
|
|
167
|
+
/** The state with `who`'s record set (undefined: removed). */
|
|
168
|
+
private withRec;
|
|
169
|
+
status(who?: string): RemoteAccessStatus;
|
|
91
170
|
get enrolled(): boolean;
|
|
171
|
+
/** Whether `who` has an authenticator set up. */
|
|
172
|
+
isEnrolled(who: string): boolean;
|
|
173
|
+
/** `who`'s own "ask for my code to confirm from other devices" switch (never on without an app). */
|
|
174
|
+
strictOf(who: string): boolean;
|
|
92
175
|
/**
|
|
93
176
|
* #3355 review (Prism P2): which app is set up — an opaque id of this enrollment (its secret and when it was set up), null
|
|
94
177
|
* when none. Replacing the app, or removing it and setting one up again, gives another id: what a code from the old one
|
|
95
178
|
* authorized can tell it no longer holds. Never the secret itself.
|
|
96
179
|
*/
|
|
97
180
|
get enrollment(): string | null;
|
|
181
|
+
enrollmentOf(who: string): string | null;
|
|
182
|
+
/** Turn `who`'s own switch on or off. On only with their app set up. "unsaved": in force in memory, not on disk yet. */
|
|
183
|
+
setStrict(who: string, on: boolean): "ok" | "not_enrolled" | "unsaved";
|
|
98
184
|
/** The sessions authorized from outside since the last revocation (their receipts hold). */
|
|
99
185
|
get admitted(): ReadonlySet<string>;
|
|
100
186
|
/**
|
|
@@ -105,32 +191,61 @@ export declare class WebRemoteAccess {
|
|
|
105
191
|
/** Undo a change whose write failed, keeping whatever was already owed to the disk before it (#3015 review r3, P2 1). */
|
|
106
192
|
private restore;
|
|
107
193
|
get outside(): boolean;
|
|
194
|
+
/** Whether `who` can have a record: they already do, or there is room (the host operator's is always allowed). */
|
|
195
|
+
hasRoom(who: string): boolean;
|
|
196
|
+
/** Void the set-up the session `handle` began: its secret can never be finished (a fresh begin is the only way on). */
|
|
197
|
+
cancelEnrollment(handle: string): void;
|
|
108
198
|
/**
|
|
109
|
-
* A new secret for the session `handle` to set up (it replaces nothing until confirmEnrollment). Returned once:
|
|
110
|
-
* caller shows it to that session and forgets it.
|
|
199
|
+
* A new secret for the session `handle` to set up, as `who` (it replaces nothing until confirmEnrollment). Returned once:
|
|
200
|
+
* the caller shows it to that session and forgets it.
|
|
111
201
|
*/
|
|
112
|
-
beginEnrollment(handle: string, account: string): {
|
|
202
|
+
beginEnrollment(handle: string, account: string, who?: string): {
|
|
113
203
|
secret: string;
|
|
114
204
|
uri: string;
|
|
115
205
|
expiresInMs: number;
|
|
116
206
|
};
|
|
117
207
|
/**
|
|
118
|
-
* The first code from the app being set up, by the session that began it. "ok": it is now
|
|
119
|
-
* replaced
|
|
208
|
+
* The first code from the app being set up, by the session that began it. "ok": it is now `who`'s (a previous one is
|
|
209
|
+
* replaced, their switch kept). The host operator's also ends what was authorized from outside, and starts the limiter
|
|
210
|
+
* afresh only when made on the AgEnD computer itself (`physicalHost`); another admin's does neither — enrolling must not be a way
|
|
211
|
+
* to reset the fleet-wide wrong-code limit. "full": no room for another admin's record (a record is never accepted that a restart
|
|
212
|
+
* would drop).
|
|
120
213
|
*/
|
|
121
|
-
confirmEnrollment(handle: string, code: string
|
|
214
|
+
confirmEnrollment(handle: string, code: string, opts?: {
|
|
215
|
+
physicalHost?: boolean;
|
|
216
|
+
}): "ok" | "wrong" | "expired" | "unsaved" | "full";
|
|
122
217
|
/**
|
|
123
|
-
* Forget
|
|
124
|
-
*
|
|
218
|
+
* Forget `who`'s app (their switch with it); the host operator's also turns the outside switch off and ends what was
|
|
219
|
+
* authorized from outside. Nothing set up: nothing happens — in particular a set-up still waiting for its first code is left
|
|
220
|
+
* alone (a recovery begun on the host must not be cleared by someone else's Remove). In force in memory at once; false: not
|
|
221
|
+
* saved yet (retried — a restart before that would read the old file).
|
|
125
222
|
*/
|
|
126
|
-
remove(): boolean;
|
|
223
|
+
remove(who?: string): boolean;
|
|
127
224
|
/**
|
|
128
225
|
* The switch. On only with an app set up. Off ends what was authorized from outside (handles). "unsaved": in force in
|
|
129
226
|
* memory, not on disk yet (retried; asking again writes it again).
|
|
130
227
|
*/
|
|
131
228
|
setOutside(on: boolean): "ok" | "not_enrolled" | "unsaved";
|
|
132
229
|
/** A code typed at sign-in from outside. Each step is accepted once; wrong codes count toward a wait. */
|
|
133
|
-
verify(code: string): TotpVerdict;
|
|
230
|
+
verify(code: string, who?: string): TotpVerdict;
|
|
231
|
+
/**
|
|
232
|
+
* #3486: a new browser signs in with an admin's OWN authenticator code. `who`: the admin the typed name resolved to (null: it
|
|
233
|
+
* resolved to nobody — no such name, an admin with no app, one no longer an admin: the caller does not say which); `ident`: the
|
|
234
|
+
* normalized text typed, whatever it is; `browser`: this browser's key, and whether it carries a valid "known device" mark for `who`.
|
|
235
|
+
* A code is compared with that admin's secret when there is one and with a decoy secret when there is not — the same work — and
|
|
236
|
+
* every failed attempt changes and saves the same counters, so neither the answer nor the time says whether a name is an admin who
|
|
237
|
+
* has an app. What can pause an attempt: this browser's own limiter, the typed name's, the whole sign-in's (all three answer
|
|
238
|
+
* identically for every name). The admin's own limiter is a ceiling that never changes an answer: while it is in force a
|
|
239
|
+
* code is not tried and is answered as any wrong one (so using two names of one admin shows nothing either). A known device is
|
|
240
|
+
* not held by the shared ceilings, only by its mark's own limiter and the known-path limiter of its admin (so shedding cookies resets nothing).
|
|
241
|
+
* `browser.key` is the cookie-derived key, or — when `known` — the key of the mark itself.
|
|
242
|
+
* - one use per time step: the same `lastStep` as the admin's confirmations and switch;
|
|
243
|
+
* - success clears that admin's own count, that name's and this browser's — never the whole sign-in's, which only time lowers.
|
|
244
|
+
*/
|
|
245
|
+
signIn(who: string | null, ident: string, code: string, browser: {
|
|
246
|
+
key: string;
|
|
247
|
+
known: boolean;
|
|
248
|
+
}): SignInVerdict;
|
|
134
249
|
/**
|
|
135
250
|
* Saved: true. Not saved: false (warned once until it works again) — memory keeps the new state, and it is written
|
|
136
251
|
* again by the next change or every OUTSIDE_SAVE_RETRY_MS until it is (#3008 review, Prism P2 1).
|
|
@@ -13,6 +13,15 @@
|
|
|
13
13
|
* code resets it — #3008 C(b), confirmed by the user, decision 0471da59). Never a permanent
|
|
14
14
|
* lock (the user's decision 4). It is fleet-wide: one guesser from many addresses is one guesser.
|
|
15
15
|
*
|
|
16
|
+
* AGEND-122 (upstream #3486, per-admin): the authenticator is each admin's own. The record above is the HOST OPERATOR's — a
|
|
17
|
+
* web-only fleet's one person, and the one connections from outside sign in with — and a chat fleet's other admins each have
|
|
18
|
+
* their own under `admins`, keyed by connection and account. An admin enrols, replaces and removes only their own; each has
|
|
19
|
+
* their own "ask for my code to confirm from other devices" switch (`strict`), kept with the record so removing the app removes
|
|
20
|
+
* it. The wrong-code limiter stays fleet-wide.
|
|
21
|
+
*
|
|
22
|
+
* #3486: the same per-admin app also signs a new browser in as that admin (`signIn`): one use per step with the confirmations
|
|
23
|
+
* (`lastStep`), its own limiters (per admin in the record, per typed name in memory, one fleet-wide), never the confirmations' own.
|
|
24
|
+
*
|
|
16
25
|
* The secret never leaves this module except once, to the host operator who is setting it up (beginEnrollment). It is
|
|
17
26
|
* never logged, never in a status, a Notice or an error.
|
|
18
27
|
*/
|
|
@@ -37,6 +46,42 @@ export const TOTP_WRONG_LIMIT = 5;
|
|
|
37
46
|
/** The first wait; #3008 C(b): each further one doubles, up to TOTP_PAUSE_MAX_MS. A correct code resets it. */
|
|
38
47
|
export const TOTP_PAUSE_MS = 15 * 60_000;
|
|
39
48
|
export const TOTP_PAUSE_MAX_MS = 24 * 60 * 60_000;
|
|
49
|
+
/**
|
|
50
|
+
* #3486 (new-device sign-in with an admin's own authenticator): the wrong-code limits of that sign-in, which are NOT the
|
|
51
|
+
* confirmation limiter above — an unauthenticated route must not be able to pause the confirmations of admins already signed in.
|
|
52
|
+
* Four layers, so that one person's typos stop only that person, and the shared ones are only ceilings:
|
|
53
|
+
* 1. **this browser** (first to trip): SIGNIN_BROWSER_WRONG_LIMIT wrong codes pause that browser alone — 5 minutes, doubling up to
|
|
54
|
+
* an hour. Memory only; it counts every failure the same, whatever name was typed;
|
|
55
|
+
* 2. **the admin**, 3. **the name typed** (a name that is no admin's is counted exactly like one that is: nothing tells them apart)
|
|
56
|
+
* and 4. **the whole sign-in**: shared ceilings (SIGNIN_WRONG_LIMIT, SIGNIN_WRONG_LIMIT, SIGNIN_FLEET_WRONG_LIMIT wrong codes →
|
|
57
|
+
* 15 minutes, doubling up to a day). A browser the admin already signed in from (its "known device" mark) is not held by these.
|
|
58
|
+
* A shared count forgets after a day of no wrong codes (this browser's after an hour), and the doubling level steps down once a day has
|
|
59
|
+
* passed without one. A browser with a valid known-device mark is counted by the mark instead of its cookie id (so shedding cookies
|
|
60
|
+
* resets nothing) and, with every other attempt carrying a mark for the same admin, in a fifth limiter (SIGNIN_KNOWN_WRONG_LIMIT).
|
|
61
|
+
* Half-way through the admin's count (and the whole sign-in's) the admins are told once per cycle.
|
|
62
|
+
*/
|
|
63
|
+
export const SIGNIN_BROWSER_WRONG_LIMIT = 5;
|
|
64
|
+
export const SIGNIN_BROWSER_PAUSE_MS = 5 * 60_000;
|
|
65
|
+
export const SIGNIN_BROWSER_PAUSE_MAX_MS = 60 * 60_000;
|
|
66
|
+
export const SIGNIN_WRONG_LIMIT = 10;
|
|
67
|
+
export const SIGNIN_FLEET_WRONG_LIMIT = 50;
|
|
68
|
+
/** A shared wrong-code count is forgotten after this long without one (a slow guesser must not escape by pacing); the doubling level drops one step per SIGNIN_LEVEL_QUIET_MS without one. */
|
|
69
|
+
export const SIGNIN_COUNT_QUIET_MS = 24 * 60 * 60_000;
|
|
70
|
+
/** This browser's own count forgets sooner: it only holds that browser. */
|
|
71
|
+
export const SIGNIN_BROWSER_QUIET_MS = 60 * 60_000;
|
|
72
|
+
/** Attempts that carry a valid known-device mark of one admin count together in one more limiter, whatever cookies they send. */
|
|
73
|
+
export const SIGNIN_KNOWN_WRONG_LIMIT = 30;
|
|
74
|
+
export const SIGNIN_LEVEL_QUIET_MS = 24 * 60 * 60_000;
|
|
75
|
+
/** How many typed names' limiters (saved) and browsers' (memory) are remembered; the shared ceilings bound how fast they can be made. */
|
|
76
|
+
const SIGNIN_IDENT_MAX = 4096;
|
|
77
|
+
const SIGNIN_BROWSER_MAX = 4096;
|
|
78
|
+
/**
|
|
79
|
+
* #3486: whether a chat fleet's admin may sign a new browser in with their own authenticator over a PUBLIC link too (the
|
|
80
|
+
* quick or named link). The one place that says so — the owner may veto it at acceptance: set this to `false` and a sign-in over
|
|
81
|
+
* a link is refused (404, as if the route were not there) while direct connections (LAN, tailnet, the owner's own proxy) keep
|
|
82
|
+
* working. A web-only fleet's link is another thing: only the outside link the owner opened with "Allow connections from outside".
|
|
83
|
+
*/
|
|
84
|
+
export const TOTP_SIGNIN_OVER_PUBLIC_LINK = true;
|
|
40
85
|
/** #3008 review (Prism P2 1): a state that could not be saved is written again this often until it is. */
|
|
41
86
|
export const OUTSIDE_SAVE_RETRY_MS = 30_000;
|
|
42
87
|
/** How long a secret being set up waits for its first code. */
|
|
@@ -129,6 +174,44 @@ export function otpauthUri(secretBase32, account) {
|
|
|
129
174
|
const label = encodeURIComponent(`AgEnD:${account}`);
|
|
130
175
|
return `otpauth://totp/${label}?secret=${secretBase32}&issuer=AgEnD&algorithm=SHA1&digits=${TOTP_DIGITS}&period=${TOTP_STEP_SECONDS}`;
|
|
131
176
|
}
|
|
177
|
+
const NO_LIM = Object.freeze({ wrong: 0, level: 0, pausedUntil: 0, at: 0, told: false });
|
|
178
|
+
const readLimWith = (v, limit) => {
|
|
179
|
+
const l = v;
|
|
180
|
+
if (!l || typeof l !== "object")
|
|
181
|
+
return undefined;
|
|
182
|
+
const n = (x) => (Number.isSafeInteger(x) && x >= 0 ? x : 0);
|
|
183
|
+
const lim = { wrong: Math.min(n(l.wrong), limit - 1), level: Math.min(n(l.level), 32), pausedUntil: n(l.pausedUntil), at: n(l.at), told: l.told === true };
|
|
184
|
+
return lim.wrong || lim.level || lim.pausedUntil ? lim : undefined;
|
|
185
|
+
};
|
|
186
|
+
/** A limiter as it reads now: the count forgotten after a quiet spell (`quietMs`), the level one step down per quiet day (after any wait ended). */
|
|
187
|
+
function settle(l, now, quietMs = SIGNIN_COUNT_QUIET_MS) {
|
|
188
|
+
const quiet = now - Math.max(l.at, l.pausedUntil);
|
|
189
|
+
if (quiet < quietMs)
|
|
190
|
+
return l;
|
|
191
|
+
return { ...l, wrong: 0, told: false, level: Math.max(0, l.level - Math.floor(quiet / SIGNIN_LEVEL_QUIET_MS)) };
|
|
192
|
+
}
|
|
193
|
+
/** One more wrong code in a limiter: its new state, the wait it started (0: none), and whether it just passed `halfAt` for the first time this cycle. */
|
|
194
|
+
function bumpLim(l, limit, baseMs, maxMs, now, quietMs = SIGNIN_COUNT_QUIET_MS, halfAt = Infinity) {
|
|
195
|
+
const s = settle(l, now, quietMs), wrong = s.wrong + 1, half = !s.told && wrong >= halfAt;
|
|
196
|
+
if (wrong < limit)
|
|
197
|
+
return { lim: { ...s, wrong, at: now, told: s.told || half }, wait: 0, half };
|
|
198
|
+
const wait = Math.min(baseMs * 2 ** s.level, maxMs);
|
|
199
|
+
return { lim: { wrong: 0, level: s.level + 1, pausedUntil: now + wait, at: now, told: s.told || half }, wait, half };
|
|
200
|
+
}
|
|
201
|
+
const limitsIdle = (l, now) => { const s = settle(l, now); return !s.wrong && !s.level && s.pausedUntil <= now; };
|
|
202
|
+
/** The host operator's key (a web-only fleet's one admin; also a chat fleet's host session). */
|
|
203
|
+
export const HOST_ADMIN_KEY = "host\u0000operator";
|
|
204
|
+
/** An admin's key: their connection and their account on it (ids are per platform). */
|
|
205
|
+
export const adminKey = (adapterId, userId) => `${adapterId}\u0000${userId}`;
|
|
206
|
+
/** At most this many admins have an authenticator (a chat fleet's admin lists are short). */
|
|
207
|
+
export const ADMIN_AUTHENTICATORS_MAX = 64;
|
|
208
|
+
const readRec = (t) => {
|
|
209
|
+
const r = t;
|
|
210
|
+
return r && typeof r.secret === "string" && (base32Decode(r.secret)?.length ?? 0) >= 16 && Number.isSafeInteger(r.enrolledAt)
|
|
211
|
+
&& Number.isSafeInteger(r.lastStep) ? { secret: r.secret, enrolledAt: r.enrolledAt, lastStep: r.lastStep, ...(r.strict === true ? { strict: true } : {}),
|
|
212
|
+
...(readLimWith(r.lim, SIGNIN_WRONG_LIMIT) ? { lim: readLimWith(r.lim, SIGNIN_WRONG_LIMIT) } : {}),
|
|
213
|
+
...(readLimWith(r.klim, SIGNIN_KNOWN_WRONG_LIMIT) ? { klim: readLimWith(r.klim, SIGNIN_KNOWN_WRONG_LIMIT) } : {}) } : undefined;
|
|
214
|
+
};
|
|
132
215
|
/** How many sessions from outside one generation remembers (each is a sign-in with a code; older ones read as revoked). */
|
|
133
216
|
export const OUTSIDE_HANDLES_MAX = 64;
|
|
134
217
|
const blank = () => ({ v: 1, outside: false, wrong: 0, level: 0, pausedUntil: 0, handles: [] });
|
|
@@ -138,11 +221,16 @@ export class WebRemoteAccess {
|
|
|
138
221
|
now;
|
|
139
222
|
monotonic;
|
|
140
223
|
state = blank();
|
|
141
|
-
|
|
224
|
+
/** Set-ups waiting for their first code, per session handle: one session's start never replaces another's. */
|
|
225
|
+
pending = new Map();
|
|
142
226
|
warned = false;
|
|
143
227
|
/** The state in memory is not on disk yet (a write failed): written again, by the next change or the retry timer. */
|
|
144
228
|
dirty = false;
|
|
145
229
|
retry = null;
|
|
230
|
+
/** #3486: the limiter of each browser (memory only; bounded). Key: the caller's hash of its cookie id and address. */
|
|
231
|
+
browserLim = new Map();
|
|
232
|
+
/** #3486: what a sign-in for an identifier that is no admin's is compared with — a secret nobody has, so the work done is the same. */
|
|
233
|
+
decoySecret = randomBytes(SECRET_BYTES);
|
|
146
234
|
constructor(path, log, now = Date.now, monotonic = () => performance.now()) {
|
|
147
235
|
this.path = path;
|
|
148
236
|
this.log = log;
|
|
@@ -161,11 +249,26 @@ export class WebRemoteAccess {
|
|
|
161
249
|
const v = JSON.parse(raw);
|
|
162
250
|
if (v.v !== 1)
|
|
163
251
|
throw new Error("shape");
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
|
|
252
|
+
const totp = readRec(v.totp);
|
|
253
|
+
const admins = {};
|
|
254
|
+
if (v.admins && typeof v.admins === "object" && !Array.isArray(v.admins)) {
|
|
255
|
+
for (const [k, r] of Object.entries(v.admins).slice(0, ADMIN_AUTHENTICATORS_MAX)) {
|
|
256
|
+
const rec = readRec(r);
|
|
257
|
+
if (rec && k.length <= 400)
|
|
258
|
+
admins[k] = rec;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
167
261
|
const count = (n) => (Number.isSafeInteger(n) && n >= 0 ? n : 0);
|
|
168
|
-
|
|
262
|
+
const signin = readLimWith(v.signin, SIGNIN_FLEET_WRONG_LIMIT);
|
|
263
|
+
const idents = {};
|
|
264
|
+
if (v.idents && typeof v.idents === "object" && !Array.isArray(v.idents)) {
|
|
265
|
+
for (const [k, l] of Object.entries(v.idents).slice(-SIGNIN_IDENT_MAX)) {
|
|
266
|
+
const lim = /^[0-9a-f]{64}$/.test(k) ? readLimWith(l, SIGNIN_WRONG_LIMIT) : undefined;
|
|
267
|
+
if (lim)
|
|
268
|
+
idents[k] = lim;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
this.state = { v: 1, ...(totp ? { totp } : {}), ...(Object.keys(admins).length ? { admins } : {}), ...(signin ? { signin } : {}), ...(Object.keys(idents).length ? { idents } : {}),
|
|
169
272
|
// Never on without an app set up: a file that says otherwise is read as off.
|
|
170
273
|
outside: v.outside === true && !!totp,
|
|
171
274
|
wrong: Math.min(count(v.wrong), TOTP_WRONG_LIMIT - 1), level: Math.min(count(v.level), 32),
|
|
@@ -179,19 +282,53 @@ export class WebRemoteAccess {
|
|
|
179
282
|
this.state = blank();
|
|
180
283
|
}
|
|
181
284
|
}
|
|
182
|
-
|
|
183
|
-
|
|
285
|
+
/** The keys (adminKey) of the chat admins that have an authenticator — never shown to anyone; the sign-in resolves a typed name among them. */
|
|
286
|
+
get adminKeys() { return Object.keys(this.state.admins ?? {}); }
|
|
287
|
+
/** One admin's record (the host operator's by default). */
|
|
288
|
+
rec(who) { return who === HOST_ADMIN_KEY ? this.state.totp : this.state.admins?.[who]; }
|
|
289
|
+
/** The state with `who`'s record set (undefined: removed). */
|
|
290
|
+
withRec(state, who, rec) {
|
|
291
|
+
if (who === HOST_ADMIN_KEY) {
|
|
292
|
+
const { totp: _old, ...rest } = state;
|
|
293
|
+
return { ...rest, ...(rec ? { totp: rec } : {}) };
|
|
294
|
+
}
|
|
295
|
+
const { admins: _old, ...rest } = state, admins = { ...(state.admins ?? {}) };
|
|
296
|
+
if (rec)
|
|
297
|
+
admins[who] = rec;
|
|
298
|
+
else
|
|
299
|
+
delete admins[who];
|
|
300
|
+
return { ...rest, ...(Object.keys(admins).length ? { admins } : {}) };
|
|
301
|
+
}
|
|
302
|
+
status(who = HOST_ADMIN_KEY) {
|
|
303
|
+
const r = this.rec(who);
|
|
304
|
+
return { enrolled: !!r, enrolledAt: r?.enrolledAt ?? null, outside: this.state.outside, strict: !!r?.strict,
|
|
184
305
|
pausedForMs: Math.max(0, this.state.pausedUntil - this.now()) };
|
|
185
306
|
}
|
|
186
307
|
get enrolled() { return !!this.state.totp; }
|
|
308
|
+
/** Whether `who` has an authenticator set up. */
|
|
309
|
+
isEnrolled(who) { return !!this.rec(who); }
|
|
310
|
+
/** `who`'s own "ask for my code to confirm from other devices" switch (never on without an app). */
|
|
311
|
+
strictOf(who) { return !!this.rec(who)?.strict; }
|
|
187
312
|
/**
|
|
188
313
|
* #3355 review (Prism P2): which app is set up — an opaque id of this enrollment (its secret and when it was set up), null
|
|
189
314
|
* when none. Replacing the app, or removing it and setting one up again, gives another id: what a code from the old one
|
|
190
315
|
* authorized can tell it no longer holds. Never the secret itself.
|
|
191
316
|
*/
|
|
192
|
-
get enrollment() {
|
|
193
|
-
|
|
194
|
-
|
|
317
|
+
get enrollment() { return this.enrollmentOf(HOST_ADMIN_KEY); }
|
|
318
|
+
enrollmentOf(who) {
|
|
319
|
+
const t = this.rec(who);
|
|
320
|
+
return t ? createHash("sha256").update(`agend-totp-enrollment\0${who}\0${t.secret}\0${t.enrolledAt}`).digest("hex").slice(0, 32) : null;
|
|
321
|
+
}
|
|
322
|
+
/** Turn `who`'s own switch on or off. On only with their app set up. "unsaved": in force in memory, not on disk yet. */
|
|
323
|
+
setStrict(who, on) {
|
|
324
|
+
const r = this.rec(who);
|
|
325
|
+
if (!r)
|
|
326
|
+
return "not_enrolled";
|
|
327
|
+
if (!!r.strict === on && !this.dirty)
|
|
328
|
+
return "ok";
|
|
329
|
+
const { strict: _s, ...rest } = r;
|
|
330
|
+
this.state = this.withRec(this.state, who, on ? { ...rest, strict: true } : rest);
|
|
331
|
+
return this.flush() ? "ok" : "unsaved";
|
|
195
332
|
}
|
|
196
333
|
/** The sessions authorized from outside since the last revocation (their receipts hold). */
|
|
197
334
|
get admitted() { return new Set(this.state.handles); }
|
|
@@ -221,47 +358,71 @@ export class WebRemoteAccess {
|
|
|
221
358
|
this.flush(); // still owed: keep trying (re-arms the timer)
|
|
222
359
|
}
|
|
223
360
|
get outside() { return this.state.outside && !!this.state.totp; }
|
|
361
|
+
/** Whether `who` can have a record: they already do, or there is room (the host operator's is always allowed). */
|
|
362
|
+
hasRoom(who) {
|
|
363
|
+
return who === HOST_ADMIN_KEY || !!this.state.admins?.[who] || Object.keys(this.state.admins ?? {}).length < ADMIN_AUTHENTICATORS_MAX;
|
|
364
|
+
}
|
|
365
|
+
/** Void the set-up the session `handle` began: its secret can never be finished (a fresh begin is the only way on). */
|
|
366
|
+
cancelEnrollment(handle) { this.pending.delete(handle); }
|
|
224
367
|
/**
|
|
225
|
-
* A new secret for the session `handle` to set up (it replaces nothing until confirmEnrollment). Returned once:
|
|
226
|
-
* caller shows it to that session and forgets it.
|
|
368
|
+
* A new secret for the session `handle` to set up, as `who` (it replaces nothing until confirmEnrollment). Returned once:
|
|
369
|
+
* the caller shows it to that session and forgets it.
|
|
227
370
|
*/
|
|
228
|
-
beginEnrollment(handle, account) {
|
|
371
|
+
beginEnrollment(handle, account, who = HOST_ADMIN_KEY) {
|
|
229
372
|
const secret = base32Encode(randomBytes(SECRET_BYTES));
|
|
230
|
-
this.pending
|
|
373
|
+
this.pending.delete(handle);
|
|
374
|
+
this.pending.set(handle, { secret, who, until: this.monotonic() + TOTP_ENROLL_TTL_MS });
|
|
375
|
+
for (const [h, p] of this.pending)
|
|
376
|
+
if (this.monotonic() > p.until)
|
|
377
|
+
this.pending.delete(h);
|
|
378
|
+
while (this.pending.size > 32)
|
|
379
|
+
this.pending.delete(this.pending.keys().next().value);
|
|
231
380
|
return { secret, uri: otpauthUri(secret, account), expiresInMs: TOTP_ENROLL_TTL_MS };
|
|
232
381
|
}
|
|
233
382
|
/**
|
|
234
|
-
* The first code from the app being set up, by the session that began it. "ok": it is now
|
|
235
|
-
* replaced
|
|
383
|
+
* The first code from the app being set up, by the session that began it. "ok": it is now `who`'s (a previous one is
|
|
384
|
+
* replaced, their switch kept). The host operator's also ends what was authorized from outside, and starts the limiter
|
|
385
|
+
* afresh only when made on the AgEnD computer itself (`physicalHost`); another admin's does neither — enrolling must not be a way
|
|
386
|
+
* to reset the fleet-wide wrong-code limit. "full": no room for another admin's record (a record is never accepted that a restart
|
|
387
|
+
* would drop).
|
|
236
388
|
*/
|
|
237
|
-
confirmEnrollment(handle, code) {
|
|
238
|
-
const p = this.pending;
|
|
239
|
-
if (!p ||
|
|
240
|
-
|
|
241
|
-
this.pending = null;
|
|
389
|
+
confirmEnrollment(handle, code, opts = {}) {
|
|
390
|
+
const p = this.pending.get(handle);
|
|
391
|
+
if (!p || this.monotonic() > p.until) {
|
|
392
|
+
this.pending.delete(handle);
|
|
242
393
|
return "expired";
|
|
243
394
|
}
|
|
395
|
+
// Capacity is enforced before a new record is acknowledged: one that would not survive a restart is never accepted.
|
|
396
|
+
if (!this.hasRoom(p.who))
|
|
397
|
+
return "full";
|
|
244
398
|
const step = matchTotp(base32Decode(p.secret), code, this.now(), -1);
|
|
245
399
|
if (step === null)
|
|
246
400
|
return "wrong";
|
|
247
|
-
const before = this.state, wasDirty = this.dirty;
|
|
248
|
-
|
|
249
|
-
|
|
401
|
+
const before = this.state, wasDirty = this.dirty, old = this.rec(p.who);
|
|
402
|
+
const rec = { secret: p.secret, enrolledAt: this.now(), lastStep: step, ...(old?.strict ? { strict: true } : {}) };
|
|
403
|
+
// A new host app replaces the old one: what was authorized under it ends (the admitted sessions are forgotten). The fleet-wide
|
|
404
|
+
// wrong-code pause is reset only by an enrolment made on the AgEnD computer itself (`physicalHost`, the caller's proof of where
|
|
405
|
+
// it came from): the host operator's identity used remotely — a host cookie on another device — never clears it.
|
|
406
|
+
const reset = p.who === HOST_ADMIN_KEY && opts.physicalHost === true;
|
|
407
|
+
this.state = p.who === HOST_ADMIN_KEY ? { ...this.withRec(this.state, p.who, rec), ...(reset ? { wrong: 0, level: 0, pausedUntil: 0 } : {}), handles: [] } : this.withRec(this.state, p.who, rec);
|
|
250
408
|
if (!this.flush()) {
|
|
251
409
|
// Not set up: the state before stands — and if it was itself still owed to the disk (an unsaved Off), it still is.
|
|
252
410
|
this.restore(before, wasDirty);
|
|
253
411
|
return "unsaved";
|
|
254
412
|
}
|
|
255
|
-
this.pending
|
|
413
|
+
this.pending.delete(handle);
|
|
256
414
|
return "ok";
|
|
257
415
|
}
|
|
258
416
|
/**
|
|
259
|
-
* Forget
|
|
260
|
-
*
|
|
417
|
+
* Forget `who`'s app (their switch with it); the host operator's also turns the outside switch off and ends what was
|
|
418
|
+
* authorized from outside. Nothing set up: nothing happens — in particular a set-up still waiting for its first code is left
|
|
419
|
+
* alone (a recovery begun on the host must not be cleared by someone else's Remove). In force in memory at once; false: not
|
|
420
|
+
* saved yet (retried — a restart before that would read the old file).
|
|
261
421
|
*/
|
|
262
|
-
remove() {
|
|
263
|
-
this.
|
|
264
|
-
|
|
422
|
+
remove(who = HOST_ADMIN_KEY) {
|
|
423
|
+
if (!this.rec(who))
|
|
424
|
+
return true;
|
|
425
|
+
this.state = who === HOST_ADMIN_KEY ? { ...blank(), ...(this.state.admins ? { admins: this.state.admins } : {}), ...(this.state.signin ? { signin: this.state.signin } : {}), ...(this.state.idents ? { idents: this.state.idents } : {}) } : this.withRec(this.state, who, undefined);
|
|
265
426
|
return this.flush();
|
|
266
427
|
}
|
|
267
428
|
/**
|
|
@@ -278,8 +439,8 @@ export class WebRemoteAccess {
|
|
|
278
439
|
return this.flush() ? "ok" : "unsaved";
|
|
279
440
|
}
|
|
280
441
|
/** A code typed at sign-in from outside. Each step is accepted once; wrong codes count toward a wait. */
|
|
281
|
-
verify(code) {
|
|
282
|
-
const t = this.
|
|
442
|
+
verify(code, who = HOST_ADMIN_KEY) {
|
|
443
|
+
const t = this.rec(who);
|
|
283
444
|
if (!t)
|
|
284
445
|
return { kind: "not_enrolled" };
|
|
285
446
|
const now = this.now();
|
|
@@ -288,9 +449,9 @@ export class WebRemoteAccess {
|
|
|
288
449
|
const step = matchTotp(base32Decode(t.secret), code, now, t.lastStep);
|
|
289
450
|
if (step !== null) {
|
|
290
451
|
const before = this.state;
|
|
291
|
-
this.state = { ...this.state,
|
|
452
|
+
this.state = { ...this.withRec(this.state, who, { ...t, lastStep: step }), wrong: 0, level: 0, pausedUntil: 0 };
|
|
292
453
|
if (!this.flush()) {
|
|
293
|
-
this.state =
|
|
454
|
+
this.state = this.withRec(before, who, { ...t, lastStep: step });
|
|
294
455
|
return { kind: "unavailable" };
|
|
295
456
|
}
|
|
296
457
|
return { kind: "ok" };
|
|
@@ -307,6 +468,78 @@ export class WebRemoteAccess {
|
|
|
307
468
|
this.flush();
|
|
308
469
|
return { kind: "wrong", paused: true, retryAfterMs: wait, wrong: TOTP_WRONG_LIMIT, skewSteps };
|
|
309
470
|
}
|
|
471
|
+
/**
|
|
472
|
+
* #3486: a new browser signs in with an admin's OWN authenticator code. `who`: the admin the typed name resolved to (null: it
|
|
473
|
+
* resolved to nobody — no such name, an admin with no app, one no longer an admin: the caller does not say which); `ident`: the
|
|
474
|
+
* normalized text typed, whatever it is; `browser`: this browser's key, and whether it carries a valid "known device" mark for `who`.
|
|
475
|
+
* A code is compared with that admin's secret when there is one and with a decoy secret when there is not — the same work — and
|
|
476
|
+
* every failed attempt changes and saves the same counters, so neither the answer nor the time says whether a name is an admin who
|
|
477
|
+
* has an app. What can pause an attempt: this browser's own limiter, the typed name's, the whole sign-in's (all three answer
|
|
478
|
+
* identically for every name). The admin's own limiter is a ceiling that never changes an answer: while it is in force a
|
|
479
|
+
* code is not tried and is answered as any wrong one (so using two names of one admin shows nothing either). A known device is
|
|
480
|
+
* not held by the shared ceilings, only by its mark's own limiter and the known-path limiter of its admin (so shedding cookies resets nothing).
|
|
481
|
+
* `browser.key` is the cookie-derived key, or — when `known` — the key of the mark itself.
|
|
482
|
+
* - one use per time step: the same `lastStep` as the admin's confirmations and switch;
|
|
483
|
+
* - success clears that admin's own count, that name's and this browser's — never the whole sign-in's, which only time lowers.
|
|
484
|
+
*/
|
|
485
|
+
signIn(who, ident, code, browser) {
|
|
486
|
+
const now = this.now(), rec = who ? this.rec(who) : undefined, known = browser.known && !!rec;
|
|
487
|
+
const identKey = createHash("sha256").update(`agend-signin-ident\0${ident}`).digest("hex");
|
|
488
|
+
const fleet = settle(this.state.signin ?? NO_LIM, now), byIdent = settle(this.state.idents?.[identKey] ?? NO_LIM, now);
|
|
489
|
+
const byAdmin = settle(rec?.lim ?? NO_LIM, now), byBrowser = settle(this.browserLim.get(browser.key) ?? NO_LIM, now, SIGNIN_BROWSER_QUIET_MS);
|
|
490
|
+
const byKnown = settle(rec?.klim ?? NO_LIM, now);
|
|
491
|
+
// A known device is held by its own mark's limiter and by the known-path limiter of its admin (every attempt carrying one of X's marks counts there), not by the shared ones.
|
|
492
|
+
const waits = [byBrowser.pausedUntil, ...(known ? [byKnown.pausedUntil] : [fleet.pausedUntil, byIdent.pausedUntil])].map(p => Math.min(p - now, TOTP_PAUSE_MAX_MS));
|
|
493
|
+
const wait = Math.max(...waits);
|
|
494
|
+
const idle = { fleet: false, admin: false, waitMs: 0, halfFleet: false, halfAdmin: false };
|
|
495
|
+
if (wait > 0)
|
|
496
|
+
return { kind: "paused", retryAfterMs: wait, began: idle };
|
|
497
|
+
const secret = rec ? base32Decode(rec.secret) : this.decoySecret;
|
|
498
|
+
const step = matchTotp(secret, code, now, rec ? rec.lastStep : -1);
|
|
499
|
+
const held = !known && byAdmin.pausedUntil > now; // the admin's ceiling: the code is not tried
|
|
500
|
+
if (rec && who && step !== null && !held) {
|
|
501
|
+
const before = this.state, beforeBrowser = this.browserLim.get(browser.key);
|
|
502
|
+
const { lim: _lim, klim: _klim, ...clean } = rec;
|
|
503
|
+
const idents = { ...(this.state.idents ?? {}) };
|
|
504
|
+
delete idents[identKey];
|
|
505
|
+
const { idents: _idents, ...rest } = this.withRec(this.state, who, { ...clean, lastStep: step });
|
|
506
|
+
this.state = { ...rest, ...(Object.keys(idents).length ? { idents } : {}) };
|
|
507
|
+
this.browserLim.delete(browser.key);
|
|
508
|
+
if (!this.flush()) {
|
|
509
|
+
this.state = { ...this.withRec(before, who, { ...clean, lastStep: step }), ...(before.signin ? { signin: before.signin } : {}), ...(before.idents ? { idents: before.idents } : {}) };
|
|
510
|
+
if (beforeBrowser)
|
|
511
|
+
this.browserLim.set(browser.key, beforeBrowser);
|
|
512
|
+
return { kind: "unavailable" };
|
|
513
|
+
}
|
|
514
|
+
return { kind: "ok" };
|
|
515
|
+
}
|
|
516
|
+
// Wrong, or no such admin, or the admin's ceiling: the same counters, the same write — and the same clock-skew look (the decoy when there is no admin).
|
|
517
|
+
const skew = totpSkew(secret, code, now);
|
|
518
|
+
const f = bumpLim(fleet, SIGNIN_FLEET_WRONG_LIMIT, TOTP_PAUSE_MS, TOTP_PAUSE_MAX_MS, now, SIGNIN_COUNT_QUIET_MS, SIGNIN_FLEET_WRONG_LIMIT / 2);
|
|
519
|
+
const i = bumpLim(byIdent, SIGNIN_WRONG_LIMIT, TOTP_PAUSE_MS, TOTP_PAUSE_MAX_MS, now);
|
|
520
|
+
const a = rec ? bumpLim(byAdmin, SIGNIN_WRONG_LIMIT, TOTP_PAUSE_MS, TOTP_PAUSE_MAX_MS, now, SIGNIN_COUNT_QUIET_MS, SIGNIN_WRONG_LIMIT / 2) : { lim: NO_LIM, wait: 0, half: false };
|
|
521
|
+
const k = known ? bumpLim(byKnown, SIGNIN_KNOWN_WRONG_LIMIT, TOTP_PAUSE_MS, TOTP_PAUSE_MAX_MS, now, SIGNIN_COUNT_QUIET_MS, SIGNIN_KNOWN_WRONG_LIMIT / 2) : { lim: byKnown, wait: 0, half: false };
|
|
522
|
+
const w = bumpLim(byBrowser, SIGNIN_BROWSER_WRONG_LIMIT, SIGNIN_BROWSER_PAUSE_MS, SIGNIN_BROWSER_PAUSE_MAX_MS, now, SIGNIN_BROWSER_QUIET_MS);
|
|
523
|
+
this.browserLim.delete(browser.key);
|
|
524
|
+
this.browserLim.set(browser.key, w.lim);
|
|
525
|
+
while (this.browserLim.size > SIGNIN_BROWSER_MAX)
|
|
526
|
+
this.browserLim.delete(this.browserLim.keys().next().value);
|
|
527
|
+
const idents = {};
|
|
528
|
+
for (const [k, l] of Object.entries(this.state.idents ?? {}))
|
|
529
|
+
if (k !== identKey && !limitsIdle(l, now))
|
|
530
|
+
idents[k] = l;
|
|
531
|
+
idents[identKey] = i.lim;
|
|
532
|
+
for (const k of Object.keys(idents).slice(0, Math.max(0, Object.keys(idents).length - SIGNIN_IDENT_MAX)))
|
|
533
|
+
delete idents[k];
|
|
534
|
+
const { idents: _old, ...base } = rec && who ? this.withRec(this.state, who, { ...rec, lim: a.lim, ...(known ? { klim: k.lim } : {}) }) : this.state;
|
|
535
|
+
this.state = { ...base, signin: f.lim, idents };
|
|
536
|
+
this.flush();
|
|
537
|
+
const began = { fleet: f.wait > 0, admin: !!rec && (a.wait > 0 || i.wait > 0 || k.wait > 0), waitMs: Math.max(f.wait, i.wait, a.wait, k.wait),
|
|
538
|
+
halfFleet: f.half, halfAdmin: !!rec && (a.half || k.half) };
|
|
539
|
+
// Answered by what every name shares: this browser's wait, the name's, the whole sign-in's (a known device: its mark's and its admin's known-path wait).
|
|
540
|
+
const started = Math.max(w.wait, ...(known ? [k.wait] : [f.wait, i.wait]));
|
|
541
|
+
return started > 0 ? { kind: "paused", retryAfterMs: started, began } : { kind: "wrong", ...(rec && skew !== null ? { skewSteps: skew } : {}), began };
|
|
542
|
+
}
|
|
310
543
|
/**
|
|
311
544
|
* Saved: true. Not saved: false (warned once until it works again) — memory keeps the new state, and it is written
|
|
312
545
|
* again by the next change or every OUTSIDE_SAVE_RETRY_MS until it is (#3008 review, Prism P2 1).
|