Skip to content

Commit

Permalink
added rsa-sha-xxx key sig support
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Jul 29, 2022
1 parent 24b497d commit 2f5fa9f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,17 @@ class Client extends EventEmitter {
});
} else if (curAuth.type === 'publickey') {
proto.authPK(curAuth.username, curAuth.key, (buf, cb) => {
const signature = curAuth.key.sign(buf);
let signatureAlgo;
if (curAuth.key.type === 'ssh-rsa') {
if (this._protocol._remoteHostKeyAlgorithms
.includes('rsa-sha2-512')) {
signatureAlgo = 'sha512';
} else if (this._protocol._remotleHostKeyAlgorithms
.includes('rsa-sha2-256')) {
signatureAlgo = 'sha256';
}
}
const signature = curAuth.key.sign(buf, signatureAlgo);
if (signature instanceof Error) {
signature.message =
`Error signing data with key: ${signature.message}`;
Expand Down
11 changes: 10 additions & 1 deletion lib/protocol/Protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,16 @@ class Protocol {
if (pubKey instanceof Error)
throw new Error('Invalid key');

const keyType = pubKey.type;
let keyType = pubKey.type;
if (keyType === 'ssh-rsa') {
for (const algo of ['rsa-sha2-512', 'rsa-sha2-256']) {
if (this._remoteHostKeyAlgorithms.includes(algo)) {
keyType = algo;
break;
}
}
}

pubKey = pubKey.getPublicSSH();

const userLen = Buffer.byteLength(username);
Expand Down
2 changes: 2 additions & 0 deletions lib/protocol/kex.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ function handleKexInit(self, payload) {
const local = self._offer;
const remote = init;

self._remoteHostKeyAlgorithms = remote.serverHostKey;

let localKex = local.lists.kex.array;
if (self._compatFlags & COMPAT.BAD_DHGEX) {
let found = false;
Expand Down

0 comments on commit 2f5fa9f

Please sign in to comment.