totp-simple 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f72b1057794a08a63a66b4706396a04bbeb6cca
4
+ data.tar.gz: 8d2c4703613d9d877e377b5d576519c436c113be
5
+ SHA512:
6
+ metadata.gz: 7bdd60e3882d26771401b9579662c0ca79d325946188dfbfc4640baf53fccfa89796b820c11e59968d9f4a3716256dcec7397be76d69a2cea2024791fa822307
7
+ data.tar.gz: c159ad5625fba9d813c605278dc8bf94f34cd970f530c0601ad9a7444ffaf19bed823cef293d389871cb7559a93f975b7458e92a6815515f428ba228e1420c68
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ language: ruby
2
+ script: rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in totp.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 about:source
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # TOTP Simple
2
+
3
+ This library provides token generation and verification according to https://tools.ietf.org/html/rfc6238
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'totp-simple'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install totp-simple
18
+
19
+ ## Usage
20
+
21
+ Warning, this gems has the name *totp-simple* but the actual library is called
22
+ *TOTP*. This is for historical reasons, as we haven't planned to publish this
23
+ gem on rubygems.org.
24
+
25
+ ```ruby
26
+ require 'totp'
27
+
28
+ password = TOTP::Password.new('shared-secret').generate
29
+
30
+ TOTP::Password.new('shared-secret').verify(password)
31
+
32
+ ```
33
+
34
+ ## Testing
35
+
36
+ rspec
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( https://github.com/aboutsource/totp-simple/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create a new Pull Request
@@ -0,0 +1,28 @@
1
+ module TOTP
2
+ class Password < Struct.new(:secret)
3
+
4
+ TIME_STEP = 3
5
+
6
+ def generate(now = Time.now.to_i)
7
+ OpenSSL::HMAC.hexdigest(Password.digest, secret, (now/TIME_STEP).to_s)
8
+ end
9
+
10
+ # Verify given password by comparison with new generated password
11
+ # Repeat verification 2 times and go back in time to avoid time
12
+ # synchronisation errors. See https://tools.ietf.org/html/rfc6238#section-6
13
+ def verify(password)
14
+ (0..2).each do |step|
15
+ i = Time.now.to_i - (step*TIME_STEP)
16
+
17
+ return true if generate(i) == password
18
+ end
19
+ false
20
+ end
21
+
22
+
23
+ def self.digest
24
+ @@digest ||= OpenSSL::Digest.new('sha256')
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module TOTP
2
+ VERSION = "0.0.3"
3
+ end
data/lib/totp.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "totp/version"
2
+ require "totp/password"
3
+
4
+ module TOTP
5
+ end
@@ -0,0 +1,93 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+ require 'totp'
4
+
5
+ # This file was generated by the `rspec --init` command. Conventionally, all
6
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
7
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
8
+ # file to always be loaded, without a need to explicitly require it in any files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # The settings below are suggested to provide a good initial experience
46
+ # with RSpec, but feel free to customize to your heart's content.
47
+ =begin
48
+ # These two settings work together to allow you to limit a spec run
49
+ # to individual examples or groups you care about by tagging them with
50
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
51
+ # get run.
52
+ config.filter_run :focus
53
+ config.run_all_when_everything_filtered = true
54
+
55
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
56
+ # For more details, see:
57
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
58
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
59
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
60
+ config.disable_monkey_patching!
61
+
62
+ # This setting enables warnings. It's recommended, but in some cases may
63
+ # be too noisy due to issues in dependencies.
64
+ config.warnings = true
65
+
66
+ # Many RSpec users commonly either run the entire suite or an individual
67
+ # file, and it's useful to allow more verbose output when running an
68
+ # individual spec file.
69
+ if config.files_to_run.one?
70
+ # Use the documentation formatter for detailed output,
71
+ # unless a formatter has already been configured
72
+ # (e.g. via a command-line flag).
73
+ config.default_formatter = 'doc'
74
+ end
75
+
76
+ # Print the 10 slowest examples and example groups at the
77
+ # end of the spec run, to help surface which specs are running
78
+ # particularly slow.
79
+ config.profile_examples = 10
80
+
81
+ # Run specs in random order to surface order dependencies. If you find an
82
+ # order dependency and want to debug it, you can fix the order by providing
83
+ # the seed, which is printed after each run.
84
+ # --seed 1234
85
+ config.order = :random
86
+
87
+ # Seed global randomization in this process using the `--seed` CLI option.
88
+ # Setting this allows you to use `--seed` to deterministically reproduce
89
+ # test failures related to randomization by passing the same `--seed` value
90
+ # as the one that triggered the failure.
91
+ Kernel.srand config.seed
92
+ =end
93
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe TOTP::Password do
4
+
5
+ describe '#generate' do
6
+ subject { TOTP::Password.new('secret').generate }
7
+
8
+ it { is_expected.to be_a String }
9
+ it { is_expected.to match(/^[a-z0-9]{64}$/) }
10
+ end
11
+
12
+
13
+ describe '#verify' do
14
+ let(:now) { Time.now.to_i }
15
+ let(:secret) { 'secret' }
16
+ let(:password) { TOTP::Password.new(secret).generate(now) }
17
+
18
+ subject { TOTP::Password.new('secret').verify(password) }
19
+
20
+ describe 'with valid secret' do
21
+ describe 'in time' do
22
+ it { is_expected.to be true }
23
+ end
24
+
25
+ describe 'after 5 seconds' do
26
+ let(:now) { Time.now.to_i - 5}
27
+
28
+ it { is_expected.to be true }
29
+ end
30
+
31
+ describe 'after 9 seconds' do
32
+ let(:now) { Time.now.to_i - 9}
33
+
34
+ it { is_expected.to be false }
35
+ end
36
+ end
37
+
38
+ describe 'with invalid secret' do
39
+ let(:secret) { 'invalid secret' }
40
+
41
+ it { is_expected.to be false }
42
+ end
43
+ end # end of #verfiy
44
+ end
data/totp.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'totp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "totp-simple"
8
+ spec.version = TOTP::VERSION
9
+ spec.authors = ["about:source"]
10
+ spec.email = ["support@aboutsource.net"]
11
+ spec.summary = %q{Generate and validate totp token, see RFC 6238}
12
+ spec.description = %q{Generate and validate totp token, see RFC 6238. Very simple implementation so far.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rspec", "~> 3.1"
23
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: totp-simple
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - about:source
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ description: Generate and validate totp token, see RFC 6238. Very simple implementation
42
+ so far.
43
+ email:
44
+ - support@aboutsource.net
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".travis.yml"
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - lib/totp.rb
56
+ - lib/totp/password.rb
57
+ - lib/totp/version.rb
58
+ - spec/spec_helper.rb
59
+ - spec/totp/password_spec.rb
60
+ - totp.gemspec
61
+ homepage: ''
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Generate and validate totp token, see RFC 6238
85
+ test_files:
86
+ - spec/spec_helper.rb
87
+ - spec/totp/password_spec.rb
88
+ has_rdoc: