Commit Graph

41 Commits

Author SHA1 Message Date
Michael Coyne
39f8ca64ce Add key rotation message Encryptor and Verifier
Both classes now have a rotate method where new instances are added for
each call. When decryption or verification fails the next rotation
instance is tried.
2017-09-23 17:16:21 -04:00
Assain
3b506ee0d8 Add expires_at, expires_in, and purpose meta_data to messages. 2017-07-19 17:19:16 +05:30
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 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Michael Coyne
51b090549b Updates to MessageEncryptor AEAD tests 2017-05-15 08:55:46 +00:00
Michael Coyne
71fb6def5f Fix for AEAD auth_tag check in MessageEncryptor
When MessageEncryptor tries to +decrypt_and_verify+ ciphertexts
generated in a different mode (such CBC-HMAC), the +auth_tag+ may be
+nil+ and must explicitly check for it.

See the discussion here:
https://github.com/rails/rails/pull/28132#discussion_r116388462
2017-05-15 08:54:39 +00:00
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Vipul A M
79c847892f
Start passing cipher from EncryptedCookieJar since we use it to determine key length 2016-09-01 03:00:10 +05:30
Vipul A M
ae32b69ab9
Follow up of #25602
Since keys are truncated, ruby 2.4 doesn't accept keys greater than their lenghts.
keys of same value but different lenght and greater than key size of cipher, produce the same results
as reproduced at https://gist.github.com/rhenium/b81355fe816dcfae459cc5eadfc4f6f9
Since our default cipher is 'aes-256-cbc', key length for which is 32 bytes, limit the length of key being passed to Encryptor to 32 bytes.
This continues to support backwards compat with any existing signed data, already encrupted and signed with 32+ byte keys.
Also fixes the passing of this value in multiple tests.
2016-09-01 02:53:48 +05:30
Xavier Noria
80e66cc4d9 normalizes indentation and whitespace across the project 2016-08-06 20:16:27 +02:00
Xavier Noria
411ccbdab2 remove redundant curlies from hash arguments 2016-08-06 19:44:11 +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
Bart de Water
d4ea18a8cb
Allow MessageEncryptor to take advantage of authenticated encryption modes
AEAD modes like `aes-256-gcm` provide both confidentiality and data authenticity, eliminating the need to use MessageVerifier to check if the encrypted data has been tampered with.

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-07-21 10:38:33 -07:00
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
claudiob
e428ddecec Remove "rescue" clause around "require 'openssl'"
Some `require 'openssl'` statements were surrounded by `rescue` blocks to deal with Ruby versions that did not support `OpenSSL::Digest::SHA1` or `OpenSSL::PKCS5`.

[As @jeremy explains](a6a0904fcb (commitcomment-8826666)) in the original commit:

> If jruby didn't have jruby-openssl gem, the require wouldn't work. Not sure whether either of these are still relevant today.

