dsh-workbench-vault 0.0.0-stage → 0.3.7
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 +21 -0
- package/README.md +26 -2
- package/cordis.patch.yml +6 -0
- package/lib/client.js +4806 -0
- package/lib/db/db.js +401 -0
- package/lib/domain/actions-sets.js +271 -0
- package/lib/domain/actions.js +532 -0
- package/lib/domain/groups.js +301 -0
- package/lib/domain/migrate.js +128 -0
- package/lib/domain/secret-input.js +33 -0
- package/lib/domain/sets.js +303 -0
- package/lib/domain/vault.js +589 -0
- package/lib/index.js +165 -0
- package/lib/infra/crypto.js +79 -0
- package/package.json +116 -4
package/lib/index.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wb-addon-vault:独立凭据保险箱域。
|
|
3
|
+
* 明文只在 UI reveal 或 plugin lease 时短暂出现;agent 永远拿不到。
|
|
4
|
+
* 0.3.0:集合层(分组 ⊃ 集合 ⊃ 凭据)+ 七种通用凭据类型;密文与口令包裹上云,device key 与使用记录留本机。
|
|
5
|
+
* 0.3.1:凭据表单明文支持小眼睛临时显示;主口令/删除确认改用应用内弹层(桌面端不支持 window.prompt)。
|
|
6
|
+
* 0.3.3:备注两栏合并为单个「备注」(meta.note);新建分组改弹窗并可直接勾选集合。
|
|
7
|
+
* 0.3.4:集合选择改用共享 filter-checklist(关键字搜索 + 滚动分页),任务/站点/储物标签筛选同步复用。
|
|
8
|
+
* 0.3.6:口令输入框统一用共享的明文切换控件(lib/secret-field.cjs),初始化页主/确认口令、解锁页与口令弹层都能点小眼睛看明文,各自独立切换。
|
|
9
|
+
* 0.3.5:修复「保存凭据后列表不新增」——客户端 unwrap 对 ok:false 抛错、锁定态在凭据页提示并可内联解锁、写成功后无条件刷新列表。
|
|
10
|
+
*/
|
|
11
|
+
import { ensureSchema, bindClock } from "./db/db.js";
|
|
12
|
+
import { createVault } from "./domain/vault.js";
|
|
13
|
+
import { createGroups } from "./domain/groups.js";
|
|
14
|
+
import { registerVaultActions } from "./domain/actions.js";
|
|
15
|
+
|
|
16
|
+
export const name = "dsh-workbench-vault";
|
|
17
|
+
export const inject = ["workbench"];
|
|
18
|
+
|
|
19
|
+
export function apply(ctx) {
|
|
20
|
+
const host = ctx.workbench;
|
|
21
|
+
if (!host) throw new Error("wb-addon-vault 依赖 workbench 宿主");
|
|
22
|
+
ctx.effect(() => host.registerDomain(createDomain(host)), "vault-domain");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createDomain(host) {
|
|
26
|
+
let vault = null;
|
|
27
|
+
let groups = null;
|
|
28
|
+
let schemas = [];
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
id: "wb-addon-vault",
|
|
32
|
+
title: "凭据保险箱",
|
|
33
|
+
description: "集中保存密码、应用专用密码与 token;按分组授权给业务模块,加密落库、密文可同步。",
|
|
34
|
+
version: "0.3.7",
|
|
35
|
+
tables: [
|
|
36
|
+
"vault_header",
|
|
37
|
+
"vault_device",
|
|
38
|
+
"vault_group",
|
|
39
|
+
"vault_secret",
|
|
40
|
+
"vault_set",
|
|
41
|
+
"vault_group_set",
|
|
42
|
+
"vault_set_secret",
|
|
43
|
+
"vault_binding",
|
|
44
|
+
"vault_subject_type",
|
|
45
|
+
"vault_secret_usage",
|
|
46
|
+
],
|
|
47
|
+
sync: {
|
|
48
|
+
tables: [
|
|
49
|
+
{ name: "vault_header", mode: "row", uniqueKeys: [["id"]], uniquePolicy: "lww" },
|
|
50
|
+
{ name: "vault_secret", mode: "row", uniqueKeys: [["id"], ["name"]], uniquePolicy: "lww-tombstone" },
|
|
51
|
+
{ name: "vault_group", mode: "row", uniqueKeys: [["id"], ["name"]], uniquePolicy: "lww-tombstone" },
|
|
52
|
+
{
|
|
53
|
+
name: "vault_binding",
|
|
54
|
+
mode: "row",
|
|
55
|
+
uniqueKeys: [["id"], ["subject_type", "subject_id", "group_id"]],
|
|
56
|
+
uniquePolicy: "lww-tombstone",
|
|
57
|
+
},
|
|
58
|
+
{ name: "vault_subject_type", mode: "row", uniqueKeys: [["id"], ["type"]], uniquePolicy: "lww-tombstone" },
|
|
59
|
+
{ name: "vault_set", mode: "row", uniqueKeys: [["id"], ["name"]], uniquePolicy: "lww-tombstone" },
|
|
60
|
+
{
|
|
61
|
+
name: "vault_group_set",
|
|
62
|
+
mode: "row",
|
|
63
|
+
uniqueKeys: [["id"], ["group_id", "set_id"]],
|
|
64
|
+
uniquePolicy: "lww-tombstone",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "vault_set_secret",
|
|
68
|
+
mode: "row",
|
|
69
|
+
uniqueKeys: [["id"], ["set_id", "secret_id"]],
|
|
70
|
+
uniquePolicy: "lww-tombstone",
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
views: [
|
|
75
|
+
{ id: "status", title: "保险箱", icon: "shield" },
|
|
76
|
+
{ id: "secrets", title: "凭据", icon: "key" },
|
|
77
|
+
{ id: "sets", title: "集合", icon: "layers" },
|
|
78
|
+
{ id: "groups", title: "分组与关联", icon: "folder" },
|
|
79
|
+
{ id: "config", title: "设置", icon: "sliders" },
|
|
80
|
+
{ id: "data", title: "数据", icon: "database" },
|
|
81
|
+
{ id: "actions", title: "Action 清单", icon: "list" },
|
|
82
|
+
],
|
|
83
|
+
capability: {
|
|
84
|
+
summary: "保存连接器/站点需要的密码、手机号、证件号与 token;分组挂集合、集合装凭据,明文只向 UI 或 plugin 租约暴露。",
|
|
85
|
+
records: [
|
|
86
|
+
{
|
|
87
|
+
kind: "set",
|
|
88
|
+
table: "vault_set",
|
|
89
|
+
title: "凭据集合",
|
|
90
|
+
description: "可复用的凭据容器:一个集合能挂到多个分组,也能装多条凭据,删除只断关联。",
|
|
91
|
+
when: ["同一个业务账号要复用多条凭据", "一份凭据要给多个分组使用"],
|
|
92
|
+
primaryAction: "vault.setList",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
kind: "secret",
|
|
96
|
+
table: "vault_secret",
|
|
97
|
+
title: "凭据",
|
|
98
|
+
description: "一条加密凭据(密码/手机号/证件号/token),可加入多个集合,列表只显示名称与备注。",
|
|
99
|
+
when: ["需要保存邮箱密码或应用专用密码", "连接器要绑定一个 token", "想在 agent 面前隐藏明文"],
|
|
100
|
+
primaryAction: "vault.secretCreate",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
kind: "group",
|
|
104
|
+
table: "vault_group",
|
|
105
|
+
title: "凭据分组",
|
|
106
|
+
description: "把多条凭据收成一组,业务对象通过 vault_binding 关联到组,而不是逐条绑定。",
|
|
107
|
+
when: ["一个站点/邮箱要复用多条凭据", "按用途(邮件、订阅、支付)归类"],
|
|
108
|
+
primaryAction: "vault.groupCreate",
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
fields: [
|
|
112
|
+
{ name: "name", type: "string", description: "唯一名称" },
|
|
113
|
+
{
|
|
114
|
+
name: "kind",
|
|
115
|
+
type: "password|phone|id_card|token|app_password|api_key|other",
|
|
116
|
+
description: "凭据类型;密码/手机号/证件号/Token/应用专用密码/API Key/其它",
|
|
117
|
+
},
|
|
118
|
+
{ name: "groupId", type: "string", description: "所属分组,可空;写入时自动挂到该组的默认集合" },
|
|
119
|
+
{ name: "setId", type: "string", description: "直接指定所属集合,优先于 groupId" },
|
|
120
|
+
{ name: "meta", type: "object", description: "非敏感备注(用户名、URL、过期提醒)" },
|
|
121
|
+
],
|
|
122
|
+
notFor: ["浏览器密码自动填充", "跨设备同步明文", "给 agent 读取明文"],
|
|
123
|
+
notes: [
|
|
124
|
+
"vault_header/vault_secret/vault_group/vault_set/vault_group_set/vault_set_secret/vault_binding/vault_subject_type 随云同步;device key 与 last_used_at 只留本机。",
|
|
125
|
+
"同步上去的是 KDF 参数与密文,云端没有口令也解不开;换机重新输入口令即可解锁。",
|
|
126
|
+
"备份仍不导出密文,换机靠同步或重新录入。",
|
|
127
|
+
"旧版分组的直属凭据在首次解锁时迁移进「<组名> · 默认」集合;站点专属类型收口为通用类型。",
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
setup(api) {
|
|
131
|
+
ensureSchema(api.db);
|
|
132
|
+
bindClock(() => api.now());
|
|
133
|
+
vault = createVault({ db: api.db, log: api.log });
|
|
134
|
+
groups = createGroups({ db: api.db });
|
|
135
|
+
const register = api.action.bind(api);
|
|
136
|
+
api.action = (actionName, def) => {
|
|
137
|
+
schemas.push({ name: actionName, domain: "wb-addon-vault", description: def.description, input: def.input, examples: def.examples });
|
|
138
|
+
register(actionName, def);
|
|
139
|
+
};
|
|
140
|
+
registerVaultActions(api, vault, groups);
|
|
141
|
+
api.action = register;
|
|
142
|
+
const origTool = api.tool.bind(api);
|
|
143
|
+
api.tool = (toolName, def) => origTool(toolName, def);
|
|
144
|
+
api.action("vault.actionSchema", {
|
|
145
|
+
description: "只读:本域 action 清单与输入 schema(插件自证,不读宿主统一接口)。",
|
|
146
|
+
input: { type: "object", properties: {}, additionalProperties: false },
|
|
147
|
+
execute: () => ({ shellVersion: api.shellVersion || "", domains: [{ id: "wb-addon-vault", version: (api.addon && api.addon.version) || "0.3.6" }], actions: schemas }),
|
|
148
|
+
});
|
|
149
|
+
void host;
|
|
150
|
+
},
|
|
151
|
+
exportData() {
|
|
152
|
+
return {
|
|
153
|
+
formatVersion: 1,
|
|
154
|
+
exportedAt: new Date().toISOString(),
|
|
155
|
+
note: "保险箱密文与 KDF 参数不进入备份;换机请重新输入口令(或等云同步),不要靠备份还原密文。",
|
|
156
|
+
secrets: [],
|
|
157
|
+
groups: [],
|
|
158
|
+
bindings: [],
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
importData() {
|
|
162
|
+
return 0;
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 保险箱密码学:scrypt 派生 KEK,AES-256-GCM 包裹 DEK / 加密 secret。
|
|
3
|
+
* 密文格式与 sites 现有实现一致:v1:<b64 iv>:<b64 tag>:<b64 ct>。
|
|
4
|
+
*/
|
|
5
|
+
import {
|
|
6
|
+
createCipheriv,
|
|
7
|
+
createDecipheriv,
|
|
8
|
+
randomBytes,
|
|
9
|
+
scryptSync,
|
|
10
|
+
} from "node:crypto";
|
|
11
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
|
|
15
|
+
export const KDF_DEFAULT = { N: 32768, r: 8, p: 1, keylen: 32 };
|
|
16
|
+
|
|
17
|
+
export function deriveKey(passphrase, salt, kdf = KDF_DEFAULT) {
|
|
18
|
+
const N = Number(kdf.N) || KDF_DEFAULT.N;
|
|
19
|
+
const r = Number(kdf.r) || KDF_DEFAULT.r;
|
|
20
|
+
const p = Number(kdf.p) || KDF_DEFAULT.p;
|
|
21
|
+
return scryptSync(String(passphrase), Buffer.from(salt, "base64"), Number(kdf.keylen) || 32, {
|
|
22
|
+
N,
|
|
23
|
+
r,
|
|
24
|
+
p,
|
|
25
|
+
maxmem: 128 * 1024 * 1024,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function seal(key, plaintext, aad = "") {
|
|
30
|
+
const iv = randomBytes(12);
|
|
31
|
+
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
32
|
+
if (aad) cipher.setAAD(Buffer.from(aad, "utf8"));
|
|
33
|
+
const ct = Buffer.concat([cipher.update(Buffer.from(plaintext)), cipher.final()]);
|
|
34
|
+
const tag = cipher.getAuthTag();
|
|
35
|
+
return "v1:" + iv.toString("base64") + ":" + tag.toString("base64") + ":" + ct.toString("base64");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function open(key, payload, aad = "") {
|
|
39
|
+
const parts = String(payload || "").split(":");
|
|
40
|
+
if (parts.length !== 4 || parts[0] !== "v1") throw new Error("密文格式不支持");
|
|
41
|
+
const iv = Buffer.from(parts[1], "base64");
|
|
42
|
+
const tag = Buffer.from(parts[2], "base64");
|
|
43
|
+
const ct = Buffer.from(parts[3], "base64");
|
|
44
|
+
const decipher = createDecipheriv("aes-256-gcm", key, iv);
|
|
45
|
+
if (aad) decipher.setAAD(Buffer.from(aad, "utf8"));
|
|
46
|
+
decipher.setAuthTag(tag);
|
|
47
|
+
return Buffer.concat([decipher.update(ct), decipher.final()]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function secretAad(id, name, kind) {
|
|
51
|
+
return "vault:" + String(id) + ":" + String(name) + ":" + String(kind);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function wbHome() {
|
|
55
|
+
return process.env.WB_HOME || join(homedir(), ".dsh", "workbench");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function deviceKeyPath() {
|
|
59
|
+
return join(wbHome(), "vault-device.key");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function readDeviceKey() {
|
|
63
|
+
const path = deviceKeyPath();
|
|
64
|
+
if (!existsSync(path)) return null;
|
|
65
|
+
const buf = readFileSync(path);
|
|
66
|
+
return buf.length === 32 ? buf : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function writeDeviceKey(key) {
|
|
70
|
+
const path = deviceKeyPath();
|
|
71
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
72
|
+
writeFileSync(path, key, { mode: 0o600 });
|
|
73
|
+
chmodSync(path, 0o600);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function removeDeviceKey() {
|
|
77
|
+
const path = deviceKeyPath();
|
|
78
|
+
if (existsSync(path)) rmSync(path);
|
|
79
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,118 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-workbench-vault",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.7",
|
|
4
|
+
"description": "个人工作台凭据保险箱:加密保存密码与 token,agent 只见掩码",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"cordis.patch.yml",
|
|
10
|
+
"package.json",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"wb": {
|
|
16
|
+
"addon": {
|
|
17
|
+
"id": "wb-addon-vault",
|
|
18
|
+
"title": "凭据保险箱",
|
|
19
|
+
"version": "0.3.7",
|
|
20
|
+
"minShell": "0.8.0",
|
|
21
|
+
"tables": [
|
|
22
|
+
"vault_header",
|
|
23
|
+
"vault_device",
|
|
24
|
+
"vault_group",
|
|
25
|
+
"vault_secret",
|
|
26
|
+
"vault_binding",
|
|
27
|
+
"vault_subject_type",
|
|
28
|
+
"vault_secret_usage"
|
|
29
|
+
],
|
|
30
|
+
"views": [
|
|
31
|
+
"status",
|
|
32
|
+
"secrets",
|
|
33
|
+
"groups",
|
|
34
|
+
"config",
|
|
35
|
+
"data",
|
|
36
|
+
"actions"
|
|
37
|
+
],
|
|
38
|
+
"toolActions": [
|
|
39
|
+
"vault.status",
|
|
40
|
+
"vault.setup",
|
|
41
|
+
"vault.unlock",
|
|
42
|
+
"vault.lock",
|
|
43
|
+
"vault.setUnlockMode",
|
|
44
|
+
"vault.changePassphrase",
|
|
45
|
+
"vault.secretList",
|
|
46
|
+
"vault.secretCreate",
|
|
47
|
+
"vault.secretUpdate",
|
|
48
|
+
"vault.secretDelete",
|
|
49
|
+
"vault.secretReveal",
|
|
50
|
+
"vault.rotateDeviceKey",
|
|
51
|
+
"vault.dataTables",
|
|
52
|
+
"vault.dataQuery",
|
|
53
|
+
"vault.actionSchema",
|
|
54
|
+
"vault.groupList",
|
|
55
|
+
"vault.groupCreate",
|
|
56
|
+
"vault.groupUpdate",
|
|
57
|
+
"vault.groupDelete",
|
|
58
|
+
"vault.subjectRegister",
|
|
59
|
+
"vault.bind",
|
|
60
|
+
"vault.unbind",
|
|
61
|
+
"vault.bindingsOf",
|
|
62
|
+
"vault.subjectsOf",
|
|
63
|
+
"vault.subjectSecrets",
|
|
64
|
+
"vault.bindingPurge",
|
|
65
|
+
"vault.syncStatus"
|
|
66
|
+
],
|
|
67
|
+
"client": "lib/client.js"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"dsh-workbench-host": "^0.8.0"
|
|
72
|
+
},
|
|
73
|
+
"dsh": {
|
|
74
|
+
"bundle": {
|
|
75
|
+
"patch": "./cordis.patch.yml"
|
|
76
|
+
},
|
|
77
|
+
"client": {
|
|
78
|
+
"inject": [
|
|
79
|
+
"dsh-workbench-host"
|
|
80
|
+
],
|
|
81
|
+
"platform": "web"
|
|
82
|
+
},
|
|
83
|
+
"engines": {
|
|
84
|
+
"dsh": ">=0.2.0-rc.1 <0.3.0"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"exports": {
|
|
88
|
+
".": "./lib/index.js",
|
|
89
|
+
"./client": "./lib/client.js",
|
|
90
|
+
"./package.json": "./package.json"
|
|
91
|
+
},
|
|
92
|
+
"author": "ityyq777",
|
|
93
|
+
"keywords": [
|
|
94
|
+
"dsh",
|
|
95
|
+
"dsh-plugin",
|
|
96
|
+
"deepseek-harness",
|
|
97
|
+
"vault",
|
|
98
|
+
"secrets",
|
|
99
|
+
"password",
|
|
100
|
+
"token",
|
|
101
|
+
"security"
|
|
102
|
+
],
|
|
103
|
+
"repository": {
|
|
104
|
+
"type": "git",
|
|
105
|
+
"url": "git+https://github.com/ityyq777/dsh-workbench.git",
|
|
106
|
+
"directory": "packages/vault"
|
|
107
|
+
},
|
|
108
|
+
"homepage": "https://github.com/ityyq777/dsh-workbench#readme",
|
|
109
|
+
"bugs": {
|
|
110
|
+
"url": "https://github.com/ityyq777/dsh-workbench/issues"
|
|
111
|
+
},
|
|
112
|
+
"engines": {
|
|
113
|
+
"node": ">=22.5"
|
|
114
|
+
},
|
|
115
|
+
"publishConfig": {
|
|
116
|
+
"access": "public"
|
|
117
|
+
}
|
|
118
|
+
}
|