Skip to content

Commit fcd0dea

Browse files
ghedoagentzh
authored andcommitted
ssl: support enabling TLSv1.3 via lua_ssl_protocols.
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
1 parent 9e5cc6e commit fcd0dea

File tree

5 files changed

+120
-5
lines changed

5 files changed

+120
-5
lines changed

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ env:
4848
- DRIZZLE_VER=2011.07.21
4949
- TEST_NGINX_SLEEP=0.006
5050
matrix:
51-
- NGINX_VERSION=1.13.6 OPENSSL_VER=1.0.2n OPENSSL_PATCH_VER=1.0.2h
52-
- NGINX_VERSION=1.13.6 OPENSSL_VER=1.1.0g OPENSSL_PATCH_VER=1.1.0d
51+
- NGINX_VERSION=1.13.6 OPENSSL_VER=1.0.2n OPENSSL_OPT="" OPENSSL_PATCH_VER=1.0.2h
52+
- NGINX_VERSION=1.13.6 OPENSSL_VER=1.1.0g OPENSSL_OPT="" OPENSSL_PATCH_VER=1.1.0d
53+
# TODO: when adding an OpenSSL version >= 1.1.1, please add "enable-tls1_3"
54+
# to $OPENSSL_OPT.
5355

5456
services:
5557
- memcache
@@ -113,7 +115,7 @@ script:
113115
- tar zxf download-cache/openssl-$OPENSSL_VER.tar.gz
114116
- cd openssl-$OPENSSL_VER/
115117
- patch -p1 < ../../openresty/patches/openssl-$OPENSSL_PATCH_VER-sess_set_get_cb_yield.patch
116-
- ./config no-threads shared enable-ssl3 enable-ssl3-method -g --prefix=$OPENSSL_PREFIX -DPURIFY > build.log 2>&1 || (cat build.log && exit 1)
118+
- ./config no-threads shared enable-ssl3 enable-ssl3-method $OPENSSL_OPT -g --prefix=$OPENSSL_PREFIX -DPURIFY > build.log 2>&1 || (cat build.log && exit 1)
117119
- make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1)
118120
- sudo make PATH=$PATH install_sw > build.log 2>&1 || (cat build.log && exit 1)
119121
- cd ..

README.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2921,14 +2921,16 @@ This directive was first introduced in the `v0.9.11` release.
29212921
lua_ssl_protocols
29222922
-----------------
29232923

2924-
**syntax:** *lua_ssl_protocols \[SSLv2\] \[SSLv3\] \[TLSv1\] [TLSv1.1] [TLSv1.2]*
2924+
**syntax:** *lua_ssl_protocols \[SSLv2\] \[SSLv3\] \[TLSv1\] [TLSv1.1] [TLSv1.2] [TLSv1.3]*
29252925

29262926
**default:** *lua_ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2*
29272927

29282928
**context:** *http, server, location*
29292929

