telehash/telehash-js

endpoint generation failed [Error: EC_KEY_generate_key failed]

aleksen opened this issue · 9 comments

OS: Fedora 21 64bit
Node version: v0.10.33
Telehash version: 0.3.23

Happens when I attempt to:

var th = require("telehash");
th.generate(function(err, endpoint){
    if(err) return console.log("endpoint generation failed",err);
});

To help narrow this down, could you clone https://github.com/quartzjer/e3x-cs2a and do a npm test and see if it runs?

[aleksen@localhost e3x-cs2a]$ npm test

e3x-cs2a@0.0.5 test /home/aleksen/tmp/e3x-cs2a
make test

PURE=false ./node_modules/.bin/mocha --reporter list

․ cs2a should export an object: 1ms
․ cs2a should report id: 0ms
․ cs2a should grow a pair: 79ms
․ cs2a should load a pair: 5ms
․ cs2a should fail loading nothing: 0ms
․ cs2a should fail with bad data: 0ms
․ cs2a should local decrypt: 6ms
․ cs2a should load a remote: 3ms
․ cs2a should local encrypt: 8ms
․ cs2a should remote encrypt: 7ms

  1. cs2a should remote verify
    ․ cs2a should dynamically encrypt, decrypt, and verify: 15ms
  2. cs2a should load an ephemeral
  3. cs2a ephemeral local encrypt
    ․ cs2a ephemeral full: 16ms

12 passing (161ms)
3 failing

  1. cs2a should remote verify:
    Error: error:04098086:rsa routines:RSA_verify_PKCS1_PSS_mgf1:last octet invalid
    at Object.hashAndVerify (/home/aleksen/tmp/e3x-cs2a/node_modules/ursa/lib/ursa.js:305:24)
    at Object.id.verify (/home/aleksen/tmp/e3x-cs2a/node.js:48:17)
    at self.verify (/home/aleksen/tmp/e3x-cs2a/cs2a.js:118:18)
    at Context. (/home/aleksen/tmp/e3x-cs2a/test/cs2a.test.js:90:23)
    at callFn (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runnable.js:251:21)
    at Test.Runnable.run (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runnable.js:244:7)
    at Runner.runTest (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:374:10)
    at /home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:452:12
    at next (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:299:14)
    at /home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:309:7
    at next (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:248:23)
    at Object._onImmediate (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:276:5)
    at processImmediate as _immediateCallback

  2. cs2a should load an ephemeral:
    Error: error:04098086:rsa routines:RSA_verify_PKCS1_PSS_mgf1:last octet invalid
    at Object.hashAndVerify (/home/aleksen/tmp/e3x-cs2a/node_modules/ursa/lib/ursa.js:305:24)
    at Object.id.verify (/home/aleksen/tmp/e3x-cs2a/node.js:48:17)
    at self.verify (/home/aleksen/tmp/e3x-cs2a/cs2a.js:118:18)
    at Context. (/home/aleksen/tmp/e3x-cs2a/test/cs2a.test.js:115:19)
    at callFn (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runnable.js:251:21)
    at Test.Runnable.run (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runnable.js:244:7)
    at Runner.runTest (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:374:10)
    at /home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:452:12
    at next (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:299:14)
    at /home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:309:7
    at next (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:248:23)
    at Object._onImmediate (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:276:5)
    at processImmediate as _immediateCallback

  3. cs2a ephemeral local encrypt:
    Error: error:04098086:rsa routines:RSA_verify_PKCS1_PSS_mgf1:last octet invalid
    at Object.hashAndVerify (/home/aleksen/tmp/e3x-cs2a/node_modules/ursa/lib/ursa.js:305:24)
    at Object.id.verify (/home/aleksen/tmp/e3x-cs2a/node.js:48:17)
    at self.verify (/home/aleksen/tmp/e3x-cs2a/cs2a.js:118:18)
    at Context. (/home/aleksen/tmp/e3x-cs2a/test/cs2a.test.js:124:19)
    at callFn (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runnable.js:251:21)
    at Test.Runnable.run (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runnable.js:244:7)
    at Runner.runTest (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:374:10)
    at /home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:452:12
    at next (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:299:14)
    at /home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:309:7
    at next (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:248:23)
    at Object._onImmediate (/home/aleksen/tmp/e3x-cs2a/node_modules/mocha/lib/runner.js:276:5)
    at processImmediate as _immediateCallback

Makefile:2: recipe for target 'test' failed
make: *** [test] Error 3
npm ERR! weird error 2
npm ERR! not ok code 0

If you don't mind, would you try a few more things to help debug?

Do the tests pass when you run PURE=true ./node_modules/.bin/mocha --reporter list -t 30000 for cs2a?

