@@ -14,7 +14,6 @@ local FFI_OK = base.FFI_OK
1414local FFI_AGAIN = base .FFI_AGAIN
1515local FFI_NO_REQ_CTX = base .FFI_NO_REQ_CTX
1616local get_request = base .get_request
17- local new_tab = base .new_tab
1817local clear_tab = base .clear_tab
1918local error = error
2019local assert = assert
@@ -50,12 +49,11 @@ local errmsg = base.get_errmsg_ptr()
5049local session_ptr = ffi .new (" void *[1]" )
5150local server_name_str = ffi .new (" ngx_str_t[1]" )
5251local openssl_error_code = ffi .new (" int[1]" )
53- local cached_options = new_tab (0 , 4 )
5452
5553local function setclientcert (self , cert , pkey )
5654 if not cert or not pkey then
5755 self [SOCKET_CLIENT_CERT_INDEX ] = nil
58- self [SOCKET_CLIENT_PRIV_INDEX ] = nil
56+ self [SOCKET_CLIENT_PKEY_INDEX ] = nil
5957 return
6058 end
6159
@@ -68,27 +66,27 @@ local function setclientcert(self, cert, pkey)
6866 end
6967
7068 self [SOCKET_CLIENT_CERT_INDEX ] = cert
71- self [SOCKET_CLIENT_PRIV_INDEX ] = pkey
69+ self [SOCKET_CLIENT_PKEY_INDEX ] = pkey
7270end
7371
74- local function tlshandshake (self , options )
75- if not options then
76- clear_tab (cached_options )
77- options = cached_options
7872
79- elseif type (options ) ~= " table" then
80- error (" bad options arg: table expected" , 2 )
73+ local function sslhandshake (self , reused_session , server_name , ssl_verify ,
74+ send_status_req , ...)
75+
76+ local n = select (" #" , ... )
77+ if not self or n > 1 then
78+ error (" ngx.socket sslhandshake: expecting 1 ~ 5 arguments " ..
79+ " (including the object), but seen " .. (self and 5 + n or 0 ))
8180 end
8281
8382 local r = get_request ()
8483 if not r then
8584 error (" no request found" , 2 )
8685 end
8786
88- local reused_session = options .reused_session
8987 session_ptr [0 ] = type (reused_session ) == " cdata" and reused_session or nil
9088
91- if options . server_name then
89+ if server_name then
9290 server_name_str [0 ].data = options .server_name
9391 server_name_str [0 ].len = # options .server_name
9492
@@ -97,31 +95,16 @@ local function tlshandshake(self, options)
9795 server_name_str [0 ].len = 0
9896 end
9997
100- local client_cert = options .client_cert
101- local client_pkey = options .client_priv_key
102- if client_cert then
103- if not client_pkey then
104- error (" client certificate supplied without corresponding " ..
105- " private key" , 2 )
106- end
107-
108- if type (client_cert ) ~= " cdata" then
109- error (" bad client_cert option type" , 2 )
110- end
111-
112- if type (client_pkey ) ~= " cdata" then
113- error (" bad client_priv_key option type" , 2 )
114- end
115- end
116-
117- local u = self [SOCKET_CTX_INDEX ]
98+ local u = self [SOCKET_CTX_INDEX ]
99+ local client_cert = self [SOCKET_CLIENT_CERT_INDEX ]
100+ local client_pkey = self [SOCKET_CLIENT_PKEY_INDEX ]
118101
119- local rc = C .ngx_http_lua_ffi_socket_tcp_tlshandshake (r , u ,
102+ local rc = C .ngx_http_lua_ffi_socket_tcp_sslhandshake (r , u ,
120103 session_ptr [0 ],
121104 reused_session ~= false ,
122105 server_name_str ,
123- options . verify and 1 or 0 ,
124- options . ocsp_status_req and 1 or 0 ,
106+ ssl_verify and 1 or 0 ,
107+ send_status_req and 1 or 0 ,
125108 client_cert , client_pkey , errmsg )
126109
127110 if rc == FFI_NO_REQ_CTX then
@@ -146,7 +129,7 @@ local function tlshandshake(self, options)
146129 return true
147130 end
148131
149- rc = C .ngx_http_lua_ffi_socket_tcp_get_tlshandshake_result (r , u ,
132+ rc = C .ngx_http_lua_ffi_socket_tcp_get_sslhandshake_result (r , u ,
150133 session_ptr , errmsg , openssl_error_code )
151134
152135 assert (rc == FFI_OK )
@@ -155,70 +138,19 @@ local function tlshandshake(self, options)
155138 return nil
156139 end
157140
158- return ffi_gc (session_ptr [0 ], C .ngx_http_lua_ffi_tls_free_session )
141+ return ffi_gc (session_ptr [0 ], C .ngx_http_lua_ffi_ssl_free_session )
159142 end
160143
161144 assert (rc == FFI_AGAIN )
162145
163146 co_yield ()
164147
165- rc = C .ngx_http_lua_ffi_socket_tcp_get_tlshandshake_result (r , u ,
148+ rc = C .ngx_http_lua_ffi_socket_tcp_get_sslhandshake_result (r , u ,
166149 session_ptr , errmsg , openssl_error_code )
167150 end
168151end
169152
170153
171- local function sslhandshake (self , reused_session , server_name , ssl_verify ,
172- send_status_req , ...)
173-
174- local n = select (" #" , ... )
175- if not self or n > 1 then
176- error (" ngx.socket sslhandshake: expecting 1 ~ 5 arguments " ..
177- " (including the object), but seen " .. (self and 5 + n or 0 ))
178- end
179-
180- cached_options .reused_session = reused_session
181- cached_options .server_name = server_name
182- cached_options .verify = ssl_verify
183- cached_options .ocsp_status_req = send_status_req
184-
185- local r = get_request ()
186- if not r then
187- error (" no request found" , 2 )
188- end
189-
190- session_ptr [0 ] = type (reused_session ) == " cdata" and reused_session or nil
191-
192- if server_name then
193- server_name_str [0 ].data = options .server_name
194- server_name_str [0 ].len = # options .server_name
195-
196- else
197- server_name_str [0 ].data = nil
198- server_name_str [0 ].len = 0
199- end
200-
201- local client_cert = options .client_cert
202- local client_pkey = options .client_priv_key
203- if client_cert then
204- if not client_pkey then
205- error (" client certificate supplied without corresponding " ..
206- " private key" , 2 )
207- end
208-
209- if type (client_cert ) ~= " cdata" then
210- error (" bad client_cert option type" , 2 )
211- end
212-
213- if type (client_pkey ) ~= " cdata" then
214- error (" bad client_priv_key option type" , 2 )
215- end
216- end
217-
218- return res , err
219- end
220-
221-
222154do
223155 local old_socket_tcp = ngx .socket .tcp
224156
0 commit comments