ai-remote 0.4.2 → 0.4.4

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 (75) hide show
  1. package/dist/index.js +1 -6
  2. package/dist/{protocols/index.d.ts → protocols.d.ts} +2 -0
  3. package/dist/protocols.js +24 -0
  4. package/package.json +15 -10
  5. package/dist/protocols/index.js +0 -34
  6. package/dist/protocols/rdp/buffer.d.ts +0 -38
  7. package/dist/protocols/rdp/buffer.js +0 -169
  8. package/dist/protocols/rdp/caps.d.ts +0 -49
  9. package/dist/protocols/rdp/caps.js +0 -259
  10. package/dist/protocols/rdp/cert.d.ts +0 -18
  11. package/dist/protocols/rdp/cert.js +0 -134
  12. package/dist/protocols/rdp/client.d.ts +0 -56
  13. package/dist/protocols/rdp/client.js +0 -1069
  14. package/dist/protocols/rdp/cliprdr.d.ts +0 -27
  15. package/dist/protocols/rdp/cliprdr.js +0 -239
  16. package/dist/protocols/rdp/credssp.d.ts +0 -34
  17. package/dist/protocols/rdp/credssp.js +0 -253
  18. package/dist/protocols/rdp/crypto.d.ts +0 -63
  19. package/dist/protocols/rdp/crypto.js +0 -368
  20. package/dist/protocols/rdp/display.d.ts +0 -38
  21. package/dist/protocols/rdp/display.js +0 -588
  22. package/dist/protocols/rdp/gcc.d.ts +0 -23
  23. package/dist/protocols/rdp/gcc.js +0 -131
  24. package/dist/protocols/rdp/keymap.d.ts +0 -9
  25. package/dist/protocols/rdp/keymap.js +0 -131
  26. package/dist/protocols/rdp/mcs.d.ts +0 -40
  27. package/dist/protocols/rdp/mcs.js +0 -222
  28. package/dist/protocols/rdp/ntlm.d.ts +0 -61
  29. package/dist/protocols/rdp/ntlm.js +0 -304
  30. package/dist/protocols/rdp/pdu.d.ts +0 -155
  31. package/dist/protocols/rdp/pdu.js +0 -443
  32. package/dist/protocols/rdp/rail.d.ts +0 -119
  33. package/dist/protocols/rdp/rail.js +0 -382
  34. package/dist/protocols/rdp/rle.d.ts +0 -13
  35. package/dist/protocols/rdp/rle.js +0 -275
  36. package/dist/protocols/rdp/sec.d.ts +0 -59
  37. package/dist/protocols/rdp/sec.js +0 -155
  38. package/dist/protocols/rdp/session.d.ts +0 -62
  39. package/dist/protocols/rdp/session.js +0 -306
  40. package/dist/protocols/rdp/tls.d.ts +0 -18
  41. package/dist/protocols/rdp/tls.js +0 -353
  42. package/dist/protocols/rdp/vchannel.d.ts +0 -28
  43. package/dist/protocols/rdp/vchannel.js +0 -58
  44. package/dist/protocols/rdp/x224.d.ts +0 -40
  45. package/dist/protocols/rdp/x224.js +0 -109
  46. package/dist/protocols/ssh/kex.d.ts +0 -97
  47. package/dist/protocols/ssh/kex.js +0 -176
  48. package/dist/protocols/ssh/messages.d.ts +0 -50
  49. package/dist/protocols/ssh/messages.js +0 -54
  50. package/dist/protocols/ssh/session.d.ts +0 -66
  51. package/dist/protocols/ssh/session.js +0 -608
  52. package/dist/protocols/ssh/terminal.d.ts +0 -46
  53. package/dist/protocols/ssh/terminal.js +0 -190
  54. package/dist/protocols/ssh/transport.d.ts +0 -62
  55. package/dist/protocols/ssh/transport.js +0 -612
  56. package/dist/protocols/ssh/wire.d.ts +0 -52
  57. package/dist/protocols/ssh/wire.js +0 -188
  58. package/dist/protocols/types.d.ts +0 -127
  59. package/dist/protocols/types.js +0 -0
  60. package/dist/protocols/vnc/input.d.ts +0 -5
  61. package/dist/protocols/vnc/input.js +0 -15
  62. package/dist/protocols/vnc/session.d.ts +0 -12
  63. package/dist/protocols/vnc/session.js +0 -258
  64. package/dist/shared/connection.d.ts +0 -81
  65. package/dist/shared/connection.js +0 -113
  66. package/dist/shared/device.d.ts +0 -26
  67. package/dist/shared/device.js +0 -0
  68. package/dist/shared/hosts.d.ts +0 -63
  69. package/dist/shared/hosts.js +0 -132
  70. package/dist/shared/icons.d.ts +0 -46
  71. package/dist/shared/icons.js +0 -41
  72. package/dist/shared/protocol.d.ts +0 -28
  73. package/dist/shared/protocol.js +0 -39
  74. package/dist/shared/signals.d.ts +0 -37
  75. package/dist/shared/signals.js +0 -41
