From 61581d1af753446380ad8c2d735867b844e2109f Mon Sep 17 00:00:00 2001 From: Herrie Date: Wed, 17 Mar 2021 11:13:39 +0100 Subject: [PATCH 1/2] Cryto.js: Nasty workaround for incorrect signature (257 vs 256) and hex key length (514 vs 512) For some unknown reason, the signature gets a length of 257 bytes instead of 256 bytes, and the length of the hex value is 514 bytes instead of 512 bytes. This works around it, until a proper fix is implemented. The bug seems to be caused by https://github.com/node-ebics/node-ebics-client/blob/master/lib/crypto/Crypto.js#L71 somehow. Signed-off-by: Herman van Hazendonk --- lib/crypto/Crypto.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/crypto/Crypto.js b/lib/crypto/Crypto.js index 445088c..a2032b5 100644 --- a/lib/crypto/Crypto.js +++ b/lib/crypto/Crypto.js @@ -72,7 +72,19 @@ module.exports = class Crypto { const power = new BigNumber(key.d()); const mod = new BigNumber(key.n()); - return (modPow(base, power, mod)).toBEBuffer().toString('base64'); + //Somehow sometimes we have a 514 byte hex key that starts with "00". In that case use only the last 512 bytes + var hexString = modPow(base, power, mod).toBEBuffer().toString('hex'); + if(hexString.substr(0,2) === "00" && hexString.length == 514) + { + console.log("hex string of key starts with \"00\" and is 514 bytes long, fixing it to be 512 bytes long by stripping leading \"00\""); + hexString = hexString.substr(2); + var base64String = Buffer.from(hexString, 'hex').toString('base64') + return base64String; + } + else + { + return (modPow(base, power, mod)).toBEBuffer().toString('base64'); + } } static pad(d) { From 500737dbc75bbe717da57c97d9c1a8fc125fbc0f Mon Sep 17 00:00:00 2001 From: Herman van Hazendonk Date: Mon, 29 Mar 2021 09:12:23 +0200 Subject: [PATCH 2/2] Remove not needed else statement Cleanup as per comment --- lib/crypto/Crypto.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/crypto/Crypto.js b/lib/crypto/Crypto.js index a2032b5..4d53560 100644 --- a/lib/crypto/Crypto.js +++ b/lib/crypto/Crypto.js @@ -78,13 +78,8 @@ module.exports = class Crypto { { console.log("hex string of key starts with \"00\" and is 514 bytes long, fixing it to be 512 bytes long by stripping leading \"00\""); hexString = hexString.substr(2); - var base64String = Buffer.from(hexString, 'hex').toString('base64') - return base64String; - } - else - { - return (modPow(base, power, mod)).toBEBuffer().toString('base64'); } + return Buffer.from(hexString, 'hex').toString('base64'); } static pad(d) {