| PackageDescription | This module implements a secure way to encode session data. It is primarily
intended for storing session data in browser cookies, but could be used
with other backend storage where security of stored session data is
important.
Features include:
* Data serialization and compression using Sereal
* Data encryption using AES with a unique derived key per encoded session
* Enforced expiration timestamp (optional)
* Integrity protected with a message authentication code (MAC)
The storage protocol used in this module is based heavily on at
http://www.cse.msu.edu/~alexliu/publications/Cookie/Cookie_COMNET.pdf by
Alex Liu and others. Liu proposes a session cookie value as follows:
user|expiration|E(data,k)|HMAC(user|expiration|data|ssl-key,k)
where
| denotes concatenation with a separator character
E(p,q) is a symmetric encryption of p with key q
HMAC(p,q) is a keyed message hash of p with key q
k is HMAC(user|expiration, sk)
sk is a secret key shared by all servers
ssl-key is an SSL session key
Because SSL session keys are not readily available (and SSL termination may
happen prior to the application server), we omit 'ssl-key'. This weakens
protection against replay attacks if an attacker can break the SSL session
key and intercept messages.
Using 'user' and 'expiration' to generate the encryption and MAC keys was a
method proposed to ensure unique keys to defeat volume attacks against the
secret key. Rather than rely on those for uniqueness (with the unfortunate
side effect of revealing user names and prohibiting anonymous sessions), we
replace 'user' with a cryptographically-strong random salt value.
The original proposal also calculates a MAC based on unencrypted data. We
instead calculate the MAC based on the encrypted data. This avoids an extra
step decrypting invalid messages. Because the salt is already encoded into
the key, we omit it from the MAC input.
Therefore, the session storage protocol used by this module is as follows:
salt|expiration|E(data,k)|HMAC(expiration|E(data,k),k)
where
| denotes concatenation with a separator character
E(p,q) is a symmetric encryption of p with key q
HMAC(p,q) is a keyed message hash of p with key q
k is HMAC(salt, sk)
sk is a secret key shared by all servers
The salt value is generated using Math::Random::ISAAC::XS, seeded from
Crypt::URandom.
The HMAC algorithm is 'hmac_sha256' from Digest::SHA. Encryption is done by
Crypt::CBC using Crypt::Rijndael (AES). The ciphertext and MAC's in the
cookie are Base64 encoded by MIME::Base64 by default.
During session retrieval, if the MAC does not authenticate or if the
expiration is set and in the past, the session will be discarded. |