@@ -41,9 +41,9 @@ void ngx_http_lua_ffi_ssl_free_session(void *sess);
4141]]
4242
4343
44- local SOCKET_CTX_INDEX = 1
45- local SOCKET_CLIENT_CERT_INDEX = 6
46- local SOCKET_CLIENT_KEY_INDEX = 7
44+ local SOCKET_CTX_INDEX = 1
45+ local SOCKET_CLIENT_CERT_INDEX = 6
46+ local SOCKET_CLIENT_PKEY_INDEX = 7
4747
4848
4949local errmsg = base .get_errmsg_ptr ()
@@ -52,6 +52,25 @@ local server_name_str = ffi.new("ngx_str_t[1]")
5252local openssl_error_code = ffi .new (" int[1]" )
5353local cached_options = new_tab (0 , 4 )
5454
55+ local function setclientcert (cosocket , cert , pkey )
56+ if not cert or not pkey then
57+ cosocket [SOCKET_CLIENT_CERT_INDEX ] = nil
58+ cosocket [SOCKET_CLIENT_PRIV_INDEX ] = nil
59+
60+ return
61+ end
62+
63+ if type (cert ) ~= " cdata" then
64+ error (" bad client cert type" , 2 )
65+ end
66+
67+ if type (pkey ) ~= " cdata" then
68+ error (" bad client pkey type" , 2 )
69+ end
70+
71+ cosocket [SOCKET_CLIENT_CERT_INDEX ] = cert
72+ cosocket [SOCKET_CLIENT_PRIV_INDEX ] = pkey
73+ end
5574
5675local function tlshandshake (self , options )
5776 if not options then
181200 error (sock , 2 )
182201 end
183202
184- sock .tlshandshake = tlshandshake
185- sock .sslhandshake = sslhandshake
203+ sock .setclientcert = setclientcert
204+ sock .sslhandshake = sslhandshake
186205
187206 return sock
188207 end
0 commit comments