password_rehasher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 409cef18ec9de50002c666881ae5cb056408d819
4
+ data.tar.gz: 8fd6efa013ae5e7cacaf6dcbff3ec0513dacd884
5
+ SHA512:
6
+ metadata.gz: 01cd32f04dd356ed981600d1da983976e83937c75ab877e4f2ad13b85215cb40969e2f226fabbd7c5effbada3c7ac0942091098770f5d0898d768f938792ebce
7
+ data.tar.gz: e059422957191020d44b05508408db860539c8ee7ad1f38735655a61f542b34f9729feee4da13a6e10325640322fb3d4cf5df2eda2448da1d6e23b77a67c1274
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "scrypt", '~> 2.0.2'
4
+
5
+ group :test, :development do
6
+ gem 'rspec', '~> 3.3.0'
7
+ gem 'pry'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ coderay (1.1.0)
5
+ diff-lcs (1.2.5)
6
+ ffi (1.9.10)
7
+ ffi-compiler (0.1.3)
8
+ ffi (>= 1.0.0)
9
+ rake
10
+ method_source (0.8.2)
11
+ pry (0.10.3)
12
+ coderay (~> 1.1.0)
13
+ method_source (~> 0.8.1)
14
+ slop (~> 3.4)
15
+ rake (10.4.2)
16
+ rspec (3.3.0)
17
+ rspec-core (~> 3.3.0)
18
+ rspec-expectations (~> 3.3.0)
19
+ rspec-mocks (~> 3.3.0)
20
+ rspec-core (3.3.2)
21
+ rspec-support (~> 3.3.0)
22
+ rspec-expectations (3.3.1)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.3.0)
25
+ rspec-mocks (3.3.2)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.3.0)
28
+ rspec-support (3.3.0)
29
+ scrypt (2.0.2)
30
+ ffi-compiler (>= 0.0.2)
31
+ rake
32
+ slop (3.6.0)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ pry
39
+ rspec (~> 3.3.0)
40
+ scrypt (~> 2.0.2)
41
+
42
+ BUNDLED WITH
43
+ 1.10.6
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # password_rehasher
2
+
3
+ Password Rehasher is a temporary gem to rehash the passwords in the RPM database to scrypt.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ if (PasswordRehasher.password_valid?(plaintext_password, crypted_password)) {
9
+ if (PasswordRehasher.rehash_needed?(crypted_password)) {
10
+ user.crypted_password = PasswordRehasher.hash_password(password)
11
+ user.save
12
+ }
13
+ # user is logged in
14
+ } else {
15
+ # user is not logged in
16
+ }
17
+ ```
@@ -0,0 +1,31 @@
1
+ require "scrypt"
2
+ require 'digest/sha1'
3
+
4
+ class PasswordRehasher
5
+ VERSION = "0.1.0"
6
+
7
+ def self.password_valid?(plaintext_password, hashed_password)
8
+ case hashed_password.length
9
+ when 40
10
+ hashed_password == Digest::SHA1.hexdigest(plaintext_password)
11
+ when 90
12
+ password = SCrypt::Password.new(hashed_password)
13
+ password == plaintext_password
14
+ when 103
15
+ scrypt_plus_sha1_hash = hashed_password[13..-1]
16
+ sha1_hashed_password = Digest::SHA1.hexdigest(plaintext_password)
17
+ password = SCrypt::Password.new(scrypt_plus_sha1_hash)
18
+ password == sha1_hashed_password
19
+ else
20
+ false
21
+ end
22
+ end
23
+
24
+ def self.rehash_needed?(hashed_password)
25
+ hashed_password.length != 90
26
+ end
27
+
28
+ def self.hash_password(plaintext_password)
29
+ SCrypt::Password.create(plaintext_password)
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'password_rehasher'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "password_rehasher"
8
+ gem.version = PasswordRehasher::VERSION
9
+ gem.authors = ["John Hyland", "Polina Vorozheykina"]
10
+ gem.email = ["jhyland@newrelic.com", "pvorozheykina@newrelic.com"]
11
+ gem.description = %q{Temporary gem to rehash passwords to scrypt}
12
+ gem.summary = %q{Temporary gem to rehash passwords to scrypt}
13
+ gem.homepage = "https://source.datanerd.us/platform-services/password_rehasher"
14
+ gem.license = 'New Relic'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_runtime_dependency 'scrypt', '~> 2.0.2'
22
+
23
+ gem.add_development_dependency 'rspec', '~> 3.3.0'
24
+ gem.add_development_dependency 'pry'
25
+
26
+ end
@@ -0,0 +1,70 @@
1
+ describe PasswordRehasher do
2
+ let(:plaintext_password) { "some_password" }
3
+ let(:incorrect_plaintext_password) { "some_passwords" }
4
+
5
+ let(:sha1_hashed_password) { "7165f6d407dc2fd68528da63260a913e71623e86" }
6
+ let(:nested_hashed_password) { "nested hash: 400$8$38$e4df71f5896cd935$55ef6d79674ed4274e433e51ad75f0c80fd3599717698c46b11df7e67c5b0206" }
7
+ let(:scrypt_hashed_password) { "400$8$38$76f69b1ead11cf5c$b0e509793a43e66d206d549cec5f039acf15b52fe965cd3b5d855408459c3ddb" }
8
+ let(:invalid_hashed_password) { "400$8$38$76f60b1ead11cf5c$b0e509793a43e66d206d549cec5f039acf15b52fe965cd3b5d855408459c3ddb" }
9
+
10
+ describe '::VERSION' do
11
+ subject { PasswordRehasher::VERSION }
12
+
13
+ it { is_expected.to_not be_nil }
14
+ end
15
+
16
+ describe '.password_valid?' do
17
+ subject { PasswordRehasher.password_valid?(plaintext_password, hashed_password) }
18
+
19
+ context 'with a SHA1 hash' do
20
+ let(:hashed_password) { sha1_hashed_password }
21
+ it { is_expected.to be_truthy }
22
+ end
23
+
24
+ context 'with a nested hash' do
25
+ let(:hashed_password) { nested_hashed_password }
26
+ it { is_expected.to be_truthy }
27
+ end
28
+
29
+ context 'with an scrypt hash' do
30
+ let(:hashed_password) { scrypt_hashed_password }
31
+ it { is_expected.to be_truthy }
32
+ end
33
+
34
+ context 'with an scrypt hash' do
35
+ let(:hashed_password) { invalid_hashed_password }
36
+ it { is_expected.to be_falsey }
37
+ end
38
+ end
39
+
40
+ describe '.rehash_needed?' do
41
+ subject { PasswordRehasher.rehash_needed?(hashed_password) }
42
+
43
+ context 'with a SHA1 hash' do
44
+ let(:hashed_password) { sha1_hashed_password }
45
+ it { is_expected.to be_truthy }
46
+ end
47
+
48
+ context 'with a nested hash' do
49
+ let(:hashed_password) { nested_hashed_password }
50
+ it { is_expected.to be_truthy }
51
+ end
52
+
53
+ context 'with an scrypt hash' do
54
+ let(:hashed_password) { scrypt_hashed_password }
55
+ it { is_expected.to be_falsey }
56
+ end
57
+ end
58
+
59
+ describe '.hash_password' do
60
+ subject(:password_object) { PasswordRehasher.hash_password(plaintext_password) }
61
+
62
+ it "returns a password object matching the plaintext password" do
63
+ expect(password_object == plaintext_password).to be_truthy
64
+ end
65
+
66
+ it "returns a password object that does not match a different plaintext password" do
67
+ expect(password_object == incorrect_plaintext_password).to be_falsey
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,98 @@
1
+ require_relative "../lib/password_rehasher.rb"
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # 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
+ # Allows RSpec to persist some state between runs in order to support
56
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
57
+ # you configure your source control system to ignore this file.
58
+ config.example_status_persistence_file_path = "spec/examples.txt"
59
+
60
+ # Limits the available syntax to the non-monkey patched syntax that is
61
+ # recommended. For more details, see:
62
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
63
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
64
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
65
+ config.disable_monkey_patching!
66
+
67
+ # This setting enables warnings. It's recommended, but in some cases may
68
+ # be too noisy due to issues in dependencies.
69
+ config.warnings = true
70
+
71
+ # Many RSpec users commonly either run the entire suite or an individual
72
+ # file, and it's useful to allow more verbose output when running an
73
+ # individual spec file.
74
+ if config.files_to_run.one?
75
+ # Use the documentation formatter for detailed output,
76
+ # unless a formatter has already been configured
77
+ # (e.g. via a command-line flag).
78
+ config.default_formatter = 'doc'
79
+ end
80
+
81
+ # Print the 10 slowest examples and example groups at the
82
+ # end of the spec run, to help surface which specs are running
83
+ # particularly slow.
84
+ config.profile_examples = 10
85
+
86
+ # Run specs in random order to surface order dependencies. If you find an
87
+ # order dependency and want to debug it, you can fix the order by providing
88
+ # the seed, which is printed after each run.
89
+ # --seed 1234
90
+ config.order = :random
91
+
92
+ # Seed global randomization in this process using the `--seed` CLI option.
93
+ # Setting this allows you to use `--seed` to deterministically reproduce
94
+ # test failures related to randomization by passing the same `--seed` value
95
+ # as the one that triggered the failure.
96
+ Kernel.srand config.seed
97
+ =end
98
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: password_rehasher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Hyland
8
+ - Polina Vorozheykina
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-10-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: scrypt
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 2.0.2
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.0.2
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 3.3.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 3.3.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: pry
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: Temporary gem to rehash passwords to scrypt
57
+ email:
58
+ - jhyland@newrelic.com
59
+ - pvorozheykina@newrelic.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - README.md
69
+ - lib/password_rehasher.rb
70
+ - password_rehasher.gemspec
71
+ - spec/password_rehasher_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: https://source.datanerd.us/platform-services/password_rehasher
74
+ licenses:
75
+ - New Relic
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.6
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Temporary gem to rehash passwords to scrypt
97
+ test_files:
98
+ - spec/password_rehasher_spec.rb
99
+ - spec/spec_helper.rb
100
+ has_rdoc: