From fe8a98826c64507deccfff4aa27d0c62697dbdd6 Mon Sep 17 00:00:00 2001 From: wanderer Date: Sun, 17 Jan 2016 21:01:39 -0500 Subject: [PATCH 1/2] added test for recover that fails with elliptic --- test/recover.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/recover.js b/test/recover.js index 5eca6b9..999648b 100644 --- a/test/recover.js +++ b/test/recover.js @@ -111,5 +111,13 @@ module.exports = function (secp256k1, opts) { secp256k1.recoverSync(util.getMessage(), signature, 0) }).to.throw(Error, /signature/) }) + + it('Should throw error on invalid siganture', function () { + expect(function () { + var msgHash = new Buffer('fe7a79529ed5f7c3375d06b26b186a8644e0e16c373d7a12be41c62d6042b77a', 'hex') + var signature = new Buffer('98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a0000000000000000000000000000000000000000000000000000000000000000', 'hex') + secp256k1.recoverSync(msgHash, signature, 0) + }).to.throw(Error, /public/) + }) }) } From 58b9e7bff263dca67522764651461f208a6a33f0 Mon Sep 17 00:00:00 2001 From: wanderer Date: Sun, 17 Jan 2016 21:28:19 -0500 Subject: [PATCH 2/2] added fix for elliptic recovery bug --- lib/elliptic/recover.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/elliptic/recover.js b/lib/elliptic/recover.js index 2f4ab89..7d4a590 100644 --- a/lib/elliptic/recover.js +++ b/lib/elliptic/recover.js @@ -28,6 +28,10 @@ exports.recoverSync = function (msg, signature, recovery) { try { var sigObj = {r: signature.slice(0, 32), s: signature.slice(32, 64)} var pubKey = ec.recoverPubKey(msg, sigObj, recovery) + if (!ec.verify(msg, sigObj, pubKey)) { + throw new Error(messages.ECDSA_RECOVER_FAIL) + } + return new Buffer(pubKey.encodeCompressed()) } catch (err) { throw new Error(messages.ECDSA_RECOVER_FAIL)