Skip to content

Commit d2de694

Browse files
committed
Merge branch 'master' into proxy_ssl_verify_by_lua
2 parents 9cc21da + 6650f3a commit d2de694

File tree

2 files changed

+98
-6
lines changed

2 files changed

+98
-6
lines changed

lib/ngx/ssl.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ local ffi = require "ffi"
99
local C = ffi.C
1010
local ffi_str = ffi.string
1111
local ffi_gc = ffi.gc
12-
local ffi_copy = ffi.copy
13-
local ffi_sizeof = ffi.sizeof
14-
local ffi_typeof = ffi.typeof
1512
local ffi_new = ffi.new
1613
local get_request = base.get_request
1714
local error = error
1815
local tonumber = tonumber
19-
local format = string.format
20-
local concat = table.concat
2116
local errmsg = base.get_errmsg_ptr()
2217
local get_string_buf = base.get_string_buf
2318
local get_size_ptr = base.get_size_ptr
@@ -215,6 +210,10 @@ elseif subsystem == 'stream' then
215210

216211
int ngx_stream_lua_ffi_ssl_client_random(ngx_stream_lua_request_t *r,
217212
unsigned char *out, size_t *outlen, char **err);
213+
214+
int ngx_stream_lua_ffi_req_shared_ssl_ciphers(ngx_stream_lua_request_t *r,
215+
unsigned short *ciphers, unsigned short *nciphers,
216+
int filter_grease, char **err);
218217
]]
219218

220219
ngx_lua_ffi_ssl_set_der_certificate =
@@ -240,6 +239,8 @@ elseif subsystem == 'stream' then
240239
ngx_lua_ffi_free_priv_key = C.ngx_stream_lua_ffi_free_priv_key
241240
ngx_lua_ffi_ssl_verify_client = C.ngx_stream_lua_ffi_ssl_verify_client
242241
ngx_lua_ffi_ssl_client_random = C.ngx_stream_lua_ffi_ssl_client_random
242+
ngx_lua_ffi_req_shared_ssl_ciphers =
243+
C.ngx_stream_lua_ffi_req_shared_ssl_ciphers
243244
end
244245

245246

t/stream/ssl.t

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use t::TestCore::Stream;
88

99
repeat_each(2);
1010

11-
plan tests => repeat_each() * (blocks() * 6 + 1);
11+
plan tests => repeat_each() * (blocks() * 6 + 2);
1212

1313
no_long_string();
1414
#no_diff();
@@ -2335,3 +2335,94 @@ client-random length: 32
23352335
[error]
23362336
[alert]
23372337
[emerg]
2338+
2339+
2340+
2341+
=== TEST 29: get shared SSL ciphers
2342+
--- stream_config
2343+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
2344+
2345+
server {
2346+
listen 127.0.0.1:$TEST_NGINX_RAND_PORT_1 ssl;
2347+
ssl_protocols TLSv1.2;
2348+
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384;
2349+
2350+
ssl_certificate_by_lua_block {
2351+
local ssl = require "ngx.ssl"
2352+
local ciphers, err = ssl.get_req_shared_ssl_ciphers()
2353+
if not err and ciphers then
2354+
ngx.log(ngx.INFO, "shared ciphers count: ", #ciphers)
2355+
local count = 0
2356+
for i, cipher_id in ipairs(ciphers) do
2357+
count = count + 1
2358+
ngx.log(ngx.INFO, string.format("%d: SHARED_CIPHER 0x%04x", i, cipher_id))
2359+
if count >= 3 then -- log only first 3 to avoid too much output
2360+
break
2361+
end
2362+
end
2363+
else
2364+
ngx.log(ngx.ERR, "failed to get shared ciphers: ", err)
2365+
end
2366+
}
2367+
ssl_certificate ../../cert/test.crt;
2368+
ssl_certificate_key ../../cert/test.key;
2369+
2370+
return 'it works!\n';
2371+
}
2372+
--- stream_server_config
2373+
lua_ssl_trusted_certificate ../../cert/test.crt;
2374+
lua_ssl_protocols TLSv1.2;
2375+
lua_ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256;
2376+
2377+
content_by_lua_block {
2378+
do
2379+
local sock = ngx.socket.tcp()
2380+
2381+
sock:settimeout(3000)
2382+
2383+
local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_RAND_PORT_1)
2384+
if not ok then
2385+
ngx.say("failed to connect: ", err)
2386+
return
2387+
end
2388+
2389+
ngx.say("connected: ", ok)
2390+
2391+
local sess, err = sock:sslhandshake(nil, nil, true)
2392+
if not sess then
2393+
ngx.say("failed to do SSL handshake: ", err)
2394+
return
2395+
end
2396+
2397+
ngx.say("ssl handshake: ", type(sess))
2398+
2399+
while true do
2400+
local line, err = sock:receive()
2401+
if not line then
2402+
-- ngx.say("failed to receive response status line: ", err)
2403+
break
2404+
end
2405+
2406+
ngx.say("received: ", line)
2407+
end
2408+
2409+
local ok, err = sock:close()
2410+
ngx.say("close: ", ok, " ", err)
2411+
end -- do
2412+
-- collectgarbage()
2413+
}
2414+
2415+
--- stream_response
2416+
connected: 1
2417+
ssl handshake: userdata
2418+
received: it works!
2419+
close: 1 nil
2420+
2421+
--- error_log eval
2422+
[qr/shared ciphers count: \d+/,
2423+
qr/1: SHARED_CIPHER 0x/]
2424+
2425+
--- no_error_log
2426+
[alert]
2427+
[crit]
2428+
[error]

0 commit comments

Comments
 (0)