Skip to content

Commit e40ca05

Browse files
committed
lib: add ed25519 key support
1 parent 3b3a7a7 commit e40ca05

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/client.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var SFTPStream = ssh2_streams.SFTPStream;
1111
var consts = ssh2_streams.constants;
1212
var BUGS = consts.BUGS;
1313
var ALGORITHMS = consts.ALGORITHMS;
14+
var EDDSA_SUPPORTED = consts.EDDSA_SUPPORTED;
1415
var parseKey = ssh2_streams.utils.parseKey;
1516

1617
var Channel = require('./Channel');
@@ -522,6 +523,7 @@ Client.prototype.connect = function(cfg) {
522523
var pubKeyFullType = agentKey.toString('ascii', 4, 4 + keyLen);
523524
var pubKeyType = pubKeyFullType.slice(4);
524525
// Check that we support the key type first
526+
// TODO: move key type checking logic to ssh2-streams
525527
switch (pubKeyFullType) {
526528
case 'ssh-rsa':
527529
case 'ssh-dss':
@@ -530,6 +532,8 @@ Client.prototype.connect = function(cfg) {
530532
case 'ecdsa-sha2-nistp521':
531533
break;
532534
default:
535+
if (EDDSA_SUPPORTED && pubKeyFullType === 'ssh-ed25519')
536+
break;
533537
debug('DEBUG: Agent: Skipping unsupported key type: '
534538
+ pubKeyFullType);
535539
return tryNextAgentKey();

lib/server.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function Server(cfg, listener) {
2828
var hostKeys = {
2929
'ssh-rsa': null,
3030
'ssh-dss': null,
31+
'ssh-ed25519': null,
3132
'ecdsa-sha2-nistp256': null,
3233
'ecdsa-sha2-nistp384': null,
3334
'ecdsa-sha2-nistp521': null
@@ -992,11 +993,15 @@ function PKAuthContext(stream, username, service, method, pkInfo, cb) {
992993
this.signature = pkInfo.signature;
993994
var sigAlgo;
994995
if (this.signature) {
996+
// TODO: move key type checking logic to ssh2-streams
995997
switch (pkInfo.keyAlgo) {
996998
case 'ssh-rsa':
997999
case 'ssh-dss':
9981000
sigAlgo = 'sha1';
9991001
break;
1002+
case 'ssh-ed25519':
1003+
sigAlgo = null;
1004+
break;
10001005
case 'ecdsa-sha2-nistp256':
10011006
sigAlgo = 'sha256';
10021007
break;
@@ -1016,8 +1021,9 @@ PKAuthContext.prototype.accept = function() {
10161021
if (!this.signature) {
10171022
this._initialResponse = true;
10181023
this._stream.authPKOK(this.key.algo, this.key.data);
1019-
} else
1024+
} else {
10201025
AuthContext.prototype.accept.call(this);
1026+
}
10211027
};
10221028

10231029
function HostbasedAuthContext(stream, username, service, method, pkInfo, cb) {
@@ -1027,11 +1033,15 @@ function HostbasedAuthContext(stream, username, service, method, pkInfo, cb) {
10271033
this.signature = pkInfo.signature;
10281034
var sigAlgo;
10291035
if (this.signature) {
1036+
// TODO: move key type checking logic to ssh2-streams
10301037
switch (pkInfo.keyAlgo) {
10311038
case 'ssh-rsa':
10321039
case 'ssh-dss':
10331040
sigAlgo = 'sha1';
10341041
break;
1042+
case 'ssh-ed25519':
1043+
sigAlgo = null;
1044+
break;
10351045
case 'ecdsa-sha2-nistp256':
10361046
sigAlgo = 'sha256';
10371047
break;

0 commit comments

Comments
 (0)