secure_compare 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b5039edbec15eff681421317d5ce85544af301bf
4
+ data.tar.gz: 13f2d41e76ac653a7d9307661d98d75de48ad258
5
+ SHA512:
6
+ metadata.gz: 132d13dff8c38178127688b75aada9994d7c115f2344e1b510b38b94129acd7caf28537a888b36c8c90a0d09d6d8ea62e3ad33a774db518a2c13a881038edc71
7
+ data.tar.gz: 33e1a91e80c882d1b509520ef622abd184c329b6e3d09f556ea08ca38d6ce58e11c305e8aa368457f5f310f8f5a8771d9cc8d8e17b3f83d8aace9b6ed1f06ecd
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in secure_compare.gemspec
4
+ gemspec
5
+ *.gem
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
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.
@@ -0,0 +1,34 @@
1
+ # SecureCompare
2
+
3
+ This is a copy of ActiveSupport::MessageVerifier.secure_compare, pulled out.
4
+
5
+ Use this to prevent timing attacks when you are checking tokens, or whatnot.
6
+
7
+ See: http://rdist.root.org/2010/07/19/exploiting-remote-timing-attacks/
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'secure_compare'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install secure_compare
22
+
23
+ ## Usage
24
+
25
+ SecureCompare.compare(secret_token, what_they_sent)
26
+
27
+
28
+ ## Tests
29
+
30
+ ruby -Ilib:test -Ilib test/test.rb
31
+
32
+ ## Contributing
33
+
34
+ You shouldn't need to. If you do, open an issue on github.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,11 @@
1
+ module SecureCompare
2
+ def self.compare(a, b)
3
+ return false unless a.bytesize == b.bytesize
4
+
5
+ l = a.unpack "C#{a.bytesize}"
6
+
7
+ res = 0
8
+ b.each_byte { |byte| res |= byte ^ l.shift }
9
+ res == 0
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "secure_compare"
7
+ spec.version = '0.0.1'
8
+ spec.authors = ["Micah Gates"]
9
+ spec.email = ["gems@mgates.com"]
10
+ spec.description = %q{This is a copy of ActiveSupport::MessageVerifier.secure_compare, pulled out.}
11
+ spec.summary = %q{Use this to prevent timing attacks when you are checking tokens, or whatnot.}
12
+ spec.homepage = "https://github.com/mgates/secure_compare"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,14 @@
1
+ require 'minitest/autorun'
2
+ require "secure_compare"
3
+
4
+ class Test < Minitest::Test
5
+ def test_that_equals_are_equal
6
+ assert SecureCompare.compare("asdf", "asdf")
7
+ end
8
+ def test_that_unequals_are_not_equal
9
+ refute SecureCompare.compare("asdf", "qwer")
10
+ end
11
+ def test_that_different_lengths_are_not_equal
12
+ refute SecureCompare.compare("asdf", "asdfg")
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: secure_compare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Micah Gates
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-19 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This is a copy of ActiveSupport::MessageVerifier.secure_compare, pulled
42
+ out.
43
+ email:
44
+ - gems@mgates.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/secure_compare.rb
55
+ - secure_compare.gemspec
56
+ - test/test.rb
57
+ homepage: https://github.com/mgates/secure_compare
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.0.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Use this to prevent timing attacks when you are checking tokens, or whatnot.
81
+ test_files:
82
+ - test/test.rb
83
+ has_rdoc: