rotp 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a9c9c9d92e7df6e74c912f064f44aed0a2c6345
4
- data.tar.gz: 664591b20546f52e2f216759bd0a0516ca1c6be8
3
+ metadata.gz: 2f0dbf99a0880ce75c5936772e82623ca5c83d94
4
+ data.tar.gz: caaae71f337eb86af23afd0ffc38a5f318121e5d
5
5
  SHA512:
6
- metadata.gz: 72190c4a66d89ea2220550701fb2f7bb6b932ca93603cadad1b054b07e3e135cd752d61a87c78a87e59e71cea5cb89cae02784d508b8c51ba65797150e6d2421
7
- data.tar.gz: 6d1a508e6379354f303338c7b42a393522602128c354fe2808ebe0b397a348588365921d48bf145ad6faed795b9428a48374aeddcfc3f9dc529855b84b2948ca
6
+ metadata.gz: 0df2b27a1a0a078a3458746eaeacf5b1461858b26fb74a5774fa441e9897546dbc2ce3767854812613a69d520c64c9a04a4c5f62a6f91e885b02ff0c27c4f2a9
7
+ data.tar.gz: fed6bf9cdb5c28d8e1acdd7e39ba7211e8fe943530f589e0739e4b446973236d892aede78144f4a54c467179329f5ad9a5c576901e63b63230f0d51b8e5a2175
data/README.markdown CHANGED
@@ -92,6 +92,11 @@ Now run the following and compare the output
92
92
 
93
93
  ### Changelog
94
94
 
95
+ #### 1.6.0
96
+
97
+ - Add verify_with_retries to HOTP
98
+ - Fix 'cgi' require and global DEFAULT_INTERVAL
99
+
95
100
  #### 1.5.0
96
101
 
97
102
  - Add support for "issuer" parameter on provisioning url
data/lib/rotp/hotp.rb CHANGED
@@ -15,6 +15,22 @@ module ROTP
15
15
  super(otp, self.at(counter))
16
16
  end
17
17
 
18
+ # Verifies the OTP passed in against the current time OTP, with a given number of retries.
19
+ # Returns the counter that was verified successfully
20
+ # @param [String/Integer] otp the OTP to check against
21
+ # @param [Integer] initial counter the counter of the OTP
22
+ # @param [Integer] number of retries
23
+ def verify_with_retries(otp, initial_count, retries = 1)
24
+ return false if retries <= 0
25
+
26
+ 1.upto(retries) do |counter|
27
+ current_counter = initial_count + counter
28
+ return current_counter if verify(otp, current_counter)
29
+ end
30
+
31
+ false
32
+ end
33
+
18
34
  # Returns the provisioning URI for the OTP
19
35
  # This can then be encoded in a QR Code and used
20
36
  # to provision the Google Authenticator app
data/lib/rotp/totp.rb CHANGED
@@ -1,6 +1,5 @@
1
- DEFAULT_INTERVAL = 30
2
-
3
1
  module ROTP
2
+ DEFAULT_INTERVAL = 30
4
3
  class TOTP < OTP
5
4
 
6
5
  attr_reader :interval, :issuer
data/lib/rotp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ROTP
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.0"
3
3
  end
data/lib/rotp.rb CHANGED
@@ -1,9 +1,11 @@
1
+ require 'cgi'
2
+ require 'uri'
3
+ require 'openssl'
1
4
  require 'rotp/base32'
2
5
  require 'rotp/otp'
3
6
  require 'rotp/hotp'
4
7
  require 'rotp/totp'
5
- require 'uri'
6
- require 'openssl'
8
+
7
9
 
8
10
  module ROTP
9
11
  end
data/spec/hotp_spec.rb CHANGED
@@ -24,6 +24,20 @@ describe ROTP::HOTP do
24
24
  params["secret"].first.should == "a" * 32
25
25
  end
26
26
 
27
+ context "with retries" do
28
+ it "should verify that retry is a valid number" do
29
+ subject.verify_with_retries(161024, @counter, -1).should be_false
30
+ subject.verify_with_retries(161024, @counter, 0).should be_false
31
+ end
32
+
33
+ it "should verify up to the total number of retries and return the counter" do
34
+ subject.verify_with_retries(161024, @counter - 10, 10).should == @counter
35
+ end
36
+
37
+ it "should verify that retry is a valid number" do
38
+ subject.verify_with_retries(161024, @counter - 20, 10).should be_false
39
+ end
40
+ end
27
41
  end
28
42
 
29
43
  describe "HOTP example values from the rfc" do
data/spec/totp_spec.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'cgi'
2
1
  require 'spec_helper'
3
2
 
4
3
  describe ROTP::TOTP do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rotp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Percival
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-24 00:00:00.000000000 Z
11
+ date: 2013-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake