Commit Graph

17 Commits

Author SHA1 Message Date
Ryuta Kamizono 8c7883d3fc ✂️ [ci skip] 2021-03-22 04:46:11 +09:00
Dirkjan Bussink 447e28347e
Allow configuration of the digest class used in the key generator
This change allows for configuration of the hash digest that is used in
the key generator for key derivation.

SHA1 is an outdated algorithm and security auditors tend to frown on
its usage. By allowing this to be configured, it becomes possible to
move to a more up to date hash mechanism.

While I don't think this has any current relevant security implications,
especially not with a proper random secret base, moving away from SHA1
makes conversations with auditors and FIPS compliance checks easier
since the best answer is always that an approved algorithm is used.

A rotation can be built using this change with an approach like the
following for encrypted cookies:

```ruby
Rails.application.config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA256

Rails.application.config.action_dispatch.cookies_rotations.tap do |cookies|
  salt = Rails.application.config.action_dispatch.authenticated_encrypted_cookie_salt
  secret_key_base = Rails.application.secrets.secret_key_base

  key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000, hash_digest_class: OpenSSL::Digest::SHA1)
  key_len = ActiveSupport::MessageEncryptor.key_len
  secret = key_generator.generate_key(salt, key_len)

  cookies.rotate :encrypted, secret
end
```

This turns the default into using SHA256 but also still accepts secrets
derived using SHA1.

The defaults for new apps is here changed to use SHA256. Existing apps
will keep using SHA1.
2021-01-07 14:28:01 +01:00
Jack McCracken dd870dd029
Add a separator to the cache key for ActiveSupport::CachingKeyGenerator 2020-05-04 13:56:38 -04:00
Michael Grosser 203998c916
allow running each test with pure ruby path/to/test.rb
also:
 - makes test dependencies obvious
 - makes tests runnable from within subfolders
2019-12-18 08:49:19 -06:00
yuuji.yaginuma 0193b89be6 Remove unused requires 2018-08-17 12:51:14 +09:00
Jeremy Daer 4b42c7e52a Ruby 2.4: take advantage of String#unpack1
https://bugs.ruby-lang.org/issues/12752
https://ruby-doc.org/core-2.4.0/String.html#method-i-unpack1
2018-03-01 22:42:51 -08:00
Koichi ITO ac717d65a3 [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment` 2017-07-11 13:12:32 +09:00
Kir Shatrov 72950568dd Use frozen-string-literal in ActiveSupport 2017-07-09 15:08:29 +03:00
Matthew Draper 87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30
Kir Shatrov cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Xavier Noria 80e66cc4d9 normalizes indentation and whitespace across the project 2016-08-06 20:16:27 +02:00
Xavier Noria 5c315a8fa6 modernizes hash syntax in activesupport 2016-08-06 19:38:33 +02:00
Xavier Noria a731125f12 applies new string literal convention in activesupport/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:10:53 +02:00
Matthew Draper ea7fee03f7 Partially revert #25192
KeyGenerator is used in other contexts, and we cannot change its
output... even if it does accidentally default to generating excess key
material for our primary internal usage.
2016-07-01 01:01:45 +09:30
Vipul A M 8ee269cf51
We default to using aes-256-cbc as our verification/signing cipher. It can accept key lengths of 128, 192 or 256-bit, whereas currently we were providing twice the acceptable value.
ruby < 2.4 allowed accepting these values, as extra key bits were ignored. Since ce635262f5 this now has a strict checking on key length.

Default to key length 32 bytes, to match the compatible length for  aes-256-cbc

Fixes #25185
2016-06-27 17:43:55 -07:00
Eugene Gilburg 3b9cc0a56f missing activesupport test coverage 2014-07-19 17:15:40 -07:00
Michael Koziarski def2ccb8e3 Add ActiveSupport::KeyGenerator as a simple wrapper around PBKDF2
This will be used to derive keys from the secret and a salt, in order to allow us to
do things like encrypted cookie stores without using the secret for multiple
purposes directly.
2012-10-01 14:22:19 +13:00