Skip to content

Commit

Permalink
lib: add ed25519 key support
Browse files Browse the repository at this point in the history
  • Loading branch information
mscdex committed Apr 2, 2019
1 parent 3b3a7a7 commit e40ca05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var SFTPStream = ssh2_streams.SFTPStream;
var consts = ssh2_streams.constants;
var BUGS = consts.BUGS;
var ALGORITHMS = consts.ALGORITHMS;
var EDDSA_SUPPORTED = consts.EDDSA_SUPPORTED;
var parseKey = ssh2_streams.utils.parseKey;

var Channel = require('./Channel');
Expand Down Expand Up @@ -522,6 +523,7 @@ Client.prototype.connect = function(cfg) {
var pubKeyFullType = agentKey.toString('ascii', 4, 4 + keyLen);
var pubKeyType = pubKeyFullType.slice(4);
// Check that we support the key type first
// TODO: move key type checking logic to ssh2-streams
switch (pubKeyFullType) {
case 'ssh-rsa':
case 'ssh-dss':
Expand All @@ -530,6 +532,8 @@ Client.prototype.connect = function(cfg) {
case 'ecdsa-sha2-nistp521':
break;
default:
if (EDDSA_SUPPORTED && pubKeyFullType === 'ssh-ed25519')
break;
debug('DEBUG: Agent: Skipping unsupported key type: '
+ pubKeyFullType);
return tryNextAgentKey();
Expand Down
12 changes: 11 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function Server(cfg, listener) {
var hostKeys = {
'ssh-rsa': null,
'ssh-dss': null,
'ssh-ed25519': null,
'ecdsa-sha2-nistp256': null,
'ecdsa-sha2-nistp384': null,
'ecdsa-sha2-nistp521': null
Expand Down Expand Up @@ -992,11 +993,15 @@ function PKAuthContext(stream, username, service, method, pkInfo, cb) {
this.signature = pkInfo.signature;
var sigAlgo;
if (this.signature) {
// TODO: move key type checking logic to ssh2-streams
switch (pkInfo.keyAlgo) {
case 'ssh-rsa':
case 'ssh-dss':
sigAlgo = 'sha1';
break;
case 'ssh-ed25519':
sigAlgo = null;
break;
case 'ecdsa-sha2-nistp256':
sigAlgo = 'sha256';
break;
Expand All @@ -1016,8 +1021,9 @@ PKAuthContext.prototype.accept = function() {
if (!this.signature) {
this._initialResponse = true;
this._stream.authPKOK(this.key.algo, this.key.data);
} else
} else {
AuthContext.prototype.accept.call(this);
}
};

function HostbasedAuthContext(stream, username, service, method, pkInfo, cb) {
Expand All @@ -1027,11 +1033,15 @@ function HostbasedAuthContext(stream, username, service, method, pkInfo, cb) {
this.signature = pkInfo.signature;
var sigAlgo;
if (this.signature) {
// TODO: move key type checking logic to ssh2-streams
switch (pkInfo.keyAlgo) {
case 'ssh-rsa':
case 'ssh-dss':
sigAlgo = 'sha1';
break;
case 'ssh-ed25519':
sigAlgo = null;
break;
case 'ecdsa-sha2-nistp256':
sigAlgo = 'sha256';
break;
Expand Down

0 comments on commit e40ca05

Please sign in to comment.