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,169 +0,0 @@
1
- function allocate(length) {
2
- return new Uint8Array(length);
3
- }
4
- class Writer {
5
- bytes;
6
- view;
7
- offset = 0;
8
- constructor(capacity = 512) {
9
- this.bytes = allocate(capacity);
10
- this.view = new DataView(this.bytes.buffer);
11
- }
12
- #ensure(extra) {
13
- if (this.offset + extra <= this.bytes.length) return;
14
- let capacity = this.bytes.length * 2;
15
- while (capacity < this.offset + extra) capacity *= 2;
16
- const grown = allocate(capacity);
17
- grown.set(this.bytes.subarray(0, this.offset));
18
- this.bytes = grown;
19
- this.view = new DataView(grown.buffer);
20
- }
21
- u8(value) {
22
- this.#ensure(1);
23
- this.view.setUint8(this.offset, value);
24
- this.offset += 1;
25
- return this;
26
- }
27
- u16le(value) {
28
- this.#ensure(2);
29
- this.view.setUint16(this.offset, value, true);
30
- this.offset += 2;
31
- return this;
32
- }
33
- u16be(value) {
34
- this.#ensure(2);
35
- this.view.setUint16(this.offset, value, false);
36
- this.offset += 2;
37
- return this;
38
- }
39
- u32le(value) {
40
- this.#ensure(4);
41
- this.view.setUint32(this.offset, value >>> 0, true);
42
- this.offset += 4;
43
- return this;
44
- }
45
- u32be(value) {
46
- this.#ensure(4);
47
- this.view.setUint32(this.offset, value >>> 0, false);
48
- this.offset += 4;
49
- return this;
50
- }
51
- raw(bytes) {
52
- this.#ensure(bytes.length);
53
- this.bytes.set(bytes, this.offset);
54
- this.offset += bytes.length;
55
- return this;
56
- }
57
- zeros(count) {
58
- this.#ensure(count);
59
- this.offset += count;
60
- return this;
61
- }
62
- /** UTF-16LE, optionally padded or truncated to a fixed byte width. */
63
- utf16le(text, fixedBytes) {
64
- const start = this.offset;
65
- for (const unit of text) {
66
- const code = unit.codePointAt(0) ?? 0;
67
- if (fixedBytes !== void 0 && this.offset - start >= fixedBytes - 2) break;
68
- if (code > 65535) {
69
- for (let i = 0; i < unit.length; i++) this.u16le(unit.charCodeAt(i));
70
- } else {
71
- this.u16le(code);
72
- }
73
- }
74
- if (fixedBytes !== void 0) {
75
- this.zeros(fixedBytes - (this.offset - start));
76
- }
77
- return this;
78
- }
79
- /** Overwrite an earlier 16-bit slot, for length fields known only later. */
80
- patchU16le(position, value) {
81
- this.view.setUint16(position, value, true);
82
- return this;
83
- }
84
- patchU16be(position, value) {
85
- this.view.setUint16(position, value, false);
86
- return this;
87
- }
88
- get length() {
89
- return this.offset;
90
- }
91
- take() {
92
- return this.bytes.slice(0, this.offset);
93
- }
94
- }
95
- class Reader {
96
- bytes;
97
- view;
98
- offset;
99
- constructor(bytes, offset = 0) {
100
- this.bytes = bytes;
101
- this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
102
- this.offset = offset;
103
- }
104
- get remaining() {
105
- return this.bytes.length - this.offset;
106
- }
107
- #need(count) {
108
- if (this.remaining < count) {
109
- throw new Error(`RDP: truncated frame (needed ${count} bytes, ${this.remaining} left)`);
110
- }
111
- }
112
- u8() {
113
- this.#need(1);
114
- return this.view.getUint8(this.offset++);
115
- }
116
- u16le() {
117
- this.#need(2);
118
- const value = this.view.getUint16(this.offset, true);
119
- this.offset += 2;
120
- return value;
121
- }
122
- u16be() {
123
- this.#need(2);
124
- const value = this.view.getUint16(this.offset, false);
125
- this.offset += 2;
126
- return value;
127
- }
128
- u32le() {
129
- this.#need(4);
130
- const value = this.view.getUint32(this.offset, true);
131
- this.offset += 4;
132
- return value;
133
- }
134
- u32be() {
135
- this.#need(4);
136
- const value = this.view.getUint32(this.offset, false);
137
- this.offset += 4;
138
- return value;
139
- }
140
- raw(count) {
141
- this.#need(count);
142
- const slice = this.bytes.subarray(this.offset, this.offset + count);
143
- this.offset += count;
144
- return slice;
145
- }
146
- skip(count) {
147
- this.#need(count);
148
- this.offset += count;
149
- return this;
150
- }
151
- rest() {
152
- return this.bytes.subarray(this.offset);
153
- }
154
- }
155
- function concatBytes(...parts) {
156
- const total = parts.reduce((sum, part) => sum + part.length, 0);
157
- const out = allocate(total);
158
- let offset = 0;
159
- for (const part of parts) {
160
- out.set(part, offset);
161
- offset += part.length;
162
- }
163
- return out;
164
- }
165
- export {
166
- Reader,
167
- Writer,
168
- concatBytes
169
- };
@@ -1,49 +0,0 @@
1
- export declare const CAPSET: {
2
- GENERAL: number;
3
- BITMAP: number;
4
- ORDER: number;
5
- BITMAPCACHE: number;
6
- CONTROL: number;
7
- ACTIVATION: number;
8
- POINTER: number;
9
- SHARE: number;
10
- COLORCACHE: number;
11
- SOUND: number;
12
- INPUT: number;
13
- FONT: number;
14
- BRUSH: number;
15
- GLYPHCACHE: number;
16
- OFFSCREENCACHE: number;
17
- VIRTUALCHANNEL: number;
18
- RAIL: number;
19
- WINDOW: number;
20
- MULTIFRAGMENTUPDATE: number;
21
- LARGE_POINTER: number;
22
- SURFACE_COMMANDS: number;
23
- BITMAP_CODECS: number;
24
- };
25
- export declare function buildClientCapabilities({ width, height, keyboardLayout, remoteApp, remoteAppCaps }: {
26
- height: any;
27
- keyboardLayout: any;
28
- remoteApp?: boolean;
29
- remoteAppCaps?: any;
30
- width: any;
31
- }): {
32
- bytes: Uint8Array<ArrayBufferLike>;
33
- count: number;
34
- };
35
- /**
36
- * Read the host's Demand Active capabilities. The desktop size it reports wins
37
- * over anything the client asked for.
38
- */
39
- export declare function parseServerCapabilities(bytes: Uint8Array): {
40
- desktopWidth: number;
41
- desktopHeight: number;
42
- preferredBitsPerPixel: number;
43
- refreshRectSupport: boolean;
44
- railSupportLevel: number;
45
- windowSupportLevel: number;
46
- numIconCaches: number;
47
- numIconCacheEntries: number;
48
- types: any[];
49
- };
@@ -1,259 +0,0 @@
1
- import { Reader, Writer, concatBytes } from "./buffer.js";
2
- const CAPSET = {
3
- GENERAL: 1,
4
- BITMAP: 2,
5
- ORDER: 3,
6
- BITMAPCACHE: 4,
7
- CONTROL: 5,
8
- ACTIVATION: 7,
9
- POINTER: 8,
10
- SHARE: 9,
11
- COLORCACHE: 10,
12
- SOUND: 12,
13
- INPUT: 13,
14
- FONT: 14,
15
- BRUSH: 15,
16
- GLYPHCACHE: 16,
17
- OFFSCREENCACHE: 17,
18
- VIRTUALCHANNEL: 20,
19
- RAIL: 23,
20
- WINDOW: 24,
21
- MULTIFRAGMENTUPDATE: 26,
22
- LARGE_POINTER: 27,
23
- SURFACE_COMMANDS: 28,
24
- BITMAP_CODECS: 29
25
- };
26
- const INPUT_FLAG_SCANCODES = 1;
27
- const INPUT_FLAG_MOUSEX = 4;
28
- const INPUT_FLAG_UNICODE = 16;
29
- const FASTPATH_OUTPUT_SUPPORTED = 1;
30
- const LONG_CREDENTIALS_SUPPORTED = 4;
31
- const NEGOTIATE_ORDER_SUPPORT = 2;
32
- const ZERO_BOUNDS_DELTA_SUPPORT = 8;
33
- function capabilitySet(type, body) {
34
- const writer = new Writer(body.length + 4);
35
- writer.u16le(type).u16le(body.length + 4).raw(body);
36
- return writer.take();
37
- }
38
- function generalCapability() {
39
- const writer = new Writer(24);
40
- writer.u16le(1);
41
- writer.u16le(3);
42
- writer.u16le(512);
43
- writer.u16le(0);
44
- writer.u16le(0);
45
- writer.u16le(FASTPATH_OUTPUT_SUPPORTED | LONG_CREDENTIALS_SUPPORTED);
46
- writer.u16le(0);
47
- writer.u16le(0);
48
- writer.u16le(0);
49
- writer.u8(1);
50
- writer.u8(1);
51
- return capabilitySet(CAPSET.GENERAL, writer.take());
52
- }
53
- function bitmapCapability(width, height) {
54
- const writer = new Writer(28);
55
- writer.u16le(16);
56
- writer.u16le(1);
57
- writer.u16le(1);
58
- writer.u16le(1);
59
- writer.u16le(width);
60
- writer.u16le(height);
61
- writer.u16le(0);
62
- writer.u16le(1);
63
- writer.u16le(1);
64
- writer.u8(0);
65
- writer.u8(0);
66
- writer.u16le(1);
67
- writer.u16le(0);
68
- return capabilitySet(CAPSET.BITMAP, writer.take());
69
- }
70
- function orderCapability() {
71
- const writer = new Writer(88);
72
- writer.zeros(16);
73
- writer.u32le(0);
74
- writer.u16le(1);
75
- writer.u16le(20);
76
- writer.u16le(0);
77
- writer.u16le(1);
78
- writer.u16le(0);
79
- writer.u16le(NEGOTIATE_ORDER_SUPPORT | ZERO_BOUNDS_DELTA_SUPPORT);
80
- writer.zeros(32);
81
- writer.u16le(0);
82
- writer.u16le(0);
83
- writer.u32le(0);
84
- writer.u32le(230400);
85
- writer.u16le(0);
86
- writer.u16le(0);
87
- writer.u16le(0);
88
- writer.u16le(0);
89
- return capabilitySet(CAPSET.ORDER, writer.take());
90
- }
91
- function bitmapCacheCapability() {
92
- const writer = new Writer(40);
93
- writer.zeros(24);
94
- writer.u16le(0).u16le(0);
95
- writer.u16le(0).u16le(0);
96
- writer.u16le(0).u16le(0);
97
- return capabilitySet(CAPSET.BITMAPCACHE, writer.take());
98
- }
99
- function controlCapability() {
100
- const writer = new Writer(12);
101
- writer.u16le(0);
102
- writer.u16le(0);
103
- writer.u16le(2);
104
- writer.u16le(2);
105
- return capabilitySet(CAPSET.CONTROL, writer.take());
106
- }
107
- function activationCapability() {
108
- const writer = new Writer(12);
109
- writer.u16le(0).u16le(0).u16le(0).u16le(0);
110
- return capabilitySet(CAPSET.ACTIVATION, writer.take());
111
- }
112
- function pointerCapability() {
113
- const writer = new Writer(10);
114
- writer.u16le(1);
115
- writer.u16le(20);
116
- writer.u16le(20);
117
- return capabilitySet(CAPSET.POINTER, writer.take());
118
- }
119
- function shareCapability() {
120
- const writer = new Writer(8);
121
- writer.u16le(0).u16le(0);
122
- return capabilitySet(CAPSET.SHARE, writer.take());
123
- }
124
- function colorCacheCapability() {
125
- const writer = new Writer(8);
126
- writer.u16le(6).u16le(0);
127
- return capabilitySet(CAPSET.COLORCACHE, writer.take());
128
- }
129
- function soundCapability() {
130
- const writer = new Writer(8);
131
- writer.u16le(0).u16le(0);
132
- return capabilitySet(CAPSET.SOUND, writer.take());
133
- }
134
- function inputCapability(keyboardLayout) {
135
- const writer = new Writer(88);
136
- writer.u16le(INPUT_FLAG_SCANCODES | INPUT_FLAG_MOUSEX | INPUT_FLAG_UNICODE);
137
- writer.u16le(0);
138
- writer.u32le(keyboardLayout);
139
- writer.u32le(4);
140
- writer.u32le(0);
141
- writer.u32le(12);
142
- writer.zeros(64);
143
- return capabilitySet(CAPSET.INPUT, writer.take());
144
- }
145
- function fontCapability() {
146
- const writer = new Writer(8);
147
- writer.u16le(1).u16le(0);
148
- return capabilitySet(CAPSET.FONT, writer.take());
149
- }
150
- function brushCapability() {
151
- const writer = new Writer(8);
152
- writer.u32le(0);
153
- return capabilitySet(CAPSET.BRUSH, writer.take());
154
- }
155
- function glyphCacheCapability() {
156
- const writer = new Writer(52);
157
- for (let i = 0; i < 10; i++) writer.u16le(0).u16le(0);
158
- writer.u32le(0);
159
- writer.u16le(0);
160
- writer.u16le(0);
161
- return capabilitySet(CAPSET.GLYPHCACHE, writer.take());
162
- }
163
- function offscreenCacheCapability() {
164
- const writer = new Writer(12);
165
- writer.u32le(0);
166
- writer.u16le(0);
167
- writer.u16le(0);
168
- return capabilitySet(CAPSET.OFFSCREENCACHE, writer.take());
169
- }
170
- function remoteProgramsCapability() {
171
- const writer = new Writer(4);
172
- writer.u32le(1);
173
- return capabilitySet(CAPSET.RAIL, writer.take());
174
- }
175
- function windowListCapability(iconCaches = 0, iconCacheEntries = 0) {
176
- const writer = new Writer(7);
177
- writer.u32le(1);
178
- writer.u8(iconCaches);
179
- writer.u16le(iconCacheEntries);
180
- return capabilitySet(CAPSET.WINDOW, writer.take());
181
- }
182
- function buildClientCapabilities({ width, height, keyboardLayout, remoteApp = false, remoteAppCaps = null }) {
183
- const sets = [
184
- generalCapability(),
185
- bitmapCapability(width, height),
186
- orderCapability(),
187
- bitmapCacheCapability(),
188
- colorCacheCapability(),
189
- activationCapability(),
190
- controlCapability(),
191
- pointerCapability(),
192
- shareCapability(),
193
- inputCapability(keyboardLayout),
194
- brushCapability(),
195
- glyphCacheCapability(),
196
- soundCapability(),
197
- fontCapability(),
198
- offscreenCacheCapability()
199
- ];
200
- if (remoteApp) {
201
- sets.push(remoteProgramsCapability());
202
- sets.push(windowListCapability(
203
- remoteAppCaps?.numIconCaches || 0,
204
- remoteAppCaps?.numIconCacheEntries || 0
205
- ));
206
- }
207
- return { bytes: concatBytes(...sets), count: sets.length };
208
- }
209
- function parseServerCapabilities(bytes) {
210
- const reader = new Reader(bytes);
211
- const numberCapabilities = reader.u16le();
212
- reader.u16le();
213
- const result = {
214
- desktopWidth: 0,
215
- desktopHeight: 0,
216
- preferredBitsPerPixel: 16,
217
- refreshRectSupport: false,
218
- railSupportLevel: 0,
219
- windowSupportLevel: 0,
220
- numIconCaches: 0,
221
- numIconCacheEntries: 0,
222
- types: []
223
- };
224
- for (let i = 0; i < numberCapabilities && reader.remaining >= 4; i++) {
225
- const type = reader.u16le();
226
- const length = reader.u16le();
227
- if (length < 4 || length - 4 > reader.remaining) break;
228
- const body = new Reader(reader.raw(length - 4));
229
- result.types.push(type);
230
- if (type === CAPSET.BITMAP && body.remaining >= 20) {
231
- result.preferredBitsPerPixel = body.u16le();
232
- body.skip(6);
233
- result.desktopWidth = body.u16le();
234
- result.desktopHeight = body.u16le();
235
- continue;
236
- }
237
- if (type === CAPSET.GENERAL && body.remaining >= 20) {
238
- body.skip(18);
239
- result.refreshRectSupport = body.u8() !== 0;
240
- continue;
241
- }
242
- if (type === CAPSET.RAIL && body.remaining >= 4) {
243
- result.railSupportLevel = body.u32le();
244
- continue;
245
- }
246
- if (type === CAPSET.WINDOW && body.remaining >= 7) {
247
- result.windowSupportLevel = body.u32le();
248
- result.numIconCaches = body.u8();
249
- result.numIconCacheEntries = body.u16le();
250
- continue;
251
- }
252
- }
253
- return result;
254
- }
255
- export {
256
- CAPSET,
257
- buildClientCapabilities,
258
- parseServerCapabilities
259
- };
@@ -1,18 +0,0 @@
1
- /**
2
- * Pull the RSA public key out of a DER X.509 certificate, for the TLS layer.
3
- *
4
- * CredSSP needs the exact bytes of the certificate's subjectPublicKey BIT
5
- * STRING contents -- the DER RSAPublicKey -- because that is what both ends
6
- * hash to bind the authentication to this TLS channel (MS-CSSP 3.1.5).
7
- */
8
- export declare function parseX509PublicKey(der: Uint8Array): {
9
- modulus: Uint8Array<ArrayBufferLike>;
10
- exponent: Uint8Array<ArrayBufferLike>;
11
- subjectPublicKey: any;
12
- };
13
- /** Parse a server certificate blob into an RSA public key. */
14
- export declare function parseServerCertificate(certificateBytes: Uint8Array): {
15
- modulus: Uint8Array<ArrayBuffer>;
16
- exponent: Uint8Array<ArrayBuffer>;
17
- source: string;
18
- };
@@ -1,134 +0,0 @@
1
- import { Reader } from "./buffer.js";
2
- const CERT_PROPRIETARY = 1;
3
- const CERT_X509 = 2;
4
- const RSA1_MAGIC = 826364754;
5
- const BB_RSA_KEY_BLOB = 6;
6
- const OID_RSA_ENCRYPTION = [42, 134, 72, 134, 247, 13, 1, 1, 1];
7
- function derRead(bytes, offset) {
8
- let cursor = offset;
9
- const tag = bytes[cursor++];
10
- let length = bytes[cursor++];
11
- if (length & 128) {
12
- const byteCount = length & 127;
13
- length = 0;
14
- for (let i = 0; i < byteCount; i++) length = length << 8 | bytes[cursor++];
15
- }
16
- return {
17
- tag,
18
- contentStart: cursor,
19
- contentEnd: cursor + length,
20
- next: cursor + length,
21
- content: bytes.subarray(cursor, cursor + length)
22
- };
23
- }
24
- function derChildren(bytes) {
25
- const children = [];
26
- let offset = 0;
27
- while (offset < bytes.length) {
28
- const node = derRead(bytes, offset);
29
- children.push(node);
30
- if (node.next <= offset) break;
31
- offset = node.next;
32
- }
33
- return children;
34
- }
35
- function containsOid(bytes, oid) {
36
- outer: for (let i = 0; i + oid.length <= bytes.length; i++) {
37
- for (let j = 0; j < oid.length; j++) {
38
- if (bytes[i + j] !== oid[j]) continue outer;
39
- }
40
- return true;
41
- }
42
- return false;
43
- }
44
- function derIntegerToLe(content) {
45
- let start = 0;
46
- while (start < content.length - 1 && content[start] === 0) start++;
47
- return content.subarray(start).slice().reverse();
48
- }
49
- function rsaKeyFromX509(der) {
50
- const certificate = derRead(der, 0);
51
- const tbsCertificate = derRead(der, certificate.contentStart);
52
- for (const child of derChildren(tbsCertificate.content)) {
53
- if (child.tag !== 48) continue;
54
- const parts = derChildren(child.content);
55
- if (parts.length < 2) continue;
56
- if (parts[0].tag !== 48 || !containsOid(parts[0].content, OID_RSA_ENCRYPTION)) continue;
57
- if (parts[1].tag !== 3) continue;
58
- const publicKey = derRead(parts[1].content.subarray(1), 0);
59
- const [modulus, exponent] = derChildren(publicKey.content);
60
- if (!modulus || !exponent) break;
61
- return {
62
- modulus: derIntegerToLe(modulus.content),
63
- exponent: derIntegerToLe(exponent.content),
64
- source: "x509"
65
- };
66
- }
67
- throw new Error("RDP: no RSA public key found in the host X.509 certificate");
68
- }
69
- function rsaKeyFromProprietary(reader) {
70
- reader.u32le();
71
- reader.u32le();
72
- const publicKeyBlobType = reader.u16le();
73
- const publicKeyBlobLength = reader.u16le();
74
- if (publicKeyBlobType !== BB_RSA_KEY_BLOB) {
75
- throw new Error(`RDP: unsupported public key blob type 0x${publicKeyBlobType.toString(16)}`);
76
- }
77
- const blob = new Reader(reader.raw(publicKeyBlobLength));
78
- if (blob.u32le() !== RSA1_MAGIC) {
79
- throw new Error("RDP: the host RSA public key blob is not in RSA1 format");
80
- }
81
- const keyLength = blob.u32le();
82
- blob.u32le();
83
- blob.u32le();
84
- const exponent = blob.raw(4).slice();
85
- if (keyLength < 9) throw new Error("RDP: the host RSA modulus is too short");
86
- const modulus = blob.raw(keyLength - 8).slice();
87
- return { modulus, exponent, source: "proprietary" };
88
- }
89
- function parseX509PublicKey(der) {
90
- const certificate = derRead(der, 0);
91
- const tbsCertificate = derRead(der, certificate.contentStart);
92
- for (const child of derChildren(tbsCertificate.content)) {
93
- if (child.tag !== 48) continue;
94
- const parts = derChildren(child.content);
95
- if (parts.length < 2) continue;
96
- if (parts[0].tag !== 48 || !containsOid(parts[0].content, OID_RSA_ENCRYPTION)) continue;
97
- if (parts[1].tag !== 3) continue;
98
- const subjectPublicKey = parts[1].content.subarray(1);
99
- const publicKey = derRead(subjectPublicKey, 0);
100
- const [modulus, exponent] = derChildren(publicKey.content);
101
- if (!modulus || !exponent) break;
102
- const stripLeadingZero = (bytes) => {
103
- let start = 0;
104
- while (start < bytes.length - 1 && bytes[start] === 0) start++;
105
- return bytes.subarray(start);
106
- };
107
- return {
108
- modulus: stripLeadingZero(modulus.content),
109
- exponent: stripLeadingZero(exponent.content),
110
- subjectPublicKey
111
- };
112
- }
113
- throw new Error("TLS: no RSA public key found in the host certificate");
114
- }
115
- function parseServerCertificate(certificateBytes) {
116
- const reader = new Reader(certificateBytes);
117
- const version = reader.u32le() & 2147483647;
118
- if (version === CERT_PROPRIETARY) return rsaKeyFromProprietary(reader);
119
- if (version === CERT_X509) {
120
- const certificateCount = reader.u32le();
121
- let leaf = null;
122
- for (let i = 0; i < certificateCount; i++) {
123
- const length = reader.u32le();
124
- leaf = reader.raw(length);
125
- }
126
- if (!leaf) throw new Error("RDP: the host sent an empty X.509 certificate chain");
127
- return rsaKeyFromX509(leaf);
128
- }
129
- throw new Error(`RDP: unsupported server certificate version ${version}`);
130
- }
131
- export {
132
- parseServerCertificate,
133
- parseX509PublicKey
134
- };
@@ -1,56 +0,0 @@
1
- /**
2
- * A single RDP connection. Emits:
3
- * 'ready' { width, height } -- the desktop size is known
4
- * 'bitmap' { rects } -- decoded rectangles to paint
5
- * 'palette' Uint8Array -- 8bpp palette update
6
- * 'pointer' pointer update -- shape, position or visibility
7
- * 'error' { message } -- fatal, always followed by 'close'
8
- * 'close' { clean, message }
9
- */
10
- export declare class RdpClient extends EventTarget {
11
- #private;
12
- constructor(url: string, options?: {});
13
- disconnect(): void;
14
- /**
15
- * The window the session exists to show: the largest top-level application
16
- * window. Menus, tooltips and drag images are RAIL windows too, and fitting
17
- * one of those to the browser instead of the application would be worse than
18
- * doing nothing.
19
- */
20
- get remoteAppPrimaryWindow(): any;
21
- /**
22
- * Size the remote application's window to the room the browser has for it.
23
- *
24
- * The RDP desktop is fixed for the life of a connection -- resizing it needs
25
- * the dynamic virtual channel this client does not speak -- so the desktop is
26
- * negotiated large at connect time and the application window is moved and
27
- * resized inside it instead. The canvas then shows only that window.
28
- */
29
- fitRemoteApp(width: number, height: number): boolean;
30
- /**
31
- * Hand the host our clipboard text. Resolves once the host has acknowledged
32
- * owning it, which is what makes it safe to send a paste keystroke next.
33
- */
34
- setClipboardText(text: string): any;
35
- get clipboardShared(): boolean;
36
- /**
37
- * Deliver text into the session the way a person would: put it on the host's
38
- * clipboard, wait for the host to acknowledge owning it, then press the paste
39
- * shortcut. Waiting is what stops the keystroke from pasting the previous
40
- * contents. A host with no clipboard channel gets the text typed instead.
41
- */
42
- pasteToHost(text: string): any;
43
- get connected(): boolean;
44
- sendKeyByCode(code: number, pressed: boolean): boolean;
45
- sendUnicode(text: string): void;
46
- sendCtrlAltDel(): void;
47
- sendMouseMove(x: number, y: number): void;
48
- sendMouseButton(button: number, pressed: boolean, x: number, y: number): void;
49
- sendWheel(delta: number, x: number, y: number, horizontal?: boolean): void;
50
- /** Tell the host which lock keys are already on, so they do not drift. */
51
- sendKeyboardSync(toggleFlags: number): void;
52
- /** Ask the host to resend a region, used after the canvas is re-created. */
53
- refresh(rect: any): void;
54
- /** Pause or resume host output, e.g. while the tab is hidden. */
55
- setOutputEnabled(enabled: boolean): void;
56
- }