@mnemonik/credentials 0.1.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/LICENSE +38 -0
- package/dist/contracts.d.ts +104 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +42 -0
- package/dist/contracts.js.map +1 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +596 -0
- package/dist/index.js.map +1 -0
- package/dist/osSecretStore.d.ts +10 -0
- package/dist/osSecretStore.d.ts.map +1 -0
- package/dist/osSecretStore.js +211 -0
- package/dist/osSecretStore.js.map +1 -0
- package/dist/storage.d.ts +52 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +204 -0
- package/dist/storage.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { execFile as nodeExecFile } from 'node:child_process';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
const service = 'mnemonik.credentials.v1';
|
|
4
|
+
const unavailable = () => new Error('os_store_unavailable');
|
|
5
|
+
const cachedReads = new Map();
|
|
6
|
+
// The script is fixed code. Target and UTF-8 secret arrive on separate stdin lines.
|
|
7
|
+
// CredFree/FreeHGlobal run even if marshaling or a native operation fails.
|
|
8
|
+
const windowsCode = `
|
|
9
|
+
using System;
|
|
10
|
+
using System.Runtime.InteropServices;
|
|
11
|
+
using System.Text;
|
|
12
|
+
public class MnemonikCredential {
|
|
13
|
+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
14
|
+
public struct Credential {
|
|
15
|
+
public uint Flags, Type;
|
|
16
|
+
public string TargetName, Comment;
|
|
17
|
+
public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten;
|
|
18
|
+
public uint CredentialBlobSize;
|
|
19
|
+
public IntPtr CredentialBlob;
|
|
20
|
+
public uint Persist, AttributeCount;
|
|
21
|
+
public IntPtr Attributes;
|
|
22
|
+
public string TargetAlias, UserName;
|
|
23
|
+
}
|
|
24
|
+
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
25
|
+
public static extern bool CredWriteW(ref Credential value, uint flags);
|
|
26
|
+
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
27
|
+
public static extern bool CredReadW(string target, uint type, uint flags, out IntPtr value);
|
|
28
|
+
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
29
|
+
public static extern bool CredDeleteW(string target, uint type, uint flags);
|
|
30
|
+
[DllImport("advapi32.dll")]
|
|
31
|
+
public static extern void CredFree(IntPtr value);
|
|
32
|
+
public static int Run(string op, string target, string encoded) {
|
|
33
|
+
bool ok;
|
|
34
|
+
int error = 0;
|
|
35
|
+
if (op == "set") {
|
|
36
|
+
byte[] bytes = Convert.FromBase64String(encoded);
|
|
37
|
+
IntPtr blob = Marshal.AllocHGlobal(bytes.Length);
|
|
38
|
+
try {
|
|
39
|
+
Marshal.Copy(bytes, 0, blob, bytes.Length);
|
|
40
|
+
Credential value = new Credential { Type = 1, TargetName = target, Persist = 2,
|
|
41
|
+
CredentialBlobSize = (uint)bytes.Length, CredentialBlob = blob };
|
|
42
|
+
ok = CredWriteW(ref value, 0);
|
|
43
|
+
if (!ok) error = Marshal.GetLastWin32Error();
|
|
44
|
+
} finally { Marshal.FreeHGlobal(blob); }
|
|
45
|
+
} else if (op == "delete") {
|
|
46
|
+
ok = CredDeleteW(target, 1, 0);
|
|
47
|
+
if (!ok) error = Marshal.GetLastWin32Error();
|
|
48
|
+
} else {
|
|
49
|
+
IntPtr pointer;
|
|
50
|
+
ok = CredReadW(target, 1, 0, out pointer);
|
|
51
|
+
if (!ok) error = Marshal.GetLastWin32Error();
|
|
52
|
+
if (ok) {
|
|
53
|
+
try {
|
|
54
|
+
Credential value = (Credential)Marshal.PtrToStructure(pointer, typeof(Credential));
|
|
55
|
+
byte[] bytes = new byte[value.CredentialBlobSize];
|
|
56
|
+
Marshal.Copy(value.CredentialBlob, bytes, 0, bytes.Length);
|
|
57
|
+
Console.Write(Convert.ToBase64String(bytes));
|
|
58
|
+
} finally { CredFree(pointer); }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return ok ? 0 : error == 1168 ? 3 : 1;
|
|
62
|
+
}
|
|
63
|
+
}`.replace(/\n\s*/gu, ' ');
|
|
64
|
+
function createStore(platform, execFile) {
|
|
65
|
+
let failed = false;
|
|
66
|
+
let availability;
|
|
67
|
+
const kind = platform === 'darwin'
|
|
68
|
+
? 'keychain'
|
|
69
|
+
: platform === 'win32'
|
|
70
|
+
? 'credential-manager'
|
|
71
|
+
: 'secret-service';
|
|
72
|
+
const cacheKey = (name) => `${kind}\0${name}`;
|
|
73
|
+
async function run(file, args, input, missing) {
|
|
74
|
+
if (failed)
|
|
75
|
+
throw unavailable();
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const fail = () => {
|
|
78
|
+
failed = true;
|
|
79
|
+
reject(unavailable());
|
|
80
|
+
};
|
|
81
|
+
try {
|
|
82
|
+
const child = execFile(file, args, {
|
|
83
|
+
encoding: 'utf8',
|
|
84
|
+
timeout: platform === 'win32' ? 60_000 : 10_000,
|
|
85
|
+
maxBuffer: 64 * 1024,
|
|
86
|
+
windowsHide: true,
|
|
87
|
+
}, (error, stdout, stderr) => {
|
|
88
|
+
const code = error?.code;
|
|
89
|
+
const notFound = missing &&
|
|
90
|
+
(platform === 'darwin'
|
|
91
|
+
? code === 44 &&
|
|
92
|
+
stderr.includes('The specified item could not be found in the keychain.')
|
|
93
|
+
: platform === 'win32'
|
|
94
|
+
? code === 3
|
|
95
|
+
: code === 1 && !stderr);
|
|
96
|
+
if (notFound)
|
|
97
|
+
resolve(undefined);
|
|
98
|
+
else if (error)
|
|
99
|
+
fail();
|
|
100
|
+
else
|
|
101
|
+
resolve(stdout);
|
|
102
|
+
});
|
|
103
|
+
child.stdin?.on('error', fail);
|
|
104
|
+
child.stdin?.end(input);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
fail();
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async function operation(op, name, secret = '') {
|
|
112
|
+
try {
|
|
113
|
+
if (failed || !/^[\w.:-]+$/u.test(name))
|
|
114
|
+
throw unavailable();
|
|
115
|
+
if (platform === 'darwin') {
|
|
116
|
+
// security's interactive parser accepts quoted arguments but not embedded line breaks.
|
|
117
|
+
const quote = (value) => `"${value.replace(/[\\"]/gu, '\\$&')}"`;
|
|
118
|
+
const command = op === 'set'
|
|
119
|
+
? 'add-generic-password -U'
|
|
120
|
+
: op === 'get'
|
|
121
|
+
? 'find-generic-password -w'
|
|
122
|
+
: 'delete-generic-password';
|
|
123
|
+
const input = `${command} -a ${quote(name)} -s ${quote(service)}${op === 'set' ? ` -w ${quote(secret)}` : ''}\n`;
|
|
124
|
+
if (/[\r\n\0]/u.test(secret) || Buffer.byteLength(input) >= 4096)
|
|
125
|
+
throw unavailable();
|
|
126
|
+
const result = await run('security', ['-i'], input, op !== 'set');
|
|
127
|
+
return result?.replace(/\r?\n$/u, '');
|
|
128
|
+
}
|
|
129
|
+
if (platform === 'win32') {
|
|
130
|
+
const target = name.startsWith(`${service}:`) ? name : `${service}:${name}`;
|
|
131
|
+
const script = `$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue'; try { Add-Type -TypeDefinition '${windowsCode}'; $target=[Console]::In.ReadLine(); $secret=[Console]::In.ReadLine(); exit [MnemonikCredential]::Run('${op}', $target, $secret) } catch { exit 1 }`;
|
|
132
|
+
const output = await run('powershell', [
|
|
133
|
+
'-NoProfile',
|
|
134
|
+
'-NonInteractive',
|
|
135
|
+
'-EncodedCommand',
|
|
136
|
+
Buffer.from(script, 'utf16le').toString('base64'),
|
|
137
|
+
], `${target}\n${Buffer.from(secret, 'utf8').toString('base64')}\n`, op !== 'set');
|
|
138
|
+
if (output === undefined)
|
|
139
|
+
return undefined;
|
|
140
|
+
if (!/^[A-Za-z0-9+/=\r\n]*$/u.test(output))
|
|
141
|
+
throw unavailable();
|
|
142
|
+
return Buffer.from(output.trim(), 'base64').toString('utf8');
|
|
143
|
+
}
|
|
144
|
+
return await run('secret-tool', [
|
|
145
|
+
op === 'set' ? 'store' : op === 'get' ? 'lookup' : 'clear',
|
|
146
|
+
...(op === 'set' ? ['--label=Mnemonik CLI credential'] : []),
|
|
147
|
+
'service',
|
|
148
|
+
service,
|
|
149
|
+
'name',
|
|
150
|
+
name,
|
|
151
|
+
], op === 'set' ? secret : '', op !== 'set');
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
failed = true;
|
|
155
|
+
throw unavailable();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
kind,
|
|
160
|
+
isAvailable() {
|
|
161
|
+
if (failed)
|
|
162
|
+
return Promise.resolve(false);
|
|
163
|
+
return (availability ??= (async () => {
|
|
164
|
+
const probe = `${service}:probe:${randomUUID()}`;
|
|
165
|
+
if (platform === 'darwin') {
|
|
166
|
+
await run('security', ['-i'], 'default-keychain -d user\n', false);
|
|
167
|
+
await operation('set', probe, 'availability-probe');
|
|
168
|
+
await operation('delete', probe);
|
|
169
|
+
}
|
|
170
|
+
else
|
|
171
|
+
await operation('get', probe);
|
|
172
|
+
return true;
|
|
173
|
+
})().catch(() => false));
|
|
174
|
+
},
|
|
175
|
+
async get(name) {
|
|
176
|
+
const key = cacheKey(name);
|
|
177
|
+
let read = cachedReads.get(key);
|
|
178
|
+
if (!read) {
|
|
179
|
+
read = operation('get', name);
|
|
180
|
+
cachedReads.set(key, read);
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
return await read;
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
if (cachedReads.get(key) === read)
|
|
187
|
+
cachedReads.delete(key);
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
async set(name, secret) {
|
|
192
|
+
await operation('set', name, secret);
|
|
193
|
+
cachedReads.set(cacheKey(name), Promise.resolve(secret));
|
|
194
|
+
},
|
|
195
|
+
async delete(name) {
|
|
196
|
+
await operation('delete', name);
|
|
197
|
+
cachedReads.set(cacheKey(name), Promise.resolve(undefined));
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
let current;
|
|
202
|
+
/** CLI wiring opts in. Production availability/failure is shared for this process. */
|
|
203
|
+
export function osSecretStore(options) {
|
|
204
|
+
const platform = options?.platform ?? process.platform;
|
|
205
|
+
if (!['darwin', 'win32', 'linux'].includes(platform))
|
|
206
|
+
return undefined;
|
|
207
|
+
if (options)
|
|
208
|
+
return createStore(platform, options.execFile ?? nodeExecFile);
|
|
209
|
+
return (current ??= createStore(platform, nodeExecFile));
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=osSecretStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osSecretStore.js","sourceRoot":"","sources":["../src/osSecretStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,OAAO,GAAG,yBAAyB,CAAC;AAG1C,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAC5D,MAAM,WAAW,GAAG,IAAI,GAAG,EAAuC,CAAC;AAEnE,oFAAoF;AACpF,2EAA2E;AAC3E,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuDlB,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AAE3B,SAAS,WAAW,CAAC,QAAyB,EAAE,QAA6B;IAC3E,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,YAA0C,CA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IACvE,IAAI,OAAO;QAAE,OAAO,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,YAAY,CAAC,CAAC;IAC5E,OAAO,CAAC,OAAO,KAAK,WAAW,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Stats } from 'node:fs';
|
|
2
|
+
import { stateDirectory, type ExecFile, type Fault } from '@mnemonik/local-setup';
|
|
3
|
+
export { stateDirectory };
|
|
4
|
+
export type CredentialFailureReason = 'symlink_rejected' | 'wrong_owner' | 'weak_permissions' | 'not_regular_file' | 'path_outside_state' | 'acl_identity_unavailable';
|
|
5
|
+
export declare class CredentialError extends Error {
|
|
6
|
+
readonly reason: CredentialFailureReason;
|
|
7
|
+
constructor(reason: CredentialFailureReason);
|
|
8
|
+
}
|
|
9
|
+
type Lstat = (path: string) => Promise<Stats>;
|
|
10
|
+
export interface SecureFileOptions {
|
|
11
|
+
stateDir?: string;
|
|
12
|
+
platform?: NodeJS.Platform;
|
|
13
|
+
lstat?: Lstat;
|
|
14
|
+
uid?: number;
|
|
15
|
+
fault?: Fault;
|
|
16
|
+
execFile?: ExecFile;
|
|
17
|
+
username?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function credentialPaths(stateDir?: string, familyId?: string): {
|
|
20
|
+
root: string;
|
|
21
|
+
records: string;
|
|
22
|
+
secrets: string;
|
|
23
|
+
cliRecord: string;
|
|
24
|
+
cliSecret: string;
|
|
25
|
+
rootRecord: string;
|
|
26
|
+
rootSecret: string;
|
|
27
|
+
familyRecords: string;
|
|
28
|
+
familySecrets: string;
|
|
29
|
+
record: string;
|
|
30
|
+
secret: string;
|
|
31
|
+
};
|
|
32
|
+
export declare class SecureFiles {
|
|
33
|
+
readonly stateDir: string;
|
|
34
|
+
private readonly platform;
|
|
35
|
+
private readonly lstat;
|
|
36
|
+
private readonly uid;
|
|
37
|
+
private readonly fault?;
|
|
38
|
+
private readonly execFile?;
|
|
39
|
+
private readonly username?;
|
|
40
|
+
constructor(options?: SecureFileOptions);
|
|
41
|
+
private assertInsideState;
|
|
42
|
+
private components;
|
|
43
|
+
private inspect;
|
|
44
|
+
private makeDirectory;
|
|
45
|
+
ensureParent(path: string): Promise<void>;
|
|
46
|
+
read(path: string): Promise<Buffer | null>;
|
|
47
|
+
write(path: string, bytes: Buffer, point: string): Promise<void>;
|
|
48
|
+
remove(path: string): Promise<void>;
|
|
49
|
+
list(path: string): Promise<string[]>;
|
|
50
|
+
removeEmptyDirectories(paths: string[]): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,KAAK,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,EAEL,cAAc,EAEd,KAAK,QAAQ,EACb,KAAK,KAAK,EACX,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B,MAAM,MAAM,uBAAuB,GAC/B,kBAAkB,GAClB,aAAa,GACb,kBAAkB,GAClB,kBAAkB,GAClB,oBAAoB,GACpB,0BAA0B,CAAC;AAE/B,qBAAa,eAAgB,SAAQ,KAAK;aACZ,MAAM,EAAE,uBAAuB;IAA3D,YAA4B,MAAM,EAAE,uBAAuB,EAG1D;CACF;AAED,KAAK,KAAK,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9C,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC3B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,KAAK,CAAC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import { createHash } from 'node:crypto';
|
|
2
|
+
import { lstat as nodeLstat, mkdir, open, readdir, rmdir, unlink } from 'node:fs/promises';
|
|
3
|
+
import { constants } from 'node:fs';
|
|
4
|
+
import { basename, dirname, isAbsolute, join, parse, relative, resolve, sep } from 'node:path';
|
|
5
|
+
import { atomicWrite, stateDirectory, windowsCurrentUserAcl, } from '@mnemonik/local-setup';
|
|
6
|
+
export { stateDirectory };
|
|
7
|
+
export class CredentialError extends Error {
|
|
8
|
+
reason;
|
|
9
|
+
constructor(reason) {
|
|
10
|
+
super(reason);
|
|
11
|
+
this.reason = reason;
|
|
12
|
+
this.name = 'CredentialError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const digest = (value) => createHash('sha256').update(value).digest('hex');
|
|
16
|
+
export function credentialPaths(stateDir = stateDirectory(), familyId) {
|
|
17
|
+
const root = join(stateDir, 'credentials');
|
|
18
|
+
const familyName = familyId ? digest(familyId) : '';
|
|
19
|
+
return {
|
|
20
|
+
root,
|
|
21
|
+
records: join(root, 'records'),
|
|
22
|
+
secrets: join(root, 'secrets'),
|
|
23
|
+
cliRecord: join(root, 'records', 'cli.json'),
|
|
24
|
+
cliSecret: join(root, 'secrets', 'cli.json'),
|
|
25
|
+
rootRecord: join(root, 'records', 'root-binding.json'),
|
|
26
|
+
rootSecret: join(root, 'secrets', 'root-binding.key'),
|
|
27
|
+
familyRecords: join(root, 'records', 'families'),
|
|
28
|
+
familySecrets: join(root, 'secrets', 'families'),
|
|
29
|
+
record: join(root, 'records', 'families', `${familyName}.json`),
|
|
30
|
+
secret: join(root, 'secrets', 'families', `${familyName}.json`),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const codeIs = (error, code) => error.code === code;
|
|
34
|
+
export class SecureFiles {
|
|
35
|
+
stateDir;
|
|
36
|
+
platform;
|
|
37
|
+
lstat;
|
|
38
|
+
uid;
|
|
39
|
+
fault;
|
|
40
|
+
execFile;
|
|
41
|
+
username;
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
this.stateDir = resolve(options.stateDir ?? stateDirectory());
|
|
44
|
+
this.platform = options.platform ?? process.platform;
|
|
45
|
+
this.lstat = options.lstat ?? nodeLstat;
|
|
46
|
+
this.uid = options.uid ?? process.getuid?.();
|
|
47
|
+
this.fault = options.fault;
|
|
48
|
+
this.execFile = options.execFile;
|
|
49
|
+
this.username = options.username;
|
|
50
|
+
}
|
|
51
|
+
assertInsideState(path) {
|
|
52
|
+
const absolute = resolve(path);
|
|
53
|
+
const fromState = relative(this.stateDir, absolute);
|
|
54
|
+
if (fromState === '..' || fromState.startsWith(`..${sep}`) || isAbsolute(fromState))
|
|
55
|
+
throw new CredentialError('path_outside_state');
|
|
56
|
+
return absolute;
|
|
57
|
+
}
|
|
58
|
+
components(path) {
|
|
59
|
+
const absolute = resolve(path);
|
|
60
|
+
const root = parse(absolute).root;
|
|
61
|
+
const parts = absolute.slice(root.length).split(sep).filter(Boolean);
|
|
62
|
+
const result = [];
|
|
63
|
+
let current = root;
|
|
64
|
+
for (const part of parts) {
|
|
65
|
+
current = join(current, part);
|
|
66
|
+
result.push(current);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
async inspect(path, expectFile, allowMissing) {
|
|
71
|
+
const absolute = this.assertInsideState(path);
|
|
72
|
+
for (const component of this.components(absolute)) {
|
|
73
|
+
let value;
|
|
74
|
+
try {
|
|
75
|
+
value = await this.lstat(component);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (allowMissing && codeIs(error, 'ENOENT'))
|
|
79
|
+
continue;
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
if (value.isSymbolicLink())
|
|
83
|
+
throw new CredentialError('symlink_rejected');
|
|
84
|
+
const protectedComponent = component === this.stateDir || component.startsWith(`${this.stateDir}${sep}`);
|
|
85
|
+
if (!protectedComponent || this.platform === 'win32')
|
|
86
|
+
continue;
|
|
87
|
+
if (this.uid !== undefined && value.uid !== this.uid)
|
|
88
|
+
throw new CredentialError('wrong_owner');
|
|
89
|
+
const final = component === absolute;
|
|
90
|
+
const allowed = final && expectFile ? 0o600 : 0o700;
|
|
91
|
+
if ((value.mode & 0o777 & ~allowed) !== 0)
|
|
92
|
+
throw new CredentialError('weak_permissions');
|
|
93
|
+
if (final && expectFile && !value.isFile())
|
|
94
|
+
throw new CredentialError('not_regular_file');
|
|
95
|
+
if (final && !expectFile && !value.isDirectory())
|
|
96
|
+
throw new CredentialError('not_regular_file');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async makeDirectory(path) {
|
|
100
|
+
try {
|
|
101
|
+
await mkdir(path, { mode: 0o700 });
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (!codeIs(error, 'EEXIST'))
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
if (this.platform === 'win32')
|
|
108
|
+
await windowsCurrentUserAcl(path, true, {
|
|
109
|
+
execFile: this.execFile,
|
|
110
|
+
username: this.username,
|
|
111
|
+
});
|
|
112
|
+
await this.inspect(path, false, false);
|
|
113
|
+
}
|
|
114
|
+
async ensureParent(path) {
|
|
115
|
+
const absolute = this.assertInsideState(path);
|
|
116
|
+
await this.inspect(absolute, true, true);
|
|
117
|
+
for (const component of this.components(dirname(absolute))) {
|
|
118
|
+
if (component === this.stateDir || component.startsWith(`${this.stateDir}${sep}`))
|
|
119
|
+
await this.makeDirectory(component);
|
|
120
|
+
}
|
|
121
|
+
await this.inspect(dirname(absolute), false, false);
|
|
122
|
+
}
|
|
123
|
+
async read(path) {
|
|
124
|
+
const absolute = this.assertInsideState(path);
|
|
125
|
+
try {
|
|
126
|
+
await this.inspect(absolute, true, false);
|
|
127
|
+
const noFollow = this.platform === 'win32' ? 0 : constants.O_NOFOLLOW;
|
|
128
|
+
const handle = await open(absolute, constants.O_RDONLY | noFollow);
|
|
129
|
+
try {
|
|
130
|
+
return await handle.readFile();
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
await handle.close();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (codeIs(error, 'ENOENT'))
|
|
138
|
+
return null;
|
|
139
|
+
if (codeIs(error, 'ELOOP'))
|
|
140
|
+
throw new CredentialError('symlink_rejected');
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async write(path, bytes, point) {
|
|
145
|
+
const absolute = this.assertInsideState(path);
|
|
146
|
+
await this.ensureParent(absolute);
|
|
147
|
+
await this.inspect(absolute, true, true);
|
|
148
|
+
try {
|
|
149
|
+
await atomicWrite(absolute, bytes, async (atomicPoint) => {
|
|
150
|
+
await this.fault?.(atomicPoint === 'mid_write' ? `before_${point}_rename` : atomicPoint);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
const prefix = `${basename(absolute)}.`;
|
|
155
|
+
for (const name of await this.list(dirname(absolute))) {
|
|
156
|
+
if (name.startsWith(prefix) && name.endsWith('.tmp'))
|
|
157
|
+
await this.remove(join(dirname(absolute), name));
|
|
158
|
+
}
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
if (this.platform === 'win32')
|
|
162
|
+
await windowsCurrentUserAcl(absolute, false, {
|
|
163
|
+
execFile: this.execFile,
|
|
164
|
+
username: this.username,
|
|
165
|
+
});
|
|
166
|
+
await this.inspect(absolute, true, false);
|
|
167
|
+
}
|
|
168
|
+
async remove(path) {
|
|
169
|
+
const absolute = this.assertInsideState(path);
|
|
170
|
+
try {
|
|
171
|
+
await this.inspect(absolute, true, false);
|
|
172
|
+
await unlink(absolute);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
if (!codeIs(error, 'ENOENT'))
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async list(path) {
|
|
180
|
+
const absolute = this.assertInsideState(path);
|
|
181
|
+
try {
|
|
182
|
+
await this.inspect(absolute, false, false);
|
|
183
|
+
return await readdir(absolute);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
if (codeIs(error, 'ENOENT'))
|
|
187
|
+
return [];
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async removeEmptyDirectories(paths) {
|
|
192
|
+
for (const path of paths) {
|
|
193
|
+
try {
|
|
194
|
+
await this.inspect(path, false, false);
|
|
195
|
+
await rmdir(path);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
if (!codeIs(error, 'ENOENT') && !codeIs(error, 'ENOTEMPTY'))
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAc,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/F,OAAO,EACL,WAAW,EACX,cAAc,EACd,qBAAqB,GAGtB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,CAAC;AAU1B,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACZ,MAAM;IAAlC,YAA4B,MAA+B;QACzD,KAAK,CAAC,MAAM,CAAC,CAAC;sBADY,MAAM;QAEhC,IAAI,CAAC,IAAI,GAAG,iB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,CAAC;YACpB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC;oBAAE,MAAM,KAAK,CAAC;YAC3E,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mnemonik/credentials",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/JayDeeCo-Limited/mnemonik.git",
|
|
7
|
+
"directory": "packages/credentials"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "node ../../node_modules/@typescript/native/bin/tsc",
|
|
23
|
+
"typecheck": "node ../../node_modules/@typescript/native/bin/tsc --noEmit -p tsconfig.test.json",
|
|
24
|
+
"test": "vitest run --config vitest.config.ts tests/credentials.test.ts",
|
|
25
|
+
"prepublishOnly": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=24"
|
|
29
|
+
},
|
|
30
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@mnemonik/local-setup": "0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
36
|
+
"vitest": "^4.1.11"
|
|
37
|
+
}
|
|
38
|
+
}
|