Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on SCrypt #679

Merged
merged 2 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

* Breaking Changes
* None
* Breaking Changes, Major
* There is no longer a default `crypto_provider`. We still recommend SCrypt,
but don't want users of other providers to be forced to install it. You
must now explicitly specify your `crypto_provider`, eg. in your `user.rb`.

acts_as_authentic do |config|
c.crypto_provider = ::Authlogic::CryptoProviders::SCrypt
end

To continue to use the `scrypt` gem, add it to your `Gemfile`.

gem "scrypt", "~> 3.0"

* Breaking Changes, Minor
* The arity of `crypto_provider` has changed from -1 (one optional arg) to 0
(no arguments). To set the provider, use `crypto_provider=`.
* Added
* None
* Fixed
* None
* [#668](https://github.com/binarylogic/authlogic/pull/668) -
BCrypt user forced to load SCrypt

## 5.0.4 (2019-09-11)

Expand Down
2 changes: 1 addition & 1 deletion authlogic.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ require "authlogic/version"
s.add_dependency "activerecord", [">= 5.2", "< 6.1"]
s.add_dependency "activesupport", [">= 5.2", "< 6.1"]
s.add_dependency "request_store", "~> 1.0"
s.add_dependency "scrypt", ">= 1.2", "< 4.0"
s.add_development_dependency "bcrypt", "~> 3.1"
s.add_development_dependency "byebug", "~> 10.0"
s.add_development_dependency "coveralls", "~> 0.8.22"
Expand All @@ -38,6 +37,7 @@ require "authlogic/version"
s.add_development_dependency "pg", "~> 1.1.4"
s.add_development_dependency "rubocop", "~> 0.67.2"
s.add_development_dependency "rubocop-performance", "~> 1.1"
s.add_development_dependency "scrypt", ">= 1.2", "< 4.0"
s.add_development_dependency "simplecov", "~> 0.16.1"
s.add_development_dependency "simplecov-console", "~> 0.4.2"
s.add_development_dependency "sqlite3", "~> 1.3.13"
Expand Down
1 change: 1 addition & 0 deletions lib/authlogic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
path = File.dirname(__FILE__) + "/authlogic/"

[
"errors",
"i18n",
"random",
"config",
Expand Down
18 changes: 14 additions & 4 deletions lib/authlogic/acts_as_authentic/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,23 @@ def check_passwords_against_database(value = nil)
# transition to a better crypto provider without causing your users any
# pain.
#
# * <tt>Default:</tt> CryptoProviders::SCrypt
# * <tt>Default:</tt> There is no longer a default value. Prior to
# Authlogic 6, the default was `CryptoProviders::SCrypt`. If you try
# to read this config option before setting it, it will raise a
# `NilCryptoProvider` error. See that error's message for further
# details, and rationale for this change.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we raise an error on boot instead of lazily? Seems more certain that people will see it.

# * <tt>Accepts:</tt> Class
def crypto_provider(value = nil)
def crypto_provider
acts_as_authentic_config[:crypto_provider].tap { |provider|
raise NilCryptoProvider if provider.nil?
}
end

def crypto_provider=(value)
raise NilCryptoProvider if value.nil?
CryptoProviders::Guidance.new(value).impart_wisdom
rw_config(:crypto_provider, value, CryptoProviders::SCrypt)
rw_config(:crypto_provider, value)
end
alias crypto_provider= crypto_provider

# Let's say you originally encrypted your passwords with Sha1. Sha1 is
# starting to join the party with MD5 and you want to switch to
Expand Down
35 changes: 35 additions & 0 deletions lib/authlogic/errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module Authlogic
# Parent class of all Authlogic errors.
class Error < StandardError
end

# :nodoc:
class InvalidCryptoProvider < Error
end

# :nodoc:
class NilCryptoProvider < InvalidCryptoProvider
def message
<<~EOS
In version 5, Authlogic used SCrypt by default. As of version 6, there
is no default. We still recommend SCrypt. If you previously relied on
this default, then, in your User model (or equivalent), please set the
following:

acts_as_authentic do |config|
c.crypto_provider = ::Authlogic::CryptoProviders::SCrypt
end

Furthermore, the authlogic gem no longer depends on the scrypt gem. In
your Gemfile, please add scrypt.

gem "scrypt", "~> 3.0"

We have made this change in Authlogic 6 so that users of other crypto
providers no longer need to install the scrypt gem.
EOS
end
end
end
2 changes: 1 addition & 1 deletion test/acts_as_authentic_test/password_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_crypto_provider_config
end
assert_equal Authlogic::CryptoProviders::BCrypt, User.crypto_provider
silence_warnings do
User.crypto_provider Authlogic::CryptoProviders::Sha512
User.crypto_provider = Authlogic::CryptoProviders::Sha512
end
assert_equal Authlogic::CryptoProviders::Sha512, User.crypto_provider
end
Expand Down
4 changes: 3 additions & 1 deletion test/libs/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

# This model demonstrates an `after_save` callback.
class Admin < ActiveRecord::Base
acts_as_authentic
acts_as_authentic do |c|
c.crypto_provider = Authlogic::CryptoProviders::SCrypt
end

validates :password, confirmation: true

Expand Down
1 change: 1 addition & 0 deletions test/libs/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class User < ActiveRecord::Base
LOGIN = /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/.freeze

acts_as_authentic do |c|
c.crypto_provider = Authlogic::CryptoProviders::SCrypt
c.transition_from_crypto_providers Authlogic::CryptoProviders::Sha512
end
belongs_to :company
Expand Down