Could you try same npm test on https://github.com/quartzjer/e3x-cs1a?

Also, is it possible you have an old openssl lib? What does openssl version show?

$ PURE=true ./node_modules/.bin/mocha --reporter list -t 30000

․ cs2a should export an object: 1ms
․ cs2a should report id: 1ms
․ cs2a should grow a pair: 6217ms
․ cs2a should load a pair: 3ms
․ cs2a should fail loading nothing: 0ms
․ cs2a should fail with bad data: 0ms
․ cs2a should local decrypt: 106ms
․ cs2a should load a remote: 63ms
․ cs2a should local encrypt: 133ms
․ cs2a should remote encrypt: 126ms
․ cs2a should remote verify: 137ms
․ cs2a should dynamically encrypt, decrypt, and verify: 382ms
․ cs2a should load an ephemeral: 155ms
․ cs2a ephemeral local encrypt: 156ms
․ cs2a ephemeral full: 512ms

15 passing (8s)

$ npm test

e3x-cs1a@0.0.16 test /home/aleksen/tmp/e3x-cs1a
make test

PURE=false ./node_modules/.bin/mocha --reporter list

․ cs1a should export an object: 0ms
․ cs1a should report id: 0ms

  1. cs1a should grow a pair
  2. cs1a should load a pair
    ․ cs1a should fail loading nothing: 0ms
    ․ cs1a should fail with bad data: 0ms
  3. cs1a should local decrypt
  4. cs1a should load a remote
  5. cs1a should local encrypt
  6. cs1a should remote encrypt
  7. cs1a should remote verify
  8. cs1a should dynamically encrypt, decrypt, and verify
    ․ cs1a should load an ephemeral: 0ms
  9. cs1a ephemeral local encrypt
  10. cs1a ephemeral full

5 passing (14ms)
10 failing

  1. cs1a should grow a pair:
    AssertionError: expected [Error: EC_KEY_generate_key failed] to not exist

  2. cs1a should load a pair:
    AssertionError: expected [Error: o2i_ECPublicKey failed, Invalid public key] to not exist

  3. cs1a should local decrypt:

  AssertionError: expected false to equal true
  + expected - actual

  +true
  -false

  at Context.<anonymous> (/home/aleksen/tmp/e3x-cs1a/test/cs1a.test.js:55:42)
  at callFn (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:251:21)
  at Test.Runnable.run (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:244:7)
  at Runner.runTest (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:374:10)
  at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:452:12
  at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:299:14)
  at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:309:7
  at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:248:23)
  at Object._onImmediate (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:276:5)
  at processImmediate [as _immediateCallback] (timers.js:345:15)
  1. cs1a should load a remote:
    TypeError: Cannot read property 'length' of undefined
    at Context. (/home/aleksen/tmp/e3x-cs1a/test/cs1a.test.js:64:24)
    at callFn (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:251:21)
    at Test.Runnable.run (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:244:7)
    at Runner.runTest (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:374:10)
    at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:452:12
    at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:299:14)
    at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:309:7
    at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:248:23)
    at Object._onImmediate (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:276:5)
    at processImmediate as _immediateCallback

  2. cs1a should local encrypt:

  AssertionError: expected false to equal true
  + expected - actual

  +true
  -false

  at Context.<anonymous> (/home/aleksen/tmp/e3x-cs1a/test/cs1a.test.js:71:44)
  at callFn (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:251:21)
  at Test.Runnable.run (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:244:7)
  at Runner.runTest (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:374:10)
  at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:452:12
  at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:299:14)
  at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:309:7
  at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:248:23)
  at Object._onImmediate (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:276:5)
  at processImmediate [as _immediateCallback] (timers.js:345:15)
  1. cs1a should remote encrypt:
  AssertionError: expected false to equal true
  + expected - actual

  +true
  -false

  at Context.<anonymous> (/home/aleksen/tmp/e3x-cs1a/test/cs1a.test.js:80:44)
  at callFn (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:251:21)
  at Test.Runnable.run (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:244:7)
  at Runner.runTest (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:374:10)
  at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:452:12
  at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:299:14)
  at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:309:7
  at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:248:23)
  at Object._onImmediate (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:276:5)
  at processImmediate [as _immediateCallback] (timers.js:345:15)
  1. cs1a should remote verify:
    TypeError: Cannot call method 'deriveSharedSecret' of undefined
    at self.verify (/home/aleksen/tmp/e3x-cs1a/cs1a.js:83:31)
    at Context. (/home/aleksen/tmp/e3x-cs1a/test/cs1a.test.js:88:23)
    at callFn (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:251:21)
    at Test.Runnable.run (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:244:7)
    at Runner.runTest (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:374:10)
    at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:452:12
    at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:299:14)
    at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:309:7
    at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:248:23)
    at Object._onImmediate (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:276:5)
    at processImmediate as _immediateCallback

  2. cs1a should dynamically encrypt, decrypt, and verify:

  AssertionError: expected 'false' to equal '4242'
  + expected - actual

  +4242
  -false

  at Context.<anonymous> (/home/aleksen/tmp/e3x-cs1a/test/cs1a.test.js:101:56)
  at callFn (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:251:21)
  at Test.Runnable.run (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:244:7)
  at Runner.runTest (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:374:10)
  at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:452:12
  at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:299:14)
  at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:309:7
  at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:248:23)
  at Object._onImmediate (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:276:5)
  at processImmediate [as _immediateCallback] (timers.js:345:15)
  1. cs1a ephemeral local encrypt:
    Error: Must give cipher-type, key, and iv as argument
    at new Cipheriv (crypto.js:346:17)
    at Object.Cipheriv (crypto.js:344:12)
    at Object.aes (/home/aleksen/tmp/e3x-cs1a/node.js:17:26)
    at self.encrypt (/home/aleksen/tmp/e3x-cs1a/cs1a.js:184:24)
    at Context. (/home/aleksen/tmp/e3x-cs1a/test/cs1a.test.js:117:29)
    at callFn (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:251:21)
    at Test.Runnable.run (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:244:7)
    at Runner.runTest (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:374:10)
    at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:452:12
    at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:299:14)
    at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:309:7
    at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:248:23)
    at Object._onImmediate (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:276:5)
    at processImmediate as _immediateCallback

  2. cs1a ephemeral full:
    Error: Must give cipher-type, key, and iv as argument
    at new Cipheriv (crypto.js:346:17)
    at Object.Cipheriv (crypto.js:344:12)
    at Object.aes (/home/aleksen/tmp/e3x-cs1a/node.js:17:26)
    at self.encrypt (/home/aleksen/tmp/e3x-cs1a/cs1a.js:184:24)
    at Context. (/home/aleksen/tmp/e3x-cs1a/test/cs1a.test.js:136:33)
    at callFn (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:251:21)
    at Test.Runnable.run (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runnable.js:244:7)
    at Runner.runTest (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:374:10)
    at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:452:12
    at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:299:14)
    at /home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:309:7
    at next (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:248:23)
    at Object._onImmediate (/home/aleksen/tmp/e3x-cs1a/node_modules/mocha/lib/runner.js:276:5)
    at processImmediate as _immediateCallback

