Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: added the ngx.ssl.session module for the contexts ssl_sessio…
…n_fetch_by_lua* and ssl_session_store_by_lua*. thanks Zi Lin for the patches.
- Loading branch information
Showing
6 changed files
with
1,078 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
local _M = {} | ||
|
||
|
||
local ffi = require "ffi" | ||
local base = require "resty.core.base" | ||
|
||
|
||
local C = ffi.C | ||
local ffi_str = ffi.string | ||
local getfenv = getfenv | ||
local error = error | ||
local errmsg = base.get_errmsg_ptr() | ||
local get_string_buf = base.get_string_buf | ||
local FFI_ERROR = base.FFI_ERROR | ||
|
||
|
||
ffi.cdef[[ | ||
int ngx_http_lua_ffi_ssl_set_serialized_session(ngx_http_request_t *r, | ||
const unsigned char *buf, int len, char **err); | ||
|
||
int ngx_http_lua_ffi_ssl_get_serialized_session(ngx_http_request_t *r, | ||
char *buf, char **err); | ||
|
||
int ngx_http_lua_ffi_ssl_get_session_id(ngx_http_request_t *r, | ||
char *buf, char **err); | ||
|
||
int ngx_http_lua_ffi_ssl_get_serialized_session_size(ngx_http_request_t *r, | ||
char **err); | ||
|
||
int ngx_http_lua_ffi_ssl_get_session_id_size(ngx_http_request_t *r, | ||
char **err); | ||
]] | ||
|
||
|
||
-- return session, err | ||
function _M.get_serialized_session() | ||
local r = getfenv(0).__ngx_req | ||
if not r then | ||
return error("no request found") | ||
end | ||
|
||
local len = C.ngx_http_lua_ffi_ssl_get_serialized_session_size(r, errmsg) | ||
|
||
if len < 0 then | ||
return nil, ffi_str(errmsg[0]) | ||
end | ||
|
||
if len > 4096 then | ||
return nil, "session too big to serialize" | ||
end | ||
local buf = get_string_buf(len) | ||
|
||
local rc = C.ngx_http_lua_ffi_ssl_get_serialized_session(r, buf, errmsg) | ||
|
||
if rc == FFI_ERROR then | ||
return nil, ffi_str(errmsg[0]) | ||
end | ||
|
||
return ffi_str(buf, len) | ||
end | ||
|
||
|
||
-- return session_id, err | ||
function _M.get_session_id() | ||
local r = getfenv(0).__ngx_req | ||
if not r then | ||
return error("no request found") | ||
end | ||
|
||
local len = C.ngx_http_lua_ffi_ssl_get_session_id_size(r, errmsg) | ||
|
||
if len < 0 then | ||
return nil, ffi_str(errmsg[0]) | ||
end | ||
|
||
local buf = get_string_buf(len) | ||
|
||
local rc = C.ngx_http_lua_ffi_ssl_get_session_id(r, buf, errmsg) | ||
|
||
if rc == FFI_ERROR then | ||
return nil, ffi_str(errmsg[0]) | ||
end | ||
|
||
return ffi_str(buf, len) | ||
end | ||
|
||
|
||
-- return ok, err | ||
function _M.set_serialized_session(sess) | ||
local r = getfenv(0).__ngx_req | ||
if not r then | ||
return error("no request found") | ||
end | ||
|
||
local rc = C.ngx_http_lua_ffi_ssl_set_serialized_session(r, sess, #sess, | ||
errmsg) | ||
if rc == FFI_ERROR then | ||
return nil, ffi_str(errmsg[0]) | ||
end | ||
|
||
return true | ||
end | ||
|
||
|
||
return _M |
Oops, something went wrong.