Skip to content

Commit 1cf312f

Browse files
committed
Release 2.2, fixing issue #18.
1 parent fbc1057 commit 1cf312f

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

CHANGES

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
Changes with lua-resty-session 2.2 17 Sep 2015
2+
3+
*) Change: Removed all session_cipher_* deprecated settings
4+
(it was somewhat broken in 2.1).
5+
6+
*) Change: Changed session secret to be by default 32 bytes random data
7+
8+
See Also: https://github.com/bungle/lua-resty-session/issues/18
9+
10+
Thanks @iain-buclaw-sociomantic
11+
12+
*) Documentation: Added documentation about removed features and
13+
corrected about session secret size accordingly.
14+
115
Changes with lua-resty-session 2.1 7 Sep 2015
216

317
*) Feature: Added architecture for Cipher adapter plugins.

README.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ pluggable cipher adapters. You can also disable encryption by choosing `none` ad
102102

103103
Session identifier length is by default 16 bytes (randomly generated data with OpenSSL
104104
`RAND_pseudo_bytes` function). The server secret is also generated by default with this same
105-
function, and its length is determined by calculating the used `$session_aes_size` divided
106-
by 8 (so by default it uses 32 bytes). This will work until Nginx is restarted, but you might want
107-
to consider setting your own secret using `set $session_secret 623q4hR325t36VsCD3g567922IC0073T;`,
105+
function and it's default length is 32 bytes. This will work until Nginx is restarted, but you
106+
might want to consider setting your own secret using `set $session_secret 623q4hR325t36VsCD3g567922IC0073T;`,
108107
for example (this will work in farms installations as well, but you are then responsible for
109108
rotating the secret). On farm installations you should also configure other session configuration
110109
variables the same on all the servers in the farm.
@@ -745,28 +744,28 @@ as where the original cookie was delivered. This check is disabled by default.
745744
`session.check.scheme` is additional check to validate that the request was made using the same protocol
746745
as the one used when the original cookie was delivered. This check is enabled by default.
747746

748-
#### number session.cipher.size (deprecated in 2.1, use session.aes.size)
747+
#### number session.cipher.size (deprecated in 2.1 and removed in 2.2, use session.aes.size)
749748

750749
`session.cipher.size` holds the size of the cipher (`lua-resty-string` supports AES in `128`, `192`,
751750
and `256` bits key sizes). See `aes.cipher` function in `lua-resty-string` for more information.
752751
By default this will use `256` bits key size. This can be configured with Nginx
753752
`set $session_cipher_size 256;`.
754753

755-
#### string session.cipher.mode (deprecated in 2.1, use session.aes.mode)
754+
#### string session.cipher.mode (deprecated in 2.1 and removed in 2.2, use session.aes.mode)
756755

757756
`session.cipher.mode` holds the mode of the cipher. `lua-resty-string` supports AES in `ecb`, `cbc`,
758757
`cfb1`, `cfb8`, `cfb128`, `ofb`, and `ctr` modes (ctr mode is not available with 256 bit keys).
759758
See `aes.cipher` function in `lua-resty-string` for more information. By default `cbc` mode is
760759
used. This can be configured with Nginx `set $session_cipher_mode cbc;`.
761760

762-
#### function session.cipher.hash (deprecated in 2.1, use session.aes.hash)
761+
#### function session.cipher.hash (deprecated in 2.1 and removed in 2.2, use session.aes.hash)
763762

764763
`session.cipher.hash` is used in ecryption key, and iv derivation (see: OpenSSL
765764
[EVP_BytesToKey](https://www.openssl.org/docs/crypto/EVP_BytesToKey.html)). By default `sha512` is
766765
used but `md5`, `sha1`, `sha224`, `sha256`, and `sha384` are supported as well in `lua-resty-string`.
767766
This can be configured with Nginx `set $session_cipher_hash sha512;`.
768767

769-
#### number session.cipher.rounds (deprecated in 2.1, use session.aes.rounds)
768+
#### number session.cipher.rounds (deprecated in 2.1 and removed in 2.2, use session.aes.rounds)
770769

771770
`session.cipher.rounds` can be used to slow-down the encryption key, and iv derivation. By default
772771
this is set to `1` (the fastest). This can be configured with Nginx `set $session_cipher_rounds 1;`.
@@ -830,7 +829,7 @@ set $session_check_ua on;
830829
set $session_check_scheme on;
831830
set $session_check_addr off;
832831
set $session_identifier_length 16;
833-
# these are deprecated in 2.1, use session_aes_* instead
832+
# these are deprecated in 2.1 and removed in 2.2, use session_aes_* instead
834833
set $session_cipher_mode cbc;
835834
set $session_cipher_size 256;
836835
set $session_cipher_hash sha512;

lib/resty/session.lua

+7-12
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ local defaults = {
129129
length = tonumber(ngx_var.session_identifier_length) or 16
130130
}
131131
}
132-
defaults.secret = ngx_var.session_secret or random(defaults.cipher.size / 8)
132+
defaults.secret = ngx_var.session_secret or random(32)
133133

134134
local session = {
135-
_VERSION = "2.1"
135+
_VERSION = "2.2"
136136
}
137137

138138
session.__index = session
@@ -159,6 +159,10 @@ function session.new(opts)
159159
if not o then
160160
k = require "resty.session.encoders.base64"
161161
end
162+
local o, l = pcall(require, "resty.session.ciphers." .. (e or f))
163+
if not o then
164+
l = require "resty.session.ciphers.aes"
165+
end
162166
local self = {
163167
name = y.name or z.name,
164168
serializer = j,
@@ -173,7 +177,7 @@ function session.new(opts)
173177
domain = a.domain or b.domain,
174178
secure = a.secure or b.secure,
175179
httponly = a.httponly or b.httponly,
176-
delimiter = a.delimiter or b.delimiter,
180+
delimiter = a.delimiter or b.delimiter
177181
}, check = {
178182
ssi = c.ssi or d.ssi,
179183
ua = c.ua or d.ua,
@@ -184,15 +188,6 @@ function session.new(opts)
184188
}
185189
}
186190
self.storage = i.new(self)
187-
if type(e) == "table" then
188-
-- This is for backward compability
189-
self.aes = e
190-
e = "aes"
191-
end
192-
local o, l = pcall(require, "resty.session.ciphers." .. (e or f))
193-
if not o then
194-
l = require "resty.session.ciphers.aes"
195-
end
196191
self.cipher = l.new(self)
197192
return setmetatable(self, session)
198193
end

0 commit comments

Comments
 (0)