@zukhruf/ssh 0.0.0-stage → 0.8.29

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 (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1123 -2
  3. package/dist/address.d.ts +8 -0
  4. package/dist/address.d.ts.map +1 -0
  5. package/dist/address.js +15 -0
  6. package/dist/address.js.map +1 -0
  7. package/dist/agent.d.ts +35 -0
  8. package/dist/agent.d.ts.map +1 -0
  9. package/dist/agent.js +288 -0
  10. package/dist/agent.js.map +1 -0
  11. package/dist/channel-stream.d.ts +16 -0
  12. package/dist/channel-stream.d.ts.map +1 -0
  13. package/dist/channel-stream.js +102 -0
  14. package/dist/channel-stream.js.map +1 -0
  15. package/dist/client.d.ts +114 -0
  16. package/dist/client.d.ts.map +1 -0
  17. package/dist/client.js +587 -0
  18. package/dist/client.js.map +1 -0
  19. package/dist/config.d.ts +82 -0
  20. package/dist/config.d.ts.map +1 -0
  21. package/dist/config.js +255 -0
  22. package/dist/config.js.map +1 -0
  23. package/dist/control/control-client.d.ts +12 -0
  24. package/dist/control/control-client.d.ts.map +1 -0
  25. package/dist/control/control-client.js +156 -0
  26. package/dist/control/control-client.js.map +1 -0
  27. package/dist/control/control-master.d.ts +12 -0
  28. package/dist/control/control-master.d.ts.map +1 -0
  29. package/dist/control/control-master.js +101 -0
  30. package/dist/control/control-master.js.map +1 -0
  31. package/dist/control/control-stream.d.ts +29 -0
  32. package/dist/control/control-stream.d.ts.map +1 -0
  33. package/dist/control/control-stream.js +54 -0
  34. package/dist/control/control-stream.js.map +1 -0
  35. package/dist/control/messages.d.ts +38 -0
  36. package/dist/control/messages.d.ts.map +1 -0
  37. package/dist/control/messages.js +92 -0
  38. package/dist/control/messages.js.map +1 -0
  39. package/dist/control/serve-dial.d.ts +11 -0
  40. package/dist/control/serve-dial.d.ts.map +1 -0
  41. package/dist/control/serve-dial.js +47 -0
  42. package/dist/control/serve-dial.js.map +1 -0
  43. package/dist/control/serve-session.d.ts +11 -0
  44. package/dist/control/serve-session.d.ts.map +1 -0
  45. package/dist/control/serve-session.js +78 -0
  46. package/dist/control/serve-session.js.map +1 -0
  47. package/dist/control/wire.d.ts +41 -0
  48. package/dist/control/wire.d.ts.map +1 -0
  49. package/dist/control/wire.js +100 -0
  50. package/dist/control/wire.js.map +1 -0
  51. package/dist/control.d.ts +4 -0
  52. package/dist/control.d.ts.map +1 -0
  53. package/dist/control.js +4 -0
  54. package/dist/control.js.map +1 -0
  55. package/dist/dial-route.d.ts +14 -0
  56. package/dist/dial-route.d.ts.map +1 -0
  57. package/dist/dial-route.js +87 -0
  58. package/dist/dial-route.js.map +1 -0
  59. package/dist/host-key-algorithms.d.ts +7 -0
  60. package/dist/host-key-algorithms.d.ts.map +1 -0
  61. package/dist/host-key-algorithms.js +16 -0
  62. package/dist/host-key-algorithms.js.map +1 -0
  63. package/dist/host-key-policy.d.ts +22 -0
  64. package/dist/host-key-policy.d.ts.map +1 -0
  65. package/dist/host-key-policy.js +72 -0
  66. package/dist/host-key-policy.js.map +1 -0
  67. package/dist/identities.d.ts +18 -0
  68. package/dist/identities.d.ts.map +1 -0
  69. package/dist/identities.js +81 -0
  70. package/dist/identities.js.map +1 -0
  71. package/dist/index.d.ts +9 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +8 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/knownhosts.d.ts +33 -0
  76. package/dist/knownhosts.d.ts.map +1 -0
  77. package/dist/knownhosts.js +241 -0
  78. package/dist/knownhosts.js.map +1 -0
  79. package/dist/match-pattern.d.ts +3 -0
  80. package/dist/match-pattern.d.ts.map +1 -0
  81. package/dist/match-pattern.js +18 -0
  82. package/dist/match-pattern.js.map +1 -0
  83. package/dist/private-key.d.ts +42 -0
  84. package/dist/private-key.d.ts.map +1 -0
  85. package/dist/private-key.js +100 -0
  86. package/dist/private-key.js.map +1 -0
  87. package/dist/prompt.d.ts +6 -0
  88. package/dist/prompt.d.ts.map +1 -0
  89. package/dist/prompt.js +2 -0
  90. package/dist/prompt.js.map +1 -0
  91. package/dist/proxy-command.d.ts +33 -0
  92. package/dist/proxy-command.d.ts.map +1 -0
  93. package/dist/proxy-command.js +121 -0
  94. package/dist/proxy-command.js.map +1 -0
  95. package/dist/proxy-jump.d.ts +19 -0
  96. package/dist/proxy-jump.d.ts.map +1 -0
  97. package/dist/proxy-jump.js +63 -0
  98. package/dist/proxy-jump.js.map +1 -0
  99. package/dist/public-key.d.ts +22 -0
  100. package/dist/public-key.d.ts.map +1 -0
  101. package/dist/public-key.js +102 -0
  102. package/dist/public-key.js.map +1 -0
  103. package/dist/remote-listener.d.ts +14 -0
  104. package/dist/remote-listener.d.ts.map +1 -0
  105. package/dist/remote-listener.js +39 -0
  106. package/dist/remote-listener.js.map +1 -0
  107. package/dist/server-alive-check.d.ts +36 -0
  108. package/dist/server-alive-check.d.ts.map +1 -0
  109. package/dist/server-alive-check.js +103 -0
  110. package/dist/server-alive-check.js.map +1 -0
  111. package/dist/server.d.ts +114 -0
  112. package/dist/server.d.ts.map +1 -0
  113. package/dist/server.js +460 -0
  114. package/dist/server.js.map +1 -0
  115. package/dist/session.d.ts +97 -0
  116. package/dist/session.d.ts.map +1 -0
  117. package/dist/session.js +193 -0
  118. package/dist/session.js.map +1 -0
  119. package/dist/ssh-g.d.ts +19 -0
  120. package/dist/ssh-g.d.ts.map +1 -0
  121. package/dist/ssh-g.js +67 -0
  122. package/dist/ssh-g.js.map +1 -0
  123. package/dist/ssh2-agent-forwarding.d.ts +51 -0
  124. package/dist/ssh2-agent-forwarding.d.ts.map +1 -0
  125. package/dist/ssh2-agent-forwarding.js +56 -0
  126. package/dist/ssh2-agent-forwarding.js.map +1 -0
  127. package/dist/ssh2-channel-open-failure.d.ts +28 -0
  128. package/dist/ssh2-channel-open-failure.d.ts.map +1 -0
  129. package/dist/ssh2-channel-open-failure.js +35 -0
  130. package/dist/ssh2-channel-open-failure.js.map +1 -0
  131. package/dist/ssh2-keepalive-request.d.ts +31 -0
  132. package/dist/ssh2-keepalive-request.d.ts.map +1 -0
  133. package/dist/ssh2-keepalive-request.js +6 -0
  134. package/dist/ssh2-keepalive-request.js.map +1 -0
  135. package/dist/ssh2-server-channel.d.ts +63 -0
  136. package/dist/ssh2-server-channel.d.ts.map +1 -0
  137. package/dist/ssh2-server-channel.js +309 -0
  138. package/dist/ssh2-server-channel.js.map +1 -0
  139. package/package.json +75 -4
@@ -0,0 +1,100 @@
1
+ // Each frame is one byte of type, four bytes of length (big-endian) and the
2
+ // payload. The types after the request and the reply are the messages of an
3
+ // SSH channel (RFC 4254 §5.2, §5.3, §6.7, §6.9, §6.10), so each side relays
4
+ // one message for one message.
5
+ export const FrameType = {
6
+ /** client → master, the first frame: JSON Request. */
7
+ request: 0,
8
+ /** master → client, the answer to the request: JSON Reply. */
9
+ reply: 1,
10
+ /** Both ways: SSH_MSG_CHANNEL_DATA; for a session, stdin or stdout. */
11
+ data: 2,
12
+ /** master → client: SSH_MSG_CHANNEL_EXTENDED_DATA type 1, stderr. */
13
+ extendedData: 3,
14
+ /** Both ways: SSH_MSG_CHANNEL_EOF. Empty. */
15
+ eof: 4,
16
+ /** client → master: SSH_MSG_CHANNEL_CLOSE of a session. Empty. */
17
+ close: 5,
18
+ /** client → master: window-change, JSON WindowSize. */
19
+ windowChange: 6,
20
+ /** client → master: signal, its name in UTF-8. */
21
+ signal: 7,
22
+ /** master → client, the last frame of a session: JSON Ending. */
23
+ exit: 8,
24
+ /** master → client, the last frame of a dial that failed: JSON WireError. */
25
+ error: 9,
26
+ };
27
+ const headerLength = 5;
28
+ export function encode(type, payload = Buffer.alloc(0)) {
29
+ const body = typeof payload === 'string' ? Buffer.from(payload) : payload;
30
+ const header = Buffer.alloc(headerLength);
31
+ header.writeUInt8(type, 0);
32
+ header.writeUInt32BE(body.length, 1);
33
+ return Buffer.concat([header, body]);
34
+ }
35
+ export function encodeJson(type, value) {
36
+ return encode(type, JSON.stringify(value));
37
+ }
38
+ /** The JSON of the payload; undefined when it is not JSON, which no check of messages.ts accepts. */
39
+ export function decodeJson(frame) {
40
+ try {
41
+ return JSON.parse(frame.payload.toString());
42
+ }
43
+ catch {
44
+ return undefined;
45
+ }
46
+ }
47
+ /** The first frame of `buffered` and the bytes after it, or undefined while the frame is not whole. */
48
+ function takeFrame(buffered) {
49
+ if (buffered.length < headerLength)
50
+ return undefined;
51
+ const end = headerLength + buffered.readUInt32BE(1);
52
+ if (buffered.length < end)
53
+ return undefined;
54
+ return {
55
+ frame: {
56
+ type: buffered.readUInt8(0),
57
+ payload: buffered.subarray(headerLength, end),
58
+ },
59
+ rest: buffered.subarray(end),
60
+ };
61
+ }
62
+ /**
63
+ * The first frame of a connection: the request, or the reply. The socket is
64
+ * paused after it, with the bytes after the frame put back, so the channel
65
+ * reads them when it opens. Rejects with `closed` when the socket closes
66
+ * first.
67
+ */
68
+ export function readFirstFrame(socket, closed) {
69
+ const first = Promise.withResolvers();
70
+ let buffered = Buffer.alloc(0);
71
+ const onClose = () => first.reject(closed);
72
+ const onData = (chunk) => {
73
+ buffered = Buffer.concat([buffered, chunk]);
74
+ const taken = takeFrame(buffered);
75
+ if (taken === undefined)
76
+ return;
77
+ socket.off('data', onData);
78
+ socket.off('close', onClose);
79
+ socket.pause();
80
+ if (taken.rest.length > 0)
81
+ socket.unshift(taken.rest);
82
+ first.resolve(taken.frame);
83
+ };
84
+ socket.on('data', onData);
85
+ socket.once('close', onClose);
86
+ return first.promise;
87
+ }
88
+ /** Gives each frame of the socket to `handler`, from the bytes that readFirstFrame left on. */
89
+ export function readFrames(socket, handler) {
90
+ let buffered = Buffer.alloc(0);
91
+ socket.on('data', (chunk) => {
92
+ buffered = Buffer.concat([buffered, chunk]);
93
+ for (let taken = takeFrame(buffered); taken !== undefined; taken = takeFrame(buffered)) {
94
+ buffered = taken.rest;
95
+ handler(taken.frame);
96
+ }
97
+ });
98
+ socket.resume();
99
+ }
100
+ //# sourceMappingURL=wire.js.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 export { ControlClient } from './control/control-client.ts';
3
+ export { ControlMaster } from './control/control-master.ts';
4
+ //# sourceMappingURL=control.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../src/control.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,4 @@
1
+ /** @zukhruf/ssh/control: one connection for many processes, as OpenSSH's ControlMaster. */
2
+ export { ControlClient } from "./control/control-client.js";
3
+ export { ControlMaster } from "./control/control-master.js";
4
+ //# sourceMappingURL=control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control.js","sourceRoot":"","sources":["../src/control.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { Clock } from '@zukhruf/async';
2
+ import { Client, type ClientConfig } from './client.ts';
3
+ import type { JumpHost, Route } from './config.ts';
4
+ import type { Environment } from './ssh-g.ts';
5
+ export interface DialContext {
6
+ readonly clock: Clock;
7
+ readonly signal: AbortSignal | undefined;
8
+ readonly environment: Environment;
9
+ }
10
+ /** What only the destination has: a jump host opens no session. */
11
+ export type SessionSettings = Pick<ClientConfig, 'sessionEnv' | 'agentForwarding'>;
12
+ /** Reaches `host` by `route` (README, "Connect with the settings of OpenSSH"). */
13
+ export declare function dialHost(host: JumpHost, route: Route, session: SessionSettings, context: DialContext): Promise<Client>;
14
+ //# sourceMappingURL=dial-route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dial-route.d.ts","sourceRoot":"","sources":["../src/dial-route.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAG5C,OAAO,EACL,MAAM,EACN,KAAK,YAAY,EAIlB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAInD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CACnC;AAED,mEAAmE;AACnE,MAAM,MAAM,eAAe,GAAG,IAAI,CAChC,YAAY,EACZ,YAAY,GAAG,iBAAiB,CACjC,CAAC;AAEF,kFAAkF;AAClF,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,CAAC,CAyBjB"}
@@ -0,0 +1,87 @@
1
+ import { joinHostPort } from "./address.js";
2
+ import { Client, closeWithClient, ownTransport, restrictClient, } from "./client.js";
3
+ import { HostKeyPolicy } from "./host-key-policy.js";
4
+ import { Identities } from "./identities.js";
5
+ import { startProxyCommand } from "./proxy-command.js";
6
+ /** Reaches `host` by `route` (README, "Connect with the settings of OpenSSH"). */
7
+ export async function dialHost(host, route, session, context) {
8
+ const { signal } = context;
9
+ const address = joinHostPort(host.hostname, host.port);
10
+ switch (route.kind) {
11
+ case 'direct':
12
+ return handshakeHost(host, session, context, (config) => Client.dial(address, config, {
13
+ ...(host.addressFamily && { family: host.addressFamily }),
14
+ ...(signal && { signal }),
15
+ }));
16
+ case 'proxy-command':
17
+ return handshakeHost(host, session, context, async (config) => {
18
+ const transport = startProxyCommand(route.command, host, context.environment);
19
+ const client = await handshakeOn(transport, address, config, signal);
20
+ ownTransport(client, transport);
21
+ return client;
22
+ });
23
+ case 'jump':
24
+ return dialThroughJumpHosts(host, route, session, context);
25
+ }
26
+ }
27
+ /**
28
+ * The first jump host by its own route, then each next host through a
29
+ * direct-tcpip channel of the client before it (ADR 0006). Each client owns
30
+ * the one before it, so the close of the destination's client closes the
31
+ * chain from the last jump host back to the first.
32
+ */
33
+ async function dialThroughJumpHosts(host, route, session, context) {
34
+ const [first, ...later] = route.jumpHosts;
35
+ const { signal } = context;
36
+ let previous = await dialHost(first, first.route, {}, context);
37
+ try {
38
+ for (const next of [...later, host]) {
39
+ const address = joinHostPort(next.hostname, next.port);
40
+ const channel = await previous.dial('tcp', address, {
41
+ ...(signal && { signal }),
42
+ });
43
+ const client = await handshakeHost(next, next === host ? session : {}, context, (config) => handshakeOn(channel, address, config, signal));
44
+ closeWithClient(client, previous);
45
+ previous = client;
46
+ }
47
+ return previous;
48
+ }
49
+ catch (error) {
50
+ await previous.close();
51
+ throw error;
52
+ }
53
+ }
54
+ /** Client.handshake, which leaves the transport to its caller when it throws before it starts. */
55
+ async function handshakeOn(transport, address, config, signal) {
56
+ try {
57
+ return await Client.handshake(transport, address, config, {
58
+ ...(signal && { signal }),
59
+ });
60
+ }
61
+ catch (error) {
62
+ transport.destroy();
63
+ throw error;
64
+ }
65
+ }
66
+ /** The handshake of one host: its own known hosts and policy, its own identities, its own timeouts. */
67
+ async function handshakeHost(host, session, context, open) {
68
+ const policy = await HostKeyPolicy.read(host);
69
+ await using identities = new Identities(host);
70
+ const client = await open({
71
+ user: host.user,
72
+ auth: [identities.method],
73
+ hostKey: policy.check,
74
+ hostKeyAlgorithms: policy.algorithms(),
75
+ clock: context.clock,
76
+ ...(host.connectTimeout !== undefined && {
77
+ connectTimeout: host.connectTimeout,
78
+ }),
79
+ ...(host.keepalive && { keepalive: host.keepalive }),
80
+ ...session,
81
+ });
82
+ const restriction = await policy.restriction();
83
+ if (restriction !== undefined)
84
+ restrictClient(client, restriction);
85
+ return client;
86
+ }
87
+ //# sourceMappingURL=dial-route.js.map
@@ -0,0 +1 @@
1
+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D,GAAG,OAAO;KACX,CAAC,CAAC;IACH,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC;IAC/C,IAAI,WAAW,KAAK,SAAS;QAAE,cAAc,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACnE,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The host key algorithms of ssh2 1.17.0 (`SUPPORTED_SERVER_HOST_KEY` in
3
+ * lib/protocol/constants.js:64-76). It has no *-cert-v01@openssh.com
4
+ * algorithm, so a client offers none of those names.
5
+ */
6
+ export declare const ssh2HostKeyAlgorithms: readonly ["ssh-ed25519", "ecdsa-sha2-nistp256", "ecdsa-sha2-nistp384", "ecdsa-sha2-nistp521", "rsa-sha2-512", "rsa-sha2-256", "ssh-rsa", "ssh-dss"];
7
+ //# sourceMappingURL=host-key-algorithms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-key-algorithms.d.ts","sourceRoot":"","sources":["../src/host-key-algorithms.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,qJASxB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The host key algorithms of ssh2 1.17.0 (`SUPPORTED_SERVER_HOST_KEY` in
3
+ * lib/protocol/constants.js:64-76). It has no *-cert-v01@openssh.com
4
+ * algorithm, so a client offers none of those names.
5
+ */
6
+ export const ssh2HostKeyAlgorithms = [
7
+ 'ssh-ed25519',
8
+ 'ecdsa-sha2-nistp256',
9
+ 'ecdsa-sha2-nistp384',
10
+ 'ecdsa-sha2-nistp521',
11
+ 'rsa-sha2-512',
12
+ 'rsa-sha2-256',
13
+ 'ssh-rsa',
14
+ 'ssh-dss',
15
+ ];
16
+ //# sourceMappingURL=host-key-algorithms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-key-algorithms.js","sourceRoot":"","sources":["../src/host-key-algorithms.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,aAAa;IACb,qBAAqB;IACrB,qBAAqB;IACrB,qBAAqB;IACrB,cAAc;IACd,cAAc;IACd,SAAS;IACT,SAAS;CACD,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { HostKeyCallback } from './client.ts';
2
+ import type { JumpHost } from './config.ts';
3
+ type PolicyHost = Pick<JumpHost, 'hostname' | 'port' | 'hostKeyAlias' | 'knownHostsFiles' | 'strictHostKeyChecking' | 'hashKnownHosts' | 'hostKeyAlgorithms'>;
4
+ /**
5
+ * OpenSSH's StrictHostKeyChecking around the known hosts of one host (ADR
6
+ * 0005), as `check_host_key` in sshconnect.c of OpenSSH 10.5p1 applies it,
7
+ * with no prompt. The name is the HostKeyAlias as it is, or the hostname with
8
+ * the port (`get_hostfile_hostname_ipaddr` in sshconnect.c).
9
+ */
10
+ export declare class HostKeyPolicy {
11
+ #private;
12
+ private constructor();
13
+ /** Reads the user files, then the global files. */
14
+ static read(host: PolicyHost): Promise<HostKeyPolicy>;
15
+ /** The host key algorithms of the config, with those of the known keys first (`order_hostkeyalgs` in sshconnect2.c). */
16
+ algorithms(): string[];
17
+ /** After a handshake: the error of a changed or revoked key that StrictHostKeyChecking no let through, so the client runs in OpenSSH's restricted mode; undefined for a trusted key. */
18
+ restriction(): Promise<Error | undefined>;
19
+ readonly check: HostKeyCallback;
20
+ }
21
+ export {};
22
+ //# sourceMappingURL=host-key-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-key-policy.d.ts","sourceRoot":"","sources":["../src/host-key-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAI5C,KAAK,UAAU,GAAG,IAAI,CACpB,QAAQ,EACN,UAAU,GACV,MAAM,GACN,cAAc,GACd,iBAAiB,GACjB,uBAAuB,GACvB,gBAAgB,GAChB,mBAAmB,CACtB,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,aAAa;;IAOxB,OAAO;IAUP,mDAAmD;WACtC,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC;IAK3D,wHAAwH;IACxH,UAAU,IAAI,MAAM,EAAE;IAStB,wLAAwL;IACxL,WAAW,IAAI,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;IAIzC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAS7B;CAuBH"}
@@ -0,0 +1,72 @@
1
+ import { Latch } from '@zukhruf/async';
2
+ import { KeyError, KnownHosts, RevokedError } from "./knownhosts.js";
3
+ /**
4
+ * OpenSSH's StrictHostKeyChecking around the known hosts of one host (ADR
5
+ * 0005), as `check_host_key` in sshconnect.c of OpenSSH 10.5p1 applies it,
6
+ * with no prompt. The name is the HostKeyAlias as it is, or the hostname with
7
+ * the port (`get_hostfile_hostname_ipaddr` in sshconnect.c).
8
+ */
9
+ export class HostKeyPolicy {
10
+ #host;
11
+ #knownHosts;
12
+ #name;
13
+ /** Opens at the first check that lets the key through: with the error of a changed or revoked key that StrictHostKeyChecking no let through, else undefined. */
14
+ #trusted = new Latch();
15
+ constructor(host, knownHosts) {
16
+ this.#host = host;
17
+ this.#knownHosts = knownHosts;
18
+ // KnownHosts looks up a name with no port for port 22.
19
+ this.#name =
20
+ host.hostKeyAlias === undefined
21
+ ? { hostname: host.hostname, port: host.port }
22
+ : { hostname: host.hostKeyAlias, port: 22 };
23
+ }
24
+ /** Reads the user files, then the global files. */
25
+ static async read(host) {
26
+ const { user, global } = host.knownHostsFiles;
27
+ return new HostKeyPolicy(host, await KnownHosts.read([...user, ...global]));
28
+ }
29
+ /** The host key algorithms of the config, with those of the known keys first (`order_hostkeyalgs` in sshconnect2.c). */
30
+ algorithms() {
31
+ const { hostname, port } = this.#name;
32
+ return this.#knownHosts.hostKeyAlgorithms(hostname, port, this.#host.hostKeyAlgorithms);
33
+ }
34
+ /** After a handshake: the error of a changed or revoked key that StrictHostKeyChecking no let through, so the client runs in OpenSSH's restricted mode; undefined for a trusted key. */
35
+ restriction() {
36
+ return this.#trusted.wait();
37
+ }
38
+ check = async (_hostname, _port, key) => {
39
+ const { hostname, port } = this.#name;
40
+ try {
41
+ this.#knownHosts.check(hostname, port, key);
42
+ }
43
+ catch (error) {
44
+ this.#trusted.open(await this.#refused(error, key));
45
+ return;
46
+ }
47
+ this.#trusted.open(undefined);
48
+ };
49
+ /** Throws the error unless the policy lets the key through; returns the error of a key that only the restricted mode lets through. */
50
+ async #refused(error, key) {
51
+ const policy = this.#host.strictHostKeyChecking;
52
+ const unknown = error instanceof KeyError && error.want.length === 0;
53
+ if (unknown && (policy === 'accept-new' || policy === 'no')) {
54
+ await this.#add(key);
55
+ return undefined;
56
+ }
57
+ const changed = error instanceof KeyError || error instanceof RevokedError;
58
+ if (changed && policy === 'no')
59
+ return error;
60
+ throw error;
61
+ }
62
+ /** Appends to the first user file. With no user file, OpenSSH fails to add, logs it and connects (`add_host_to_hostfile` in check_host_key). */
63
+ async #add(key) {
64
+ if (this.#host.knownHostsFiles.user.length === 0)
65
+ return;
66
+ const { hostname, port } = this.#name;
67
+ await this.#knownHosts.add(hostname, port, key, {
68
+ hash: this.#host.hashKnownHosts,
69
+ });
70
+ }
71
+ }
72
+ //# sourceMappingURL=host-key-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-key-policy.js","sourceRoot":"","sources":["../src/host-key-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAIvC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAcrE;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IACf,KAAK,CAAa;IAClB,WAAW,CAAa;IACxB,KAAK,CAAuD;IACrE,gKAAgK;IACvJ,QAAQ,GAAG,IAAI,KAAK,EAAqB,CAAC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L,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ import type { AuthMethod } from './client.ts';
2
+ import type { JumpHost } from './config.ts';
3
+ type IdentityHost = Pick<JumpHost, 'identityAgent' | 'identityFiles' | 'identitiesOnly'>;
4
+ /**
5
+ * The publickey auth of a host, in OpenSSH's order (`pubkey_prepare` in
6
+ * sshconnect2.c of OpenSSH 10.5p1): the keys of the agent in its order, with
7
+ * IdentitiesOnly only those of an identity file, then the identity files that
8
+ * the agent lacks. An encrypted file is skipped, as in batch mode (ADR 0004).
9
+ * The dispose closes the connection to the agent.
10
+ */
11
+ export declare class Identities implements AsyncDisposable {
12
+ #private;
13
+ constructor(host: IdentityHost);
14
+ readonly method: AuthMethod;
15
+ [Symbol.asyncDispose](): Promise<void>;
16
+ }
17
+ export {};
18
+ //# sourceMappingURL=identities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identities.d.ts","sourceRoot":"","sources":["../src/identities.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQ5C,KAAK,YAAY,GAAG,IAAI,CACtB,QAAQ,EACR,eAAe,GAAG,eAAe,GAAG,gBAAgB,CACrD,CAAC;AAQF;;;;;;GAMG;AACH,qBAAa,UAAW,YAAW,eAAe;;gBAIpC,IAAI,EAAE,YAAY;IAI9B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAGzB;IAqCI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7C"}
@@ -0,0 +1,81 @@
1
+ import { once } from 'node:events';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { connect } from 'node:net';
4
+ import { AgentClient } from "./agent.js";
5
+ import { PassphraseMissingError, PrivateKey, } from "./private-key.js";
6
+ /**
7
+ * The publickey auth of a host, in OpenSSH's order (`pubkey_prepare` in
8
+ * sshconnect2.c of OpenSSH 10.5p1): the keys of the agent in its order, with
9
+ * IdentitiesOnly only those of an identity file, then the identity files that
10
+ * the agent lacks. An encrypted file is skipped, as in batch mode (ADR 0004).
11
+ * The dispose closes the connection to the agent.
12
+ */
13
+ export class Identities {
14
+ #host;
15
+ #agent = new DisposableStack();
16
+ constructor(host) {
17
+ this.#host = host;
18
+ }
19
+ method = {
20
+ type: 'publickey',
21
+ signers: () => this.#signers(),
22
+ };
23
+ async #signers() {
24
+ const files = (await Promise.all(this.#host.identityFiles.map(readIdentityFile))).filter((file) => file !== undefined);
25
+ const inFile = (key) => files.some((file) => file.publicKey?.equals(key) === true);
26
+ const agent = (await this.#agentSigners()).filter((signer) => !this.#host.identitiesOnly || inFile(signer.publicKey));
27
+ const held = (key) => agent.some((signer) => key !== undefined && signer.publicKey.equals(key));
28
+ return [
29
+ ...agent,
30
+ ...files
31
+ .filter((file) => !held(file.publicKey))
32
+ .flatMap(({ privateKey }) => privateKey ?? []),
33
+ ];
34
+ }
35
+ /** No agent at the socket is no agent keys, as OpenSSH goes on without one. */
36
+ async #agentSigners() {
37
+ const path = this.#host.identityAgent;
38
+ if (path === undefined)
39
+ return [];
40
+ const socket = this.#agent.adopt(connect(path), (each) => each.destroy());
41
+ try {
42
+ await once(socket, 'connect');
43
+ }
44
+ catch (error) {
45
+ if (isErrno(error, 'ENOENT') || isErrno(error, 'ECONNREFUSED')) {
46
+ return [];
47
+ }
48
+ throw error;
49
+ }
50
+ return new AgentClient(socket).signers();
51
+ }
52
+ async [Symbol.asyncDispose]() {
53
+ this.#agent.dispose();
54
+ }
55
+ }
56
+ /** A file that is missing, or that the package cannot read as a key, offers nothing, as OpenSSH goes on past it. */
57
+ async function readIdentityFile(file) {
58
+ let data;
59
+ try {
60
+ data = await readFile(file);
61
+ }
62
+ catch (error) {
63
+ if (isErrno(error, 'ENOENT'))
64
+ return undefined;
65
+ throw error;
66
+ }
67
+ try {
68
+ const privateKey = PrivateKey.parse(data);
69
+ return { publicKey: privateKey.publicKey, privateKey };
70
+ }
71
+ catch (error) {
72
+ if (error instanceof PassphraseMissingError) {
73
+ return { publicKey: error.publicKey, privateKey: undefined };
74
+ }
75
+ return undefined;
76
+ }
77
+ }
78
+ function isErrno(error, code) {
79
+ return Error.isError(error) && 'code' in error && error.code === code;
80
+ }
81
+ //# sourceMappingURL=identities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identities.js","sourceRoot":"","sources":["../src/identities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,OAAO,EACL,sBAAsB,EACtB,UAAU,GAEX,MAAM,kBAAkB,CAAC;AAc1B;;;;;;GAMG;AACH,MAAM,OAAO,UAAU;IACZ,KAAK,CAAe;IACpB,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IAExC,YAAY,IAAkB;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAEQ,MAAM,GAAe;QAC5B,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE;KAC/B,CAAC;IAEF,KAAK,CAAC,QAAQ;QACZ,MAAM,KAAK,GAAG,CACZ,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAClE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;QACvC,MAAM,MAAM,GAAG,CAAC,GAAc,EAAW,EAAE,CACzC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,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O,EAAE,CAAC;YACZ,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QACD,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;CACF;AAED,oHAAoH;AACpH,KAAK,UAAU,gBAAgB,CAC7B,IAAY;IAEZ,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC;YAAE,OAAO,SAAS,CAAC;QAC/C,MAAM,KAAK,CAAC;IACd,CAAC;IACD,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,sBAAsB,EAAE,CAAC;YAC5C,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;QAC/D,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CAAC,KAAc,EAAE,IAAY;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AACxE,CAAC"}
@@ -0,0 +1,9 @@
1
+ /** @zukhruf/ssh: an SSH client and server inside the Node process. */
2
+ export { AuthenticationError, type AuthMethod, Client, type ClientConfig, type HostKeyCallback, OpenChannelError, type RejectionReason, } from './client.ts';
3
+ export { PassphraseMissingError, PrivateKey, type Signer, } from './private-key.ts';
4
+ export type { Prompt } from './prompt.ts';
5
+ export { PublicKey } from './public-key.ts';
6
+ export { RemoteListener } from './remote-listener.ts';
7
+ export { type GlobalRequest, type IncomingChannel, type ServerConfig, ServerConn, ServerSession, type SessionRequest, } from './server.ts';
8
+ export { type Exit, ExitError, ExitMissingError, Session, type SignalName, type TerminalModes, type WindowSize, } from './session.ts';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,OAAO,EACL,mBAAmB,EACnB,KAAK,UAAU,EACf,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,gBAAgB,EAChB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,UAAU,EACV,KAAK,MAAM,GACZ,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,UAAU,EACV,aAAa,EACb,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,IAAI,EACT,SAAS,EACT,gBAAgB,EAChB,OAAO,EACP,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,UAAU,GAChB,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /** @zukhruf/ssh: an SSH client and server inside the Node process. */
2
+ export { AuthenticationError, Client, OpenChannelError, } from "./client.js";
3
+ export { PassphraseMissingError, PrivateKey, } from "./private-key.js";
4
+ export { PublicKey } from "./public-key.js";
5
+ export { RemoteListener } from "./remote-listener.js";
6
+ export { ServerConn, ServerSession, } from "./server.js";
7
+ export { ExitError, ExitMissingError, Session, } from "./session.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,OAAO,EACL,mBAAmB,EAEnB,MAAM,EAGN,gBAAgB,GAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,UAAU,GAEX,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAIL,UAAU,EACV,aAAa,GAEd,MAAM,aAAa,CAAC;AACrB,OAAO,EAEL,SAAS,EACT,gBAAgB,EAChB,OAAO,GAIR,MAAM,cAAc,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { PublicKey } from './public-key.ts';
2
+ /** Go's knownhosts.KnownKey. */
3
+ export interface KnownKey {
4
+ readonly key: PublicKey;
5
+ readonly file: string;
6
+ readonly line: number;
7
+ }
8
+ /** Go's knownhosts.KeyError: an empty `want` means an unknown host. */
9
+ export declare class KeyError extends Error {
10
+ readonly want: readonly KnownKey[];
11
+ constructor(name: string, want: readonly KnownKey[]);
12
+ }
13
+ /** Go's knownhosts.RevokedError. */
14
+ export declare class RevokedError extends Error {
15
+ readonly revoked: KnownKey;
16
+ constructor(name: string, revoked: KnownKey);
17
+ }
18
+ /** The keys of the known hosts files. Go's ssh/knownhosts. */
19
+ export declare class KnownHosts {
20
+ #private;
21
+ private constructor();
22
+ /** Reads the files in order; a missing file is empty. Go's knownhosts.New. */
23
+ static read(files: readonly string[]): Promise<KnownHosts>;
24
+ /** Throws KeyError or RevokedError. Looks up [hostname]:port when the port is not 22. */
25
+ check(hostname: string, port: number, key: PublicKey): void;
26
+ /** The algorithms of the known keys of the host first, then the rest of `offered`. Default `offered`: each one that the package supports. */
27
+ hostKeyAlgorithms(hostname: string, port: number, offered?: readonly string[]): string[];
28
+ /** Appends a line to the first file, hashed when `hash` is true. Go's knownhosts.Line. */
29
+ add(hostname: string, port: number, key: PublicKey, options: {
30
+ readonly hash: boolean;
31
+ }): Promise<void>;
32
+ }
33
+ //# sourceMappingURL=knownhosts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knownhosts.d.ts","sourceRoot":"","sources":["../src/knownhosts.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,gCAAgC;AAChC,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,uEAAuE;AACvE,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,IAAI,EAAE,SAAS,QAAQ,EAAE,CAAC;gBAEvB,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,QAAQ,EAAE;CASpD;AAED,oCAAoC;AACpC,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;gBAEf,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ;CAO5C;AAOD,8DAA8D;AAC9D,qBAAa,UAAU;;IAKrB,OAAO;IAUP,8EAA8E;WACjE,IAAI,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IAkBhE,yFAAyF;IACzF,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,GAAG,IAAI;IAe3D,6IAA6I;IAC7I,iBAAiB,CACf,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE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