rotp 3.3.0 → 3.3.1

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: 6966922a92bffb8bf74497e36d3f2e42e63f47a5
4
- data.tar.gz: 0dbef9d1ed476e382b243d232240458d396b3593
3
+ metadata.gz: 6597229fd1ace9419ec1212d4cdedaa8392d5e2c
4
+ data.tar.gz: 7784edcd67e532d6e1c14e229c79e2b1c6c5bb6e
5
5
  SHA512:
6
- metadata.gz: 3af99a2dcadd3591d235ecb8f1d0752ceadaa0b8649c1851163a7d0ce7e88bf5a564d1d32b6f3a2e2a3b290e36fd378b39e1d0a3a5225ba7ead905e3c207806f
7
- data.tar.gz: c9504564ca0ec36d3efac011b9079d33d5038bf917ff4f5d6700556a71956fab49710304551e2d2d0a23f6c6a91dcdb7a296dd26468f6a78de8dc0584a0c35da
6
+ metadata.gz: cc83e697d928afc3be726fa0a7569f87bb5d69362ae429af512e35bc5f15d6cce947c510ab6204b6cac99601a3870600577360750f3e9af35762e316ce45080b
7
+ data.tar.gz: 5cdefb29436b550ecd825baa13cc2365c994705f575b474d9a8d02ecad1764ce9982bc04537ea95afbfe24b304c1a1a71e339f4223f496138f7eaeaa76261050
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  .yardoc
4
4
  pkg/*
5
5
  coverage
6
+ Gemfile.lock
@@ -6,4 +6,4 @@ rvm:
6
6
  - 2.0.0
7
7
  - 1.9.3
8
8
  script:
9
- - bundler exec rspec
9
+ - bundle exec rspec
@@ -1,5 +1,10 @@
1
1
  ### Changelog
2
2
 
3
+ #### 3.3.1
4
+
5
+ - Add OpenSSL as a requirement for Ruby 2.5. Fixes #70 & #64
6
+ - Allow Base32 with padding. #71
7
+
3
8
  #### 3.3.0
4
9
 
5
10
  - Add digest algorithm parameter for non SHA1 digests - #62 from @btalbot
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # The Ruby One Time Password Library
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/mdp/rotp.png)](https://travis-ci.org/mdp/rotp)
3
+ [![Build Status](https://travis-ci.org/mdp/rotp.svg?branch=master)](https://travis-ci.org/mdp/rotp)
4
4
  [![Gem Version](https://badge.fury.io/rb/rotp.svg)](https://rubygems.org/gems/rotp)
5
5
  [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/mdp/rotp/blob/master/LICENSE)
6
6
 
@@ -46,13 +46,13 @@ totp.provisioning_uri("alice@google.com")
46
46
 
47
47
  ```ruby
48
48
  hotp = ROTP::HOTP.new("base32secretkey3232")
49
- hotp.at(0) # => "260182"
50
- hotp.at(1) # => "055283"
51
- hotp.at(1401) # => "316439"
49
+ hotp.at(0) # => "786922"
50
+ hotp.at(1) # => "595254"
51
+ hotp.at(1401) # => "259769"
52
52
 
53
53
  # OTP verified with a counter
54
- hotp.verify("316439", 1401) # => true
55
- hotp.verify("316439", 1402) # => false
54
+ hotp.verify("259769", 1401) # => true
55
+ hotp.verify("259769", 1402) # => false
56
56
  ```
57
57
 
58
58
  ### Verifying a Time based OTP with drift
@@ -1,6 +1,7 @@
1
1
  require 'cgi'
2
2
  require 'uri'
3
3
  require 'securerandom'
4
+ require 'openssl'
4
5
  require 'rotp/base32'
5
6
  require 'rotp/otp'
6
7
  require 'rotp/hotp'
@@ -5,6 +5,7 @@ module ROTP
5
5
 
6
6
  class << self
7
7
  def decode(str)
8
+ str = str.tr('=','')
8
9
  output = []
9
10
  str.scan(/.{1,8}/).each do |block|
10
11
  char_array = decode_block(block).map{|c| c.chr}
@@ -58,6 +58,10 @@ module ROTP
58
58
  # along with the secret
59
59
  #
60
60
  def int_to_bytestring(int, padding = 8)
61
+ unless int >= 0
62
+ raise ArgumentError, "#int_to_bytestring requires a positive number"
63
+ end
64
+
61
65
  result = []
62
66
  until int == 0
63
67
  result << (int & 0xFF).chr
@@ -20,6 +20,7 @@ module ROTP
20
20
  unless time.class == Time
21
21
  time = Time.at(time.to_i)
22
22
  end
23
+
23
24
  generate_otp(timecode(time), padding)
24
25
  end
25
26
 
@@ -1,3 +1,3 @@
1
1
  module ROTP
2
- VERSION = "3.3.0"
2
+ VERSION = "3.3.1"
3
3
  end
@@ -44,6 +44,12 @@ RSpec.describe ROTP::Base32 do
44
44
  expect(ROTP::Base32.decode('234BCDEFG').unpack('H*').first).to eq 'd6f8110c8530'
45
45
  expect(ROTP::Base32.decode('234BCDEFG234BCDEFG').unpack('H*').first).to eq 'd6f8110c8536b7c0886429'
46
46
  end
47
+
48
+ context 'with padding' do
49
+ it 'correctly decodes a string' do
50
+ expect(ROTP::Base32.decode('F==').unpack('H*').first).to eq '28'
51
+ end
52
+ end
47
53
  end
48
54
  end
49
55
  end
@@ -161,6 +161,21 @@ RSpec.describe ROTP::TOTP do
161
161
 
162
162
  end
163
163
 
164
+ describe 'invalid_verification with nil time as argument' do
165
+ let(:verification) { totp.verify_with_drift token, drift, nil }
166
+
167
+ context 'positive drift' do
168
+ let(:token) { totp.at now - 30 }
169
+ let(:drift) { 60 }
170
+
171
+ it 'raises error' do
172
+ expect do
173
+ verification
174
+ end.to raise_error(ArgumentError)
175
+ end
176
+ end
177
+ end
178
+
164
179
  describe '#verify_with_drift' do
165
180
  let(:verification) { totp.verify_with_drift token, drift, now }
166
181
  let(:drift) { 0 }
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: 3.3.0
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Percival
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-22 00:00:00.000000000 Z
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -82,7 +82,6 @@ files:
82
82
  - Dockerfile-2.1
83
83
  - Dockerfile-2.3
84
84
  - Gemfile
85
- - Gemfile.lock
86
85
  - Guardfile
87
86
  - LICENSE
88
87
  - README.md
@@ -1,41 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- rotp (3.2.0)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- diff-lcs (1.2.5)
10
- docile (1.1.5)
11
- json (1.8.3)
12
- rake (10.5.0)
13
- rspec (3.5.0)
14
- rspec-core (~> 3.5.0)
15
- rspec-expectations (~> 3.5.0)
16
- rspec-mocks (~> 3.5.0)
17
- rspec-core (3.5.2)
18
- rspec-support (~> 3.5.0)
19
- rspec-expectations (3.5.0)
20
- diff-lcs (>= 1.2.0, < 2.0)
21
- rspec-support (~> 3.5.0)
22
- rspec-mocks (3.5.0)
23
- diff-lcs (>= 1.2.0, < 2.0)
24
- rspec-support (~> 3.5.0)
25
- rspec-support (3.5.0)
26
- simplecov (0.12.0)
27
- docile (~> 1.1.0)
28
- json (>= 1.8, < 3)
29
- simplecov-html (~> 0.10.0)
30
- simplecov-html (0.10.0)
31
- timecop (0.8.1)
32
-
33
- PLATFORMS
34
- ruby
35
-
36
- DEPENDENCIES
37
- rake (~> 10.5)
38
- rotp!
39
- rspec (~> 3.5)
40
- simplecov (~> 0.12)
41
- timecop (~> 0.8)