Skip to content

Commit 22735ce

Browse files
committed
added rsa-sha-xxx key sig support
1 parent 24b497d commit 22735ce

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lib/client.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,17 @@ class Client extends EventEmitter {
402402
});
403403
} else if (curAuth.type === 'publickey') {
404404
proto.authPK(curAuth.username, curAuth.key, (buf, cb) => {
405-
const signature = curAuth.key.sign(buf);
405+
let signatureAlgo;
406+
if (curAuth.key.type === 'ssh-rsa') {
407+
if (this._protocol._remoteHostKeyAlgorithms
408+
.includes('rsa-sha2-512')) {
409+
signatureAlgo = 'sha512';
410+
} else if (this._protocol._remoteHostKeyAlgorithms
411+
.includes('rsa-sha2-256')) {
412+
signatureAlgo = 'sha256';
413+
}
414+
}
415+
const signature = curAuth.key.sign(buf, signatureAlgo);
406416
if (signature instanceof Error) {
407417
signature.message =
408418
`Error signing data with key: ${signature.message}`;

lib/protocol/Protocol.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,16 @@ class Protocol {
616616
if (pubKey instanceof Error)
617617
throw new Error('Invalid key');
618618

619-
const keyType = pubKey.type;
619+
let keyType = pubKey.type;
620+
if (keyType === 'ssh-rsa') {
621+
for (const algo of ['rsa-sha2-512', 'rsa-sha2-256']) {
622+
if (this._remoteHostKeyAlgorithms.includes(algo)) {
623+
keyType = algo;
624+
break;
625+
}
626+
}
627+
}
628+
620629
pubKey = pubKey.getPublicSSH();
621630

622631
const userLen = Buffer.byteLength(username);

lib/protocol/kex.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ function handleKexInit(self, payload) {
197197
const local = self._offer;
198198
const remote = init;
199199

200+
self._remoteHostKeyAlgorithms = remote.serverHostKey;
201+
200202
let localKex = local.lists.kex.array;
201203
if (self._compatFlags & COMPAT.BAD_DHGEX) {
202204
let found = false;

0 commit comments

Comments
 (0)