29302930
Enables the specified protocols for requests to a SSL/TLS server in the [tcpsock:sslhandshake](#tcpsocksslhandshake) method.
29312931

2932+
The support for the `TLSv1.3` parameter requires version `v0.10.12` *and* OpenSSL 1.1.1.
2933+
29322934
This directive was first introduced in the `v0.9.11` release.
29332935

29342936
[Back to TOC](#directives)

doc/HttpLuaModule.wiki

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2469,14 +2469,16 @@ This directive was first introduced in the <code>v0.9.11</code> release.
24692469
24702470
== lua_ssl_protocols ==
24712471
2472-
'''syntax:''' ''lua_ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2]''
2472+
'''syntax:''' ''lua_ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2] [TLSv1.3]''
24732473
24742474
'''default:''' ''lua_ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2''
24752475
24762476
'''context:''' ''http, server, location''
24772477
24782478
Enables the specified protocols for requests to a SSL/TLS server in the [[#tcpsock:sslhandshake|tcpsock:sslhandshake]] method.
24792479
2480+
The support for the <code>TLSv1.3</code> parameter requires version <code>v0.10.12</code> *and* OpenSSL 1.1.1.
2481+
24802482
This directive was first introduced in the <code>v0.9.11</code> release.
24812483
24822484
== lua_ssl_trusted_certificate ==

src/ngx_http_lua_module.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ static ngx_conf_bitmask_t ngx_http_lua_ssl_protocols[] = {
6565
{ ngx_string("TLSv1"), NGX_SSL_TLSv1 },
6666
{ ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 },
6767
{ ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 },
68+
#ifdef NGX_SSL_TLSv1_3
69+
{ ngx_string("TLSv1.3"), NGX_SSL_TLSv1_3 },
70+
#endif
6871
{ ngx_null_string, 0 }
6972
};
7073

t/155-tls13.t

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# vim:set ft= ts=4 sw=4 et fdm=marker:
2+
3+
use Test::Nginx::Socket::Lua;
4+
5+
repeat_each(3);
6+
7+
# All these tests need to have new openssl
8+
my $NginxBinary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
9+
my $openssl_version = eval { `$NginxBinary -V 2>&1` };
10+
11+
if ($openssl_version =~ m/built with OpenSSL (0\S*|1\.0\S*|1\.1\.0\S*)/) {
12+
plan(skip_all => "too old OpenSSL, need 1.1.1, was $1");
13+
} else {
14+
plan tests => repeat_each() * (blocks() * 5);
15+
}
16+
17+
$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
18+
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
19+
20+
sub read_file {
21+
my $infile = shift;
22+
open my $in, $infile
23+
or die "cannot open $infile for reading: $!";
24+
my $cert = do { local $/; <$in> };
25+
close $in;
26+
$cert;
27+
}
28+
29+
our $TestCertificate = read_file("t/cert/test.crt");
30+
our $TestCertificateKey = read_file("t/cert/test.key");
31+
32+
#log_level 'warn';
33+
log_level 'debug';
34+
35+
no_long_string();
36+
#no_diff();
37+
38+
run_tests();
39+
40+
__DATA__
41+
42+
=== TEST 1: handshake, TLSv1.3
43+
--- http_config
44+
server {
45+
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
46+
server_name test.com;
47+
ssl_certificate ../html/test.crt;
48+
ssl_certificate_key ../html/test.key;
49+
ssl_protocols TLSv1.2 TLSv1.3;
50+
51+
server_tokens off;
52+
location /foo {
53+
default_type 'text/plain';
54+
content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
55+
}
56+
}
57+
--- config
58+
server_tokens off;
59+
lua_ssl_trusted_certificate ../html/test.crt;
60+
lua_ssl_protocols TLSv1.2 TLSv1.3;
61+
location /t {
62+
#set $port 5000;
63+
set $port $TEST_NGINX_MEMCACHED_PORT;
64+
65+
content_by_lua_block {
66+
do
67+
local sock = ngx.socket.tcp()
68+
69+
sock:settimeout(3000)
70+
71+
local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
72+
if not ok then
73+
ngx.say("failed to connect: ", err)
74+
return
75+
end
76+
77+
ngx.say("connected: ", ok)
78+
79+
local sess, err = sock:sslhandshake(nil, "test.com", true)
80+
if not sess then
81+
ngx.say("failed to do SSL handshake: ", err)
82+
else
83+
ngx.say("ssl handshake: ", type(sess))
84+
end
85+
end -- do
86+
collectgarbage()
87+
}
88+
}
89+
90+
--- request
91+
GET /t
92+
--- response_body
93+
connected: 1
94+
ssl handshake: userdata
95+
96+
--- user_files eval
97+
">>> test.key
98+
$::TestCertificateKey
99+
>>> test.crt
100+
$::TestCertificate"
101+
--- error_log
102+
SSL: TLSv1.3,
103+
--- no_error_log
104+
[error]
105+
[alert]
106+
--- timeout: 5

0 commit comments

Comments
 (0)