@@ -42,6 +42,7 @@ local ngx_lua_ffi_socket_tcp_setoption
4242local ngx_lua_ffi_socket_getfd
4343local ngx_lua_ffi_socket_getsslpointer
4444local ngx_lua_ffi_socket_getsslctx
45+ local ngx_lua_ffi_socket_tcp_settrustedstore
4546
4647if subsystem == ' http' then
4748ffi .cdef [[
@@ -103,6 +104,13 @@ if pcall(function() return C.ngx_http_lua_ffi_socket_tcp_get_ssl_ctx end) then
103104ngx_lua_ffi_socket_getsslctx = C .ngx_http_lua_ffi_socket_tcp_get_ssl_ctx
104105end
105106
107+ if pcall (function ()
108+ return C .ngx_http_lua_ffi_socket_tcp_settrustedstore
109+ end ) then
110+ ngx_lua_ffi_socket_tcp_settrustedstore =
111+ C .ngx_http_lua_ffi_socket_tcp_settrustedstore
112+ end
113+
106114
107115elseif subsystem == ' stream' then
108116
128136ngx_stream_lua_ffi_socket_tcp_get_ssl_ctx (ngx_stream_lua_request_t * r ,
129137 ngx_stream_lua_socket_tcp_upstream_t * u , void ** pctx ,
130138 char ** errmsg );
139+
140+ int
141+ ngx_stream_lua_ffi_socket_tcp_settrustedstore (ngx_stream_lua_request_t * r ,
142+ ngx_stream_lua_socket_tcp_upstream_t * u , void * store , char ** errmsg );
131143]]
132144
133145ngx_lua_ffi_socket_tcp_getoption = C .ngx_stream_lua_ffi_socket_tcp_getoption
@@ -142,6 +154,13 @@ if pcall(function() return C.ngx_stream_lua_ffi_socket_tcp_get_ssl_pointer end)
142154then
143155ngx_lua_ffi_socket_getsslctx = C .ngx_stream_lua_ffi_socket_tcp_get_ssl_pointer
144156end
157+
158+ if pcall (function ()
159+ return C .ngx_stream_lua_ffi_socket_tcp_settrustedstore
160+ end ) then
161+ ngx_lua_ffi_socket_tcp_settrustedstore =
162+ C .ngx_stream_lua_ffi_socket_tcp_settrustedstore
163+ end
145164end
146165
147166
@@ -298,6 +317,38 @@ local function getsslctx(cosocket)
298317end
299318
300319
320+ local NULL_STORE = ffi_new (" void *" , nil )
321+
322+
323+ local function settrustedstore (cosocket , store )
324+ if not ngx_lua_ffi_socket_tcp_settrustedstore then
325+ return nil , " tcpsock:settrustedstore is not supported by "
326+ .. " the current nginx module"
327+ end
328+
329+ if store ~= nil and type (store ) ~= " cdata" then
330+ return nil , " bad store arg: cdata expected, got " .. type (store )
331+ end
332+
333+ local r = get_request ()
334+ if not r then
335+ error (" no request found" , 2 )
336+ end
337+
338+ local u = get_tcp_socket (cosocket )
339+
340+ local rc = ngx_lua_ffi_socket_tcp_settrustedstore (r , u ,
341+ store or NULL_STORE ,
342+ errmsg )
343+ if rc ~= FFI_OK then
344+ return nil , ffi_str (errmsg [0 ])
345+ end
346+
347+ cosocket [SOCKET_TRUSTED_STORE_INDEX ] = store
348+
349+ return true
350+ end
351+
301352
302353if subsystem == ' http' then
303354local server_name_str = ffi_new (" ngx_str_t[1]" )
@@ -332,48 +383,6 @@ local function setclientcert(cosocket, cert, pkey)
332383end
333384
334385
335- local ngx_lua_ffi_socket_tcp_settrustedstore
336- if pcall (function ()
337- return C .ngx_http_lua_ffi_socket_tcp_settrustedstore
338- end ) then
339- ngx_lua_ffi_socket_tcp_settrustedstore =
340- C .ngx_http_lua_ffi_socket_tcp_settrustedstore
341- end
342-
343-
344- local NULL_STORE = ffi_new (" void *" , nil )
345-
346-
347- local function settrustedstore (cosocket , store )
348- if not ngx_lua_ffi_socket_tcp_settrustedstore then
349- return nil , " tcpsock:settrustedstore is not supported by " ..
350- " the current lua-nginx-module"
351- end
352-
353- if store ~= nil and type (store ) ~= " cdata" then
354- return nil , " bad store arg: cdata expected, got " .. type (store )
355- end
356-
357- local r = get_request ()
358- if not r then
359- error (" no request found" , 2 )
360- end
361-
362- local u = get_tcp_socket (cosocket )
363-
364- local rc = ngx_lua_ffi_socket_tcp_settrustedstore (r , u ,
365- store or NULL_STORE ,
366- errmsg )
367- if rc ~= FFI_OK then
368- return nil , ffi_str (errmsg [0 ])
369- end
370-
371- cosocket [SOCKET_TRUSTED_STORE_INDEX ] = store
372-
373- return true
374- end
375-
376-
377386local function sslhandshake (cosocket , reused_session , server_name , ssl_verify ,
378387 send_status_req , ...)
379388
520529 method_table .getfd = getfd
521530 method_table .getsslpointer = getsslpointer
522531 method_table .getsslctx = getsslctx
532+ if ngx_lua_ffi_socket_tcp_settrustedstore then
533+ method_table .settrustedstore = settrustedstore
534+ end
523535
524536 method_table = registry .__tcp_raw_req_cosocket_mt
525537 method_table .getfd = getfd
0 commit comments