forked from libapps/libapps-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnassh_relay_sshfe.js
More file actions
84 lines (74 loc) · 2 KB
/
nassh_relay_sshfe.js
File metadata and controls
84 lines (74 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2018 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Implementation for the ssh-fe@google.com proxy.
*/
import {lib} from '../../libdot/index.js';
import {hterm} from '../../hterm/index.js';
import {getGoogleSshAgentExtension} from './nassh_google.js';
import {LocalPreferenceManager} from './nassh_preference_manager.js';
import {Relay} from './nassh_relay.js';
import {Stream} from './nassh_stream.js';
import {RelaySshfeWsStream} from './nassh_stream_relay_sshfe.js';
/**
* SSH-FE relay implementation.
*/
export class Sshfe extends Relay {
/**
* @param {!hterm.Terminal.IO} io
* @param {!Object} options
* @param {!Location} location
* @param {!lib.Storage} storage
* @param {!LocalPreferenceManager} localPrefs
* @override
*/
constructor(io, options, location, storage, localPrefs) {
super(io, options, location, storage, localPrefs);
this.sshAgent_ = options['--ssh-agent'] || getGoogleSshAgentExtension();
this.relayServer = `wss://${this.proxyHost}:${this.proxyPort}`;
}
/** @override */
redirect() {
// This shouldn't be called in the first place.
throw new Error('ssh-fe does not redirect');
}
/**
* @return {!Promise<boolean>}
* @override
*/
async init() {
// Most init happens in the stream below.
return true;
}
/**
* @return {!Object}
* @override
*/
saveState() { return {}; }
/**
* @param {!Object} state
* @override
*/
loadState(state) {}
/**
* @param {string} host
* @param {number} port
* @return {!Promise<!Stream>}
* @override
*/
async openSocket(host, port) {
const settings = {
io: this.io_,
relayHost: this.proxyHost,
relayPort: this.proxyPort,
relayUser: this.username,
host: host,
port: port,
sshAgent: this.sshAgent_,
};
const stream = new RelaySshfeWsStream();
await stream.open(settings);
return stream;
}
}