Skip to content

Commit c0533ba

Browse files
committed
ngx_lua_ffi_ssl_get_client_hello_ciphers
1 parent 1065213 commit c0533ba

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

lib/ngx/ssl/clienthello.lua

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ local ngx_lua_ffi_ssl_get_client_hello_server_name
2828
local ngx_lua_ffi_ssl_get_client_hello_ext
2929
local ngx_lua_ffi_ssl_set_protocols
3030
local ngx_lua_ffi_ssl_get_client_hello_ext_present
31+
local ngx_lua_ffi_ssl_get_client_hello_ciphers
3132

3233

3334
if subsystem == 'http' then
@@ -45,6 +46,9 @@ if subsystem == 'http' then
4546
int ngx_http_lua_ffi_ssl_get_client_hello_ext_present(ngx_http_request_t *r,
4647
int **extensions, size_t *extensions_len, char **err);
4748
/* Undefined for the stream subsystem */
49+
int ngx_http_lua_ffi_ssl_get_client_hello_ciphers(ngx_http_request_t *r,
50+
int **ciphers, size_t *cipherslen, char **err);
51+
/* Undefined for the stream subsystem */
4852
]]
4953

5054
ngx_lua_ffi_ssl_get_client_hello_server_name =
@@ -54,6 +58,9 @@ if subsystem == 'http' then
5458
ngx_lua_ffi_ssl_set_protocols = C.ngx_http_lua_ffi_ssl_set_protocols
5559
ngx_lua_ffi_ssl_get_client_hello_ext_present =
5660
C.ngx_http_lua_ffi_ssl_get_client_hello_ext_present
61+
ngx_lua_ffi_ssl_get_client_hello_ciphers =
62+
C.ngx_http_lua_ffi_ssl_get_client_hello_ciphers
63+
5764

5865

5966
elseif subsystem == 'stream' then
@@ -148,6 +155,41 @@ function _M.get_client_hello_ext_present()
148155
return nil, ffi_str(errmsg[0])
149156
end
150157

158+
-- return ciphers_table, err
159+
-- including GREASE ciphers
160+
function _M.get_client_hello_ciphers()
161+
local r = get_request()
162+
if not r then
163+
error("no request found")
164+
end
165+
166+
if ngx_phase() ~= "ssl_client_hello" then
167+
error("API disabled in the current context")
168+
end
169+
170+
local sizep = get_size_ptr()
171+
172+
local rc = ngx_lua_ffi_ssl_get_client_hello_ciphers(r, intp,
173+
sizep, errmsg)
174+
if rc == FFI_OK then
175+
local array = intp[0]
176+
local size = tonumber(sizep[0])
177+
local ciphers_table = table_new(size, 0)
178+
for i=0, size-1, 1 do
179+
ciphers_table[i + 1] = array[i]
180+
end
181+
182+
return ciphers_table
183+
end
184+
185+
-- NGX_DECLINED
186+
if rc == -5 then
187+
return nil
188+
end
189+
190+
return nil, ffi_str(errmsg[0])
191+
end
192+
151193
-- return ext, err
152194
function _M.get_client_hello_ext(ext_type)
153195
local r = get_request()

0 commit comments

Comments
 (0)