annotate src/event/ngx_event_quic.c @ 8192:fb0879c65650 quic

Fixed ngx_quic_varint_len misuse in the previous change.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 05 Mar 2020 15:26:15 +0300
parents 7bd7c4e24951
children 4355efde26d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
2 /*
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
3 * Copyright (C) Nginx, Inc.
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
4 */
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
5
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
6
8171
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 #include <ngx_config.h>
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 #include <ngx_core.h>
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
9
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
10
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
11 #define quic_version 0xff000018
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
12
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
13 #define NGX_AES_128_GCM_SHA256 0x1301
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
14 #define NGX_AES_256_GCM_SHA384 0x1302
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
15
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
16
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
17 #if (NGX_HAVE_NONALIGNED)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
18
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
19 #define ngx_quic_parse_uint16(p) ntohs(*(uint16_t *) (p))
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
20 #define ngx_quic_parse_uint32(p) ntohl(*(uint32_t *) (p))
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
21
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
22 #define ngx_quic_write_uint16 ngx_quic_write_uint16_aligned
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
23 #define ngx_quic_write_uint32 ngx_quic_write_uint32_aligned
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
24
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
25 #else
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
26
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
27 #define ngx_quic_parse_uint16(p) ((p)[0] << 8 | (p)[1])
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
28 #define ngx_quic_parse_uint32(p) \
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
29 ((uint32_t) (p)[0] << 24 | (p)[1] << 16 | (p)[2] << 8 | (p)[3])
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
30
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
31 #define ngx_quic_write_uint16(p, s) \
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
32 ((p)[0] = (u_char) ((s) >> 8), \
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
33 (p)[1] = (u_char) (s), \
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
34 (p) + sizeof(uint16_t))
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
35
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
36 #define ngx_quic_write_uint32(p, s) \
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
37 ((p)[0] = (u_char) ((s) >> 24), \
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
38 (p)[1] = (u_char) ((s) >> 16), \
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
39 (p)[2] = (u_char) ((s) >> 8), \
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
40 (p)[3] = (u_char) (s), \
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
41 (p) + sizeof(uint32_t))
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
42
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
43 #endif
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
44
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
45
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
46 #define ngx_quic_write_uint16_aligned(p, s) \
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
47 (*(uint16_t *) (p) = htons((uint16_t) (s)), (p) + sizeof(uint16_t))
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
48
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
49 #define ngx_quic_write_uint32_aligned(p, s) \
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
50 (*(uint32_t *) (p) = htonl((uint32_t) (s)), (p) + sizeof(uint32_t))
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
51
8191
7bd7c4e24951 Macro for calculating size of varint.
Vladimir Homutov <vl@nginx.com>
parents: 8190
diff changeset
52 #define ngx_quic_varint_len(value) \
7bd7c4e24951 Macro for calculating size of varint.
Vladimir Homutov <vl@nginx.com>
parents: 8190
diff changeset
53 ((value) <= 63 ? 1 : (value) <= 16383 ? 2 : (value) <= 1073741823 ? 4 : 8)
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
54
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
55
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
56 #if (NGX_DEBUG)
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
57
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
58 #define ngx_quic_hexdump(log, fmt, data, len, ...) \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
59 do { \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
60 ngx_int_t m; \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
61 u_char buf[2048]; \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
62 \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
63 if (log->log_level & NGX_LOG_DEBUG_EVENT) { \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
64 m = ngx_hex_dump(buf, (u_char *) data, ngx_min(len, 1024)) - buf; \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
65 ngx_log_debug(NGX_LOG_DEBUG_EVENT, log, 0, \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
66 "%s: " fmt " %*s%s, len: %uz", \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
67 __FUNCTION__, __VA_ARGS__, m, buf, \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
68 len < 2048 ? "" : "...", len); \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
69 } \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
70 } while (0)
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
71
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
72 #else
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
73
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
74 #define ngx_quic_hexdump(log, fmt, data, len, ...)
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
75
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
76 #endif
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
77
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
78 #define ngx_quic_hexdump0(log, fmt, data, len) \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
79 ngx_quic_hexdump(log, fmt "%s", data, len, "") \
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
80
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
81
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
82 /* 17.2. Long Header Packets */
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
83
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
84 #define NGX_QUIC_PKT_LONG 0x80
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
85
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
86 #define NGX_QUIC_PKT_INITIAL 0xc0
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
87 #define NGX_QUIC_PKT_HANDSHAKE 0xe0
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
88
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
89 /* 12.4. Frames and Frame Types */
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
90 #define NGX_QUIC_FT_PADDING 0x00
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
91 #define NGX_QUIC_FT_PING 0x01
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
92 #define NGX_QUIC_FT_ACK 0x02
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
93 #define NGX_QUIC_FT_ACK_ECN 0x03
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
94 #define NGX_QUIC_FT_RESET_STREAM 0x04
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
95 #define NGX_QUIC_FT_STOP_SENDING 0x05
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
96 #define NGX_QUIC_FT_CRYPTO 0x06
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
97 #define NGX_QUIC_FT_NEW_TOKEN 0x07
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
98 #define NGX_QUIC_FT_STREAM 0x08 // - 0x0f
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
99 #define NGX_QUIC_FT_MAX_DATA 0x10
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
100 #define NGX_QUIC_FT_MAX_STREAM_DATA 0x11
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
101 #define NGX_QUIC_FT_MAX_STREAMS 0x12
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
102 #define NGX_QUIC_FT_MAX_STREAMS2 0x13 // XXX
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
103 #define NGX_QUIC_FT_DATA_BLOCKED 0x14
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
104 #define NGX_QUIC_FT_STREAM_DATA_BLOCKED 0x15
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
105 #define NGX_QUIC_FT_STREAMS_BLOCKED 0x16
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
106 #define NGX_QUIC_FT_STREAMS_BLOCKED2 0x17 // XXX
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
107 #define NGX_QUIC_FT_NEW_CONNECTION_ID 0x18
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
108 #define NGX_QUIC_FT_RETIRE_CONNECTION_ID 0x19
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
109 #define NGX_QUIC_FT_PATH_CHALLENGE 0x1a
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
110 #define NGX_QUIC_FT_PATH_RESPONSE 0x1b
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
111 #define NGX_QUIC_FT_CONNECTION_CLOSE 0x1c
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
112 #define NGX_QUIC_FT_CONNECTION_CLOSE2 0x1d // XXX
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
113 #define NGX_QUIC_FT_HANDSHAKE_DONE 0x1e
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
114
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
115
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
116 /* TODO: real states, these are stubs */
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
117 typedef enum {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
118 NGX_QUIC_ST_INITIAL,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
119 NGX_QUIC_ST_HANDSHAKE,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
120 NGX_QUIC_ST_APP_DATA
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
121 } ngx_quic_state_t;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
122
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
123
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
124 typedef struct {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
125 ngx_str_t secret;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
126 ngx_str_t key;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
127 ngx_str_t iv;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
128 ngx_str_t hp;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
129 } ngx_quic_secret_t;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
130
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
131
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
132 typedef enum ssl_encryption_level_t ngx_quic_level_t;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
133
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
134 typedef struct ngx_quic_frame_s ngx_quic_frame_t;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
135
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
136 typedef struct {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
137 ngx_uint_t pn;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
138 // ngx_uint_t nranges;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
139 // ...
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
140 } ngx_quic_ack_frame_t;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
141
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
142 typedef ngx_str_t ngx_quic_crypto_frame_t;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
143
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
144 struct ngx_quic_frame_s {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
145 ngx_uint_t type;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
146 ngx_quic_level_t level;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
147 ngx_quic_frame_t *next;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
148 union {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
149 ngx_quic_crypto_frame_t crypto;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
150 ngx_quic_ack_frame_t ack;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
151 // more frames
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
152 } u;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
153
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
154 u_char info[128]; // for debug purposes
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
155 };
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
156
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
157
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
158 struct ngx_quic_connection_s {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
159
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
160 ngx_quic_state_t state;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
161 ngx_ssl_t *ssl;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
162
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
163 ngx_quic_frame_t *frames;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
164
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
165 ngx_str_t scid;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
166 ngx_str_t dcid;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
167 ngx_str_t token;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
168
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
169 /* current packet numbers for each namespace */
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
170 ngx_uint_t initial_pn;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
171 ngx_uint_t handshake_pn;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
172 ngx_uint_t appdata_pn;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
173
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
174 ngx_quic_secret_t client_in;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
175 ngx_quic_secret_t client_hs;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
176 ngx_quic_secret_t client_ad;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
177 ngx_quic_secret_t server_in;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
178 ngx_quic_secret_t server_hs;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
179 ngx_quic_secret_t server_ad;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
180 };
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
181
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
182
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
183 typedef struct {
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
184 ngx_quic_secret_t *secret;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
185 ngx_uint_t type;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
186 ngx_uint_t *number;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
187 ngx_uint_t flags;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
188 ngx_uint_t version;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
189 ngx_str_t *token;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
190 ngx_quic_level_t level;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
191 } ngx_quic_header_t;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
192
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
193
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
194 static ngx_int_t ngx_quic_new_connection(ngx_connection_t *c, ngx_ssl_t *ssl,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
195 ngx_buf_t *b);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
196 static ngx_int_t ngx_quic_handshake_input(ngx_connection_t *c, ngx_buf_t *b);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
197
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
198 static int ngx_quic_set_encryption_secrets(ngx_ssl_conn_t *ssl_conn,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
199 enum ssl_encryption_level_t level, const uint8_t *read_secret,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
200 const uint8_t *write_secret, size_t secret_len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
201 static int ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
202 enum ssl_encryption_level_t level, const uint8_t *data, size_t len);
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
203 static ngx_int_t ngx_quic_create_long_packet(ngx_connection_t *c,
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
204 ngx_ssl_conn_t *ssl_conn, ngx_quic_header_t *pkt, ngx_str_t *in,
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
205 ngx_str_t *res);
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
206 static ngx_int_t ngx_quic_create_short_packet(ngx_connection_t *c,
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
207 ngx_ssl_conn_t *ssl_conn, ngx_quic_header_t *pkt, ngx_str_t *in,
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
208 ngx_str_t *res);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
209 static int ngx_quic_flush_flight(ngx_ssl_conn_t *ssl_conn);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
210 static int ngx_quic_send_alert(ngx_ssl_conn_t *ssl_conn,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
211 enum ssl_encryption_level_t level, uint8_t alert);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
212
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
213 static uint64_t ngx_quic_parse_pn(u_char **pos, ngx_int_t len, u_char *mask);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
214 static uint64_t ngx_quic_parse_int(u_char **pos);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
215 static void ngx_quic_build_int(u_char **pos, uint64_t value);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
216
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
217 static ngx_int_t ngx_hkdf_extract(u_char *out_key, size_t *out_len,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
218 const EVP_MD *digest, const u_char *secret, size_t secret_len,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
219 const u_char *salt, size_t salt_len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
220 static ngx_int_t ngx_hkdf_expand(u_char *out_key, size_t out_len,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
221 const EVP_MD *digest, const u_char *prk, size_t prk_len,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
222 const u_char *info, size_t info_len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
223
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
224 static ngx_int_t ngx_quic_hkdf_expand(ngx_connection_t *c, const EVP_MD *digest,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
225 ngx_str_t *out, ngx_str_t *label, const uint8_t *prk, size_t prk_len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
226
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
227 static ngx_int_t ngx_quic_tls_open(ngx_connection_t *c,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
228 const EVP_CIPHER *cipher, ngx_quic_secret_t *s, ngx_str_t *out,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
229 u_char *nonce, ngx_str_t *in, ngx_str_t *ad);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
230 static ngx_int_t ngx_quic_tls_seal(ngx_connection_t *c,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
231 const EVP_CIPHER *cipher, ngx_quic_secret_t *s, ngx_str_t *out,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
232 u_char *nonce, ngx_str_t *in, ngx_str_t *ad);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
233
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
234 static ngx_int_t ngx_quic_tls_hp(ngx_connection_t *c, const EVP_CIPHER *cipher,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
235 ngx_quic_secret_t *s, u_char *out, u_char *in);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
236
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
237
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
238 static SSL_QUIC_METHOD quic_method = {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
239 ngx_quic_set_encryption_secrets,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
240 ngx_quic_add_handshake_data,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
241 ngx_quic_flush_flight,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
242 ngx_quic_send_alert,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
243 };
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
244
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
245
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
246 void
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
247 ngx_quic_init_ssl_methods(SSL_CTX* ctx)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
248 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
249 SSL_CTX_set_quic_method(ctx, &quic_method);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
250 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
251
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
252
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
253 ngx_int_t
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
254 ngx_quic_input(ngx_connection_t *c, ngx_ssl_t *ssl, ngx_buf_t *b)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
255 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
256 if (c->quic == NULL) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
257 return ngx_quic_new_connection(c, ssl, b); //TODO: change state by results
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
258 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
259
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
260 switch (c->quic->state) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
261 case NGX_QUIC_ST_INITIAL:
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
262 case NGX_QUIC_ST_HANDSHAKE:
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
263 return ngx_quic_handshake_input(c, b);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
264 default:
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
265 /* application data */
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
266 break;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
267 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
268
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
269 return NGX_OK;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
270 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
271
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
272 static ngx_int_t
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
273 ngx_quic_send_packet(ngx_connection_t *c, ngx_quic_connection_t *qc,
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
274 ngx_quic_level_t level, ngx_str_t *payload)
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
275 {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
276 ngx_str_t res;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
277 ngx_quic_header_t pkt;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
278
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
279 static ngx_str_t initial_token = ngx_null_string;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
280
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
281 ngx_memzero(&pkt, sizeof(ngx_quic_header_t));
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
282 ngx_quic_hexdump0(c->log, "payload", payload->data, payload->len);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
283
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
284 pkt.level = level;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
285
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
286 if (level == ssl_encryption_initial) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
287 pkt.number = &qc->initial_pn;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
288 pkt.flags = NGX_QUIC_PKT_INITIAL;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
289 pkt.secret = &qc->server_in;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
290 pkt.token = &initial_token;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
291
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
292 if (ngx_quic_create_long_packet(c, c->ssl->connection,
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
293 &pkt, payload, &res)
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
294 != NGX_OK)
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
295 {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
296 return NGX_ERROR;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
297 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
298
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
299 } else if (level == ssl_encryption_handshake) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
300 pkt.number = &qc->handshake_pn;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
301 pkt.flags = NGX_QUIC_PKT_HANDSHAKE;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
302 pkt.secret = &qc->server_hs;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
303
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
304 if (ngx_quic_create_long_packet(c, c->ssl->connection,
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
305 &pkt, payload, &res)
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
306 != NGX_OK)
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
307 {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
308 return NGX_ERROR;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
309 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
310
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
311 } else {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
312 pkt.number = &qc->appdata_pn;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
313 pkt.secret = &qc->server_ad;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
314
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
315 if (ngx_quic_create_short_packet(c, c->ssl->connection,
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
316 &pkt, payload, &res)
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
317 != NGX_OK)
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
318 {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
319 return NGX_ERROR;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
320 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
321 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
322
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
323 ngx_quic_hexdump0(c->log, "packet to send", res.data, res.len);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
324
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
325 c->send(c, res.data, res.len); // TODO: err handling
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
326
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
327 return NGX_OK;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
328 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
329
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
330
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
331 static size_t
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
332 ngx_quic_create_ack(u_char *p, ngx_quic_ack_frame_t *ack)
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
333 {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
334 if (p == NULL) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
335 return 5; /* minimal ACK */
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
336 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
337
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
338 ngx_quic_build_int(&p, NGX_QUIC_FT_ACK);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
339 ngx_quic_build_int(&p, ack->pn);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
340 ngx_quic_build_int(&p, 0);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
341 ngx_quic_build_int(&p, 0);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
342 ngx_quic_build_int(&p, ack->pn);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
343
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
344 return 5;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
345 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
346
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
347
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
348 static size_t
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
349 ngx_quic_create_crypto(u_char *p, ngx_quic_crypto_frame_t *crypto)
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
350 {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
351 u_char *start;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
352
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
353 if (p == NULL) {
8192
fb0879c65650 Fixed ngx_quic_varint_len misuse in the previous change.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8191
diff changeset
354 return 2 + ngx_quic_varint_len(crypto->len) + crypto->len;
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
355 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
356
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
357 start = p;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
358
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
359 ngx_quic_build_int(&p, NGX_QUIC_FT_CRYPTO);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
360 ngx_quic_build_int(&p, 0);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
361 ngx_quic_build_int(&p, crypto->len);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
362 p = ngx_cpymem(p, crypto->data, crypto->len);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
363
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
364 return p - start;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
365 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
366
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
367 size_t
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
368 ngx_quic_frame_len(ngx_quic_frame_t *frame)
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
369 {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
370 switch (frame->type) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
371 case NGX_QUIC_FT_ACK:
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
372 return ngx_quic_create_ack(NULL, &frame->u.ack);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
373 case NGX_QUIC_FT_CRYPTO:
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
374 return ngx_quic_create_crypto(NULL, &frame->u.crypto);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
375 default:
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
376 /* BUG: unsupported frame type generated */
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
377 return 0;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
378 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
379 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
380
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
381
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
382 /* pack a group of frames [start; end) into memory p and send as single packet */
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
383 ngx_int_t
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
384 ngx_quic_frames_send(ngx_connection_t *c, ngx_quic_frame_t *start,
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
385 ngx_quic_frame_t *end, size_t total)
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
386 {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
387 u_char *p;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
388 ngx_str_t out;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
389 ngx_quic_frame_t *f;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
390
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
391 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
392 "sending frames %p...%p", start, end);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
393
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
394 p = ngx_pnalloc(c->pool, total);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
395 if (p == NULL) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
396 return NGX_ERROR;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
397 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
398
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
399 out.data = p;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
400
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
401 for (f = start; f != end; f = f->next) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
402
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
403 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "frame: %s", f->info);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
404
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
405 switch (f->type) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
406 case NGX_QUIC_FT_ACK:
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
407 p += ngx_quic_create_ack(p, &f->u.ack);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
408 break;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
409
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
410 case NGX_QUIC_FT_CRYPTO:
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
411 p += ngx_quic_create_crypto(p, &f->u.crypto);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
412 break;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
413
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
414 default:
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
415 /* BUG: unsupported frame type generated */
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
416 return NGX_ERROR;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
417 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
418 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
419
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
420 out.len = p - out.data;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
421
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
422 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
423 "packet ready: %ui bytes at level %d",
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
424 out.len, start->level);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
425
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
426 // IOVEC/sendmsg_chain ?
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
427 if (ngx_quic_send_packet(c, c->quic, start->level, &out) != NGX_OK) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
428 return NGX_ERROR;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
429 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
430
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
431 return NGX_OK;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
432 }
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
433
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
434 ngx_int_t
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
435 ngx_quic_output(ngx_connection_t *c)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
436 {
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
437 size_t len;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
438 ngx_uint_t lvl;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
439 ngx_quic_frame_t *f, *start;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
440 ngx_quic_connection_t *qc;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
441
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
442 qc = c->quic;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
443
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
444 if (qc->frames == NULL) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
445 return NGX_OK;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
446 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
447
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
448 lvl = qc->frames->level;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
449 start = qc->frames;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
450 f = start;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
451
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
452 do {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
453 len = 0;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
454
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
455 do {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
456 /* process same-level group of frames */
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
457
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
458 len += ngx_quic_frame_len(f);// TODO: handle overflow, max size
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
459
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
460 f = f->next;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
461 } while (f && f->level == lvl);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
462
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
463
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
464 if (ngx_quic_frames_send(c, start, f, len) != NGX_OK) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
465 return NGX_ERROR;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
466 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
467
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
468 if (f == NULL) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
469 break;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
470 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
471
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
472 lvl = f->level; // TODO: must not decrease (ever, also between calls)
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
473 start = f;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
474
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
475 } while (1);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
476
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
477 qc->frames = NULL;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
478
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
479 return NGX_OK;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
480 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
481
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
482
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
483 static int
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
484 ngx_quic_set_encryption_secrets(ngx_ssl_conn_t *ssl_conn,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
485 enum ssl_encryption_level_t level, const uint8_t *read_secret,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
486 const uint8_t *write_secret, size_t secret_len)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
487 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
488 ngx_uint_t i;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
489 const EVP_MD *digest;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
490 const EVP_CIPHER *cipher;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
491 ngx_connection_t *c;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
492 ngx_quic_secret_t *client, *server;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
493
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
494 c = ngx_ssl_get_connection((ngx_ssl_conn_t *) ssl_conn);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
495
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
496 ngx_quic_hexdump(c->log, "level:%d read", read_secret, secret_len, level);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
497 ngx_quic_hexdump(c->log, "level:%d read", write_secret, secret_len, level);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
498
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
499 switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl_conn)) & 0xffff) {
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
500
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
501 case NGX_AES_128_GCM_SHA256:
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
502 cipher = EVP_aes_128_gcm();
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
503 digest = EVP_sha256();
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
504 break;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
505
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
506 case NGX_AES_256_GCM_SHA384:
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
507 cipher = EVP_aes_256_gcm();
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
508 digest = EVP_sha384();
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
509 break;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
510
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
511 default:
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
512 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "unexpected cipher");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
513 return 0;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
514 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
515
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
516 switch (level) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
517
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
518 case ssl_encryption_handshake:
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
519 client = &c->quic->client_hs;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
520 server = &c->quic->server_hs;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
521
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
522 break;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
523
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
524 case ssl_encryption_application:
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
525 client = &c->quic->client_ad;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
526 server = &c->quic->server_ad;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
527
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
528 break;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
529
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
530 default:
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
531 return 0;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
532 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
533
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
534 client->key.len = EVP_CIPHER_key_length(cipher);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
535 server->key.len = EVP_CIPHER_key_length(cipher);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
536
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
537 client->iv.len = EVP_CIPHER_iv_length(cipher);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
538 server->iv.len = EVP_CIPHER_iv_length(cipher);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
539
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
540 client->hp.len = EVP_CIPHER_key_length(cipher);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
541 server->hp.len = EVP_CIPHER_key_length(cipher);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
542
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
543 struct {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
544 ngx_str_t label;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
545 ngx_str_t *key;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
546 const uint8_t *secret;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
547 } seq[] = {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
548 { ngx_string("tls13 quic key"), &client->key, read_secret },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
549 { ngx_string("tls13 quic iv"), &client->iv, read_secret },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
550 { ngx_string("tls13 quic hp"), &client->hp, read_secret },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
551 { ngx_string("tls13 quic key"), &server->key, write_secret },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
552 { ngx_string("tls13 quic iv"), &server->iv, write_secret },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
553 { ngx_string("tls13 quic hp"), &server->hp, write_secret },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
554 };
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
555
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
556 for (i = 0; i < (sizeof(seq) / sizeof(seq[0])); i++) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
557
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
558 if (ngx_quic_hkdf_expand(c, digest, seq[i].key, &seq[i].label,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
559 seq[i].secret, secret_len)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
560 != NGX_OK)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
561 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
562 return 0;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
563 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
564 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
565
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
566 return 1;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
567 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
568
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
569
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
570 static ngx_int_t
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
571 ngx_quic_create_long_packet(ngx_connection_t *c, ngx_ssl_conn_t *ssl_conn,
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
572 ngx_quic_header_t *pkt, ngx_str_t *payload, ngx_str_t *res)
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
573 {
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
574 u_char *p, *pnp, *nonce, *sample, *packet;
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
575 ngx_str_t ad, out;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
576 const EVP_CIPHER *cipher;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
577 ngx_quic_connection_t *qc;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
578
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
579 u_char mask[16];
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
580
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
581 qc = c->quic;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
582
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
583 out.len = payload->len + EVP_GCM_TLS_TAG_LEN;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
584
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
585 ad.data = ngx_alloc(346 /*max header*/, c->log);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
586 if (ad.data == 0) {
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
587 return NGX_ERROR;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
588 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
589
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
590 p = ad.data;
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
591
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
592 *p++ = pkt->flags;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
593
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
594 p = ngx_quic_write_uint32(p, quic_version);
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
595
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
596 *p++ = qc->scid.len;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
597 p = ngx_cpymem(p, qc->scid.data, qc->scid.len);
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
598
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
599 *p++ = qc->dcid.len;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
600 p = ngx_cpymem(p, qc->dcid.data, qc->dcid.len);
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
601
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
602 if (pkt->token) { // if pkt->flags & initial ?
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
603 ngx_quic_build_int(&p, pkt->token->len);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
604 }
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
605
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
606 ngx_quic_build_int(&p, out.len + 1); // length (inc. pnl)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
607 pnp = p;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
608
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
609 *p++ = (*pkt->number)++;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
610
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
611 ad.len = p - ad.data;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
612
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
613 ngx_quic_hexdump0(c->log, "ad", ad.data, ad.len);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
614
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
615 switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl_conn)) & 0xffff) {
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
616
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
617 case NGX_AES_128_GCM_SHA256:
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
618 cipher = EVP_aes_128_gcm();
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
619 break;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
620
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
621 case NGX_AES_256_GCM_SHA384:
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
622 cipher = EVP_aes_256_gcm();
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
623 break;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
624
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
625 default:
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
626 return NGX_ERROR;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
627 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
628
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
629 nonce = ngx_pstrdup(c->pool, &pkt->secret->iv);
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
630 if (pkt->level == ssl_encryption_handshake) {
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
631 nonce[11] ^= (*pkt->number - 1);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
632 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
633
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
634 ngx_quic_hexdump0(c->log, "server_iv", pkt->secret->iv.data, 12);
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
635 ngx_quic_hexdump0(c->log, "nonce", nonce, 12);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
636
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
637 if (ngx_quic_tls_seal(c, cipher, pkt->secret, &out, nonce, payload, &ad) != NGX_OK) {
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
638 return NGX_ERROR;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
639 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
640
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
641 sample = &out.data[3]; // pnl=0
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
642 if (ngx_quic_tls_hp(c, EVP_aes_128_ecb(), pkt->secret, mask, sample) != NGX_OK) {
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
643 return NGX_ERROR;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
644 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
645
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
646 ngx_quic_hexdump0(c->log, "sample", sample, 16);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
647 ngx_quic_hexdump0(c->log, "mask", mask, 16);
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
648 ngx_quic_hexdump0(c->log, "hp_key", pkt->secret->hp.data, 16);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
649
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
650 // header protection, pnl = 0
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
651 ad.data[0] ^= mask[0] & 0x0f;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
652 *pnp ^= mask[1];
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
653
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
654 packet = ngx_alloc(ad.len + out.len, c->log);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
655 if (packet == 0) {
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
656 return NGX_ERROR;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
657 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
658
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
659 p = ngx_cpymem(packet, ad.data, ad.len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
660 p = ngx_cpymem(p, out.data, out.len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
661
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
662 res->data = packet;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
663 res->len = p - packet;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
664
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
665 return NGX_OK;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
666 }
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
667
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
668
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
669 static ngx_int_t
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
670 ngx_quic_create_short_packet(ngx_connection_t *c, ngx_ssl_conn_t *ssl_conn,
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
671 ngx_quic_header_t *pkt, ngx_str_t *payload, ngx_str_t *res)
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
672 {
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
673 u_char *p, *pnp, *nonce, *sample, *packet;
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
674 ngx_str_t ad, out;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
675 const EVP_CIPHER *cipher;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
676 ngx_quic_connection_t *qc;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
677
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
678 u_char mask[16];
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
679
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
680 qc = c->quic;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
681
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
682 out.len = payload->len + EVP_GCM_TLS_TAG_LEN;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
683
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
684 ad.data = ngx_alloc(25 /*max header*/, c->log);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
685 if (ad.data == 0) {
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
686 return NGX_ERROR;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
687 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
688
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
689 p = ad.data;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
690
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
691 *p++ = 0x40;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
692
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
693 p = ngx_cpymem(p, qc->scid.data, qc->scid.len);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
694
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
695 pnp = p;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
696
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
697 *p++ = (*pkt->number)++;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
698
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
699 ad.len = p - ad.data;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
700
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
701 ngx_quic_hexdump0(c->log, "ad", ad.data, ad.len);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
702
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
703 switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl_conn)) & 0xffff) {
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
704
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
705 case NGX_AES_128_GCM_SHA256:
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
706 cipher = EVP_aes_128_gcm();
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
707 break;
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
708
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
709 case NGX_AES_256_GCM_SHA384:
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
710 cipher = EVP_aes_256_gcm();
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
711 break;
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
712
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
713 default:
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
714 return NGX_ERROR;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
715 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
716
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
717 nonce = ngx_pstrdup(c->pool, &pkt->secret->iv);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
718 if (pkt->level == ssl_encryption_handshake) {
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
719 nonce[11] ^= (*pkt->number - 1);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
720 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
721
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
722 ngx_quic_hexdump0(c->log, "server_iv", pkt->secret->iv.data, 12);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
723 ngx_quic_hexdump0(c->log, "nonce", nonce, 12);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
724
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
725 if (ngx_quic_tls_seal(c, cipher, pkt->secret, &out, nonce, payload, &ad)
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
726 != NGX_OK)
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
727 {
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
728 return NGX_ERROR;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
729 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
730
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
731 ngx_quic_hexdump0(c->log, "out", out.data, out.len);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
732
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
733 sample = &out.data[3]; // pnl=0
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
734 if (ngx_quic_tls_hp(c, EVP_aes_128_ecb(), pkt->secret, mask, sample)
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
735 != NGX_OK)
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
736 {
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
737 return NGX_ERROR;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
738 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
739
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
740 ngx_quic_hexdump0(c->log, "sample", sample, 16);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
741 ngx_quic_hexdump0(c->log, "mask", mask, 16);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
742 ngx_quic_hexdump0(c->log, "hp_key", pkt->secret->hp.data, 16);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
743
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
744 // header protection, pnl = 0
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
745 ad.data[0] ^= mask[0] & 0x1f;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
746 *pnp ^= mask[1];
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
747
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
748 packet = ngx_alloc(ad.len + out.len, c->log);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
749 if (packet == 0) {
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
750 return NGX_ERROR;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
751 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
752
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
753 p = ngx_cpymem(packet, ad.data, ad.len);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
754 p = ngx_cpymem(p, out.data, out.len);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
755
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
756 ngx_quic_hexdump0(c->log, "packet", packet, p - packet);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
757
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
758 res->data = packet;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
759 res->len = p - packet;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
760
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
761 return NGX_OK;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
762 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
763
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
764
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
765 static void
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
766 ngx_quic_queue_frame(ngx_quic_connection_t *qc, ngx_quic_frame_t *frame)
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
767 {
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
768 ngx_quic_frame_t *f;
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
769
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
770 if (qc->frames == NULL) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
771 qc->frames = frame;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
772 return;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
773 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
774
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
775 for (f = qc->frames; f->next; f = f->next) { /* void */ }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
776
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
777 f->next = frame;
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
778 }
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
779
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
780
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
781 static int
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
782 ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn,
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
783 enum ssl_encryption_level_t level, const uint8_t *data, size_t len)
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
784 {
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
785 u_char *p;
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
786 ngx_quic_frame_t *frame;
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
787 ngx_connection_t *c;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
788 ngx_quic_connection_t *qc;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
789
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
790 c = ngx_ssl_get_connection((ngx_ssl_conn_t *) ssl_conn);
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
791 qc = c->quic;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
792
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
793 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
794 "ngx_quic_add_handshake_data");
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
795
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
796 frame = ngx_pcalloc(c->pool, sizeof(ngx_quic_frame_t));
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
797 if (frame == NULL) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
798 return 0;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
799 }
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
800
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
801 p = ngx_pnalloc(c->pool, len);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
802 if (p == NULL) {
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
803 return 0;
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
804 }
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
805
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
806 ngx_memcpy(p, data, len);
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
807
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
808 frame->level = level;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
809 frame->type = NGX_QUIC_FT_CRYPTO;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
810 frame->u.crypto.len = len;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
811 frame->u.crypto.data = p;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
812
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
813 ngx_sprintf(frame->info, "crypto, generated by SSL len=%ui level=%d", len, level);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
814
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
815 ngx_quic_queue_frame(qc, frame);
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
816
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
817 if (level == ssl_encryption_initial) {
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
818 frame = ngx_pcalloc(c->pool, sizeof(ngx_quic_frame_t));
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
819 if (frame == NULL) {
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
820 return 0;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
821 }
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
822 frame->level = level;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
823 frame->type = NGX_QUIC_FT_ACK;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
824 frame->u.ack.pn = 0;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
825 ngx_sprintf(frame->info, "ACK for PN=0 at initial, added manually from add_handshake_data");
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
826
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
827 ngx_quic_queue_frame(qc, frame);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
828 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
829
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
830 return 1;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
831 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
832
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
833
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
834 static int
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
835 ngx_quic_flush_flight(ngx_ssl_conn_t *ssl_conn)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
836 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
837 ngx_connection_t *c;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
838
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
839 c = ngx_ssl_get_connection((ngx_ssl_conn_t *) ssl_conn);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
840
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
841 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "ngx_quic_flush_flight()");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
842
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
843 if (ngx_quic_output(c) != NGX_OK) {
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
844 return 0;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
845 }
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
846
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
847 return 1;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
848 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
849
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
850
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
851 static int
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
852 ngx_quic_send_alert(ngx_ssl_conn_t *ssl_conn, enum ssl_encryption_level_t level,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
853 uint8_t alert)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
854 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
855 ngx_connection_t *c;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
856
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
857 c = ngx_ssl_get_connection((ngx_ssl_conn_t *) ssl_conn);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
858
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
859 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
860 "ngx_quic_send_alert(), lvl=%d, alert=%d",
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
861 (int) level, (int) alert);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
862
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
863 return 1;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
864 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
865
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
866
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
867 static ngx_int_t
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
868 ngx_quic_new_connection(ngx_connection_t *c, ngx_ssl_t *ssl, ngx_buf_t *b)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
869 {
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
870 int n, sslerr;
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
871 ngx_quic_connection_t *qc;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
872
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
873 if ((b->pos[0] & 0xf0) != NGX_QUIC_PKT_INITIAL) {
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
874 ngx_log_error(NGX_LOG_INFO, c->log, 0, "invalid initial packet");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
875 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
876 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
877
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
878 if (ngx_buf_size(b) < 1200) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
879 ngx_log_error(NGX_LOG_INFO, c->log, 0, "too small UDP datagram");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
880 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
881 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
882
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
883 ngx_int_t flags = *b->pos++;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
884 uint32_t version = ngx_quic_parse_uint32(b->pos);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
885 b->pos += sizeof(uint32_t);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
886
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
887 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
888 "quic flags:%xi version:%xD", flags, version);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
889
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
890 if (version != quic_version) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
891 ngx_log_error(NGX_LOG_INFO, c->log, 0, "unsupported quic version");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
892 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
893 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
894
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
895 qc = ngx_pcalloc(c->pool, sizeof(ngx_quic_connection_t));
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
896 if (qc == NULL) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
897 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
898 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
899
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
900 c->quic = qc;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
901
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
902 qc->dcid.len = *b->pos++;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
903 qc->dcid.data = ngx_pnalloc(c->pool, qc->dcid.len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
904 if (qc->dcid.data == NULL) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
905 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
906 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
907
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
908 ngx_memcpy(qc->dcid.data, b->pos, qc->dcid.len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
909 b->pos += qc->dcid.len;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
910
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
911 qc->scid.len = *b->pos++;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
912 qc->scid.data = ngx_pnalloc(c->pool, qc->scid.len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
913 if (qc->scid.data == NULL) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
914 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
915 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
916
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
917 ngx_memcpy(qc->scid.data, b->pos, qc->scid.len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
918 b->pos += qc->scid.len;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
919
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
920 qc->token.len = ngx_quic_parse_int(&b->pos);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
921 qc->token.data = ngx_pnalloc(c->pool, qc->token.len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
922 if (qc->token.data == NULL) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
923 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
924 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
925
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
926 ngx_memcpy(qc->token.data, b->pos, qc->token.len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
927 b->pos += qc->token.len;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
928
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
929 ngx_int_t plen = ngx_quic_parse_int(&b->pos);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
930
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
931 if (plen > b->last - b->pos) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
932 ngx_log_error(NGX_LOG_INFO, c->log, 0, "truncated initial packet");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
933 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
934 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
935
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
936 /* draft-ietf-quic-tls-23#section-5.4.2:
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
937 * the Packet Number field is assumed to be 4 bytes long
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
938 * draft-ietf-quic-tls-23#section-5.4.[34]:
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
939 * AES-Based and ChaCha20-Based header protections sample 16 bytes
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
940 */
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
941 u_char *sample = b->pos + 4;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
942
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
943 ngx_quic_hexdump0(c->log, "DCID", qc->dcid.data, qc->dcid.len);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
944 ngx_quic_hexdump0(c->log, "SCID", qc->scid.data, qc->scid.len);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
945 ngx_quic_hexdump0(c->log, "token", qc->token.data, qc->token.len);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
946 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
947 "quic packet length: %d", plen);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
948 ngx_quic_hexdump0(c->log, "sample", sample, 16);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
949
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
950
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
951 // initial secret
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
952
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
953 size_t is_len;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
954 uint8_t is[SHA256_DIGEST_LENGTH];
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
955 ngx_uint_t i;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
956 const EVP_MD *digest;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
957 const EVP_CIPHER *cipher;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
958 static const uint8_t salt[20] =
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
959 "\xc3\xee\xf7\x12\xc7\x2e\xbb\x5a\x11\xa7"
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
960 "\xd2\x43\x2b\xb4\x63\x65\xbe\xf9\xf5\x02";
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
961
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
962 /* AEAD_AES_128_GCM prior to handshake, quic-tls-23#section-5.3 */
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
963
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
964 cipher = EVP_aes_128_gcm();
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
965 digest = EVP_sha256();
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
966
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
967 if (ngx_hkdf_extract(is, &is_len, digest, qc->dcid.data, qc->dcid.len,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
968 salt, sizeof(salt))
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
969 != NGX_OK)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
970 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
971 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
972 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
973
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
974 ngx_str_t iss = {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
975 .data = is,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
976 .len = is_len
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
977 };
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
978
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
979 ngx_quic_hexdump0(c->log, "salt", salt, sizeof(salt));
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
980 ngx_quic_hexdump0(c->log, "initial secret", is, is_len);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
981
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
982 /* draft-ietf-quic-tls-23#section-5.2 */
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
983 qc->client_in.secret.len = SHA256_DIGEST_LENGTH;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
984 qc->server_in.secret.len = SHA256_DIGEST_LENGTH;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
985
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
986 qc->client_in.key.len = EVP_CIPHER_key_length(cipher);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
987 qc->server_in.key.len = EVP_CIPHER_key_length(cipher);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
988
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
989 qc->client_in.hp.len = EVP_CIPHER_key_length(cipher);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
990 qc->server_in.hp.len = EVP_CIPHER_key_length(cipher);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
991
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
992 qc->client_in.iv.len = EVP_CIPHER_iv_length(cipher);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
993 qc->server_in.iv.len = EVP_CIPHER_iv_length(cipher);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
994
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
995 struct {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
996 ngx_str_t label;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
997 ngx_str_t *key;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
998 ngx_str_t *prk;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
999 } seq[] = {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1000
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1001 /* draft-ietf-quic-tls-23#section-5.2 */
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1002 { ngx_string("tls13 client in"), &qc->client_in.secret, &iss },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1003 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1004 ngx_string("tls13 quic key"),
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1005 &qc->client_in.key,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1006 &qc->client_in.secret,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1007 },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1008 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1009 ngx_string("tls13 quic iv"),
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1010 &qc->client_in.iv,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1011 &qc->client_in.secret,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1012 },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1013 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1014 /* AEAD_AES_128_GCM prior to handshake, quic-tls-23#section-5.4.1 */
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1015 ngx_string("tls13 quic hp"),
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1016 &qc->client_in.hp,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1017 &qc->client_in.secret,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1018 },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1019 { ngx_string("tls13 server in"), &qc->server_in.secret, &iss },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1020 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1021 /* AEAD_AES_128_GCM prior to handshake, quic-tls-23#section-5.3 */
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1022 ngx_string("tls13 quic key"),
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1023 &qc->server_in.key,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1024 &qc->server_in.secret,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1025 },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1026 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1027 ngx_string("tls13 quic iv"),
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1028 &qc->server_in.iv,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1029 &qc->server_in.secret,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1030 },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1031 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1032 /* AEAD_AES_128_GCM prior to handshake, quic-tls-23#section-5.4.1 */
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1033 ngx_string("tls13 quic hp"),
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1034 &qc->server_in.hp,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1035 &qc->server_in.secret,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1036 },
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1037
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1038 };
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1039
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1040 for (i = 0; i < (sizeof(seq) / sizeof(seq[0])); i++) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1041
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1042 if (ngx_quic_hkdf_expand(c, digest, seq[i].key, &seq[i].label,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1043 seq[i].prk->data, seq[i].prk->len)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1044 != NGX_OK)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1045 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1046 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1047 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1048 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1049
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1050 // header protection
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1051
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1052 uint8_t mask[16];
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1053 if (ngx_quic_tls_hp(c, EVP_aes_128_ecb(), &qc->client_in, mask, sample)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1054 != NGX_OK)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1055 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1056 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1057 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1058
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1059 u_char clearflags = flags ^ (mask[0] & 0x0f);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1060 ngx_int_t pnl = (clearflags & 0x03) + 1;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1061 uint64_t pn = ngx_quic_parse_pn(&b->pos, pnl, &mask[1]);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1062
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1063 ngx_quic_hexdump0(c->log, "sample", sample, 16);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1064 ngx_quic_hexdump0(c->log, "mask", mask, 5);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1065 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1066 "quic packet number: %uL, len: %xi", pn, pnl);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1067
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1068 // packet protection
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1069
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1070 ngx_str_t in;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1071 in.data = b->pos;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1072 in.len = plen - pnl;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1073
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1074 ngx_str_t ad;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1075 ad.len = b->pos - b->start;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1076 ad.data = ngx_pnalloc(c->pool, ad.len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1077 if (ad.data == NULL) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1078 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1079 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1080
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1081 ngx_memcpy(ad.data, b->start, ad.len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1082 ad.data[0] = clearflags;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1083 ad.data[ad.len - pnl] = (u_char)pn;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1084
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1085 uint8_t *nonce = ngx_pstrdup(c->pool, &qc->client_in.iv);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1086 nonce[11] ^= pn;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1087
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1088 ngx_quic_hexdump0(c->log, "nonce", nonce, 12);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1089 ngx_quic_hexdump0(c->log, "ad", ad.data, ad.len);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1090
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1091 ngx_str_t out;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1092
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1093 if (ngx_quic_tls_open(c, EVP_aes_128_gcm(), &qc->client_in, &out, nonce,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1094 &in, &ad)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1095 != NGX_OK)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1096 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1097 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1098 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1099
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1100 ngx_quic_hexdump0(c->log, "packet payload", out.data, out.len);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1101
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1102 if (out.data[0] != 0x06) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1103 ngx_log_error(NGX_LOG_INFO, c->log, 0,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1104 "unexpected frame in initial packet");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1105 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1106 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1107
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1108 if (out.data[1] != 0x00) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1109 ngx_log_error(NGX_LOG_INFO, c->log, 0,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1110 "unexpected CRYPTO offset in initial packet");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1111 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1112 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1113
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1114 uint8_t *crypto = &out.data[2];
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1115 uint64_t crypto_len = ngx_quic_parse_int(&crypto);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1116
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1117 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1118 "quic initial packet CRYPTO length: %uL pp:%p:%p",
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1119 crypto_len, out.data, crypto);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1120
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1121 if (ngx_ssl_create_connection(ssl, c, NGX_SSL_BUFFER) != NGX_OK) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1122 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1123 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1124
8187
de5917df2c30 Adjusted transport parameters stub for active_connection_id_limit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8186
diff changeset
1125 /* STUB: initial_max_streams_uni=3, active_connection_id_limit=5 */
de5917df2c30 Adjusted transport parameters stub for active_connection_id_limit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8186
diff changeset
1126 static const uint8_t params[12] = "\x00\x0a\x00\x0e\x00\x01\x05\x00\x09\x00\x01\x03";
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1127
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1128 if (SSL_set_quic_transport_params(c->ssl->connection, params,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1129 sizeof(params)) == 0)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1130 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1131 ngx_log_error(NGX_LOG_INFO, c->log, 0,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1132 "SSL_set_quic_transport_params() failed");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1133 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1134 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1135
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1136 n = SSL_do_handshake(c->ssl->connection);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1137
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1138 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_do_handshake: %d", n);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1139
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1140 if (n == -1) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1141 sslerr = SSL_get_error(c->ssl->connection, n);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1142
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1143 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d",
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1144 sslerr);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1145 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1146
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1147 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1148 "SSL_quic_read_level: %d, SSL_quic_write_level: %d",
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1149 (int) SSL_quic_read_level(c->ssl->connection),
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1150 (int) SSL_quic_write_level(c->ssl->connection));
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1151
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1152 if (!SSL_provide_quic_data(c->ssl->connection,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1153 SSL_quic_read_level(c->ssl->connection),
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1154 crypto, crypto_len))
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1155 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1156 ngx_ssl_error(NGX_LOG_INFO, c->log, 0,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1157 "SSL_provide_quic_data() failed");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1158 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1159 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1160
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1161 n = SSL_do_handshake(c->ssl->connection);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1162
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1163 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_do_handshake: %d", n);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1164
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1165 if (n == -1) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1166 sslerr = SSL_get_error(c->ssl->connection, n);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1167
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1168 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d",
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1169 sslerr);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1170
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1171 if (sslerr == SSL_ERROR_SSL) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1172 ngx_ssl_error(NGX_LOG_ERR, c->log, 0, "SSL_do_handshake() failed");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1173 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1174 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1175
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1176 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1177 "SSL_quic_read_level: %d, SSL_quic_write_level: %d",
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1178 (int) SSL_quic_read_level(c->ssl->connection),
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1179 (int) SSL_quic_write_level(c->ssl->connection));
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1180
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1181 return NGX_OK;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1182 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1183
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1184
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1185 static ngx_int_t
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1186 ngx_quic_handshake_input(ngx_connection_t *c, ngx_buf_t *bb)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1187 {
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1188 int sslerr;
8188
bf555b94e387 Using cached ssl_conn in ngx_quic_handshake_input(), NFC.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8187
diff changeset
1189 u_char *p, *b;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1190 ssize_t n;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1191 ngx_str_t out;
8188
bf555b94e387 Using cached ssl_conn in ngx_quic_handshake_input(), NFC.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8187
diff changeset
1192 ngx_ssl_conn_t *ssl_conn;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1193 const EVP_CIPHER *cipher;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1194 ngx_quic_connection_t *qc;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1195
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1196 qc = c->quic;
8188
bf555b94e387 Using cached ssl_conn in ngx_quic_handshake_input(), NFC.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8187
diff changeset
1197 ssl_conn = c->ssl->connection;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1198
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1199 n = bb->last - bb->pos;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1200 p = bb->pos;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1201 b = bb->start;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1202
8190
2bc1f97c1c2d Fixed packet "input" debug log message.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8189
diff changeset
1203 ngx_quic_hexdump0(c->log, "input", p, n);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1204
8184
ec1f84996990 Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents: 8183
diff changeset
1205 if ((p[0] & 0xf0) != NGX_QUIC_PKT_HANDSHAKE) {
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1206 ngx_log_error(NGX_LOG_INFO, c->log, 0, "invalid packet type");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1207 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1208 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1209
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1210 ngx_int_t flags = *p++;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1211 uint32_t version = ngx_quic_parse_uint32(p);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1212 p += sizeof(uint32_t);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1213
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1214 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1215 "quic flags:%xi version:%xD", flags, version);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1216
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1217 if (version != quic_version) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1218 ngx_log_error(NGX_LOG_INFO, c->log, 0, "unsupported quic version");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1219 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1220 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1221
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1222 if (*p++ != qc->dcid.len) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1223 ngx_log_error(NGX_LOG_INFO, c->log, 0, "unexpected quic dcidl");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1224 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1225 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1226
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1227 if (ngx_memcmp(p, qc->dcid.data, qc->dcid.len) != 0) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1228 ngx_log_error(NGX_LOG_INFO, c->log, 0, "unexpected quic dcid");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1229 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1230 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1231
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1232 p += qc->dcid.len;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1233
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1234 if (*p++ != qc->scid.len) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1235 ngx_log_error(NGX_LOG_INFO, c->log, 0, "unexpected quic scidl");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1236 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1237 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1238
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1239 if (ngx_memcmp(p, qc->scid.data, qc->scid.len) != 0) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1240 ngx_log_error(NGX_LOG_INFO, c->log, 0, "unexpected quic scid");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1241 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1242 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1243
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1244 p += qc->scid.len;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1245
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1246 ngx_int_t plen = ngx_quic_parse_int(&p);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1247
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1248 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1249 "quic packet length: %d", plen);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1250
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1251 if (plen > b + n - p) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1252 ngx_log_error(NGX_LOG_INFO, c->log, 0, "truncated handshake packet");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1253 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1254 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1255
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1256 u_char *sample = p + 4;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1257
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1258 ngx_quic_hexdump0(c->log, "sample", sample, 16);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1259
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1260 // header protection
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1261
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1262 uint8_t mask[16];
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1263 if (ngx_quic_tls_hp(c, EVP_aes_128_ecb(), &qc->client_hs, mask, sample)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1264 != NGX_OK)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1265 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1266 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1267 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1268
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1269 u_char clearflags = flags ^ (mask[0] & 0x0f);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1270 ngx_int_t pnl = (clearflags & 0x03) + 1;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1271 uint64_t pn = ngx_quic_parse_pn(&p, pnl, &mask[1]);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1272
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1273 ngx_quic_hexdump0(c->log, "mask", mask, 5);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1274 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1275 "quic clear flags: %xi", clearflags);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1276 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1277 "quic packet number: %uL, len: %xi", pn, pnl);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1278
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1279 // packet protection
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1280
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1281 ngx_str_t in;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1282 in.data = p;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1283 in.len = plen - pnl;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1284
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1285 ngx_str_t ad;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1286 ad.len = p - b;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1287 ad.data = ngx_pnalloc(c->pool, ad.len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1288 if (ad.data == NULL) {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1289 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1290 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1291
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1292 ngx_memcpy(ad.data, b, ad.len);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1293 ad.data[0] = clearflags;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1294 ad.data[ad.len - pnl] = (u_char)pn;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1295
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1296 uint8_t *nonce = ngx_pstrdup(c->pool, &qc->client_hs.iv);
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1297 nonce[11] ^= pn;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1298
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1299 ngx_quic_hexdump0(c->log, "nonce", nonce, 12);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1300 ngx_quic_hexdump0(c->log, "ad", ad.data, ad.len);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1301
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
1302 switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl_conn)) & 0xffff) {
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
1303
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
1304 case NGX_AES_128_GCM_SHA256:
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
1305 cipher = EVP_aes_128_gcm();
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
1306 break;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1307
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
1308 case NGX_AES_256_GCM_SHA384:
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
1309 cipher = EVP_aes_256_gcm();
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
1310 break;
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1311
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
1312 default:
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1313 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "unexpected cipher");
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1314 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1315 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1316
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1317 if (ngx_quic_tls_open(c, cipher, &qc->client_hs, &out, nonce, &in, &ad)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1318 != NGX_OK)
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1319 {
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1320 return NGX_ERROR;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1321 }
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1322
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1323 ngx_quic_hexdump0(c->log, "packet payload", out.data, out.len);
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1324
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1325 if (out.data[0] != 0x06) {
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1326 ngx_log_error(NGX_LOG_INFO, c->log, 0,
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1327 "non-CRYPTO frame in HS packet, skipping");
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1328 return NGX_OK;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1329 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1330
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1331 if (out.data[1] != 0x00) {
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1332 ngx_log_error(NGX_LOG_INFO, c->log, 0,
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1333 "not yet supported CRYPTO offset in initial packet");
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1334 return NGX_ERROR;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1335 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1336
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1337 uint8_t *crypto = &out.data[2];
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1338 uint64_t crypto_len = ngx_quic_parse_int(&crypto);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1339
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1340 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1341 "quic Handshake packet CRYPTO length: %uL pp:%p:%p",
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1342 crypto_len, out.data, crypto);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1343
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1344 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1345 "SSL_quic_read_level: %d, SSL_quic_write_level: %d",
8188
bf555b94e387 Using cached ssl_conn in ngx_quic_handshake_input(), NFC.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8187
diff changeset
1346 (int) SSL_quic_read_level(ssl_conn),
bf555b94e387 Using cached ssl_conn in ngx_quic_handshake_input(), NFC.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8187
diff changeset
1347 (int) SSL_quic_write_level(ssl_conn));
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1348
8188
bf555b94e387 Using cached ssl_conn in ngx_quic_handshake_input(), NFC.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8187
diff changeset
1349 if (!SSL_provide_quic_data(ssl_conn, SSL_quic_read_level(ssl_conn),
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1350 crypto, crypto_len))
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1351 {
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1352 ngx_ssl_error(NGX_LOG_INFO, c->log, 0,
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1353 "SSL_provide_quic_data() failed");
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1354 return NGX_ERROR;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1355 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1356
8188
bf555b94e387 Using cached ssl_conn in ngx_quic_handshake_input(), NFC.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8187
diff changeset
1357 n = SSL_do_handshake(ssl_conn);
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1358
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1359 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_do_handshake: %d", n);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1360
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1361 if (n == -1) {
8188
bf555b94e387 Using cached ssl_conn in ngx_quic_handshake_input(), NFC.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8187
diff changeset
1362 sslerr = SSL_get_error(ssl_conn, n);
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1363
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1364 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d",
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1365 sslerr);
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1366
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1367 if (sslerr == SSL_ERROR_SSL) {
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1368 ngx_ssl_error(NGX_LOG_ERR, c->log, 0, "SSL_do_handshake() failed");
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1369 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1370 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1371
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1372 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1373 "SSL_quic_read_level: %d, SSL_quic_write_level: %d",
8188
bf555b94e387 Using cached ssl_conn in ngx_quic_handshake_input(), NFC.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8187
diff changeset
1374 (int) SSL_quic_read_level(ssl_conn),
bf555b94e387 Using cached ssl_conn in ngx_quic_handshake_input(), NFC.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8187
diff changeset
1375 (int) SSL_quic_write_level(ssl_conn));
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1376
8189
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
1377 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
1378 "quic ssl cipher: %s", SSL_get_cipher(ssl_conn));
80a07843c711 Using SSL cipher suite id to obtain cipher/digest, part 1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8188
diff changeset
1379
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1380 // ACK Client Finished
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1381
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
1382 ngx_quic_frame_t *frame;
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1383
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
1384 frame = ngx_pcalloc(c->pool, sizeof(ngx_quic_frame_t));
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
1385 if (frame == NULL) {
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1386 return 0;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1387 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1388
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
1389 frame->level = ssl_encryption_handshake;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
1390 frame->type = NGX_QUIC_FT_ACK;
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
1391 frame->u.ack.pn = pn;
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1392
8186
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
1393 ngx_sprintf(frame->info, "ACK for PN=%d at handshake level, in respond to client finished", pn);
0a2683df5f11 Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents: 8185
diff changeset
1394 ngx_quic_queue_frame(qc, frame);
8185
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1395
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1396 if (ngx_quic_output(c) != NGX_OK) {
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1397 return 0;
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1398 }
6a76d9657772 QUIC handshake final bits.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8184
diff changeset
1399
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1400 return NGX_OK;
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1401 }
8171
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1402
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1403
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1404 uint64_t
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1405 ngx_quic_parse_int(u_char **pos)
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1406 {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1407 u_char *p;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1408 uint64_t value;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1409 ngx_uint_t len;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1410
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1411 p = *pos;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1412 len = 1 << ((*p & 0xc0) >> 6);
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1413 value = *p++ & 0x3f;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1414
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1415 while (--len) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1416 value = (value << 8) + *p++;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1417 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1418
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1419 *pos = p;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1420 return value;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1421 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1422
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1423
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1424 void
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1425 ngx_quic_build_int(u_char **pos, uint64_t value)
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1426 {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1427 u_char *p;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1428 ngx_uint_t len;//, len2;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1429
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1430 p = *pos;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1431 len = 0;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1432
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1433 while (value >> ((1 << len) * 8 - 2)) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1434 len++;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1435 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1436
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1437 *p = len << 6;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1438
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1439 // len2 =
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1440 len = (1 << len);
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1441 len--;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1442 *p |= value >> (len * 8);
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1443 p++;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1444
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1445 while (len) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1446 *p++ = value >> ((len-- - 1) * 8);
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1447 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1448
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1449 *pos = p;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1450 // return len2;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1451 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1452
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1453
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1454 static uint64_t
8171
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1455 ngx_quic_parse_pn(u_char **pos, ngx_int_t len, u_char *mask)
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1456 {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1457 u_char *p;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1458 uint64_t value;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1459
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1460 p = *pos;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1461 value = *p++ ^ *mask++;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1462
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1463 while (--len) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1464 value = (value << 8) + (*p++ ^ *mask++);
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1465 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1466
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1467 *pos = p;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1468 return value;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1469 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1470
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1471
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1472 static ngx_int_t
8171
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1473 ngx_hkdf_extract(u_char *out_key, size_t *out_len, const EVP_MD *digest,
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1474 const u_char *secret, size_t secret_len, const u_char *salt,
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1475 size_t salt_len)
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1476 {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1477 #ifdef OPENSSL_IS_BORINGSSL
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1478 if (HKDF_extract(out_key, out_len, digest, secret, secret_len, salt,
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1479 salt_len)
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1480 == 0)
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1481 {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1482 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1483 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1484 #else
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1485
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1486 EVP_PKEY_CTX *pctx;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1487
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1488 pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1489
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1490 if (EVP_PKEY_derive_init(pctx) <= 0) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1491 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1492 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1493
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1494 if (EVP_PKEY_CTX_hkdf_mode(pctx, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY) <= 0) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1495 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1496 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1497
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1498 if (EVP_PKEY_CTX_set_hkdf_md(pctx, digest) <= 0) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1499 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1500 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1501
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1502 if (EVP_PKEY_CTX_set1_hkdf_key(pctx, secret, secret_len) <= 0) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1503 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1504 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1505
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1506 if (EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, salt_len) <= 0) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1507 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1508 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1509
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1510 if (EVP_PKEY_derive(pctx, out_key, out_len) <= 0) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1511 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1512 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1513
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1514 #endif
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1515
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1516 return NGX_OK;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1517 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1518
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1519
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1520 static ngx_int_t
8179
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1521 ngx_quic_hkdf_expand(ngx_connection_t *c, const EVP_MD *digest, ngx_str_t *out,
8180
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1522 ngx_str_t *label, const uint8_t *prk, size_t prk_len)
8179
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1523 {
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1524 uint8_t *p;
8180
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1525 size_t info_len;
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1526 uint8_t info[20];
8179
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1527
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1528 out->data = ngx_pnalloc(c->pool, out->len);
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1529 if (out->data == NULL) {
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1530 return NGX_ERROR;
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1531 }
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1532
8180
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1533 info_len = 2 + 1 + label->len + 1;
8179
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1534
8180
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1535 info[0] = 0;
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1536 info[1] = out->len;
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1537 info[2] = label->len;
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1538 p = ngx_cpymem(&info[3], label->data, label->len);
8179
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1539 *p = '\0';
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1540
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1541 if (ngx_hkdf_expand(out->data, out->len, digest,
8180
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1542 prk, prk_len, info, info_len)
8179
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1543 != NGX_OK)
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1544 {
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1545 ngx_ssl_error(NGX_LOG_INFO, c->log, 0,
8180
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1546 "ngx_hkdf_expand(%V) failed", label);
8179
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1547 return NGX_ERROR;
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1548 }
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1549
8183
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1550 ngx_quic_hexdump(c->log, "%V info", info, info_len, label);
6091506af0f7 Aded the "ngx_quic_hexdump" macro.
Vladimir Homutov <vl@nginx.com>
parents: 8182
diff changeset
1551 ngx_quic_hexdump(c->log, "%V key", out->data, out->len, label);
8179
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1552
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1553 return NGX_OK;
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1554 }
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1555
7ee1ada04c8a Generic function for HKDF expansion.
Vladimir Homutov <vl@nginx.com>
parents: 8178
diff changeset
1556
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1557 static ngx_int_t
8171
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1558 ngx_hkdf_expand(u_char *out_key, size_t out_len, const EVP_MD *digest,
8180
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1559 const uint8_t *prk, size_t prk_len, const u_char *info, size_t info_len)
8171
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1560 {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1561 #ifdef OPENSSL_IS_BORINGSSL
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1562 if (HKDF_expand(out_key, out_len, digest, prk, prk_len, info, info_len)
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1563 == 0)
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1564 {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1565 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1566 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1567 #else
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1568
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1569 EVP_PKEY_CTX *pctx;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1570
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1571 pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1572
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1573 if (EVP_PKEY_derive_init(pctx) <= 0) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1574 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1575 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1576
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1577 if (EVP_PKEY_CTX_hkdf_mode(pctx, EVP_PKEY_HKDEF_MODE_EXPAND_ONLY) <= 0) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1578 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1579 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1580
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1581 if (EVP_PKEY_CTX_set_hkdf_md(pctx, digest) <= 0) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1582 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1583 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1584
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1585 if (EVP_PKEY_CTX_set1_hkdf_key(pctx, prk, prk_len) <= 0) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1586 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1587 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1588
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1589 if (EVP_PKEY_CTX_add1_hkdf_info(pctx, info, info_len) <= 0) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1590 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1591 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1592
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1593 if (EVP_PKEY_derive(pctx, out_key, &out_len) <= 0) {
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1594 return NGX_ERROR;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1595 }
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1596
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1597 #endif
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1598
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1599 return NGX_OK;
4daf03d2bd0a OpenSSL compatibility.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1600 }
8177
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1601
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1602
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1603 static ngx_int_t
8180
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1604 ngx_quic_tls_open(ngx_connection_t *c, const EVP_CIPHER *cipher,
8177
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1605 ngx_quic_secret_t *s, ngx_str_t *out, u_char *nonce, ngx_str_t *in,
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1606 ngx_str_t *ad)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1607 {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1608 out->len = in->len - EVP_GCM_TLS_TAG_LEN;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1609 out->data = ngx_pnalloc(c->pool, out->len);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1610 if (out->data == NULL) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1611 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1612 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1613
8180
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1614 #ifdef OPENSSL_IS_BORINGSSLL
8177
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1615 EVP_AEAD_CTX *ctx;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1616
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1617 ctx = EVP_AEAD_CTX_new(cipher, s->key.data, s->key.len,
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1618 EVP_AEAD_DEFAULT_TAG_LENGTH);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1619 if (ctx == NULL) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1620 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_AEAD_CTX_new() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1621 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1622 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1623
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1624 if (EVP_AEAD_CTX_open(ctx, out->data, &out->len, out->len, nonce, s->iv.len,
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1625 in->data, in->len, ad->data, ad->len)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1626 != 1)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1627 {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1628 EVP_AEAD_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1629 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_AEAD_CTX_open() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1630 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1631 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1632
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1633 EVP_AEAD_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1634 #else
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1635 int len;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1636 u_char *tag;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1637 EVP_CIPHER_CTX *ctx;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1638
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1639 ctx = EVP_CIPHER_CTX_new();
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1640 if (ctx == NULL) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1641 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_CIPHER_CTX_new() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1642 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1643 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1644
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1645 if (EVP_DecryptInit_ex(ctx, cipher, NULL, NULL, NULL) != 1) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1646 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1647 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_DecryptInit_ex() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1648 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1649 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1650
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1651 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, s->iv.len, NULL)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1652 == 0)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1653 {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1654 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1655 ngx_ssl_error(NGX_LOG_INFO, c->log, 0,
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1656 "EVP_CIPHER_CTX_ctrl(EVP_CTRL_GCM_SET_IVLEN) failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1657 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1658 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1659
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1660 if (EVP_DecryptInit_ex(ctx, NULL, NULL, s->key.data, nonce) != 1) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1661 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1662 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_DecryptInit_ex() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1663 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1664 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1665
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1666 if (EVP_DecryptUpdate(ctx, NULL, &len, ad->data, ad->len) != 1) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1667 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1668 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_DecryptUpdate() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1669 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1670 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1671
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1672 if (EVP_DecryptUpdate(ctx, out->data, &len, in->data,
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1673 in->len - EVP_GCM_TLS_TAG_LEN)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1674 != 1)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1675 {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1676 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1677 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_DecryptUpdate() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1678 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1679 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1680
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1681 out->len = len;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1682 tag = in->data + in->len - EVP_GCM_TLS_TAG_LEN;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1683
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1684 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, EVP_GCM_TLS_TAG_LEN, tag)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1685 == 0)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1686 {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1687 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1688 ngx_ssl_error(NGX_LOG_INFO, c->log, 0,
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1689 "EVP_CIPHER_CTX_ctrl(EVP_CTRL_GCM_SET_TAG) failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1690 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1691 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1692
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1693 if (EVP_DecryptFinal_ex(ctx, out->data + len, &len) <= 0) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1694 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1695 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_DecryptFinal_ex failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1696 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1697 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1698
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1699 out->len += len;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1700
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1701 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1702 #endif
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1703
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1704 return NGX_OK;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1705 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1706
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1707
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1708 static ngx_int_t
8180
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1709 ngx_quic_tls_seal(ngx_connection_t *c, const EVP_CIPHER *cipher,
8177
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1710 ngx_quic_secret_t *s, ngx_str_t *out, u_char *nonce, ngx_str_t *in,
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1711 ngx_str_t *ad)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1712 {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1713 out->len = in->len + EVP_GCM_TLS_TAG_LEN;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1714 out->data = ngx_pnalloc(c->pool, out->len);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1715 if (out->data == NULL) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1716 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1717 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1718
8180
01dc595de244 Cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8179
diff changeset
1719 #ifdef OPENSSL_IS_BORINGSSLL
8177
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1720 EVP_AEAD_CTX *ctx;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1721
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1722 ctx = EVP_AEAD_CTX_new(cipher, s->key.data, s->key.len,
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1723 EVP_AEAD_DEFAULT_TAG_LENGTH);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1724 if (ctx == NULL) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1725 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_AEAD_CTX_new() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1726 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1727 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1728
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1729 if (EVP_AEAD_CTX_seal(ctx, out->data, &out->len, out->len, nonce, s->iv.len,
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1730 in->data, in->len, ad->data, ad->len)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1731 != 1)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1732 {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1733 EVP_AEAD_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1734 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_AEAD_CTX_seal() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1735 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1736 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1737
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1738 EVP_AEAD_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1739 #else
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1740 int len;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1741 EVP_CIPHER_CTX *ctx;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1742
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1743 ctx = EVP_CIPHER_CTX_new();
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1744 if (ctx == NULL) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1745 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_CIPHER_CTX_new() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1746 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1747 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1748
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1749 if (EVP_EncryptInit_ex(ctx, cipher, NULL, NULL, NULL) != 1) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1750 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1751 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_EncryptInit_ex() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1752 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1753 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1754
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1755 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, s->iv.len, NULL)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1756 == 0)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1757 {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1758 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1759 ngx_ssl_error(NGX_LOG_INFO, c->log, 0,
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1760 "EVP_CIPHER_CTX_ctrl(EVP_CTRL_GCM_SET_IVLEN) failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1761 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1762 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1763
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1764 if (EVP_EncryptInit_ex(ctx, NULL, NULL, s->key.data, nonce) != 1) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1765 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1766 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_EncryptInit_ex() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1767 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1768 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1769
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1770 if (EVP_EncryptUpdate(ctx, NULL, &len, ad->data, ad->len) != 1) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1771 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1772 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_EncryptUpdate() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1773 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1774 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1775
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1776 if (EVP_EncryptUpdate(ctx, out->data, &len, in->data, in->len) != 1) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1777 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1778 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_EncryptUpdate() failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1779 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1780 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1781
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1782 out->len = len;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1783
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1784 if (EVP_EncryptFinal_ex(ctx, out->data + out->len, &len) <= 0) {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1785 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1786 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_EncryptFinal_ex failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1787 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1788 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1789
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1790 out->len += len;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1791
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1792 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, EVP_GCM_TLS_TAG_LEN,
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1793 out->data + in->len)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1794 == 0)
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1795 {
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1796 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1797 ngx_ssl_error(NGX_LOG_INFO, c->log, 0,
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1798 "EVP_CIPHER_CTX_ctrl(EVP_CTRL_GCM_GET_TAG) failed");
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1799 return NGX_ERROR;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1800 }
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1801
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1802 EVP_CIPHER_CTX_free(ctx);
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1803
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1804 out->len += EVP_GCM_TLS_TAG_LEN;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1805 #endif
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1806
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1807 return NGX_OK;
76e29ff31cd3 AEAD routines, introduced ngx_quic_tls_open()/ngx_quic_tls_seal().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8171
diff changeset
1808 }
8178
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1809
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1810
8182
b28ea685a56e Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents: 8180
diff changeset
1811 static ngx_int_t
8178
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1812 ngx_quic_tls_hp(ngx_connection_t *c, const EVP_CIPHER *cipher,
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1813 ngx_quic_secret_t *s, u_char *out, u_char *in)
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1814 {
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1815 int outlen;
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1816 EVP_CIPHER_CTX *ctx;
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1817
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1818 ctx = EVP_CIPHER_CTX_new();
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1819 if (ctx == NULL) {
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1820 return NGX_ERROR;
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1821 }
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1822
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1823 if (EVP_EncryptInit_ex(ctx, cipher, NULL, s->hp.data, NULL) != 1) {
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1824 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_EncryptInit_ex() failed");
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1825 goto failed;
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1826 }
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1827
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1828 if (!EVP_EncryptUpdate(ctx, out, &outlen, in, 16)) {
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1829 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "EVP_EncryptUpdate() failed");
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1830 goto failed;
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1831 }
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1832
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1833 EVP_CIPHER_CTX_free(ctx);
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1834
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1835 return NGX_OK;
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1836
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1837 failed:
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1838
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1839 EVP_CIPHER_CTX_free(ctx);
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1840
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1841 return NGX_ERROR;
a9ff4392ecde QUIC header protection routines, introduced ngx_quic_tls_hp().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8177
diff changeset
1842 }