@mysterycode-liwen/dsh-credential-vault 1.5.3 → 1.6.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/README.md +6 -0
- package/bridge/vault-bridge-client.js +166 -0
- package/client.js +113 -1
- package/index.js +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -126,6 +126,12 @@ Host 侧工具在 Harness 启动时注册。重启 Harness,或在插件管理
|
|
|
126
126
|
|
|
127
127
|
## 更新日志 / Changelog
|
|
128
128
|
|
|
129
|
+
### 1.6.0 — 2026-11-28 — 跨插件加密数据接口
|
|
130
|
+
|
|
131
|
+
- 新增:浏览器内加密桥接 API(ECDH P-256 + AES-GCM,一次性会话),供本人开发的其它插件安全读取凭据——调用方需持有凭据保险箱插件,未安装时自动空转、不影响使用。
|
|
132
|
+
- 新增:通用客户端模块模板 `bridge/vault-bridge-client.js`(零依赖、随包发布),其它插件复制即可接入;支持按标题/类型查询真实密钥值。
|
|
133
|
+
- 新增:授权方 dsh-mail 已接入,「邮箱授权码」可从保险箱一键填入。
|
|
134
|
+
|
|
129
135
|
### 1.5.3 — 2026-11-28 — 关联凭据改为可搜索下拉框
|
|
130
136
|
|
|
131
137
|
- **关联凭据编辑器改为下拉多选框**:点击展开浮层,顶部可按名称实时搜索;提供「全部 / API Key / 密钥 / 其他」类型筛选 chips,快速定位目标凭据。
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* vault-bridge-client.js — reusable client module for the DSH credential vault bridge
|
|
3
|
+
* ------------------------------------------------------------------------------
|
|
4
|
+
* Copy this whole file's contents into your plugin's client.js (inside
|
|
5
|
+
* factory(require)), or load it through your plugin's build step. ZERO deps:
|
|
6
|
+
* it only uses window.crypto.subtle, btoa/atob and TextEncoder/TextDecoder.
|
|
7
|
+
*
|
|
8
|
+
* WHY THIS EXISTS
|
|
9
|
+
* The vault keeps real secrets in its own browser localStorage. The Harness
|
|
10
|
+
* Host process only ever sees metadata (secrets are masked), so a plugin that
|
|
11
|
+
* needs a real value (e.g. a mail app password) must talk to the vault's
|
|
12
|
+
* browser-side bridge. This module does that.
|
|
13
|
+
*
|
|
14
|
+
* All payloads are encrypted with an ECDH (P-256) + AES-GCM session:
|
|
15
|
+
* 1. client.query(...) -> bridge.hello() = vault ephemeral public key + id
|
|
16
|
+
* 2. client generates its own ephemeral key pair, derives the shared AES key
|
|
17
|
+
* 3. client seals the query, vault decrypts / reads secrets / seals result
|
|
18
|
+
* 4. client opens the result with the same derived key.
|
|
19
|
+
* No plaintext and no long-lived key ever crosses the bridge. If the vault is
|
|
20
|
+
* not installed, isAvailable() is false and query() rejects NOT_INSTALLED —
|
|
21
|
+
* gate your UI on isAvailable() so the feature silently disappears.
|
|
22
|
+
*
|
|
23
|
+
* SECURITY NOTE
|
|
24
|
+
* The bridge is a same-document JS object. ECDH stops passive observers and
|
|
25
|
+
* other plugins from reading the payload, but a hostile script in the same
|
|
26
|
+
* document could still call the bridge as if it were your plugin. The vault
|
|
27
|
+
* never auto-authorises: each session is one-time use and expires in 60s.
|
|
28
|
+
*
|
|
29
|
+
* USAGE
|
|
30
|
+
* const vault = createVaultV1Client();
|
|
31
|
+
* if (vault.isAvailable()) {
|
|
32
|
+
* const entries = await vault.query({ category: 'account', title: 'qq' });
|
|
33
|
+
* const secret = vault.secretOf(entries[0]); // real password / key value
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* Node (tests): also exported via module.exports when available.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
function createVaultV1Client(options) {
|
|
40
|
+
options = options || {};
|
|
41
|
+
var win = options.window || (typeof window !== 'undefined' ? window : null);
|
|
42
|
+
var BRIDGE_KEY = '@mysterycode-liwen/dsh-credential-vault/bridge/v1';
|
|
43
|
+
|
|
44
|
+
function cryptoObj() {
|
|
45
|
+
return (win && win.crypto) || (typeof globalThis !== 'undefined' && globalThis.crypto) || null;
|
|
46
|
+
}
|
|
47
|
+
function subtle() {
|
|
48
|
+
var c = cryptoObj();
|
|
49
|
+
return c && c.subtle ? c.subtle : null;
|
|
50
|
+
}
|
|
51
|
+
function randomFill(bytes) {
|
|
52
|
+
var c = cryptoObj();
|
|
53
|
+
if (!c || !c.getRandomValues) throw new Error('NO_CRYPTO');
|
|
54
|
+
c.getRandomValues(bytes);
|
|
55
|
+
return bytes;
|
|
56
|
+
}
|
|
57
|
+
function toB64u(bytes) {
|
|
58
|
+
var s = '';
|
|
59
|
+
for (var i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]);
|
|
60
|
+
var btoaFn = options.btoa || (typeof btoa === 'function' ? btoa : (win && win.btoa));
|
|
61
|
+
return btoaFn(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
62
|
+
}
|
|
63
|
+
function fromB64u(str) {
|
|
64
|
+
var s = String(str).replace(/-/g, '+').replace(/_/g, '/');
|
|
65
|
+
while (s.length % 4) s += '=';
|
|
66
|
+
var atobFn = options.atob || (typeof atob === 'function' ? atob : (win && win.atob));
|
|
67
|
+
var bin = atobFn(s), out = new Uint8Array(bin.length);
|
|
68
|
+
for (var i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
function enc(str) { return new TextEncoder().encode(str); }
|
|
72
|
+
function dec(bytes) { return new TextDecoder().decode(bytes); }
|
|
73
|
+
|
|
74
|
+
function bridge() {
|
|
75
|
+
if (!win || !win[BRIDGE_KEY]) return null;
|
|
76
|
+
var b = win[BRIDGE_KEY];
|
|
77
|
+
return b && b.version === 1 && typeof b.hello === 'function' && typeof b.query === 'function' ? b : null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function generatePair(s) {
|
|
81
|
+
return s.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, true, ['deriveBits']);
|
|
82
|
+
}
|
|
83
|
+
function deriveKey(s, priv, peerJwk) {
|
|
84
|
+
return s.importKey('jwk', peerJwk, { name: 'ECDH', namedCurve: 'P-256' }, false, [])
|
|
85
|
+
.then(function (pub) { return s.deriveBits({ name: 'ECDH', public: pub }, priv, 256); })
|
|
86
|
+
.then(function (bits) { return s.importKey('raw', bits, { name: 'AES-GCM' }, false, ['encrypt', 'decrypt']); });
|
|
87
|
+
}
|
|
88
|
+
function seal(s, key, obj) {
|
|
89
|
+
var iv = randomFill(new Uint8Array(12));
|
|
90
|
+
return s.encrypt({ name: 'AES-GCM', iv: iv }, key, enc(JSON.stringify(obj)))
|
|
91
|
+
.then(function (ct) { return { iv: toB64u(iv), ciphertext: toB64u(new Uint8Array(ct)) }; });
|
|
92
|
+
}
|
|
93
|
+
function open(s, key, payload) {
|
|
94
|
+
if (!payload || typeof payload.iv !== 'string' || typeof payload.ciphertext !== 'string') {
|
|
95
|
+
return Promise.reject(new Error('BAD_CIPHERTEXT'));
|
|
96
|
+
}
|
|
97
|
+
return s.decrypt({ name: 'AES-GCM', iv: fromB64u(payload.iv) }, key, fromB64u(payload.ciphertext))
|
|
98
|
+
.then(function (plain) { return JSON.parse(dec(new Uint8Array(plain))); });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function isAvailable() { return !!bridge(); }
|
|
102
|
+
|
|
103
|
+
function query(criteria) {
|
|
104
|
+
criteria = criteria || {};
|
|
105
|
+
var b = bridge();
|
|
106
|
+
if (!b) return Promise.reject(new Error('NOT_INSTALLED'));
|
|
107
|
+
var s = subtle();
|
|
108
|
+
if (!s) return Promise.reject(new Error('NO_CRYPTO'));
|
|
109
|
+
var vaultPub, sessionId, priv, aes;
|
|
110
|
+
return Promise.resolve(b.hello())
|
|
111
|
+
.then(function (hello) {
|
|
112
|
+
if (!hello || !hello.sessionId || !hello.publicKeyJwk) throw new Error('BAD_HELLO');
|
|
113
|
+
sessionId = hello.sessionId;
|
|
114
|
+
vaultPub = hello.publicKeyJwk;
|
|
115
|
+
return generatePair(s);
|
|
116
|
+
})
|
|
117
|
+
.then(function (kp) {
|
|
118
|
+
priv = kp.privateKey;
|
|
119
|
+
return s.exportKey('jwk', kp.publicKey);
|
|
120
|
+
})
|
|
121
|
+
.then(function (pubJwk) {
|
|
122
|
+
return deriveKey(s, priv, vaultPub).then(function (key) {
|
|
123
|
+
aes = key;
|
|
124
|
+
return seal(s, aes, {
|
|
125
|
+
category: criteria.category || 'all',
|
|
126
|
+
title: criteria.title || '',
|
|
127
|
+
limit: criteria.limit || 100
|
|
128
|
+
}).then(function (sealed) {
|
|
129
|
+
return b.query({
|
|
130
|
+
sessionId: sessionId,
|
|
131
|
+
publicKeyJwk: pubJwk,
|
|
132
|
+
iv: sealed.iv,
|
|
133
|
+
ciphertext: sealed.ciphertext
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
})
|
|
138
|
+
.then(function (result) {
|
|
139
|
+
if (!result) throw new Error('NO_RESPONSE');
|
|
140
|
+
if (result.error) throw new Error(result.error);
|
|
141
|
+
return open(s, aes, result);
|
|
142
|
+
})
|
|
143
|
+
.then(function (plain) { return plain && Array.isArray(plain.entries) ? plain.entries : []; });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function secretOf(entry) {
|
|
147
|
+
if (!entry) return '';
|
|
148
|
+
var keys = ['password', 'keyValue', 'apiKey', 'content', 'appSecret', 'token', 'encodingAesKey', 'uploadKey'];
|
|
149
|
+
for (var i = 0; i < keys.length; i++) {
|
|
150
|
+
if (typeof entry[keys[i]] === 'string' && entry[keys[i]]) return entry[keys[i]];
|
|
151
|
+
}
|
|
152
|
+
return '';
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
version: 1,
|
|
157
|
+
isAvailable: isAvailable,
|
|
158
|
+
query: query,
|
|
159
|
+
secretOf: secretOf,
|
|
160
|
+
_debug: { toB64u: toB64u, fromB64u: fromB64u, deriveKey: deriveKey, seal: seal, open: open }
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
165
|
+
module.exports = { createVaultV1Client: createVaultV1Client };
|
|
166
|
+
}
|
package/client.js
CHANGED
|
@@ -15,7 +15,7 @@ window.__ModuleLoader__.load({
|
|
|
15
15
|
// whatever port the Web GUI is on.
|
|
16
16
|
var API = 'dsh-credential-vault/';
|
|
17
17
|
/** Plugin version shown in Settings; keep in sync with package.json on release. */
|
|
18
|
-
var VERSION = '1.
|
|
18
|
+
var VERSION = '1.6.0';
|
|
19
19
|
|
|
20
20
|
// Compare two semver-ish strings: -1 (left older), 0 (equal), 1 (left newer).
|
|
21
21
|
// Used to decide "update available" against THIS client's version, so the
|
|
@@ -627,6 +627,117 @@ window.__ModuleLoader__.load({
|
|
|
627
627
|
try { window.localStorage.setItem(STORAGE_KEY, JSON.stringify(arr)); } catch (e) {}
|
|
628
628
|
syncToHost(arr);
|
|
629
629
|
}
|
|
630
|
+
|
|
631
|
+
// ---- Cross-plugin encrypted bridge (ECDH P-256 + AES-GCM) ------------
|
|
632
|
+
// Other plugins (e.g. dsh-mail) need a real secret from the vault. The Host
|
|
633
|
+
// process only has a metadata snapshot, so the only place that can answer
|
|
634
|
+
// is this browser client. We publish a same-document bridge object that
|
|
635
|
+
// speaks an encrypted, one-time-session protocol; nothing here touches the
|
|
636
|
+
// Host route and nothing persists. Registered on window in apply(); if this
|
|
637
|
+
// plugin is not installed, the object simply never exists and consumers
|
|
638
|
+
// detect that via isAvailable() and silently no-op.
|
|
639
|
+
var BRIDGE_KEY = '@mysterycode-liwen/dsh-credential-vault/bridge/v1';
|
|
640
|
+
var bridgeSessions = {}; // sessionId -> { key, used, expires }
|
|
641
|
+
function bridgeB64u(bytes) {
|
|
642
|
+
var s = '';
|
|
643
|
+
for (var i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]);
|
|
644
|
+
return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
645
|
+
}
|
|
646
|
+
function bridgeUnb64u(str) {
|
|
647
|
+
var b = String(str).replace(/-/g, '+').replace(/_/g, '/');
|
|
648
|
+
while (b.length % 4) b += '=';
|
|
649
|
+
var bin = atob(b), out = new Uint8Array(bin.length);
|
|
650
|
+
for (var i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
651
|
+
return out;
|
|
652
|
+
}
|
|
653
|
+
function bridgeEnc(str) { return new TextEncoder().encode(str); }
|
|
654
|
+
function bridgeDec(bytes) { return new TextDecoder().decode(bytes); }
|
|
655
|
+
function bridgeDerive(s, priv, peerJwk) {
|
|
656
|
+
return s.importKey('jwk', peerJwk, { name: 'ECDH', namedCurve: 'P-256' }, false, [])
|
|
657
|
+
.then(function (pub) { return s.deriveBits({ name: 'ECDH', public: pub }, priv, 256); })
|
|
658
|
+
.then(function (bits) { return s.importKey('raw', bits, { name: 'AES-GCM' }, false, ['encrypt', 'decrypt']); });
|
|
659
|
+
}
|
|
660
|
+
function bridgeSeal(s, key, obj) {
|
|
661
|
+
var iv = new Uint8Array(12);
|
|
662
|
+
window.crypto.getRandomValues(iv);
|
|
663
|
+
return s.encrypt({ name: 'AES-GCM', iv: iv }, key, bridgeEnc(JSON.stringify(obj)))
|
|
664
|
+
.then(function (ct) {
|
|
665
|
+
return { iv: bridgeB64u(iv), ciphertext: bridgeB64u(new Uint8Array(ct)) };
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
function bridgeOpen(s, key, payload) {
|
|
669
|
+
if (!payload || typeof payload.iv !== 'string' || typeof payload.ciphertext !== 'string') {
|
|
670
|
+
return Promise.reject(new Error('BAD_CIPHERTEXT'));
|
|
671
|
+
}
|
|
672
|
+
return s.decrypt({ name: 'AES-GCM', iv: bridgeUnb64u(payload.iv) }, key, bridgeUnb64u(payload.ciphertext))
|
|
673
|
+
.then(function (plain) { return JSON.parse(bridgeDec(new Uint8Array(plain))); });
|
|
674
|
+
}
|
|
675
|
+
function newBridge() {
|
|
676
|
+
var s = (window.crypto && window.crypto.subtle) || null;
|
|
677
|
+
return {
|
|
678
|
+
version: 1,
|
|
679
|
+
hello: function () {
|
|
680
|
+
if (!s) return Promise.reject(new Error('NO_CRYPTO'));
|
|
681
|
+
return s.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, true, ['deriveBits'])
|
|
682
|
+
.then(function (kp) {
|
|
683
|
+
var id = Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 10);
|
|
684
|
+
return s.exportKey('jwk', kp.publicKey).then(function (pubJwk) {
|
|
685
|
+
bridgeSessions[id] = { keyPair: kp, used: false, expires: Date.now() + 60000 };
|
|
686
|
+
return { sessionId: id, publicKeyJwk: pubJwk };
|
|
687
|
+
});
|
|
688
|
+
});
|
|
689
|
+
},
|
|
690
|
+
query: function (req) {
|
|
691
|
+
if (!s) return Promise.resolve({ error: 'NO_CRYPTO' });
|
|
692
|
+
if (!req || !req.sessionId || !req.publicKeyJwk) {
|
|
693
|
+
return Promise.resolve({ error: 'BAD_REQUEST' });
|
|
694
|
+
}
|
|
695
|
+
var sess = bridgeSessions[req.sessionId];
|
|
696
|
+
if (!sess) return Promise.resolve({ error: 'UNKNOWN_SESSION' });
|
|
697
|
+
if (sess.expires < Date.now()) {
|
|
698
|
+
delete bridgeSessions[req.sessionId];
|
|
699
|
+
return Promise.resolve({ error: 'SESSION_EXPIRED' });
|
|
700
|
+
}
|
|
701
|
+
if (sess.used) return Promise.resolve({ error: 'SESSION_USED' });
|
|
702
|
+
// One-time session: consume immediately, even if decryption later fails.
|
|
703
|
+
sess.used = true;
|
|
704
|
+
try { delete bridgeSessions[req.sessionId]; } catch (e) {}
|
|
705
|
+
var sharedKey = null;
|
|
706
|
+
return bridgeDerive(s, sess.keyPair.privateKey, req.publicKeyJwk)
|
|
707
|
+
.then(function (key) { sharedKey = key; return bridgeOpen(s, key, req); })
|
|
708
|
+
.then(function (criteria) {
|
|
709
|
+
var cat = criteria && criteria.category ? criteria.category : 'all';
|
|
710
|
+
var title = criteria && typeof criteria.title === 'string' ? criteria.title.toLowerCase() : '';
|
|
711
|
+
var limit = criteria && criteria.limit ? Math.min(Number(criteria.limit) || 100, 500) : 100;
|
|
712
|
+
var all = loadEntries(); // REAL entries incl. secrets, from localStorage
|
|
713
|
+
var SECRET_KEYS = ['password', 'apiKey', 'content', 'appSecret', 'token',
|
|
714
|
+
'encodingAesKey', 'uploadKey', 'keyValue'];
|
|
715
|
+
var out = [];
|
|
716
|
+
for (var i = 0; i < all.length && out.length < limit; i++) {
|
|
717
|
+
var e = all[i];
|
|
718
|
+
if (cat !== 'all' && e.category !== cat) continue;
|
|
719
|
+
if (title && String(e.title || '').toLowerCase().indexOf(title) < 0) continue;
|
|
720
|
+
var item = {};
|
|
721
|
+
Object.keys(e).forEach(function (k) { item[k] = e[k]; });
|
|
722
|
+
// Belt-and-braces: only known secret keys are included; all are
|
|
723
|
+
// real values because the consumer authenticated with the AES key.
|
|
724
|
+
SECRET_KEYS.forEach(function (k) {
|
|
725
|
+
if (typeof e[k] === 'string') item[k] = e[k];
|
|
726
|
+
});
|
|
727
|
+
out.push(item);
|
|
728
|
+
}
|
|
729
|
+
return bridgeSeal(s, sharedKey, { entries: out });
|
|
730
|
+
})
|
|
731
|
+
.then(function (sealed) { return sealed; })
|
|
732
|
+
.catch(function () { return { error: 'DECRYPT_FAILED' }; });
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
function registerBridge() {
|
|
737
|
+
try {
|
|
738
|
+
if (!window[BRIDGE_KEY]) window[BRIDGE_KEY] = newBridge();
|
|
739
|
+
} catch (e) {}
|
|
740
|
+
}
|
|
630
741
|
// Mirror only METADATA to the Host so the Harness/Agent can discover which
|
|
631
742
|
// credentials exist via dsh_credential_vault_read. Plaintext secrets stay in
|
|
632
743
|
// this browser's localStorage and are NEVER sent to the Host process. The
|
|
@@ -2756,6 +2867,7 @@ window.__ModuleLoader__.load({
|
|
|
2756
2867
|
return {
|
|
2757
2868
|
inject: ['slots'],
|
|
2758
2869
|
apply(ctx) {
|
|
2870
|
+
registerBridge();
|
|
2759
2871
|
ctxRef = ctx;
|
|
2760
2872
|
layout = (ctx.get && ctx.get('layout')) || null;
|
|
2761
2873
|
locale = (ctx.get && ctx.get('locale')) || null;
|
package/index.js
CHANGED
|
@@ -46,7 +46,7 @@ const MAX_LIMIT = 200
|
|
|
46
46
|
const SUMMARY_FIELDS = ['id', 'title', 'category', 'username', 'provider', 'expiry', 'updatedAt']
|
|
47
47
|
|
|
48
48
|
/** Current plugin version. Keep in sync with package.json when releasing. */
|
|
49
|
-
const CURRENT_VERSION = '1.
|
|
49
|
+
const CURRENT_VERSION = '1.6.0'
|
|
50
50
|
|
|
51
51
|
/** Where update checks read the latest published version from (GitHub Releases latest). */
|
|
52
52
|
const RELEASES_API = 'https://api.github.com/repos/mysterycode-liwen/dsh-credential-vault/releases/latest'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mysterycode-liwen/dsh-credential-vault",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "DeepSeek Harness 侧边栏凭据保险箱:本地保存账号密码、API Key 与恢复码,支持访问密码、密保重置、闲置自动锁定,并提供默认脱敏的 Agent 读取工具。",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"client.js",
|
|
39
39
|
"cordis.patch.yml",
|
|
40
40
|
"locale/*.json",
|
|
41
|
+
"bridge/*.js",
|
|
41
42
|
"icon.svg",
|
|
42
43
|
"README.md",
|
|
43
44
|
"LICENSE"
|