@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
package/Cargo.lock
CHANGED
|
@@ -14,15 +14,15 @@ dependencies = [
|
|
|
14
14
|
|
|
15
15
|
[[package]]
|
|
16
16
|
name = "ai-vault"
|
|
17
|
-
version = "0.
|
|
17
|
+
version = "0.9.1"
|
|
18
18
|
dependencies = [
|
|
19
19
|
"base64",
|
|
20
20
|
"chacha20poly1305",
|
|
21
21
|
"chrono",
|
|
22
22
|
"clap",
|
|
23
|
+
"fs4",
|
|
23
24
|
"getrandom",
|
|
24
25
|
"hmac",
|
|
25
|
-
"libc",
|
|
26
26
|
"scrypt",
|
|
27
27
|
"serde",
|
|
28
28
|
"serde_json",
|
|
@@ -75,7 +75,7 @@ version = "1.1.5"
|
|
|
75
75
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
76
76
|
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
|
|
77
77
|
dependencies = [
|
|
78
|
-
"windows-sys",
|
|
78
|
+
"windows-sys 0.61.2",
|
|
79
79
|
]
|
|
80
80
|
|
|
81
81
|
[[package]]
|
|
@@ -86,7 +86,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
|
|
|
86
86
|
dependencies = [
|
|
87
87
|
"anstyle",
|
|
88
88
|
"once_cell_polyfill",
|
|
89
|
-
"windows-sys",
|
|
89
|
+
"windows-sys 0.61.2",
|
|
90
90
|
]
|
|
91
91
|
|
|
92
92
|
[[package]]
|
|
@@ -107,6 +107,12 @@ version = "1.8.3"
|
|
|
107
107
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
108
108
|
checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
|
|
109
109
|
|
|
110
|
+
[[package]]
|
|
111
|
+
name = "bitflags"
|
|
112
|
+
version = "2.13.2"
|
|
113
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
114
|
+
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
|
115
|
+
|
|
110
116
|
[[package]]
|
|
111
117
|
name = "block-buffer"
|
|
112
118
|
version = "0.10.4"
|
|
@@ -267,12 +273,32 @@ dependencies = [
|
|
|
267
273
|
"subtle",
|
|
268
274
|
]
|
|
269
275
|
|
|
276
|
+
[[package]]
|
|
277
|
+
name = "errno"
|
|
278
|
+
version = "0.3.15"
|
|
279
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
280
|
+
checksum = "e35d6e78f4cebb90e51d543db8fe41528851d6deeef6ef21ebd4bfdc1e784776"
|
|
281
|
+
dependencies = [
|
|
282
|
+
"libc",
|
|
283
|
+
"windows-sys 0.61.2",
|
|
284
|
+
]
|
|
285
|
+
|
|
270
286
|
[[package]]
|
|
271
287
|
name = "find-msvc-tools"
|
|
272
288
|
version = "0.1.16"
|
|
273
289
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
274
290
|
checksum = "3e44f110d1777dc6559a51e7d45083945ded4f1bf3305494350f693b6d20b9c8"
|
|
275
291
|
|
|
292
|
+
[[package]]
|
|
293
|
+
name = "fs4"
|
|
294
|
+
version = "0.13.1"
|
|
295
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
296
|
+
checksum = "8640e34b88f7652208ce9e88b1a37a2ae95227d84abec377ccd3c5cfeb141ed4"
|
|
297
|
+
dependencies = [
|
|
298
|
+
"rustix",
|
|
299
|
+
"windows-sys 0.59.0",
|
|
300
|
+
]
|
|
301
|
+
|
|
276
302
|
[[package]]
|
|
277
303
|
name = "futures-core"
|
|
278
304
|
version = "0.3.34"
|
|
@@ -395,6 +421,12 @@ version = "0.2.191"
|
|
|
395
421
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
396
422
|
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
397
423
|
|
|
424
|
+
[[package]]
|
|
425
|
+
name = "linux-raw-sys"
|
|
426
|
+
version = "0.12.1"
|
|
427
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
428
|
+
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
|
|
429
|
+
|
|
398
430
|
[[package]]
|
|
399
431
|
name = "log"
|
|
400
432
|
version = "0.4.35"
|
|
@@ -493,6 +525,19 @@ dependencies = [
|
|
|
493
525
|
"getrandom",
|
|
494
526
|
]
|
|
495
527
|
|
|
528
|
+
[[package]]
|
|
529
|
+
name = "rustix"
|
|
530
|
+
version = "1.1.6"
|
|
531
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
532
|
+
checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa"
|
|
533
|
+
dependencies = [
|
|
534
|
+
"bitflags",
|
|
535
|
+
"errno",
|
|
536
|
+
"libc",
|
|
537
|
+
"linux-raw-sys",
|
|
538
|
+
"windows-sys 0.61.2",
|
|
539
|
+
]
|
|
540
|
+
|
|
496
541
|
[[package]]
|
|
497
542
|
name = "rustversion"
|
|
498
543
|
version = "1.0.23"
|
|
@@ -763,6 +808,15 @@ dependencies = [
|
|
|
763
808
|
"windows-link",
|
|
764
809
|
]
|
|
765
810
|
|
|
811
|
+
[[package]]
|
|
812
|
+
name = "windows-sys"
|
|
813
|
+
version = "0.59.0"
|
|
814
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
815
|
+
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
|
816
|
+
dependencies = [
|
|
817
|
+
"windows-targets",
|
|
818
|
+
]
|
|
819
|
+
|
|
766
820
|
[[package]]
|
|
767
821
|
name = "windows-sys"
|
|
768
822
|
version = "0.61.2"
|
|
@@ -772,6 +826,70 @@ dependencies = [
|
|
|
772
826
|
"windows-link",
|
|
773
827
|
]
|
|
774
828
|
|
|
829
|
+
[[package]]
|
|
830
|
+
name = "windows-targets"
|
|
831
|
+
version = "0.52.6"
|
|
832
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
833
|
+
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
|
834
|
+
dependencies = [
|
|
835
|
+
"windows_aarch64_gnullvm",
|
|
836
|
+
"windows_aarch64_msvc",
|
|
837
|
+
"windows_i686_gnu",
|
|
838
|
+
"windows_i686_gnullvm",
|
|
839
|
+
"windows_i686_msvc",
|
|
840
|
+
"windows_x86_64_gnu",
|
|
841
|
+
"windows_x86_64_gnullvm",
|
|
842
|
+
"windows_x86_64_msvc",
|
|
843
|
+
]
|
|
844
|
+
|
|
845
|
+
[[package]]
|
|
846
|
+
name = "windows_aarch64_gnullvm"
|
|
847
|
+
version = "0.52.6"
|
|
848
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
849
|
+
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
|
850
|
+
|
|
851
|
+
[[package]]
|
|
852
|
+
name = "windows_aarch64_msvc"
|
|
853
|
+
version = "0.52.6"
|
|
854
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
855
|
+
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
|
856
|
+
|
|
857
|
+
[[package]]
|
|
858
|
+
name = "windows_i686_gnu"
|
|
859
|
+
version = "0.52.6"
|
|
860
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
861
|
+
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
|
862
|
+
|
|
863
|
+
[[package]]
|
|
864
|
+
name = "windows_i686_gnullvm"
|
|
865
|
+
version = "0.52.6"
|
|
866
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
867
|
+
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
|
868
|
+
|
|
869
|
+
[[package]]
|
|
870
|
+
name = "windows_i686_msvc"
|
|
871
|
+
version = "0.52.6"
|
|
872
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
873
|
+
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
|
874
|
+
|
|
875
|
+
[[package]]
|
|
876
|
+
name = "windows_x86_64_gnu"
|
|
877
|
+
version = "0.52.6"
|
|
878
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
879
|
+
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
|
880
|
+
|
|
881
|
+
[[package]]
|
|
882
|
+
name = "windows_x86_64_gnullvm"
|
|
883
|
+
version = "0.52.6"
|
|
884
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
885
|
+
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
|
886
|
+
|
|
887
|
+
[[package]]
|
|
888
|
+
name = "windows_x86_64_msvc"
|
|
889
|
+
version = "0.52.6"
|
|
890
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
891
|
+
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
|
892
|
+
|
|
775
893
|
[[package]]
|
|
776
894
|
name = "zeroize"
|
|
777
895
|
version = "1.9.2"
|
package/README.md
CHANGED
|
@@ -58,6 +58,34 @@ printf '//registry.npmjs.org/:_authToken=%s\n' "<token>" > ~/.npmrc && chmod 600
|
|
|
58
58
|
|
|
59
59
|
别的平台要有自己的二进制包:`./scripts/stage-npm.sh darwin-arm64 --from <交叉编译产物>`,发布后把对应名字加进 `optionalDependencies`。没有匹配的平台包时,shim 会明确报错并提示 `cargo install --path crates/ai-vault`。
|
|
60
60
|
|
|
61
|
+
### 平台
|
|
62
|
+
|
|
63
|
+
| 平台 | 状态 |
|
|
64
|
+
|---|---|
|
|
65
|
+
| Linux x64 / arm64 | ✅ 已发布(`@xiaolikt/ai-vault-linux-x64` / `-linux-arm64`) |
|
|
66
|
+
| Windows x64 | ✅ 已发布(`@xiaolikt/ai-vault-win32-x64`),对话框走 PowerShell/WinForms |
|
|
67
|
+
| macOS arm64 / x64 | 🔧 代码已可编译(`cargo check --target aarch64-apple-darwin` 通过),二进制需要 Apple SDK —— 由 `.github/workflows/build.yml` 的 macOS runner 产出 |
|
|
68
|
+
|
|
69
|
+
跨平台的部分:
|
|
70
|
+
- **加密/存储**:纯 Rust(chacha20poly1305、scrypt、hmac、sha2、base64、zeroize)
|
|
71
|
+
- **文件锁**:`fs4`(Linux/macOS 用 flock,Windows 用 LockFileEx)
|
|
72
|
+
- **权限**:Unix 设 0600/0700;Windows 没有位权限,靠 `%USERPROFILE%\.ai-vault` 的 ACL
|
|
73
|
+
- **会话目录**:Linux `$XDG_RUNTIME_DIR`、macOS `$TMPDIR`、Windows `%TEMP%`(都是每人一份、可被系统清理)
|
|
74
|
+
- **弹窗**:Linux zenity / macOS osascript / Windows PowerShell+WinForms,同一套 `Answer` 契约(`NoUi` 才回退到宿主输入框)
|
|
75
|
+
|
|
76
|
+
自己交叉编译(不需要 Mac/Windows 机器):
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
cargo install cargo-zigbuild
|
|
80
|
+
rustup target add aarch64-unknown-linux-gnu x86_64-pc-windows-gnu
|
|
81
|
+
cargo zigbuild --release --target aarch64-unknown-linux-gnu
|
|
82
|
+
cargo zigbuild --release --target x86_64-pc-windows-gnu
|
|
83
|
+
./scripts/stage-npm.sh linux-arm64 --from target/aarch64-unknown-linux-gnu/release/ai-vault
|
|
84
|
+
./scripts/stage-npm.sh win32-x64 --from target/x86_64-pc-windows-gnu/release/ai-vault.exe
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`stage-npm.sh` 两种写法都收:npm 平台名(`darwin-arm64`)或 Rust triple(`aarch64-apple-darwin`)。macOS 的二进制只能用 Apple SDK 链,所以留给 CI(tag push 时自动构建 + 发布)。
|
|
88
|
+
|
|
61
89
|
### 从源码 / git
|
|
62
90
|
|
|
63
91
|
```bash
|
|
@@ -93,8 +121,9 @@ ai-vault [--dir DIR] [--json] <命令>
|
|
|
93
121
|
| `init [--password-stdin]` | 建库(弹窗两次设密码),成功后直接给一个令牌 |
|
|
94
122
|
| `unlock [--password-stdin] [--requester ID]` | 按当前模式解锁,stdout 一个令牌 |
|
|
95
123
|
| `mode [get]` / `mode set never\|time\|session [--hours N]` | 查看/切换解锁模式(切换要主密码) |
|
|
96
|
-
| `settings [键] [值]` | 全部设置:`vault
|
|
124
|
+
| `settings [键] [值]` | 全部设置:`vault.*` `bitwarden.*` `ente.unlock` `ente.hours` |
|
|
97
125
|
| `bw-session get\|put\|clear` | Bitwarden 会话密钥的落盘副本(`bitwarden.unlock != session` 时用,加密封存) |
|
|
126
|
+
| `ente-session get\|put\|clear` | Ente 的 `ENTE_CLI_VAULT_KEY`(`ente.unlock != session` 时用,同样加密封存) |
|
|
98
127
|
| `rekey` | 把旧库的 scrypt 参数升到当前默认(要主密码) |
|
|
99
128
|
| `status --token T` | 条目数、过期时间、还活着的读授权 |
|
|
100
129
|
| `lock --token T \| --all` | 丢掉令牌(`--all` 清空本机所有会话) |
|
|
@@ -149,6 +178,8 @@ ai-vault get <条目> --token <T> --answer-stdin --approval <hex> <<< 'y'
|
|
|
149
178
|
| `ente_list` | Ente Auth 条目元数据(名称/签发方/账号/类型) | read | 否 |
|
|
150
179
|
| `ente_code` | 读一条当前 TOTP/Steam 验证码,每次弹窗确认 | write | 是,用户当场允许 |
|
|
151
180
|
|
|
181
|
+
Ente 的会话由 `ente` 自己管(登录一次);`ente.unlock` 只决定那把 `ENTE_CLI_VAULT_KEY` 要不要由 ai-vault 加密封存。
|
|
182
|
+
|
|
152
183
|
字段选择:`password`(默认)· `totp`(种子)· `code`(动态验证码)· `notes` · `field:<自定义字段名>`。
|
|
153
184
|
|
|
154
185
|
### 查询顺序:本地优先,Bitwarden 兜底
|
|
@@ -264,6 +295,15 @@ export ENTE_CLI_VAULT_KEY=<那个 key> # 之后连钥匙串都不用
|
|
|
264
295
|
|
|
265
296
|
所以在 `session` 这种日常形态下,**每次查看不会再要你的密码**,最多要一次系统钥匙串解锁。
|
|
266
297
|
|
|
298
|
+
想连钥匙串都不要(无人值守):
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
ente vault key generate # 打印一个 key,拿一次就固定
|
|
302
|
+
/vault ente-key # 在弹窗里粘进去,ai-vault 把它加密封存
|
|
303
|
+
/vault settings ente.unlock never # 之后 ente 子进程自动带上它
|
|
304
|
+
```
|
|
305
|
+
`ente.unlock` 和 `bitwarden.unlock` 是同一套三档(`never`/`time`/`session`),`ente-session get|put|clear` 是它的 CLI 入口;密钥用库目录的 wrap key 封存(0600),单独拷走 `ente.session.json` 解不开。插件永远不会把你 shell 里导出的 `ENTE_CLI_VAULT_KEY` 传给子进程——只有它自己封存的那把会。
|
|
306
|
+
|
|
267
307
|
pi-ai-vault 只是这套 CLI 的客户端,本身不保存 Ente 的任何密钥:
|
|
268
308
|
|
|
269
309
|
| 工具 | 作用 |
|
package/bin/ai-vault.cjs
CHANGED
|
@@ -29,6 +29,12 @@ function candidates() {
|
|
|
29
29
|
// A source checkout: package root/target/{release,debug}/ai-vault.
|
|
30
30
|
const root = join(__dirname, "..");
|
|
31
31
|
found.push(join(root, "target", "release", EXE), join(root, "target", "debug", EXE));
|
|
32
|
+
// Windows has no exec bit and npm links .cmd/.ps1 wrappers: try the whole set.
|
|
33
|
+
if (process.platform === "win32") {
|
|
34
|
+
for (const name of ["ai-vault.exe", "ai-vault.cmd", "ai-vault.ps1"]) {
|
|
35
|
+
found.push(join(root, "target", "release", name), join(root, "target", "debug", name));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
32
38
|
return found.filter((path) => path && path !== __filename);
|
|
33
39
|
}
|
|
34
40
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "ai-vault"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.9.1"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
description = "Machine-wide encrypted secret store shared by AI coding agents"
|
|
6
6
|
license = "MIT"
|
|
@@ -17,11 +17,10 @@ chrono = { version = "0.4", default-features = false, features = ["clock", "std"
|
|
|
17
17
|
clap = { version = "4", features = ["derive", "env"] }
|
|
18
18
|
getrandom = "0.2"
|
|
19
19
|
hmac = "0.12"
|
|
20
|
+
fs4 = { version = "0.13", features = ["sync"] }
|
|
20
21
|
scrypt = "0.11"
|
|
21
22
|
serde = { version = "1", features = ["derive"] }
|
|
22
23
|
serde_json = "1"
|
|
23
24
|
sha2 = "0.10"
|
|
24
25
|
zeroize = "1"
|
|
25
26
|
|
|
26
|
-
[target.'cfg(unix)'.dependencies]
|
|
27
|
-
libc = "0.2"
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
//! Records who asked for what, never a value. A full or read-only disk is not
|
|
4
4
|
//! allowed to break the operation being audited.
|
|
5
5
|
|
|
6
|
-
use std::fs
|
|
6
|
+
use std::fs;
|
|
7
7
|
use std::io::Write;
|
|
8
|
-
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
|
9
8
|
use std::path::Path;
|
|
10
9
|
|
|
11
10
|
use serde::{Deserialize, Serialize};
|
|
@@ -37,20 +36,19 @@ pub fn append(path: &Path, session: &str, event: &str, item: Option<&str>, reaso
|
|
|
37
36
|
};
|
|
38
37
|
if let Some(dir) = path.parent() {
|
|
39
38
|
let _ = fs::create_dir_all(dir);
|
|
40
|
-
|
|
39
|
+
crate::perms::restrict_dir(dir);
|
|
41
40
|
}
|
|
42
41
|
if let Ok(meta) = fs::metadata(path) {
|
|
43
42
|
if meta.len() > MAX_BYTES {
|
|
44
43
|
let _ = fs::rename(path, path.with_extension("log.1"));
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
|
-
let result = OpenOptions::new()
|
|
46
|
+
let result = std::fs::OpenOptions::new()
|
|
48
47
|
.create(true)
|
|
49
48
|
.append(true)
|
|
50
|
-
.mode(0o600)
|
|
51
49
|
.open(path)
|
|
52
50
|
.and_then(|mut file| {
|
|
53
|
-
|
|
51
|
+
crate::perms::restrict_file(path);
|
|
54
52
|
file.write_all(format!("{line}\n").as_bytes())
|
|
55
53
|
});
|
|
56
54
|
result.is_ok()
|
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
//! these commands and never links against the encryption itself.
|
|
4
4
|
|
|
5
5
|
use std::io::{self, BufRead, Read};
|
|
6
|
-
use std::os::unix::fs::PermissionsExt;
|
|
7
6
|
use std::path::PathBuf;
|
|
8
7
|
|
|
9
8
|
use clap::{Parser, Subcommand};
|
|
10
9
|
use serde_json::json;
|
|
11
10
|
|
|
12
|
-
use crate::
|
|
11
|
+
use crate::sealed::{self, Kind};
|
|
13
12
|
use crate::config::{self, ImportPolicy, UnlockMode, UnlockPolicy};
|
|
14
13
|
use crate::crypto::{self, Kdf};
|
|
15
14
|
use crate::dialog::{self, Answer};
|
|
@@ -84,6 +83,11 @@ enum Cmd {
|
|
|
84
83
|
/// get | put | clear
|
|
85
84
|
action: String,
|
|
86
85
|
},
|
|
86
|
+
/// Ente's `ENTE_CLI_VAULT_KEY` (ente.unlock = never | time)
|
|
87
|
+
EnteSession {
|
|
88
|
+
/// get | put | clear
|
|
89
|
+
action: String,
|
|
90
|
+
},
|
|
87
91
|
/// Show or change how often the master password is asked for
|
|
88
92
|
Mode {
|
|
89
93
|
/// "get" or "set"
|
|
@@ -291,7 +295,7 @@ fn migrate_legacy(paths: &Paths) {
|
|
|
291
295
|
if std::fs::copy(&legacy_store, paths.store()).is_err() {
|
|
292
296
|
return;
|
|
293
297
|
}
|
|
294
|
-
|
|
298
|
+
crate::perms::restrict_file(&paths.store());
|
|
295
299
|
if legacy.join("audit.log").exists() && !paths.audit().exists() {
|
|
296
300
|
let _ = std::fs::copy(legacy.join("audit.log"), paths.audit());
|
|
297
301
|
}
|
|
@@ -321,7 +325,8 @@ fn dispatch(cmd: Cmd, paths: &Paths, json: bool) -> Outcome {
|
|
|
321
325
|
Cmd::Settings { key, value, password_stdin } => {
|
|
322
326
|
settings(paths, &out, key.as_deref(), value.as_deref(), None, password_stdin)
|
|
323
327
|
}
|
|
324
|
-
Cmd::BwSession { action } =>
|
|
328
|
+
Cmd::BwSession { action } => sealed_session(paths, &out, Kind::Bitwarden, &action),
|
|
329
|
+
Cmd::EnteSession { action } => sealed_session(paths, &out, Kind::Ente, &action),
|
|
325
330
|
Cmd::Mode { action, value, hours, password_stdin } => {
|
|
326
331
|
mode(paths, &out, &action, value.as_deref(), hours, password_stdin)
|
|
327
332
|
}
|
|
@@ -488,7 +493,7 @@ fn signing_key(paths: &Paths) -> Result<Option<String>, String> {
|
|
|
488
493
|
if let Some(secret) = host_secret() {
|
|
489
494
|
return Ok(Some(secret));
|
|
490
495
|
}
|
|
491
|
-
|
|
496
|
+
sealed::wrap_key_hex(paths).map(Some)
|
|
492
497
|
}
|
|
493
498
|
|
|
494
499
|
/// The host integration (the extension) is recognised by the secret it
|
|
@@ -496,6 +501,13 @@ fn signing_key(paths: &Paths) -> Result<Option<String>, String> {
|
|
|
496
501
|
/// and is treated like a human caller until it has a secret to sign with.
|
|
497
502
|
/// This keeps a half-configured host from getting a session it can neither
|
|
498
503
|
/// verify nor relay for.
|
|
504
|
+
fn kind_label(kind: Kind) -> &'static str {
|
|
505
|
+
match kind {
|
|
506
|
+
Kind::Bitwarden => "bitwarden",
|
|
507
|
+
Kind::Ente => "ente",
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
499
511
|
fn is_host() -> bool {
|
|
500
512
|
std::env::var_os("AI_VAULT_HOST").is_some_and(|v| v == "1") && host_secret().is_some()
|
|
501
513
|
}
|
|
@@ -749,12 +761,15 @@ fn setting_key(raw: &str) -> Option<&'static str> {
|
|
|
749
761
|
"bitwarden.unlock" | "bitwarden.mode" | "bw.unlock" | "bw.mode" => Some("bitwarden.unlock"),
|
|
750
762
|
"bitwarden.hours" | "bw.hours" => Some("bitwarden.hours"),
|
|
751
763
|
"bitwarden.import" | "bw.import" | "import" => Some("bitwarden.import"),
|
|
764
|
+
"ente.unlock" | "ente.mode" => Some("ente.unlock"),
|
|
765
|
+
"ente.hours" => Some("ente.hours"),
|
|
752
766
|
_ => None,
|
|
753
767
|
}
|
|
754
768
|
}
|
|
755
769
|
|
|
756
770
|
fn settings_value(config: &config::Config, paths: &Paths) -> serde_json::Value {
|
|
757
|
-
let bw_saved =
|
|
771
|
+
let bw_saved = sealed::load(paths, Kind::Bitwarden).ok().flatten();
|
|
772
|
+
let ente_saved = sealed::load(paths, Kind::Ente).ok().flatten();
|
|
758
773
|
json!({
|
|
759
774
|
"ok": true,
|
|
760
775
|
"vault": {
|
|
@@ -763,12 +778,18 @@ fn settings_value(config: &config::Config, paths: &Paths) -> serde_json::Value {
|
|
|
763
778
|
"auto": paths.auto_session().exists(),
|
|
764
779
|
},
|
|
765
780
|
"bitwarden": {
|
|
766
|
-
"unlock": config.bitwarden.unlock.as_str(),
|
|
767
|
-
"hours": config.bitwarden.hours,
|
|
781
|
+
"unlock": config.bitwarden.store.unlock.as_str(),
|
|
782
|
+
"hours": config.bitwarden.store.hours,
|
|
768
783
|
"import": config.bitwarden.import.as_str(),
|
|
769
784
|
"persisted": bw_saved.is_some(),
|
|
770
785
|
"expiresAt": bw_saved.as_ref().and_then(|s| s.expires_at),
|
|
771
786
|
},
|
|
787
|
+
"ente": {
|
|
788
|
+
"unlock": config.ente.unlock.as_str(),
|
|
789
|
+
"hours": config.ente.hours,
|
|
790
|
+
"persisted": ente_saved.is_some(),
|
|
791
|
+
"expiresAt": ente_saved.as_ref().and_then(|s| s.expires_at),
|
|
792
|
+
},
|
|
772
793
|
})
|
|
773
794
|
}
|
|
774
795
|
|
|
@@ -780,12 +801,15 @@ fn settings_human(config: &config::Config, paths: &Paths) -> String {
|
|
|
780
801
|
"vault 机器级会话: {}",
|
|
781
802
|
if paths.auto_session().exists() { "有(免密)" } else { "无" }
|
|
782
803
|
),
|
|
783
|
-
format!("bitwarden.unlock: {} (never | time | session)", config.bitwarden.unlock.as_str()),
|
|
784
|
-
format!("bitwarden.hours: {}", config.bitwarden.hours),
|
|
804
|
+
format!("bitwarden.unlock: {} (never | time | session)", config.bitwarden.store.unlock.as_str()),
|
|
805
|
+
format!("bitwarden.hours: {}", config.bitwarden.store.hours),
|
|
785
806
|
format!("bitwarden.import: {} (ask | always | never)", config.bitwarden.import.as_str()),
|
|
807
|
+
format!("ente.unlock: {} (never | time | session)", config.ente.unlock.as_str()),
|
|
808
|
+
format!("ente.hours: {}", config.ente.hours),
|
|
809
|
+
format!("ente 已落盘的密钥: {}", if sealed::load(paths, Kind::Ente).ok().flatten().is_some() { "有" } else { "无" }),
|
|
786
810
|
format!(
|
|
787
811
|
"bitwarden 已落盘的会话: {}",
|
|
788
|
-
match
|
|
812
|
+
match sealed::load(paths, Kind::Bitwarden).ok().flatten() {
|
|
789
813
|
Some(saved) => match saved.expires_at {
|
|
790
814
|
Some(at) => format!("有({} 后过期)", ((at - session::now_ms()) / 60_000).max(0)),
|
|
791
815
|
None => "有(不过期)".to_string(),
|
|
@@ -822,8 +846,10 @@ fn settings(
|
|
|
822
846
|
let shown = match key {
|
|
823
847
|
"vault.unlock" => config.unlock.mode.as_str().to_string(),
|
|
824
848
|
"vault.hours" => config.unlock.hours.to_string(),
|
|
825
|
-
"bitwarden.unlock" => config.bitwarden.unlock.as_str().to_string(),
|
|
826
|
-
"bitwarden.hours" => config.bitwarden.hours.to_string(),
|
|
849
|
+
"bitwarden.unlock" => config.bitwarden.store.unlock.as_str().to_string(),
|
|
850
|
+
"bitwarden.hours" => config.bitwarden.store.hours.to_string(),
|
|
851
|
+
"ente.unlock" => config.ente.unlock.as_str().to_string(),
|
|
852
|
+
"ente.hours" => config.ente.hours.to_string(),
|
|
827
853
|
_ => config.bitwarden.import.as_str().to_string(),
|
|
828
854
|
};
|
|
829
855
|
out.value(json!({ "ok": true, "key": key, "value": shown }), || format!("{key}: {shown}"));
|
|
@@ -866,21 +892,40 @@ fn settings(
|
|
|
866
892
|
"bitwarden.unlock" => {
|
|
867
893
|
let mode = UnlockMode::parse(raw_value)
|
|
868
894
|
.ok_or_else(|| Fault::Usage(format!("unknown mode \"{raw_value}\" — never, time or session")))?;
|
|
869
|
-
config.bitwarden.unlock = mode;
|
|
895
|
+
config.bitwarden.store.unlock = mode;
|
|
870
896
|
if let Some(hours) = hours {
|
|
871
|
-
config.bitwarden.hours = hours.clamp(1, 24 * 90);
|
|
897
|
+
config.bitwarden.store.hours = hours.clamp(1, 24 * 90);
|
|
872
898
|
}
|
|
873
899
|
config::save(paths, &config)?;
|
|
874
900
|
// Going back to per-session must not leave a key on disk.
|
|
875
901
|
if mode == UnlockMode::Session {
|
|
876
|
-
|
|
902
|
+
sealed::clear(paths, Kind::Bitwarden);
|
|
877
903
|
}
|
|
878
904
|
}
|
|
879
905
|
"bitwarden.hours" => {
|
|
880
906
|
let hours: i64 = raw_value
|
|
881
907
|
.parse()
|
|
882
908
|
.map_err(|_| Fault::Usage(format!("\"{raw_value}\" is not a number of hours")))?;
|
|
883
|
-
config.bitwarden.hours = hours.clamp(1, 24 * 90);
|
|
909
|
+
config.bitwarden.store.hours = hours.clamp(1, 24 * 90);
|
|
910
|
+
config::save(paths, &config)?;
|
|
911
|
+
}
|
|
912
|
+
"ente.unlock" => {
|
|
913
|
+
let mode = UnlockMode::parse(raw_value)
|
|
914
|
+
.ok_or_else(|| Fault::Usage(format!("unknown mode \"{raw_value}\" — never, time or session")))?;
|
|
915
|
+
config.ente.unlock = mode;
|
|
916
|
+
if let Some(hours) = hours {
|
|
917
|
+
config.ente.hours = hours.clamp(1, 24 * 90);
|
|
918
|
+
}
|
|
919
|
+
config::save(paths, &config)?;
|
|
920
|
+
if mode == UnlockMode::Session {
|
|
921
|
+
sealed::clear(paths, Kind::Ente);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
"ente.hours" => {
|
|
925
|
+
let hours: i64 = raw_value
|
|
926
|
+
.parse()
|
|
927
|
+
.map_err(|_| Fault::Usage(format!("\"{raw_value}\" is not a number of hours")))?;
|
|
928
|
+
config.ente.hours = hours.clamp(1, 24 * 90);
|
|
884
929
|
config::save(paths, &config)?;
|
|
885
930
|
}
|
|
886
931
|
_ => {
|
|
@@ -913,12 +958,13 @@ fn mode(
|
|
|
913
958
|
}
|
|
914
959
|
}
|
|
915
960
|
|
|
916
|
-
fn
|
|
961
|
+
fn sealed_session(paths: &Paths, out: &Out, kind: Kind, action: &str) -> Outcome {
|
|
917
962
|
match action.trim() {
|
|
918
963
|
"" | "get" => {
|
|
919
|
-
let stored =
|
|
920
|
-
.ok_or_else(|| Fault::Auth("no persisted
|
|
921
|
-
let key =
|
|
964
|
+
let stored = sealed::load(paths, kind)?
|
|
965
|
+
.ok_or_else(|| Fault::Auth(format!("no persisted {} secret — save one first", kind_label(kind))))?;
|
|
966
|
+
let key = sealed::key(paths, kind)?
|
|
967
|
+
.ok_or_else(|| Fault::Auth(format!("no persisted {} secret", kind_label(kind))))?;
|
|
922
968
|
out.value(
|
|
923
969
|
json!({ "ok": true, "key": key, "savedAt": stored.saved_at, "expiresAt": stored.expires_at }),
|
|
924
970
|
|| key,
|
|
@@ -930,8 +976,8 @@ fn bw_session(paths: &Paths, out: &Out, action: &str) -> Outcome {
|
|
|
930
976
|
if key.is_empty() {
|
|
931
977
|
return Err(Fault::Usage("bw-session put expects the session key on stdin".into()));
|
|
932
978
|
}
|
|
933
|
-
let expires_at =
|
|
934
|
-
audit::append(&paths.audit(), "cli", "
|
|
979
|
+
let expires_at = sealed::save(paths, kind, &key)?;
|
|
980
|
+
audit::append(&paths.audit(), "cli", "sealed", None, Some(kind_label(kind)));
|
|
935
981
|
out.value(json!({ "ok": true, "expiresAt": expires_at }), || {
|
|
936
982
|
match expires_at {
|
|
937
983
|
Some(at) => format!("saved (expires in {} min)", ((at - session::now_ms()) / 60_000).max(0)),
|
|
@@ -941,14 +987,14 @@ fn bw_session(paths: &Paths, out: &Out, action: &str) -> Outcome {
|
|
|
941
987
|
Ok(())
|
|
942
988
|
}
|
|
943
989
|
"clear" | "delete" => {
|
|
944
|
-
let removed =
|
|
945
|
-
audit::append(&paths.audit(), "cli", "
|
|
990
|
+
let removed = sealed::clear(paths, kind);
|
|
991
|
+
audit::append(&paths.audit(), "cli", "sealed", None, Some(kind_label(kind)));
|
|
946
992
|
out.value(json!({ "ok": true, "removed": removed }), || {
|
|
947
993
|
if removed { "cleared".to_string() } else { "nothing stored".to_string() }
|
|
948
994
|
});
|
|
949
995
|
Ok(())
|
|
950
996
|
}
|
|
951
|
-
other => Err(Fault::Usage(format!("unknown
|
|
997
|
+
other => Err(Fault::Usage(format!("unknown session action \"{other}\" (get, put, clear)"))),
|
|
952
998
|
}
|
|
953
999
|
}
|
|
954
1000
|
|
|
@@ -90,15 +90,28 @@ impl Default for UnlockPolicy {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/// How a third-party CLI's credential is kept on disk.
|
|
93
94
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
|
94
|
-
pub struct
|
|
95
|
-
/// `never` keeps the
|
|
96
|
-
///
|
|
97
|
-
/// deadline; `session` (default)
|
|
95
|
+
pub struct StorePolicy {
|
|
96
|
+
/// `never` keeps the credential in the store directory (sealed), so the
|
|
97
|
+
/// CLI needs no keychain or password; `time` does the same with a
|
|
98
|
+
/// deadline; `session` (default) leaves it in the CLI's own keychain.
|
|
98
99
|
#[serde(default = "default_bw_mode")]
|
|
99
100
|
pub unlock: UnlockMode,
|
|
100
101
|
#[serde(default = "default_hours")]
|
|
101
102
|
pub hours: i64,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
impl Default for StorePolicy {
|
|
106
|
+
fn default() -> Self {
|
|
107
|
+
StorePolicy { unlock: default_bw_mode(), hours: default_hours() }
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
|
112
|
+
pub struct BitwardenPolicy {
|
|
113
|
+
#[serde(flatten)]
|
|
114
|
+
pub store: StorePolicy,
|
|
102
115
|
#[serde(default = "default_import")]
|
|
103
116
|
pub import: ImportPolicy,
|
|
104
117
|
}
|
|
@@ -113,7 +126,7 @@ fn default_import() -> ImportPolicy {
|
|
|
113
126
|
|
|
114
127
|
impl Default for BitwardenPolicy {
|
|
115
128
|
fn default() -> Self {
|
|
116
|
-
BitwardenPolicy {
|
|
129
|
+
BitwardenPolicy { store: StorePolicy::default(), import: default_import() }
|
|
117
130
|
}
|
|
118
131
|
}
|
|
119
132
|
|
|
@@ -123,6 +136,10 @@ pub struct Config {
|
|
|
123
136
|
pub unlock: UnlockPolicy,
|
|
124
137
|
#[serde(default)]
|
|
125
138
|
pub bitwarden: BitwardenPolicy,
|
|
139
|
+
/// Ente's `ENTE_CLI_VAULT_KEY`: `session` leaves it to the OS keychain,
|
|
140
|
+
/// `never`/`time` keep it sealed next to the store.
|
|
141
|
+
#[serde(default)]
|
|
142
|
+
pub ente: StorePolicy,
|
|
126
143
|
}
|
|
127
144
|
|
|
128
145
|
/// A missing or unreadable config means the defaults. A broken file must not
|
|
@@ -156,7 +173,8 @@ mod tests {
|
|
|
156
173
|
fn defaults_are_the_cautious_ones() {
|
|
157
174
|
let config = Config::default();
|
|
158
175
|
assert_eq!(config.unlock.mode, UnlockMode::Session);
|
|
159
|
-
assert_eq!(config.bitwarden.unlock, UnlockMode::Session);
|
|
176
|
+
assert_eq!(config.bitwarden.store.unlock, UnlockMode::Session);
|
|
177
|
+
assert_eq!(config.ente.unlock, UnlockMode::Session);
|
|
160
178
|
assert_eq!(config.bitwarden.import, ImportPolicy::Ask);
|
|
161
179
|
}
|
|
162
180
|
|
|
@@ -166,6 +184,6 @@ mod tests {
|
|
|
166
184
|
let parsed: Config = serde_json::from_str(r#"{"unlock":{"mode":"time","hours":4}}"#).unwrap();
|
|
167
185
|
assert_eq!(parsed.unlock.mode, UnlockMode::Time);
|
|
168
186
|
assert_eq!(parsed.bitwarden.import, ImportPolicy::Ask);
|
|
169
|
-
assert_eq!(parsed.bitwarden.hours, 8);
|
|
187
|
+
assert_eq!(parsed.bitwarden.store.hours, 8);
|
|
170
188
|
}
|
|
171
189
|
}
|