@agent-relay/core-bridge 17.2.1 → 18.0.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/dist/auth.d.ts +147 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +385 -0
- package/dist/auth.js.map +1 -0
- package/dist/client.d.ts +88 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +338 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +107 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +142 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +25 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +42 -0
- package/dist/paths.js.map +1 -0
- package/dist/spawn.d.ts +160 -0
- package/dist/spawn.d.ts.map +1 -0
- package/dist/spawn.js +232 -0
- package/dist/spawn.js.map +1 -0
- package/dist/trust.d.ts +20 -0
- package/dist/trust.d.ts.map +1 -0
- package/dist/trust.js +40 -0
- package/dist/trust.js.map +1 -0
- package/package.json +1 -1
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import type { CallOptions, CoreClient } from './client.js';
|
|
3
|
+
/** The transcript version byte, which is also the challenge `version`. */
|
|
4
|
+
export declare const CALLER_TRANSCRIPT_VERSION = 1;
|
|
5
|
+
/** The transcript's domain separation string. */
|
|
6
|
+
export declare const CALLER_TRANSCRIPT_DOMAIN = "agent-relay/service-caller/v1";
|
|
7
|
+
/** How long a challenge stays valid after it was issued, in milliseconds. */
|
|
8
|
+
export declare const CALLER_CHALLENGE_TTL_MS = 30000;
|
|
9
|
+
/** The `caller.json` `auth` value naming this transcript. */
|
|
10
|
+
export declare const CALLER_AUTH_SCHEME = "challenge-hmac-sha256/v1";
|
|
11
|
+
/** The `caller.json` schemas this reader accepts. */
|
|
12
|
+
export declare const CALLER_FILE_SCHEMAS: readonly ["agent-relay-service-caller/1", "agent-relay-service-caller/2"];
|
|
13
|
+
/** The largest `caller.json` this reader opens, in bytes. */
|
|
14
|
+
export declare const MAX_CALLER_FILE_BYTES: number;
|
|
15
|
+
/** The params of `spawn_callers.challenge`. */
|
|
16
|
+
export type CallerChallengeParams = {
|
|
17
|
+
/** The caller's registry id: `sc_` and 16 lowercase hex characters. */
|
|
18
|
+
caller_id: string;
|
|
19
|
+
};
|
|
20
|
+
/** The result of `spawn_callers.challenge`. */
|
|
21
|
+
export interface CallerChallenge {
|
|
22
|
+
/** Exactly 1: the transcript version byte. */
|
|
23
|
+
version: number;
|
|
24
|
+
/** `ch_` and 32 lowercase hex characters. */
|
|
25
|
+
challenge_id: string;
|
|
26
|
+
/** 32 random bytes in base64url without padding (43 characters). */
|
|
27
|
+
nonce: string;
|
|
28
|
+
/** Unix milliseconds on Desktop's clock. */
|
|
29
|
+
issued_at_ms: number;
|
|
30
|
+
/** `issued_at_ms + 30000`. */
|
|
31
|
+
expires_at_ms: number;
|
|
32
|
+
}
|
|
33
|
+
/** The params of `spawn_callers.authenticate`. */
|
|
34
|
+
export type CallerAuthenticateParams = {
|
|
35
|
+
/** The `challenge_id` of the challenge being answered. */
|
|
36
|
+
challenge_id: string;
|
|
37
|
+
/** The HMAC-SHA256 authenticator in base64url without padding (43 characters). */
|
|
38
|
+
authenticator: string;
|
|
39
|
+
};
|
|
40
|
+
/** The result of `spawn_callers.authenticate`: the connection is now bound. */
|
|
41
|
+
export interface CallerBound {
|
|
42
|
+
caller_id: string;
|
|
43
|
+
/** The caller's display name: 1 to 200 of `A-Z a-z 0-9 _ -`. */
|
|
44
|
+
caller_name: string;
|
|
45
|
+
/** The record's authority generation, from 1 to 2^53 - 1. */
|
|
46
|
+
authority_generation: number;
|
|
47
|
+
}
|
|
48
|
+
/** Every value the version 1 transcript covers. */
|
|
49
|
+
export interface CallerTranscriptInput {
|
|
50
|
+
challengeId: string;
|
|
51
|
+
/** The 32 raw nonce bytes. */
|
|
52
|
+
nonce: Uint8Array;
|
|
53
|
+
callerId: string;
|
|
54
|
+
siteUrl: string;
|
|
55
|
+
workspaceId: string;
|
|
56
|
+
userId: string;
|
|
57
|
+
issuedAtMs: number;
|
|
58
|
+
expiresAtMs: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Builds the exact version 1 transcript bytes: the version byte, then each
|
|
62
|
+
* field with a big-endian u16 length prefix.
|
|
63
|
+
* @param input - The challenge fields and the caller's own `caller.json` scope.
|
|
64
|
+
* @returns The transcript bytes the authenticator covers.
|
|
65
|
+
* @throws CoreBridgeError `invalid_params` when a value is outside its bound.
|
|
66
|
+
*/
|
|
67
|
+
export declare function callerTranscript(input: CallerTranscriptInput): Buffer;
|
|
68
|
+
/**
|
|
69
|
+
* A caller's credential as read from `caller.json`. It holds the derived key,
|
|
70
|
+
* never the secret, and prints as `[redacted]`: it cannot be logged or
|
|
71
|
+
* serialised by accident.
|
|
72
|
+
*/
|
|
73
|
+
export declare class CallerCredential {
|
|
74
|
+
#private;
|
|
75
|
+
/** The caller's registry id, which is sent as the challenge param. */
|
|
76
|
+
readonly callerId: string;
|
|
77
|
+
/** `workspace.site_url`, used only in the transcript. */
|
|
78
|
+
readonly siteUrl: string;
|
|
79
|
+
/** `workspace.workspace_id`, used only in the transcript. */
|
|
80
|
+
readonly workspaceId: string;
|
|
81
|
+
/** `account.user_id`, used only in the transcript. */
|
|
82
|
+
readonly userId: string;
|
|
83
|
+
private constructor();
|
|
84
|
+
/**
|
|
85
|
+
* Checks a parsed `caller.json` document and derives its key.
|
|
86
|
+
* @param document - The parsed `caller.json` contents.
|
|
87
|
+
* @returns The credential, holding `SHA-256(secret)` and not the secret.
|
|
88
|
+
* @throws CoreBridgeError `caller_file_invalid` when the document does not
|
|
89
|
+
* have the `caller.json` shape. The message never contains the secret.
|
|
90
|
+
*/
|
|
91
|
+
static fromDocument(document: unknown): CallerCredential;
|
|
92
|
+
/**
|
|
93
|
+
* Computes the authenticator for one challenge.
|
|
94
|
+
* @param challenge - The challenge exactly as `spawn_callers.challenge` returned it.
|
|
95
|
+
* @returns The HMAC-SHA256 authenticator in base64url without padding.
|
|
96
|
+
* @throws CoreBridgeError `invalid_reply` when the challenge is malformed.
|
|
97
|
+
*/
|
|
98
|
+
authenticatorFor(challenge: CallerChallenge): string;
|
|
99
|
+
/**
|
|
100
|
+
* Keeps the key out of JSON.
|
|
101
|
+
* @returns A placeholder.
|
|
102
|
+
*/
|
|
103
|
+
toJSON(): string;
|
|
104
|
+
/**
|
|
105
|
+
* Keeps the key out of string conversion.
|
|
106
|
+
* @returns A placeholder.
|
|
107
|
+
*/
|
|
108
|
+
toString(): string;
|
|
109
|
+
/**
|
|
110
|
+
* Keeps the key out of `console.log` and `util.inspect`.
|
|
111
|
+
* @returns A placeholder.
|
|
112
|
+
*/
|
|
113
|
+
[inspect.custom](): string;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Binds a bridge connection to a service caller: one challenge and one
|
|
117
|
+
* authenticate. After it returns, `spawn.invoke`, `spawn.status` and
|
|
118
|
+
* `spawn.release` on this connection act as the caller and name no caller.
|
|
119
|
+
* Failures are the core's typed errors (`CoreRpcError`), for example
|
|
120
|
+
* `auth_failed`, `auth_locked`, `already_bound` or `challenge_outstanding`.
|
|
121
|
+
* @param client - A greeted connection that has not been bound yet.
|
|
122
|
+
* @param credential - The credential read from `caller.json`.
|
|
123
|
+
* @param options - Optional timeout and cancellation controls for each of
|
|
124
|
+
* the two calls; the default is the client's call timeout (15 seconds).
|
|
125
|
+
* @returns The bound caller.
|
|
126
|
+
*/
|
|
127
|
+
export declare function authenticate(client: CoreClient, credential: CallerCredential, options?: CallOptions): Promise<CallerBound>;
|
|
128
|
+
/**
|
|
129
|
+
* Reads `caller.json` securely and returns its credential.
|
|
130
|
+
*
|
|
131
|
+
* On macOS and Linux the file must be a regular file (not a symlink), owned
|
|
132
|
+
* by this user, with no group or other permission bits (0600 or stricter),
|
|
133
|
+
* in a directory that is not group- or world-writable unless it is sticky;
|
|
134
|
+
* it is opened with `O_NOFOLLOW`.
|
|
135
|
+
*
|
|
136
|
+
* On Windows the path must be absolute, the file must not be a symlink or
|
|
137
|
+
* reparse point (its real path must be itself), and it must be a regular
|
|
138
|
+
* file. Node has no API to read a Windows access list, so the reader cannot
|
|
139
|
+
* verify the file's DACL or owner; it relies on the per-user profile's
|
|
140
|
+
* access list that Desktop writes the file under.
|
|
141
|
+
* @param file - The absolute path of `caller.json`.
|
|
142
|
+
* @returns The credential, holding the derived key and not the secret.
|
|
143
|
+
* @throws CoreBridgeError `caller_file_unsafe` when the file fails a check
|
|
144
|
+
* above, `caller_file_invalid` when its contents are malformed.
|
|
145
|
+
*/
|
|
146
|
+
export declare function readCallerCredential(file: string): Promise<CallerCredential>;
|
|
147
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG3D,0EAA0E;AAC1E,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAC3C,iDAAiD;AACjD,eAAO,MAAM,wBAAwB,kCAAkC,CAAC;AACxE,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAC9C,6DAA6D;AAC7D,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAC7D,qDAAqD;AACrD,eAAO,MAAM,mBAAmB,2EAA4E,CAAC;AAC7G,6DAA6D;AAC7D,eAAO,MAAM,qBAAqB,QAAY,CAAC;AAE/C,+CAA+C;AAC/C,MAAM,MAAM,qBAAqB,GAAG;IAClC,uEAAuE;IACvE,SAAS,EA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DAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAGxB,OAAO;IAQP;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,gBAAgB;IA4BxD;;;;;OAKG;IACH,gBAAgB,CAAC,SAAS,EAAE,eAAe,GAAG,MAAM;IAepD;;;OAGG;IACH,MAAM,IAAI,MAAM;IAIhB;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;OAGG;IACH,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM;CAG3B;AAwDD;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,UAAU,EAClB,UAAU,EAAE,gBAAgB,EAC5B,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,WAAW,CAAC,CAatB;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAwElF"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client side of service-caller challenge authentication
|
|
3
|
+
* (`spawn_callers.challenge` and `spawn_callers.authenticate`), served by
|
|
4
|
+
* Agent Relay Desktop's spawn caller extension.
|
|
5
|
+
*
|
|
6
|
+
* A service caller proves it holds its `caller.json` secret without sending
|
|
7
|
+
* it: it asks for a challenge, computes
|
|
8
|
+
* `HMAC-SHA256(SHA-256(secret), transcript)` over the version 1 transcript,
|
|
9
|
+
* and sends that authenticator. A successful authenticate binds the bridge
|
|
10
|
+
* connection to the caller for the rest of its life; the `spawn.*` calls on
|
|
11
|
+
* it then name no caller at all.
|
|
12
|
+
*
|
|
13
|
+
* Rules a caller must know:
|
|
14
|
+
* - A connection can be bound once. Open a new connection to bind again.
|
|
15
|
+
* - A challenge is single-use and expires 30 seconds after it was issued.
|
|
16
|
+
* - Three attempts on one connection that end without a binding lock it
|
|
17
|
+
* (`auth_locked`); open a new connection.
|
|
18
|
+
* - Neither the secret nor the derived key ever leaves this process.
|
|
19
|
+
*/
|
|
20
|
+
import { createHash, createHmac } from 'node:crypto';
|
|
21
|
+
import { constants as fsConstants } from 'node:fs';
|
|
22
|
+
import { lstat, open, realpath, stat } from 'node:fs/promises';
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
import { inspect } from 'node:util';
|
|
25
|
+
import { CoreBridgeError, CoreRpcError } from './errors.js';
|
|
26
|
+
/** The transcript version byte, which is also the challenge `version`. */
|
|
27
|
+
export const CALLER_TRANSCRIPT_VERSION = 1;
|
|
28
|
+
/** The transcript's domain separation string. */
|
|
29
|
+
export const CALLER_TRANSCRIPT_DOMAIN = 'agent-relay/service-caller/v1';
|
|
30
|
+
/** How long a challenge stays valid after it was issued, in milliseconds. */
|
|
31
|
+
export const CALLER_CHALLENGE_TTL_MS = 30_000;
|
|
32
|
+
/** The `caller.json` `auth` value naming this transcript. */
|
|
33
|
+
export const CALLER_AUTH_SCHEME = 'challenge-hmac-sha256/v1';
|
|
34
|
+
/** The `caller.json` schemas this reader accepts. */
|
|
35
|
+
export const CALLER_FILE_SCHEMAS = ['agent-relay-service-caller/1', 'agent-relay-service-caller/2'];
|
|
36
|
+
/** The largest `caller.json` this reader opens, in bytes. */
|
|
37
|
+
export const MAX_CALLER_FILE_BYTES = 64 * 1024;
|
|
38
|
+
const CALLER_ID = /^sc_[0-9a-f]{16}$/;
|
|
39
|
+
const CHALLENGE_ID = /^ch_[0-9a-f]{32}$/;
|
|
40
|
+
const B64URL_32 = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
|
|
41
|
+
const SECRET = /^rsc_[A-Za-z0-9_-]{43}$/;
|
|
42
|
+
const CALLER_NAME = /^[A-Za-z0-9_-]{1,200}$/;
|
|
43
|
+
const NONCE_BYTES = 32;
|
|
44
|
+
function invalid(code, message) {
|
|
45
|
+
return new CoreBridgeError(code, message);
|
|
46
|
+
}
|
|
47
|
+
function bytesWithin(field, value, min, max) {
|
|
48
|
+
if (typeof value !== 'string')
|
|
49
|
+
throw invalid('invalid_params', `Caller transcript input is invalid: ${field} must be a string.`);
|
|
50
|
+
const bytes = Buffer.from(value, 'utf8');
|
|
51
|
+
if (bytes.length < min || bytes.length > max) {
|
|
52
|
+
throw invalid('invalid_params', `Caller transcript input is invalid: ${field} must be ${min} to ${max} bytes.`);
|
|
53
|
+
}
|
|
54
|
+
return bytes;
|
|
55
|
+
}
|
|
56
|
+
function matching(field, value, pattern) {
|
|
57
|
+
if (typeof value !== 'string' || !pattern.test(value)) {
|
|
58
|
+
throw invalid('invalid_params', `Caller transcript input is invalid: ${field} is malformed.`);
|
|
59
|
+
}
|
|
60
|
+
return Buffer.from(value, 'ascii');
|
|
61
|
+
}
|
|
62
|
+
function millis(field, value) {
|
|
63
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0) {
|
|
64
|
+
throw invalid('invalid_params', `Caller transcript input is invalid: ${field} must be an integer from 0 to 2^53 - 1.`);
|
|
65
|
+
}
|
|
66
|
+
return BigInt(value);
|
|
67
|
+
}
|
|
68
|
+
function field(bytes) {
|
|
69
|
+
const prefix = Buffer.alloc(2);
|
|
70
|
+
prefix.writeUInt16BE(bytes.length);
|
|
71
|
+
return Buffer.concat([prefix, bytes]);
|
|
72
|
+
}
|
|
73
|
+
function u64(value) {
|
|
74
|
+
const out = Buffer.alloc(8);
|
|
75
|
+
out.writeBigUInt64BE(value);
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Builds the exact version 1 transcript bytes: the version byte, then each
|
|
80
|
+
* field with a big-endian u16 length prefix.
|
|
81
|
+
* @param input - The challenge fields and the caller's own `caller.json` scope.
|
|
82
|
+
* @returns The transcript bytes the authenticator covers.
|
|
83
|
+
* @throws CoreBridgeError `invalid_params` when a value is outside its bound.
|
|
84
|
+
*/
|
|
85
|
+
export function callerTranscript(input) {
|
|
86
|
+
if (!(input.nonce instanceof Uint8Array) || input.nonce.length !== NONCE_BYTES) {
|
|
87
|
+
throw invalid('invalid_params', 'Caller transcript input is invalid: nonce must be 32 bytes.');
|
|
88
|
+
}
|
|
89
|
+
return Buffer.concat([
|
|
90
|
+
Buffer.from([CALLER_TRANSCRIPT_VERSION]),
|
|
91
|
+
field(Buffer.from(CALLER_TRANSCRIPT_DOMAIN, 'ascii')),
|
|
92
|
+
field(matching('challenge_id', input.challengeId, CHALLENGE_ID)),
|
|
93
|
+
field(input.nonce),
|
|
94
|
+
field(matching('caller_id', input.callerId, CALLER_ID)),
|
|
95
|
+
field(bytesWithin('site_url', input.siteUrl, 1, 2048)),
|
|
96
|
+
field(bytesWithin('workspace_id', input.workspaceId, 1, 256)),
|
|
97
|
+
field(bytesWithin('user_id', input.userId, 1, 256)),
|
|
98
|
+
field(u64(millis('issued_at_ms', input.issuedAtMs))),
|
|
99
|
+
field(u64(millis('expires_at_ms', input.expiresAtMs))),
|
|
100
|
+
]);
|
|
101
|
+
}
|
|
102
|
+
const KEY = Symbol('key');
|
|
103
|
+
/**
|
|
104
|
+
* A caller's credential as read from `caller.json`. It holds the derived key,
|
|
105
|
+
* never the secret, and prints as `[redacted]`: it cannot be logged or
|
|
106
|
+
* serialised by accident.
|
|
107
|
+
*/
|
|
108
|
+
export class CallerCredential {
|
|
109
|
+
/** The caller's registry id, which is sent as the challenge param. */
|
|
110
|
+
callerId;
|
|
111
|
+
/** `workspace.site_url`, used only in the transcript. */
|
|
112
|
+
siteUrl;
|
|
113
|
+
/** `workspace.workspace_id`, used only in the transcript. */
|
|
114
|
+
workspaceId;
|
|
115
|
+
/** `account.user_id`, used only in the transcript. */
|
|
116
|
+
userId;
|
|
117
|
+
#key;
|
|
118
|
+
constructor(key, callerId, siteUrl, workspaceId, userId) {
|
|
119
|
+
this.#key = key;
|
|
120
|
+
this.callerId = callerId;
|
|
121
|
+
this.siteUrl = siteUrl;
|
|
122
|
+
this.workspaceId = workspaceId;
|
|
123
|
+
this.userId = userId;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Checks a parsed `caller.json` document and derives its key.
|
|
127
|
+
* @param document - The parsed `caller.json` contents.
|
|
128
|
+
* @returns The credential, holding `SHA-256(secret)` and not the secret.
|
|
129
|
+
* @throws CoreBridgeError `caller_file_invalid` when the document does not
|
|
130
|
+
* have the `caller.json` shape. The message never contains the secret.
|
|
131
|
+
*/
|
|
132
|
+
static fromDocument(document) {
|
|
133
|
+
const bad = (rule) => invalid('caller_file_invalid', `caller.json is invalid: ${rule}.`);
|
|
134
|
+
if (typeof document !== 'object' || document === null || Array.isArray(document))
|
|
135
|
+
throw bad('it must be an object');
|
|
136
|
+
const doc = document;
|
|
137
|
+
if (!CALLER_FILE_SCHEMAS.includes(doc.schema))
|
|
138
|
+
throw bad('schema is not one this reader knows');
|
|
139
|
+
if (doc.schema !== CALLER_FILE_SCHEMAS[0] && doc.auth !== CALLER_AUTH_SCHEME)
|
|
140
|
+
throw bad('auth is not one this reader knows');
|
|
141
|
+
if (typeof doc.caller_id !== 'string' || !CALLER_ID.test(doc.caller_id)) {
|
|
142
|
+
throw bad('caller_id must be "sc_" and 16 lowercase hex characters');
|
|
143
|
+
}
|
|
144
|
+
if (typeof doc.secret !== 'string' || !SECRET.test(doc.secret))
|
|
145
|
+
throw bad('secret is malformed');
|
|
146
|
+
const workspace = doc.workspace;
|
|
147
|
+
const account = doc.account;
|
|
148
|
+
const text = (value, name, max) => {
|
|
149
|
+
if (typeof value !== 'string' || value.length === 0 || Buffer.byteLength(value, 'utf8') > max) {
|
|
150
|
+
throw bad(`${name} must be 1 to ${max} bytes`);
|
|
151
|
+
}
|
|
152
|
+
return value;
|
|
153
|
+
};
|
|
154
|
+
const siteUrl = text(workspace?.site_url, 'workspace.site_url', 2048);
|
|
155
|
+
const workspaceId = text(workspace?.workspace_id, 'workspace.workspace_id', 256);
|
|
156
|
+
const userId = text(account?.user_id, 'account.user_id', 256);
|
|
157
|
+
const key = createHash('sha256').update(doc.secret, 'utf8').digest();
|
|
158
|
+
return new CallerCredential(key, doc.caller_id, siteUrl, workspaceId, userId);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Computes the authenticator for one challenge.
|
|
162
|
+
* @param challenge - The challenge exactly as `spawn_callers.challenge` returned it.
|
|
163
|
+
* @returns The HMAC-SHA256 authenticator in base64url without padding.
|
|
164
|
+
* @throws CoreBridgeError `invalid_reply` when the challenge is malformed.
|
|
165
|
+
*/
|
|
166
|
+
authenticatorFor(challenge) {
|
|
167
|
+
checkChallenge(challenge);
|
|
168
|
+
const transcript = callerTranscript({
|
|
169
|
+
challengeId: challenge.challenge_id,
|
|
170
|
+
nonce: Buffer.from(challenge.nonce, 'base64url'),
|
|
171
|
+
callerId: this.callerId,
|
|
172
|
+
siteUrl: this.siteUrl,
|
|
173
|
+
workspaceId: this.workspaceId,
|
|
174
|
+
userId: this.userId,
|
|
175
|
+
issuedAtMs: challenge.issued_at_ms,
|
|
176
|
+
expiresAtMs: challenge.expires_at_ms,
|
|
177
|
+
});
|
|
178
|
+
return createHmac('sha256', this.#key).update(transcript).digest('base64url');
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Keeps the key out of JSON.
|
|
182
|
+
* @returns A placeholder.
|
|
183
|
+
*/
|
|
184
|
+
toJSON() {
|
|
185
|
+
return '[redacted]';
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Keeps the key out of string conversion.
|
|
189
|
+
* @returns A placeholder.
|
|
190
|
+
*/
|
|
191
|
+
toString() {
|
|
192
|
+
return '[redacted]';
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Keeps the key out of `console.log` and `util.inspect`.
|
|
196
|
+
* @returns A placeholder.
|
|
197
|
+
*/
|
|
198
|
+
[inspect.custom]() {
|
|
199
|
+
return 'CallerCredential [redacted]';
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function badReply(rule) {
|
|
203
|
+
return new CoreRpcError(`The caller challenge reply is invalid: ${rule}.`, {
|
|
204
|
+
rpcCode: -32603,
|
|
205
|
+
kind: 'internal',
|
|
206
|
+
retryable: false,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function checkChallenge(challenge) {
|
|
210
|
+
if (typeof challenge !== 'object' || challenge === null)
|
|
211
|
+
throw badReply('it must be an object');
|
|
212
|
+
if (challenge.version !== CALLER_TRANSCRIPT_VERSION)
|
|
213
|
+
throw badReply('version must be 1');
|
|
214
|
+
if (typeof challenge.challenge_id !== 'string' || !CHALLENGE_ID.test(challenge.challenge_id)) {
|
|
215
|
+
throw badReply('challenge_id is malformed');
|
|
216
|
+
}
|
|
217
|
+
if (typeof challenge.nonce !== 'string' || !B64URL_32.test(challenge.nonce))
|
|
218
|
+
throw badReply('nonce is malformed');
|
|
219
|
+
const { issued_at_ms: issued, expires_at_ms: expires } = challenge;
|
|
220
|
+
if (!Number.isSafeInteger(issued) || issued < 0)
|
|
221
|
+
throw badReply('issued_at_ms is out of range');
|
|
222
|
+
if (expires !== issued + CALLER_CHALLENGE_TTL_MS || !Number.isSafeInteger(expires)) {
|
|
223
|
+
throw badReply('expires_at_ms must be issued_at_ms + 30000');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function checkBound(bound, callerId) {
|
|
227
|
+
const fail = (rule) => new CoreRpcError(`The caller authenticate reply is invalid: ${rule}.`, {
|
|
228
|
+
rpcCode: -32603,
|
|
229
|
+
kind: 'internal',
|
|
230
|
+
retryable: false,
|
|
231
|
+
});
|
|
232
|
+
if (typeof bound !== 'object' || bound === null)
|
|
233
|
+
throw fail('it must be an object');
|
|
234
|
+
if (bound.caller_id !== callerId)
|
|
235
|
+
throw fail('caller_id is not the caller that authenticated');
|
|
236
|
+
if (typeof bound.caller_name !== 'string' || !CALLER_NAME.test(bound.caller_name))
|
|
237
|
+
throw fail('caller_name is malformed');
|
|
238
|
+
if (!Number.isSafeInteger(bound.authority_generation) || bound.authority_generation < 1) {
|
|
239
|
+
throw fail('authority_generation is out of range');
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
caller_id: bound.caller_id,
|
|
243
|
+
caller_name: bound.caller_name,
|
|
244
|
+
authority_generation: bound.authority_generation,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function requireMethod(client, method) {
|
|
248
|
+
if (!client.hello.methods.includes(method)) {
|
|
249
|
+
throw new CoreRpcError(`This Agent Relay core does not offer ${method}; update Agent Relay Desktop.`, {
|
|
250
|
+
rpcCode: -32601,
|
|
251
|
+
kind: 'method_not_found',
|
|
252
|
+
retryable: false,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Binds a bridge connection to a service caller: one challenge and one
|
|
258
|
+
* authenticate. After it returns, `spawn.invoke`, `spawn.status` and
|
|
259
|
+
* `spawn.release` on this connection act as the caller and name no caller.
|
|
260
|
+
* Failures are the core's typed errors (`CoreRpcError`), for example
|
|
261
|
+
* `auth_failed`, `auth_locked`, `already_bound` or `challenge_outstanding`.
|
|
262
|
+
* @param client - A greeted connection that has not been bound yet.
|
|
263
|
+
* @param credential - The credential read from `caller.json`.
|
|
264
|
+
* @param options - Optional timeout and cancellation controls for each of
|
|
265
|
+
* the two calls; the default is the client's call timeout (15 seconds).
|
|
266
|
+
* @returns The bound caller.
|
|
267
|
+
*/
|
|
268
|
+
export async function authenticate(client, credential, options) {
|
|
269
|
+
requireMethod(client, 'spawn_callers.challenge');
|
|
270
|
+
requireMethod(client, 'spawn_callers.authenticate');
|
|
271
|
+
const challengeParams = { caller_id: credential.callerId };
|
|
272
|
+
const challenge = await client.call('spawn_callers.challenge', challengeParams, options);
|
|
273
|
+
const params = {
|
|
274
|
+
challenge_id: challenge?.challenge_id,
|
|
275
|
+
authenticator: credential.authenticatorFor(challenge),
|
|
276
|
+
};
|
|
277
|
+
return checkBound(await client.call('spawn_callers.authenticate', params, options), credential.callerId);
|
|
278
|
+
}
|
|
279
|
+
function unsafe(file, rule) {
|
|
280
|
+
return new CoreBridgeError('caller_file_unsafe', `Refusing to read ${file}: ${rule}.`);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Reads `caller.json` securely and returns its credential.
|
|
284
|
+
*
|
|
285
|
+
* On macOS and Linux the file must be a regular file (not a symlink), owned
|
|
286
|
+
* by this user, with no group or other permission bits (0600 or stricter),
|
|
287
|
+
* in a directory that is not group- or world-writable unless it is sticky;
|
|
288
|
+
* it is opened with `O_NOFOLLOW`.
|
|
289
|
+
*
|
|
290
|
+
* On Windows the path must be absolute, the file must not be a symlink or
|
|
291
|
+
* reparse point (its real path must be itself), and it must be a regular
|
|
292
|
+
* file. Node has no API to read a Windows access list, so the reader cannot
|
|
293
|
+
* verify the file's DACL or owner; it relies on the per-user profile's
|
|
294
|
+
* access list that Desktop writes the file under.
|
|
295
|
+
* @param file - The absolute path of `caller.json`.
|
|
296
|
+
* @returns The credential, holding the derived key and not the secret.
|
|
297
|
+
* @throws CoreBridgeError `caller_file_unsafe` when the file fails a check
|
|
298
|
+
* above, `caller_file_invalid` when its contents are malformed.
|
|
299
|
+
*/
|
|
300
|
+
export async function readCallerCredential(file) {
|
|
301
|
+
if (typeof file !== 'string' || !path.isAbsolute(file) || file.includes('\0')) {
|
|
302
|
+
throw unsafe(String(file), 'the path must be absolute');
|
|
303
|
+
}
|
|
304
|
+
// Open once and check the open descriptor, not the path, so nothing can
|
|
305
|
+
// swap the file between a check and the read. On macOS and Linux
|
|
306
|
+
// O_NOFOLLOW refuses a symlink in place of the file (ELOOP) and O_NONBLOCK
|
|
307
|
+
// keeps a FIFO from blocking the open; Windows has neither flag.
|
|
308
|
+
const posix = process.platform !== 'win32';
|
|
309
|
+
let flags = fsConstants.O_RDONLY;
|
|
310
|
+
if (posix) {
|
|
311
|
+
if (typeof fsConstants.O_NOFOLLOW === 'number')
|
|
312
|
+
flags |= fsConstants.O_NOFOLLOW;
|
|
313
|
+
if (typeof fsConstants.O_NONBLOCK === 'number')
|
|
314
|
+
flags |= fsConstants.O_NONBLOCK;
|
|
315
|
+
}
|
|
316
|
+
let handle;
|
|
317
|
+
try {
|
|
318
|
+
handle = await open(file, flags);
|
|
319
|
+
}
|
|
320
|
+
catch (error) {
|
|
321
|
+
const code = error?.code;
|
|
322
|
+
if (code === 'ELOOP')
|
|
323
|
+
throw unsafe(file, 'it is a symbolic link');
|
|
324
|
+
if (code === 'EISDIR')
|
|
325
|
+
throw unsafe(file, 'it is not a regular file');
|
|
326
|
+
// ENOENT and ENOTDIR pass through unchanged, as a missing file always has.
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
let text;
|
|
330
|
+
try {
|
|
331
|
+
const opened = await handle.stat();
|
|
332
|
+
if (!opened.isFile())
|
|
333
|
+
throw unsafe(file, 'it is not a regular file');
|
|
334
|
+
if (opened.size > MAX_CALLER_FILE_BYTES)
|
|
335
|
+
throw unsafe(file, 'it is larger than 64 KiB');
|
|
336
|
+
if (!posix) {
|
|
337
|
+
// Windows gap: Node exposes no access-list API, so the DACL and owner
|
|
338
|
+
// are not verified here. The file lives in the user's profile, whose
|
|
339
|
+
// access list admits only that user, SYSTEM and administrators. What
|
|
340
|
+
// can be checked is: an absolute path that is not a reparse point.
|
|
341
|
+
// The path is examined after the open and must name the file that was
|
|
342
|
+
// opened; it is never used to read. Paths compare case-insensitively,
|
|
343
|
+
// as NTFS resolves them.
|
|
344
|
+
const link = await lstat(file);
|
|
345
|
+
if (link.isSymbolicLink())
|
|
346
|
+
throw unsafe(file, 'it is a symbolic link');
|
|
347
|
+
if (link.ino !== opened.ino || link.dev !== opened.dev) {
|
|
348
|
+
throw unsafe(file, 'it changed while being opened');
|
|
349
|
+
}
|
|
350
|
+
if ((await realpath(file)).toLowerCase() !== path.resolve(file).toLowerCase()) {
|
|
351
|
+
throw unsafe(file, 'it resolves through a link');
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
if (typeof process.getuid === 'function' && opened.uid !== process.getuid()) {
|
|
356
|
+
throw unsafe(file, 'it is not owned by this user');
|
|
357
|
+
}
|
|
358
|
+
if ((opened.mode & 0o077) !== 0)
|
|
359
|
+
throw unsafe(file, 'it is readable or writable by other users (it must be 0600)');
|
|
360
|
+
const parent = await stat(path.dirname(file));
|
|
361
|
+
if ((parent.mode & 0o022) !== 0 && (parent.mode & 0o1000) === 0) {
|
|
362
|
+
throw unsafe(file, 'its directory is writable by other users');
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const buffer = Buffer.alloc(MAX_CALLER_FILE_BYTES + 1);
|
|
366
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
367
|
+
if (bytesRead > MAX_CALLER_FILE_BYTES)
|
|
368
|
+
throw unsafe(file, 'it is larger than 64 KiB');
|
|
369
|
+
text = buffer.subarray(0, bytesRead).toString('utf8');
|
|
370
|
+
buffer.fill(0);
|
|
371
|
+
}
|
|
372
|
+
finally {
|
|
373
|
+
await handle.close();
|
|
374
|
+
}
|
|
375
|
+
let document;
|
|
376
|
+
try {
|
|
377
|
+
document = JSON.parse(text);
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
// The parser's message can quote the file, secret included.
|
|
381
|
+
throw new CoreBridgeError('caller_file_invalid', 'caller.json is invalid: it is not JSON.');
|
|
382
|
+
}
|
|
383
|
+
return CallerCredential.fromDocument(document);
|
|
384
|
+
}
|
|
385
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,IAAI,E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IAAI,eAAe,CAAC,qBAAqB,EAAE,yCAAyC,CAAC,CAAC;IAC9F,CAAC;IACD,OAAO,gBAAgB,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;AACjD,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Every event topic the core publishes (`protocol.rs` `Topic`). */
|
|
2
|
+
export declare const TOPICS: readonly ["status", "activity", "shutdown", "invalidated", "notify", "sign_in"];
|
|
3
|
+
/** An event topic a client can subscribe to. */
|
|
4
|
+
export type Topic = (typeof TOPICS)[number];
|
|
5
|
+
/** The core's answer to `hello`. Feature-detect with `methods`. */
|
|
6
|
+
export interface HelloResult {
|
|
7
|
+
bridge_version: number;
|
|
8
|
+
daemon_version: string;
|
|
9
|
+
pid: number;
|
|
10
|
+
methods: string[];
|
|
11
|
+
topics: Topic[];
|
|
12
|
+
}
|
|
13
|
+
/** One event the core pushed to a subscribed connection (`protocol.rs` `Event`). */
|
|
14
|
+
export interface CoreEvent {
|
|
15
|
+
topic: Topic | (string & {});
|
|
16
|
+
/** Increases by one per event across all topics, per core process. */
|
|
17
|
+
seq: number;
|
|
18
|
+
data: unknown;
|
|
19
|
+
}
|
|
20
|
+
/** How {@link connectCore} finds and talks to the core. */
|
|
21
|
+
export interface ConnectOptions {
|
|
22
|
+
/** The bridge socket path; default {@link coreSocketPath}(`env`, `home`). */
|
|
23
|
+
socket?: string;
|
|
24
|
+
env?: NodeJS.ProcessEnv;
|
|
25
|
+
home?: string;
|
|
26
|
+
/** Bound on connecting; default 15 000 ms. */
|
|
27
|
+
connectTimeoutMs?: number;
|
|
28
|
+
/** Bound on each call (including `hello`); default 15 000 ms. */
|
|
29
|
+
callTimeoutMs?: number;
|
|
30
|
+
/** Aborts connecting; once connected, aborting closes the client. */
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
}
|
|
33
|
+
/** Per-call options. */
|
|
34
|
+
export interface CallOptions {
|
|
35
|
+
/** Overrides the client's `callTimeoutMs` for this call. */
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
/** Abandons this call; the connection stays open. */
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}
|
|
40
|
+
/** A greeted connection to the core's bridge. */
|
|
41
|
+
export interface CoreClient {
|
|
42
|
+
/** The core's greeting. */
|
|
43
|
+
readonly hello: HelloResult;
|
|
44
|
+
/** The socket path this client connected to. */
|
|
45
|
+
readonly socket: string;
|
|
46
|
+
/** Calls one bridge method and returns its result (`null` when the core sent none). */
|
|
47
|
+
call<T = unknown>(method: string, params?: Record<string, unknown>, opts?: CallOptions): Promise<T>;
|
|
48
|
+
/** Subscribes this connection to topics; the result carries a status snapshot. */
|
|
49
|
+
subscribe(topics: Topic[]): Promise<{
|
|
50
|
+
topics: Topic[];
|
|
51
|
+
status: unknown;
|
|
52
|
+
}>;
|
|
53
|
+
/** Unsubscribes this connection from topics. */
|
|
54
|
+
unsubscribe(topics: Topic[]): Promise<{
|
|
55
|
+
topics: Topic[];
|
|
56
|
+
}>;
|
|
57
|
+
/** Listens for events; returns a function that removes the listener. */
|
|
58
|
+
onEvent(listener: (event: CoreEvent) => void): () => void;
|
|
59
|
+
/** Listens for the connection closing, with the error that closed it if any; returns a remover. */
|
|
60
|
+
onClose(listener: (error?: Error) => void): () => void;
|
|
61
|
+
/** Whether the connection is closed. */
|
|
62
|
+
readonly closed: boolean;
|
|
63
|
+
/** Closes the connection; pending calls fail with {@link CoreClosedError}. */
|
|
64
|
+
close(): void;
|
|
65
|
+
/** Closes the connection and waits until it is closed. */
|
|
66
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Connect to the core and greet it.
|
|
70
|
+
*
|
|
71
|
+
* Order: socket file exists (else not running), its directory and the socket
|
|
72
|
+
* file pass the ownership and mode checks, connect, `hello`, and the greeting
|
|
73
|
+
* has the core's shape. Only "nothing answers" is {@link CoreNotRunningError};
|
|
74
|
+
* every other failure is its own error, so a caller never takes a refused or
|
|
75
|
+
* foreign socket for an absent core and starts a second one.
|
|
76
|
+
* @param opts - Where the core is and how long to wait
|
|
77
|
+
* @returns A greeted client
|
|
78
|
+
* @throws CoreNotRunningError, CoreUntrustedError, NotACoreError, BridgeVersionMismatchError, CoreBridgeError
|
|
79
|
+
*/
|
|
80
|
+
export declare function connectCore(opts?: ConnectOptions): Promise<CoreClient>;
|
|
81
|
+
/**
|
|
82
|
+
* {@link connectCore}, but resolves undefined when no core is running
|
|
83
|
+
* ({@link CoreNotRunningError}); every other failure still throws.
|
|
84
|
+
* @param opts - Where the core is and how long to wait
|
|
85
|
+
* @returns A greeted client, or undefined when nothing answers
|
|
86
|
+
*/
|
|
87
|
+
export declare function tryConnectCore(opts?: ConnectOptions): Promise<CoreClient | undefined>;
|
|
88
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAoBA,oEAAoE;AACpE,eAAO,MAAM,MAAM,iFAAkF,CAAC;AACtG,gDAAgD;AAChD,MAAM,MAAM,KAAK,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5C,mEAAmE;AACnE,MAAM,WAAW,WAAW;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,oFAAoF;AACpF,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IAC7B,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC;CACf;AAED,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAC7B,6EAA6E;IAC7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