diff --git a/lib/key.js b/lib/key.js index 78f194a..5545a8f 100644 --- a/lib/key.js +++ b/lib/key.js @@ -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; @@ -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 ' + diff --git a/lib/private-key.js b/lib/private-key.js index 13b62ce..dc3bc10 100644 --- a/lib/private-key.js +++ b/lib/private-key.js @@ -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; @@ -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 ' + diff --git a/package.json b/package.json index 79b8073..dd4406f 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -30,7 +30,7 @@ "url": "https://github.com/arekinath/node-sshpk/issues" }, "engines": { - "node": ">=0.10.0" + "node": ">=0.8.0" }, "directories": { "bin": "./bin", diff --git a/test/dhe.js b/test/dhe.js index c73fb6e..1c2cb71 100644 --- a/test/dhe.js +++ b/test/dhe.js @@ -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); @@ -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) { diff --git a/test/private-key.js b/test/private-key.js index ce3b666..0b1a754 100644 --- a/test/private-key.js +++ b/test/private-key.js @@ -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'); diff --git a/test/signature.js b/test/signature.js index a2d4847..0a96f54 100644 --- a/test/signature.js +++ b/test/signature.js @@ -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); @@ -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(); +});