Skip to content

Commit 0e7406c

Browse files
committed
Merge branch 'master' of https://github.com/openresty/lua-nginx-module into ffi_ssl_ciphers
2 parents 2ad0ac3 + 9aed90f commit 0e7406c

20 files changed

+1967
-147
lines changed

.travis.yml

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ addons:
2929
- libunwind-dev
3030
- wget
3131
- libbrotli1
32+
- lsb-release
33+
- wget
34+
- gnupg
35+
- ca-certificates
3236

3337
cache:
3438
directories:
@@ -42,13 +46,10 @@ env:
4246
- LUAJIT_LIB=$LUAJIT_PREFIX/lib
4347
- LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1
4448
- LUA_INCLUDE_DIR=$LUAJIT_INC
45-
- PCRE_PREFIX=/opt/pcre
46-
- PCRE2_PREFIX=/opt/pcre2
47-
- PCRE_LIB=$PCRE_PREFIX/lib
49+
- PCRE2_PREFIX=/usr/local/openresty/pcre2
4850
- PCRE2_LIB=$PCRE2_PREFIX/lib
49-
- PCRE_INC=$PCRE_PREFIX/include
5051
- PCRE2_INC=$PCRE2_PREFIX/include
51-
- OPENSSL_PREFIX=/opt/ssl
52+
- OPENSSL_PREFIX=/usr/local/openresty/openssl3
5253
- OPENSSL_LIB=$OPENSSL_PREFIX/lib
5354
- OPENSSL_INC=$OPENSSL_PREFIX/include
5455
- LIBDRIZZLE_PREFIX=/opt/drizzle
@@ -59,14 +60,10 @@ env:
5960
- TEST_NGINX_SLEEP=0.006
6061
- MALLOC_PERTURB_=9
6162
jobs:
62-
#- NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.1w OPENSSL_PATCH_VER=1.1.1f
63-
#- NGINX_VERSION=1.25.1 OPENSSL_VER=1.1.1w TEST_NGINX_USE_HTTP2=1
64-
- NGINX_VERSION=1.27.1 OPENSSL_VER=1.1.1w OPENSSL_PATCH_VER=1.1.1f TEST_NGINX_TIMEOUT=5 PCRE_VER=8.45
65-
- NGINX_VERSION=1.27.1 OPENSSL_VER=3.0.15 OPENSSL_PATCH_VER=3.0.15 TEST_NGINX_TIMEOUT=5 PCRE2_VER=10.42
66-
- NGINX_VERSION=1.27.1 OPENSSL_VER=1.1.1w OPENSSL_PATCH_VER=1.1.1f TEST_NGINX_TIMEOUT=5 PCRE_VER=8.45 TEST_NGINX_USE_HTTP2=1
67-
- NGINX_VERSION=1.27.1 OPENSSL_VER=3.0.15 OPENSSL_PATCH_VER=3.0.15 TEST_NGINX_TIMEOUT=5 PCRE2_VER=10.42 TEST_NGINX_USE_HTTP2=1
68-
- NGINX_VERSION=1.27.1 OPENSSL_VER=3.0.15 OPENSSL_PATCH_VER=3.0.15 TEST_NGINX_USE_HTTP3=1 TEST_NGINX_QUIC_IDLE_TIMEOUT=3 PCRE2_VER=10.42
69-
- NGINX_VERSION=1.27.1 BORINGSSL=1 TEST_NGINX_USE_HTTP3=1 TEST_NGINX_QUIC_IDLE_TIMEOUT=3 PCRE2_VER=10.42
63+
- NGINX_VERSION=1.27.1 OPENSSL_VER=3.5.0 OPENSSL_PATCH_VER=3.5.0 TEST_NGINX_TIMEOUT=5 PCRE2_VER=10.45
64+
- NGINX_VERSION=1.27.1 OPENSSL_VER=3.5.0 OPENSSL_PATCH_VER=3.5.0 TEST_NGINX_TIMEOUT=5 PCRE2_VER=10.45 TEST_NGINX_USE_HTTP2=1
65+
- NGINX_VERSION=1.27.1 OPENSSL_VER=3.5.0 OPENSSL_PATCH_VER=3.5.0 TEST_NGINX_USE_HTTP3=1 TEST_NGINX_QUIC_IDLE_TIMEOUT=3 PCRE2_VER=10.45
66+
- NGINX_VERSION=1.27.1 BORINGSSL=1 TEST_NGINX_USE_HTTP3=1 TEST_NGINX_QUIC_IDLE_TIMEOUT=3 PCRE2_VER=10.45
7067

