From 8c4a46471706df2ce67022867166f76b53570da4 Mon Sep 17 00:00:00 2001 From: Christopher Hudel Date: Thu, 26 Oct 2017 16:15:49 -0400 Subject: [PATCH] Update jsOTP.js Fixes issue with counter values > 127. Changed to HEX format and simply used the counter in an 8-byte padded hex format. --- dist/jsOTP.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dist/jsOTP.js b/dist/jsOTP.js index be318d7..d46536f 100644 --- a/dist/jsOTP.js +++ b/dist/jsOTP.js @@ -78,7 +78,7 @@ throw "Error: invalid code length"; } } - + Hotp.prototype.uintToString = function(uintArray) { var decodedString, encodedString; encodedString = String.fromCharCode.apply(null, uintArray); @@ -88,9 +88,10 @@ Hotp.prototype.getOtp = function(key, counter) { var digest, h, offset, shaObj, v; - shaObj = new jsSHA("SHA-1", "TEXT"); + shaObj = new jsSHA("SHA-1", "HEX"); // was "TEXT" but this broke for counter > 127 shaObj.setHMACKey(key, "TEXT"); - shaObj.update(this.uintToString(new Uint8Array(this.intToBytes(counter)))); + counterString = ("0000000000000000" + counter.toString(16)).slice(-16); // padded hex counter value + shaObj.update(counterString); digest = shaObj.getHMAC("HEX"); h = this.hexToBytes(digest); offset = h[19] & 0xf;