@@ -71,6 +71,10 @@ ngx_http_lua_ffi_ssl_free_session(void *sess);
7171int
7272ngx_http_lua_ffi_socket_tcp_getfd (ngx_http_request_t * r ,
7373 ngx_http_lua_socket_tcp_upstream_t * u , char ** errmsg );
74+ int
75+ ngx_http_lua_socket_tcp_get_ssl_session (ngx_http_request_t * r ,
76+ ngx_http_lua_socket_tcp_upstream_t * u , void ** sess ,
77+ char ** errmsg );
7478]]
7579
7680ngx_lua_ffi_socket_tcp_getoption = C .ngx_http_lua_ffi_socket_tcp_getoption
102106
103107
104108local output_value_buf = ffi_new (" int[1]" )
109+ local session_ptr = ffi_new (" void *[1]" )
105110local ERR_BUF_SIZE = 4096
106111
107112local FFI_OK = base .FFI_OK
211216
212217
213218if subsystem == ' http' then
214- local session_ptr = ffi_new (" void *[1]" )
215219local server_name_str = ffi_new (" ngx_str_t[1]" )
216220local openssl_error_code = ffi_new (" int[1]" )
217221
@@ -334,6 +338,26 @@ local function sslhandshake(cosocket, reused_session, server_name, ssl_verify,
334338end
335339
336340
341+ local function getsslsession (cosocket )
342+ if not cosocket then
343+ error (" ngx.socket getfd: expecting the cosocket object, but seen none" )
344+ end
345+
346+ local r = get_request ()
347+ if not r then
348+ error (" no request found" )
349+ end
350+
351+ local u = get_tcp_socket (cosocket )
352+ local rc = C .ngx_http_lua_socket_tcp_get_ssl_session (r , u ,
353+ session_ptr , errmsg )
354+ if rc == FFI_ERROR then
355+ return nil , ffi_str (errmsg [0 ])
356+ end
357+
358+ return ffi_gc (session_ptr [0 ], C .ngx_http_lua_ffi_ssl_free_session )
359+ end
360+
337361do
338362 local method_table = registry .__tcp_cosocket_mt
339363 method_table .getoption = getoption
343367 method_table .getfd = getfd
344368 method_table .getoption = getoption
345369 method_table .setoption = setoption
370+ method_table .getsslsession = getsslsession
346371
347372 method_table = registry .__tcp_req_cosocket_mt
348373 method_table .getfd = getfd
0 commit comments