@@ -8,7 +8,7 @@ use t::TestCore::Stream;
88
99repeat_each(2 );
1010
11- plan tests => repeat_each() * (blocks() * 6 + 1 );
11+ plan tests => repeat_each() * (blocks() * 6 + 2 );
1212
1313no_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 0 x/ ]
2424+
2425+ -- - no_error_log
2426+ [alert]
2427+ [crit]
2428+ [error]
0 commit comments