Introduced quic_version macro, uint16/uint32 routines ported.

This commit is contained in:
Sergey Kandaurov 2020-02-28 13:09:52 +03:00
parent ef8b06b186
commit 8993721298
3 changed files with 50 additions and 10 deletions

View File

@ -271,10 +271,7 @@ quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn,
} else if (level == ssl_encryption_handshake) {
*p++ = 0xe0; // handshake, packet number len
}
*p++ = 0xff;
*p++ = 0x00;
*p++ = 0x00;
*p++ = 0x18;
p = ngx_quic_write_uint32(p, quic_version);
*p++ = qc->scid.len;
p = ngx_cpymem(p, qc->scid.data, qc->scid.len);
*p++ = qc->dcid.len;

View File

@ -10,6 +10,8 @@
#include <ngx_event_openssl.h>
#define quic_version 0xff000018
typedef struct {
ngx_str_t secret;
@ -58,4 +60,45 @@ ngx_int_t
ngx_quic_tls_hp(ngx_connection_t *c, const EVP_CIPHER *cipher,
ngx_quic_secret_t *s, u_char *out, u_char *in);
#if (NGX_HAVE_NONALIGNED)
#define ngx_quic_parse_uint16(p) ntohs(*(uint16_t *) (p))
#define ngx_quic_parse_uint32(p) ntohl(*(uint32_t *) (p))
#else
#define ngx_quic_parse_uint16(p) ((p)[0] << 8 | (p)[1])
#define ngx_quic_parse_uint32(p) \
((uint32_t) (p)[0] << 24 | (p)[1] << 16 | (p)[2] << 8 | (p)[3])
#endif
#define ngx_quic_write_uint16_aligned(p, s) \
(*(uint16_t *) (p) = htons((uint16_t) (s)), (p) + sizeof(uint16_t))
#define ngx_quic_write_uint32_aligned(p, s) \
(*(uint32_t *) (p) = htonl((uint32_t) (s)), (p) + sizeof(uint32_t))
#if (NGX_HAVE_NONALIGNED)
#define ngx_quic_write_uint16 ngx_quic_write_uint16_aligned
#define ngx_quic_write_uint32 ngx_quic_write_uint32_aligned
#else
#define ngx_quic_write_uint16(p, s) \
((p)[0] = (u_char) ((s) >> 8), \
(p)[1] = (u_char) (s), \
(p) + sizeof(uint16_t))
#define ngx_quic_write_uint32(p, s) \
((p)[0] = (u_char) ((s) >> 24), \
(p)[1] = (u_char) ((s) >> 16), \
(p)[2] = (u_char) ((s) >> 8), \
(p)[3] = (u_char) (s), \
(p) + sizeof(uint32_t))
#endif
#endif /* _NGX_EVENT_QUIC_H_INCLUDED_ */

View File

@ -691,13 +691,13 @@ ngx_http_quic_handshake(ngx_event_t *rev)
}
ngx_int_t flags = *b->pos++;
uint32_t version = ngx_http_v2_parse_uint32(b->pos);
b->pos += 4;
uint32_t version = ngx_quic_parse_uint32(b->pos);
b->pos += sizeof(uint32_t);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0,
"quic flags:%xi version:%xD", flags, version);
if (version != 0xff000018) {
if (version != quic_version) {
ngx_log_error(NGX_LOG_INFO, rev->log, 0, "unsupported quic version");
ngx_http_close_connection(c);
return;
@ -1117,13 +1117,13 @@ ngx_http_quic_handshake_handler(ngx_event_t *rev)
}
ngx_int_t flags = *p++;
uint32_t version = ngx_http_v2_parse_uint32(p);
p += 4;
uint32_t version = ngx_quic_parse_uint32(p);
p += sizeof(uint32_t);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0,
"quic flags:%xi version:%xD", flags, version);
if (version != 0xff000018) {
if (version != quic_version) {
ngx_log_error(NGX_LOG_INFO, rev->log, 0, "unsupported quic version");
ngx_http_close_connection(c);
return;