File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -402,7 +402,17 @@ class Client extends EventEmitter {
402
402
} ) ;
403
403
} else if ( curAuth . type === 'publickey' ) {
404
404
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 ) ;
406
416
if ( signature instanceof Error ) {
407
417
signature . message =
408
418
`Error signing data with key: ${ signature . message } ` ;
Original file line number Diff line number Diff line change @@ -616,7 +616,16 @@ class Protocol {
616
616
if ( pubKey instanceof Error )
617
617
throw new Error ( 'Invalid key' ) ;
618
618
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
+
620
629
pubKey = pubKey . getPublicSSH ( ) ;
621
630
622
631
const userLen = Buffer . byteLength ( username ) ;
Original file line number Diff line number Diff line change @@ -197,6 +197,8 @@ function handleKexInit(self, payload) {
197
197
const local = self . _offer ;
198
198
const remote = init ;
199
199
200
+ self . _remoteHostKeyAlgorithms = remote . serverHostKey ;
201
+
200
202
let localKex = local . lists . kex . array ;
201
203
if ( self . _compatFlags & COMPAT . BAD_DHGEX ) {
202
204
let found = false ;
You can’t perform that action at this time.
0 commit comments