@lightharu/krouter 1.8.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.
Files changed (61) hide show
  1. package/LICENSE +679 -0
  2. package/README.md +238 -0
  3. package/dist-web/assets/index-CM4-0adf.css +1 -0
  4. package/dist-web/assets/index-DCslvfUR.js +139 -0
  5. package/dist-web/favicon.svg +9 -0
  6. package/dist-web/icon.svg +9 -0
  7. package/dist-web/index.html +19 -0
  8. package/out-server/main/kiroAuthSync.js +249 -0
  9. package/out-server/main/kproxy/certManager.js +262 -0
  10. package/out-server/main/kproxy/index.js +254 -0
  11. package/out-server/main/kproxy/mitmProxy.js +475 -0
  12. package/out-server/main/kproxy/types.js +23 -0
  13. package/out-server/main/proxy/accountPool.js +543 -0
  14. package/out-server/main/proxy/clientConfig.js +596 -0
  15. package/out-server/main/proxy/index.js +25 -0
  16. package/out-server/main/proxy/kiroApi.js +1996 -0
  17. package/out-server/main/proxy/logger.js +407 -0
  18. package/out-server/main/proxy/modelCatalog.js +75 -0
  19. package/out-server/main/proxy/promptCacheTracker.js +301 -0
  20. package/out-server/main/proxy/proxyServer.js +3543 -0
  21. package/out-server/main/proxy/selfSignedCert.js +179 -0
  22. package/out-server/main/proxy/systemProxy.js +250 -0
  23. package/out-server/main/proxy/tokenCounter.js +164 -0
  24. package/out-server/main/proxy/toolNameRegistry.js +57 -0
  25. package/out-server/main/proxy/translator.js +1084 -0
  26. package/out-server/main/proxy/types.js +3 -0
  27. package/out-server/main/registration/browser-identity.js +184 -0
  28. package/out-server/main/registration/chainProxy.js +349 -0
  29. package/out-server/main/registration/config.js +58 -0
  30. package/out-server/main/registration/email-service.js +801 -0
  31. package/out-server/main/registration/fingerprint.js +352 -0
  32. package/out-server/main/registration/http-utils.js +148 -0
  33. package/out-server/main/registration/jwe.js +74 -0
  34. package/out-server/main/registration/names.js +142 -0
  35. package/out-server/main/registration/proton-mail-window.js +339 -0
  36. package/out-server/main/registration/registrar.js +1715 -0
  37. package/out-server/main/registration/tlsClientPool.js +70 -0
  38. package/out-server/main/registration/xxtea.js +161 -0
  39. package/out-server/main/runtimePaths.js +19 -0
  40. package/out-server/main/utils/redact.js +95 -0
  41. package/out-server/server/index.js +1272 -0
  42. package/out-server/server/services/accountExtras.js +105 -0
  43. package/out-server/server/services/accountProfileHydration.js +95 -0
  44. package/out-server/server/services/authFlows.js +509 -0
  45. package/out-server/server/services/dashboardTunnel.js +315 -0
  46. package/out-server/server/services/diagnostics.js +326 -0
  47. package/out-server/server/services/kiroAccounts.js +431 -0
  48. package/out-server/server/services/kiroSettings.js +260 -0
  49. package/out-server/server/services/kproxyRuntime.js +264 -0
  50. package/out-server/server/services/localKiroCredentials.js +320 -0
  51. package/out-server/server/services/machineIdRuntime.js +327 -0
  52. package/out-server/server/services/protonBrowserRuntime.js +724 -0
  53. package/out-server/server/services/proxyRuntime.js +523 -0
  54. package/out-server/server/services/registrationRuntime.js +106 -0
  55. package/out-server/server/store.js +266 -0
  56. package/package.json +113 -0
  57. package/resources/tls-client-xgo-1.14.0-windows-amd64.dll +0 -0
  58. package/scripts/kiro-manager-cli.cjs +3 -0
  59. package/scripts/krouter-cli.cjs +509 -0
  60. package/src/renderer/src/assets/krouter-logo.svg +11 -0
  61. package/src/renderer/src/assets/krouter-mark.svg +9 -0
