ai-remote 0.4.2 → 0.4.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.
Files changed (62) hide show
  1. package/dist/index.js +1 -6
  2. package/dist/protocols/index.js +3 -34
  3. package/dist/protocols/ssh/session.js +17 -608
  4. package/dist/protocols/ssh/terminal.js +6 -190
  5. package/dist/shared/connection.js +1 -113
  6. package/dist/shared/hosts.js +1 -132
  7. package/dist/shared/icons.js +1 -41
  8. package/dist/shared/protocol.js +1 -39
  9. package/dist/shared/signals.js +1 -41
  10. package/package.json +1 -1
  11. package/dist/protocols/rdp/buffer.d.ts +0 -38
  12. package/dist/protocols/rdp/buffer.js +0 -169
  13. package/dist/protocols/rdp/caps.d.ts +0 -49
  14. package/dist/protocols/rdp/caps.js +0 -259
  15. package/dist/protocols/rdp/cert.d.ts +0 -18
  16. package/dist/protocols/rdp/cert.js +0 -134
  17. package/dist/protocols/rdp/client.d.ts +0 -56
  18. package/dist/protocols/rdp/client.js +0 -1069
  19. package/dist/protocols/rdp/cliprdr.d.ts +0 -27
  20. package/dist/protocols/rdp/cliprdr.js +0 -239
  21. package/dist/protocols/rdp/credssp.d.ts +0 -34
  22. package/dist/protocols/rdp/credssp.js +0 -253
  23. package/dist/protocols/rdp/crypto.d.ts +0 -63
  24. package/dist/protocols/rdp/crypto.js +0 -368
  25. package/dist/protocols/rdp/display.d.ts +0 -38
  26. package/dist/protocols/rdp/display.js +0 -588
  27. package/dist/protocols/rdp/gcc.d.ts +0 -23
  28. package/dist/protocols/rdp/gcc.js +0 -131
  29. package/dist/protocols/rdp/keymap.d.ts +0 -9
  30. package/dist/protocols/rdp/keymap.js +0 -131
  31. package/dist/protocols/rdp/mcs.d.ts +0 -40
  32. package/dist/protocols/rdp/mcs.js +0 -222
  33. package/dist/protocols/rdp/ntlm.d.ts +0 -61
  34. package/dist/protocols/rdp/ntlm.js +0 -304
  35. package/dist/protocols/rdp/pdu.d.ts +0 -155
  36. package/dist/protocols/rdp/pdu.js +0 -443
  37. package/dist/protocols/rdp/rail.d.ts +0 -119
  38. package/dist/protocols/rdp/rail.js +0 -382
  39. package/dist/protocols/rdp/rle.d.ts +0 -13
  40. package/dist/protocols/rdp/rle.js +0 -275
  41. package/dist/protocols/rdp/sec.d.ts +0 -59
  42. package/dist/protocols/rdp/sec.js +0 -155
  43. package/dist/protocols/rdp/session.d.ts +0 -62
  44. package/dist/protocols/rdp/session.js +0 -306
  45. package/dist/protocols/rdp/tls.d.ts +0 -18
  46. package/dist/protocols/rdp/tls.js +0 -353
  47. package/dist/protocols/rdp/vchannel.d.ts +0 -28
  48. package/dist/protocols/rdp/vchannel.js +0 -58
  49. package/dist/protocols/rdp/x224.d.ts +0 -40
  50. package/dist/protocols/rdp/x224.js +0 -109
  51. package/dist/protocols/ssh/kex.d.ts +0 -97
  52. package/dist/protocols/ssh/kex.js +0 -176
  53. package/dist/protocols/ssh/messages.d.ts +0 -50
  54. package/dist/protocols/ssh/messages.js +0 -54
  55. package/dist/protocols/ssh/transport.d.ts +0 -62
  56. package/dist/protocols/ssh/transport.js +0 -612
  57. package/dist/protocols/ssh/wire.d.ts +0 -52
  58. package/dist/protocols/ssh/wire.js +0 -188
  59. package/dist/protocols/vnc/input.d.ts +0 -5
  60. package/dist/protocols/vnc/input.js +0 -15
  61. package/dist/protocols/vnc/session.d.ts +0 -12
  62. package/dist/protocols/vnc/session.js +0 -258
