tsscmp-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e0eeb7ed7d42f62404f62c36ac5dfbf489ae466e833e0047a6fc719f93723465
4
+ data.tar.gz: e8a08372125a3ff90b3f26ad2d5014514687b0eae8b9701996a45a1f4073531f
5
+ SHA512:
6
+ metadata.gz: de7ec4cfa2b0a5d81478824d12f512a76faa17b8ff50afab7b6ed5daa0df30f3c58a1426a68e757796a114cb0c5aea197685cb78763fe264576e648a9eff1854
7
+ data.tar.gz: 21435b249a3088ad22675bd7257ac261701d050f7e570804fe9999ced76328c67be0889fd11b5d27feead86ef24f8ca987ece49dd11b048d4ec36935e0c8c654
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,6 @@
1
+ LineLength:
2
+ Max: 120
3
+ Style/Documentation:
4
+ Enabled: false
5
+ CyclomaticComplexity:
6
+ Max: 10
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tsscmp-ruby.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rubocop', require: false
8
+ end
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tsscmp-ruby (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ jaro_winkler (1.5.2)
11
+ minitest (5.11.3)
12
+ parallel (1.17.0)
13
+ parser (2.6.2.1)
14
+ ast (~> 2.4.0)
15
+ psych (3.1.0)
16
+ rainbow (3.0.0)
17
+ rake (10.5.0)
18
+ rubocop (0.67.2)
19
+ jaro_winkler (~> 1.5.1)
20
+ parallel (~> 1.10)
21
+ parser (>= 2.5, != 2.5.1.1)
22
+ psych (>= 3.1.0)
23
+ rainbow (>= 2.2.2, < 4.0)
24
+ ruby-progressbar (~> 1.7)
25
+ unicode-display_width (>= 1.4.0, < 1.6)
26
+ ruby-progressbar (1.10.0)
27
+ unicode-display_width (1.5.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 2.0)
34
+ minitest (~> 5.0)
35
+ rake (~> 10.0)
36
+ rubocop
37
+ tsscmp-ruby!
38
+
39
+ BUNDLED WITH
40
+ 2.0.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 saka1
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # tsscmp-ruby
2
+
3
+ This gem provides timing-safe string compare with [double HMAC pattern](https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2011/february/double-hmac-verification/).
4
+ It is inspired by [suryagh's tsscmp library](https://github.com/suryagh/tsscmp).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'tsscmp-ruby'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install tsscmp-ruby
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require 'tsscmp-ruby'
26
+
27
+ Tsscmp.compare("a", "a") #=> true
28
+ Tsscmp.compare("a", "b") #=> false
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/saka1/tsscmp-ruby.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## TODO
40
+
41
+ - Statistical tests on timing-safe
42
+ - Remove dependency to openssl
43
+
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,31 @@
1
+ require 'tsscmp/version'
2
+
3
+ require 'securerandom'
4
+ require 'openssl'
5
+
6
+ module Tsscmp
7
+ module_function
8
+
9
+ # Constant time string comparison.
10
+ #
11
+ # Returns true if the two arguments have same value, otherwise false.
12
+ def compare(a, b) # rubocop:disable Naming/UncommunicativeMethodParamName:
13
+ return false if a.nil? || b.nil?
14
+
15
+ # assume the arguments is String
16
+ raise TypeError unless a.is_a?(String) || b.is_a?(String)
17
+ return false unless a.size == b.size
18
+
19
+ key = SecureRandom.random_bytes(32)
20
+ ah = OpenSSL::HMAC.hexdigest('sha256', key, a)
21
+ bh = OpenSSL::HMAC.hexdigest('sha256', key, b)
22
+
23
+ # Implementation Note:
24
+ # `&& a == b` is a very very conservative comparison.
25
+ # In my opnion, `ah == bh` is enough to compare securely although several other implementations use the strictly method such as:
26
+ # - https://github.com/rails/rails/blob/v5.2.3/activesupport/lib/active_support/security_utils.rb#L27
27
+ # - https://github.com/suryagh/tsscmp/blob/v1.0.6/lib/index.js#L35
28
+ # So, as of the present time, I add `&& a == b`.
29
+ ah == bh && a == b
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Tsscmp
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,41 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'tsscmp/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'tsscmp-ruby'
7
+ spec.version = Tsscmp::VERSION
8
+ spec.authors = ['saka1']
9
+ spec.email = ['github@saka1.net']
10
+
11
+ spec.summary = 'Timing safe string compare with double HMAC pattern'
12
+ spec.description = 'Timing safe string compare with double HMAC pattern'
13
+ spec.homepage = 'https://github.com/saka1/tsscmp-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ #spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = 'https://github.com/saka1/tsscmp-ruby'
23
+ spec.metadata['changelog_uri'] = 'https://github.com/saka1/tsscmp-ruby'
24
+ else
25
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
26
+ 'public gem pushes.'
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = 'exe'
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ['lib']
37
+
38
+ spec.add_development_dependency 'bundler', '~> 2.0'
39
+ spec.add_development_dependency 'minitest', '~> 5.0'
40
+ spec.add_development_dependency 'rake', '~> 10.0'
41
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tsscmp-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - saka1
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-09 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Timing safe string compare with double HMAC pattern
56
+ email:
57
+ - github@saka1.net
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rubocop.yml"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - lib/tsscmp.rb
71
+ - lib/tsscmp/version.rb
72
+ - tsscmp-ruby.gemspec
73
+ homepage: https://github.com/saka1/tsscmp-ruby
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ homepage_uri: https://github.com/saka1/tsscmp-ruby
78
+ source_code_uri: https://github.com/saka1/tsscmp-ruby
79
+ changelog_uri: https://github.com/saka1/tsscmp-ruby
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.7.6
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Timing safe string compare with double HMAC pattern
100
+ test_files: []