@zukhruf/ssh 0.0.0-stage → 0.8.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1123 -2
- package/dist/address.d.ts +8 -0
- package/dist/address.d.ts.map +1 -0
- package/dist/address.js +15 -0
- package/dist/address.js.map +1 -0
- package/dist/agent.d.ts +35 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +288 -0
- package/dist/agent.js.map +1 -0
- package/dist/channel-stream.d.ts +16 -0
- package/dist/channel-stream.d.ts.map +1 -0
- package/dist/channel-stream.js +102 -0
- package/dist/channel-stream.js.map +1 -0
- package/dist/client.d.ts +114 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +587 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +82 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +255 -0
- package/dist/config.js.map +1 -0
- package/dist/control/control-client.d.ts +12 -0
- package/dist/control/control-client.d.ts.map +1 -0
- package/dist/control/control-client.js +156 -0
- package/dist/control/control-client.js.map +1 -0
- package/dist/control/control-master.d.ts +12 -0
- package/dist/control/control-master.d.ts.map +1 -0
- package/dist/control/control-master.js +101 -0
- package/dist/control/control-master.js.map +1 -0
- package/dist/control/control-stream.d.ts +29 -0
- package/dist/control/control-stream.d.ts.map +1 -0
- package/dist/control/control-stream.js +54 -0
- package/dist/control/control-stream.js.map +1 -0
- package/dist/control/messages.d.ts +38 -0
- package/dist/control/messages.d.ts.map +1 -0
- package/dist/control/messages.js +92 -0
- package/dist/control/messages.js.map +1 -0
- package/dist/control/serve-dial.d.ts +11 -0
- package/dist/control/serve-dial.d.ts.map +1 -0
- package/dist/control/serve-dial.js +47 -0
- package/dist/control/serve-dial.js.map +1 -0
- package/dist/control/serve-session.d.ts +11 -0
- package/dist/control/serve-session.d.ts.map +1 -0
- package/dist/control/serve-session.js +78 -0
- package/dist/control/serve-session.js.map +1 -0
- package/dist/control/wire.d.ts +41 -0
- package/dist/control/wire.d.ts.map +1 -0
- package/dist/control/wire.js +100 -0
- package/dist/control/wire.js.map +1 -0
- package/dist/control.d.ts +4 -0
- package/dist/control.d.ts.map +1 -0
- package/dist/control.js +4 -0
- package/dist/control.js.map +1 -0
- package/dist/dial-route.d.ts +14 -0
- package/dist/dial-route.d.ts.map +1 -0
- package/dist/dial-route.js +87 -0
- package/dist/dial-route.js.map +1 -0
- package/dist/host-key-algorithms.d.ts +7 -0
- package/dist/host-key-algorithms.d.ts.map +1 -0
- package/dist/host-key-algorithms.js +16 -0
- package/dist/host-key-algorithms.js.map +1 -0
- package/dist/host-key-policy.d.ts +22 -0
- package/dist/host-key-policy.d.ts.map +1 -0
- package/dist/host-key-policy.js +72 -0
- package/dist/host-key-policy.js.map +1 -0
- package/dist/identities.d.ts +18 -0
- package/dist/identities.d.ts.map +1 -0
- package/dist/identities.js +81 -0
- package/dist/identities.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/knownhosts.d.ts +33 -0
- package/dist/knownhosts.d.ts.map +1 -0
- package/dist/knownhosts.js +241 -0
- package/dist/knownhosts.js.map +1 -0
- package/dist/match-pattern.d.ts +3 -0
- package/dist/match-pattern.d.ts.map +1 -0
- package/dist/match-pattern.js +18 -0
- package/dist/match-pattern.js.map +1 -0
- package/dist/private-key.d.ts +42 -0
- package/dist/private-key.d.ts.map +1 -0
- package/dist/private-key.js +100 -0
- package/dist/private-key.js.map +1 -0
- package/dist/prompt.d.ts +6 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +2 -0
- package/dist/prompt.js.map +1 -0
- package/dist/proxy-command.d.ts +33 -0
- package/dist/proxy-command.d.ts.map +1 -0
- package/dist/proxy-command.js +121 -0
- package/dist/proxy-command.js.map +1 -0
- package/dist/proxy-jump.d.ts +19 -0
- package/dist/proxy-jump.d.ts.map +1 -0
- package/dist/proxy-jump.js +63 -0
- package/dist/proxy-jump.js.map +1 -0
- package/dist/public-key.d.ts +22 -0
- package/dist/public-key.d.ts.map +1 -0
- package/dist/public-key.js +102 -0
- package/dist/public-key.js.map +1 -0
- package/dist/remote-listener.d.ts +14 -0
- package/dist/remote-listener.d.ts.map +1 -0
- package/dist/remote-listener.js +39 -0
- package/dist/remote-listener.js.map +1 -0
- package/dist/server-alive-check.d.ts +36 -0
- package/dist/server-alive-check.d.ts.map +1 -0
- package/dist/server-alive-check.js +103 -0
- package/dist/server-alive-check.js.map +1 -0
- package/dist/server.d.ts +114 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +460 -0
- package/dist/server.js.map +1 -0
- package/dist/session.d.ts +97 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +193 -0
- package/dist/session.js.map +1 -0
- package/dist/ssh-g.d.ts +19 -0
- package/dist/ssh-g.d.ts.map +1 -0
- package/dist/ssh-g.js +67 -0
- package/dist/ssh-g.js.map +1 -0
- package/dist/ssh2-agent-forwarding.d.ts +51 -0
- package/dist/ssh2-agent-forwarding.d.ts.map +1 -0
- package/dist/ssh2-agent-forwarding.js +56 -0
- package/dist/ssh2-agent-forwarding.js.map +1 -0
- package/dist/ssh2-channel-open-failure.d.ts +28 -0
- package/dist/ssh2-channel-open-failure.d.ts.map +1 -0
- package/dist/ssh2-channel-open-failure.js +35 -0
- package/dist/ssh2-channel-open-failure.js.map +1 -0
- package/dist/ssh2-keepalive-request.d.ts +31 -0
- package/dist/ssh2-keepalive-request.d.ts.map +1 -0
- package/dist/ssh2-keepalive-request.js +6 -0
- package/dist/ssh2-keepalive-request.js.map +1 -0
- package/dist/ssh2-server-channel.d.ts +63 -0
- package/dist/ssh2-server-channel.d.ts.map +1 -0
- package/dist/ssh2-server-channel.js +309 -0
- package/dist/ssh2-server-channel.js.map +1 -0
- package/package.json +75 -4
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { appendFile, mkdir, readFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
import { ssh2HostKeyAlgorithms } from "./host-key-algorithms.js";
|
|
5
|
+
import { matchPattern } from "./match-pattern.js";
|
|
6
|
+
import { PublicKey } from "./public-key.js";
|
|
7
|
+
/** Go's knownhosts.KeyError: an empty `want` means an unknown host. */
|
|
8
|
+
export class KeyError extends Error {
|
|
9
|
+
want;
|
|
10
|
+
constructor(name, want) {
|
|
11
|
+
super(want.length === 0
|
|
12
|
+
? `knownhosts: the host key of ${name} is unknown`
|
|
13
|
+
: `knownhosts: the host key of ${name} does not match the known keys at ${want.map(({ file, line }) => `${file}:${line}`).join(', ')}`);
|
|
14
|
+
this.name = 'KeyError';
|
|
15
|
+
this.want = want;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Go's knownhosts.RevokedError. */
|
|
19
|
+
export class RevokedError extends Error {
|
|
20
|
+
revoked;
|
|
21
|
+
constructor(name, revoked) {
|
|
22
|
+
super(`knownhosts: the host key of ${name} is revoked at ${revoked.file}:${revoked.line}`);
|
|
23
|
+
this.name = 'RevokedError';
|
|
24
|
+
this.revoked = revoked;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// The host key algorithms of ssh2 that OpenSSH still accepts.
|
|
28
|
+
const supportedHostKeyAlgorithms = ssh2HostKeyAlgorithms.filter((algorithm) => algorithm !== 'ssh-dss');
|
|
29
|
+
/** The keys of the known hosts files. Go's ssh/knownhosts. */
|
|
30
|
+
export class KnownHosts {
|
|
31
|
+
#files;
|
|
32
|
+
#hostKeys;
|
|
33
|
+
#revoked;
|
|
34
|
+
constructor(files, hostKeys, revoked) {
|
|
35
|
+
this.#files = files;
|
|
36
|
+
this.#hostKeys = hostKeys;
|
|
37
|
+
this.#revoked = revoked;
|
|
38
|
+
}
|
|
39
|
+
/** Reads the files in order; a missing file is empty. Go's knownhosts.New. */
|
|
40
|
+
static async read(files) {
|
|
41
|
+
const hostKeys = [];
|
|
42
|
+
const revoked = [];
|
|
43
|
+
for (const file of files) {
|
|
44
|
+
const lines = (await readIfPresent(file)).split(/\r?\n/);
|
|
45
|
+
for (const [index, text] of lines.entries()) {
|
|
46
|
+
const parsed = parseLine(text, file, index + 1);
|
|
47
|
+
if (parsed === undefined)
|
|
48
|
+
continue;
|
|
49
|
+
if (parsed.marker === '@revoked') {
|
|
50
|
+
revoked.push(parsed.line);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
hostKeys.push(parsed.line);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return new KnownHosts([...files], hostKeys, revoked);
|
|
58
|
+
}
|
|
59
|
+
/** Throws KeyError or RevokedError. Looks up [hostname]:port when the port is not 22. */
|
|
60
|
+
check(hostname, port, key) {
|
|
61
|
+
const name = lookupName(hostname, port);
|
|
62
|
+
const revoked = this.#revoked.find((line) => line.matches(name) && line.known.key.equals(key));
|
|
63
|
+
if (revoked !== undefined)
|
|
64
|
+
throw new RevokedError(name, revoked.known);
|
|
65
|
+
const want = [];
|
|
66
|
+
for (const line of this.#hostKeys) {
|
|
67
|
+
if (!line.matches(name))
|
|
68
|
+
continue;
|
|
69
|
+
if (line.known.key.equals(key))
|
|
70
|
+
return;
|
|
71
|
+
want.push(line.known);
|
|
72
|
+
}
|
|
73
|
+
throw new KeyError(name, want);
|
|
74
|
+
}
|
|
75
|
+
/** The algorithms of the known keys of the host first, then the rest of `offered`. Default `offered`: each one that the package supports. */
|
|
76
|
+
hostKeyAlgorithms(hostname, port, offered = supportedHostKeyAlgorithms) {
|
|
77
|
+
const name = lookupName(hostname, port);
|
|
78
|
+
const revoked = this.#revoked.filter((line) => line.matches(name));
|
|
79
|
+
const known = new Set(this.#hostKeys
|
|
80
|
+
.filter((line) => line.matches(name) &&
|
|
81
|
+
!revoked.some(({ known }) => known.key.equals(line.known.key)))
|
|
82
|
+
.flatMap(({ known }) => algorithmsOf(known.key.type)));
|
|
83
|
+
return [
|
|
84
|
+
...offered.filter((algorithm) => known.has(algorithm)),
|
|
85
|
+
...offered.filter((algorithm) => !known.has(algorithm)),
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
/** Appends a line to the first file, hashed when `hash` is true. Go's knownhosts.Line. */
|
|
89
|
+
async add(hostname, port, key, options) {
|
|
90
|
+
const [file] = this.#files;
|
|
91
|
+
if (file === undefined) {
|
|
92
|
+
throw new Error('knownhosts: no known hosts file to add the key to');
|
|
93
|
+
}
|
|
94
|
+
const name = lookupName(hostname, port);
|
|
95
|
+
const host = options.hash ? HashedName.of(name) : new Patterns(name);
|
|
96
|
+
await mkdir(dirname(file), { recursive: true, mode: 0o700 });
|
|
97
|
+
const content = await readIfPresent(file);
|
|
98
|
+
const unterminated = content !== '' && !content.endsWith('\n');
|
|
99
|
+
await appendFile(file, `${unterminated ? '\n' : ''}${host.toString()} ${key.toString()}\n`);
|
|
100
|
+
const line = content === '' ? 1 : content.split('\n').length + (unterminated ? 1 : 0);
|
|
101
|
+
this.#hostKeys.push(new HostLine(host, { key, file, line }));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** The name that OpenSSH writes and looks up: `host`, or `[host]:port` when the port is not 22 (`put_host_port` in misc.c). */
|
|
105
|
+
function lookupName(hostname, port) {
|
|
106
|
+
const host = hostname.toLowerCase();
|
|
107
|
+
return port === 22 ? host : `[${host}]:${port}`;
|
|
108
|
+
}
|
|
109
|
+
/** The algorithms that a key of the type signs with: an RSA key signs with SHA-2 too (RFC 8332). */
|
|
110
|
+
function algorithmsOf(type) {
|
|
111
|
+
return type === 'ssh-rsa'
|
|
112
|
+
? ['rsa-sha2-512', 'rsa-sha2-256', 'ssh-rsa']
|
|
113
|
+
: [type];
|
|
114
|
+
}
|
|
115
|
+
async function readIfPresent(file) {
|
|
116
|
+
try {
|
|
117
|
+
return await readFile(file, 'utf8');
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (Error.isError(error) && 'code' in error && error.code === 'ENOENT') {
|
|
121
|
+
return '';
|
|
122
|
+
}
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
class HostLine {
|
|
127
|
+
#host;
|
|
128
|
+
known;
|
|
129
|
+
constructor(host, known) {
|
|
130
|
+
this.#host = host;
|
|
131
|
+
this.known = known;
|
|
132
|
+
}
|
|
133
|
+
matches(name) {
|
|
134
|
+
return this.#host.matches(name);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* A line of SSH_KNOWN_HOSTS FILE FORMAT in sshd(8): `[marker] hosts type
|
|
139
|
+
* base64 [comment]`. A line that cannot be read is skipped, as OpenSSH skips
|
|
140
|
+
* it. An `@cert-authority` line is read and dropped: ssh2 offers no
|
|
141
|
+
* certificate host key algorithm (ADR 0005).
|
|
142
|
+
*/
|
|
143
|
+
function parseLine(text, file, line) {
|
|
144
|
+
const fields = text.trim().split(/[ \t]+/);
|
|
145
|
+
if (fields[0] === undefined || fields[0] === '' || fields[0].startsWith('#'))
|
|
146
|
+
return undefined;
|
|
147
|
+
let marker;
|
|
148
|
+
if (fields[0] === '@revoked' || fields[0] === '@cert-authority') {
|
|
149
|
+
marker = fields[0];
|
|
150
|
+
fields.shift();
|
|
151
|
+
}
|
|
152
|
+
const [hosts, type, blob] = fields;
|
|
153
|
+
if (hosts === undefined || type === undefined || blob === undefined) {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
if (hosts.startsWith('@') || marker === '@cert-authority')
|
|
157
|
+
return undefined;
|
|
158
|
+
const key = parseKey(type, blob);
|
|
159
|
+
const host = hosts.startsWith('|')
|
|
160
|
+
? HashedName.parse(hosts)
|
|
161
|
+
: new Patterns(hosts);
|
|
162
|
+
if (key === undefined || host === undefined)
|
|
163
|
+
return undefined;
|
|
164
|
+
return { marker, line: new HostLine(host, { key, file, line }) };
|
|
165
|
+
}
|
|
166
|
+
function parseKey(type, blob) {
|
|
167
|
+
try {
|
|
168
|
+
const key = PublicKey.parse(Buffer.from(blob, 'base64'));
|
|
169
|
+
return key.type === type ? key : undefined;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** A comma list of patterns with `*`, `?` and `!`, matched as OpenSSH's `match_hostname` does: without case, on the whole lookup name. */
|
|
176
|
+
class Patterns {
|
|
177
|
+
#text;
|
|
178
|
+
#patterns;
|
|
179
|
+
constructor(text) {
|
|
180
|
+
this.#text = text;
|
|
181
|
+
this.#patterns = text
|
|
182
|
+
.split(',')
|
|
183
|
+
.filter((pattern) => pattern !== '')
|
|
184
|
+
.map((pattern) => {
|
|
185
|
+
const negated = pattern.startsWith('!');
|
|
186
|
+
return {
|
|
187
|
+
negated,
|
|
188
|
+
glob: (negated ? pattern.slice(1) : pattern).toLowerCase(),
|
|
189
|
+
};
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
matches(name) {
|
|
193
|
+
let matched = false;
|
|
194
|
+
for (const { negated, glob } of this.#patterns) {
|
|
195
|
+
if (!matchPattern(glob, name))
|
|
196
|
+
continue;
|
|
197
|
+
if (negated)
|
|
198
|
+
return false;
|
|
199
|
+
matched = true;
|
|
200
|
+
}
|
|
201
|
+
return matched;
|
|
202
|
+
}
|
|
203
|
+
toString() {
|
|
204
|
+
return this.#text;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/** `|1|<salt>|<HMAC-SHA1 of the name>`, OpenSSH's HashKnownHosts (`host_hash` in hostfile.c). */
|
|
208
|
+
class HashedName {
|
|
209
|
+
#salt;
|
|
210
|
+
#hash;
|
|
211
|
+
constructor(salt, hash) {
|
|
212
|
+
this.#salt = salt;
|
|
213
|
+
this.#hash = hash;
|
|
214
|
+
}
|
|
215
|
+
static parse(text) {
|
|
216
|
+
const [empty, type, salt, hash, ...rest] = text.split('|');
|
|
217
|
+
if (empty !== '' ||
|
|
218
|
+
type !== '1' ||
|
|
219
|
+
salt === undefined ||
|
|
220
|
+
hash === undefined ||
|
|
221
|
+
rest.length > 0) {
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
return new HashedName(Buffer.from(salt, 'base64'), Buffer.from(hash, 'base64'));
|
|
225
|
+
}
|
|
226
|
+
static of(name) {
|
|
227
|
+
const salt = randomBytes(20);
|
|
228
|
+
return new HashedName(salt, hmac(salt, name));
|
|
229
|
+
}
|
|
230
|
+
matches(name) {
|
|
231
|
+
const hash = hmac(this.#salt, name);
|
|
232
|
+
return (hash.length === this.#hash.length && timingSafeEqual(hash, this.#hash));
|
|
233
|
+
}
|
|
234
|
+
toString() {
|
|
235
|
+
return `|1|${this.#salt.toString('base64')}|${this.#hash.toString('base64')}`;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function hmac(salt, name) {
|
|
239
|
+
return createHmac('sha1', salt).update(name).digest();
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=knownhosts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knownhosts.js","sourceRoot":"","sources":["../src/knownhosts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,uEAAuE;AACvE,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAsB;IAEnC,YAAY,IAAY,EAAE,IAAyB;QACjD,KAAK,CACH,IAAI,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AAC,CACvE,CAAC;IACJ,CAAC;IAED,QAAQ;QACN,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;IAChF,CAAC;CACF;AAED,SAAS,IAAI,CAAC,IAAY,EAAE,IAAY;IACtC,OAAO,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-pattern.d.ts","sourceRoot":"","sources":["../src/match-pattern.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAcnE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** OpenSSH's `match_pattern` (match.c): `*` matches any run of characters, and `?` one character, with case. */
|
|
2
|
+
export function matchPattern(pattern, name) {
|
|
3
|
+
if (pattern === '')
|
|
4
|
+
return name === '';
|
|
5
|
+
const [first] = pattern;
|
|
6
|
+
if (first === '*') {
|
|
7
|
+
for (let start = 0; start <= name.length; start++) {
|
|
8
|
+
if (matchPattern(pattern.slice(1), name.slice(start)))
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (name === '')
|
|
14
|
+
return false;
|
|
15
|
+
return ((first === '?' || first === name[0]) &&
|
|
16
|
+
matchPattern(pattern.slice(1), name.slice(1)));
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=match-pattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-pattern.js","sourceRoot":"","sources":["../src/match-pattern.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,IAAY;IACxD,IAAI,OAAO,KAAK,EAAE;QAAE,OAAO,IAAI,KAAK,EAAE,CAAC;IACvC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;IACxB,IAAI,KAAK,KAAK,GAAG,EAAE,CAAC;QAClB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YAClD,IAAI,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAAE,OAAO,IAAI,CAAC;QACrE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IAC9B,OAAO,CACL,CAAC,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;QACpC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAC9C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { PublicKey } from './public-key.ts';
|
|
2
|
+
/** A private key that signs: a parsed key, or a key of the agent. Go's ssh.Signer. */
|
|
3
|
+
export interface Signer {
|
|
4
|
+
readonly publicKey: PublicKey;
|
|
5
|
+
/** The signature blob of `algorithm`, such as rsa-sha2-256; without one, the algorithm of the key type. */
|
|
6
|
+
sign(data: Uint8Array, algorithm?: string): Promise<Uint8Array>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The ParsedKey of the protocol library (ADR 0003), written out so that no
|
|
10
|
+
* .d.ts of the package imports it. ServerConn gives it to the server of the
|
|
11
|
+
* library, which signs the key exchange with it synchronously (kex.js:731 of
|
|
12
|
+
* version 1.17.0); a Signer signs asynchronously. Not exported from the package.
|
|
13
|
+
* The static block of PrivateKey checks that a ParsedKey is a ProtocolKey, and
|
|
14
|
+
* ServerConn checks the other direction.
|
|
15
|
+
*/
|
|
16
|
+
export interface ProtocolKey {
|
|
17
|
+
type: 'ssh-rsa' | 'ssh-dss' | 'ssh-ed25519' | 'ecdsa-sha2-nistp256' | 'ecdsa-sha2-nistp384' | 'ecdsa-sha2-nistp521';
|
|
18
|
+
comment: string;
|
|
19
|
+
sign(data: Buffer | string, algo?: string): Buffer;
|
|
20
|
+
verify(data: Buffer | string, signature: Buffer, algo?: string): boolean;
|
|
21
|
+
isPrivateKey(): boolean;
|
|
22
|
+
getPrivatePEM(): string;
|
|
23
|
+
getPublicPEM(): string;
|
|
24
|
+
getPublicSSH(): Buffer;
|
|
25
|
+
equals(key: Buffer | string | ProtocolKey): boolean;
|
|
26
|
+
}
|
|
27
|
+
/** The ProtocolKey of a PrivateKey. Not exported from the package. */
|
|
28
|
+
export declare function protocolKeyOf(key: PrivateKey): ProtocolKey;
|
|
29
|
+
export declare class PassphraseMissingError extends Error {
|
|
30
|
+
readonly publicKey: PublicKey | undefined;
|
|
31
|
+
constructor(publicKey: PublicKey | undefined);
|
|
32
|
+
}
|
|
33
|
+
/** Go's ParsePrivateKey and ParsePrivateKeyWithPassphrase. */
|
|
34
|
+
export declare class PrivateKey implements Signer {
|
|
35
|
+
#private;
|
|
36
|
+
readonly publicKey: PublicKey;
|
|
37
|
+
private constructor();
|
|
38
|
+
/** An OpenSSH key, or a PKCS#1, PKCS#8 or SEC1 PEM key. Throws PassphraseMissingError for an encrypted key with no passphrase. */
|
|
39
|
+
static parse(data: Uint8Array, passphrase?: string): PrivateKey;
|
|
40
|
+
sign(data: Uint8Array, algorithm?: string): Promise<Uint8Array>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=private-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-key.d.ts","sourceRoot":"","sources":["../src/private-key.ts"],"names":[],"mappings":"AAEA,OAAO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C,EAAE,MAAM,GAAG,UAAU;IAoBzD,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAUtE"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import ssh2, {} from 'ssh2';
|
|
2
|
+
import { PublicKey } from "./public-key.js";
|
|
3
|
+
const bridge = {
|
|
4
|
+
protocolKeyOf: () => {
|
|
5
|
+
throw new Error('ssh: the PrivateKey class has not loaded');
|
|
6
|
+
},
|
|
7
|
+
};
|
|
8
|
+
/** The ProtocolKey of a PrivateKey. Not exported from the package. */
|
|
9
|
+
export function protocolKeyOf(key) {
|
|
10
|
+
return bridge.protocolKeyOf(key);
|
|
11
|
+
}
|
|
12
|
+
export class PassphraseMissingError extends Error {
|
|
13
|
+
publicKey;
|
|
14
|
+
constructor(publicKey) {
|
|
15
|
+
super('ssh: this private key is passphrase protected');
|
|
16
|
+
this.name = 'PassphraseMissingError';
|
|
17
|
+
this.publicKey = publicKey;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// The hash of each RSA signature algorithm (RFC 8332); the other key types
|
|
21
|
+
// have one signature algorithm, which ssh2 picks from the key.
|
|
22
|
+
const rsaHashes = {
|
|
23
|
+
'ssh-rsa': 'sha1',
|
|
24
|
+
'rsa-sha2-256': 'sha256',
|
|
25
|
+
'rsa-sha2-512': 'sha512',
|
|
26
|
+
};
|
|
27
|
+
/** Go's ParsePrivateKey and ParsePrivateKeyWithPassphrase. */
|
|
28
|
+
export class PrivateKey {
|
|
29
|
+
publicKey;
|
|
30
|
+
#key;
|
|
31
|
+
static {
|
|
32
|
+
bridge.protocolKeyOf = (key) => key.#key;
|
|
33
|
+
}
|
|
34
|
+
constructor(key) {
|
|
35
|
+
this.#key = key;
|
|
36
|
+
this.publicKey = PublicKey.parse(key.getPublicSSH());
|
|
37
|
+
}
|
|
38
|
+
/** An OpenSSH key, or a PKCS#1, PKCS#8 or SEC1 PEM key. Throws PassphraseMissingError for an encrypted key with no passphrase. */
|
|
39
|
+
static parse(data, passphrase) {
|
|
40
|
+
const bytes = Buffer.from(data);
|
|
41
|
+
const parsed = ssh2.utils.parseKey(bytes, passphrase);
|
|
42
|
+
if (Error.isError(parsed)) {
|
|
43
|
+
if (passphrase === undefined &&
|
|
44
|
+
parsed.message.includes('no passphrase given')) {
|
|
45
|
+
throw new PassphraseMissingError(clearPublicKey(bytes));
|
|
46
|
+
}
|
|
47
|
+
throw new Error(`ssh: cannot parse the private key: ${parsed.message}`, {
|
|
48
|
+
cause: parsed,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (!parsed.isPrivateKey()) {
|
|
52
|
+
throw new Error('ssh: the key is not a private key');
|
|
53
|
+
}
|
|
54
|
+
return new PrivateKey(parsed);
|
|
55
|
+
}
|
|
56
|
+
async sign(data, algorithm) {
|
|
57
|
+
const hash = algorithm === undefined ? undefined : rsaHashes[algorithm];
|
|
58
|
+
const signature = this.#key.sign(Buffer.from(data), hash);
|
|
59
|
+
if (Error.isError(signature)) {
|
|
60
|
+
throw new Error(`ssh: cannot sign with the ${this.publicKey.type} key`, {
|
|
61
|
+
cause: signature,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return new Uint8Array(signature);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// An OpenSSH private key file holds its public key unencrypted
|
|
68
|
+
// (OpenSSH PROTOCOL.key): "openssh-key-v1\0", the cipher name, the KDF name,
|
|
69
|
+
// the KDF options, the number of keys, then the first public key.
|
|
70
|
+
function clearPublicKey(file) {
|
|
71
|
+
const text = file.toString('latin1');
|
|
72
|
+
const body = /-----BEGIN OPENSSH PRIVATE KEY-----([\s\S]*?)-----END OPENSSH PRIVATE KEY-----/.exec(text)?.[1];
|
|
73
|
+
if (body === undefined)
|
|
74
|
+
return undefined;
|
|
75
|
+
const bytes = Buffer.from(body.replace(/\s+/g, ''), 'base64');
|
|
76
|
+
const magic = Buffer.from('openssh-key-v1\0', 'latin1');
|
|
77
|
+
if (!bytes.subarray(0, magic.length).equals(magic))
|
|
78
|
+
return undefined;
|
|
79
|
+
let offset = magic.length;
|
|
80
|
+
const readString = () => {
|
|
81
|
+
if (offset + 4 > bytes.length)
|
|
82
|
+
return undefined;
|
|
83
|
+
const length = bytes.readUInt32BE(offset);
|
|
84
|
+
const end = offset + 4 + length;
|
|
85
|
+
if (end > bytes.length)
|
|
86
|
+
return undefined;
|
|
87
|
+
const value = bytes.subarray(offset + 4, end);
|
|
88
|
+
offset = end;
|
|
89
|
+
return value;
|
|
90
|
+
};
|
|
91
|
+
for (const _field of ['cipher', 'kdf', 'kdf options']) {
|
|
92
|
+
if (readString() === undefined)
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const keyCountLength = 4;
|
|
96
|
+
offset += keyCountLength;
|
|
97
|
+
const wire = readString();
|
|
98
|
+
return wire === undefined ? undefined : PublicKey.parse(wire);
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=private-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-key.js","sourceRoot":"","sources":["../src/private-key.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAkB,MAAM,MAAM,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAqC5C,MAAM,MAAM,GAAwD;IAClE,aAAa,EAAE,GAAG,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;CACF,CAAC;AAEF,sEAAsE;AACtE,MAAM,UAAU,aAAa,CAAC,GAAe;IAC3C,OAAO,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACtC,SAAS,CAAwB;IAE1C,YAAY,SAAgC;QAC1C,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACvD,IAAI,CAAC,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ED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ChildProcessByStdio } from 'node:child_process';
|
|
2
|
+
import { Duplex, type Readable, type Writable } from 'node:stream';
|
|
3
|
+
import type { JumpHost } from './config.ts';
|
|
4
|
+
import type { Environment } from './ssh-g.ts';
|
|
5
|
+
type ProxyProcess = ChildProcessByStdio<Writable, Readable, null>;
|
|
6
|
+
/**
|
|
7
|
+
* Runs a ProxyCommand as OpenSSH does (ADR 0010): `<SHELL> -c "exec
|
|
8
|
+
* <command>"` with its tokens expanded, SHELL of the environment or /bin/sh,
|
|
9
|
+
* the environment as its whole environment, and its stderr left to the Node
|
|
10
|
+
* process (`ssh_proxy_connect` in sshconnect.c of OpenSSH 10.5p1). Its stdin
|
|
11
|
+
* and stdout are the transport.
|
|
12
|
+
*/
|
|
13
|
+
export declare function startProxyCommand(command: string, host: JumpHost, environment: Environment): ProxyCommandTransport;
|
|
14
|
+
/**
|
|
15
|
+
* The stdout and the stdin of a ProxyCommand as one stream. The end of its
|
|
16
|
+
* stdout ends the transport, as OpenSSH reads the end of the connection
|
|
17
|
+
* (`client_process_net_input` in clientloop.c). When the client ends its side
|
|
18
|
+
* or destroys the transport, the command gets SIGHUP and nothing waits for it
|
|
19
|
+
* to exit (`ssh_kill_proxy_command` in sshconnect.c). ref() and unref() reach
|
|
20
|
+
* the command and both of its pipes.
|
|
21
|
+
*/
|
|
22
|
+
export declare class ProxyCommandTransport extends Duplex {
|
|
23
|
+
#private;
|
|
24
|
+
constructor(child: ProxyProcess);
|
|
25
|
+
ref(): void;
|
|
26
|
+
unref(): void;
|
|
27
|
+
_read(): void;
|
|
28
|
+
_write(chunk: Buffer, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
29
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
30
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=proxy-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-command.d.ts","sourceRoot":"","sources":["../src/proxy-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAS,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAE,MAAM,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,KAAK,YAAY,GAAG,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AAElE;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,QAAQ,EACd,WAAW,EAAE,WAAW,GACvB,qBAAqB,CASvB;AAmCD;;;;;;;GAOG;AACH,qBAAa,qBAAsB,SAAQ,MAAM;;gBAInC,KAAK,EAAE,YAAY;IAgB/B,GAAG,IAAI,IAAI;IAKX,KAAK,IAAI,IAAI;IAKJ,KAAK,IAAI,IAAI;IAIb,MAAM,CACb,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,cAAc,EACzB,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GACvC,IAAI;IAIE,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAOtD,QAAQ,CACf,KAAK,EAAE,KAAK,GAAG,IAAI,EACnB,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GACvC,IAAI;CAcR"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { Socket } from 'node:net';
|
|
3
|
+
import { Duplex } from 'node:stream';
|
|
4
|
+
import { parseProxyJump } from "./proxy-jump.js";
|
|
5
|
+
/**
|
|
6
|
+
* Runs a ProxyCommand as OpenSSH does (ADR 0010): `<SHELL> -c "exec
|
|
7
|
+
* <command>"` with its tokens expanded, SHELL of the environment or /bin/sh,
|
|
8
|
+
* the environment as its whole environment, and its stderr left to the Node
|
|
9
|
+
* process (`ssh_proxy_connect` in sshconnect.c of OpenSSH 10.5p1). Its stdin
|
|
10
|
+
* and stdout are the transport.
|
|
11
|
+
*/
|
|
12
|
+
export function startProxyCommand(command, host, environment) {
|
|
13
|
+
const expanded = expandProxyCommand(`exec ${command}`, host);
|
|
14
|
+
const shell = environment['SHELL'] || '/bin/sh';
|
|
15
|
+
return new ProxyCommandTransport(spawn(shell, ['-c', expanded], {
|
|
16
|
+
env: environment,
|
|
17
|
+
stdio: ['pipe', 'pipe', 'inherit'],
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
/** `expand_proxy_command` in ssh.c and `percent_expand` in misc.c of OpenSSH 10.5p1: %h, %k, %n, %p, %r and %%; any other token fails, as OpenSSH fails. */
|
|
21
|
+
function expandProxyCommand(command, host) {
|
|
22
|
+
const original = originalHost(host.destination);
|
|
23
|
+
const tokens = {
|
|
24
|
+
'%': '%',
|
|
25
|
+
h: host.hostname,
|
|
26
|
+
k: host.hostKeyAlias ?? original,
|
|
27
|
+
n: original,
|
|
28
|
+
p: String(host.port),
|
|
29
|
+
r: host.user,
|
|
30
|
+
};
|
|
31
|
+
return command.replaceAll(/%(.?)/gs, (_match, key) => {
|
|
32
|
+
const value = tokens[key];
|
|
33
|
+
if (value === undefined) {
|
|
34
|
+
throw new Error(key === ''
|
|
35
|
+
? `ssh: the ProxyCommand ${command} ends with a lone %`
|
|
36
|
+
: `ssh: the ProxyCommand ${command} has the unknown token %${key}`);
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** The host of the destination as the command line gave it, OpenSSH's `host_arg` (ssh.c): the host of an `ssh://` URI, or the part after the last `@`. */
|
|
42
|
+
function originalHost(destination) {
|
|
43
|
+
if (destination.startsWith('ssh://')) {
|
|
44
|
+
const [hop] = parseProxyJump(destination);
|
|
45
|
+
if (hop !== undefined)
|
|
46
|
+
return hop.host;
|
|
47
|
+
}
|
|
48
|
+
return destination.slice(destination.lastIndexOf('@') + 1);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The stdout and the stdin of a ProxyCommand as one stream. The end of its
|
|
52
|
+
* stdout ends the transport, as OpenSSH reads the end of the connection
|
|
53
|
+
* (`client_process_net_input` in clientloop.c). When the client ends its side
|
|
54
|
+
* or destroys the transport, the command gets SIGHUP and nothing waits for it
|
|
55
|
+
* to exit (`ssh_kill_proxy_command` in sshconnect.c). ref() and unref() reach
|
|
56
|
+
* the command and both of its pipes.
|
|
57
|
+
*/
|
|
58
|
+
export class ProxyCommandTransport extends Duplex {
|
|
59
|
+
#child;
|
|
60
|
+
#pipes;
|
|
61
|
+
constructor(child) {
|
|
62
|
+
super({ allowHalfOpen: false });
|
|
63
|
+
this.#child = child;
|
|
64
|
+
this.#pipes = [pipeOf(child.stdin), pipeOf(child.stdout)];
|
|
65
|
+
child.once('error', (error) => this.destroy(error));
|
|
66
|
+
child.stdout.on('data', (chunk) => {
|
|
67
|
+
if (!this.push(chunk))
|
|
68
|
+
child.stdout.pause();
|
|
69
|
+
});
|
|
70
|
+
child.stdout.once('end', () => this.push(null));
|
|
71
|
+
child.stdout.once('error', (error) => this.destroy(error));
|
|
72
|
+
// A command that exits closes its stdin, so a write after it fails with
|
|
73
|
+
// EPIPE; the end of its stdout ends the transport.
|
|
74
|
+
child.stdin.on('error', () => undefined);
|
|
75
|
+
this.once('finish', () => this.destroy());
|
|
76
|
+
}
|
|
77
|
+
ref() {
|
|
78
|
+
this.#child.ref();
|
|
79
|
+
for (const pipe of this.#pipes)
|
|
80
|
+
pipe.ref();
|
|
81
|
+
}
|
|
82
|
+
unref() {
|
|
83
|
+
this.#child.unref();
|
|
84
|
+
for (const pipe of this.#pipes)
|
|
85
|
+
pipe.unref();
|
|
86
|
+
}
|
|
87
|
+
_read() {
|
|
88
|
+
this.#child.stdout.resume();
|
|
89
|
+
}
|
|
90
|
+
_write(chunk, _encoding, callback) {
|
|
91
|
+
this.#child.stdin.write(chunk, () => callback());
|
|
92
|
+
}
|
|
93
|
+
_final(callback) {
|
|
94
|
+
this.#child.stdin.end(() => {
|
|
95
|
+
this.#hangUp();
|
|
96
|
+
callback();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
_destroy(error, callback) {
|
|
100
|
+
this.#hangUp();
|
|
101
|
+
this.#child.stdout.destroy();
|
|
102
|
+
this.#child.stdin.destroy();
|
|
103
|
+
callback(error);
|
|
104
|
+
}
|
|
105
|
+
#hangUp() {
|
|
106
|
+
const child = this.#child;
|
|
107
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
108
|
+
child.kill('SIGHUP');
|
|
109
|
+
}
|
|
110
|
+
child.unref();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Node makes each 'pipe' of spawn a net.Socket (createSocket in
|
|
114
|
+
// lib/internal/child_process.js); the types name only a stream.
|
|
115
|
+
function pipeOf(stream) {
|
|
116
|
+
if (!(stream instanceof Socket)) {
|
|
117
|
+
throw new TypeError('ssh: a pipe of the ProxyCommand is not a socket');
|
|
118
|
+
}
|
|
119
|
+
return stream;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=proxy-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-command.js","sourceRoot":"","sources":["../src/proxy-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAA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AC;QACf,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QAC5B,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;IAED,OAAO;QACL,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YACzD,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvB,CAAC;QACD,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;CACF;AAED,gEAAgE;AAChE,gEAAgE;AAChE,SAAS,MAAM,CAAC,MAA2B;IACzC,IAAI,CAAC,CAAC,MAAM,YAAY,MAAM,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,iDAAiD,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** One jump host of a ProxyJump value: `[user@]host[:port]` or `ssh://[user@]host[:port]`. */
|
|
2
|
+
export interface Hop {
|
|
3
|
+
readonly host: string;
|
|
4
|
+
readonly user: string | undefined;
|
|
5
|
+
readonly port: number | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The jump hosts of the ProxyJump value that ssh -G prints, in order, each
|
|
9
|
+
* with the user and the port that the value gives (`parse_jump` in
|
|
10
|
+
* readconf.c and `parse_user_host_port` in misc.c of OpenSSH 10.5p1).
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseProxyJump(value: string): Hop[];
|
|
13
|
+
/**
|
|
14
|
+
* The flags of the ssh that OpenSSH starts for a jump host (ssh.c of OpenSSH
|
|
15
|
+
* 10.5p1, lines 1292-1340): `-l` and `-p` from the ProxyJump value, and the
|
|
16
|
+
* caller's `-F <file>` when it gave one. No other flag of the caller.
|
|
17
|
+
*/
|
|
18
|
+
export declare function jumpHostFlags(hop: Hop, callerFlags: readonly string[]): string[];
|
|
19
|
+
//# sourceMappingURL=proxy-jump.d.ts.map
|