Skip to content

Commit 66b9539

Browse files
authored
Merge pull request #1828 from drawing/master
xquic: support lua cert cb
2 parents fb29798 + ca1126b commit 66b9539

File tree

7 files changed

+77
-2
lines changed

7 files changed

+77
-2
lines changed

modules/ngx_http_lua_module/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,3 +514,5 @@ CORE_INCS="$CORE_INCS $ngx_addon_dir/src/api"
514514
CFLAGS="$CFLAGS -DNDK_SET_VAR"
515515

516516
echo "/* DO NOT EDIT! This file was automatically generated by config */" > "$ngx_addon_dir/src/ngx_http_lua_autoconf.h"
517+
518+
have=T_NGX_HTTP_HAVE_LUA_MODULE . auto/have

modules/ngx_http_lua_module/src/ngx_http_lua_ssl_certby.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ ngx_http_lua_ssl_cert_handler(ngx_ssl_conn_t *ssl_conn, void *data)
231231

232232
hc = c->data;
233233

234+
#if (T_NGX_XQUIC)
235+
if (c->xquic_conn) {
236+
ngx_http_xquic_connection_t *qc = (ngx_http_xquic_connection_t *)c->data;
237+
hc = qc->http_connection;
238+
}
239+
#endif
240+
234241
fc = ngx_http_lua_create_fake_connection(NULL);
235242
if (fc == NULL) {
236243
goto failed;
@@ -255,6 +262,10 @@ ngx_http_lua_ssl_cert_handler(ngx_ssl_conn_t *ssl_conn, void *data)
255262
fc->log->log_level = c->log->log_level;
256263
fc->ssl = c->ssl;
257264

265+
#if (T_NGX_XQUIC)
266+
fc->xquic_conn = c->xquic_conn;
267+
#endif
268+
258269
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
259270

260271
#if (nginx_version >= 1009000)

modules/ngx_http_xquic_module/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ http {
100100

101101
# 浏览器使用 HTTP3
102102

103+
**注意:浏览器访问需要确保证书受信。**
104+
103105
浏览器默认不会使用 `HTTP3` 请求,需要服务端响应包头 `Alt-Svc` 进行升级说明,浏览器通过响应包头感知到服务端是支持 `HTTP3` 的,下次请求会尝试使用 `HTTP3`
104106

105107
```nginx
@@ -190,4 +192,4 @@ http {
190192
app: tengine
191193
```
192194
193-
对用户来讲,还是通过 443 端口访问,通过四层负责均衡设备,转换为 `Tengine` 的 2443 端口。
195+
对用户来讲,还是通过 443 端口访问,通过四层负载均衡设备,转换为 `Tengine` 的 2443 端口。

modules/ngx_http_xquic_module/ngx_http_xquic.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#endif
2121

2222

23+
#ifdef T_NGX_HTTP_HAVE_LUA_MODULE
24+
#include <ngx_http_lua_ssl_certby.h>
25+
extern ngx_module_t ngx_http_lua_module;
26+
#endif
2327

2428
ngx_int_t
2529
ngx_http_v3_conn_check_concurrent_cnt(ngx_http_xquic_main_conf_t *qmcf)
@@ -187,6 +191,22 @@ ngx_http_v3_cert_cb(const char *sni, void **chain,
187191
hc = qc->http_connection;
188192
c = qc->connection;
189193

194+
#ifdef T_NGX_HTTP_HAVE_LUA_MODULE
195+
ngx_http_lua_srv_conf_t *lscf = NULL;
196+
197+
lscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_lua_module);
198+
if (lscf != NULL && lscf->srv.ssl_cert_src.len) {
199+
ngx_ssl_conn_t *ssl_conn = qc->ssl_conn;
200+
201+
ngx_http_lua_ssl_cert_handler(ssl_conn, NULL);
202+
*chain = NULL;
203+
*cert = NULL;
204+
*key = NULL;
205+
206+
return XQC_OK;
207+
}
208+
#endif
209+
190210
/*
191211
* get the server core conf by sni, this is useful when multiple server
192212
* block listen on the same port. but useless when there is noly a single
@@ -256,6 +276,8 @@ int
256276
ngx_http_v3_conn_create_notify(xqc_h3_conn_t *h3_conn,
257277
const xqc_cid_t *cid, void *user_data)
258278
{
279+
ngx_connection_t *c;
280+
259281
/* we set alp user_data when accept connection */
260282
ngx_http_xquic_connection_t *user_conn = (ngx_http_xquic_connection_t *) user_data;
261283
user_conn->ssl_conn = (ngx_ssl_conn_t *) xqc_h3_conn_get_ssl(h3_conn);
@@ -265,6 +287,24 @@ ngx_http_v3_conn_create_notify(xqc_h3_conn_t *h3_conn,
265287

266288
xqc_h3_conn_set_user_data(h3_conn, user_conn);
267289

290+
c = user_conn->connection;
291+
292+
if (SSL_set_ex_data(user_conn->ssl_conn, ngx_ssl_connection_index, c) == 0)
293+
{
294+
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0, "|xquic|SSL_set_ex_data() failed|");
295+
return XQC_ERROR;
296+
}
297+
298+
c->xquic_conn = 1;
299+
300+
ngx_ssl_connection_t *p_ssl = ngx_pcalloc(c->pool, sizeof(ngx_ssl_connection_t));
301+
if (p_ssl == NULL) {
302+
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0, "|xquic|alloc ngx_ssl_connection_t failed|");
303+
return XQC_ERROR;
304+
}
305+
p_ssl->connection = user_conn->ssl_conn;
306+
c->ssl = p_ssl;
307+
268308
return NGX_OK;
269309
}
270310

modules/ngx_http_xquic_module/ngx_http_xquic_filter_module.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,18 @@ ngx_http_xquic_header_filter(ngx_http_request_t *r)
465465

466466
h->hash = 1;
467467
ngx_str_set(&h->key, NGX_HTTP_XQUIC_NAME_SERVER);
468-
if (clcf->server_tokens) {
468+
if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) {
469+
#if (T_NGX_SERVER_INFO)
470+
ngx_str_set(&h->value, TENGINE_VER);
471+
#else
469472
ngx_str_set(&h->value, NGINX_VER);
473+
#endif
474+
} else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) {
475+
#if (T_NGX_SERVER_INFO)
476+
ngx_str_set(&h->value, TENGINE_VER_BUILD);
477+
#else
478+
ngx_str_set(&h->value, NGINX_VER_BUILD);
479+
#endif
470480
} else {
471481
ngx_str_set(&h->value, TENGINE);
472482
}

src/core/ngx_connection.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ struct ngx_connection_s {
264264
#if (T_NGX_HAVE_XUDP)
265265
unsigned xudp_tx:1;
266266
#endif
267+
268+
#if (T_NGX_XQUIC)
269+
unsigned xquic_conn:1;
270+
#endif
267271
};
268272

269273

src/event/ngx_event_openssl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3898,7 +3898,13 @@ ngx_ssl_shutdown(ngx_connection_t *c)
38983898
return rc;
38993899
}
39003900

3901+
#if (T_NGX_XQUIC)
3902+
if (!c->xquic_conn) {
3903+
SSL_free(c->ssl->connection);
3904+
}
3905+
#else
39013906
SSL_free(c->ssl->connection);
3907+
#endif
39023908
c->ssl = NULL;
39033909
c->recv = ngx_recv;
39043910

0 commit comments

Comments
 (0)