Skip to content

Commit

Permalink
[change] Reversed changes to make verifyDelta throw when non-matching…
Browse files Browse the repository at this point in the history
… digits
  • Loading branch information
markbao committed Jan 27, 2016
1 parent a99bc50 commit fe554c5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 52 deletions.
25 changes: 0 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,6 @@ it at counter position 7, it will return `{ delta: 2 }`.

**Kind**: function

**Throws**: Error if a given token is not a number, or if the number of digits
in a token does not match the number of digits specified (i.e. if digits
is not specified and the token is not 6 digits, or if digits is specified
and the token digits does not equal the specified digits.)

**Returns**: <code>Object</code> - On success, returns an object with the counter
difference between the client and the server as the `delta` property (i.e.
`{ delta: 0 }`).
Expand All @@ -493,11 +488,6 @@ hotp.verifyDelta.

**Kind**: function

**Throws**: Error if a given token is not a number, or if the number of digits
in a token does not match the number of digits specified (i.e. if digits
is not specified and the token is not 6 digits, or if digits is specified
and the token digits does not equal the specified digits.)

**Returns**: <code>Boolean</code> - Returns true if the token matches within the given
window, false otherwise.

Expand Down Expand Up @@ -557,11 +547,6 @@ If it finds it at counter position 1002, it will return `{ delta: 2 }`.

**Kind**: function

**Throws**: Error if a given token is not a number, or if the number of digits
in a token does not match the number of digits specified (i.e. if digits
is not specified and the token is not 6 digits, or if digits is specified
and the token digits does not equal the specified digits.)

**Returns**: <code>Object</code> - On success, returns an object with the time step
difference between the client and the server as the `delta` property (e.g.
`{ delta: 0 }`).
Expand All @@ -588,11 +573,6 @@ an object. For more on how to use a window with this, see totp.verifyDelta.

**Kind**: function

**Throws**: Error if a given token is not a number, or if the number of digits
in a token does not match the number of digits specified (i.e. if digits
is not specified and the token is not 6 digits, or if digits is specified
and the token digits does not equal the specified digits.)

**Returns**: <code>Boolean</code> - Returns true if the token matches within the given
window, false otherwise.

Expand Down Expand Up @@ -659,11 +639,6 @@ the app.
To generate a suitable QR Code, pass the generated URL to a QR Code
generator, such as the `qr-image` module.

Throws an error if secret or label is missing, or if hotp is used and a
counter is missing, if the type is not one of `hotp` or `totp`, if the
algorithm is not one of the supported SHA1, SHA256, or SHA512, if the
URL is called with an invalid number of digits, or an invalid period.

**Kind**: function

