gestalt-mobile 0.75.3 → 0.75.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -402,6 +402,22 @@ two local relay processes behind `https://relay.example.org`), but an RP-ID/
|
|
|
402
402
|
hostname change is refused once credentials exist because it would strand those
|
|
403
403
|
credentials. Do not expose `--host 0.0.0.0` before that boundary is in place.
|
|
404
404
|
|
|
405
|
+
### Move to a different hostname
|
|
406
|
+
|
|
407
|
+
Stop every Gestalt Mobile relay using the same account. Run the reset on the
|
|
408
|
+
machine hosting Mobile with the new public origin.
|
|
409
|
+
|
|
410
|
+
```sh
|
|
411
|
+
gestalt-mobile reset-passkeys --public-origin https://new-relay.example.org --confirm
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
With the Gestalt manager, use `npx gestalt mobile reset-passkeys` with the same
|
|
415
|
+
arguments. The reset revokes all passkeys and browser sessions for the old
|
|
416
|
+
hostname across the account's relays. Saved Codex sessions and workspaces
|
|
417
|
+
remain available. Start Mobile with the same workspace and state options and
|
|
418
|
+
the new `--public-origin`. Enroll the first device before making the relay
|
|
419
|
+
reachable over the network.
|
|
420
|
+
|
|
405
421
|
An empty authorization store is deliberately bootstrap-open: the first verified passkey becomes the owner. Register a device before exposing the service. The
|
|
406
422
|
final authorized device cannot be deleted; synced passkeys can represent more
|
|
407
423
|
than one physical device, and an enrollment QR/link is neither recovery nor
|
|
@@ -12,7 +12,8 @@ import { dirname, resolve } from 'node:path';
|
|
|
12
12
|
import { fileURLToPath } from 'node:url';
|
|
13
13
|
import { promisify } from 'node:util';
|
|
14
14
|
import { composeRelayApp } from './composition.js';
|
|
15
|
-
import { CliUsageError, parseConfig } from './config.js';
|
|
15
|
+
import { CliUsageError, createRelyingPartyConfig, parseConfig, } from './config.js';
|
|
16
|
+
import { AuthorizationHostnameMismatchError, checkAuthorizationHostname, resetAuthorizationHostname, } from './platform/auth/sqlite-authorization-store.js';
|
|
16
17
|
import { LauncherProfileCatalog } from './platform/catalog/launcher-profile-catalog.js';
|
|
17
18
|
import { FilesystemSkillProfileStore } from './platform/skills/filesystem-skill-profile-store.js';
|
|
18
19
|
import { loadPwaIcon } from './platform/pwa/load-pwa-icon.js';
|
|
@@ -21,6 +22,7 @@ import { relayStatePath } from './platform/persistence/state-path.js';
|
|
|
21
22
|
const runFile = promisify(execFile);
|
|
22
23
|
export const usage = `Usage: gestalt-mobile [options]
|
|
23
24
|
gestalt-mobile trace <session-id> [--json] [--cwd <path>] [--data-dir <path>]
|
|
25
|
+
gestalt-mobile reset-passkeys --public-origin <origin> --confirm
|
|
24
26
|
|
|
25
27
|
Options:
|
|
26
28
|
--cwd <path> Workspace root (default: current directory)
|
|
@@ -144,6 +146,18 @@ export function installShutdownHandlers(app, signalSource = process) {
|
|
|
144
146
|
return shutdown;
|
|
145
147
|
}
|
|
146
148
|
function parseInvocation(args, cwd) {
|
|
149
|
+
if (args[0] === 'reset-passkeys') {
|
|
150
|
+
const options = args.slice(1);
|
|
151
|
+
const originIndex = options.indexOf('--public-origin');
|
|
152
|
+
const origin = options[originIndex + 1];
|
|
153
|
+
if (options.length !== 3 ||
|
|
154
|
+
originIndex < 0 ||
|
|
155
|
+
!origin ||
|
|
156
|
+
origin.startsWith('--') ||
|
|
157
|
+
!options.includes('--confirm'))
|
|
158
|
+
throw new CliUsageError('Passkey reset requires --public-origin <origin> and --confirm');
|
|
159
|
+
return { command: 'reset-passkeys', rpId: createRelyingPartyConfig(origin).rpId };
|
|
160
|
+
}
|
|
147
161
|
if (args[0] === 'trace') {
|
|
148
162
|
const sessionId = args[1];
|
|
149
163
|
if (!sessionId || sessionId.startsWith('--'))
|
|
@@ -209,12 +223,28 @@ async function listSkillProfiles(store, stdout, stderr) {
|
|
|
209
223
|
}
|
|
210
224
|
return failed ? 1 : 0;
|
|
211
225
|
}
|
|
226
|
+
function reportHostnameMismatch(error, publicOrigin, launcher, stderr) {
|
|
227
|
+
if (!(error instanceof AuthorizationHostnameMismatchError))
|
|
228
|
+
throw error;
|
|
229
|
+
// A WHATWG URL can accept characters with special meaning in a shell.
|
|
230
|
+
const originArgument = /^https?:\/\/[a-z\d.-]+(?::\d+)?$/i.test(publicOrigin)
|
|
231
|
+
? publicOrigin
|
|
232
|
+
: '"<new-origin>"';
|
|
233
|
+
stderr.write(`${error.message}. Stop every Gestalt Mobile relay on this account.\n` +
|
|
234
|
+
'Run the local reset command to revoke existing passkeys and browser sessions and enroll a new first device.\n' +
|
|
235
|
+
` ${launcher} reset-passkeys --public-origin ${originArgument} --confirm\n`);
|
|
236
|
+
return 1;
|
|
237
|
+
}
|
|
212
238
|
export async function runCli(dependencies = {}) {
|
|
213
239
|
const args = dependencies.args ?? process.argv.slice(2);
|
|
214
240
|
const cwd = dependencies.cwd ?? process.cwd();
|
|
215
241
|
const moduleUrl = dependencies.moduleUrl ?? import.meta.url;
|
|
216
242
|
const stdout = dependencies.stdout ?? process.stdout;
|
|
217
243
|
const stderr = dependencies.stderr ?? process.stderr;
|
|
244
|
+
const home = dependencies.homeDirectory ?? homedir();
|
|
245
|
+
const launcher = (dependencies.environment ?? process.env).GESTALT_MANAGER_VERSION
|
|
246
|
+
? 'npx gestalt mobile'
|
|
247
|
+
: 'gestalt-mobile';
|
|
218
248
|
let invocation;
|
|
219
249
|
try {
|
|
220
250
|
invocation = parseInvocation(args, cwd);
|
|
@@ -233,6 +263,22 @@ export async function runCli(dependencies = {}) {
|
|
|
233
263
|
stdout.write(`${await packageVersion(moduleUrl)}\n`);
|
|
234
264
|
return 0;
|
|
235
265
|
}
|
|
266
|
+
if (invocation.command === 'reset-passkeys') {
|
|
267
|
+
try {
|
|
268
|
+
const result = resetAuthorizationHostname(home, invocation.rpId);
|
|
269
|
+
if (result === 'reset')
|
|
270
|
+
stdout.write('Passkeys and browser sessions cleared. Start Mobile with the new origin and enroll your first device.\n');
|
|
271
|
+
else if (result === 'alreadyConfigured')
|
|
272
|
+
stdout.write('The passkey hostname already matches the requested origin.\n');
|
|
273
|
+
else
|
|
274
|
+
stdout.write('There is no passkey hostname to reset. Start Mobile with the requested origin.\n');
|
|
275
|
+
return 0;
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
stderr.write(`Unable to reset passkeys: ${error instanceof Error ? error.message : 'unknown error'}\n`);
|
|
279
|
+
return 1;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
236
282
|
if (invocation.command === 'trace') {
|
|
237
283
|
const stateHome = dependencies.environment?.XDG_STATE_HOME ??
|
|
238
284
|
process.env.XDG_STATE_HOME ??
|
|
@@ -250,10 +296,18 @@ export async function runCli(dependencies = {}) {
|
|
|
250
296
|
return 1;
|
|
251
297
|
}
|
|
252
298
|
}
|
|
253
|
-
const skillProfiles = new FilesystemSkillProfileStore(
|
|
299
|
+
const skillProfiles = new FilesystemSkillProfileStore(home);
|
|
254
300
|
if (invocation.command === 'list')
|
|
255
301
|
return listSkillProfiles(skillProfiles, stdout, stderr);
|
|
256
302
|
const config = invocation.config;
|
|
303
|
+
if (config.passkeyAuthEnabled) {
|
|
304
|
+
try {
|
|
305
|
+
checkAuthorizationHostname(home, config.relyingParty.rpId);
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
return reportHostnameMismatch(error, config.relyingParty.publicOrigin, launcher, stderr);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
257
311
|
if (!config.passkeyAuthEnabled)
|
|
258
312
|
stderr.write('WARNING: Passkey access control is disabled; anyone who can reach this server has full access.\n');
|
|
259
313
|
let explicitSkillProfile;
|
|
@@ -297,7 +351,12 @@ export async function runCli(dependencies = {}) {
|
|
|
297
351
|
homeDirectory: dependencies.homeDirectory,
|
|
298
352
|
explicitSkillProfile,
|
|
299
353
|
planMeasurementBaseUrl: `http://${config.host}:${config.port}`,
|
|
354
|
+
}).catch((error) => {
|
|
355
|
+
reportHostnameMismatch(error, config.relyingParty.publicOrigin, launcher, stderr);
|
|
356
|
+
return null;
|
|
300
357
|
});
|
|
358
|
+
if (!app)
|
|
359
|
+
return 1;
|
|
301
360
|
installShutdownHandlers(app, dependencies.signalSource);
|
|
302
361
|
let address;
|
|
303
362
|
try {
|
|
@@ -3,8 +3,60 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
7
|
+
if (value !== null && value !== void 0) {
|
|
8
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
9
|
+
var dispose, inner;
|
|
10
|
+
if (async) {
|
|
11
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
12
|
+
dispose = value[Symbol.asyncDispose];
|
|
13
|
+
}
|
|
14
|
+
if (dispose === void 0) {
|
|
15
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
16
|
+
dispose = value[Symbol.dispose];
|
|
17
|
+
if (async) inner = dispose;
|
|
18
|
+
}
|
|
19
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
20
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
21
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
22
|
+
}
|
|
23
|
+
else if (async) {
|
|
24
|
+
env.stack.push({ async: true });
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
};
|
|
28
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
29
|
+
return function (env) {
|
|
30
|
+
function fail(e) {
|
|
31
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
32
|
+
env.hasError = true;
|
|
33
|
+
}
|
|
34
|
+
var r, s = 0;
|
|
35
|
+
function next() {
|
|
36
|
+
while (r = env.stack.pop()) {
|
|
37
|
+
try {
|
|
38
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
39
|
+
if (r.dispose) {
|
|
40
|
+
var result = r.dispose.call(r.value);
|
|
41
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
42
|
+
}
|
|
43
|
+
else s |= 1;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
fail(e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
50
|
+
if (env.hasError) throw env.error;
|
|
51
|
+
}
|
|
52
|
+
return next();
|
|
53
|
+
};
|
|
54
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
55
|
+
var e = new Error(message);
|
|
56
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
57
|
+
});
|
|
58
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
59
|
+
import { mkdirSync, chmodSync, statSync } from 'node:fs';
|
|
8
60
|
import { dirname, join, resolve } from 'node:path';
|
|
9
61
|
import { DatabaseSync } from 'node:sqlite';
|
|
10
62
|
import { authorizedDeviceId, localOwnerId, passkeyCeremonyId, webAuthnCredentialId, } from '../../features/auth/domain/identifiers.js';
|
|
@@ -21,6 +73,75 @@ const startupLockWaiter = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_
|
|
|
21
73
|
export function authorizationDatabasePath(homeDirectory) {
|
|
22
74
|
return join(resolve(homeDirectory), '.codex-gestalt', 'gestalt-mobile', 'auth.sqlite');
|
|
23
75
|
}
|
|
76
|
+
export class AuthorizationHostnameMismatchError extends Error {
|
|
77
|
+
constructor() {
|
|
78
|
+
super('WebAuthn RP ID hostname changed while credentials exist');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function storedRpId(db) {
|
|
82
|
+
if (!db.prepare("SELECT 1 FROM sqlite_schema WHERE type = 'table' AND name = 'auth_settings'").get())
|
|
83
|
+
return undefined;
|
|
84
|
+
const settings = db.prepare('SELECT rp_id FROM auth_settings WHERE singleton = 1').get();
|
|
85
|
+
return settings?.rp_id;
|
|
86
|
+
}
|
|
87
|
+
export function checkAuthorizationHostname(homeDirectory, rpId) {
|
|
88
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
89
|
+
try {
|
|
90
|
+
const path = authorizationDatabasePath(homeDirectory);
|
|
91
|
+
if (!statSync(path, { throwIfNoEntry: false }))
|
|
92
|
+
return;
|
|
93
|
+
const db = __addDisposableResource(env_1, new DatabaseSync(path, { readOnly: true, timeout: SQLITE_STARTUP_BUSY_TIMEOUT_MS }), false);
|
|
94
|
+
db.exec('BEGIN');
|
|
95
|
+
const stored = storedRpId(db);
|
|
96
|
+
if (stored !== undefined &&
|
|
97
|
+
stored !== rpId &&
|
|
98
|
+
db.prepare('SELECT 1 FROM auth_devices LIMIT 1').get())
|
|
99
|
+
throw new AuthorizationHostnameMismatchError();
|
|
100
|
+
}
|
|
101
|
+
catch (e_1) {
|
|
102
|
+
env_1.error = e_1;
|
|
103
|
+
env_1.hasError = true;
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
__disposeResources(env_1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function resetAuthorizationHostname(homeDirectory, rpId) {
|
|
110
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
111
|
+
try {
|
|
112
|
+
const path = authorizationDatabasePath(homeDirectory);
|
|
113
|
+
if (!statSync(path, { throwIfNoEntry: false }))
|
|
114
|
+
return 'uninitialized';
|
|
115
|
+
const db = __addDisposableResource(env_2, new DatabaseSync(path, { timeout: SQLITE_STARTUP_BUSY_TIMEOUT_MS }), false);
|
|
116
|
+
// An exclusive WAL connection cannot acquire its lock while another relay
|
|
117
|
+
// has the shared auth database open. Keep the lock until the reset commits.
|
|
118
|
+
db.exec('PRAGMA locking_mode = EXCLUSIVE;');
|
|
119
|
+
try {
|
|
120
|
+
return withImmediateTransaction(db, () => {
|
|
121
|
+
const stored = storedRpId(db);
|
|
122
|
+
if (stored === undefined)
|
|
123
|
+
return 'uninitialized';
|
|
124
|
+
if (stored === rpId)
|
|
125
|
+
return 'alreadyConfigured';
|
|
126
|
+
db.exec('DELETE FROM auth_sessions; DELETE FROM auth_tickets; DELETE FROM auth_ceremonies; DELETE FROM auth_devices;');
|
|
127
|
+
db.prepare('UPDATE auth_settings SET rp_id = ?, user_handle = ? WHERE singleton = 1').run(rpId, randomBytes(32));
|
|
128
|
+
return 'reset';
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
if (isLocked(error))
|
|
133
|
+
throw new Error('Stop every Gestalt Mobile relay using this authorization database, then retry.');
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (e_2) {
|
|
138
|
+
env_2.error = e_2;
|
|
139
|
+
env_2.hasError = true;
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
__disposeResources(env_2);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
24
145
|
/** SQLite adapter for the auth bounded context. No SQLite types escape this file. */
|
|
25
146
|
export class SqliteAuthorizationStore {
|
|
26
147
|
path;
|
|
@@ -86,7 +207,7 @@ CREATE TABLE IF NOT EXISTS auth_sessions (token_hash TEXT PRIMARY KEY, device_id
|
|
|
86
207
|
.prepare('SELECT rp_id FROM auth_settings WHERE singleton = 1')
|
|
87
208
|
.get();
|
|
88
209
|
if (settings && settings.rp_id !== this.relyingParty.rpId && this.deviceCount() > 0)
|
|
89
|
-
throw new
|
|
210
|
+
throw new AuthorizationHostnameMismatchError();
|
|
90
211
|
});
|
|
91
212
|
}
|
|
92
213
|
initializeOwner(userHandle) {
|
|
@@ -101,7 +222,7 @@ CREATE TABLE IF NOT EXISTS auth_sessions (token_hash TEXT PRIMARY KEY, device_id
|
|
|
101
222
|
.prepare('INSERT INTO auth_settings (singleton, schema_version, rp_id, user_handle) VALUES (1, ?, ?, ?)')
|
|
102
223
|
.run(SCHEMA_VERSION, this.relyingParty.rpId, userHandle);
|
|
103
224
|
else if (current.rp_id !== this.relyingParty.rpId && this.deviceCount() > 0)
|
|
104
|
-
throw new
|
|
225
|
+
throw new AuthorizationHostnameMismatchError();
|
|
105
226
|
else if (current.rp_id !== this.relyingParty.rpId)
|
|
106
227
|
this.statements
|
|
107
228
|
.prepare('UPDATE auth_settings SET rp_id = ? WHERE singleton = 1')
|