According to the [release notes for JRuby 1.7.13](http://www.jruby.org/2014/06/24/jruby-1-7-13.html):

> jruby-openssl 0.9.5 bundled

which means the above `rescue` block is not needed anymore.

All the Ruby versions supported by the current version of Rails provide those OpenSSL libraries, so Travis CI should also be happy by removing the `rescue` blocks.

---

Just to confirm, with JRuby:

    $ ruby --version #=> jruby 1.7.16.1 (1.9.3p392) 2014-10-28 4e93f31 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_20-b26 +jit [darwin-x86_64]
    $ irb
    irb(main):001:0> require 'openssl' #=> true
    irb(main):002:0> OpenSSL::Digest::SHA1 #=> OpenSSL::Digest::SHA1
    irb(main):003:0> OpenSSL::PKCS5 # => OpenSSL::PKCS5

And with Ruby 2.1:

    $ ruby --version #=> ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
    $ irb
    irb(main):001:0> require 'openssl' #=> true
    irb(main):002:0> OpenSSL::Digest::SHA1 #=> OpenSSL::Digest::SHA1
    irb(main):003:0> OpenSSL::PKCS5 #=> OpenSSL::PKCS5
2014-12-03 21:58:02 -08:00
Jeremy Kemper
8ef1ef1b82 Merge pull request #10635 from vipulnsward/change_to_strict
Use `Base.strict_decode64` instead of `Base.decode64`
2013-12-06 08:08:28 -08:00
Ryan Glover
a64d4e85e3 Standardize all JSON encoded times to use 3 decimal fractional seconds 2013-11-07 10:43:51 -05:00
Vipul A M
a4e1e5d632 Use Base.strict_decode64 instead of Base.decode64 just as we do in encoding;
Also reduce extra object allocation by creating string directly instead of join on Array
2013-05-16 02:19:33 +05:30
Ryan Davis
adc049b06f Fixed bad tests to clean up after themselves. 2013-05-03 15:37:18 -07:00
Ezekiel Smithburg
77828e20fc s/messqage/message/ in message_encryptor_test.rb 2013-01-09 13:32:35 -08:00
Santiago Pastorino
38c40dbbc1 Add cookie.encrypted which returns an EncryptedCookieJar
How to use it?

cookies.encrypted[:discount] = 45
=> Set-Cookie: discount=ZS9ZZ1R4cG1pcUJ1bm80anhQang3dz09LS1mbDZDSU5scGdOT3ltQ2dTdlhSdWpRPT0%3D--ab54663c9f4e3bc340c790d6d2b71e92f5b60315; path=/
cookies.encrypted[:discount]
=> 45
2012-11-03 14:57:53 -02:00
Sergey Nartimov
0f2f8003d2 remove ActiveSupport::Base64 in favor of ::Base64 2012-01-02 22:48:15 +03:00
Vasiliy Ermolovich
a19d0f5a66 deprecate Base64.encode64s from AS. Use Base64.strict_encode64 instead 2011-12-27 22:46:44 +03:00
José Valim
6a6fc4e1db Remove deprecations from Active Support. 2011-12-20 15:18:42 +01:00
José Valim
a625523e75 Don't marshal dump twice when using encryptor. 2011-11-09 20:21:52 -02:00
José Valim
71e84a3b51 Deprecated ActiveSupport::MessageEncryptor#encrypt and decrypt. 2011-11-09 20:04:42 -02:00
Willem van Bergen
6d520803ee Test deprecation warning when not using an options hash as second parameter. 2011-09-15 15:51:30 -04:00
Willem van Bergen
41fea03342 Use an options hash to specify digest/cipher algorithm and a serializer for MessageVerifier and MessageEncryptor. 2011-09-15 14:27:12 -04:00
Willem van Bergen
db040cdf8b Implement API suggestions of pull request. 2011-09-15 13:15:21 -04:00
Willem van Bergen
a8aaef6762 Fixed tests so that they will also run properly in other timezones. 2011-09-15 09:50:39 -04:00
Willem van Bergen
bffaa888ac Custom serializers and deserializers in MessageVerifier and MessageEncryptor.
By default, these classes use Marshal for serializing and deserializing messages. Unfortunately, the Marshal format is closely associated with Ruby internals and even changes between different interpreters. This makes the resulting message very hard to impossible to unserialize messages generated by these classes in other environments like node.js.

This patch solves this by allowing you to set your own custom serializer and deserializer lambda functions. By default, it still uses Marshal to be backwards compatible.
2011-09-15 08:28:53 -04:00
Jon Leighton
d411c85a65 Replace references to ActiveSupport::SecureRandom with just SecureRandom, and require 'securerandom' from the stdlib when active support is required. 2011-05-23 20:25:44 +01:00
Santiago Pastorino
b451de0d6d Deletes trailing whitespaces (over text files only find * -type f -exec sed 's/[ \t]*$//' -i {} \;) 2010-08-14 04:12:33 -03:00
Marius Nuennerich
35598db01a repair the activesupport message encryptor tests for me, do so in the same way as jeremy did with message verifier
[#4517 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-05-01 10:04:01 -07:00
Jeremy Kemper
41e7c68d87 Ruby 1.9.2: marshaling round-trips Time#zone 2010-03-28 22:52:08 -07:00
Jeremy Kemper
bc1538e995 Repair time dependencies 2009-11-14 11:37:06 -08:00
Jeremy Kemper
1c36172c13 Ruby 1.9 compat: rename deprecated assert_raises to assert_raise.
[#1617 state:resolved]
2009-03-08 13:11:58 -07:00
Michael Koziarski
07abc5efe1 Add a MessageEncryptor, just like MessageVerifier but using symmetric key encryption.
The use of encryption prevents people from seeing any potentially secret values you've used.  It also supports and encrypt_and_sign model to prevent people from tampering with the bits and creating random junk that gets fed to

A motivated coder could use this to add an :encrypt=>true option to the cookie store.
2008-11-25 20:51:30 +01:00