Makefile:2: recipe for target 'test' failed
make: *** [test] Error 10
npm ERR! weird error 2
npm ERR! not ok code 0

Could you try e3x-cs1a again now, and telehash-js if that works? I added another validation check to fall-back if the compiled ecc doesn't work.

My guess is that your openssl is erroring but I'm not sure why, does your openssl ecparam -list_curves show secp160r1?

Hi again!

I forgot to include openssl version in the previous comments. Here we are:

$ openssl version
OpenSSL 1.0.1k-fips 8 Jan 2015

Seems like secp160r1 is missing:

$ openssl ecparam -list_curves
secp384r1 : NIST/SECG curve over a 384 bit prime field
secp521r1 : NIST/SECG curve over a 521 bit prime field
prime256v1: X9.62/SECG curve over a 256 bit prime field

And finally the test:
$ npm test

e3x-cs1a@0.0.17 test /home/aleksen/tmp/e3x-cs1a
make test

PURE=false ./node_modules/.bin/mocha --reporter list

․ cs1a should export an object: 0ms
․ cs1a should report id: 0ms
․ cs1a should grow a pair: 34ms
․ cs1a should load a pair: 2ms
․ cs1a should fail loading nothing: 0ms

  1. cs1a should fail with bad data
    ․ cs1a should local decrypt: 21ms
    ․ cs1a should load a remote: 17ms
    ․ cs1a should local encrypt: 38ms
    ․ cs1a should remote encrypt: 29ms
    ․ cs1a should remote verify: 17ms
    ․ cs1a should dynamically encrypt, decrypt, and verify: 62ms
    ․ cs1a should load an ephemeral: 23ms
    ․ cs1a ephemeral local encrypt: 20ms
    ․ cs1a ephemeral full: 70ms

14 passing (346ms)
1 failing

  1. cs1a should fail with bad data:
    AssertionError: expected undefined to exist

Makefile:2: recipe for target 'test' failed
make: *** [test] Error 1
npm ERR! weird error 2
npm ERR! not ok code 0

Ok, it's fine if an openssl build doesn't support it because there is a pure-javascript fallback in those cases, openssl is just faster when available.

I think I fixed the bad test so try cs1a again, and I think telehash-js should work now unless there's issues somewhere else yet, thank you!

Works! Thanks!