@peer2peer/cli 0.1.3 → 0.1.5
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 +9 -7
- package/dist/app.d.ts +28 -0
- package/dist/app.js +112 -21
- package/dist/circle-ops.js +2 -1
- package/dist/cli.d.ts +3 -3
- package/dist/cli.js +211 -4
- package/dist/config.d.ts +5 -0
- package/dist/doctor.d.ts +7 -0
- package/dist/doctor.js +73 -2
- package/dist/format.d.ts +3 -1
- package/dist/format.js +12 -0
- package/dist/identity.js +2 -0
- package/dist/keystore.d.ts +223 -0
- package/dist/keystore.js +1021 -0
- package/dist/outbox.d.ts +2 -4
- package/dist/outbox.js +12 -3
- package/dist/procstart.js +11 -3
- package/dist/projects.js +4 -8
- package/dist/relay-client.d.ts +8 -0
- package/dist/relay-client.js +7 -1
- package/dist/rotation-lock.d.ts +17 -0
- package/dist/rotation-lock.js +188 -0
- package/dist/rotation.d.ts +27 -1
- package/dist/rotation.js +141 -15
- package/dist/sandbox.d.ts +195 -0
- package/dist/sandbox.js +763 -0
- package/dist/state.d.ts +8 -0
- package/dist/state.js +12 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
export type KeyBackend = "file" | "keychain";
|
|
2
|
+
/** One run of an OS tool: what came back. `error` is the spawn's own failure (ENOENT, ETIMEDOUT). */
|
|
3
|
+
export interface RunResult {
|
|
4
|
+
status: number | null;
|
|
5
|
+
stdout: string;
|
|
6
|
+
stderr: string;
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Runs `file` with `args` (never through a shell), `input` on its stdin. Tests stand in their own. */
|
|
10
|
+
export type Runner = (file: string, args: readonly string[], input: string) => RunResult;
|
|
11
|
+
/** How long one keychain call may take: a locked keychain may be showing its unlock prompt. */
|
|
12
|
+
export declare const KEYCHAIN_TIMEOUT_MS = 20000;
|
|
13
|
+
export declare const realRunner: Runner;
|
|
14
|
+
/** A keychain call that failed: `reason` is safe to show (never the secret, never the tool's raw output with it). */
|
|
15
|
+
export declare class KeychainError extends Error {
|
|
16
|
+
readonly reason: string;
|
|
17
|
+
constructor(reason: string);
|
|
18
|
+
}
|
|
19
|
+
export interface Keychain {
|
|
20
|
+
readonly kind: "macos" | "linux" | "windows";
|
|
21
|
+
/** "the macOS Keychain", for messages. */
|
|
22
|
+
readonly label: string;
|
|
23
|
+
/** Why this keychain can't be used here (its tool is missing), or undefined. */
|
|
24
|
+
unavailable(): string | undefined;
|
|
25
|
+
/** The secret, or undefined when there is no such item. Throws KeychainError when the keychain can't be read. */
|
|
26
|
+
get(service: string, account: string): string | undefined;
|
|
27
|
+
/** Stores (or replaces) the item. Throws KeychainError. */
|
|
28
|
+
set(service: string, account: string, label: string, secret: string): void;
|
|
29
|
+
/** Deletes the item; false when there was none. Throws KeychainError. */
|
|
30
|
+
remove(service: string, account: string): boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The tool's message, safe to show: one line, short, with the secret (and anything shaped like one)
|
|
34
|
+
* taken out. The tools don't echo secrets, but this never relies on it.
|
|
35
|
+
*/
|
|
36
|
+
export declare function toolMessage(out: string, secret?: string): string;
|
|
37
|
+
export declare const SECURITY = "/usr/bin/security";
|
|
38
|
+
/**
|
|
39
|
+
* The macOS Keychain through `/usr/bin/security`. Writes go through `security -i`, which reads its
|
|
40
|
+
* commands from stdin, so the secret is never in a command line. The item's access list trusts
|
|
41
|
+
* `/usr/bin/security` only (`-T`): other apps get the system's prompt. `keychainFile` points at
|
|
42
|
+
* another keychain than the default one (the opt-in test uses a throwaway keychain).
|
|
43
|
+
*/
|
|
44
|
+
export declare function macosKeychain(run?: Runner, opts?: {
|
|
45
|
+
keychainFile?: string;
|
|
46
|
+
exists?: (p: string) => boolean;
|
|
47
|
+
}): Keychain;
|
|
48
|
+
/** Where secret-tool is looked for: system folders only (never PATH, never a user-writable folder). */
|
|
49
|
+
export declare const SECRET_TOOL_PATHS: string[];
|
|
50
|
+
/** The Secret Service (GNOME Keyring, KWallet) through libsecret's `secret-tool`; `store` reads the secret from stdin. */
|
|
51
|
+
export declare function libsecretKeychain(run?: Runner, opts?: {
|
|
52
|
+
exists?: (p: string) => boolean;
|
|
53
|
+
}): Keychain;
|
|
54
|
+
/**
|
|
55
|
+
* The C# that does the work on Windows. It reads the request from stdin itself and writes the answer
|
|
56
|
+
* to stdout itself, so the secret never passes through a PowerShell cmdlet, pipeline or variable
|
|
57
|
+
* (with PowerShell module or script block logging on, those are recorded in the event log). The
|
|
58
|
+
* request: one field per line, `op`, `target`, `account`, `label`, `secret` (each in the narrow
|
|
59
|
+
* alphabets above: no line breaks). Credentials are generic ones persisted on this machine only
|
|
60
|
+
* (CRED_PERSIST_LOCAL_MACHINE: never roamed). Exit 3: no such credential.
|
|
61
|
+
*/
|
|
62
|
+
export declare const WINDOWS_CSHARP: string;
|
|
63
|
+
/**
|
|
64
|
+
* The PowerShell that runs it (passed as -EncodedCommand: no secret in it): a static loader that
|
|
65
|
+
* compiles the C# above with the .NET compiler directly and calls it. No cmdlet runs (not even
|
|
66
|
+
* Add-Type), no module is loaded (autoloading off: nothing from a user-writable PSModulePath), and
|
|
67
|
+
* nothing reads stdin but the C#.
|
|
68
|
+
*/
|
|
69
|
+
export declare const WINDOWS_SCRIPT: string;
|
|
70
|
+
/** The fixed path of Windows PowerShell 5.1, which every supported Windows has. */
|
|
71
|
+
export declare const WINDOWS_POWERSHELL = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
|
|
72
|
+
/**
|
|
73
|
+
* Windows PowerShell by its absolute path: the fixed `C:\\Windows` one when it is there. Otherwise
|
|
74
|
+
* %SystemRoot% (or %windir%) only when it is a drive's own Windows folder (`D:\\Windows`, `D:\\WINNT`),
|
|
75
|
+
* never anything else the environment names (a folder in a user profile). Undefined: none to trust.
|
|
76
|
+
*/
|
|
77
|
+
export declare function powershellPath(env?: Record<string, string | undefined>, exists?: (p: string) => boolean): string | undefined;
|
|
78
|
+
export declare function windowsKeychain(run?: Runner, opts?: {
|
|
79
|
+
exists?: (p: string) => boolean;
|
|
80
|
+
env?: Record<string, string | undefined>;
|
|
81
|
+
}): Keychain;
|
|
82
|
+
/** Tests: use `k` instead of the platform's keychain (null: none on this platform); undefined restores it. */
|
|
83
|
+
export declare function useKeychainForTests(k: Keychain | null | undefined): void;
|
|
84
|
+
/** This platform's keychain, or undefined where p2p knows none. */
|
|
85
|
+
export declare function platformKeychain(platform?: NodeJS.Platform): Keychain | undefined;
|
|
86
|
+
export declare const SERVICE_PREFIX = "peer2peer-keys-";
|
|
87
|
+
/** Contains the service prefix, so a guard looking for p2p's items also sees a lookup by label. */
|
|
88
|
+
export declare const LABEL = "peer2peer-keys-device";
|
|
89
|
+
/** The home as the keychain item names it: its real path when it exists (a symlinked P2P_HOME is the same home). */
|
|
90
|
+
export declare function canonicalHome(home: string): string;
|
|
91
|
+
/** The keychain service for `home`: one per home, so two homes (two identities on one machine) never share an item. */
|
|
92
|
+
export declare function serviceFor(home: string): string;
|
|
93
|
+
export declare function markerFile(home: string): string;
|
|
94
|
+
/** The backend new keys are written to: keystore.json's, else files. Throws when the file is there but unreadable (fail closed). */
|
|
95
|
+
export declare function configuredBackend(home: string): KeyBackend;
|
|
96
|
+
/** The keys document as the CLI uses it (state.ts KeysDoc), with secrets. */
|
|
97
|
+
export interface FullKeys {
|
|
98
|
+
v: 1;
|
|
99
|
+
userId: string;
|
|
100
|
+
did: string;
|
|
101
|
+
spk: string;
|
|
102
|
+
kpk: string;
|
|
103
|
+
cert: string;
|
|
104
|
+
ik?: string;
|
|
105
|
+
[k: string]: unknown;
|
|
106
|
+
}
|
|
107
|
+
/** keys.json when the secrets are in the keychain. */
|
|
108
|
+
interface SealedKeys {
|
|
109
|
+
v: 1;
|
|
110
|
+
userId: string;
|
|
111
|
+
did: string;
|
|
112
|
+
cert: string;
|
|
113
|
+
store: "keychain";
|
|
114
|
+
service: string;
|
|
115
|
+
[k: string]: unknown;
|
|
116
|
+
}
|
|
117
|
+
/** Whether a raw keys.json holds the secrets itself. */
|
|
118
|
+
export declare function holdsSecrets(raw: unknown): boolean;
|
|
119
|
+
/** Whether a raw keys.json says its secrets are in the keychain. */
|
|
120
|
+
export declare function isSealed(raw: unknown): raw is SealedKeys;
|
|
121
|
+
/** The item's secret for keys `k` (exported for the tests). */
|
|
122
|
+
export declare function payloadOf(k: FullKeys): string;
|
|
123
|
+
/** The keys document as the CLI uses it from what keys.json holds: the secrets from the keychain when it says so. */
|
|
124
|
+
export declare function openKeys(home: string, raw: unknown): unknown;
|
|
125
|
+
/**
|
|
126
|
+
* The device signing seed for the person token (projects.ts), read synchronously: from keys.json,
|
|
127
|
+
* or from the keychain when keys.json says so. Undefined when it can't be read.
|
|
128
|
+
*/
|
|
129
|
+
export declare function signingSeedSync(home: string): string | undefined;
|
|
130
|
+
/** Throws the keychain's error when this home's keys are in a keychain that can't be read now; else nothing. */
|
|
131
|
+
export declare function assertKeysReadable(home: string): void;
|
|
132
|
+
/** Whether this home's keys are in a keychain that can't be read now. */
|
|
133
|
+
export declare function keysUnreadable(home: string): boolean;
|
|
134
|
+
/** What CliState's backend is (state.ts CliBackend), restated here to keep this module free of state.ts. */
|
|
135
|
+
export interface DocStore {
|
|
136
|
+
read(name: string): Promise<unknown>;
|
|
137
|
+
write(name: string, value: unknown): Promise<void>;
|
|
138
|
+
remove?(name: string): Promise<void>;
|
|
139
|
+
withLock<T>(fn: () => Promise<T>): Promise<T>;
|
|
140
|
+
}
|
|
141
|
+
/** Removes the wipe files a move left behind (zeroed where safe: zeroAndRemove). Returns how many there were. */
|
|
142
|
+
export declare function sweepWipeLeftovers(home: string): Promise<number>;
|
|
143
|
+
/**
|
|
144
|
+
* CliState's backend with the keys document routed: written to the keychain when the home chose it
|
|
145
|
+
* (keystore.json), read from wherever keys.json says. Every other document passes through.
|
|
146
|
+
*/
|
|
147
|
+
export declare class KeyStoreBackend implements DocStore {
|
|
148
|
+
readonly inner: DocStore;
|
|
149
|
+
readonly home: string;
|
|
150
|
+
/** A read-only run's overlay (readonly.ts): writes stay in memory, never reach the keychain. */
|
|
151
|
+
private readonly opts;
|
|
152
|
+
constructor(inner: DocStore, home: string,
|
|
153
|
+
/** A read-only run's overlay (readonly.ts): writes stay in memory, never reach the keychain. */
|
|
154
|
+
opts?: {
|
|
155
|
+
memoryOnly?: boolean;
|
|
156
|
+
});
|
|
157
|
+
read(name: string): Promise<unknown>;
|
|
158
|
+
/** keys.json as it is on disk (sealed or not). */
|
|
159
|
+
readRaw(): Promise<unknown>;
|
|
160
|
+
write(name: string, value: unknown): Promise<void>;
|
|
161
|
+
remove(name: string): Promise<void>;
|
|
162
|
+
withLock<T>(fn: () => Promise<T>): Promise<T>;
|
|
163
|
+
}
|
|
164
|
+
export interface KeyStoreStatus {
|
|
165
|
+
/** Where new keys are written (keystore.json). */
|
|
166
|
+
configured: KeyBackend;
|
|
167
|
+
/** Where this device's keys are now: none (no identity here yet), file or keychain. */
|
|
168
|
+
keys: "none" | "file" | "keychain";
|
|
169
|
+
/** Whether they could be read just now. */
|
|
170
|
+
readable: boolean;
|
|
171
|
+
/** What is wrong, in words, when something is. */
|
|
172
|
+
problem?: string;
|
|
173
|
+
/** The OS keychain p2p uses on this platform. */
|
|
174
|
+
keychain: {
|
|
175
|
+
kind?: Keychain["kind"];
|
|
176
|
+
label: string;
|
|
177
|
+
available: boolean;
|
|
178
|
+
why?: string;
|
|
179
|
+
};
|
|
180
|
+
/** keychain: the item's service name and account (not secret). */
|
|
181
|
+
item?: {
|
|
182
|
+
service: string;
|
|
183
|
+
account: string;
|
|
184
|
+
};
|
|
185
|
+
/** Wipe files an interrupted move left in `cli/` (they may hold the old keys.json's bytes). */
|
|
186
|
+
leftovers?: string[];
|
|
187
|
+
}
|
|
188
|
+
/** Where this home's keys are and whether they can be read (no secret in it). Read only. */
|
|
189
|
+
export declare function keyStoreStatus(home: string): KeyStoreStatus;
|
|
190
|
+
export interface MoveResult {
|
|
191
|
+
backend: KeyBackend;
|
|
192
|
+
/** Whether keys were moved (false: there were none yet, or they were there already). */
|
|
193
|
+
moved: boolean;
|
|
194
|
+
/** Where new keys go from now on, in words. */
|
|
195
|
+
where: string;
|
|
196
|
+
item?: {
|
|
197
|
+
service: string;
|
|
198
|
+
account: string;
|
|
199
|
+
};
|
|
200
|
+
warnings: string[];
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Moves this home's keys into the keychain: stored, read back and compared byte for byte, and only
|
|
204
|
+
* then keys.json loses its secrets (its old bytes overwritten). Each step can be repeated: an
|
|
205
|
+
* interrupted move is finished by running it again (or by the next command that loads the keys).
|
|
206
|
+
*/
|
|
207
|
+
export declare function moveKeysToKeychain(store: KeyStoreBackend): Promise<MoveResult>;
|
|
208
|
+
/**
|
|
209
|
+
* Moves this home's keys back into keys.json: written and read back first, then the keychain item
|
|
210
|
+
* is deleted. Fails closed: keys that can't be read from the keychain stay there.
|
|
211
|
+
*/
|
|
212
|
+
export declare function moveKeysToFiles(store: KeyStoreBackend): Promise<MoveResult>;
|
|
213
|
+
/**
|
|
214
|
+
* A home that chose the keychain whose keys.json holds secrets (a move that was interrupted, or a
|
|
215
|
+
* rotation or follow that swapped in a new identity's files): moves them now. Called on load by
|
|
216
|
+
* commands that may write; never by read-only ones. Returns a warning when it couldn't.
|
|
217
|
+
*/
|
|
218
|
+
export declare function finishPendingMove(store: KeyStoreBackend): Promise<string | undefined>;
|
|
219
|
+
/** Stores, reads back and deletes a throwaway item under `service`; throws when any of it fails. Its secret is random, never a key. */
|
|
220
|
+
export declare function probeKeychain(kc: Keychain, service: string): void;
|
|
221
|
+
/** Best effort: deletes this home's keychain item for device `did` (a half-made identity that was wiped). */
|
|
222
|
+
export declare function forgetKeychainItem(home: string, did: string | undefined): void;
|
|
223
|
+
export {};
|