7168
services:
7269
- memcached
@@ -77,15 +74,16 @@ before_install:
7774
- '! grep -n -P ''(?<=.{80}).+'' --color `find src -name ''*.c''` `find . -name ''*.h''` || (echo "ERROR: Found C source lines exceeding 80 columns." > /dev/stderr; exit 1)'
7875
- '! grep -n -P ''\t+'' --color `find src -name ''*.c''` `find . -name ''*.h''` || (echo "ERROR: Cannot use tabs." > /dev/stderr; exit 1)'
7976
- /usr/bin/env perl $(command -v cpanm) --sudo --notest Test::Nginx IPC::Run > build.log 2>&1 || (cat build.log && exit 1)
77+
- wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
78+
- echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/openresty.list
79+
- sudo apt-get update
80+
- sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends openresty-pcre2 openresty-openssl3 openresty-pcre2-dev openresty-openssl3-dev
81+
8082

8183
install:
8284
- if [ ! -f download-cache/drizzle7-$DRIZZLE_VER.tar.gz ]; then wget -P download-cache https://github.com/openresty/openresty-deps-prebuild/releases/download/v20230902/drizzle7-$DRIZZLE_VER.tar.gz; fi
83-
#- if [ -n "$PCRE_VER" ] && [ ! -f download-cache/pcre-$PCRE_VER.tar.gz ]; then wget -P download-cache https://downloads.sourceforge.net/project/pcre/pcre/${PCRE_VER}/pcre-${PCRE_VER}.tar.gz; fi
8485
#- if [ -n "$PCRE2_VER" ] && [ ! -f download-cache/pcre2-$PCRE2_VER.tar.gz ]; then wget -P download-cache https://github.com/PCRE2Project/pcre2/releases/download/pcre2-${PCRE2_VER}/pcre2-${PCRE2_VER}.tar.gz; fi
8586
#- if [ -n "$OPENSSL_VER" ] && [ ! -f download-cache/openssl-$OPENSSL_VER.tar.gz ]; then wget -P download-cache https://github.com/openssl/openssl/releases/download/openssl-$OPENSSL_VER/openssl-$OPENSSL_VER.tar.gz || wget -P download-cache https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz || wget -P download-cache https://www.openssl.org/source/old/${OPENSSL_VER//[a-z]/}/openssl-$OPENSSL_VER.tar.gz; fi
86-
- if [ -n "$OPENSSL_VER" ]; then wget https://github.com/openresty/openresty-deps-prebuild/releases/download/v1.0.0/openssl-${OPENSSL_VER}-x64-focal.tar.gz; fi
87-
- if [ -n "$PCRE_VER" ]; then wget https://github.com/openresty/openresty-deps-prebuild/releases/download/v1.0.0/pcre-${PCRE_VER}-x64-focal.tar.gz; fi
88-
- if [ -n "$PCRE2_VER" ]; then wget https://github.com/openresty/openresty-deps-prebuild/releases/download/v1.0.0/pcre2-${PCRE2_VER}-x64-focal.tar.gz; fi
8987
- wget https://github.com/openresty/openresty-deps-prebuild/releases/download/v20230902/boringssl-20230902-x64-focal.tar.gz
9088
- wget https://github.com/openresty/openresty-deps-prebuild/releases/download/v20230902/curl-h3-x64-focal.tar.gz
9189
- git clone https://github.com/openresty/test-nginx.git
@@ -137,13 +135,9 @@ script:
137135
- sudo make install-libdrizzle-1.0 > build.log 2>&1 || (cat build.log && exit 1)
138136
- cd ../mockeagain/ && make CC=$CC -j$JOBS && cd ..
139137
- cd lua-cjson/ && make -j$JOBS && sudo make install && cd ..
140-
#- if [ -n "PCRE_VER" ]; then tar zxf download-cache/pcre-$PCRE_VER.tar.gz; cd pcre-$PCRE_VER/; ./configure --prefix=$PCRE_PREFIX --enable-jit --enable-utf --enable-unicode-properties > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi
141138
#- if [ -n "$PCRE2_VER" ]; then tar zxf download-cache/pcre2-$PCRE2_VER.tar.gz; cd pcre2-$PCRE2_VER/; ./configure --prefix=$PCRE2_PREFIX --enable-jit --enable-utf > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi
142139
#- if [ -n "$OPENSSL_VER" ]; then tar zxf download-cache/openssl-$OPENSSL_VER.tar.gz; cd openssl-$OPENSSL_VER/; patch -p1 < ../../openresty/patches/openssl-$OPENSSL_PATCH_VER-sess_set_get_cb_yield.patch; ./config shared enable-ssl3 enable-ssl3-method -g --prefix=$OPENSSL_PREFIX --libdir=lib -DPURIFY > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo make PATH=$PATH install_sw > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi
143-
- if [ -n "$BORINGSSL" ]; then sudo mkdir -p /opt/ssl && sudo tar -C /opt/ssl -xf boringssl-20230902-x64-focal.tar.gz --strip-components=1; fi
144-
- if [ -n "$OPENSSL_VER" ]; then sudo mkdir -p /opt/ssl && sudo tar -C /opt/ssl -xf openssl-$OPENSSL_VER-x64-focal.tar.gz --strip-components=2; fi
145-
- if [ -n "$PCRE_VER" ]; then sudo mkdir -p $PCRE_PREFIX && sudo tar -C $PCRE_PREFIX -xf pcre-$PCRE_VER-x64-focal.tar.gz --strip-components=2; fi
146-
- if [ -n "$PCRE2_VER" ]; then sudo mkdir -p $PCRE2_PREFIX && sudo tar -C $PCRE2_PREFIX -xf pcre2-$PCRE2_VER-x64-focal.tar.gz --strip-components=2; fi
140+
- if [ -n "$BORINGSSL" ]; then sudo rm -fr /usr/local/openresty/openssl3/ && sudo mkdir -p /usr/local/openresty/openssl3 && sudo tar -C /usr/local/openresty/openssl3 -xf boringssl-20230902-x64-focal.tar.gz --strip-components=1; fi
147141
- export NGX_BUILD_CC=$CC
148142
- sh util/build-without-ssl.sh $NGINX_VERSION > build.log 2>&1 || (cat build.log && exit 1)
149143
- sh util/build-with-dd.sh $NGINX_VERSION > build.log 2>&1 || (cat build.log && exit 1)
@@ -160,4 +154,4 @@ script:
160154
- dig +short myip.opendns.com @resolver1.opendns.com || exit 0
161155
- dig +short @$TEST_NGINX_RESOLVER openresty.org || exit 0
162156
- dig +short @$TEST_NGINX_RESOLVER agentzh.org || exit 0
163-
- /usr/bin/env perl $(command -v prove) -I. -Itest-nginx/lib -r t/
157+
- /usr/bin/env perl $(command -v prove) -I. -Itest-nginx/inc -Itest-nginx/lib -r t/

