Skip to content

Commit 292b1e6

Browse files
committed
changes so that we can use ngx.ctx to pass data from downstream
phases to upstream phases & its related test case
1 parent c152081 commit 292b1e6

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

src/ngx_stream_lua_ctx.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ ngx_stream_lua_ffi_get_ctx_ref(ngx_stream_lua_request_t *r, int *in_ssl_phase,
9797
}
9898

9999
*in_ssl_phase = ctx->context & (NGX_STREAM_LUA_CONTEXT_SSL_CERT
100-
#ifdef HAVE_PROXY_SSL_PATCH
101-
| NGX_STREAM_LUA_CONTEXT_PROXY_SSL_VERIFY
102-
#endif
103100
| NGX_STREAM_LUA_CONTEXT_SSL_CLIENT_HELLO);
104101
*ssl_ctx_ref = LUA_NOREF;
105102

src/ngx_stream_lua_proxy_ssl_verifyby.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ ngx_stream_lua_proxy_ssl_verify_handler(X509_STORE_CTX *x509_store, void *arg)
258258
ngx_stream_lua_request_t *r = NULL;
259259
ngx_pool_cleanup_t *cln;
260260
ngx_stream_lua_srv_conf_t *lscf;
261+
ngx_stream_lua_ctx_t *ctx;
261262
ngx_stream_lua_ssl_ctx_t *cctx;
262263
ngx_stream_core_srv_conf_t *cscf;
263264
ngx_stream_session_t *s, *fs;
@@ -315,6 +316,14 @@ ngx_stream_lua_proxy_ssl_verify_handler(X509_STORE_CTX *x509_store, void *arg)
315316

316317
fs->main_conf = s->main_conf;
317318
fs->srv_conf = s->srv_conf;
319+
/*
320+
* so that we can use ngx.ctx to pass data from downstream phases to
321+
* upstream phases if there is any
322+
*/
323+
ctx = ngx_stream_get_module_ctx(s, ngx_stream_lua_module);
324+
if (ctx) {
325+
ngx_stream_set_ctx(fs, ctx, ngx_stream_lua_module);
326+
}
318327

319328
r = ngx_stream_lua_create_fake_request(fs);
320329
if (r == NULL) {

t/164-proxy-ssl-verify-by.t

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,3 +887,41 @@ qr/\[debug\] .*? SSL_do_handshake: 1/,
887887
proxy_ssl_verify_by_lua: openssl default verify
888888
[error]
889889
[alert]
890+
891+
892+
893+
=== TEST 22: ngx.ctx to pass data from downstream phase to upstream phase
894+
--- stream_config
895+
server {
896+
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
897+
898+
ssl_certificate ../../cert/mtls_server.crt;
899+
ssl_certificate_key ../../cert/mtls_server.key;
900+
901+
return 'it works!\n';
902+
}
903+
--- stream_server_config
904+
proxy_pass unix:$TEST_NGINX_HTML_DIR/nginx.sock;
905+
proxy_ssl on;
906+
proxy_ssl_verify on;
907+
proxy_ssl_name example.com;
908+
proxy_ssl_certificate ../../cert/mtls_client.crt;
909+
proxy_ssl_certificate_key ../../cert/mtls_client.key;
910+
proxy_ssl_trusted_certificate ../../cert/mtls_ca.crt;
911+
proxy_ssl_session_reuse off;
912+
913+
preread_by_lua_block {
914+
ngx.ctx.greeting = "I am from preread phase"
915+
}
916+
917+
proxy_ssl_verify_by_lua_block {
918+
ngx.log(ngx.INFO, "greeting: ", ngx.ctx.greeting)
919+
}
920+
--- stream_response
921+
it works!
922+
--- error_log
923+
greeting: I am from preread phase
924+
proxy_ssl_verify_by_lua: handler return value: 0, cert verify callback exit code: 1
925+
--- no_error_log
926+
[error]
927+
[alert]

0 commit comments

Comments
 (0)