Skip to content

Commit dbad0d1

Browse files
committed
Release 2.18. Fix #40.
1 parent 01d705b commit dbad0d1

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

Changes.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to `lua-resty-session` will be documented in this file.
44

5+
## [2.18] - 2017-07-10
6+
### Fixed
7+
- Automatically creates exactly 64 bits salt as required by the latest
8+
lua-resty-string.
9+
See also: https://github.com/bungle/lua-resty-session/issues/40
10+
Thanks @peturorri
11+
512
## [2.17] - 2017-06-12
613
### Added
714
- Added session.hide() function to hide session cookies from upstream

lib/resty/session.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ local function init()
203203
end
204204

205205
local session = {
206-
_VERSION = "2.17"
206+
_VERSION = "2.18"
207207
}
208208

209209
session.__index = session

lib/resty/session/ciphers/aes.lua

+20-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ local tonumber = tonumber
33
local aes = require "resty.aes"
44
local cip = aes.cipher
55
local hashes = aes.hash
6+
local ceil = math.ceil
67
local var = ngx.var
8+
local sub = string.sub
9+
local rep = string.rep
10+
711

812
local CIPHER_MODES = {
913
ecb = "ecb",
@@ -28,6 +32,19 @@ local defaults = {
2832
rounds = tonumber(var.session_aes_rounds) or 1
2933
}
3034

35+
local function salt(s)
36+
if s then
37+
local z = #s
38+
if z < 8 then
39+
return sub(rep(s, ceil(8 / z), 1, 8))
40+
end
41+
if z > 8 then
42+
return sub(s, 1, 8)
43+
end
44+
return s
45+
end
46+
end
47+
3148
local cipher = {}
3249

3350
cipher.__index = cipher
@@ -43,11 +60,11 @@ function cipher.new(config)
4360
end
4461

4562
function cipher:encrypt(d, k, s)
46-
return aes:new(k, s, cip(self.size, self.mode), self.hash, self.rounds):encrypt(d)
63+
return aes:new(k, salt(s), cip(self.size, self.mode), self.hash, self.rounds):encrypt(d)
4764
end
4865

4966
function cipher:decrypt(d, k, s)
50-
return aes:new(k, s, cip(self.size, self.mode), self.hash, self.rounds):decrypt(d)
67+
return aes:new(k, salt(s), cip(self.size, self.mode), self.hash, self.rounds):decrypt(d)
5168
end
5269

53-
return cipher
70+
return cipher

0 commit comments

Comments
 (0)