Support for HTTP/3 ALPN.

This is required by Chrome.
This commit is contained in:
Roman Arutyunyan 2020-03-23 19:26:24 +03:00
parent 77a4c2d172
commit ede2656c60
4 changed files with 22 additions and 11 deletions

View File

@ -11,8 +11,8 @@
#include <ngx_event_openssl.h> #include <ngx_event_openssl.h>
#define quic_version 0xff000018 /* draft-24 (ngtcp2) */ #define NGX_QUIC_DRAFT_VERSION 24
//#define quic_version 0xff00001b /* draft-27 (FFN 76) */ #define NGX_QUIC_VERSION (0xff000000 + NGX_QUIC_DRAFT_VERSION)
#define NGX_QUIC_MAX_SHORT_HEADER 25 #define NGX_QUIC_MAX_SHORT_HEADER 25
#define NGX_QUIC_MAX_LONG_HEADER 346 #define NGX_QUIC_MAX_LONG_HEADER 346

View File

@ -56,7 +56,7 @@ static u_char *ngx_quic_parse_int_multi(u_char *pos, u_char *end, ...);
static void ngx_quic_build_int(u_char **pos, uint64_t value); static void ngx_quic_build_int(u_char **pos, uint64_t value);
static u_char *ngx_quic_read_uint8(u_char *pos, u_char *end, uint8_t *value); static u_char *ngx_quic_read_uint8(u_char *pos, u_char *end, uint8_t *value);
/*static*/ u_char *ngx_quic_read_uint16(u_char *pos, u_char *end, uint16_t *value); // usage depends on quic_version /*static*/ u_char *ngx_quic_read_uint16(u_char *pos, u_char *end, uint16_t *value); // usage depends on NGX_QUIC_VERSION
static u_char *ngx_quic_read_uint32(u_char *pos, u_char *end, uint32_t *value); static u_char *ngx_quic_read_uint32(u_char *pos, u_char *end, uint32_t *value);
static u_char *ngx_quic_read_bytes(u_char *pos, u_char *end, size_t len, static u_char *ngx_quic_read_bytes(u_char *pos, u_char *end, size_t len,
u_char **out); u_char **out);
@ -295,7 +295,7 @@ ngx_quic_parse_long_header(ngx_quic_header_t *pkt)
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0,
"quic flags:%xi version:%xD", pkt->flags, pkt->version); "quic flags:%xi version:%xD", pkt->flags, pkt->version);
if (pkt->version != quic_version) { if (pkt->version != NGX_QUIC_VERSION) {
ngx_log_error(NGX_LOG_ERR, pkt->log, 0, ngx_log_error(NGX_LOG_ERR, pkt->log, 0,
"unsupported quic version: 0x%xi", pkt->version); "unsupported quic version: 0x%xi", pkt->version);
return NGX_ERROR; return NGX_ERROR;
@ -349,7 +349,7 @@ ngx_quic_create_long_header(ngx_quic_header_t *pkt, ngx_str_t *out,
*p++ = pkt->flags; *p++ = pkt->flags;
p = ngx_quic_write_uint32(p, quic_version); p = ngx_quic_write_uint32(p, NGX_QUIC_VERSION);
*p++ = pkt->scid.len; *p++ = pkt->scid.len;
p = ngx_cpymem(p, pkt->scid.data, pkt->scid.len); p = ngx_cpymem(p, pkt->scid.data, pkt->scid.len);
@ -1327,7 +1327,7 @@ ngx_quic_parse_transport_params(u_char *p, u_char *end, ngx_quic_tp_t *tp,
{ {
ngx_int_t rc; ngx_int_t rc;
#if (quic_version < 0xff00001b) #if (NGX_QUIC_DRAFT_VERSION < 27)
uint16_t id, len, tp_len; uint16_t id, len, tp_len;
@ -1493,7 +1493,7 @@ ngx_quic_create_transport_params(u_char *pos, u_char *end, ngx_quic_tp_t *tp)
u_char *p; u_char *p;
size_t len; size_t len;
#if (quic_version < 0xff00001b) #if (NGX_QUIC_DRAFT_VERSION < 27)
/* older drafts with static transport parameters encoding */ /* older drafts with static transport parameters encoding */
@ -1548,13 +1548,13 @@ ngx_quic_create_transport_params(u_char *pos, u_char *end, ngx_quic_tp_t *tp)
tp->initial_max_stream_data_uni); tp->initial_max_stream_data_uni);
if (pos == NULL) { if (pos == NULL) {
#if (quic_version < 0xff00001b) #if (NGX_QUIC_DRAFT_VERSION < 27)
len += 2; len += 2;
#endif #endif
return len; return len;
} }
#if (quic_version < 0xff00001b) #if (NGX_QUIC_DRAFT_VERSION < 27)
/* TLS extension length */ /* TLS extension length */
p = ngx_quic_write_uint16(p, len); p = ngx_quic_write_uint16(p, len);
#endif #endif

View File

@ -371,7 +371,7 @@ ngx_http_ssl_alpn_select(ngx_ssl_conn_t *ssl_conn, const unsigned char **out,
#if (NGX_DEBUG) #if (NGX_DEBUG)
unsigned int i; unsigned int i;
#endif #endif
#if (NGX_HTTP_V2) #if (NGX_HTTP_V2 || NGX_HTTP_V3)
ngx_http_connection_t *hc; ngx_http_connection_t *hc;
#endif #endif
#if (NGX_HTTP_V2 || NGX_DEBUG) #if (NGX_HTTP_V2 || NGX_DEBUG)
@ -388,15 +388,23 @@ ngx_http_ssl_alpn_select(ngx_ssl_conn_t *ssl_conn, const unsigned char **out,
} }
#endif #endif
#if (NGX_HTTP_V2) #if (NGX_HTTP_V2 || NGX_HTTP_V3)
hc = c->data; hc = c->data;
#endif
#if (NGX_HTTP_V2)
if (hc->addr_conf->http2) { if (hc->addr_conf->http2) {
srv = srv =
(unsigned char *) NGX_HTTP_V2_ALPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE; (unsigned char *) NGX_HTTP_V2_ALPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE;
srvlen = sizeof(NGX_HTTP_V2_ALPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE) - 1; srvlen = sizeof(NGX_HTTP_V2_ALPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE) - 1;
} else } else
#endif
#if (NGX_HTTP_V3)
if (hc->addr_conf->http3) {
srv = (unsigned char *) NGX_HTTP_V3_ALPN_ADVERTISE;
srvlen = sizeof(NGX_HTTP_V3_ALPN_ADVERTISE) - 1;
} else
#endif #endif
{ {
srv = (unsigned char *) NGX_HTTP_NPN_ADVERTISE; srv = (unsigned char *) NGX_HTTP_NPN_ADVERTISE;

View File

@ -17,6 +17,9 @@
#define NGX_HTTP_V3_STREAM 0x48335354 /* "H3ST" */ #define NGX_HTTP_V3_STREAM 0x48335354 /* "H3ST" */
#define NGX_HTTP_V3_ALPN(s) NGX_HTTP_V3_ALPN_DRAFT(s)
#define NGX_HTTP_V3_ALPN_DRAFT(s) "\x05h3-" #s
#define NGX_HTTP_V3_ALPN_ADVERTISE NGX_HTTP_V3_ALPN(NGX_QUIC_DRAFT_VERSION)
#define NGX_HTTP_V3_VARLEN_INT_LEN 4 #define NGX_HTTP_V3_VARLEN_INT_LEN 4
#define NGX_HTTP_V3_PREFIX_INT_LEN 11 #define NGX_HTTP_V3_PREFIX_INT_LEN 11