@aivin-labs/cli 1.0.57 → 1.0.60
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/bin/cli.mjs +2 -1
- package/bin/lib/auth.mjs +119 -88
- package/bin/lib/context.mjs +58 -5
- package/bin/lib/loginHandoff.mjs +87 -0
- package/bin/lib/openFile.mjs +29 -4
- package/bin/lib/remote/client.mjs +1456 -1454
- package/bin/lib/remote/credentials.mjs +131 -125
- package/bin/lib/remote/desktop/castAuth.mjs +274 -259
- package/bin/lib/remote/desktop/castConsent.mjs +155 -154
- package/bin/lib/remote/desktop/castTrust.mjs +220 -183
- package/bin/lib/remote/desktop/desktopCastSource.mjs +77 -31
- package/bin/lib/remote/desktop/strings.mjs +158 -138
- package/bin/lib/remote/desktop/traySource.mjs +89 -15
- package/bin/lib/remote/desktop/webrtcWorker.mjs +4 -0
- package/bin/lib/remote/dpapiHelper.mjs +91 -0
- package/bin/lib/remote/gui/index.mjs +839 -567
- package/bin/lib/remote/gui/windowsHostSource.mjs +2418 -2127
- package/bin/lib/remote/tokenStore.mjs +19 -2
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'child_process';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
+
import { DpapiMode, dpapiHelper, runDpapiHelper } from './dpapiHelper.mjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Token thiết bị cất trong kho bí mật của hệ điều hành (29/10/2026). Trước đây `~/.aivin/device-credentials.json` giữ token dạng chữ thường
|
|
@@ -23,6 +24,22 @@ const DPAPI_UNPROTECT = `Add-Type -AssemblyName System.Security; $e = [Text.Enco
|
|
|
23
24
|
|
|
24
25
|
const run = (cmd, args, input) => execFileSync(cmd, args, { input, encoding: 'utf8', timeout: 20_000, windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] }).trim();
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* DPAPI: ưu tiên exe biên dịch sẵn (dpapiHelper.mjs, ~0,1 s), không có / không chạy được thì PowerShell (~1–4 s). Exe chạy được mà báo lỗi
|
|
29
|
+
* (bản mã của máy / tài khoản khác) thì ném luôn — PowerShell cũng sẽ hỏng y vậy, chỉ tốn thêm vài giây.
|
|
30
|
+
*/
|
|
31
|
+
function dpapi(mode, input) {
|
|
32
|
+
const exe = dpapiHelper();
|
|
33
|
+
if (exe) {
|
|
34
|
+
try {
|
|
35
|
+
return runDpapiHelper(exe, mode, input, DPAPI_ENTROPY);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
if (typeof e?.status === 'number') throw e;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return run('powershell.exe', [...PS, mode === DpapiMode.PROTECT ? DPAPI_PROTECT : DPAPI_UNPROTECT], input);
|
|
41
|
+
}
|
|
42
|
+
|
|
26
43
|
/** Kho dùng trên máy này. `AIVIN_TOKEN_STORE=file` ép tệp thường (máy không có kho / gỡ lỗi). */
|
|
27
44
|
export function preferredTokenStore({ platform = process.platform, env = process.env, exists = fs.existsSync } = {}) {
|
|
28
45
|
const forced = String(env.AIVIN_TOKEN_STORE || '').toLowerCase();
|
|
@@ -41,7 +58,7 @@ const quote = (s) => `"${String(s).replace(/["\\]/g, '\\$&')}"`;
|
|
|
41
58
|
*/
|
|
42
59
|
export function sealToken(token, { account, store = preferredTokenStore() } = {}) {
|
|
43
60
|
try {
|
|
44
|
-
if (store === TokenStoreKind.DPAPI) return { token_store: store, token_enc:
|
|
61
|
+
if (store === TokenStoreKind.DPAPI) return { token_store: store, token_enc: dpapi(DpapiMode.PROTECT, token) };
|
|
45
62
|
if (store === TokenStoreKind.KEYCHAIN) {
|
|
46
63
|
run('/usr/bin/security', ['-i'], `add-generic-password -U -a ${quote(account)} -s ${SERVICE} -l "Aivin device token" -w ${quote(token)}\n`);
|
|
47
64
|
return { token_store: store };
|
|
@@ -61,7 +78,7 @@ export function openToken(record) {
|
|
|
61
78
|
if (!record) return null;
|
|
62
79
|
if (record.device_token) return record.device_token;
|
|
63
80
|
try {
|
|
64
|
-
if (record.token_store === TokenStoreKind.DPAPI && record.token_enc) return
|
|
81
|
+
if (record.token_store === TokenStoreKind.DPAPI && record.token_enc) return dpapi(DpapiMode.UNPROTECT, record.token_enc) || null;
|
|
65
82
|
if (record.token_store === TokenStoreKind.KEYCHAIN) return run('/usr/bin/security', ['find-generic-password', '-a', record.token_account || record.device_id, '-s', SERVICE, '-w']) || null;
|
|
66
83
|
if (record.token_store === TokenStoreKind.LIBSECRET) return run('secret-tool', ['lookup', 'service', SERVICE, 'account', record.token_account || record.device_id]) || null;
|
|
67
84
|
} catch { /* không giải được */ }
|