rotp 4.0.2 → 4.1.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
  SHA256:
3
- metadata.gz: 72d869e33ff8ede2ef4233ed0398b730a1fc14e2b764295b090492bed133c4fc
4
- data.tar.gz: 5ee5f47d3cee494762fcaaabb4dff1dfc247bab7faa0207fc6a3b7ff7b672f05
3
+ metadata.gz: 72a52a1f0f26257e83977969144abf6324fee40c65ef4f6b3b910d30c3bb1e36
4
+ data.tar.gz: 212a5ca91186490c07221f7f17e4d39cc05778b89ebf22cf53712de2cfb8944a
5
5
  SHA512:
6
- metadata.gz: 42c5bb89a97375204c3198dd9d07080f4728162307c9b99eb6f7c46152bfa8aa21d7e02699fc911c9991ef6ae17c9465f2c8e438bf223b2097cbc9b72766912b
7
- data.tar.gz: 45dc82dd282328c5e3651a5b660ac327c1d10f07b7ca21025139fbe3edf418b661e1b67648081027e04ea9bce639195ec21d44ada7d6af9ac607984e8fcda47b
6
+ metadata.gz: 41b36b57154571a35d8d3f59961c3f1754c2bfb3bf06e2a29e2360b24ba884e7d632f86d3d5491341034a30654ba971d96bfcfecae85687a701230cf8e4523ba
7
+ data.tar.gz: d70217238c2d859b674f9cc702e9ffcb4fcb5cdf3a75d9b40306d0dee8f28198363d6001510e2cbc2b507d24cb753127d602b6dec211da77287d7ac04fabef98
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
- before_install: gem install bundler
2
+ before_install: gem install bundler -v '<2'
3
3
  rvm:
4
- - 2.3.0
5
- - 2.1.0
6
- - 2.0.0
4
+ - 2.6
5
+ - 2.5
6
+ - 2.0
7
7
  script:
8
8
  - bundle exec rspec
@@ -1,5 +1,11 @@
1
1
  ### Changelog
2
2
 
3
+ ### 4.1.0
4
+
5
+ - Add a digest option to the CLI #83
6
+ - Fix provisioning URI is README #82
7
+ - Improvements to docs
8
+
3
9
  ### 4.0.2
4
10
 
5
11
  - Fix gemspec requirment for Addressable
@@ -0,0 +1,11 @@
1
+ FROM ruby:2.0
2
+
3
+ RUN mkdir -p /usr/src/app
4
+ WORKDIR /usr/src/app
5
+
6
+ COPY Gemfile /usr/src/app/
7
+ COPY . /usr/src/app
8
+ RUN bundle install
9
+
10
+ CMD ["bundle", "exec", "rspec"]
11
+
@@ -0,0 +1,10 @@
1
+ FROM ruby:2.5
2
+
3
+ RUN mkdir -p /usr/src/app
4
+ WORKDIR /usr/src/app
5
+
6
+ COPY Gemfile /usr/src/app/
7
+ COPY . /usr/src/app
8
+ RUN bundle install
9
+
10
+ CMD ["bundle", "exec", "rspec"]
@@ -0,0 +1,11 @@
1
+ FROM ruby:2.6
2
+
3
+ RUN mkdir -p /usr/src/app
4
+ WORKDIR /usr/src/app
5
+
6
+ COPY Gemfile /usr/src/app/
7
+ COPY . /usr/src/app
8
+ RUN bundle install
9
+
10
+ CMD ["bundle", "exec", "rspec"]
11
+
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
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
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://www.rubydoc.info/github/mdp/rotp/master)
5
6
  [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/mdp/rotp/blob/master/LICENSE)
6
7
 
