Skip to content

Commit 37e5362

Browse files
doujiang24agentzh
authored andcommitted
change: ssl_session_fetch_by_lua* and ssl_session_store_by_lua* are now only allowed in the http {} context.
Use of these session hooks in the server {} scope did not make much sense since server name dispatch happens *after* ssl session resumption. Signed-off-by: Yichun Zhang (agentzh) <[email protected]>
1 parent cf0623c commit 37e5362

File tree

5 files changed

+411
-159
lines changed

5 files changed

+411
-159
lines changed

README.markdown

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,7 +2485,7 @@ ssl_session_fetch_by_lua_block
24852485

24862486
**syntax:** *ssl_session_fetch_by_lua_block { lua-script }*
24872487

2488-
**context:** *server*
2488+
**context:** *http*
24892489

24902490
**phase:** *right-before-SSL-handshake*
24912491

@@ -2541,14 +2541,17 @@ apply the following patch to the standard NGINX core 1.11.2 or later:
25412541

25422542
This directive was first introduced in the `v0.10.6` release.
25432543

2544+
Note that: this directive is only allowed to used in **http context** from the `v0.10.7` release
2545+
(because SSL session resumption happens before server name dispatch).
2546+
25442547
[Back to TOC](#directives)
25452548

25462549
ssl_session_fetch_by_lua_file
25472550
-----------------------------
25482551

25492552
**syntax:** *ssl_session_fetch_by_lua_file &lt;path-to-lua-script-file&gt;*
25502553

2551-
**context:** *server*
2554+
**context:** *http*
25522555

25532556
**phase:** *right-before-SSL-handshake*
25542557

@@ -2558,14 +2561,17 @@ When a relative path like `foo/bar.lua` is given, they will be turned into the a
25582561

25592562
This directive was first introduced in the `v0.10.6` release.
25602563

2564+
Note that: this directive is only allowed to used in **http context** from the `v0.10.7` release
2565+
(because SSL session resumption happens before server name dispatch).
2566+
25612567
[Back to TOC](#directives)
25622568

25632569
ssl_session_store_by_lua_block
25642570
------------------------------
25652571

25662572
**syntax:** *ssl_session_store_by_lua_block { lua-script }*
25672573

2568-
**context:** *server*
2574+
**context:** *http*
25692575

25702576
**phase:** *right-after-SSL-handshake*
25712577

@@ -2592,14 +2598,17 @@ But do not forget to comment this line out before publishing your site to the wo
25922598

25932599
This directive was first introduced in the `v0.10.6` release.
25942600

2601+
Note that: this directive is only allowed to used in **http context** from the `v0.10.7` release
2602+
(because SSL session resumption happens before server name dispatch).
2603+
25952604
[Back to TOC](#directives)
25962605

25972606
ssl_session_store_by_lua_file
25982607
-----------------------------
25992608

26002609
**syntax:** *ssl_session_store_by_lua_file &lt;path-to-lua-script-file&gt;*
26012610

2602-
**context:** *server*
2611+
**context:** *http*
26032612

26042613
**phase:** *right-before-SSL-handshake*
26052614

@@ -2609,6 +2618,9 @@ When a relative path like `foo/bar.lua` is given, they will be turned into the a
26092618

26102619
This directive was first introduced in the `v0.10.6` release.
26112620

2621+
Note that: this directive is only allowed to used in **http context** from the `v0.10.7` release
2622+
(because SSL session resumption happens before server name dispatch).
2623+
26122624
[Back to TOC](#directives)
26132625

26142626
lua_shared_dict

doc/HttpLuaModule.wiki

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,7 @@ This directive was first introduced in the <code>v0.10.0</code> release.
20872087
20882088
'''syntax:''' ''ssl_session_fetch_by_lua_block { lua-script }''
20892089
2090-
'''context:''' ''server''
2090+
'''context:''' ''http''
20912091
20922092
'''phase:''' ''right-before-SSL-handshake''
20932093
@@ -2143,11 +2143,14 @@ http://openresty.org/download/nginx-1.11.2-nonblocking_ssl_handshake_hooks.patch
21432143
21442144
This directive was first introduced in the <code>v0.10.6</code> release.
21452145
2146+
Note that: this directive is only allowed to used in '''http context''' from the <code>v0.10.7</code> release
2147+
(because SSL session resumption happens before server name dispatch).
2148+
21462149
== ssl_session_fetch_by_lua_file ==
21472150
21482151
'''syntax:''' ''ssl_session_fetch_by_lua_file <path-to-lua-script-file>''
21492152
2150-
'''context:''' ''server''
2153+
'''context:''' ''http''
21512154
21522155
'''phase:''' ''right-before-SSL-handshake''
21532156
@@ -2157,11 +2160,14 @@ When a relative path like <code>foo/bar.lua</code> is given, they will be turned
21572160
21582161
This directive was first introduced in the <code>v0.10.6</code> release.
21592162
2163+
Note that: this directive is only allowed to used in '''http context''' from the <code>v0.10.7</code> release
2164+
(because SSL session resumption happens before server name dispatch).
2165+
21602166
== ssl_session_store_by_lua_block ==
21612167
21622168
'''syntax:''' ''ssl_session_store_by_lua_block { lua-script }''
21632169
2164-
'''context:''' ''server''
2170+
'''context:''' ''http''
21652171
21662172
'''phase:''' ''right-after-SSL-handshake''
21672173
@@ -2188,11 +2194,14 @@ But do not forget to comment this line out before publishing your site to the wo
21882194
21892195
This directive was first introduced in the <code>v0.10.6</code> release.
21902196
2197+
Note that: this directive is only allowed to used in '''http context''' from the <code>v0.10.7</code> release
2198+
(because SSL session resumption happens before server name dispatch).
2199+
21912200
== ssl_session_store_by_lua_file ==
21922201
21932202
'''syntax:''' ''ssl_session_store_by_lua_file <path-to-lua-script-file>''
21942203
2195-
'''context:''' ''server''
2204+
'''context:''' ''http''
21962205
21972206
'''phase:''' ''right-before-SSL-handshake''
21982207
@@ -2202,6 +2211,9 @@ When a relative path like <code>foo/bar.lua</code> is given, they will be turned
22022211
22032212
This directive was first introduced in the <code>v0.10.6</code> release.
22042213
2214+
Note that: this directive is only allowed to used in '''http context''' from the <code>v0.10.7</code> release
2215+
(because SSL session resumption happens before server name dispatch).
2216+
22052217
== lua_shared_dict ==
22062218
22072219
'''syntax:''' ''lua_shared_dict <name> <size>''

src/ngx_http_lua_module.c

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -530,28 +530,28 @@ static ngx_command_t ngx_http_lua_cmds[] = {
530530
(void *) ngx_http_lua_ssl_cert_handler_file },
531531

532532
{ ngx_string("ssl_session_store_by_lua_block"),
533-
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
533+
NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
534534
ngx_http_lua_ssl_sess_store_by_lua_block,
535535
NGX_HTTP_SRV_CONF_OFFSET,
536536
0,
537537
(void *) ngx_http_lua_ssl_sess_store_handler_inline },
538538

539539
{ ngx_string("ssl_session_store_by_lua_file"),
540-
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
540+
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
541541
ngx_http_lua_ssl_sess_store_by_lua,
542542
NGX_HTTP_SRV_CONF_OFFSET,
543543
0,
544544
(void *) ngx_http_lua_ssl_sess_store_handler_file },
545545

546546
{ ngx_string("ssl_session_fetch_by_lua_block"),
547-
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
547+
NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
548548
ngx_http_lua_ssl_sess_fetch_by_lua_block,
549549
NGX_HTTP_SRV_CONF_OFFSET,
550550
0,
551551
(void *) ngx_http_lua_ssl_sess_fetch_handler_inline },
552552

553553
{ ngx_string("ssl_session_fetch_by_lua_file"),
554-
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
554+
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
555555
ngx_http_lua_ssl_sess_fetch_by_lua,
556556
NGX_HTTP_SRV_CONF_OFFSET,
557557
0,
@@ -983,21 +983,18 @@ ngx_http_lua_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
983983

984984
if (conf->srv.ssl_sess_store_src.len) {
985985
sscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_ssl_module);
986-
if (sscf == NULL || sscf->ssl.ctx == NULL) {
986+
if (sscf && sscf->ssl.ctx) {
987+
#ifdef LIBRESSL_VERSION_NUMBER
987988
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
988-
"no ssl configured for the server");
989+
"LibreSSL does not support "
990+
"ssl_session_store_by_lua*");
989991

990992
return NGX_CONF_ERROR;
991-
}
992-
993-
#ifdef LIBRESSL_VERSION_NUMBER
994-
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
995-
"LibreSSL does not support ssl_session_store_by_lua*");
996-
return NGX_CONF_ERROR;
997993
#else
998-
SSL_CTX_sess_set_new_cb(sscf->ssl.ctx,
999-
ngx_http_lua_ssl_sess_store_handler);
994+
SSL_CTX_sess_set_new_cb(sscf->ssl.ctx,
995+
ngx_http_lua_ssl_sess_store_handler);
1000996
#endif
997+
}
1001998
}
1002999

10031000
if (conf->srv.ssl_sess_fetch_src.len == 0) {
@@ -1008,21 +1005,18 @@ ngx_http_lua_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
10081005

10091006
if (conf->srv.ssl_sess_fetch_src.len) {
10101007
sscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_ssl_module);
1011-
if (sscf == NULL || sscf->ssl.ctx == NULL) {
1008+
if (sscf && sscf->ssl.ctx) {
1009+
#ifdef LIBRESSL_VERSION_NUMBER
10121010
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
1013-
"no ssl configured for the server");
1011+
"LibreSSL does not support "
1012+
"ssl_session_fetch_by_lua*");
10141013

10151014
return NGX_CONF_ERROR;
1016-
}
1017-
1018-
#ifdef LIBRESSL_VERSION_NUMBER
1019-
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
1020-
"LibreSSL does not support ssl_session_fetch_by_lua*");
1021-
return NGX_CONF_ERROR;
10221015
#else
1023-
SSL_CTX_sess_set_get_cb(sscf->ssl.ctx,
1024-
ngx_http_lua_ssl_sess_fetch_handler);
1016+
SSL_CTX_sess_set_get_cb(sscf->ssl.ctx,
1017+
ngx_http_lua_ssl_sess_fetch_handler);
10251018
#endif
1019+
}
10261020
}
10271021

10281022
#endif /* NGX_HTTP_SSL */

0 commit comments

Comments
 (0)