Skip to content

Commit e0aabe6

Browse files
committed
doc: get_client_hello_ciphers()
1 parent c7db2a6 commit e0aabe6

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/ngx/ssl/clienthello.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Table of Contents
1313
* [Methods](#methods)
1414
* [get_client_hello_server_name](#get_client_hello_server_name)
1515
* [get_supported_versions](#get_supported_versions)
16+
* [get_client_hello_ciphers](#get_client_hello_ciphers)
1617
* [get_client_hello_ext_present](#get_client_hello_ext_present)
1718
* [get_client_hello_ext](#get_client_hello_ext)
1819
* [set_protocols](#set_protocols)
@@ -126,6 +127,44 @@ So this function can only be called in the context of [ssl_client_hello_by_lua*]
126127

127128
[Back to TOC](#table-of-contents)
128129

130+
get_client_hello_ciphers
131+
----------------------------
132+
**syntax:** *ciphers, err = ssl_clt.get_client_hello_ciphers()*
133+
134+
**context:** *ssl_client_hello_by_lua**
135+
136+
Returns a Lua table containing the decimal representations of the ciphers sent by the client on success.
137+
138+
GREASE ciphers are also returned by the underlying OPENSSL function (SSL_client_hello_get0_ciphers) but excluded by the lua implementation of get_client_hello_ciphers().
139+
140+
In case of errors, `nil` and a string describing the error are returned.
141+
142+
This function can only be called in the context of [ssl_client_hello_by_lua*](https://github.com/openresty/lua-nginx-module/#ssl_client_hello_by_lua_block).
143+
144+
Example:
145+
146+
```nginx
147+
# nginx.conf
148+
server {
149+
listen 443 ssl;
150+
server_name test.com;
151+
ssl_client_hello_by_lua_block {
152+
local ssl_clt = require "ngx.ssl.clienthello"
153+
local ciphers, err = ssl_clt.get_client_hello_ciphers()
154+
if not ciphers then
155+
ngx.log(ngx.ERR, "failed to get_client_hello_ciphers()")
156+
ngx.exit(ngx.ERROR)
157+
end
158+
159+
for i, cipher in ipairs(ciphers) do
160+
ngx.log(ngx.INFO, "ciphers ", cipher)
161+
end
162+
}
163+
ssl_certificate test.crt;
164+
ssl_certificate_key test.key;
165+
}
166+
```
167+
129168
get_client_hello_ext_present
130169
----------------------------
131170
**syntax:** *ext, err = ssl_clt.get_client_hello_ext_present()*
@@ -140,6 +179,11 @@ Note that the ext is gotten from the raw extensions of the client hello message
140179

141180
So this function can only be called in the context of [ssl_client_hello_by_lua*](https://github.com/openresty/lua-nginx-module/#ssl_client_hello_by_lua_block).
142181

182+
GREASE extensions are excluded by the underlying OPENSSL function (SSL_client_hello_get1_extensions_present)
183+
184+
Most modern browsers will randomize the order of the extensions so you may want to sort the table before working with it.
185+
186+
143187
Example:
144188

145189
```nginx

t/ssl-client-hello.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ qr/1: TLS EXT \d+, context: ssl_client_hello_by_lua/
10761076
server_name test.com;
10771077
ssl_client_hello_by_lua_block {
10781078
local ssl_clt = require "ngx.ssl.clienthello"
1079-
local all_extensions, err = ssl_clt.get_client_hello_ciphers()
1079+
local ciphers, err = ssl_clt.get_client_hello_ciphers()
10801080
if not err and ciphers then
10811081
for i, cipher in ipairs(ciphers) do
10821082
ngx.log(ngx.INFO, i, ": CIPHER ", cipher)

0 commit comments

Comments
 (0)