**Throws**: Error if secret or label is missing, or if hotp is used and a
Expand Down
24 changes: 2 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ exports.counter = exports.hotp;
* @return {Object} On success, returns an object with the counter
* difference between the client and the server as the `delta` property (i.e.
* `{ delta: 0 }`).
* @throws Error if a given token is not a number, or if the number of digits
* in a token does not match the number of digits specified (i.e. if digits
* is not specified and the token is not 6 digits, or if digits is specified
* and the token digits does not equal the specified digits.)
* @method hotp․verifyDelta
* @global
*/
Expand All @@ -165,15 +161,15 @@ exports.hotp.verifyDelta = function hotpVerifyDelta (options) {

// fail if token is not of correct length
if (token.length !== digits) {
throw new Error('Speakeasy - Verify - Number of digits in token does not match digits specified (default 6)');
return;
}

// parse token to integer
token = parseInt(token, 10);

// fail if token is NA
if (isNaN(token)) {
throw new Error('Speakeasy - Verify - Given token is not a number');
return;
}

// loop from C to C + W inclusive
Expand Down Expand Up @@ -212,10 +208,6 @@ exports.hotp.verifyDelta = function hotpVerifyDelta (options) {
* sha512).
* @return {Boolean} Returns true if the token matches within the given
* window, false otherwise.
* @throws Error if a given token is not a number, or if the number of digits
* in a token does not match the number of digits specified (i.e. if digits
* is not specified and the token is not 6 digits, or if digits is specified
* and the token digits does not equal the specified digits.)
* @method hotp․verify
* @global
*/
Expand Down Expand Up @@ -333,10 +325,6 @@ exports.time = exports.totp;
* @return {Object} On success, returns an object with the time step
* difference between the client and the server as the `delta` property (e.g.
* `{ delta: 0 }`).
* @throws Error if a given token is not a number, or if the number of digits
* in a token does not match the number of digits specified (i.e. if digits
* is not specified and the token is not 6 digits, or if digits is specified
* and the token digits does not equal the specified digits.)
* @method totp․verifyDelta
* @global
*/
Expand Down Expand Up @@ -394,10 +382,6 @@ exports.totp.verifyDelta = function totpVerifyDelta (options) {
* sha512).
* @return {Boolean} Returns true if the token matches within the given
* window, false otherwise.
* @throws Error if a given token is not a number, or if the number of digits
* in a token does not match the number of digits specified (i.e. if digits
* is not specified and the token is not 6 digits, or if digits is specified
* and the token digits does not equal the specified digits.)
* @method totp․verify
* @global
*/
Expand Down Expand Up @@ -554,10 +538,6 @@ exports.generate_key_ascii = util.deprecate(function (length, symbols) {
* @param {String} [options.encoding] Key encoding (ascii, hex, base32,
* base64). If the key is not encoded in Base-32, it will be reencoded.
* @return {String} A URL suitable for use with the Google Authenticator.
* @throws Error if secret or label is missing, or if hotp is used and a
* counter is missing, if the type is not one of `hotp` or `totp`, if the
* algorithm is not one of the supported SHA1, SHA256, or SHA512, if the
* URL is called with an invalid number of digits, or an invalid period.
* @see https://github.com/google/google-authenticator/wiki/Key-Uri-Format
*/

Expand Down
10 changes: 5 additions & 5 deletions test/notp_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ it('HOTP', function () {

// make sure we can not pass in opt
options.token = 'WILL NOT PASS';
assert.throws(function () { speakeasy.hotp.verify(options); }, /Number of digits in token does not match digits specified/, 'Should error');
speakeasy.hotp.verify(options);

// check for invalid token value in verifyDelta
options.token = 'NOPASS';
assert.throws(function () { speakeasy.hotp.verifyDelta(options); }, /Given token is not a number/, 'Should not pass');
assert.ok(!speakeasy.hotp.verifyDelta(options), 'Should not pass');

// countercheck for failure
options.counter = 0;
assert.throws(function () { speakeasy.hotp.verify(options); }, /Given token is not a number/, 'Should not pass');
assert.ok(!speakeasy.hotp.verify(options), 'Should not pass');

// countercheck for passes
for (var i = 0; i < HOTP.length; i++) {
Expand Down Expand Up @@ -102,12 +102,12 @@ it('TOTtoken', function () {
// countercheck for failure
options.time = 0;
options.token = 'windowILLNOTtokenASS';
assert.throws(function () { speakeasy.totp.verify(options); }, /Number of digits in token does not match digits specified/, 'Should not pass');
assert.ok(!speakeasy.totp.verify(options), 'Should not pass');

// countercheck for failure
options.time = 0;
options.token = 'windowILLNOTtokenASS';
assert.throws(function () { speakeasy.totp.verify(options); }, /Number of digits in token does not match digits specified/, 'Should not pass');
assert.ok(!speakeasy.totp.verifyDelta(options), 'Should not pass');

// countercheck for test vector at 59s with verifyDelta
options.time = 59;
Expand Down

1 comment on commit fe554c5

@markbao
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed my mind. Doesn't make sense to throw.

Please sign in to comment.