Class: ActionDispatch::Session::EncryptedCookieStore

Inherits:
CookieStore
  • Object
show all
Defined in:
lib/encrypted_cookie_store.rb

Constant Summary collapse

EXPIRE_AFTER_KEY =
"encrypted_cookie_store.session_expire_after"
OpenSSLCipherError =
OpenSSL::Cipher.const_defined?(:CipherError) ? OpenSSL::Cipher::CipherError : OpenSSL::CipherError

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ EncryptedCookieStore



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/encrypted_cookie_store.rb', line 24

def initialize(app, options = {})
  @logger = options.delete(:logger)
  @digest = options.delete(:digest) || 'SHA1'

  @compress = options[:compress]
  @compress = true if @compress.nil?

  @secret = options.delete(:secret)
  @secret = @secret.call if @secret.respond_to?(:call)
  @secret.freeze
  @encryption_key = unhex(@secret).freeze
  ensure_encryption_key_secure

  @allow_legacy_hmac = options[:allow_legacy_hmac]

  @data_cipher = OpenSSL::Cipher::Cipher.new(EncryptedCookieStore.data_cipher_type)
  options[:refresh_interval] ||= 5.minutes

  super(app, options)
end

Class Attribute Details

.data_cipher_typeObject

Returns the value of attribute data_cipher_type.



16
17
18
# File 'lib/encrypted_cookie_store.rb', line 16

def data_cipher_type
  @data_cipher_type
end

Instance Method Details

#call(env) ⇒ Object



45
46
47
48
# File 'lib/encrypted_cookie_store.rb', line 45

def call(env)
  @expire_after = env[EXPIRE_AFTER_KEY]
  super
end

#load_session(env) ⇒ Object

overrides method in Rack::Session::Cookie



51
52
53
54
55
56
# File 'lib/encrypted_cookie_store.rb', line 51

def load_session(env)
  if time = timestamp(env)
    env['encrypted_cookie_store.session_refreshed_at'] ||= Time.at(time).utc
  end
  super
end