README.markdown

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Table of Contents
4545
* [Missing data on short circuited requests](#missing-data-on-short-circuited-requests)
4646
* [TODO](#todo)
4747
* [Changes](#changes)
48+
* [Build And Test](#build-and-test)
4849
* [Test Suite](#test-suite)
4950
* [Copyright and License](#copyright-and-license)
5051
* [See Also](#see-also)
@@ -982,6 +983,23 @@ The changes made in every release of this module are listed in the change logs o
982983

983984
[Back to TOC](#table-of-contents)
984985

986+
Build And Test
987+
==============
988+
989+
This module uses `.travis.yml` as the CI configuration.
990+
You can always check `.travis.yml` for the latest CI configuration.
991+
992+
For developers, you need to run tests locally. You can use `util/run-ci.sh`
993+
to easily set up the environment and execute the test suite.
994+
995+
To run the Test from the beginning:
996+
997+
```shell
998+
git clone https://github.com/openresty/lua-nginx-module.git
999+
cd lua-nginx-module
1000+
bash util/run-ci.sh
1001+
```
1002+
9851003
Test Suite
9861004
==========
9871005

@@ -1026,7 +1044,6 @@ To run the whole test suite in the default testing mode:
10261044
export PATH=/path/to/your/nginx/sbin:$PATH
10271045
prove -I/path/to/test-nginx/lib -r t
10281046

1029-
10301047
To run specific test files:
10311048

10321049
cd /path/to/lua-nginx-module
@@ -1169,6 +1186,7 @@ Directives
11691186
* [lua_ssl_certificate_key](#lua_ssl_certificate_key)
11701187
* [lua_ssl_trusted_certificate](#lua_ssl_trusted_certificate)
11711188
* [lua_ssl_verify_depth](#lua_ssl_verify_depth)
1189+
* [lua_ssl_key_log](#lua_ssl_key_log)
11721190
* [lua_ssl_conf_command](#lua_ssl_conf_command)
11731191
* [lua_http10_buffering](#lua_http10_buffering)
11741192
* [rewrite_by_lua_no_postpone](#rewrite_by_lua_no_postpone)
@@ -3430,6 +3448,19 @@ See also [lua_ssl_certificate](#lua_ssl_certificate), [lua_ssl_certificate_key](
34303448

34313449
[Back to TOC](#directives)
34323450

3451+
lua_ssl_key_log
3452+
---------------
3453+
3454+
**syntax:** *lua_ssl_key_log &lt;file&gt;*
3455+
3456+
**default:** *none*
3457+
3458+
**context:** *http, server, location*
3459+
3460+
Enables logging of client connection SSL keys in the [tcpsock:sslhandshake](#tcpsocksslhandshake) method and specifies the path to the key log file. Keys are logged in the SSLKEYLOGFILE format compatible with Wireshark.
3461+
3462+
[Back to TOC](#directives)
3463+
34333464
lua_ssl_conf_command
34343465
--------------------
34353466

doc/HttpLuaModule.wiki

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,6 +2925,16 @@ This directive was first introduced in the <code>v0.9.11</code> release.
29252925
29262926
See also [[#lua_ssl_certificate|lua_ssl_certificate]], [[#lua_ssl_certificate_key|lua_ssl_certificate_key]] and [[#lua_ssl_trusted_certificate|lua_ssl_trusted_certificate]].
29272927
2928+
== lua_ssl_key_log ==
2929+
2930+
'''syntax:''' ''lua_ssl_key_log <file>''
2931+
2932+
'''default:''' ''none''
2933+
2934+
'''context:''' ''http, server, location''
2935+
2936+
Enables logging of client connection SSL keys in the [[#tcpsock:sslhandshake|tcpsock:sslhandshake]] method and specifies the path to the key log file. Keys are logged in the SSLKEYLOGFILE format compatible with Wireshark.
2937+
29282938
== lua_ssl_conf_command ==
29292939
29302940
'''syntax:''' ''lua_ssl_conf_command <command>''

src/ngx_http_lua_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ typedef struct {
379379
ngx_uint_t ssl_verify_depth;
380380
ngx_str_t ssl_trusted_certificate;
381381
ngx_str_t ssl_crl;
382+
ngx_str_t ssl_key_log;
382383
#if (nginx_version >= 1019004)
383384
ngx_array_t *ssl_conf_commands;
384385
#endif

src/ngx_http_lua_module.c

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ static ngx_int_t ngx_http_lua_merge_ssl(ngx_conf_t *cf,
5454
ngx_http_lua_loc_conf_t *conf, ngx_http_lua_loc_conf_t *prev);
5555
static ngx_int_t ngx_http_lua_set_ssl(ngx_conf_t *cf,
5656
ngx_http_lua_loc_conf_t *llcf);
57+
static void key_log_callback(const ngx_ssl_conn_t *ssl_conn,
58+
const char *line);
59+
static void ngx_http_lua_ssl_cleanup_key_log(void *data);
60+
static ngx_int_t ngx_http_lua_ssl_key_log(ngx_conf_t *cf, ngx_ssl_t *ssl,
61+
ngx_str_t *file);
5762
#if (nginx_version >= 1019004)
5863
static char *ngx_http_lua_ssl_conf_command_check(ngx_conf_t *cf, void *post,
5964
void *data);
@@ -690,6 +695,13 @@ static ngx_command_t ngx_http_lua_cmds[] = {
690695
offsetof(ngx_http_lua_loc_conf_t, ssl_crl),
691696
NULL },
692697

698+
{ ngx_string("lua_ssl_key_log"),
699+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
700+
ngx_conf_set_str_slot,
701+
NGX_HTTP_LOC_CONF_OFFSET,
702+
offsetof(ngx_http_lua_loc_conf_t, ssl_key_log),
703+
NULL },
704+
693705
#if (nginx_version >= 1019004)
694706
{ ngx_string("lua_ssl_conf_command"),
695707
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
@@ -1433,6 +1445,7 @@ ngx_http_lua_create_loc_conf(ngx_conf_t *cf)
14331445
* conf->ssl_ciphers = { 0, NULL };
14341446
* conf->ssl_trusted_certificate = { 0, NULL };
14351447
* conf->ssl_crl = { 0, NULL };
1448+
* conf->ssl_key_log = { 0, NULL };
14361449
*/
14371450

14381451
conf->force_read_body = NGX_CONF_UNSET;
@@ -1553,6 +1566,7 @@ ngx_http_lua_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
15531566
ngx_conf_merge_str_value(conf->ssl_trusted_certificate,
15541567
prev->ssl_trusted_certificate, "");
15551568
ngx_conf_merge_str_value(conf->ssl_crl, prev->ssl_crl, "");
1569+
ngx_conf_merge_str_value(conf->ssl_key_log, prev->ssl_key_log, "");
15561570

15571571
#if (nginx_version >= 1019004)
15581572
ngx_conf_merge_ptr_value(conf->ssl_conf_commands, prev->ssl_conf_commands,
@@ -1616,6 +1630,7 @@ ngx_http_lua_merge_ssl(ngx_conf_t *cf,
16161630
&& conf->ssl_certificate_keys == NGX_CONF_UNSET_PTR
16171631
&& conf->ssl_trusted_certificate.data == NULL
16181632
&& conf->ssl_crl.data == NULL
1633+
&& conf->ssl_key_log.data == NULL
16191634
#if (nginx_version >= 1019004)
16201635
&& conf->ssl_conf_commands == NGX_CONF_UNSET_PTR
16211636
#endif
@@ -1723,6 +1738,12 @@ ngx_http_lua_set_ssl(ngx_conf_t *cf, ngx_http_lua_loc_conf_t *llcf)
17231738
return NGX_ERROR;
17241739
}
17251740

1741+
if (ngx_http_lua_ssl_key_log(cf, llcf->ssl, &llcf->ssl_key_log)
1742+
!= NGX_OK)
1743+
{
1744+
return NGX_ERROR;
1745+
}
1746+
17261747
#if (nginx_version >= 1019004)
17271748
if (ngx_ssl_conf_commands(cf, llcf->ssl, llcf->ssl_conf_commands)
17281749
!= NGX_OK)
@@ -1734,6 +1755,102 @@ ngx_http_lua_set_ssl(ngx_conf_t *cf, ngx_http_lua_loc_conf_t *llcf)
17341755
return NGX_OK;
17351756
}
17361757

1758+
1759+
static void
1760+
key_log_callback(const ngx_ssl_conn_t *ssl_conn, const char *line)
1761+
{
1762+
ngx_http_lua_ssl_key_log_t *ssl_key_log;
1763+
ngx_connection_t *c;
1764+
1765+
ssl_key_log = SSL_CTX_get_ex_data(SSL_get_SSL_CTX(ssl_conn),
1766+
ngx_http_lua_ssl_key_log_index);
1767+
if (ssl_key_log == NULL) {
1768+
c = ngx_ssl_get_connection((ngx_ssl_conn_t *) ssl_conn);
1769+
ngx_ssl_error(NGX_LOG_DEBUG, c->log, 0, "get ssl key log failed");
1770+
1771+
return;
1772+
}
1773+
1774+
(void) ngx_write_fd(ssl_key_log->fd, (void *) line, ngx_strlen(line));
1775+
(void) ngx_write_fd(ssl_key_log->fd, (void *) "\n", 1);
1776+
}
1777+
1778+
1779+
static void
1780+
ngx_http_lua_ssl_cleanup_key_log(void *data)
1781+
{
1782+
ngx_http_lua_ssl_key_log_t *ssl_key_log = data;
1783+
1784+
if (ngx_close_file(ssl_key_log->fd) == NGX_FILE_ERROR) {
1785+
ngx_ssl_error(NGX_LOG_ALERT, ssl_key_log->ssl->log, 0,
1786+
ngx_close_file_n "(\"%V\") failed", ssl_key_log->name);
1787+
}
1788+
}
1789+
1790+
1791+
static ngx_int_t
1792+
ngx_http_lua_ssl_key_log(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *file)
1793+
{
1794+
ngx_fd_t fd;
1795+
ngx_http_lua_ssl_key_log_t *ssl_key_log;
1796+
ngx_pool_cleanup_t *cln;
1797+
1798+
if (!file->len) {
1799+
return NGX_OK;
1800+
}
1801+
1802+
if (ngx_conf_full_name(cf->cycle, file, 1) != NGX_OK) {
1803+
return NGX_ERROR;
1804+
}
1805+
1806+
if (ngx_http_lua_ssl_init(cf->log) != NGX_OK) {
1807+
return NGX_ERROR;
1808+
}
1809+
1810+
/*
1811+
* append so that existing keylog file contents can be preserved
1812+
*/
1813+
fd = ngx_open_file(file->data, NGX_FILE_APPEND, NGX_FILE_CREATE_OR_OPEN,
1814+
NGX_FILE_DEFAULT_ACCESS);
1815+
if (fd == NGX_INVALID_FILE) {
1816+
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, ngx_open_file_n
1817+
"(\"%V\") failed", file);
1818+
return NGX_ERROR;
1819+
}
1820+
1821+
ssl_key_log = ngx_palloc(cf->pool, sizeof(ngx_http_lua_ssl_key_log_t));
1822+
if (ssl_key_log == NULL) {
1823+
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, "ngx_pcalloc() failed");
1824+
return NGX_ERROR;
1825+
}
1826+
1827+
ssl_key_log->ssl = ssl;
1828+
ssl_key_log->fd = fd;
1829+
ssl_key_log->name = *file;
1830+
1831+
if (SSL_CTX_set_ex_data(ssl->ctx, ngx_http_lua_ssl_key_log_index,
1832+
ssl_key_log) == 0)
1833+
{
1834+
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
1835+
"SSL_CTX_set_ex_data() failed");
1836+
return NGX_ERROR;
1837+
}
1838+
1839+
cln = ngx_pool_cleanup_add(cf->pool, 0);
1840+
if (cln == NULL) {
1841+
ngx_http_lua_ssl_cleanup_key_log(ssl_key_log);
1842+
return NGX_ERROR;
1843+
}
1844+
1845+
cln->handler = ngx_http_lua_ssl_cleanup_key_log;
1846+
cln->data = ssl_key_log;
1847+
1848+
SSL_CTX_set_keylog_callback(ssl->ctx, key_log_callback);
1849+
1850+
return NGX_OK;
1851+
}
1852+
1853+
17371854
#if (nginx_version >= 1019004)
17381855
static char *
17391856
ngx_http_lua_ssl_conf_command_check(ngx_conf_t *cf, void *post, void *data)

src/ngx_http_lua_ssl.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
int ngx_http_lua_ssl_ctx_index = -1;
17+
int ngx_http_lua_ssl_key_log_index = -1;
1718

1819

1920
ngx_int_t
@@ -30,6 +31,17 @@ ngx_http_lua_ssl_init(ngx_log_t *log)
3031
}
3132
}
3233

34+
if (ngx_http_lua_ssl_key_log_index == -1) {
35+
ngx_http_lua_ssl_key_log_index = SSL_get_ex_new_index(0, NULL, NULL,
36+
NULL, NULL);
37+
38+
if (ngx_http_lua_ssl_key_log_index == -1) {
39+
ngx_ssl_error(NGX_LOG_ALERT, log, 0,
40+
"lua: SSL_get_ex_new_index() for key log failed");
41+
return NGX_ERROR;
42+
}
43+
}
44+
3345
return NGX_OK;
3446
}
3547

src/ngx_http_lua_ssl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ typedef struct {
4141
} ngx_http_lua_ssl_ctx_t;
4242

4343

44+
typedef struct {
45+
ngx_ssl_t *ssl;
46+
ngx_fd_t fd;
47+
ngx_str_t name;
48+
} ngx_http_lua_ssl_key_log_t;
49+
50+
4451
ngx_int_t ngx_http_lua_ssl_init(ngx_log_t *log);
4552

4653

4754
extern int ngx_http_lua_ssl_ctx_index;
55+
extern int ngx_http_lua_ssl_key_log_index;
4856

4957

5058
#endif

0 commit comments

Comments
 (0)