@@ -0,0 +1,327 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.machineIdGetOSType = machineIdGetOSType;
7
+ exports.machineIdGenerateRandom = machineIdGenerateRandom;
8
+ exports.machineIdGetCurrent = machineIdGetCurrent;
9
+ exports.machineIdSet = machineIdSet;
10
+ exports.machineIdCheckAdmin = machineIdCheckAdmin;
11
+ exports.machineIdBackupToFile = machineIdBackupToFile;
12
+ exports.machineIdRestoreFromFile = machineIdRestoreFromFile;
13
+ const child_process_1 = require("child_process");
14
+ const fs_1 = require("fs");
15
+ const fs_2 = __importDefault(require("fs"));
16
+ const os_1 = __importDefault(require("os"));
17
+ const path_1 = __importDefault(require("path"));
18
+ const crypto_1 = __importDefault(require("crypto"));
19
+ const util_1 = require("util");
20
+ const runtimePaths_1 = require("../../main/runtimePaths");
21
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
22
+ function getOSType() {
23
+ if (process.platform === 'win32')
24
+ return 'windows';
25
+ if (process.platform === 'darwin')
26
+ return 'macos';
27
+ if (process.platform === 'linux')
28
+ return 'linux';
29
+ return 'unknown';
30
+ }
31
+ function isValidMachineId(machineId) {
32
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(machineId)
33
+ || /^[0-9a-f]{32}$/i.test(machineId);
34
+ }
35
+ function formatAsUuid(value) {
36
+ const clean = value.replace(/-/g, '').toLowerCase();
37
+ if (clean.length !== 32)
38
+ return value.toLowerCase();
39
+ return `${clean.slice(0, 8)}-${clean.slice(8, 12)}-${clean.slice(12, 16)}-${clean.slice(16, 20)}-${clean.slice(20)}`;
40
+ }
41
+ function findPowerShell() {
42
+ const systemRoot = process.env.SystemRoot || process.env.WINDIR || 'C:\\Windows';
43
+ const programFiles = process.env.ProgramFiles || 'C:\\Program Files';
44
+ const candidates = [
45
+ `${programFiles}\\PowerShell\\7\\pwsh.exe`,
46
+ `${systemRoot}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`,
47
+ `${systemRoot}\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe`,
48
+ 'pwsh.exe',
49
+ 'powershell.exe'
50
+ ];
51
+ for (const candidate of candidates) {
52
+ try {
53
+ if (path_1.default.isAbsolute(candidate)) {
54
+ if (fs_2.default.existsSync(candidate))
55
+ return candidate;
56
+ }
57
+ else {
58
+ const result = (0, child_process_1.execSync)(`where.exe ${candidate}`, { encoding: 'utf8', timeout: 3000, stdio: ['pipe', 'pipe', 'ignore'] });
59
+ const found = result.trim().split('\n')[0]?.trim();
60
+ if (found && fs_2.default.existsSync(found))
61
+ return found;
62
+ }
63
+ }
64
+ catch {
65
+ // Try the next candidate.
66
+ }
67
+ }
68
+ return null;
69
+ }
70
+ async function getWindowsMachineId() {
71
+ try {
72
+ const { stdout } = await execAsync('reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid', { timeout: 5000 });
73
+ const match = stdout.match(/MachineGuid\s+REG_SZ\s+([a-f0-9-]+)/i);
74
+ if (match?.[1])
75
+ return { success: true, machineId: match[1].toLowerCase() };
76
+ }
77
+ catch {
78
+ // Continue with PowerShell fallback.
79
+ }
80
+ const psPath = findPowerShell();
81
+ if (psPath) {
82
+ try {
83
+ const { stdout } = await execAsync(`"${psPath}" -NoProfile -Command "(Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Cryptography' -Name MachineGuid).MachineGuid"`, { timeout: 10000 });
84
+ const machineId = stdout.trim().toLowerCase();
85
+ if (isValidMachineId(machineId))
86
+ return { success: true, machineId };
87
+ }
88
+ catch {
89
+ // Continue with WMIC fallback.
90
+ }
91
+ }
92
+ try {
93
+ const { stdout } = await execAsync('wmic csproduct get UUID', { timeout: 5000 });
94
+ const uuid = stdout.split('\n').find((line) => line.trim() && !line.includes('UUID'))?.trim().toLowerCase();
95
+ if (uuid && uuid !== 'ffffffff-ffff-ffff-ffff-ffffffffffff')
96
+ return { success: true, machineId: uuid };
97
+ }
98
+ catch {
99
+ // No more fallbacks.
100
+ }
101
+ return { success: false, error: 'Unable to read Windows machine ID' };
102
+ }
103
+ async function setWindowsMachineId(newMachineId) {
104
+ try {
105
+ await execAsync(`reg add "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid /t REG_SZ /d "${newMachineId}" /f`, { timeout: 10000 });
106
+ return { success: true, machineId: newMachineId };
107
+ }
108
+ catch (error) {
109
+ const message = error instanceof Error ? error.message : String(error);
110
+ return {
111
+ success: false,
112
+ error: message,
113
+ requiresAdmin: /Access is denied|拒绝访问/i.test(message)
114
+ };
115
+ }
116
+ }
117
+ function macOverridePath() {
118
+ return path_1.default.join((0, runtimePaths_1.getRuntimeUserDataPath)(), 'machine-id-override');
119
+ }
120
+ function macKiroMachineIdPath() {
121
+ return path_1.default.join(os_1.default.homedir(), 'Library', 'Application Support', 'Kiro', 'machineid');
122
+ }
123
+ async function getMacMachineId() {
124
+ for (const filePath of [macOverridePath(), macKiroMachineIdPath()]) {
125
+ try {
126
+ const value = (await fs_1.promises.readFile(filePath, 'utf8')).trim();
127
+ if (isValidMachineId(value))
128
+ return { success: true, machineId: value.toLowerCase() };
129
+ }
130
+ catch {
131
+ // Try the next source.
132
+ }
133
+ }
134
+ try {
135
+ const { stdout } = await execAsync("ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { print $3 }'", { timeout: 5000 });
136
+ const machineId = stdout.trim().replace(/"/g, '').toLowerCase();
137
+ if (isValidMachineId(machineId))
138
+ return { success: true, machineId };
139
+ }
140
+ catch {
141
+ // No fallback.
142
+ }
143
+ return { success: false, error: 'Unable to read macOS machine ID' };
144
+ }
145
+ async function setMacMachineId(newMachineId) {
146
+ try {
147
+ await fs_1.promises.mkdir(path_1.default.dirname(macOverridePath()), { recursive: true });
148
+ await fs_1.promises.writeFile(macOverridePath(), newMachineId, 'utf8');
149
+ await fs_1.promises.mkdir(path_1.default.dirname(macKiroMachineIdPath()), { recursive: true });
150
+ await fs_1.promises.writeFile(macKiroMachineIdPath(), newMachineId, 'utf8');
151
+ return { success: true, machineId: newMachineId };
152
+ }
153
+ catch (error) {
154
+ return { success: false, error: error instanceof Error ? error.message : 'Failed to set macOS machine ID' };
155
+ }
156
+ }
157
+ async function getLinuxMachineId() {
158
+ for (const filePath of linuxMachineIdPaths()) {
159
+ try {
160
+ const value = (await fs_1.promises.readFile(filePath, 'utf8')).trim();
161
+ if (value)
162
+ return { success: true, machineId: formatAsUuid(value) };
163
+ }
164
+ catch {
165
+ // Try next path.
166
+ }
167
+ }
168
+ return { success: false, error: 'Unable to read Linux machine ID' };
169
+ }
170
+ function linuxMachineIdPaths() {
171
+ if (process.env.KIRO_MACHINE_ID_FILE)
172
+ return [path_1.default.resolve(process.env.KIRO_MACHINE_ID_FILE)];
173
+ return ['/etc/machine-id', '/var/lib/dbus/machine-id'];
174
+ }
175
+ function machineIdFileOverridePath() {
176
+ return process.env.KIRO_MACHINE_ID_FILE ? path_1.default.resolve(process.env.KIRO_MACHINE_ID_FILE) : null;
177
+ }
178
+ async function readMachineIdFileOverride() {
179
+ const filePath = machineIdFileOverridePath();
180
+ if (!filePath)
181
+ return null;
182
+ try {
183
+ const value = (await fs_1.promises.readFile(filePath, 'utf8')).trim();
184
+ return value && isValidMachineId(value)
185
+ ? { success: true, machineId: formatAsUuid(value) }
186
+ : { success: false, error: `Machine ID override file is empty or invalid: ${filePath}` };
187
+ }
188
+ catch (error) {
189
+ return { success: false, error: error instanceof Error ? error.message : `Unable to read machine ID override file: ${filePath}` };
190
+ }
191
+ }
192
+ async function writeMachineIdFileOverride(newMachineId) {
193
+ const filePath = machineIdFileOverridePath();
194
+ if (!filePath)
195
+ return null;
196
+ const raw = newMachineId.replace(/-/g, '').toLowerCase();
197
+ try {
198
+ await fs_1.promises.mkdir(path_1.default.dirname(filePath), { recursive: true });
199
+ await fs_1.promises.writeFile(filePath, `${raw}\n`, 'utf8');
200
+ return { success: true, machineId: formatAsUuid(raw) };
201
+ }
202
+ catch (error) {
203
+ return { success: false, error: error instanceof Error ? error.message : `Unable to write machine ID override file: ${filePath}` };
204
+ }
205
+ }
206
+ async function setLinuxMachineId(newMachineId) {
207
+ const raw = newMachineId.replace(/-/g, '').toLowerCase();
208
+ const paths = linuxMachineIdPaths();
209
+ let wrote = false;
210
+ for (const filePath of paths) {
211
+ try {
212
+ if (process.env.KIRO_MACHINE_ID_FILE) {
213
+ await fs_1.promises.mkdir(path_1.default.dirname(filePath), { recursive: true });
214
+ }
215
+ else {
216
+ await fs_1.promises.access(filePath);
217
+ }
218
+ await fs_1.promises.writeFile(filePath, `${raw}\n`, 'utf8');
219
+ wrote = true;
220
+ }
221
+ catch (error) {
222
+ const message = error instanceof Error ? error.message : String(error);
223
+ if (/EACCES|EPERM|permission/i.test(message)) {
224
+ return { success: false, error: 'Administrator/root permission is required to modify machine-id on this VPS.', requiresAdmin: true };
225
+ }
226
+ }
227
+ }
228
+ return wrote
229
+ ? { success: true, machineId: formatAsUuid(raw) }
230
+ : { success: false, error: 'No Linux machine-id file was found' };
231
+ }
232
+ function machineIdGetOSType() {
233
+ return getOSType();
234
+ }
235
+ function machineIdGenerateRandom() {
236
+ return crypto_1.default.randomUUID().toLowerCase();
237
+ }
238
+ async function machineIdGetCurrent() {
239
+ if (process.env.KIRO_MACHINE_ID_OVERRIDE) {
240
+ const machineId = process.env.KIRO_MACHINE_ID_OVERRIDE.trim();
241
+ return isValidMachineId(machineId)
242
+ ? { success: true, machineId: formatAsUuid(machineId) }
243
+ : { success: false, error: 'KIRO_MACHINE_ID_OVERRIDE has an invalid format' };
244
+ }
245
+ const overrideResult = await readMachineIdFileOverride();
246
+ if (overrideResult)
247
+ return overrideResult;
248
+ if (process.platform === 'win32')
249
+ return getWindowsMachineId();
250
+ if (process.platform === 'darwin')
251
+ return getMacMachineId();
252
+ if (process.platform === 'linux')
253
+ return getLinuxMachineId();
254
+ return { success: false, error: 'Unsupported operating system' };
255
+ }
256
+ async function machineIdSet(newMachineId) {
257
+ if (!isValidMachineId(newMachineId))
258
+ return { success: false, error: 'Invalid machine ID format' };
259
+ const overrideResult = await writeMachineIdFileOverride(newMachineId);
260
+ if (overrideResult)
261
+ return overrideResult;
262
+ if (process.platform === 'win32')
263
+ return setWindowsMachineId(newMachineId);
264
+ if (process.platform === 'darwin')
265
+ return setMacMachineId(newMachineId);
266
+ if (process.platform === 'linux')
267
+ return setLinuxMachineId(newMachineId);
268
+ return { success: false, error: 'Unsupported operating system' };
269
+ }
270
+ async function machineIdCheckAdmin() {
271
+ if (process.env.KIRO_MACHINE_ID_FILE)
272
+ return true;
273
+ if (process.platform === 'linux')
274
+ return process.getuid?.() === 0;
275
+ if (process.platform === 'darwin')
276
+ return true;
277
+ if (process.platform !== 'win32')
278
+ return false;
279
+ const psPath = findPowerShell();
280
+ if (psPath) {
281
+ try {
282
+ const result = (0, child_process_1.execSync)(`"${psPath}" -NoProfile -Command "([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)"`, { encoding: 'utf8', timeout: 5000 });
283
+ return result.trim().toLowerCase() === 'true';
284
+ }
285
+ catch {
286
+ // Fall through to net session.
287
+ }
288
+ }
289
+ try {
290
+ (0, child_process_1.execSync)('net session', { stdio: 'ignore', timeout: 3000 });
291
+ return true;
292
+ }
293
+ catch {
294
+ return false;
295
+ }
296
+ }
297
+ function backupPath() {
298
+ if (process.env.KIRO_MACHINE_ID_BACKUP_PATH)
299
+ return path_1.default.resolve(process.env.KIRO_MACHINE_ID_BACKUP_PATH);
300
+ return path_1.default.join((0, runtimePaths_1.getRuntimeUserDataPath)(), 'machine-id-backup.json');
301
+ }
302
+ async function machineIdBackupToFile(machineId) {
303
+ try {
304
+ await fs_1.promises.mkdir(path_1.default.dirname(backupPath()), { recursive: true });
305
+ await fs_1.promises.writeFile(backupPath(), JSON.stringify({
306
+ machineId,
307
+ backupTime: Date.now(),
308
+ osType: getOSType(),
309
+ runtime: 'web-vps'
310
+ }, null, 2), 'utf8');
311
+ return true;
312
+ }
313
+ catch {
314
+ return false;
315
+ }
316
+ }
317
+ async function machineIdRestoreFromFile() {
318
+ try {
319
+ const data = JSON.parse(await fs_1.promises.readFile(backupPath(), 'utf8'));
320
+ if (!data.machineId || !isValidMachineId(data.machineId))
321
+ return { success: false, error: 'Invalid backup file' };
322
+ return { success: true, machineId: data.machineId };
323
+ }
324
+ catch (error) {
325
+ return { success: false, error: error instanceof Error ? error.message : 'Failed to read machine ID backup' };
326
+ }
327
+ }