@@ -1,368 +0,0 @@
1
- const MD5_SHIFTS = [
2
- 7,
3
- 12,
4
- 17,
5
- 22,
6
- 7,
7
- 12,
8
- 17,
9
- 22,
10
- 7,
11
- 12,
12
- 17,
13
- 22,
14
- 7,
15
- 12,
16
- 17,
17
- 22,
18
- 5,
19
- 9,
20
- 14,
21
- 20,
22
- 5,
23
- 9,
24
- 14,
25
- 20,
26
- 5,
27
- 9,
28
- 14,
29
- 20,
30
- 5,
31
- 9,
32
- 14,
33
- 20,
34
- 4,
35
- 11,
36
- 16,
37
- 23,
38
- 4,
39
- 11,
40
- 16,
41
- 23,
42
- 4,
43
- 11,
44
- 16,
45
- 23,
46
- 4,
47
- 11,
48
- 16,
49
- 23,
50
- 6,
51
- 10,
52
- 15,
53
- 21,
54
- 6,
55
- 10,
56
- 15,
57
- 21,
58
- 6,
59
- 10,
60
- 15,
61
- 21,
62
- 6,
63
- 10,
64
- 15,
65
- 21
66
- ];
67
- const MD5_K = new Uint32Array(
68
- Array.from({ length: 64 }, (_, i) => Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296))
69
- );
70
- function rotl32(value, count) {
71
- return value << count | value >>> 32 - count;
72
- }
73
- function md5(message) {
74
- const bitLength = message.length * 8;
75
- const blockCount = Math.floor((message.length + 8) / 64) + 1;
76
- const padded = new Uint8Array(blockCount * 64);
77
- padded.set(message);
78
- padded[message.length] = 128;
79
- const tail = new DataView(padded.buffer, padded.byteLength - 8, 8);
80
- tail.setUint32(0, bitLength >>> 0, true);
81
- tail.setUint32(4, Math.floor(bitLength / 4294967296), true);
82
- let a0 = 1732584193, b0 = 4023233417, c0 = 2562383102, d0 = 271733878;
83
- const words = new Uint32Array(16);
84
- const view = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);
85
- for (let block = 0; block < blockCount; block++) {
86
- for (let i = 0; i < 16; i++) words[i] = view.getUint32(block * 64 + i * 4, true);
87
- let a = a0, b = b0, c = c0, d = d0;
88
- for (let i = 0; i < 64; i++) {
89
- let f;
90
- let g;
91
- if (i < 16) {
92
- f = b & c | ~b & d;
93
- g = i;
94
- } else if (i < 32) {
95
- f = d & b | ~d & c;
96
- g = (5 * i + 1) % 16;
97
- } else if (i < 48) {
98
- f = b ^ c ^ d;
99
- g = (3 * i + 5) % 16;
100
- } else {
101
- f = c ^ (b | ~d);
102
- g = 7 * i % 16;
103
- }
104
- const temp = d;
105
- d = c;
106
- c = b;
107
- const sum = a + f + MD5_K[i] + words[g] | 0;
108
- b = b + rotl32(sum, MD5_SHIFTS[i]) | 0;
109
- a = temp;
110
- }
111
- a0 = a0 + a | 0;
112
- b0 = b0 + b | 0;
113
- c0 = c0 + c | 0;
114
- d0 = d0 + d | 0;
115
- }
116
- const digest = new Uint8Array(16);
117
- const out = new DataView(digest.buffer);
118
- out.setUint32(0, a0 >>> 0, true);
119
- out.setUint32(4, b0 >>> 0, true);
120
- out.setUint32(8, c0 >>> 0, true);
121
- out.setUint32(12, d0 >>> 0, true);
122
- return digest;
123
- }
124
- function sha1(message) {
125
- const bitLength = message.length * 8;
126
- const blockCount = Math.floor((message.length + 8) / 64) + 1;
127
- const padded = new Uint8Array(blockCount * 64);
128
- padded.set(message);
129
- padded[message.length] = 128;
130
- const tail = new DataView(padded.buffer, padded.byteLength - 8, 8);
131
- tail.setUint32(0, Math.floor(bitLength / 4294967296));
132
- tail.setUint32(4, bitLength >>> 0);
133
- let h0 = 1732584193, h1 = 4023233417, h2 = 2562383102, h3 = 271733878, h4 = 3285377520;
134
- const words = new Uint32Array(80);
135
- const view = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);
136
- for (let block = 0; block < blockCount; block++) {
137
- for (let i = 0; i < 16; i++) words[i] = view.getUint32(block * 64 + i * 4);
138
- for (let i = 16; i < 80; i++) {
139
- words[i] = rotl32(words[i - 3] ^ words[i - 8] ^ words[i - 14] ^ words[i - 16], 1);
140
- }
141
- let a = h0, b = h1, c = h2, d = h3, e = h4;
142
- for (let i = 0; i < 80; i++) {
143
- let f;
144
- let k;
145
- if (i < 20) {
146
- f = b & c | ~b & d;
147
- k = 1518500249;
148
- } else if (i < 40) {
149
- f = b ^ c ^ d;
150
- k = 1859775393;
151
- } else if (i < 60) {
152
- f = b & c | b & d | c & d;
153
- k = 2400959708;
154
- } else {
155
- f = b ^ c ^ d;
156
- k = 3395469782;
157
- }
158
- const temp = rotl32(a, 5) + f + e + k + words[i] | 0;
159
- e = d;
160
- d = c;
161
- c = rotl32(b, 30);
162
- b = a;
163
- a = temp;
164
- }
165
- h0 = h0 + a | 0;
166
- h1 = h1 + b | 0;
167
- h2 = h2 + c | 0;
168
- h3 = h3 + d | 0;
169
- h4 = h4 + e | 0;
170
- }
171
- const digest = new Uint8Array(20);
172
- const out = new DataView(digest.buffer);
173
- [h0, h1, h2, h3, h4].forEach((word, i) => out.setUint32(i * 4, word >>> 0));
174
- return digest;
175
- }
176
- function rc4Init(key) {
177
- const s = new Uint8Array(256);
178
- for (let i = 0; i < 256; i++) s[i] = i;
179
- let j = 0;
180
- for (let i = 0; i < 256; i++) {
181
- j = j + (s[i] ?? 0) + (key[i % key.length] ?? 0) & 255;
182
- const t = s[i] ?? 0;
183
- s[i] = s[j] ?? 0;
184
- s[j] = t;
185
- }
186
- return { s, i: 0, j: 0 };
187
- }
188
- function rc4Crypt(state, data) {
189
- const out = new Uint8Array(data.length);
190
- const { s } = state;
191
- let { i, j } = state;
192
- for (let n = 0; n < data.length; n++) {
193
- i = i + 1 & 255;
194
- j = j + s[i] & 255;
195
- const t = s[i];
196
- s[i] = s[j];
197
- s[j] = t;
198
- out[n] = data[n] ^ s[s[i] + s[j] & 255];
199
- }
200
- state.i = i;
201
- state.j = j;
202
- return out;
203
- }
204
- function bigIntFromLe(bytes) {
205
- let value = 0n;
206
- for (let i = bytes.length - 1; i >= 0; i--) value = value << 8n | BigInt(bytes[i]);
207
- return value;
208
- }
209
- function bigIntToLe(value, length) {
210
- const out = new Uint8Array(length);
211
- let remaining = value;
212
- for (let i = 0; i < length; i++) {
213
- out[i] = Number(remaining & 0xffn);
214
- remaining >>= 8n;
215
- }
216
- return out;
217
- }
218
- function modPow(base, exponent, modulus) {
219
- let result = 1n;
220
- let b = base % modulus;
221
- let e = exponent;
222
- while (e > 0n) {
223
- if (e & 1n) result = result * b % modulus;
224
- b = b * b % modulus;
225
- e >>= 1n;
226
- }
227
- return result;
228
- }
229
- function rsaEncrypt(dataLe, modulusLe, exponentLe) {
230
- const modulus = bigIntFromLe(modulusLe);
231
- const exponent = bigIntFromLe(exponentLe);
232
- const value = bigIntFromLe(dataLe);
233
- if (value >= modulus) throw new Error("RDP: client random is larger than the server RSA modulus");
234
- return bigIntToLe(modPow(value, exponent, modulus), modulusLe.length);
235
- }
236
- function rsaEncryptPkcs1(message, modulusBe, exponentBe) {
237
- const bigIntFromBe = (bytes) => {
238
- let value = 0n;
239
- for (const byte of bytes) value = value << 8n | BigInt(byte);
240
- return value;
241
- };
242
- const modulus = bigIntFromBe(modulusBe);
243
- const exponent = bigIntFromBe(exponentBe);
244
- const keyLength = modulusBe.length;
245
- if (message.length > keyLength - 11) {
246
- throw new Error("TLS: RSA message is too long for this key");
247
- }
248
- const block = new Uint8Array(keyLength);
249
- block[0] = 0;
250
- block[1] = 2;
251
- const paddingLength = keyLength - message.length - 3;
252
- const padding = new Uint8Array(paddingLength);
253
- crypto.getRandomValues(padding);
254
- for (let i = 0; i < paddingLength; i++) {
255
- while (padding[i] === 0) padding[i] = Math.max(1, crypto.getRandomValues(new Uint8Array(1))[0]);
256
- block[2 + i] = padding[i];
257
- }
258
- block[2 + paddingLength] = 0;
259
- block.set(message, 3 + paddingLength);
260
- const cipher = modPow(bigIntFromBe(block), exponent, modulus);
261
- const out = new Uint8Array(keyLength);
262
- let remaining = cipher;
263
- for (let i = keyLength - 1; i >= 0; i--) {
264
- out[i] = Number(remaining & 0xffn);
265
- remaining >>= 8n;
266
- }
267
- return out;
268
- }
269
- const PAD1 = new Uint8Array(40).fill(54);
270
- const PAD2 = new Uint8Array(48).fill(92);
271
- const ENCRYPTION_METHOD = {
272
- NONE: 0,
273
- BIT_40: 1,
274
- BIT_128: 2,
275
- BIT_56: 8,
276
- FIPS: 16
277
- };
278
- function concat(...parts) {
279
- const total = parts.reduce((sum, part) => sum + part.length, 0);
280
- const out = new Uint8Array(total);
281
- let offset = 0;
282
- for (const part of parts) {
283
- out.set(part, offset);
284
- offset += part.length;
285
- }
286
- return out;
287
- }
288
- function saltedHash(secret, salt, clientRandom, serverRandom) {
289
- return md5(concat(secret, sha1(concat(salt, secret, clientRandom, serverRandom))));
290
- }
291
- function finalHash(key, clientRandom, serverRandom) {
292
- return md5(concat(key, clientRandom, serverRandom));
293
- }
294
- const SALT_A = new Uint8Array([65]);
295
- const SALT_BB = new Uint8Array([66, 66]);
296
- const SALT_CCC = new Uint8Array([67, 67, 67]);
297
- const SALT_X = new Uint8Array([88]);
298
- const SALT_YY = new Uint8Array([89, 89]);
299
- const SALT_ZZZ = new Uint8Array([90, 90, 90]);
300
- function reduceKey(key, keyLength, is40Bit) {
301
- if (keyLength !== 8) return key.slice(0, keyLength);
302
- const reduced = key.slice(0, 8);
303
- reduced[0] = 209;
304
- if (is40Bit) {
305
- reduced[1] = 38;
306
- reduced[2] = 158;
307
- }
308
- return reduced;
309
- }
310
- function keyLengthForMethod(encryptionMethod) {
311
- if (encryptionMethod === ENCRYPTION_METHOD.BIT_40) return 8;
312
- if (encryptionMethod === ENCRYPTION_METHOD.BIT_56) return 8;
313
- return 16;
314
- }
315
- function deriveSessionKeys(clientRandom, serverRandom, encryptionMethod) {
316
- const preMasterSecret = concat(clientRandom.subarray(0, 24), serverRandom.subarray(0, 24));
317
- const masterSecret = concat(
318
- saltedHash(preMasterSecret, SALT_A, clientRandom, serverRandom),
319
- saltedHash(preMasterSecret, SALT_BB, clientRandom, serverRandom),
320
- saltedHash(preMasterSecret, SALT_CCC, clientRandom, serverRandom)
321
- );
322
- const sessionKeyBlob = concat(
323
- saltedHash(masterSecret, SALT_X, clientRandom, serverRandom),
324
- saltedHash(masterSecret, SALT_YY, clientRandom, serverRandom),
325
- saltedHash(masterSecret, SALT_ZZZ, clientRandom, serverRandom)
326
- );
327
- const keyLength = keyLengthForMethod(encryptionMethod);
328
- const is40Bit = encryptionMethod === ENCRYPTION_METHOD.BIT_40;
329
- const applyReduction = (key) => reduceKey(key, keyLength, is40Bit);
330
- const macKey = applyReduction(sessionKeyBlob.subarray(0, 16));
331
- const decryptKey = applyReduction(finalHash(sessionKeyBlob.subarray(16, 32), clientRandom, serverRandom));
332
- const encryptKey = applyReduction(finalHash(sessionKeyBlob.subarray(32, 48), clientRandom, serverRandom));
333
- return {
334
- macKey,
335
- keyLength,
336
- is40Bit,
337
- // Session-key updates always restart from these initial values.
338
- initialDecryptKey: decryptKey.slice(),
339
- initialEncryptKey: encryptKey.slice(),
340
- decryptKey,
341
- encryptKey
342
- };
343
- }
344
- function macSignature(macKey, data) {
345
- const lengthField = new Uint8Array(4);
346
- new DataView(lengthField.buffer).setUint32(0, data.length, true);
347
- const inner = sha1(concat(macKey, PAD1, lengthField, data));
348
- return md5(concat(macKey, PAD2, inner)).subarray(0, 8);
349
- }
350
- function updateSessionKey(initialKey, currentKey, keyLength, is40Bit) {
351
- const inner = sha1(concat(initialKey, PAD1, currentKey));
352
- const nextKey = md5(concat(initialKey, PAD2, inner)).slice(0, keyLength);
353
- const salted = rc4Crypt(rc4Init(nextKey), nextKey);
354
- return reduceKey(salted, keyLength, is40Bit);
355
- }
356
- export {
357
- ENCRYPTION_METHOD,
358
- deriveSessionKeys,
359
- keyLengthForMethod,
360
- macSignature,
361
- md5,
362
- rc4Crypt,
363
- rc4Init,
364
- rsaEncrypt,
365
- rsaEncryptPkcs1,
366
- sha1,
367
- updateSessionKey
368
- };
@@ -1,38 +0,0 @@
1
- export declare class RdpDisplay {
2
- #private;
3
- constructor(container: any);
4
- resize(width: number, height: number): void;
5
- /**
6
- * Choose the part of the desktop that is on screen. Everything else about
7
- * the session -- painting, input coordinates, the remote pointer -- keeps
8
- * working in desktop coordinates, so only the framing changes here.
9
- */
10
- setViewport({ x, y, width, height }?: {
11
- x?: number;
12
- y?: number;
13
- }): void;
14
- applyScale(): void;
15
- /**
16
- * Zoom about a point, keeping whatever is under it in place. `focal` is in
17
- * client coordinates -- the midpoint between two fingers, usually.
18
- */
19
- setZoom(next: any, focal?: any): void;
20
- /** Move the visible window over the desktop. Returns what it actually used. */
21
- panBy(dx: any, dy: any): {
22
- x: number;
23
- y: number;
24
- };
25
- /** True when the desktop is larger than the window on either axis. */
26
- canPan(): boolean;
27
- setScaleViewport(enabled: boolean): void;
28
- /** Back to the opening view: whole desktop fitted on screen. */
29
- resetZoom(): void;
30
- drawRects(rects: any, palette: any): void;
31
- applyPointer(pointer: any): void;
32
- attachInput(client: any): void;
33
- /** A key held while focus moves away would otherwise stay down on the host. */
34
- releaseAllKeys(): void;
35
- focus(): void;
36
- blur(): void;
37
- destroy(): void;
38
- }