Skip to content

Commit 4462afd

Browse files
committed
1 parent eac2a10 commit 4462afd

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

lib/ngx/ssl/clienthello.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ if subsystem == 'http' then
3838

3939
int ngx_http_lua_ffi_ssl_set_protocols(ngx_http_request_t *r,
4040
int protocols, char **err);
41+
int ngx_http_lua_ffi_ssl_get_client_hello_ext_present(ngx_http_request_t *r,
42+
int **extensions, size_t *extensions_len, char **err);
4143
]]
4244

4345
ngx_lua_ffi_ssl_get_client_hello_server_name =
4446
C.ngx_http_lua_ffi_ssl_get_client_hello_server_name
4547
ngx_lua_ffi_ssl_get_client_hello_ext =
4648
C.ngx_http_lua_ffi_ssl_get_client_hello_ext
4749
ngx_lua_ffi_ssl_set_protocols = C.ngx_http_lua_ffi_ssl_set_protocols
50+
ngx_lua_ffi_ssl_get_client_hello_ext_present =
51+
C.ngx_http_lua_ffi_ssl_get_client_hello_ext_present
52+
4853

4954
elseif subsystem == 'stream' then
5055
ffi.cdef[[
@@ -102,6 +107,39 @@ function _M.get_client_hello_server_name()
102107
return nil, ffi_str(errmsg[0])
103108
end
104109

110+
-- return ext, err
111+
function _M.get_client_hello_ext_present()
112+
local r = get_request()
113+
if not r then
114+
error("no request found")
115+
end
116+
117+
if ngx_phase() ~= "ssl_client_hello" then
118+
error("API disabled in the current context")
119+
end
120+
121+
local sizep = get_size_ptr()
122+
local intp = ffi.new("int*[1]") -- array of len 1 of int pointers
123+
124+
local rc = ngx_lua_ffi_ssl_get_client_hello_ext_present(r, intp, sizep, errmsg)
125+
if rc == FFI_OK then -- Convert C array to Lua table
126+
local result = {}
127+
local array = intp[0] -- This is now a pointer to the first integer
128+
local size = tonumber(sizep[0])
129+
for i=0,size-1,1 do
130+
table_insert(result, array[i])
131+
end
132+
133+
return result, size
134+
end
135+
136+
-- NGX_DECLINED: no extension
137+
if rc == -5 then
138+
return nil
139+
end
140+
141+
return nil, ffi_str(errmsg[0])
142+
end
105143

106144
-- return ext, err
107145
function _M.get_client_hello_ext(ext_type)

0 commit comments

Comments
 (0)