Fixed issue causing negative counter values to be rejected
This commit is contained in:
parent
b889c99a1e
commit
13865d89d5
2
index.js
2
index.js
@ -82,7 +82,7 @@ hotp.verify = function(token, key, opt) {
|
|||||||
|
|
||||||
// Now loop through from C to C + W to determine if there is
|
// Now loop through from C to C + W to determine if there is
|
||||||
// a correct code
|
// a correct code
|
||||||
for(var i = counter; i <= counter + window; ++i) {
|
for(var i = counter - window; i <= counter + window; ++i) {
|
||||||
opt.counter = i;
|
opt.counter = i;
|
||||||
if(this.gen(key, opt) === token) {
|
if(this.gen(key, opt) === token) {
|
||||||
// We have found a matching code, trigger callback
|
// We have found a matching code, trigger callback
|
||||||
|
@ -132,6 +132,12 @@ exports.testHOTPOutOfSync = function(beforeExit, assert) {
|
|||||||
// counterheck that the test should pass for window >= 9
|
// counterheck that the test should pass for window >= 9
|
||||||
opt.window = 8;
|
opt.window = 8;
|
||||||
assert.ok(notp.hotp.verify(token, key, opt), 'Should pass for value of window >= 9');
|
assert.ok(notp.hotp.verify(token, key, opt), 'Should pass for value of window >= 9');
|
||||||
|
|
||||||
|
// counterheck that test should pass for negative counter values
|
||||||
|
token = '755224';
|
||||||
|
opt.counter = 7
|
||||||
|
opt.window = 8;
|
||||||
|
assert.ok(notp.hotp.verify(token, key, opt), 'Should pass for negative counter values');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user