@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.
- package/LICENSE +679 -0
- package/README.md +238 -0
- package/dist-web/assets/index-CM4-0adf.css +1 -0
- package/dist-web/assets/index-DCslvfUR.js +139 -0
- package/dist-web/favicon.svg +9 -0
- package/dist-web/icon.svg +9 -0
- package/dist-web/index.html +19 -0
- package/out-server/main/kiroAuthSync.js +249 -0
- package/out-server/main/kproxy/certManager.js +262 -0
- package/out-server/main/kproxy/index.js +254 -0
- package/out-server/main/kproxy/mitmProxy.js +475 -0
- package/out-server/main/kproxy/types.js +23 -0
- package/out-server/main/proxy/accountPool.js +543 -0
- package/out-server/main/proxy/clientConfig.js +596 -0
- package/out-server/main/proxy/index.js +25 -0
- package/out-server/main/proxy/kiroApi.js +1996 -0
- package/out-server/main/proxy/logger.js +407 -0
- package/out-server/main/proxy/modelCatalog.js +75 -0
- package/out-server/main/proxy/promptCacheTracker.js +301 -0
- package/out-server/main/proxy/proxyServer.js +3543 -0
- package/out-server/main/proxy/selfSignedCert.js +179 -0
- package/out-server/main/proxy/systemProxy.js +250 -0
- package/out-server/main/proxy/tokenCounter.js +164 -0
- package/out-server/main/proxy/toolNameRegistry.js +57 -0
- package/out-server/main/proxy/translator.js +1084 -0
- package/out-server/main/proxy/types.js +3 -0
- package/out-server/main/registration/browser-identity.js +184 -0
- package/out-server/main/registration/chainProxy.js +349 -0
- package/out-server/main/registration/config.js +58 -0
- package/out-server/main/registration/email-service.js +801 -0
- package/out-server/main/registration/fingerprint.js +352 -0
- package/out-server/main/registration/http-utils.js +148 -0
- package/out-server/main/registration/jwe.js +74 -0
- package/out-server/main/registration/names.js +142 -0
- package/out-server/main/registration/proton-mail-window.js +339 -0
- package/out-server/main/registration/registrar.js +1715 -0
- package/out-server/main/registration/tlsClientPool.js +70 -0
- package/out-server/main/registration/xxtea.js +161 -0
- package/out-server/main/runtimePaths.js +19 -0
- package/out-server/main/utils/redact.js +95 -0
- package/out-server/server/index.js +1272 -0
- package/out-server/server/services/accountExtras.js +105 -0
- package/out-server/server/services/accountProfileHydration.js +95 -0
- package/out-server/server/services/authFlows.js +509 -0
- package/out-server/server/services/dashboardTunnel.js +315 -0
- package/out-server/server/services/diagnostics.js +326 -0
- package/out-server/server/services/kiroAccounts.js +431 -0
- package/out-server/server/services/kiroSettings.js +260 -0
- package/out-server/server/services/kproxyRuntime.js +264 -0
- package/out-server/server/services/localKiroCredentials.js +320 -0
- package/out-server/server/services/machineIdRuntime.js +327 -0
- package/out-server/server/services/protonBrowserRuntime.js +724 -0
- package/out-server/server/services/proxyRuntime.js +523 -0
- package/out-server/server/services/registrationRuntime.js +106 -0
- package/out-server/server/store.js +266 -0
- package/package.json +113 -0
- package/resources/tls-client-xgo-1.14.0-windows-amd64.dll +0 -0
- package/scripts/kiro-manager-cli.cjs +3 -0
- package/scripts/krouter-cli.cjs +509 -0
- package/src/renderer/src/assets/krouter-logo.svg +11 -0
- package/src/renderer/src/assets/krouter-mark.svg +9 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.KProxyService = exports.MitmProxy = exports.CertManager = void 0;
|
|
40
|
+
exports.getKProxyService = getKProxyService;
|
|
41
|
+
exports.initKProxyService = initKProxyService;
|
|
42
|
+
exports.generateDeviceId = generateDeviceId;
|
|
43
|
+
exports.isValidDeviceId = isValidDeviceId;
|
|
44
|
+
// K-Proxy 模块入口
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const certManager_1 = require("./certManager");
|
|
47
|
+
const mitmProxy_1 = require("./mitmProxy");
|
|
48
|
+
const runtimePaths_1 = require("../runtimePaths");
|
|
49
|
+
const types_1 = require("./types");
|
|
50
|
+
// 导出类型
|
|
51
|
+
__exportStar(require("./types"), exports);
|
|
52
|
+
var certManager_2 = require("./certManager");
|
|
53
|
+
Object.defineProperty(exports, "CertManager", { enumerable: true, get: function () { return certManager_2.CertManager; } });
|
|
54
|
+
var mitmProxy_2 = require("./mitmProxy");
|
|
55
|
+
Object.defineProperty(exports, "MitmProxy", { enumerable: true, get: function () { return mitmProxy_2.MitmProxy; } });
|
|
56
|
+
/**
|
|
57
|
+
* K-Proxy 服务管理器
|
|
58
|
+
*/
|
|
59
|
+
class KProxyService {
|
|
60
|
+
certManager = null;
|
|
61
|
+
mitmProxy = null;
|
|
62
|
+
config;
|
|
63
|
+
events;
|
|
64
|
+
deviceIdMappings = new Map();
|
|
65
|
+
dataPath;
|
|
66
|
+
initialized = false;
|
|
67
|
+
cachedCaInfo = null;
|
|
68
|
+
constructor(config = {}, events = {}) {
|
|
69
|
+
this.config = { ...types_1.DEFAULT_KPROXY_CONFIG, ...config };
|
|
70
|
+
this.events = events;
|
|
71
|
+
this.dataPath = path.join((0, runtimePaths_1.getRuntimeUserDataPath)(), 'kproxy');
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 初始化服务(只初始化一次)
|
|
75
|
+
*/
|
|
76
|
+
async initialize() {
|
|
77
|
+
// 如果已初始化,直接返回缓存的 CA 信息
|
|
78
|
+
if (this.initialized && this.cachedCaInfo) {
|
|
79
|
+
console.log('[KProxyService] Already initialized, returning cached CA info');
|
|
80
|
+
return this.cachedCaInfo;
|
|
81
|
+
}
|
|
82
|
+
// 初始化证书管理器
|
|
83
|
+
this.certManager = (0, certManager_1.createCertManager)(this.dataPath);
|
|
84
|
+
const caInfo = await this.certManager.initialize();
|
|
85
|
+
// 初始化 MITM 代理
|
|
86
|
+
this.mitmProxy = new mitmProxy_1.MitmProxy(this.certManager, this.config, this.events);
|
|
87
|
+
this.initialized = true;
|
|
88
|
+
this.cachedCaInfo = caInfo;
|
|
89
|
+
console.log('[KProxyService] Initialized');
|
|
90
|
+
return caInfo;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 启动代理服务
|
|
94
|
+
*/
|
|
95
|
+
async start() {
|
|
96
|
+
if (!this.mitmProxy) {
|
|
97
|
+
await this.initialize();
|
|
98
|
+
}
|
|
99
|
+
await this.mitmProxy.start();
|
|
100
|
+
this.config.enabled = true;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 停止代理服务
|
|
104
|
+
*/
|
|
105
|
+
async stop() {
|
|
106
|
+
if (this.mitmProxy) {
|
|
107
|
+
await this.mitmProxy.stop();
|
|
108
|
+
}
|
|
109
|
+
this.config.enabled = false;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 重启代理服务
|
|
113
|
+
*/
|
|
114
|
+
async restart() {
|
|
115
|
+
await this.stop();
|
|
116
|
+
await this.start();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 更新配置
|
|
120
|
+
*/
|
|
121
|
+
updateConfig(config) {
|
|
122
|
+
this.config = { ...this.config, ...config };
|
|
123
|
+
if (this.mitmProxy) {
|
|
124
|
+
this.mitmProxy.updateConfig(this.config);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 获取配置
|
|
129
|
+
*/
|
|
130
|
+
getConfig() {
|
|
131
|
+
return { ...this.config };
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 获取统计信息
|
|
135
|
+
*/
|
|
136
|
+
getStats() {
|
|
137
|
+
return this.mitmProxy?.getStats() || null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* 获取 CA 证书信息
|
|
141
|
+
*/
|
|
142
|
+
getCACertInfo() {
|
|
143
|
+
return this.certManager?.getCACertInfo() || null;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 获取 CA 证书 PEM(用于导出/安装)
|
|
147
|
+
*/
|
|
148
|
+
getCACertPem() {
|
|
149
|
+
return this.certManager?.getCACertPem() || null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 设置当前设备 ID
|
|
153
|
+
*/
|
|
154
|
+
setDeviceId(deviceId) {
|
|
155
|
+
this.config.deviceId = deviceId;
|
|
156
|
+
if (this.mitmProxy) {
|
|
157
|
+
this.mitmProxy.updateConfig({ deviceId });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* 获取当前设备 ID
|
|
162
|
+
*/
|
|
163
|
+
getDeviceId() {
|
|
164
|
+
return this.config.deviceId;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 添加设备 ID 映射
|
|
168
|
+
*/
|
|
169
|
+
addDeviceIdMapping(mapping) {
|
|
170
|
+
this.deviceIdMappings.set(mapping.accountId, mapping);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 移除设备 ID 映射
|
|
174
|
+
*/
|
|
175
|
+
removeDeviceIdMapping(accountId) {
|
|
176
|
+
this.deviceIdMappings.delete(accountId);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* 获取账号的设备 ID
|
|
180
|
+
*/
|
|
181
|
+
getDeviceIdForAccount(accountId) {
|
|
182
|
+
return this.deviceIdMappings.get(accountId)?.deviceId;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* 获取所有设备 ID 映射
|
|
186
|
+
*/
|
|
187
|
+
getAllDeviceIdMappings() {
|
|
188
|
+
return Array.from(this.deviceIdMappings.values());
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 切换到账号的设备 ID
|
|
192
|
+
*/
|
|
193
|
+
switchToAccount(accountId) {
|
|
194
|
+
const mapping = this.deviceIdMappings.get(accountId);
|
|
195
|
+
if (mapping) {
|
|
196
|
+
this.setDeviceId(mapping.deviceId);
|
|
197
|
+
mapping.lastUsed = Date.now();
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* 检查是否运行中
|
|
204
|
+
*/
|
|
205
|
+
isRunning() {
|
|
206
|
+
return this.mitmProxy?.isRunning() || false;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 重置统计
|
|
210
|
+
*/
|
|
211
|
+
resetStats() {
|
|
212
|
+
this.mitmProxy?.resetStats();
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* 清除证书缓存
|
|
216
|
+
*/
|
|
217
|
+
clearCertCache() {
|
|
218
|
+
this.certManager?.clearCache();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.KProxyService = KProxyService;
|
|
222
|
+
// 单例实例
|
|
223
|
+
let kproxyService = null;
|
|
224
|
+
/**
|
|
225
|
+
* 获取 K-Proxy 服务实例
|
|
226
|
+
*/
|
|
227
|
+
function getKProxyService() {
|
|
228
|
+
return kproxyService;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* 初始化 K-Proxy 服务
|
|
232
|
+
*/
|
|
233
|
+
function initKProxyService(config = {}, events = {}) {
|
|
234
|
+
if (!kproxyService) {
|
|
235
|
+
kproxyService = new KProxyService(config, events);
|
|
236
|
+
}
|
|
237
|
+
return kproxyService;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* 生成随机设备 ID(64位十六进制)
|
|
241
|
+
*/
|
|
242
|
+
function generateDeviceId() {
|
|
243
|
+
const bytes = new Uint8Array(32);
|
|
244
|
+
crypto.getRandomValues(bytes);
|
|
245
|
+
return Array.from(bytes)
|
|
246
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
247
|
+
.join('');
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* 验证设备 ID 格式
|
|
251
|
+
*/
|
|
252
|
+
function isValidDeviceId(deviceId) {
|
|
253
|
+
return /^[a-f0-9]{64}$/i.test(deviceId);
|
|
254
|
+
}
|