Skip to content

Commit

Permalink
Re-enable node 0.8 support, without ED25519
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Wilson committed Nov 10, 2015
1 parent b07d85a commit 3b00544
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
10 changes: 8 additions & 2 deletions lib/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ var DiffieHellman = require('./dhe');
var errs = require('./errors');
var utils = require('./utils');
var PrivateKey = require('./private-key');
var edCompat = require('./ed-compat');
var edCompat;

try {
edCompat = require('./ed-compat');
} catch (e) {
/* Just continue through, and bail out if we try to use it. */
}

var InvalidAlgorithmError = errs.InvalidAlgorithmError;
var KeyParseError = errs.KeyParseError;
Expand Down Expand Up @@ -144,7 +150,7 @@ Key.prototype.createVerify = function (hashAlgo) {
assert.string(hashAlgo, 'hash algorithm');

/* ED25519 is not supported by OpenSSL, use a javascript impl. */
if (this.type === 'ed25519')
if (this.type === 'ed25519' && edCompat !== undefined)
return (new edCompat.Verifier(this, hashAlgo));
if (this.type === 'curve25519')
throw (new Error('Curve25519 keys are not suitable for ' +
Expand Down
10 changes: 8 additions & 2 deletions lib/private-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ var Signature = require('./signature');
var errs = require('./errors');
var util = require('util');
var utils = require('./utils');
var edCompat = require('./ed-compat');
var edCompat;
var ed;

try {
edCompat = require('./ed-compat');
} catch (e) {
/* Just continue through, and bail out if we try to use it. */
}

var Key = require('./key');

var InvalidAlgorithmError = errs.InvalidAlgorithmError;
Expand Down Expand Up @@ -132,7 +138,7 @@ PrivateKey.prototype.createSign = function (hashAlgo) {
assert.string(hashAlgo, 'hash algorithm');

/* ED25519 is not supported by OpenSSL, use a javascript impl. */
if (this.type === 'ed25519')
if (this.type === 'ed25519' && edCompat !== undefined)
return (new edCompat.Signer(this, hashAlgo));
if (this.type === 'curve25519')
throw (new Error('Curve25519 keys are not suitable for ' +
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sshpk",
"version": "1.6.1",
"version": "1.6.2",
"description": "A library for finding and using SSH public keys",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -30,7 +30,7 @@
"url": "https://github.com/arekinath/node-sshpk/issues"
},
"engines": {
"node": ">=0.10.0"
"node": ">=0.8.0"
},
"directories": {
"bin": "./bin",
Expand Down
7 changes: 5 additions & 2 deletions test/dhe.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ var ED_KEY, ED2_KEY, EC_KEY, EC2_KEY, ECOUT_KEY, DS_KEY, DS2_KEY, DSOUT_KEY;
var C_KEY, C2_KEY;
var C_SSH;

/* node 0.8 and earlier do not support key derivation properly */
if (process.version.match(/^v0\.[0-9]\./))
return;

test('setup', function (t) {
var k = fs.readFileSync(path.join(__dirname, 'id_ed25519'));
ED_KEY = sshpk.parsePrivateKey(k);
Expand Down Expand Up @@ -139,8 +143,7 @@ test('ecdhe reject diff curves', function (t) {
});

/* node 0.10 and earlier do not support DHE properly */
if (process.version.match(/^v0\.10\./) ||
process.version.match(/^v0\.[0-9]\./))
if (process.version.match(/^v0\.10\./))
return;

test('dhe shared secret', function (t) {
Expand Down
3 changes: 3 additions & 0 deletions test/private-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ test('PrivateKey#createSign on ECDSA 256 key', function (t) {
t.end();
});

if (process.version.match(/^v0\.[0-9]\./))
return;

test('PrivateKey#createSign on ED25519 key', function (t) {
var s = KEY_ED25519.createSign('sha512');
s.write('foobar');
Expand Down
35 changes: 19 additions & 16 deletions test/signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,6 @@ test('parse RSA sig in full wire SSH format and verify', function(t) {
t.end();
});

test('parse ED25519 sig in full wire SSH format and verify', function(t) {
var sig = sshpk.parseSignature(ED25519_SIG_SSH, 'ed25519', 'ssh');
var s = ED25519_KEY.createVerify();
s.update('foobar');
t.ok(s.verify(sig));
t.end();
});

test('sign with ED25519 key and convert to SSH format', function(t) {
var s = ED25519_KEY.createSign();
s.update('foobar');
var sig = s.sign();
t.strictEqual(sig.toString('ssh'), ED25519_SIG_SSH);
t.end();
});

test('convert DSA sig to SSH format and back', function(t) {
var sig = sshpk.parseSignature(DSA_SIG_ASN1, 'dsa', 'asn1');
t.strictEqual(sig.toString('asn1'), DSA_SIG_ASN1);
Expand Down Expand Up @@ -157,3 +141,22 @@ test('convert full wire SSH ECDSA-384 sig and verify', function(t) {
t.ok(s.verify(sig));
t.end();
});

if (process.version.match(/^v0\.[0-9]\./))
return;

test('parse ED25519 sig in full wire SSH format and verify', function(t) {
var sig = sshpk.parseSignature(ED25519_SIG_SSH, 'ed25519', 'ssh');
var s = ED25519_KEY.createVerify();
s.update('foobar');
t.ok(s.verify(sig));
t.end();
});

test('sign with ED25519 key and convert to SSH format', function(t) {
var s = ED25519_KEY.createSign();
s.update('foobar');
var sig = s.sign();
t.strictEqual(sig.toString('ssh'), ED25519_SIG_SSH);
t.end();
});

0 comments on commit 3b00544

Please sign in to comment.