bdy 1.26.12-dev → 1.26.13-stage
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/distTs/package.json +1 -1
- package/distTs/src/agent/agent.js +5 -1
- package/distTs/src/agent/manager.js +12 -3
- package/distTs/src/agent/system.js +2 -1
- package/distTs/src/sshKeygen.js +5 -1
- package/distTs/src/tunnel/api/buddy.js +2 -1
- package/distTs/src/tunnel/server/ssh.js +2 -2
- package/distTs/src/tunnel/ssh/client.js +3 -0
- package/distTs/src/tunnel/ssh/workerHostKey.js +7 -7
- package/distTs/src/tunnel/tunnel.js +10 -2
- package/package.json +1 -1
package/distTs/package.json
CHANGED
|
@@ -436,14 +436,18 @@ class Agent extends events_1.default {
|
|
|
436
436
|
});
|
|
437
437
|
tunnels.forEach((data) => {
|
|
438
438
|
let sshHostKey;
|
|
439
|
-
|
|
439
|
+
let sshHostKeyRsa;
|
|
440
|
+
if (this.manager) {
|
|
440
441
|
sshHostKey = this.manager.sshHostKey;
|
|
442
|
+
sshHostKeyRsa = this.manager.sshHostKeyRsa;
|
|
443
|
+
}
|
|
441
444
|
const tunnel = tt.find((tunnel) => data.id === tunnel.id);
|
|
442
445
|
if (!tunnel) {
|
|
443
446
|
const TunnelImpl = require('../tunnel/tunnel').default;
|
|
444
447
|
this.addTunnel(new TunnelImpl({
|
|
445
448
|
...data,
|
|
446
449
|
sshHostKey,
|
|
450
|
+
sshHostKeyRsa,
|
|
447
451
|
agent: {
|
|
448
452
|
id: this.id,
|
|
449
453
|
host: this.host,
|
|
@@ -26,6 +26,7 @@ class AgentManagerClass {
|
|
|
26
26
|
// actually gone. Anything that must not start in that window checks this.
|
|
27
27
|
exiting = false;
|
|
28
28
|
sshHostKey;
|
|
29
|
+
sshHostKeyRsa;
|
|
29
30
|
agent;
|
|
30
31
|
ws;
|
|
31
32
|
server;
|
|
@@ -38,6 +39,7 @@ class AgentManagerClass {
|
|
|
38
39
|
this.token = null;
|
|
39
40
|
this.port = null;
|
|
40
41
|
this.sshHostKey = null;
|
|
42
|
+
this.sshHostKeyRsa = null;
|
|
41
43
|
this.agent = null;
|
|
42
44
|
this.server = null;
|
|
43
45
|
this.ws = null;
|
|
@@ -713,7 +715,7 @@ class AgentManagerClass {
|
|
|
713
715
|
}
|
|
714
716
|
let tunnel;
|
|
715
717
|
try {
|
|
716
|
-
tunnel = await getApiBuddy().addTunnel(this.id || '', this.host || '', this.token || '', data, this.sshHostKey || '');
|
|
718
|
+
tunnel = await getApiBuddy().addTunnel(this.id || '', this.host || '', this.token || '', data, this.sshHostKey || '', this.sshHostKeyRsa || undefined);
|
|
717
719
|
}
|
|
718
720
|
catch (err) {
|
|
719
721
|
this.serverError(res, err.message);
|
|
@@ -838,19 +840,26 @@ class AgentManagerClass {
|
|
|
838
840
|
// load from config
|
|
839
841
|
const json = this.system.loadNewAgentConfig();
|
|
840
842
|
this.sshHostKey = json.sshHostKey;
|
|
843
|
+
this.sshHostKeyRsa = json.sshHostKeyRsa;
|
|
841
844
|
}
|
|
842
845
|
catch {
|
|
843
846
|
// save from param
|
|
844
847
|
}
|
|
845
|
-
const { createSshHostKey, isSshHostKeyValid } = require('../sshKeygen');
|
|
848
|
+
const { createSshHostKey, createSshHostKeyRsa, isSshHostKeyValid, } = require('../sshKeygen');
|
|
846
849
|
if (!isSshHostKeyValid(this.sshHostKey)) {
|
|
847
850
|
if (this.sshHostKey)
|
|
848
851
|
logger_1.default.error(texts_1.LOG_AGENT_SSH_HOST_KEY_INVALID);
|
|
849
852
|
this.sshHostKey = createSshHostKey();
|
|
850
853
|
}
|
|
854
|
+
// A config from before the RSA key has none: it is added next to the Ed25519 one, which stays
|
|
855
|
+
if (!isSshHostKeyValid(this.sshHostKeyRsa)) {
|
|
856
|
+
if (this.sshHostKeyRsa)
|
|
857
|
+
logger_1.default.error(texts_1.LOG_AGENT_SSH_HOST_KEY_INVALID);
|
|
858
|
+
this.sshHostKeyRsa = createSshHostKeyRsa();
|
|
859
|
+
}
|
|
851
860
|
try {
|
|
852
861
|
// resave config
|
|
853
|
-
this.system.saveNewAgentConfig(this.sshHostKey || '');
|
|
862
|
+
this.system.saveNewAgentConfig(this.sshHostKey || '', this.sshHostKeyRsa || '');
|
|
854
863
|
return true;
|
|
855
864
|
}
|
|
856
865
|
catch {
|
|
@@ -1096,7 +1096,7 @@ class AgentSystem {
|
|
|
1096
1096
|
return false;
|
|
1097
1097
|
}
|
|
1098
1098
|
}
|
|
1099
|
-
saveNewAgentConfig(sshHostKey) {
|
|
1099
|
+
saveNewAgentConfig(sshHostKey, sshHostKeyRsa) {
|
|
1100
1100
|
try {
|
|
1101
1101
|
this.clearAgentFiles();
|
|
1102
1102
|
}
|
|
@@ -1107,6 +1107,7 @@ class AgentSystem {
|
|
|
1107
1107
|
logger_1.default.info(texts_1.LOG_SAVING_AGENT_LOCAL_CONFIG);
|
|
1108
1108
|
(0, node_fs_1.writeFileSync)(this.getNewAgentConfigPath(), JSON.stringify({
|
|
1109
1109
|
sshHostKey,
|
|
1110
|
+
sshHostKeyRsa,
|
|
1110
1111
|
}), {
|
|
1111
1112
|
encoding: 'utf-8',
|
|
1112
1113
|
});
|
package/distTs/src/sshKeygen.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSshHostKey = exports.isSshHostKeyValid = void 0;
|
|
3
|
+
exports.createSshHostKeyRsa = exports.createSshHostKey = exports.isSshHostKeyValid = void 0;
|
|
4
4
|
const sshChannelWindow_1 = require("./sshChannelWindow");
|
|
5
5
|
// ssh2's own parser is the one ssh2.Server runs on the key, so this is the exact check that would fail later.
|
|
6
6
|
const isSshHostKeyValid = (key) => !!key && !((0, sshChannelWindow_1.requireSsh2)().utils.parseKey(key) instanceof Error);
|
|
7
7
|
exports.isSshHostKeyValid = isSshHostKeyValid;
|
|
8
8
|
const createSshHostKey = () => (0, sshChannelWindow_1.requireSsh2)().utils.generateKeyPairSync('ed25519', {}).private;
|
|
9
9
|
exports.createSshHostKey = createSshHostKey;
|
|
10
|
+
// The second host key the SSH server of a tunnel offers. A client names the algorithm, and one that
|
|
11
|
+
// knows the Ed25519 key goes on asking for it, so this one changes nothing for it.
|
|
12
|
+
const createSshHostKeyRsa = () => (0, sshChannelWindow_1.requireSsh2)().utils.generateKeyPairSync('rsa', { bits: 4096 }).private;
|
|
13
|
+
exports.createSshHostKeyRsa = createSshHostKeyRsa;
|
|
@@ -160,7 +160,7 @@ class ApiBuddyClass {
|
|
|
160
160
|
tags
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
|
-
async addTunnel(agentId, host, token, prepared, sshHostKey) {
|
|
163
|
+
async addTunnel(agentId, host, token, prepared, sshHostKey, sshHostKeyRsa) {
|
|
164
164
|
logger_1.default.info(texts_1.LOG_REGISTERING_TUNNEL);
|
|
165
165
|
const config = await makeRequest(host, '/tunnel/add', {
|
|
166
166
|
...prepared,
|
|
@@ -171,6 +171,7 @@ class ApiBuddyClass {
|
|
|
171
171
|
return new tunnel_1.default({
|
|
172
172
|
...config,
|
|
173
173
|
sshHostKey,
|
|
174
|
+
sshHostKeyRsa,
|
|
174
175
|
agent: { id: agentId, host, token },
|
|
175
176
|
});
|
|
176
177
|
}
|
|
@@ -117,14 +117,14 @@ class ServerSsh extends events_1.default {
|
|
|
117
117
|
login;
|
|
118
118
|
password;
|
|
119
119
|
server;
|
|
120
|
-
constructor(agent, login, password, hostKey) {
|
|
120
|
+
constructor(agent, login, password, hostKey, hostKeyRsa) {
|
|
121
121
|
super();
|
|
122
122
|
this.agent = agent;
|
|
123
123
|
this.login = login;
|
|
124
124
|
this.password = password;
|
|
125
125
|
this.server = new ssh2.Server({
|
|
126
126
|
...sshChannelWindow_1.SSH_CHANNEL_OPTIONS,
|
|
127
|
-
hostKeys: [hostKey],
|
|
127
|
+
hostKeys: hostKeyRsa ? [hostKey, hostKeyRsa] : [hostKey],
|
|
128
128
|
highWaterMark: 65536,
|
|
129
129
|
ident: 'SSH-2.0-Buddy',
|
|
130
130
|
algorithms: {
|
|
@@ -81,6 +81,9 @@ class SshClient extends events_1.default {
|
|
|
81
81
|
// for a worker that does not: it was the only one this list had, so every worker
|
|
82
82
|
// deployed before the post-quantum exchange takes it.
|
|
83
83
|
kex: (0, sshKex_1.withPqKex)(['ecdh-sha2-nistp256']),
|
|
84
|
+
// The worker's RSA 4096 host key where it has one, its Ed25519 key where it does not -
|
|
85
|
+
// a worker deployed before the RSA key. Either is checked the same way below.
|
|
86
|
+
serverHostKey: ['rsa-sha2-512', 'rsa-sha2-256', 'ssh-ed25519'],
|
|
84
87
|
},
|
|
85
88
|
keepaliveInterval: 10000,
|
|
86
89
|
// Capability advertisement, read by the worker off info.header at connection time. An
|
|
@@ -11,7 +11,10 @@ const node_net_1 = __importDefault(require("node:net"));
|
|
|
11
11
|
exports.WORKER_HOST_KEY_CA = [
|
|
12
12
|
'MCowBQYDK2VwAyEA2fgQwY2Ey9PRsJKdcAL4cGXkWmrVZsMJTww3lsUVYWE=',
|
|
13
13
|
].map((der) => node_crypto_1.default.createPublicKey({ key: Buffer.from(der, 'base64'), format: 'der', type: 'spki' }));
|
|
14
|
-
|
|
14
|
+
// One signature per host key the worker serves: ` bdy-sig:` for its Ed25519 key, ` bdy-sig-rsa:`
|
|
15
|
+
// for the RSA one. Each covers the exact key, so only the one made for the key the server showed
|
|
16
|
+
// verifies - whichever of them the key exchange settled on.
|
|
17
|
+
const SIGNATURES = / bdy-sig(?:-[a-z0-9]+)?:([A-Za-z0-9+/=]+)/g;
|
|
15
18
|
// Workers nobody deploys through the manager - a developer's local stack, the e2e one - have no
|
|
16
19
|
// signed key. Only ever reachable on an address of one's own network, so only those are let off.
|
|
17
20
|
const isLocalWorkerAddress = (ip) => {
|
|
@@ -42,18 +45,15 @@ exports.isLocalWorkerAddress = isLocalWorkerAddress;
|
|
|
42
45
|
const verifyWorkerHostKey = (ip, key, identRaw) => {
|
|
43
46
|
if ((0, exports.isLocalWorkerAddress)(ip))
|
|
44
47
|
return true;
|
|
45
|
-
const
|
|
46
|
-
if (!m)
|
|
47
|
-
return false;
|
|
48
|
+
const signatures = [...String(identRaw || '').matchAll(SIGNATURES)].map((m) => Buffer.from(m[1], 'base64'));
|
|
48
49
|
const message = Buffer.from(`bdy-worker-host-key\n${ip}\n${key.toString('base64')}`);
|
|
49
|
-
|
|
50
|
-
return exports.WORKER_HOST_KEY_CA.some((ca) => {
|
|
50
|
+
return signatures.some((signature) => exports.WORKER_HOST_KEY_CA.some((ca) => {
|
|
51
51
|
try {
|
|
52
52
|
return node_crypto_1.default.verify(null, message, ca, signature);
|
|
53
53
|
}
|
|
54
54
|
catch {
|
|
55
55
|
return false;
|
|
56
56
|
}
|
|
57
|
-
});
|
|
57
|
+
}));
|
|
58
58
|
};
|
|
59
59
|
exports.verifyWorkerHostKey = verifyWorkerHostKey;
|
|
@@ -57,6 +57,7 @@ class Tunnel extends events_1.default {
|
|
|
57
57
|
agent;
|
|
58
58
|
id;
|
|
59
59
|
sshHostKey;
|
|
60
|
+
sshHostKeyRsa;
|
|
60
61
|
config;
|
|
61
62
|
auth;
|
|
62
63
|
totalConnections;
|
|
@@ -78,7 +79,7 @@ class Tunnel extends events_1.default {
|
|
|
78
79
|
// drift the value. A drifted counter would latch the tunnel into answering
|
|
79
80
|
// 503 forever with no way back short of restarting the agent.
|
|
80
81
|
inFlight = new Set();
|
|
81
|
-
constructor({ agent, id, sshHostKey, ...options }) {
|
|
82
|
+
constructor({ agent, id, sshHostKey, sshHostKeyRsa, ...options }) {
|
|
82
83
|
super();
|
|
83
84
|
const { createSshHostKey, isSshHostKeyValid } = require('../sshKeygen');
|
|
84
85
|
if (!isSshHostKeyValid(sshHostKey))
|
|
@@ -86,6 +87,7 @@ class Tunnel extends events_1.default {
|
|
|
86
87
|
this.agent = agent;
|
|
87
88
|
this.id = id;
|
|
88
89
|
this.sshHostKey = sshHostKey;
|
|
90
|
+
this.sshHostKeyRsa = sshHostKeyRsa;
|
|
89
91
|
this.auth = new auth_1.default(this);
|
|
90
92
|
this.config = new config_1.default(options);
|
|
91
93
|
this.resetState();
|
|
@@ -637,7 +639,13 @@ class Tunnel extends events_1.default {
|
|
|
637
639
|
else if (this.type === tunnel_1.TUNNEL_TYPE.SSH) {
|
|
638
640
|
// ssh server
|
|
639
641
|
const ServerSsh = require('./server/ssh').default;
|
|
640
|
-
|
|
642
|
+
// Made here and not in the constructor like the Ed25519 one: an RSA 4096 key takes long
|
|
643
|
+
// enough to generate that only a tunnel which serves SSH should pay for it. The agent
|
|
644
|
+
// hands over the one it keeps (agent/manager.ts), so this is for a tunnel without one.
|
|
645
|
+
const { createSshHostKeyRsa, isSshHostKeyValid } = require('../sshKeygen');
|
|
646
|
+
if (!isSshHostKeyValid(this.sshHostKeyRsa))
|
|
647
|
+
this.sshHostKeyRsa = createSshHostKeyRsa();
|
|
648
|
+
this.sshServer = new ServerSsh(this.agent, this.sshClientUser || '', this.sshClientPassword || '', this.sshHostKey, this.sshHostKeyRsa);
|
|
641
649
|
}
|
|
642
650
|
// ssh
|
|
643
651
|
const SshClientImpl = require('./ssh/client').default;
|