Module: Cookies::Parse

Extended by:
Parse
Included in:
Parse
Defined in:
lib/brevio/session/cookies/parse.rb

Instance Method Summary collapse

Instance Method Details

#perform!(cookie) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/brevio/session/cookies/parse.rb', line 7

def perform!(cookie)
  raise NilSession if cookie.nil?
  data, iv, auth_tag = cookie.split('--').map { |value| Base64.decode64(value) }
  cipher = OpenSSL::Cipher.new(CIPHER)
  secret = OpenSSL::PKCS5.pbkdf2_hmac_sha1(brevio_config.encryption_key,
                                           SALT, 1000, cipher.key_len)

  cipher.decrypt
  cipher.key = secret
  cipher.iv  = iv
  cipher.auth_tag = auth_tag
  cipher.auth_data = ''

  cookie_payload = cipher.update(data)
  cookie_payload << cipher.final
  cookie_payload = JSON.parse(cookie_payload)
  key = JSON.parse(Base64.decode64(cookie_payload['_rails']['message']))

  "#{Config::Redis::Prefixes::SESSION}:#{key}"
end