@@ -1,176 +0,0 @@
1
- import { SshReader, SshWriter, concatBytes, padStart, toBase64, toBase64Url } from "./wire.js";
2
- const subtle = globalThis.crypto?.subtle;
3
- const KEX_ALGORITHMS = {
4
- "curve25519-sha256": { type: "x25519", hash: "SHA-256" },
5
- "curve25519-sha256@libssh.org": { type: "x25519", hash: "SHA-256" },
6
- "ecdh-sha2-nistp256": { type: "ecdh", curve: "P-256", hash: "SHA-256" }
7
- };
8
- const HOST_KEY_ALGORITHMS = {
9
- "ssh-ed25519": { keyType: "ssh-ed25519", kind: "ed25519" },
10
- "rsa-sha2-512": { keyType: "ssh-rsa", kind: "rsa", hash: "SHA-512" },
11
- "rsa-sha2-256": { keyType: "ssh-rsa", kind: "rsa", hash: "SHA-256" },
12
- "ecdsa-sha2-nistp256": { keyType: "ecdsa-sha2-nistp256", kind: "ecdsa", curve: "P-256", hash: "SHA-256" }
13
- };
14
- async function supports(algorithm, usages) {
15
- if (!subtle) return false;
16
- try {
17
- await subtle.generateKey(algorithm, false, usages);
18
- return true;
19
- } catch {
20
- return false;
21
- }
22
- }
23
- let cachedOffer = null;
24
- async function negotiableAlgorithms() {
25
- if (cachedOffer) return cachedOffer;
26
- const [x25519, ed25519] = await Promise.all([
27
- supports({ name: "X25519" }, ["deriveBits"]),
28
- supports({ name: "Ed25519" }, ["sign", "verify"])
29
- ]);
30
- const kex = [];
31
- if (x25519) kex.push("curve25519-sha256", "curve25519-sha256@libssh.org");
32
- kex.push("ecdh-sha2-nistp256");
33
- const hostKey = [];
34
- if (ed25519) hostKey.push("ssh-ed25519");
35
- hostKey.push("rsa-sha2-512", "rsa-sha2-256", "ecdsa-sha2-nistp256");
36
- cachedOffer = { kex, hostKey, x25519, ed25519 };
37
- return cachedOffer;
38
- }
39
- async function createKexClient(algorithmName) {
40
- const algorithm = KEX_ALGORITHMS[algorithmName];
41
- if (!algorithm) throw new Error(`SSH: unsupported key exchange ${algorithmName}`);
42
- if (algorithm.type === "x25519") {
43
- const pair2 = await subtle.generateKey({ name: "X25519" }, false, ["deriveBits"]);
44
- const publicKey2 = new Uint8Array(await subtle.exportKey("raw", pair2.publicKey));
45
- return {
46
- hash: algorithm.hash,
47
- publicKey: publicKey2,
48
- async sharedSecret(serverPublicKey) {
49
- if (serverPublicKey.length !== 32) throw new Error("SSH: the host sent a malformed X25519 key.");
50
- const peer = await subtle.importKey("raw", serverPublicKey, { name: "X25519" }, false, []);
51
- const secret = new Uint8Array(await subtle.deriveBits({ name: "X25519", public: peer }, pair2.privateKey, 256));
52
- if (secret.every((byte) => byte === 0)) {
53
- throw new Error("SSH: the host sent a degenerate X25519 key.");
54
- }
55
- return secret;
56
- }
57
- };
58
- }
59
- const pair = await subtle.generateKey({ name: "ECDH", namedCurve: algorithm.curve }, false, ["deriveBits"]);
60
- const publicKey = new Uint8Array(await subtle.exportKey("raw", pair.publicKey));
61
- return {
62
- hash: algorithm.hash,
63
- publicKey,
64
- async sharedSecret(serverPublicKey) {
65
- const peer = await subtle.importKey(
66
- "raw",
67
- serverPublicKey,
68
- { name: "ECDH", namedCurve: algorithm.curve },
69
- false,
70
- []
71
- );
72
- return new Uint8Array(await subtle.deriveBits({ name: "ECDH", public: peer }, pair.privateKey, 256));
73
- }
74
- };
75
- }
76
- function hostKeyType(keyBlob) {
77
- return new SshReader(keyBlob).string();
78
- }
79
- async function hostKeyFingerprint(keyBlob) {
80
- const digest = new Uint8Array(await subtle.digest("SHA-256", keyBlob));
81
- return `SHA256:${toBase64(digest).replace(/=+$/, "")}`;
82
- }
83
- async function importHostKey(algorithmName, keyBlob) {
84
- const algorithm = HOST_KEY_ALGORITHMS[algorithmName];
85
- if (!algorithm) throw new Error(`SSH: unsupported host key algorithm ${algorithmName}`);
86
- const reader = new SshReader(keyBlob);
87
- const keyType = reader.string();
88
- if (keyType !== algorithm.keyType) {
89
- throw new Error(`SSH: the host key is a ${keyType} but was announced as ${algorithmName}.`);
90
- }
91
- if (algorithm.kind === "ed25519") {
92
- return subtle.importKey("raw", reader.stringBytes(), { name: "Ed25519" }, false, ["verify"]);
93
- }
94
- if (algorithm.kind === "rsa") {
95
- const exponent = reader.mpint();
96
- const modulus = reader.mpint();
97
- return subtle.importKey(
98
- "jwk",
99
- { kty: "RSA", n: toBase64Url(modulus), e: toBase64Url(exponent), ext: true },
100
- { name: "RSASSA-PKCS1-v1_5", hash: algorithm.hash },
101
- false,
102
- ["verify"]
103
- );
104
- }
105
- reader.string();
106
- return subtle.importKey(
107
- "raw",
108
- reader.stringBytes(),
109
- { name: "ECDSA", namedCurve: algorithm.curve },
110
- false,
111
- ["verify"]
112
- );
113
- }
114
- function signatureBytes(algorithmName, signatureBlob) {
115
- const reader = new SshReader(signatureBlob);
116
- const named = reader.string();
117
- if (named !== algorithmName) {
118
- throw new Error(`SSH: the host signed with ${named} after agreeing on ${algorithmName}.`);
119
- }
120
- const raw = reader.stringBytes();
121
- if (HOST_KEY_ALGORITHMS[algorithmName]?.kind !== "ecdsa") return raw;
122
- const parts = new SshReader(raw);
123
- const r = parts.mpint();
124
- const s = parts.mpint();
125
- return concatBytes(padStart(r, 32), padStart(s, 32));
126
- }
127
- async function verifyHostKeySignature({ algorithm, keyBlob, signatureBlob, exchangeHash: exchangeHash2 }) {
128
- const { kind, hash } = HOST_KEY_ALGORITHMS[algorithm];
129
- const key = await importHostKey(algorithm, keyBlob);
130
- const signature = signatureBytes(algorithm, signatureBlob);
131
- const parameters = kind === "ecdsa" ? { name: "ECDSA", hash } : kind === "rsa" ? { name: "RSASSA-PKCS1-v1_5" } : { name: "Ed25519" };
132
- return subtle.verify(parameters, key, signature, exchangeHash2);
133
- }
134
- async function exchangeHash({
135
- hash,
136
- clientVersion,
137
- serverVersion,
138
- clientKexInit,
139
- serverKexInit,
140
- hostKeyBlob,
141
- clientPublicKey,
142
- serverPublicKey,
143
- sharedSecret
144
- }) {
145
- const writer = new SshWriter(1024);
146
- writer.string(clientVersion);
147
- writer.string(serverVersion);
148
- writer.string(clientKexInit);
149
- writer.string(serverKexInit);
150
- writer.string(hostKeyBlob);
151
- writer.string(clientPublicKey);
152
- writer.string(serverPublicKey);
153
- writer.mpint(sharedSecret);
154
- return new Uint8Array(await subtle.digest(hash, writer.take()));
155
- }
156
- async function deriveKey({ hash, sharedSecret, exchangeHash: h, letter, sessionId, length }) {
157
- const prefix = new SshWriter(64 + h.length).mpint(sharedSecret).take();
158
- const seed = concatBytes(prefix, h, new Uint8Array([letter.charCodeAt(0)]), sessionId);
159
- let material = new Uint8Array(await subtle.digest(hash, seed));
160
- while (material.length < length) {
161
- const extension = new Uint8Array(await subtle.digest(hash, concatBytes(prefix, h, material)));
162
- material = concatBytes(material, extension);
163
- }
164
- return material.subarray(0, length);
165
- }
166
- export {
167
- HOST_KEY_ALGORITHMS,
168
- KEX_ALGORITHMS,
169
- createKexClient,
170
- deriveKey,
171
- exchangeHash,
172
- hostKeyFingerprint,
173
- hostKeyType,
174
- negotiableAlgorithms,
175
- verifyHostKeySignature
176
- };
@@ -1,50 +0,0 @@
1
- export declare const MSG: {
2
- DISCONNECT: number;
3
- IGNORE: number;
4
- UNIMPLEMENTED: number;
5
- DEBUG: number;
6
- SERVICE_REQUEST: number;
7
- SERVICE_ACCEPT: number;
8
- EXT_INFO: number;
9
- KEXINIT: number;
10
- NEWKEYS: number;
11
- KEX_ECDH_INIT: number;
12
- KEX_ECDH_REPLY: number;
13
- USERAUTH_REQUEST: number;
14
- USERAUTH_FAILURE: number;
15
- USERAUTH_SUCCESS: number;
16
- USERAUTH_BANNER: number;
17
- USERAUTH_INFO_REQUEST: number;
18
- USERAUTH_INFO_RESPONSE: number;
19
- GLOBAL_REQUEST: number;
20
- REQUEST_SUCCESS: number;
21
- REQUEST_FAILURE: number;
22
- CHANNEL_OPEN: number;
23
- CHANNEL_OPEN_CONFIRMATION: number;
24
- CHANNEL_OPEN_FAILURE: number;
25
- CHANNEL_WINDOW_ADJUST: number;
26
- CHANNEL_DATA: number;
27
- CHANNEL_EXTENDED_DATA: number;
28
- CHANNEL_EOF: number;
29
- CHANNEL_CLOSE: number;
30
- CHANNEL_REQUEST: number;
31
- CHANNEL_SUCCESS: number;
32
- CHANNEL_FAILURE: number;
33
- };
34
- /** SSH_EXTENDED_DATA_STDERR. */
35
- export declare const EXTENDED_DATA_STDERR = 1;
36
- export declare const DISCONNECT_REASON: {
37
- 1: string;
38
- 2: string;
39
- 3: string;
40
- 5: string;
41
- 6: string;
42
- 7: string;
43
- 8: string;
44
- 9: string;
45
- 10: string;
46
- 11: string;
47
- 12: string;
48
- 14: string;
49
- 15: string;
50
- };
@@ -1,54 +0,0 @@
1
- const MSG = {
2
- DISCONNECT: 1,
3
- IGNORE: 2,
4
- UNIMPLEMENTED: 3,
5
- DEBUG: 4,
6
- SERVICE_REQUEST: 5,
7
- SERVICE_ACCEPT: 6,
8
- EXT_INFO: 7,
9
- KEXINIT: 20,
10
- NEWKEYS: 21,
11
- KEX_ECDH_INIT: 30,
12
- KEX_ECDH_REPLY: 31,
13
- USERAUTH_REQUEST: 50,
14
- USERAUTH_FAILURE: 51,
15
- USERAUTH_SUCCESS: 52,
16
- USERAUTH_BANNER: 53,
17
- USERAUTH_INFO_REQUEST: 60,
18
- USERAUTH_INFO_RESPONSE: 61,
19
- GLOBAL_REQUEST: 80,
20
- REQUEST_SUCCESS: 81,
21
- REQUEST_FAILURE: 82,
22
- CHANNEL_OPEN: 90,
23
- CHANNEL_OPEN_CONFIRMATION: 91,
24
- CHANNEL_OPEN_FAILURE: 92,
25
- CHANNEL_WINDOW_ADJUST: 93,
26
- CHANNEL_DATA: 94,
27
- CHANNEL_EXTENDED_DATA: 95,
28
- CHANNEL_EOF: 96,
29
- CHANNEL_CLOSE: 97,
30
- CHANNEL_REQUEST: 98,
31
- CHANNEL_SUCCESS: 99,
32
- CHANNEL_FAILURE: 100
33
- };
34
- const EXTENDED_DATA_STDERR = 1;
35
- const DISCONNECT_REASON = {
36
- 1: "the host reported a protocol error",
37
- 2: "the host could not agree on a key exchange method",
38
- 3: "the key exchange failed",
39
- 5: "the host ran out of resources",
40
- 6: "the connection was lost below SSH",
41
- 7: "the host application ended the connection",
42
- 8: "too many connections",
43
- 9: "authentication was cancelled by the user",
44
- 10: "no more authentication methods are available",
45
- 11: "the host closed the connection",
46
- 12: "authentication was cancelled by the host",
47
- 14: "the host refused the authentication attempt",
48
- 15: "the host closed the connection while authenticating"
49
- };
50
- export {
51
- DISCONNECT_REASON,
52
- EXTENDED_DATA_STDERR,
53
- MSG
54
- };
@@ -1,62 +0,0 @@
1
- export declare const CLIENT_VERSION = "SSH-2.0-CloudflareGateway_1.0";
2
- /** Pick the first client preference the host also offered (RFC 4253 7.1). */
3
- export declare function negotiate(clientNames: any, serverNames: any): any;
4
- export declare class SshTransport extends EventTarget {
5
- #private;
6
- url: string;
7
- verifyHost: (info: any) => Promise<boolean> | boolean;
8
- log: (...args: any[]) => void;
9
- socket: WebSocket | null;
10
- openTransport: ((url: string) => any) | null;
11
- closed: boolean;
12
- buffer: Uint8Array;
13
- serverVersion: string;
14
- greeting: string[];
15
- sendSequence: number;
16
- receiveSequence: number;
17
- outgoing: any;
18
- incoming: any;
19
- sessionId: Uint8Array | null;
20
- kex: any;
21
- kexQueue: Uint8Array[];
22
- keepaliveTimer: any;
23
- bytesSent: number;
24
- bytesReceived: number;
25
- encryptChain?: Promise<void>;
26
- newKeysBarrier?: Promise<void> | null;
27
- releaseNewKeys?: (() => void) | null;
28
- pendingServerKexInit?: Uint8Array | null;
29
- established?: boolean;
30
- /**
31
- * @param {string} url gateway WebSocket URL
32
- * @param {object} options
33
- * @param {(info: object) => Promise<boolean>} options.verifyHost decides
34
- * whether an unknown or changed host key may be used.
35
- */
36
- constructor(url: string, { verifyHost, log, openTransport }?: {
37
- verifyHost?: (info: any) => Promise<boolean> | boolean;
38
- log?: (...args: any[]) => void;
39
- /** Returns a WebSocket-shaped transport for `url`; default is a real one. */
40
- openTransport?: ((url: string) => any) | null;
41
- });
42
- connect(): void;
43
- disconnect(message?: string): void;
44
- fail(error: unknown): void;
45
- /** Application packets wait while a key exchange is in flight (RFC 4253 7.1). */
46
- send(payload: Uint8Array): boolean;
47
- }
48
- /** Padding for a GCM packet: only the encrypted part is block aligned. */
49
- export declare function gcmPaddingLength(payloadLength: any): number;
50
- /** A packet before any keys exist: the whole thing is block aligned. */
51
- export declare function framePlain(payload: Uint8Array): Uint8Array<ArrayBufferLike>;
52
- export declare function buildKexInit(offer: any): Uint8Array<ArrayBufferLike>;
53
- export declare function parseKexInit(payload: Uint8Array): {
54
- kex: string[];
55
- hostKey: string[];
56
- cipherClientToServer: string[];
57
- cipherServerToClient: string[];
58
- macClientToServer: string[];
59
- macServerToClient: string[];
60
- compressionClientToServer: string[];
61
- compressionServerToClient: string[];
62
- };