I have the following code to capture the fingerprint of a server for (server) testing.
I reject the connection after capturing the fingerprint by returning "false" from the hostVerifier.
Doing so causes an error (KEY_EXCHANGE_FAILED) that I would like to catch so that it doesn't propagate -- it's expected behavior in my testing environment.
But I am baffled as to how to catch this error, and am looking for ideas.
var Connection = require('ssh2');
function getSSHFingerprintSSH2(ip, port) {
return new Promise(resolve => {
let fingerprintToReturn = "fingerprint error";
let sshConnection = new Connection();
sshConnection.on('error', function() {
//normal operation resolves here after rejecting the connection
resolve(fingerprintToReturn);
});
sshConnection.connect({
host: ip,
port: port,
username: '',
password: '',
hostHash: 'sha256',
hostVerifier: function(fingerprint) {
fingerprintToReturn = fingerprint;
// returning "false" rejects the connection with a handshake error
// which is what we want to do normally, having captured the fingerprint
return false;
},
});
});
}
I have the following code to capture the fingerprint of a server for (server) testing.
I reject the connection after capturing the fingerprint by returning "false" from the hostVerifier.
Doing so causes an error (KEY_EXCHANGE_FAILED) that I would like to catch so that it doesn't propagate -- it's expected behavior in my testing environment.
But I am baffled as to how to catch this error, and am looking for ideas.