@xiaolikt/ai-vault 0.8.0 → 0.9.1
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/Cargo.lock +122 -4
- package/README.md +41 -1
- package/bin/ai-vault.cjs +6 -0
- package/crates/ai-vault/Cargo.toml +2 -3
- package/crates/ai-vault/src/audit.rs +4 -6
- package/crates/ai-vault/src/cli.rs +72 -26
- package/crates/ai-vault/src/config.rs +25 -7
- package/crates/ai-vault/src/crypto.rs +4 -11
- package/crates/ai-vault/src/dialog.rs +285 -7
- package/crates/ai-vault/src/main.rs +2 -1
- package/crates/ai-vault/src/paths.rs +30 -13
- package/crates/ai-vault/src/perms.rs +54 -0
- package/crates/ai-vault/src/{bwsession.rs → sealed.rs} +50 -24
- package/crates/ai-vault/src/session.rs +9 -21
- package/package.json +4 -2
- package/packages/pi-ai-vault/README.md +3 -1
- package/packages/pi-ai-vault/package.json +2 -2
- package/packages/pi-ai-vault/src/cli.ts +15 -6
- package/packages/pi-ai-vault/src/ente.ts +27 -1
- package/packages/pi-ai-vault/src/index.ts +23 -1
- package/packages/pi-ai-vault/src/settings.ts +3 -0
- package/test/cli.sh +17 -4
- package/test/npm.sh +14 -1
- package/tests/ente.test.mjs +51 -0
- package/tests/helpers.mjs +3 -0
- package/tests/mocks/bin/ente +7 -0
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
|
|
17
17
|
use std::collections::BTreeMap;
|
|
18
18
|
use std::fs;
|
|
19
|
-
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
|
20
19
|
|
|
21
20
|
use base64::engine::general_purpose::STANDARD as B64;
|
|
22
21
|
use base64::Engine as _;
|
|
@@ -158,7 +157,7 @@ impl Session {
|
|
|
158
157
|
signed.sign(host_secret);
|
|
159
158
|
let dir = paths.sessions();
|
|
160
159
|
fs::create_dir_all(&dir).map_err(|e| format!("cannot create {}: {e}", dir.display()))?;
|
|
161
|
-
|
|
160
|
+
crate::perms::restrict_dir(&dir);
|
|
162
161
|
let text = serde_json::to_vec(&signed).map_err(|e| format!("cannot serialize session: {e}"))?;
|
|
163
162
|
crypto::write_atomic(&paths.session_file(&signed.token), &text)
|
|
164
163
|
}
|
|
@@ -277,7 +276,7 @@ pub fn load_auto(paths: &Paths) -> Result<Option<Session>, String> {
|
|
|
277
276
|
|
|
278
277
|
pub fn save_auto(paths: &Paths, session: &Session) -> Result<(), String> {
|
|
279
278
|
fs::create_dir_all(&paths.dir).map_err(|e| format!("cannot create {}: {e}", paths.dir.display()))?;
|
|
280
|
-
|
|
279
|
+
crate::perms::restrict_dir(&paths.dir);
|
|
281
280
|
let bytes = serde_json::to_vec(session).map_err(|e| format!("cannot serialize session: {e}"))?;
|
|
282
281
|
crypto::write_atomic(&paths.auto_session(), &bytes)
|
|
283
282
|
}
|
|
@@ -294,8 +293,8 @@ pub fn ensure_session_dir(paths: &Paths) -> Result<(), String> {
|
|
|
294
293
|
fs::create_dir_all(&paths.dir).map_err(|e| format!("cannot create {}: {e}", paths.dir.display()))?;
|
|
295
294
|
let dir = paths.sessions();
|
|
296
295
|
fs::create_dir_all(&dir).map_err(|e| format!("cannot create {}: {e}", dir.display()))?;
|
|
297
|
-
|
|
298
|
-
|
|
296
|
+
crate::perms::restrict_dir(&dir);
|
|
297
|
+
crate::perms::restrict_dir(&paths.dir);
|
|
299
298
|
Ok(())
|
|
300
299
|
}
|
|
301
300
|
|
|
@@ -314,30 +313,19 @@ impl StoreLock {
|
|
|
314
313
|
.create(true)
|
|
315
314
|
.read(true)
|
|
316
315
|
.write(true)
|
|
317
|
-
.mode(0o600)
|
|
318
316
|
.open(&path)
|
|
319
317
|
.map_err(|e| format!("cannot open {}: {e}", path.display()))?;
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if rc != 0 {
|
|
325
|
-
return Err(format!("cannot lock {}: {}", path.display(), std::io::Error::last_os_error()));
|
|
326
|
-
}
|
|
327
|
-
}
|
|
318
|
+
crate::perms::restrict_file(&path);
|
|
319
|
+
// fs4 takes an OS lock on Unix (flock), Windows (LockFileEx) and macOS.
|
|
320
|
+
<fs::File as fs4::fs_std::FileExt>::lock_exclusive(&file)
|
|
321
|
+
.map_err(|e| format!("cannot lock {}: {e}", path.display()))?;
|
|
328
322
|
Ok(StoreLock { file, path })
|
|
329
323
|
}
|
|
330
324
|
}
|
|
331
325
|
|
|
332
326
|
impl Drop for StoreLock {
|
|
333
327
|
fn drop(&mut self) {
|
|
334
|
-
|
|
335
|
-
{
|
|
336
|
-
use std::os::unix::io::AsRawFd;
|
|
337
|
-
unsafe {
|
|
338
|
-
libc::flock(self.file.as_raw_fd(), libc::LOCK_UN);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
328
|
+
let _ = <fs::File as fs4::fs_std::FileExt>::unlock(&self.file);
|
|
341
329
|
let _ = &self.path;
|
|
342
330
|
}
|
|
343
331
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiaolikt/ai-vault",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "One machine-wide encrypted secret store for AI coding agents: the ai-vault Rust CLI (npm-installable) plus the pi-ai-vault extension for pi and omp.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,7 +33,9 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"optionalDependencies": {
|
|
36
|
-
"@xiaolikt/ai-vault-linux-x64": "0.
|
|
36
|
+
"@xiaolikt/ai-vault-linux-x64": "0.9.1",
|
|
37
|
+
"@xiaolikt/ai-vault-linux-arm64": "0.9.1",
|
|
38
|
+
"@xiaolikt/ai-vault-win32-x64": "0.9.1"
|
|
37
39
|
},
|
|
38
40
|
"files": [
|
|
39
41
|
"bin",
|
|
@@ -65,7 +65,9 @@ omp plugin install npm:pi-ai-vault # omp,同一个包
|
|
|
65
65
|
|
|
66
66
|
## Ente
|
|
67
67
|
|
|
68
|
-
`ente` CLI 自己登录一次(`ente account login --app auth`),插件只是它的客户端:`ente_list` 只给元数据,`ente_code`
|
|
68
|
+
`ente` CLI 自己登录一次(`ente account login --app auth`),插件只是它的客户端:`ente_list` 只给元数据,`ente_code` 每次弹窗确认。
|
|
69
|
+
|
|
70
|
+
想完全免钥匙串:`ente vault key generate` → `/vault ente-key` 粘进去 → `/vault settings ente.unlock never`。密钥由 ai-vault 加密封存。详见仓库 README。
|
|
69
71
|
|
|
70
72
|
## 安全边界(一句话版)
|
|
71
73
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ai-vault",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "pi extension for ai-vault: one machine-wide encrypted secret store plus live Bitwarden. Works in pi and in omp (the omp fork reads the same manifest).",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"security"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@xiaolikt/ai-vault": "0.
|
|
28
|
+
"@xiaolikt/ai-vault": "0.9.1"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@earendil-works/pi-coding-agent": "^1.5.0",
|
|
@@ -64,20 +64,29 @@ export function resolveBinary(): string | undefined {
|
|
|
64
64
|
// pip/npm layouts hoist differently: walk up from packages/pi-ai-vault/src.
|
|
65
65
|
let dir = dirname(fileURLToPath(import.meta.url));
|
|
66
66
|
for (let depth = 0; depth < 5; depth++) {
|
|
67
|
-
const
|
|
68
|
-
|
|
67
|
+
for (const name of process.platform === "win32" ? ["ai-vault.exe", "ai-vault.cmd", "ai-vault.ps1"] : ["ai-vault"]) {
|
|
68
|
+
const bundled = join(dir, "node_modules", ".bin", name);
|
|
69
|
+
if (existsSync(bundled)) return bundled;
|
|
70
|
+
}
|
|
69
71
|
const parent = dirname(dir);
|
|
70
72
|
if (parent === dir) break;
|
|
71
73
|
dir = parent;
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
// Windows has no execute bit and npm links .cmd/.ps1 wrappers beside the exe.
|
|
77
|
+
const names = process.platform === "win32" ? ["ai-vault.exe", "ai-vault.cmd", "ai-vault.ps1", "ai-vault"] : ["ai-vault"];
|
|
74
78
|
for (const entry of (process.env.PATH ?? "").split(delimiter)) {
|
|
75
79
|
if (!entry) continue;
|
|
76
|
-
const
|
|
77
|
-
|
|
80
|
+
for (const name of names) {
|
|
81
|
+
const candidate = join(entry, name);
|
|
82
|
+
if (existsSync(candidate)) return candidate;
|
|
83
|
+
}
|
|
78
84
|
}
|
|
79
|
-
for (const
|
|
80
|
-
|
|
85
|
+
for (const base of [join(homedir(), ".local", "bin"), join(homedir(), ".cargo", "bin"), join(homedir(), ".ai-vault", "bin")]) {
|
|
86
|
+
for (const name of names) {
|
|
87
|
+
const candidate = join(base, name);
|
|
88
|
+
if (existsSync(candidate)) return candidate;
|
|
89
|
+
}
|
|
81
90
|
}
|
|
82
91
|
return undefined;
|
|
83
92
|
}
|
|
@@ -25,6 +25,7 @@ import { Type } from "typebox";
|
|
|
25
25
|
import { auditEvent } from "./bitwarden.js";
|
|
26
26
|
import { confirmWindow, forDialog } from "./prompt.js";
|
|
27
27
|
import { withTier } from "./host.js";
|
|
28
|
+
import { getSettingsSafe, settingsCli } from "./settings.js";
|
|
28
29
|
|
|
29
30
|
export interface EnteCodeMeta {
|
|
30
31
|
id: string;
|
|
@@ -74,12 +75,37 @@ interface Run {
|
|
|
74
75
|
stderr: string;
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
/**
|
|
79
|
+
* The environment for one `ente` run.
|
|
80
|
+
*
|
|
81
|
+
* `ente.unlock = never | time`: the key is kept sealed by ai-vault (the same
|
|
82
|
+
* wrapping as the Bitwarden session), so Ente needs neither the OS keychain
|
|
83
|
+
* nor a login window. `session` (default) leaves the keychain in charge and
|
|
84
|
+
* passes nothing.
|
|
85
|
+
*/
|
|
86
|
+
async function enteEnv(signal?: AbortSignal): Promise<Record<string, string | undefined>> {
|
|
87
|
+
const env: Record<string, string | undefined> = { ...process.env };
|
|
88
|
+
// Never let a key the user exported in their shell decide this.
|
|
89
|
+
delete env.ENTE_CLI_VAULT_KEY;
|
|
90
|
+
const settings = await getSettingsSafe(signal);
|
|
91
|
+
if (settings.ente.unlock === "session") return env;
|
|
92
|
+
try {
|
|
93
|
+
const sealed = await settingsCli().json<{ key: string }>(["ente-session", "get"], { signal });
|
|
94
|
+
if (sealed?.key) env.ENTE_CLI_VAULT_KEY = sealed.key;
|
|
95
|
+
} catch {
|
|
96
|
+
// No key saved yet, or it expired: ente will fall back to the keychain,
|
|
97
|
+
// which is exactly what a `session` policy would have done.
|
|
98
|
+
}
|
|
99
|
+
return env;
|
|
100
|
+
}
|
|
101
|
+
|
|
77
102
|
async function runEnte(args: string[], signal?: AbortSignal): Promise<Run> {
|
|
78
103
|
const bin = resolveEnte();
|
|
79
104
|
if (!bin) throw new EnteError(ENTE_MISSING, 127);
|
|
80
105
|
if (signal?.aborted) throw new EnteError("Cancelled.", 4);
|
|
106
|
+
const env = await enteEnv(signal);
|
|
81
107
|
return new Promise<Run>((resolve, reject) => {
|
|
82
|
-
const child = spawn(bin, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
108
|
+
const child = spawn(bin, args, { stdio: ["ignore", "pipe", "pipe"], env });
|
|
83
109
|
let stdout = "";
|
|
84
110
|
let stderr = "";
|
|
85
111
|
const onAbort = () => child.kill("SIGKILL");
|
|
@@ -636,7 +636,8 @@ const HELP = [
|
|
|
636
636
|
"/vault init 创建全机共享的本地加密库(弹出窗口设置主密码)",
|
|
637
637
|
"/vault unlock | lock 解锁 / 锁定(清空本会话的授权)",
|
|
638
638
|
"/vault mode [never|time|session] 查看/切换解锁模式(切换要主密码)",
|
|
639
|
-
"/vault settings [键 值] 查看/修改设置(vault.unlock、bitwarden
|
|
639
|
+
"/vault settings [键 值] 查看/修改设置(vault.unlock、bitwarden.*、ente.* …)",
|
|
640
|
+
"/vault ente-key 保存 ente 的 ENTE_CLI_VAULT_KEY(免钥匙串/免登录)",
|
|
640
641
|
"/vault status 状态与授权剩余时间",
|
|
641
642
|
"/vault list 本地条目元数据",
|
|
642
643
|
"/vault add [名称] 新增本地条目(用户名、密码在弹窗里输入)",
|
|
@@ -711,6 +712,9 @@ function settingsText(s: Settings): string {
|
|
|
711
712
|
`bitwarden.hours: ${s.bitwarden.hours}`,
|
|
712
713
|
`bitwarden.import: ${s.bitwarden.import} (ask | always | never)`,
|
|
713
714
|
`bitwarden 已落盘的会话: ${persisted}`,
|
|
715
|
+
`ente.unlock: ${s.ente.unlock} (never | time | session)`,
|
|
716
|
+
`ente.hours: ${s.ente.hours}`,
|
|
717
|
+
`ente 已落盘的密钥: ${s.ente.persisted ? "有" : "无"}`,
|
|
714
718
|
].join("\n");
|
|
715
719
|
}
|
|
716
720
|
|
|
@@ -782,6 +786,24 @@ function commandHandler(scope: Scope, bw: BwState) {
|
|
|
782
786
|
}
|
|
783
787
|
return;
|
|
784
788
|
}
|
|
789
|
+
case "ente-key": {
|
|
790
|
+
// Ente's unattended key: generated by `ente vault key generate`.
|
|
791
|
+
// Saved sealed, so `ente.unlock = never | time` can use it.
|
|
792
|
+
const key = await promptSecret(dialogs(ctx), "ai-vault · Ente 密钥", "ente vault key generate 输出的密钥");
|
|
793
|
+
if (!key) {
|
|
794
|
+
note(ctx, "已取消", "warning");
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
try {
|
|
798
|
+
const args = ["ente-session", "put"];
|
|
799
|
+
await cli.run(args, { stdin: key });
|
|
800
|
+
forgetSettings();
|
|
801
|
+
note(ctx, "已保存(封存)。现在可以设置 /vault settings ente.unlock never");
|
|
802
|
+
} catch (error) {
|
|
803
|
+
note(ctx, `ai-vault: ${describe(error)}`, "error");
|
|
804
|
+
}
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
785
807
|
case "settings": {
|
|
786
808
|
const [key, ...valueParts] = rest;
|
|
787
809
|
const value = valueParts.join(" ").trim();
|
|
@@ -19,11 +19,14 @@ export interface Settings {
|
|
|
19
19
|
persisted: boolean;
|
|
20
20
|
expiresAt: number | null;
|
|
21
21
|
};
|
|
22
|
+
/** Ente's ENTE_CLI_VAULT_KEY: session leaves it to the OS keychain. */
|
|
23
|
+
ente: { unlock: UnlockModeName; hours: number; persisted: boolean; expiresAt: number | null };
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export const DEFAULT_SETTINGS: Settings = {
|
|
25
27
|
vault: { unlock: "session", hours: 8, auto: false },
|
|
26
28
|
bitwarden: { unlock: "session", hours: 8, import: "ask", persisted: false, expiresAt: null },
|
|
29
|
+
ente: { unlock: "session", hours: 8, persisted: false, expiresAt: null },
|
|
27
30
|
};
|
|
28
31
|
|
|
29
32
|
const cli = new VaultCli();
|
package/test/cli.sh
CHANGED
|
@@ -22,6 +22,8 @@ mkdir -p "$HOME"
|
|
|
22
22
|
PASS=0
|
|
23
23
|
FAIL=0
|
|
24
24
|
ok() { printf ' PASS %s\n' "$*"; PASS=$((PASS + 1)); }
|
|
25
|
+
# GNU stat (-c) vs BSD stat (-f): the mode, in octal, on either.
|
|
26
|
+
mode_of() { stat -c %a "$1" 2>/dev/null || stat -f %Lp "$1"; }
|
|
25
27
|
bad() { printf ' FAIL %s\n' "$*"; FAIL=$((FAIL + 1)); }
|
|
26
28
|
# check <description> <expected-exit> <command...>
|
|
27
29
|
check() {
|
|
@@ -43,7 +45,7 @@ grep -q 'needs-ui: password' "$TMP/err" && ok "the needs-ui step is named" || ba
|
|
|
43
45
|
check "a short password is a usage error" 2 bash -c "printf 'short' | '$BIN' init --password-stdin"
|
|
44
46
|
check "init creates the store" 0 bash -c "printf 'correct horse' | '$BIN' init --password-stdin --requester cli"
|
|
45
47
|
[[ -f "$AI_VAULT_DIR/store.json" ]] && ok "store.json exists" || bad "store.json missing"
|
|
46
|
-
[[ "$(
|
|
48
|
+
[[ "$(mode_of "$AI_VAULT_DIR/store.json")" == "600" ]] && ok "store.json is 0600" || bad "store.json is not 0600"
|
|
47
49
|
|
|
48
50
|
echo "== unlock =="
|
|
49
51
|
check "unlock without a window asks the host" 3 "$BIN" unlock
|
|
@@ -148,13 +150,24 @@ check "switch bitwarden.unlock to never" 0 "$BIN" settings bitwarden.unlock neve
|
|
|
148
150
|
check "store a bw session key" 0 bash -c "printf 'BW_BEARER_TOKEN_PLAINTEXT' | '$BIN' bw-session put --json"
|
|
149
151
|
grep -q 'BW_BEARER_TOKEN_PLAINTEXT' "$AI_VAULT_DIR/bitwarden.session.json" && bad "the bw key is plaintext on disk" || ok "the bw key is not plaintext on disk"
|
|
150
152
|
[[ -f "$AI_VAULT_DIR/.wrap" ]] && ok "a wrap key exists" || bad "no wrap key"
|
|
151
|
-
[[ "$(
|
|
153
|
+
[[ "$(mode_of "$AI_VAULT_DIR/.wrap")" == "600" ]] && ok "the wrap key is 0600" || bad "the wrap key is not 0600"
|
|
152
154
|
"$BIN" bw-session get --json | grep -q 'BW_BEARER_TOKEN_PLAINTEXT' && ok "bw-session get unseals it" || bad "bw-session get cannot unseal"
|
|
153
155
|
mv "$AI_VAULT_DIR/.wrap" "$TMP/wrap.bak"
|
|
154
156
|
check "without the wrap key the session does not open" 1 "$BIN" bw-session get
|
|
155
157
|
mv "$TMP/wrap.bak" "$AI_VAULT_DIR/.wrap"
|
|
156
158
|
"$BIN" settings bitwarden.unlock session --json >/dev/null
|
|
157
159
|
|
|
160
|
+
echo "== ente sealed key (M4 pattern) =="
|
|
161
|
+
check "ente.unlock is readable" 0 "$BIN" settings ente.unlock --json
|
|
162
|
+
check "ente-session put refused in session mode" 1 bash -c "printf 'K' | '$BIN' ente-session put"
|
|
163
|
+
check "switch ente.unlock to never" 0 "$BIN" settings ente.unlock never --json
|
|
164
|
+
check "store the Ente vault key" 0 bash -c "printf 'ENTE_KEY_PLAINTEXT' | '$BIN' ente-session put --json"
|
|
165
|
+
grep -q 'ENTE_KEY_PLAINTEXT' "$AI_VAULT_DIR/ente.session.json" && bad "the ente key is plaintext on disk" || ok "the ente key is sealed at rest"
|
|
166
|
+
[[ "$(mode_of "$AI_VAULT_DIR/ente.session.json")" == "600" ]] && ok "ente.session.json is 0600" || bad "ente.session.json is not 0600"
|
|
167
|
+
"$BIN" ente-session get --json | grep -q 'ENTE_KEY_PLAINTEXT' && ok "ente-session get unseals it" || bad "ente-session get cannot unseal"
|
|
168
|
+
"$BIN" settings ente.unlock session --json >/dev/null
|
|
169
|
+
check "switching back to session clears the ente key" 5 "$BIN" ente-session get
|
|
170
|
+
|
|
158
171
|
echo "== rekey (L2) =="
|
|
159
172
|
OLD_N=$(python3 -c "import json;print(json.load(open('$AI_VAULT_DIR/store.json'))['kdf']['N'])")
|
|
160
173
|
check "rekey with the password" 0 bash -c "printf 'correct horse' | '$BIN' rekey --password-stdin --json"
|
|
@@ -170,7 +183,7 @@ python3 - "$TMP/audit" <<'PY' && ok "the audit log records events without values
|
|
|
170
183
|
import json,sys
|
|
171
184
|
entries = json.load(open(sys.argv[1]))["entries"]
|
|
172
185
|
events = {e["event"] for e in entries}
|
|
173
|
-
for want in ("init", "unlock", "unlock_failed", "add", "grant", "read_deny", "read_allow", "remove", "import", "lock", "rekey", "
|
|
186
|
+
for want in ("init", "unlock", "unlock_failed", "add", "grant", "read_deny", "read_allow", "remove", "import", "lock", "rekey", "sealed"):
|
|
174
187
|
assert want in events, (want, events)
|
|
175
188
|
assert not any("p1ssw0rd" in json.dumps(e) or "exp-pass" in json.dumps(e) for e in entries)
|
|
176
189
|
PY
|
|
@@ -203,7 +216,7 @@ check "an unknown setting is a usage error" 2 "$BIN" settings nope.value 1
|
|
|
203
216
|
check "bw-session put is refused in session mode" 1 bash -c "printf 'K' | '$BIN' bw-session put"
|
|
204
217
|
check "switch bitwarden.unlock to never" 0 "$BIN" settings bitwarden.unlock never --json
|
|
205
218
|
check "bw-session put stores the key" 0 bash -c "printf 'GOOD_SESSION' | '$BIN' bw-session put --json"
|
|
206
|
-
[[ "$(
|
|
219
|
+
[[ "$(mode_of "$AI_VAULT_DIR/bitwarden.session.json")" == "600" ]] && ok "the bw session file is 0600" || bad "the bw session file is not 0600"
|
|
207
220
|
check "bw-session get returns it" 0 "$BIN" bw-session get --json
|
|
208
221
|
check "switch back to session" 0 "$BIN" settings bitwarden.unlock session --json
|
|
209
222
|
check "the stored key is gone" 5 "$BIN" bw-session get
|
package/test/npm.sh
CHANGED
|
@@ -17,7 +17,20 @@ bad() { printf ' FAIL %s\n' "$*"; FAIL=$((FAIL + 1)); }
|
|
|
17
17
|
|
|
18
18
|
echo "== stage the platform package =="
|
|
19
19
|
bash "$ROOT/scripts/stage-npm.sh" >"$TMP/stage" 2>&1 || { cat "$TMP/stage"; exit 1; }
|
|
20
|
-
|
|
20
|
+
# The one that matches this machine: the others are for other OSes and npm
|
|
21
|
+
# refuses to install a tarball whose os/cpu does not match.
|
|
22
|
+
case "$(uname -s)" in
|
|
23
|
+
Linux) OS=linux ;;
|
|
24
|
+
Darwin) OS=darwin ;;
|
|
25
|
+
*) OS=win32 ;;
|
|
26
|
+
esac
|
|
27
|
+
case "$(uname -m)" in
|
|
28
|
+
x86_64|amd64) ARCH=x64 ;;
|
|
29
|
+
aarch64|arm64) ARCH=arm64 ;;
|
|
30
|
+
*) ARCH="$(uname -m)" ;;
|
|
31
|
+
esac
|
|
32
|
+
PLATFORM="$OS-$ARCH"
|
|
33
|
+
[[ -d "$ROOT/npm/$PLATFORM" ]] || PLATFORM="$(cd "$ROOT/npm" && ls -d */ | head -1 | tr -d /)"
|
|
21
34
|
[[ -f "$ROOT/npm/$PLATFORM/bin/ai-vault" ]] && ok "staged $PLATFORM" || bad "nothing staged"
|
|
22
35
|
|
|
23
36
|
echo "== pack =="
|
package/tests/ente.test.mjs
CHANGED
|
@@ -2,8 +2,11 @@ import { test } from "node:test";
|
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
3
|
import { readFileSync, writeFileSync, rmSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
5
6
|
import { answers, bind, cleanUpOnExit, dialogTrace, makeCtx, textOf, useMocks } from "./helpers.mjs";
|
|
6
7
|
|
|
8
|
+
const { forgetSettings } = await import("../packages/pi-ai-vault/src/settings.ts");
|
|
9
|
+
|
|
7
10
|
const dir = useMocks();
|
|
8
11
|
const { default: aiVault } = await import("../packages/pi-ai-vault/src/index.ts");
|
|
9
12
|
cleanUpOnExit(dir);
|
|
@@ -84,3 +87,51 @@ test("a failed sync falls back to the offline cache", async () => {
|
|
|
84
87
|
assert.equal(result.isError, undefined, textOf(result));
|
|
85
88
|
assert.equal(JSON.parse(textOf(result)).length, 3);
|
|
86
89
|
});
|
|
90
|
+
|
|
91
|
+
const enteEnv = () => {
|
|
92
|
+
try {
|
|
93
|
+
return readFileSync(join(dir, "ente.env"), "utf8").trim();
|
|
94
|
+
} catch {
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
test("session mode passes no vault key: the OS keychain stays in charge", async () => {
|
|
100
|
+
const bin = process.env.AI_VAULT_BIN;
|
|
101
|
+
spawnSync(bin, ["settings", "ente.unlock", "session"], { env: process.env });
|
|
102
|
+
forgetSettings();
|
|
103
|
+
const b = bind(aiVault, true);
|
|
104
|
+
await b.tool("ente_list", {}, makeCtx().ctx);
|
|
105
|
+
assert.match(enteEnv(), /^key=$/m);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("ente.unlock=never feeds the sealed key to the ente child", async () => {
|
|
109
|
+
const bin = process.env.AI_VAULT_BIN;
|
|
110
|
+
const set = spawnSync(bin, ["settings", "ente.unlock", "never"], { env: process.env, encoding: "utf8" });
|
|
111
|
+
assert.equal(set.status, 0, set.stderr);
|
|
112
|
+
const put = spawnSync(bin, ["ente-session", "put"], { input: "MY_SECRET_VAULT_KEY", env: process.env, encoding: "utf8" });
|
|
113
|
+
assert.equal(put.status, 0, put.stderr);
|
|
114
|
+
forgetSettings();
|
|
115
|
+
|
|
116
|
+
const b = bind(aiVault, true);
|
|
117
|
+
const result = await b.tool("ente_list", {}, makeCtx().ctx);
|
|
118
|
+
assert.equal(result.isError, undefined, textOf(result));
|
|
119
|
+
assert.match(enteEnv(), /^key=MY_SECRET_VAULT_KEY$/m);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("an inherited ENTE_CLI_VAULT_KEY is not trusted in session mode", async () => {
|
|
123
|
+
const bin = process.env.AI_VAULT_BIN;
|
|
124
|
+
spawnSync(bin, ["settings", "ente.unlock", "session"], { env: process.env });
|
|
125
|
+
spawnSync(bin, ["ente-session", "clear"], { env: process.env });
|
|
126
|
+
forgetSettings();
|
|
127
|
+
const previous = process.env.ENTE_CLI_VAULT_KEY;
|
|
128
|
+
process.env.ENTE_CLI_VAULT_KEY = "LEAKED_FROM_SHELL";
|
|
129
|
+
try {
|
|
130
|
+
const b = bind(aiVault, true);
|
|
131
|
+
await b.tool("ente_list", {}, makeCtx().ctx);
|
|
132
|
+
assert.match(enteEnv(), /^key=$/m, "the shell-exported key must not reach ente");
|
|
133
|
+
} finally {
|
|
134
|
+
if (previous === undefined) delete process.env.ENTE_CLI_VAULT_KEY;
|
|
135
|
+
else process.env.ENTE_CLI_VAULT_KEY = previous;
|
|
136
|
+
}
|
|
137
|
+
});
|
package/tests/helpers.mjs
CHANGED
|
@@ -40,6 +40,9 @@ export function useMocks() {
|
|
|
40
40
|
process.env.ENTE_MOCK_DIR = dir;
|
|
41
41
|
process.env.AI_VAULT_DIR = join(dir, "vault");
|
|
42
42
|
process.env.AI_VAULT_BIN = cliBinary();
|
|
43
|
+
// The extension resolves the CLI from PATH; the tests pass one explicitly.
|
|
44
|
+
// Put the same build first so both halves run the same version.
|
|
45
|
+
process.env.PATH = `${dirname(process.env.AI_VAULT_BIN)}:${process.env.PATH}`;
|
|
43
46
|
return dir;
|
|
44
47
|
}
|
|
45
48
|
|
package/tests/mocks/bin/ente
CHANGED
|
@@ -9,7 +9,14 @@
|
|
|
9
9
|
# the list path never asked for a code.
|
|
10
10
|
DIR="${ENTE_MOCK_DIR:-/tmp/ente-mock}"
|
|
11
11
|
mkdir -p "$DIR"
|
|
12
|
+
# Record whether a vault key reached us and which, so tests can tell a
|
|
13
|
+
# keychain-backed run (nothing) from a sealed-key run (a value).
|
|
12
14
|
printf '%s\n' "$*" >>"$DIR/ente.log"
|
|
15
|
+
if [[ -n "${ENTE_CLI_VAULT_KEY:-}" ]]; then
|
|
16
|
+
printf 'key=%s\n' "$ENTE_CLI_VAULT_KEY" >>"$DIR/ente.env"
|
|
17
|
+
else
|
|
18
|
+
printf 'key=\n' >>"$DIR/ente.env"
|
|
19
|
+
fi
|
|
13
20
|
if [[ -f "$DIR/unauthenticated" ]]; then
|
|
14
21
|
echo "no account logged in; run ente account login --app auth" >&2
|
|
15
22
|
exit 3
|