7
8
  A ruby library for generating and validating one time passwords (HOTP & TOTP) according to [RFC 4226](http://tools.ietf.org/html/rfc4226) and [RFC 6238](http://tools.ietf.org/html/rfc6238).
@@ -72,14 +73,17 @@ User.find(someUserID)
72
73
  totp = ROTP::TOTP.new(user.otp_secret)
73
74
  totp.now # => "492039"
74
75
 
76
+ # Let's take a look at the last time the user authenticated with an OTP
75
77
  user.last_otp_at # => 1432703530
76
78
 
77
79
  # Verify the OTP
78
80
  last_otp_at = totp.verify("492039", after: user.last_otp_at) #=> 1472145760
79
81
  # ROTP returns the timestamp(int) of the current period
82
+
80
83
  # Store this on the user's account
81
84
  user.update(last_otp_at: last_otp_at)
82
- # Someone attempts to reused the OTP inside the 30s window
85
+
86
+ # Someone attempts to reuse the OTP inside the 30s window
83
87
  last_otp_at = totp.verify("492039", after: user.last_otp_at) #=> nil
84
88
  # It fails to verify because we are still in the same 30s interval window
85
89
  ```
@@ -115,8 +119,11 @@ Provisioning URI's generated by ROTP are compatible with most One Time Password
115
119
  Google Authenticator.
116
120
 
117
121
  ```ruby
118
- totp.provisioning_uri("alice@google.com") # => 'otpauth://totp/issuer:alice@google.com?secret=JBSWY3DPEHPK3PXP'
119
- hotp.provisioning_uri("alice@google.com", 0) # => 'otpauth://hotp/issuer:alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=0'
122
+ totp = ROTP::TOTP.new("base32secret3232", issuer: "My Service")
123
+ totp.provisioning_uri("alice@google.com") # => 'otpauth://totp/My%20Service:alice@google.com?secret=base32secret3232&issuer=My+Service'
124
+
125
+ hotp = ROTP::HOTP.new("base32secret3232", issuer: "My Service")
126
+ hotp.provisioning_uri("alice@google.com", 0) # => 'otpauth://hotp/alice@google.com?secret=base32secret3232&counter=0'
120
127
  ```
121
128
 
122
129
  This can then be rendered as a QR Code which the user can scan using their mobile phone and the appropriate application.
@@ -143,6 +150,16 @@ bundle install
143
150
  bundle exec rspec
144
151
  ```
145
152
 
153
+ ### Testign with Docker
154
+
155
+ In order to make it easier to test against different ruby version, ROTP comes
156
+ with a set of Dockerfiles for each version that we test against in Travis
157
+
158
+ ```bash
159
+ docker build -f Dockerfile-2.6 -t rotp_2.6 .
160
+ docker run --rm -v $(pwd):/usr/src/app rotp_2.6
161
+ ```
162
+
146
163
  ## Executable Usage
147
164
 
148
165
  The rotp rubygem includes an executable for helping with testing and debugging
@@ -162,7 +179,7 @@ Have a look at the [contributors graph](https://github.com/mdp/rotp/graphs/contr
162
179
 
163
180
  ## License
164
181
 
165
- MIT Copyright (C) 2016 by Mark Percival, see [LICENSE](https://github.com/mdp/rotp/blob/master/LICENSE) for details.
182
+ MIT Copyright (C) 2019 by Mark Percival, see [LICENSE](https://github.com/mdp/rotp/blob/master/LICENSE) for details.
166
183
 
167
184
  ## Other implementations
168
185
 
@@ -68,6 +68,10 @@ module ROTP
68
68
  parser.on_tail('-h', '--help', 'Show this message') do
69
69
  options!.mode = :help
70
70
  end
71
+
72
+ parser.on('-d', '--digest [ALGORITHM]', 'Use algorithm for the digest (default sha1)') do |digest|
73
+ options!.digest = digest
74
+ end
71
75
  end
72
76
  end
73
77
 
@@ -31,9 +31,9 @@ module ROTP
31
31
  return arguments.to_s if options.mode == :help
32
32
 
33
33
  if options.mode == :time
34
- ROTP::TOTP.new(options.secret).now
34
+ ROTP::TOTP.new(options.secret, options).now
35
35
  elsif options.mode == :hmac
36
- ROTP::HOTP.new(options.secret).at options.counter
36
+ ROTP::HOTP.new(options.secret, options).at options.counter
37
37
  end
38
38
  end
39
39
 
@@ -5,10 +5,10 @@ module ROTP
5
5
 
6
6
  # @param [String] secret in the form of base32
7
7
  # @option options digits [Integer] (6)
8
- # Number of integers in the OTP
8
+ # Number of integers in the OTP.
9
9
  # Google Authenticate only supports 6 currently
10
10
  # @option options digest [String] (sha1)
11
- # Digest used in the HMAC
11
+ # Digest used in the HMAC.
12
12
  # Google Authenticate only supports 'sha1' currently
13
13
  # @returns [OTP] OTP instantiation
14
14
  def initialize(s, options = {})
@@ -1,3 +1,3 @@
1
1
  module ROTP
2
- VERSION = '4.0.2'.freeze
2
+ VERSION = '4.1.0'.freeze
3
3
  end
@@ -18,6 +18,14 @@ RSpec.describe ROTP::CLI do
18
18
  end
19
19
  end
20
20
 
21
+ context 'generating a TOTP with sha256 digest' do
22
+ let(:argv) { %w[--secret JBSWY3DPEHPK3PXP --digest sha256] }
23
+
24
+ it 'prints the corresponding token' do
25
+ expect(output).to eq '544902'
26
+ end
27
+ end
28
+
21
29
  context 'generating a TOTP with no secret' do
22
30
  let(:argv) { %w[--time --secret] }
23
31
 
@@ -49,4 +57,12 @@ RSpec.describe ROTP::CLI do
49
57
  expect(output).to eq '161024'
50
58
  end
51
59
  end
60
+
61
+ context 'generating a HOTP' do
62
+ let(:argv) { %W[--hmac --secret #{'a' * 32} --counter 1234 --digest sha256] }
63
+
64
+ it 'prints the corresponding token' do
65
+ expect(output).to eq '325941'
66
+ end
67
+ end
52
68
  end
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: 4.0.2
4
+ version: 4.1.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: 2018-11-01 00:00:00.000000000 Z
11
+ date: 2019-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -92,9 +92,9 @@ files:
92
92
  - ".gitignore"
93
93
  - ".travis.yml"
94
94
  - CHANGELOG.md
95
- - Dockerfile-1.9
96
- - Dockerfile-2.1
97
- - Dockerfile-2.3
95
+ - Dockerfile-2.0
96
+ - Dockerfile-2.5
97
+ - Dockerfile-2.6
98
98
  - Gemfile
99
99
  - Guardfile
100
100
  - LICENSE
@@ -158,10 +158,4 @@ rubygems_version: 2.7.6
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: A Ruby library for generating and verifying one time passwords
161
- test_files:
162
- - spec/lib/rotp/arguments_spec.rb
163
- - spec/lib/rotp/base32_spec.rb
164
- - spec/lib/rotp/cli_spec.rb
165
- - spec/lib/rotp/hotp_spec.rb
166
- - spec/lib/rotp/totp_spec.rb
167
- - spec/spec_helper.rb
161
+ test_files: []
@@ -1,15 +0,0 @@
1
- FROM ruby:1.9
2
-
3
- # throw errors if Gemfile has been modified since Gemfile.lock
4
- RUN bundle config --global frozen 1
5
-
6
- RUN mkdir -p /usr/src/app
7
- WORKDIR /usr/src/app
8
-
9
- COPY Gemfile /usr/src/app/
10
- COPY Gemfile.lock /usr/src/app/
11
- COPY . /usr/src/app
12
- RUN bundle install
13
-
14
- CMD ["bundler", "exec", "rspec"]
15
-
@@ -1,16 +0,0 @@
1
- FROM ruby:2.1
2
-
3
- # throw errors if Gemfile has been modified since Gemfile.lock
4
- RUN bundle config --global frozen 1
5
-
6
- RUN mkdir -p /usr/src/app
7
- WORKDIR /usr/src/app
8
-
9
- COPY Gemfile /usr/src/app/
10
- COPY Gemfile.lock /usr/src/app/
11
- COPY . /usr/src/app
12
- RUN bundle install
13
-
14
-
15
- CMD ["bundler", "exec", "rspec"]
16
-
@@ -1,16 +0,0 @@
1
- FROM ruby:2.3
2
-
3
- # throw errors if Gemfile has been modified since Gemfile.lock
4
- RUN bundle config --global frozen 1
5
-
6
- RUN mkdir -p /usr/src/app
7
- WORKDIR /usr/src/app
8
-
9
- COPY Gemfile /usr/src/app/
10
- COPY Gemfile.lock /usr/src/app/
11
- COPY . /usr/src/app
12
- RUN bundle install
13
-
14
-
15
- CMD ["bundler", "exec", "rspec"]
16
-