adspower-browser 2.1.7-beta.1 → 2.1.7-beta.3
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 +65 -7
- package/cli/authWorker.js +63 -9
- package/cli/credentialWorker.js +350 -0
- package/cli/index.js +129 -48
- package/package.json +3 -1
package/README.MD
CHANGED
|
@@ -251,13 +251,71 @@ The logged-in desktop client returns apiKey, apiPort (Local API), rpaPort (RPA P
|
|
|
251
251
|
Both actual services must be ready. The callback worker survives foreground process termination,
|
|
252
252
|
waits five minutes, uses a random callback port and serializes login workers on port 59753.
|
|
253
253
|
|
|
254
|
-
|
|
255
|
-
`client
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
254
|
+
API Keys are stored in macOS login Keychain, Windows Credential Manager, or Linux Secret Service, scoped to the
|
|
255
|
+
current OS user under `com.adspower.cli.client.v1`. The account identifier is SHA-256(userId).
|
|
256
|
+
`~/.adspowerCli/<md5(userId)>` contains only version-2 connection metadata (userId, ports,
|
|
257
|
+
credentialAccount), never the API Key. `client-user.json` selects the current user.
|
|
258
|
+
|
|
259
|
+
The native helper uses Koffi prebuilt binaries (macOS arm64/x64; Windows arm64/x64/ia32).
|
|
260
|
+
No compiler, PowerShell, shell command or key in process arguments is required. Keep the
|
|
261
|
+
`koffi` and `dbus-next` runtime dependencies and `cli/credentialWorker.js` when packaging. The workspace
|
|
262
|
+
explicitly disables its install script because supported targets already ship prebuilds.
|
|
263
|
+
Native-library load failure is an error, not an invitation to use plaintext storage.
|
|
264
|
+
|
|
265
|
+
All credential operations are noninteractive and limited to five seconds per helper call.
|
|
266
|
+
macOS explicitly disables Keychain UI and restores the previous policy after each operation.
|
|
267
|
+
Windows uses generic CredReadW/CredWriteW/CredDeleteW credentials, without CredUI calls.
|
|
268
|
+
Linux talks directly to an already-running `org.freedesktop.secrets` provider (for example,
|
|
269
|
+
GNOME Keyring) on the user's D-Bus session bus. It never calls Unlock, Prompt or CreateCollection,
|
|
270
|
+
and never auto-starts the provider. A returned prompt is dismissed and reported as an error.
|
|
271
|
+
Secrets use the protocol's encrypted DH/HKDF/AES session; unsupported encryption fails without
|
|
272
|
+
retrying a plain session. No API Key is placed in process arguments or plaintext files.
|
|
273
|
+
Run WorkBuddy and the CLI under the same OS account, with access to that account's credential
|
|
274
|
+
store. A locked Keychain, changed host trust, missing credential or unavailable store produces
|
|
275
|
+
an explicit error. This cannot guarantee successful access under every OS security policy;
|
|
276
|
+
it guarantees no interactive fallback. Windows generic credentials are limited to 2560 bytes.
|
|
277
|
+
|
|
278
|
+
### Linux prerequisites
|
|
279
|
+
|
|
280
|
+
- Start the CLI and WorkBuddy as the same logged-in OS user, with that user's existing
|
|
281
|
+
`DBUS_SESSION_BUS_ADDRESS` (typically `unix:path=/run/user/<uid>/bus`). This implementation
|
|
282
|
+
supports filesystem Unix sockets only; abstract sockets and remote/TCP buses are rejected.
|
|
283
|
+
- A Secret Service provider must already be running with an unlocked, persistent default
|
|
284
|
+
collection. Create/unlock that collection through the desktop's credential manager before
|
|
285
|
+
running noninteractive CLI commands. Do not use an unencrypted or temporary session keyring.
|
|
286
|
+
- The Node D-Bus transport requires no `secret-tool`, Python, or native compiler. Its optional
|
|
287
|
+
`usocket` build is disabled in this workspace; filesystem sockets use Node's built-in transport.
|
|
288
|
+
- SSH, services and containers do not automatically inherit a desktop credential store.
|
|
289
|
+
Without an explicitly configured user bus and unlocked provider, login/status/API commands
|
|
290
|
+
fail. Do not run the CLI under `sudo` or substitute a different user's bus.
|
|
291
|
+
|
|
292
|
+
Linux errors include `LINUX_SESSION_BUS_UNAVAILABLE` (missing/unsupported bus),
|
|
293
|
+
`LINUX_SECRET_SERVICE_UNAVAILABLE` (service/transport/encrypted session failure), `LINUX_LOCKED`,
|
|
294
|
+
`LINUX_PERSISTENT_COLLECTION_REQUIRED`, `LINUX_NOT_FOUND`, `LINUX_AMBIGUOUS_CREDENTIAL`, and
|
|
295
|
+
`LINUX_INTERACTION_REQUIRED`. Timeout uses `HELPER_FAILED_OR_TIMED_OUT`. None falls back to
|
|
296
|
+
plaintext storage. Resolve the OS credential-store condition and retry; a missing saved key
|
|
297
|
+
requires `ads login` again. System-user credential storage does not isolate a key from every
|
|
298
|
+
malicious process already running under that user.
|
|
299
|
+
|
|
300
|
+
`logstatus` reads the system credential and metadata, exits nonzero with an error if credential
|
|
301
|
+
access fails, and does not probe client liveness or validate the key remotely. Business commands
|
|
302
|
+
also fail before calling APIs if the credential cannot be read. `logout` first deletes the current
|
|
303
|
+
user's system credential, then the metadata/index. Failed deletion retains metadata for retry;
|
|
304
|
+
it does not stop the desktop client or revoke the server API Key.
|
|
305
|
+
|
|
306
|
+
Legacy files containing apiKey are rejected, not used as fallback or silently migrated. Run
|
|
307
|
+
`ads login` again to replace that user's legacy file only after a successful vault write/read-back,
|
|
308
|
+
or `ads logout` to remove it. Files of other previously authorized users are not automatically
|
|
309
|
+
removed; reauthorize or remove those accounts individually. Ordinary start/stop runtime mode
|
|
310
|
+
is outside this client-session storage change.
|
|
311
|
+
|
|
312
|
+
Verification: `node tests/login-process-smoke.cjs` (from this package after build) uses a unique
|
|
313
|
+
fake account and cleans up its OS credential. Run it under the same Node executable/account
|
|
314
|
+
used by WorkBuddy on each supported OS. Tests cannot override OS policies or unlock a store.
|
|
315
|
+
|
|
316
|
+
Native API references: [Apple Keychain UI control](https://developer.apple.com/documentation/security/seckeychainsetuserinteractionallowed(_:)),
|
|
317
|
+
[Windows CredReadW](https://learn.microsoft.com/en-us/windows/win32/api/wincred/nf-wincred-credreadw),
|
|
318
|
+
[Linux Secret Service](https://specifications.freedesktop.org/secret-service/latest/).
|
|
261
319
|
|
|
262
320
|
Deploy the matching frontend to both the authorization site and the desktop renderer site.
|
|
263
321
|
The native client must forward the complete protocol URL through renderer-scheme.
|
package/cli/authWorker.js
CHANGED
|
@@ -24,7 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
|
|
25
25
|
// src/authWorker.ts
|
|
26
26
|
var import_node_fs2 = require("fs");
|
|
27
|
-
var
|
|
27
|
+
var import_node_path4 = __toESM(require("path"));
|
|
28
28
|
var import_node_crypto3 = require("crypto");
|
|
29
29
|
var import_node_net2 = require("net");
|
|
30
30
|
|
|
@@ -38,19 +38,69 @@ var pendingPath = import_node_path.default.join(import_node_os.default.homedir()
|
|
|
38
38
|
|
|
39
39
|
// src/clientSession.ts
|
|
40
40
|
var fs3 = __toESM(require("fs"));
|
|
41
|
-
var
|
|
41
|
+
var import_node_path3 = __toESM(require("path"));
|
|
42
42
|
var import_node_crypto = require("crypto");
|
|
43
43
|
|
|
44
|
+
// src/credentialVault.ts
|
|
45
|
+
var import_node_child_process2 = require("child_process");
|
|
46
|
+
var import_node_path2 = __toESM(require("path"));
|
|
47
|
+
var CredentialStoreError = class extends Error {
|
|
48
|
+
constructor(code) {
|
|
49
|
+
super(`System credential store unavailable (${code}). Use the same OS account and an accessible credential store, then run ads login again. No plaintext fallback is permitted.`);
|
|
50
|
+
this.name = "CredentialStoreError";
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
function invoke(operation, account, secret) {
|
|
54
|
+
if (!["darwin", "win32", "linux"].includes(process.platform)) throw new CredentialStoreError("UNSUPPORTED_PLATFORM");
|
|
55
|
+
if (!/^[a-f0-9]{64}$/.test(account)) throw new CredentialStoreError("INVALID_ACCOUNT");
|
|
56
|
+
let output;
|
|
57
|
+
try {
|
|
58
|
+
output = (0, import_node_child_process2.execFileSync)(process.execPath, [import_node_path2.default.join(__dirname, "credentialWorker.js")], {
|
|
59
|
+
input: JSON.stringify({ operation, account, secret }),
|
|
60
|
+
windowsHide: true,
|
|
61
|
+
timeout: 5e3,
|
|
62
|
+
killSignal: "SIGKILL",
|
|
63
|
+
maxBuffer: 32768,
|
|
64
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
65
|
+
});
|
|
66
|
+
} catch {
|
|
67
|
+
throw new CredentialStoreError("HELPER_FAILED_OR_TIMED_OUT");
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const result = JSON.parse(output.toString("utf8"));
|
|
71
|
+
if (result.ok !== true) {
|
|
72
|
+
const code = typeof result.code === "string" && /^[A-Z0-9_-]{1,64}$/.test(result.code) ? result.code : "NATIVE_FAILURE";
|
|
73
|
+
throw new CredentialStoreError(code);
|
|
74
|
+
}
|
|
75
|
+
if (operation === "read" && (typeof result.secret !== "string" || !result.secret.trim() || result.secret.length > 4096 || /[\r\n]/.test(result.secret))) throw new CredentialStoreError("INVALID_SECRET");
|
|
76
|
+
return result.secret;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error instanceof CredentialStoreError) throw error;
|
|
79
|
+
throw new CredentialStoreError("INVALID_HELPER_RESPONSE");
|
|
80
|
+
} finally {
|
|
81
|
+
output.fill(0);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
var credentialVault = {
|
|
85
|
+
write: (account, secret) => {
|
|
86
|
+
invoke("write", account, secret);
|
|
87
|
+
},
|
|
88
|
+
read: (account) => invoke("read", account),
|
|
89
|
+
remove: (account) => {
|
|
90
|
+
invoke("delete", account);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
44
94
|
// src/tools/paths.ts
|
|
45
95
|
var os2 = __toESM(require("os"));
|
|
46
|
-
var
|
|
96
|
+
var path3 = __toESM(require("path"));
|
|
47
97
|
var fs2 = __toESM(require("fs"));
|
|
48
98
|
var import_fs_extra2 = require("fs-extra2");
|
|
49
99
|
var getHomedir = () => {
|
|
50
100
|
return (typeof os2.homedir == "function" ? os2.homedir() : process.env[process.platform == "win32" ? "USERPROFILE" : "HOME"]) || "~";
|
|
51
101
|
};
|
|
52
102
|
var getPidFileDir = (create = true) => {
|
|
53
|
-
const dir =
|
|
103
|
+
const dir = path3.join(getHomedir(), ".adspowerCli");
|
|
54
104
|
if (create && !fs2.existsSync(dir)) {
|
|
55
105
|
(0, import_fs_extra2.ensureDirSync)(dir);
|
|
56
106
|
}
|
|
@@ -58,8 +108,9 @@ var getPidFileDir = (create = true) => {
|
|
|
58
108
|
};
|
|
59
109
|
|
|
60
110
|
// src/clientSession.ts
|
|
61
|
-
var userFile = (userId) =>
|
|
62
|
-
var indexFile = () =>
|
|
111
|
+
var userFile = (userId) => import_node_path3.default.join(getPidFileDir(false), (0, import_node_crypto.createHash)("md5").update(userId).digest("hex"));
|
|
112
|
+
var indexFile = () => import_node_path3.default.join(getPidFileDir(false), "client-user.json");
|
|
113
|
+
var credentialAccount = (userId) => (0, import_node_crypto.createHash)("sha256").update(userId).digest("hex");
|
|
63
114
|
var validPort = (value) => Number.isInteger(value) && Number(value) > 0 && Number(value) <= 65535;
|
|
64
115
|
function isClientSession(value) {
|
|
65
116
|
if (!value || typeof value !== "object") return false;
|
|
@@ -77,9 +128,12 @@ function writePrivateJson(file, value) {
|
|
|
77
128
|
}
|
|
78
129
|
function saveClientSession(session) {
|
|
79
130
|
if (!isClientSession(session)) throw new Error("Incomplete client connection");
|
|
80
|
-
getPidFileDir();
|
|
81
131
|
const { apiKey, userId, apiPort, rpaPort } = session;
|
|
82
|
-
|
|
132
|
+
const account = credentialAccount(userId);
|
|
133
|
+
credentialVault.write(account, apiKey);
|
|
134
|
+
if (credentialVault.read(account) !== apiKey) throw new Error("System credential verification failed. No plaintext credentials were saved.");
|
|
135
|
+
getPidFileDir();
|
|
136
|
+
writePrivateJson(userFile(userId), { version: 2, userId, apiPort, rpaPort, credentialAccount: account });
|
|
83
137
|
writePrivateJson(indexFile(), { userId });
|
|
84
138
|
}
|
|
85
139
|
|
|
@@ -187,7 +241,7 @@ async function main() {
|
|
|
187
241
|
}
|
|
188
242
|
};
|
|
189
243
|
try {
|
|
190
|
-
await import_node_fs2.promises.mkdir(
|
|
244
|
+
await import_node_fs2.promises.mkdir(import_node_path4.default.dirname(pendingPath), { recursive: true, mode: 448 });
|
|
191
245
|
await import_node_fs2.promises.writeFile(pendingPath, JSON.stringify({ id, expiresAt: Date.now() + 3e5 }), { mode: 384 });
|
|
192
246
|
receiver = await createLoginReceiver(origin, async (session) => {
|
|
193
247
|
if (finishing || !await ownsSession()) throw new Error("Login cancelled");
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
|
|
32
|
+
// src/linuxCredentials.ts
|
|
33
|
+
var linuxCredentials_exports = {};
|
|
34
|
+
__export(linuxCredentials_exports, {
|
|
35
|
+
linuxCredentials: () => linuxCredentials
|
|
36
|
+
});
|
|
37
|
+
async function linuxCredentials(request) {
|
|
38
|
+
const address = process.env.DBUS_SESSION_BUS_ADDRESS;
|
|
39
|
+
if (!address || !/^unix:(?:path|socket)=[^;,]+(?:,guid=[a-f0-9]+)?$/.test(address)) {
|
|
40
|
+
return fail("SESSION_BUS_UNAVAILABLE");
|
|
41
|
+
}
|
|
42
|
+
let bus;
|
|
43
|
+
let session;
|
|
44
|
+
let key;
|
|
45
|
+
let destination = SERVICE;
|
|
46
|
+
let rejectConnection = () => {
|
|
47
|
+
};
|
|
48
|
+
const connectionFailure = new Promise((_, reject) => {
|
|
49
|
+
rejectConnection = reject;
|
|
50
|
+
});
|
|
51
|
+
void connectionFailure.catch(() => {
|
|
52
|
+
});
|
|
53
|
+
const call = async (path, iface, member, signature = "", body = [], target = destination) => {
|
|
54
|
+
const reply = await Promise.race([bus.call(new import_dbus_next.Message({
|
|
55
|
+
destination: target,
|
|
56
|
+
path,
|
|
57
|
+
interface: iface,
|
|
58
|
+
member,
|
|
59
|
+
signature,
|
|
60
|
+
body,
|
|
61
|
+
flags: 2
|
|
62
|
+
// D-Bus NO_AUTO_START: never start a service or its setup UI.
|
|
63
|
+
})), connectionFailure]);
|
|
64
|
+
if (!reply) return fail("INVALID_RESPONSE");
|
|
65
|
+
return reply.body;
|
|
66
|
+
};
|
|
67
|
+
const checkPrompt = async (prompt) => {
|
|
68
|
+
if (prompt === "/") return;
|
|
69
|
+
try {
|
|
70
|
+
await call(prompt, `${PREFIX}.Prompt`, "Dismiss");
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
fail("INTERACTION_REQUIRED");
|
|
74
|
+
};
|
|
75
|
+
const assertUnlocked = async (path, iface) => {
|
|
76
|
+
const [locked] = await call(path, "org.freedesktop.DBus.Properties", "Get", "ss", [iface, "Locked"]);
|
|
77
|
+
if (locked?.signature !== "b" || locked.value !== false) fail("LOCKED");
|
|
78
|
+
};
|
|
79
|
+
const openSession = async () => {
|
|
80
|
+
const dh = (0, import_node_crypto.getDiffieHellman)("modp2");
|
|
81
|
+
const [peer, sessionPath] = await call(ROOT, `${PREFIX}.Service`, "OpenSession", "sv", [ALGORITHM, new import_dbus_next.Variant("ay", dh.generateKeys())]);
|
|
82
|
+
if (peer?.signature !== "ay" || !sessionPath || sessionPath === "/") fail("INVALID_SESSION");
|
|
83
|
+
session = sessionPath;
|
|
84
|
+
const shared = dh.computeSecret(Buffer.from(peer.value));
|
|
85
|
+
try {
|
|
86
|
+
key = Buffer.from((0, import_node_crypto.hkdfSync)("sha256", shared, Buffer.alloc(0), Buffer.alloc(0), 16));
|
|
87
|
+
} finally {
|
|
88
|
+
shared.fill(0);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
try {
|
|
92
|
+
bus = (0, import_dbus_next.sessionBus)({ busAddress: address, authMethods: ["EXTERNAL"] });
|
|
93
|
+
bus.on("error", () => rejectConnection(new NativeCredentialError("LINUX_SESSION_BUS_UNAVAILABLE")));
|
|
94
|
+
[destination] = await call("/org/freedesktop/DBus", "org.freedesktop.DBus", "GetNameOwner", "s", [SERVICE], "org.freedesktop.DBus");
|
|
95
|
+
const attributes = { service: NAMESPACE, account: request.account };
|
|
96
|
+
const [items, locked] = await call(ROOT, `${PREFIX}.Service`, "SearchItems", "a{ss}", [attributes]);
|
|
97
|
+
if (locked.length) fail("LOCKED");
|
|
98
|
+
if (items.length > 1) fail("AMBIGUOUS_CREDENTIAL");
|
|
99
|
+
const item = items[0];
|
|
100
|
+
if (item?.startsWith(`${ROOT}/collection/session/`)) fail("PERSISTENT_COLLECTION_REQUIRED");
|
|
101
|
+
if (item) await assertUnlocked(item, `${PREFIX}.Item`);
|
|
102
|
+
if (request.operation === "delete") {
|
|
103
|
+
if (item) {
|
|
104
|
+
const [prompt] = await call(item, `${PREFIX}.Item`, "Delete");
|
|
105
|
+
await checkPrompt(prompt);
|
|
106
|
+
}
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (request.operation === "read" && !item) fail("NOT_FOUND");
|
|
110
|
+
let collection;
|
|
111
|
+
if (request.operation === "write" && !item) {
|
|
112
|
+
[collection] = await call(ROOT, `${PREFIX}.Service`, "ReadAlias", "s", ["default"]);
|
|
113
|
+
if (!collection || collection === "/" || collection === `${ROOT}/collection/session`) fail("PERSISTENT_COLLECTION_REQUIRED");
|
|
114
|
+
await assertUnlocked(collection, `${PREFIX}.Collection`);
|
|
115
|
+
}
|
|
116
|
+
await openSession();
|
|
117
|
+
if (request.operation === "read") {
|
|
118
|
+
const [value] = await call(item, `${PREFIX}.Item`, "GetSecret", "o", [session]);
|
|
119
|
+
if (!Array.isArray(value) || value.length !== 4 || value[0] !== session) fail("INVALID_SECRET");
|
|
120
|
+
const iv = Buffer.from(value[1]);
|
|
121
|
+
const ciphertext = Buffer.from(value[2]);
|
|
122
|
+
if (iv.length !== 16 || !ciphertext.length || ciphertext.length > 16400 || ciphertext.length % 16) fail("INVALID_SECRET");
|
|
123
|
+
const decipher = (0, import_node_crypto.createDecipheriv)("aes-128-cbc", key, iv);
|
|
124
|
+
const chunks = [decipher.update(ciphertext)];
|
|
125
|
+
let bytes2;
|
|
126
|
+
try {
|
|
127
|
+
chunks.push(decipher.final());
|
|
128
|
+
bytes2 = Buffer.concat(chunks);
|
|
129
|
+
return bytes2.toString("utf8");
|
|
130
|
+
} finally {
|
|
131
|
+
chunks.forEach((chunk) => chunk.fill(0));
|
|
132
|
+
bytes2?.fill(0);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const bytes = Buffer.from(request.secret, "utf8");
|
|
136
|
+
try {
|
|
137
|
+
const iv = (0, import_node_crypto.randomBytes)(16);
|
|
138
|
+
const cipher = (0, import_node_crypto.createCipheriv)("aes-128-cbc", key, iv);
|
|
139
|
+
const value = [session, iv, Buffer.concat([cipher.update(bytes), cipher.final()]), "text/plain; charset=utf-8"];
|
|
140
|
+
if (item) {
|
|
141
|
+
await call(item, `${PREFIX}.Item`, "SetSecret", "(oayays)", [value]);
|
|
142
|
+
} else {
|
|
143
|
+
const [created, prompt] = await call(collection, `${PREFIX}.Collection`, "CreateItem", "a{sv}(oayays)b", [{
|
|
144
|
+
[`${PREFIX}.Item.Label`]: new import_dbus_next.Variant("s", "AdsPower CLI client connection"),
|
|
145
|
+
[`${PREFIX}.Item.Attributes`]: new import_dbus_next.Variant("a{ss}", attributes)
|
|
146
|
+
}, value, true]);
|
|
147
|
+
await checkPrompt(prompt);
|
|
148
|
+
if (!created || created === "/") fail("WRITE_FAILED");
|
|
149
|
+
}
|
|
150
|
+
} finally {
|
|
151
|
+
bytes.fill(0);
|
|
152
|
+
}
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (error instanceof NativeCredentialError) throw error;
|
|
155
|
+
fail("SECRET_SERVICE_UNAVAILABLE");
|
|
156
|
+
} finally {
|
|
157
|
+
key?.fill(0);
|
|
158
|
+
if (bus) {
|
|
159
|
+
if (session) {
|
|
160
|
+
try {
|
|
161
|
+
await call(session, `${PREFIX}.Session`, "Close");
|
|
162
|
+
} catch {
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
bus.disconnect();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
var import_node_crypto, import_dbus_next, SERVICE, ROOT, PREFIX, NAMESPACE, ALGORITHM, fail;
|
|
170
|
+
var init_linuxCredentials = __esm({
|
|
171
|
+
"src/linuxCredentials.ts"() {
|
|
172
|
+
"use strict";
|
|
173
|
+
import_node_crypto = require("crypto");
|
|
174
|
+
import_dbus_next = require("dbus-next");
|
|
175
|
+
init_nativeCredentials();
|
|
176
|
+
SERVICE = "org.freedesktop.secrets";
|
|
177
|
+
ROOT = "/org/freedesktop/secrets";
|
|
178
|
+
PREFIX = "org.freedesktop.Secret";
|
|
179
|
+
NAMESPACE = "com.adspower.cli.client.v1";
|
|
180
|
+
ALGORITHM = "dh-ietf1024-sha256-aes128-cbc-pkcs7";
|
|
181
|
+
fail = (code) => {
|
|
182
|
+
throw new NativeCredentialError(`LINUX_${code}`);
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// src/nativeCredentials.ts
|
|
188
|
+
function macCredentials(request) {
|
|
189
|
+
const security = import_koffi.default.load("/System/Library/Frameworks/Security.framework/Security");
|
|
190
|
+
const core = import_koffi.default.load("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation");
|
|
191
|
+
const getInteraction = security.func("int32_t SecKeychainGetUserInteractionAllowed(_Out_ uint8_t *allowed)");
|
|
192
|
+
const setInteraction = security.func("int32_t SecKeychainSetUserInteractionAllowed(uint8_t allowed)");
|
|
193
|
+
const find = security.func("int32_t SecKeychainFindGenericPassword(void *keychain, uint32_t serviceLength, const char *service, uint32_t accountLength, const char *account, _Out_ uint32_t *length, _Out_ void **data, _Out_ void **item)");
|
|
194
|
+
const add = security.func("int32_t SecKeychainAddGenericPassword(void *keychain, uint32_t serviceLength, const char *service, uint32_t accountLength, const char *account, uint32_t length, const void *data, _Out_ void **item)");
|
|
195
|
+
const modify = security.func("int32_t SecKeychainItemModifyAttributesAndData(void *item, void *attributes, uint32_t length, const void *data)");
|
|
196
|
+
const remove = security.func("int32_t SecKeychainItemDelete(void *item)");
|
|
197
|
+
const free = security.func("int32_t SecKeychainItemFreeContent(void *attributes, void *data)");
|
|
198
|
+
const release = core.func("void CFRelease(void *value)");
|
|
199
|
+
const previous = [0];
|
|
200
|
+
let status = getInteraction(previous);
|
|
201
|
+
if (status) fail2("MACOS", status);
|
|
202
|
+
status = setInteraction(0);
|
|
203
|
+
if (status) fail2("MACOS", status);
|
|
204
|
+
const data = [null], item = [null], length = [0];
|
|
205
|
+
try {
|
|
206
|
+
status = find(
|
|
207
|
+
null,
|
|
208
|
+
Buffer.byteLength(SERVICE2),
|
|
209
|
+
SERVICE2,
|
|
210
|
+
request.account.length,
|
|
211
|
+
request.account,
|
|
212
|
+
request.operation === "read" ? length : null,
|
|
213
|
+
request.operation === "read" ? data : null,
|
|
214
|
+
item
|
|
215
|
+
);
|
|
216
|
+
const missing = status === -25300;
|
|
217
|
+
if (status && !missing) fail2("MACOS", status);
|
|
218
|
+
if (request.operation === "delete") {
|
|
219
|
+
if (missing) return;
|
|
220
|
+
status = remove(item[0]);
|
|
221
|
+
} else if (request.operation === "write") {
|
|
222
|
+
const bytes = Buffer.from(request.secret, "utf8");
|
|
223
|
+
try {
|
|
224
|
+
status = missing ? add(null, Buffer.byteLength(SERVICE2), SERVICE2, request.account.length, request.account, bytes.length, bytes, null) : modify(item[0], null, bytes.length, bytes);
|
|
225
|
+
} finally {
|
|
226
|
+
bytes.fill(0);
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
if (missing) fail2("MACOS", status);
|
|
230
|
+
if (!data[0] || length[0] < 1 || length[0] > 16384) throw new NativeCredentialError("INVALID_SECRET");
|
|
231
|
+
const bytes = Buffer.from(import_koffi.default.decode(data[0], "uint8_t", length[0]));
|
|
232
|
+
try {
|
|
233
|
+
return bytes.toString("utf8");
|
|
234
|
+
} finally {
|
|
235
|
+
bytes.fill(0);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (status) fail2("MACOS", status);
|
|
239
|
+
} finally {
|
|
240
|
+
if (data[0]) free(null, data[0]);
|
|
241
|
+
if (item[0]) release(item[0]);
|
|
242
|
+
const restored = setInteraction(previous[0]);
|
|
243
|
+
if (restored) fail2("MACOS", restored);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function windowsCredentials(request) {
|
|
247
|
+
const advapi = import_koffi.default.load("advapi32.dll");
|
|
248
|
+
const kernel = import_koffi.default.load("kernel32.dll");
|
|
249
|
+
const credential = import_koffi.default.struct("AdsCredentialW", {
|
|
250
|
+
Flags: "uint32_t",
|
|
251
|
+
Type: "uint32_t",
|
|
252
|
+
TargetName: "str16",
|
|
253
|
+
Comment: "str16",
|
|
254
|
+
LastWritten: import_koffi.default.struct({ low: "uint32_t", high: "uint32_t" }),
|
|
255
|
+
CredentialBlobSize: "uint32_t",
|
|
256
|
+
CredentialBlob: "void *",
|
|
257
|
+
Persist: "uint32_t",
|
|
258
|
+
AttributeCount: "uint32_t",
|
|
259
|
+
Attributes: "void *",
|
|
260
|
+
TargetAlias: "str16",
|
|
261
|
+
UserName: "str16"
|
|
262
|
+
});
|
|
263
|
+
const read = advapi.func("int __stdcall CredReadW(const char16_t *target, uint32_t type, uint32_t flags, _Out_ void **result)");
|
|
264
|
+
const write = advapi.func("int __stdcall CredWriteW(const AdsCredentialW *credential, uint32_t flags)");
|
|
265
|
+
const remove = advapi.func("int __stdcall CredDeleteW(const char16_t *target, uint32_t type, uint32_t flags)");
|
|
266
|
+
const free = advapi.func("void __stdcall CredFree(void *buffer)");
|
|
267
|
+
const lastError = kernel.func("uint32_t __stdcall GetLastError()");
|
|
268
|
+
const target = `${SERVICE2}/${request.account}`;
|
|
269
|
+
if (request.operation === "delete") {
|
|
270
|
+
if (!remove(target, 1, 0)) {
|
|
271
|
+
const code = lastError();
|
|
272
|
+
if (code !== 1168) fail2("WINDOWS", code);
|
|
273
|
+
}
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (request.operation === "write") {
|
|
277
|
+
const bytes = Buffer.from(request.secret, "utf8");
|
|
278
|
+
try {
|
|
279
|
+
if (bytes.length > 2560) throw new NativeCredentialError("WINDOWS_SECRET_TOO_LARGE");
|
|
280
|
+
if (!write({
|
|
281
|
+
Flags: 0,
|
|
282
|
+
Type: 1,
|
|
283
|
+
TargetName: target,
|
|
284
|
+
Comment: "AdsPower CLI client connection",
|
|
285
|
+
LastWritten: { low: 0, high: 0 },
|
|
286
|
+
CredentialBlobSize: bytes.length,
|
|
287
|
+
CredentialBlob: bytes,
|
|
288
|
+
Persist: 2,
|
|
289
|
+
AttributeCount: 0,
|
|
290
|
+
Attributes: null,
|
|
291
|
+
TargetAlias: null,
|
|
292
|
+
UserName: request.account
|
|
293
|
+
}, 0)) fail2("WINDOWS", lastError());
|
|
294
|
+
} finally {
|
|
295
|
+
bytes.fill(0);
|
|
296
|
+
}
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const result = [null];
|
|
300
|
+
if (!read(target, 1, 0, result)) fail2("WINDOWS", lastError());
|
|
301
|
+
try {
|
|
302
|
+
const value = import_koffi.default.decode(result[0], credential);
|
|
303
|
+
if (!value.CredentialBlob || value.CredentialBlobSize < 1 || value.CredentialBlobSize > 2560) throw new NativeCredentialError("INVALID_SECRET");
|
|
304
|
+
const bytes = Buffer.from(import_koffi.default.decode(value.CredentialBlob, "uint8_t", value.CredentialBlobSize));
|
|
305
|
+
try {
|
|
306
|
+
return bytes.toString("utf8");
|
|
307
|
+
} finally {
|
|
308
|
+
bytes.fill(0);
|
|
309
|
+
}
|
|
310
|
+
} finally {
|
|
311
|
+
free(result[0]);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function nativeCredentials(request) {
|
|
315
|
+
if (process.platform === "linux") return Promise.resolve().then(() => (init_linuxCredentials(), linuxCredentials_exports)).then((module2) => module2.linuxCredentials(request));
|
|
316
|
+
if (process.platform === "darwin") return macCredentials(request);
|
|
317
|
+
if (process.platform === "win32") return windowsCredentials(request);
|
|
318
|
+
throw new NativeCredentialError("UNSUPPORTED_PLATFORM");
|
|
319
|
+
}
|
|
320
|
+
var import_koffi, SERVICE2, NativeCredentialError, fail2;
|
|
321
|
+
var init_nativeCredentials = __esm({
|
|
322
|
+
"src/nativeCredentials.ts"() {
|
|
323
|
+
"use strict";
|
|
324
|
+
import_koffi = __toESM(require("koffi"));
|
|
325
|
+
SERVICE2 = "com.adspower.cli.client.v1";
|
|
326
|
+
NativeCredentialError = class extends Error {
|
|
327
|
+
};
|
|
328
|
+
fail2 = (platform, code) => {
|
|
329
|
+
throw new NativeCredentialError(`${platform}_${code}`);
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// src/credentialWorker.ts
|
|
335
|
+
var fs = __toESM(require("fs"));
|
|
336
|
+
init_nativeCredentials();
|
|
337
|
+
async function main() {
|
|
338
|
+
try {
|
|
339
|
+
const input = fs.readFileSync(0, "utf8");
|
|
340
|
+
if (Buffer.byteLength(input) > 32768) throw new Error("Invalid request");
|
|
341
|
+
const request = JSON.parse(input);
|
|
342
|
+
if (!["read", "write", "delete"].includes(request.operation) || !/^[a-f0-9]{64}$/.test(request.account) || request.operation === "write" && (typeof request.secret !== "string" || !request.secret.trim() || request.secret.length > 4096 || /[\r\n]/.test(request.secret))) throw new Error("Invalid request");
|
|
343
|
+
const secret = await nativeCredentials(request);
|
|
344
|
+
process.stdout.write(JSON.stringify({ ok: true, ...request.operation === "read" ? { secret } : {} }));
|
|
345
|
+
} catch (error) {
|
|
346
|
+
const code = error instanceof NativeCredentialError ? error.message : "NATIVE_FAILURE";
|
|
347
|
+
process.stdout.write(JSON.stringify({ ok: false, code }));
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
void main();
|
package/cli/index.js
CHANGED
|
@@ -25,19 +25,69 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
|
|
26
26
|
// src/clientSession.ts
|
|
27
27
|
var fs2 = __toESM(require("fs"));
|
|
28
|
-
var
|
|
28
|
+
var import_node_path2 = __toESM(require("path"));
|
|
29
29
|
var import_node_crypto = require("crypto");
|
|
30
30
|
|
|
31
|
+
// src/credentialVault.ts
|
|
32
|
+
var import_node_child_process = require("child_process");
|
|
33
|
+
var import_node_path = __toESM(require("path"));
|
|
34
|
+
var CredentialStoreError = class extends Error {
|
|
35
|
+
constructor(code) {
|
|
36
|
+
super(`System credential store unavailable (${code}). Use the same OS account and an accessible credential store, then run ads login again. No plaintext fallback is permitted.`);
|
|
37
|
+
this.name = "CredentialStoreError";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function invoke(operation, account, secret) {
|
|
41
|
+
if (!["darwin", "win32", "linux"].includes(process.platform)) throw new CredentialStoreError("UNSUPPORTED_PLATFORM");
|
|
42
|
+
if (!/^[a-f0-9]{64}$/.test(account)) throw new CredentialStoreError("INVALID_ACCOUNT");
|
|
43
|
+
let output;
|
|
44
|
+
try {
|
|
45
|
+
output = (0, import_node_child_process.execFileSync)(process.execPath, [import_node_path.default.join(__dirname, "credentialWorker.js")], {
|
|
46
|
+
input: JSON.stringify({ operation, account, secret }),
|
|
47
|
+
windowsHide: true,
|
|
48
|
+
timeout: 5e3,
|
|
49
|
+
killSignal: "SIGKILL",
|
|
50
|
+
maxBuffer: 32768,
|
|
51
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
52
|
+
});
|
|
53
|
+
} catch {
|
|
54
|
+
throw new CredentialStoreError("HELPER_FAILED_OR_TIMED_OUT");
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const result = JSON.parse(output.toString("utf8"));
|
|
58
|
+
if (result.ok !== true) {
|
|
59
|
+
const code = typeof result.code === "string" && /^[A-Z0-9_-]{1,64}$/.test(result.code) ? result.code : "NATIVE_FAILURE";
|
|
60
|
+
throw new CredentialStoreError(code);
|
|
61
|
+
}
|
|
62
|
+
if (operation === "read" && (typeof result.secret !== "string" || !result.secret.trim() || result.secret.length > 4096 || /[\r\n]/.test(result.secret))) throw new CredentialStoreError("INVALID_SECRET");
|
|
63
|
+
return result.secret;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (error instanceof CredentialStoreError) throw error;
|
|
66
|
+
throw new CredentialStoreError("INVALID_HELPER_RESPONSE");
|
|
67
|
+
} finally {
|
|
68
|
+
output.fill(0);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
var credentialVault = {
|
|
72
|
+
write: (account, secret) => {
|
|
73
|
+
invoke("write", account, secret);
|
|
74
|
+
},
|
|
75
|
+
read: (account) => invoke("read", account),
|
|
76
|
+
remove: (account) => {
|
|
77
|
+
invoke("delete", account);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
31
81
|
// src/tools/paths.ts
|
|
32
82
|
var os = __toESM(require("os"));
|
|
33
|
-
var
|
|
83
|
+
var path2 = __toESM(require("path"));
|
|
34
84
|
var fs = __toESM(require("fs"));
|
|
35
85
|
var import_fs_extra2 = require("fs-extra2");
|
|
36
86
|
var getHomedir = () => {
|
|
37
87
|
return (typeof os.homedir == "function" ? os.homedir() : process.env[process.platform == "win32" ? "USERPROFILE" : "HOME"]) || "~";
|
|
38
88
|
};
|
|
39
89
|
var getPidFileDir = (create = true) => {
|
|
40
|
-
const dir =
|
|
90
|
+
const dir = path2.join(getHomedir(), ".adspowerCli");
|
|
41
91
|
if (create && !fs.existsSync(dir)) {
|
|
42
92
|
(0, import_fs_extra2.ensureDirSync)(dir);
|
|
43
93
|
}
|
|
@@ -46,44 +96,75 @@ var getPidFileDir = (create = true) => {
|
|
|
46
96
|
|
|
47
97
|
// src/clientSession.ts
|
|
48
98
|
var isClientMode = () => process.env.IS_WORKBUDDY !== void 0;
|
|
49
|
-
var userFile = (userId) =>
|
|
50
|
-
var indexFile = () =>
|
|
99
|
+
var userFile = (userId) => import_node_path2.default.join(getPidFileDir(false), (0, import_node_crypto.createHash)("md5").update(userId).digest("hex"));
|
|
100
|
+
var indexFile = () => import_node_path2.default.join(getPidFileDir(false), "client-user.json");
|
|
101
|
+
var credentialAccount = (userId) => (0, import_node_crypto.createHash)("sha256").update(userId).digest("hex");
|
|
51
102
|
var validPort = (value) => Number.isInteger(value) && Number(value) > 0 && Number(value) <= 65535;
|
|
52
103
|
function isClientSession(value) {
|
|
53
104
|
if (!value || typeof value !== "object") return false;
|
|
54
105
|
const session = value;
|
|
55
106
|
return typeof session.apiKey === "string" && !!session.apiKey.trim() && session.apiKey.length <= 4096 && !/[\r\n]/.test(session.apiKey) && typeof session.userId === "string" && !!session.userId.trim() && session.userId.length <= 256 && session.userId !== "1.0.0" && validPort(session.apiPort) && validPort(session.rpaPort);
|
|
56
107
|
}
|
|
57
|
-
function
|
|
108
|
+
function readUserId() {
|
|
109
|
+
let value;
|
|
58
110
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
} catch {
|
|
111
|
+
value = JSON.parse(fs2.readFileSync(indexFile(), "utf8"));
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (error.code === "ENOENT") return;
|
|
114
|
+
throw new Error("Cannot read client user index. Run ads login again.");
|
|
64
115
|
}
|
|
116
|
+
const userId = value?.userId;
|
|
117
|
+
if (typeof userId !== "string" || !userId.trim() || userId.length > 256 || userId === "1.0.0") throw new Error("Invalid client user index. Run ads login again.");
|
|
118
|
+
return userId;
|
|
65
119
|
}
|
|
66
|
-
function
|
|
67
|
-
let
|
|
120
|
+
function readMetadata(userId) {
|
|
121
|
+
let value;
|
|
68
122
|
try {
|
|
69
|
-
|
|
70
|
-
} catch
|
|
71
|
-
|
|
123
|
+
value = JSON.parse(fs2.readFileSync(userFile(userId), "utf8"));
|
|
124
|
+
} catch {
|
|
125
|
+
throw new Error("Cannot read client connection metadata. Run ads login again.");
|
|
126
|
+
}
|
|
127
|
+
if (value && Object.prototype.hasOwnProperty.call(value, "apiKey")) {
|
|
128
|
+
throw new Error("Legacy plaintext credentials detected. Run ads login to replace them with system credentials, or ads logout to remove them. Plaintext credentials will not be used.");
|
|
72
129
|
}
|
|
73
|
-
if (
|
|
130
|
+
if (!value || value.version !== 2 || value.userId !== userId || !validPort(value.apiPort) || !validPort(value.rpaPort) || value.credentialAccount !== credentialAccount(userId)) {
|
|
131
|
+
throw new Error("Invalid client connection metadata. Run ads login again.");
|
|
132
|
+
}
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
function hasClientSession() {
|
|
136
|
+
const userId = readUserId();
|
|
137
|
+
if (!userId) return false;
|
|
138
|
+
readMetadata(userId);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
function readClientSession() {
|
|
142
|
+
const userId = readUserId();
|
|
143
|
+
if (!userId) return;
|
|
144
|
+
const metadata = readMetadata(userId);
|
|
145
|
+
const apiKey = credentialVault.read(metadata.credentialAccount);
|
|
146
|
+
const session = { apiKey, userId, apiPort: metadata.apiPort, rpaPort: metadata.rpaPort };
|
|
147
|
+
if (!isClientSession(session)) throw new Error("Invalid system credential. Run ads login again.");
|
|
148
|
+
return session;
|
|
149
|
+
}
|
|
150
|
+
function removeClientSession() {
|
|
151
|
+
const userId = readUserId();
|
|
152
|
+
if (!userId) return;
|
|
153
|
+
credentialVault.remove(credentialAccount(userId));
|
|
154
|
+
fs2.rmSync(userFile(userId), { force: true });
|
|
74
155
|
fs2.rmSync(indexFile(), { force: true });
|
|
75
156
|
}
|
|
76
157
|
|
|
77
158
|
// src/auth.ts
|
|
78
|
-
var
|
|
159
|
+
var import_node_child_process2 = require("child_process");
|
|
79
160
|
var import_node_fs = require("fs");
|
|
80
161
|
var import_node_os = __toESM(require("os"));
|
|
81
|
-
var
|
|
162
|
+
var import_node_path3 = __toESM(require("path"));
|
|
82
163
|
var import_node_net = require("net");
|
|
83
|
-
var pendingPath =
|
|
164
|
+
var pendingPath = import_node_path3.default.join(import_node_os.default.homedir(), ".adspowerCli", "workbuddy-login.json");
|
|
84
165
|
async function cancelLogin() {
|
|
85
166
|
await import_node_fs.promises.rm(pendingPath, { force: true });
|
|
86
|
-
const deadline = Date.now() +
|
|
167
|
+
const deadline = Date.now() + 2e4;
|
|
87
168
|
while (await loginWorkerIsRunning()) {
|
|
88
169
|
if (Date.now() >= deadline) throw new Error("Login cancellation timed out; retry ads logout");
|
|
89
170
|
await import_node_fs.promises.rm(pendingPath, { force: true });
|
|
@@ -108,7 +189,7 @@ async function login(input = {}) {
|
|
|
108
189
|
windowsHide: true,
|
|
109
190
|
stdio: ["ignore", "ignore", "ignore", "ipc"]
|
|
110
191
|
};
|
|
111
|
-
const child = (0,
|
|
192
|
+
const child = (0, import_node_child_process2.fork)(import_node_path3.default.join(__dirname, "authWorker.js"), [input.loginhost || "https://app.adspower.com"], options);
|
|
112
193
|
await new Promise((resolve, reject) => {
|
|
113
194
|
const timer = setTimeout(() => {
|
|
114
195
|
child.kill();
|
|
@@ -208,19 +289,19 @@ var store = new Store();
|
|
|
208
289
|
|
|
209
290
|
// src/core/start.ts
|
|
210
291
|
var fs6 = __toESM(require("fs"));
|
|
211
|
-
var
|
|
212
|
-
var
|
|
292
|
+
var path8 = __toESM(require("path"));
|
|
293
|
+
var import_node_child_process5 = require("child_process");
|
|
213
294
|
|
|
214
295
|
// src/tools/index.ts
|
|
215
296
|
var readline = __toESM(require("readline/promises"));
|
|
216
|
-
var
|
|
297
|
+
var path5 = __toESM(require("path"));
|
|
217
298
|
var fs4 = __toESM(require("fs"));
|
|
218
299
|
var crypto = __toESM(require("crypto"));
|
|
219
300
|
var util = __toESM(require("util"));
|
|
220
|
-
var
|
|
301
|
+
var import_node_child_process3 = require("child_process");
|
|
221
302
|
var import_colors = require("colors");
|
|
222
303
|
var import_fs_extra22 = require("fs-extra2");
|
|
223
|
-
var VERSION = (0, import_fs_extra22.readJsonSync)(
|
|
304
|
+
var VERSION = (0, import_fs_extra22.readJsonSync)(path5.join(__dirname, "../package.json")).version;
|
|
224
305
|
var VERSION_FILE = "1.0.0";
|
|
225
306
|
var toTerminalLink = (url, label) => {
|
|
226
307
|
const text = label || url;
|
|
@@ -249,7 +330,7 @@ var browsersKill = async () => {
|
|
|
249
330
|
};
|
|
250
331
|
var taskKillBrowser = () => new Promise((resolve) => {
|
|
251
332
|
const cmd = ["linux", "darwin"].includes(process.platform) ? 'pkill -u `whoami` -f "SunBrowser"' : "taskkill -PID SunBrowser.exe";
|
|
252
|
-
(0,
|
|
333
|
+
(0, import_node_child_process3.exec)(cmd, { windowsHide: true }, (err) => {
|
|
253
334
|
if (err) {
|
|
254
335
|
}
|
|
255
336
|
resolve();
|
|
@@ -257,7 +338,7 @@ var taskKillBrowser = () => new Promise((resolve) => {
|
|
|
257
338
|
});
|
|
258
339
|
var taskKillFlowser = () => new Promise((resolve) => {
|
|
259
340
|
const cmd = ["linux", "darwin"].includes(process.platform) ? 'pkill -u `whoami` -f "FlowerBrowser"' : "taskkill -PID FlowerBrowser.exe";
|
|
260
|
-
(0,
|
|
341
|
+
(0, import_node_child_process3.exec)(cmd, { windowsHide: true }, (err) => {
|
|
261
342
|
if (err) {
|
|
262
343
|
}
|
|
263
344
|
resolve();
|
|
@@ -268,19 +349,19 @@ var pidFileName = () => {
|
|
|
268
349
|
return md5;
|
|
269
350
|
};
|
|
270
351
|
var writePidFile = (config2) => {
|
|
271
|
-
const filePath =
|
|
352
|
+
const filePath = path5.join(getPidFileDir(), pidFileName());
|
|
272
353
|
(0, import_fs_extra22.outputJsonSync)(filePath, config2 || {}, { mode: 384 });
|
|
273
354
|
if (process.platform !== "win32") fs4.chmodSync(filePath, 384);
|
|
274
355
|
};
|
|
275
356
|
var readPidFile = () => {
|
|
276
|
-
const filePath =
|
|
357
|
+
const filePath = path5.join(getPidFileDir(false), pidFileName());
|
|
277
358
|
if (fs4.existsSync(filePath)) {
|
|
278
359
|
return (0, import_fs_extra22.readJsonSync)(filePath);
|
|
279
360
|
}
|
|
280
361
|
return {};
|
|
281
362
|
};
|
|
282
363
|
var removePidFile = () => {
|
|
283
|
-
const filePath =
|
|
364
|
+
const filePath = path5.join(getPidFileDir(), pidFileName());
|
|
284
365
|
if (fs4.existsSync(filePath)) {
|
|
285
366
|
(0, import_fs_extra22.removeSync)(filePath);
|
|
286
367
|
}
|
|
@@ -288,7 +369,7 @@ var removePidFile = () => {
|
|
|
288
369
|
var isRunning = (pid) => {
|
|
289
370
|
return new Promise((resolve) => {
|
|
290
371
|
if (pid) {
|
|
291
|
-
(0,
|
|
372
|
+
(0, import_node_child_process3.exec)(
|
|
292
373
|
util.format(process.platform === "win32" ? 'tasklist /fi "PID eq %s" | findstr /i "node.exe"' : 'ps -f -p %s | grep "node"', pid),
|
|
293
374
|
{ windowsHide: true },
|
|
294
375
|
function(err, stdout, stderr) {
|
|
@@ -301,7 +382,7 @@ var isRunning = (pid) => {
|
|
|
301
382
|
});
|
|
302
383
|
};
|
|
303
384
|
var ensureBrowserPath = () => {
|
|
304
|
-
const dir =
|
|
385
|
+
const dir = path5.join(__dirname, "../cwd/source", ".browser");
|
|
305
386
|
if (!fs4.existsSync(dir)) {
|
|
306
387
|
(0, import_fs_extra22.ensureDirSync)(dir);
|
|
307
388
|
}
|
|
@@ -340,7 +421,7 @@ var getApiKeyAndPort = (options) => {
|
|
|
340
421
|
return result;
|
|
341
422
|
};
|
|
342
423
|
var hasRunning = async (options) => {
|
|
343
|
-
if (isClientMode()) return
|
|
424
|
+
if (isClientMode()) return hasClientSession();
|
|
344
425
|
const { port } = options;
|
|
345
426
|
if (port) {
|
|
346
427
|
return true;
|
|
@@ -378,7 +459,7 @@ var createLoading = (text) => {
|
|
|
378
459
|
};
|
|
379
460
|
};
|
|
380
461
|
var initSqlite3 = () => {
|
|
381
|
-
const sqliteFile =
|
|
462
|
+
const sqliteFile = path5.join(__dirname, "../cwd/lib", "node_sqlite3.node");
|
|
382
463
|
if (fs4.existsSync(sqliteFile)) {
|
|
383
464
|
return;
|
|
384
465
|
}
|
|
@@ -391,13 +472,13 @@ var initSqlite3 = () => {
|
|
|
391
472
|
const winFolder = is32 ? "ia32" : "x64";
|
|
392
473
|
const linuxFolder = isLinux && isX64 && "linux";
|
|
393
474
|
const sqliteFolder = isMac ? macFolder : isLinux ? linuxFolder : winFolder;
|
|
394
|
-
const dir =
|
|
475
|
+
const dir = path5.join(__dirname, `../sqlite/${sqliteFolder}`);
|
|
395
476
|
if (!fs4.existsSync(dir)) {
|
|
396
477
|
throw new Error(`SQLite folder not found: ${dir}`);
|
|
397
478
|
} else {
|
|
398
|
-
const sqliteFile2 =
|
|
399
|
-
const cwdPath =
|
|
400
|
-
(0, import_fs_extra22.copySync)(sqliteFile2,
|
|
479
|
+
const sqliteFile2 = path5.join(dir, "node_sqlite3.node");
|
|
480
|
+
const cwdPath = path5.join(__dirname, "../cwd/lib");
|
|
481
|
+
(0, import_fs_extra22.copySync)(sqliteFile2, path5.join(cwdPath, "node_sqlite3.node"));
|
|
401
482
|
logSuccess(`[i] SQLite file initialized successfully!`);
|
|
402
483
|
}
|
|
403
484
|
};
|
|
@@ -430,7 +511,7 @@ async function promptYesNo(question) {
|
|
|
430
511
|
var import_axios = __toESM(require("axios"));
|
|
431
512
|
var import_fs = __toESM(require("fs"));
|
|
432
513
|
var import_path = __toESM(require("path"));
|
|
433
|
-
var
|
|
514
|
+
var import_node_child_process4 = require("child_process");
|
|
434
515
|
var NPM_PACKAGE_NAME = "adspower-browser";
|
|
435
516
|
var NPM_REGISTRY_URL = `https://registry.npmjs.org/${NPM_PACKAGE_NAME}/latest`;
|
|
436
517
|
var checkUpdates = async (apiKey, baseUrl) => {
|
|
@@ -507,7 +588,7 @@ var checkUpdateNpmPackage = async () => {
|
|
|
507
588
|
var updateNpmPackage = async () => {
|
|
508
589
|
const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
509
590
|
await new Promise((resolve, reject) => {
|
|
510
|
-
const child = (0,
|
|
591
|
+
const child = (0, import_node_child_process4.spawn)(npmCommand, ["install", "-g", `${NPM_PACKAGE_NAME}@latest`], {
|
|
511
592
|
stdio: "inherit",
|
|
512
593
|
windowsHide: true
|
|
513
594
|
});
|
|
@@ -2956,11 +3037,11 @@ var import_axios3 = __toESM(require("axios"));
|
|
|
2956
3037
|
|
|
2957
3038
|
// ../core/src/rpa/local/fileTransport.ts
|
|
2958
3039
|
var import_promises = require("fs/promises");
|
|
2959
|
-
var
|
|
3040
|
+
var import_node_path4 = require("path");
|
|
2960
3041
|
var import_node_zlib = require("zlib");
|
|
2961
3042
|
var MAX_FLOW_BYTES = 32 * 1024 * 1024;
|
|
2962
3043
|
async function readDebugProcess(filePath) {
|
|
2963
|
-
if (!(0,
|
|
3044
|
+
if (!(0, import_node_path4.isAbsolute)(filePath)) throw new Error("process_file must be an absolute local path");
|
|
2964
3045
|
const file = await (0, import_promises.open)(filePath, "r");
|
|
2965
3046
|
let bytes;
|
|
2966
3047
|
try {
|
|
@@ -2983,7 +3064,7 @@ async function readDebugProcess(filePath) {
|
|
|
2983
3064
|
}
|
|
2984
3065
|
async function writeRpaLogResult(data, outputFile) {
|
|
2985
3066
|
if (!outputFile) return JSON.stringify(data, null, 2);
|
|
2986
|
-
if (!(0,
|
|
3067
|
+
if (!(0, import_node_path4.isAbsolute)(outputFile)) throw new Error("output_file must be an absolute local path");
|
|
2987
3068
|
await (0, import_promises.writeFile)(outputFile, JSON.stringify(data), { flag: "wx", mode: 384 });
|
|
2988
3069
|
const result = Array.isArray(data) ? { total_items: data.length, items: data.slice(0, 10).map(summarizeLog), next_offset: data.length > 10 ? 10 : null } : summarizeLog(data);
|
|
2989
3070
|
return JSON.stringify({ output_file: outputFile, ...result }, null, 2);
|
|
@@ -4842,7 +4923,7 @@ var getRuntimeExecArgv = () => {
|
|
|
4842
4923
|
if (process.platform !== "win32") {
|
|
4843
4924
|
return [];
|
|
4844
4925
|
}
|
|
4845
|
-
const preload =
|
|
4926
|
+
const preload = path8.join(__dirname, "core/winHideChildProcess.js");
|
|
4846
4927
|
if (!fs6.existsSync(preload)) {
|
|
4847
4928
|
return [];
|
|
4848
4929
|
}
|
|
@@ -4882,7 +4963,7 @@ var startChild = (type) => {
|
|
|
4882
4963
|
Object.entries(getEnv()).map(([key, value]) => [key, value == null ? value : String(value)])
|
|
4883
4964
|
);
|
|
4884
4965
|
try {
|
|
4885
|
-
const mainJs =
|
|
4966
|
+
const mainJs = path8.join(__dirname, "../cwd/lib", "main.min.js");
|
|
4886
4967
|
const forkOptions = {
|
|
4887
4968
|
env,
|
|
4888
4969
|
detached: true,
|
|
@@ -4891,7 +4972,7 @@ var startChild = (type) => {
|
|
|
4891
4972
|
stdio: ["ignore", "ignore", "ignore", "ipc"],
|
|
4892
4973
|
execArgv: getRuntimeExecArgv()
|
|
4893
4974
|
};
|
|
4894
|
-
child = (0,
|
|
4975
|
+
child = (0, import_node_child_process5.fork)(mainJs, [], forkOptions);
|
|
4895
4976
|
ensureBrowserPath();
|
|
4896
4977
|
store.setStoreValue("status", "starting");
|
|
4897
4978
|
logSuccess(`[i] Adspower program is starting...`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adspower-browser",
|
|
3
|
-
"version": "2.1.7-beta.
|
|
3
|
+
"version": "2.1.7-beta.3",
|
|
4
4
|
"main": "cli/index.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": {
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
"axios": "^1.8.4",
|
|
18
18
|
"colors": "^1.4.0",
|
|
19
19
|
"commander": "^14.0.3",
|
|
20
|
+
"dbus-next": "0.10.2",
|
|
20
21
|
"fs-extra2": "^1.0.1",
|
|
22
|
+
"koffi": "2.15.2",
|
|
21
23
|
"playwright-core": "^1.51.1",
|
|
22
24
|
"zod": "^4.4.3"
|
|
23
25
|
},
|