This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nginx_tls13_1_15_8.patch
208 lines (192 loc) · 6.3 KB
/
nginx_tls13_1_15_8.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
diff -Naru ./src/nginx-1.15.3/src/event/ngx_event_openssl.c ./nginx-1.15.3/src/event/ngx_event_openssl.c
--- a/src/event/ngx_event_openssl.c 2018-09-22 04:57:54.082747503 +0000
+++ b/src/event/ngx_event_openssl.c 2018-09-17 03:42:44.000000000 +0000
@@ -664,6 +664,20 @@
ngx_int_t
+ngx_ssl_ciphers_tls13(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *ciphers_tls13)
+{
+ if (SSL_CTX_set_ciphersuites(ssl->ctx, (char *) ciphers_tls13->data) == 0) {
+ ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
+ "SSL_CTX_set_ciphersuites(\"%V\") failed",
+ ciphers_tls13);
+ return NGX_ERROR;
+ }
+
+ return NGX_OK;
+}
+
+
+ngx_int_t
ngx_ssl_client_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *cert,
ngx_int_t depth)
{
@@ -3492,6 +3506,91 @@
{
#ifdef SSL_CTRL_GET_RAW_CIPHERLIST
+ int n, i, bytes;
+ size_t len;
+ u_char *ciphers, *p;
+ const SSL_CIPHER *cipher;
+
+ bytes = SSL_get0_raw_cipherlist(c->ssl->connection, NULL);
+ n = SSL_get0_raw_cipherlist(c->ssl->connection, &ciphers);
+
+ if (n <= 0) {
+ s->len = 0;
+ return NGX_OK;
+ }
+
+ len = 0;
+ n /= bytes;
+
+ for (i = 0; i < n; i++) {
+ cipher = SSL_CIPHER_find(c->ssl->connection, ciphers + i * bytes);
+
+ if (cipher) {
+ len += ngx_strlen(SSL_CIPHER_get_name(cipher));
+
+ } else {
+ len += sizeof("0x") - 1 + bytes * (sizeof("00") - 1);
+ }
+
+ len += sizeof(":") - 1;
+ }
+
+ s->data = ngx_pnalloc(pool, len);
+ if (s->data == NULL) {
+ return NGX_ERROR;
+ }
+
+ p = s->data;
+
+ for (i = 0; i < n; i++) {
+ cipher = SSL_CIPHER_find(c->ssl->connection, ciphers + i * bytes);
+
+ if (cipher) {
+ p = ngx_sprintf(p, "%s", SSL_CIPHER_get_name(cipher));
+
+ } else {
+ p = ngx_sprintf(p, "0x");
+ p = ngx_hex_dump(p, ciphers + i * bytes, bytes);
+ }
+
+ *p++ = ':';
+ }
+
+ p--;
+
+ s->len = p - s->data;
+
+#else
+
+ u_char buf[4096];
+
+ if (SSL_get_shared_ciphers(c->ssl->connection, (char *) buf, 4096)
+ == NULL)
+ {
+ s->len = 0;
+ return NGX_OK;
+ }
+
+ s->len = ngx_strlen(buf);
+ s->data = ngx_pnalloc(pool, s->len);
+ if (s->data == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_memcpy(s->data, buf, s->len);
+
+#endif
+
+ return NGX_OK;
+}
+
+
+// TBD
+ngx_int_t
+ngx_ssl_get_ciphers_tls13(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
+{
+#ifdef SSL_CTRL_GET_RAW_CIPHERLIST
+
int n, i, bytes;
size_t len;
u_char *ciphers, *p;
diff -Naru ./src/nginx-1.15.3/src/event/ngx_event_openssl.h ./nginx-1.15.3/src/event/ngx_event_openssl.h
--- a/src/event/ngx_event_openssl.h 2018-09-03 10:28:43.005844720 +0000
+++ b/src/event/ngx_event_openssl.h 2018-09-13 14:54:34.000000000 +0000
@@ -174,6 +174,7 @@
ngx_str_t *cert, ngx_str_t *key, ngx_array_t *passwords);
ngx_int_t ngx_ssl_ciphers(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *ciphers,
ngx_uint_t prefer_server_ciphers);
+ngx_int_t ngx_ssl_ciphers_tls13(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *ciphers);
ngx_int_t ngx_ssl_client_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl,
ngx_str_t *cert, ngx_int_t depth);
ngx_int_t ngx_ssl_trusted_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl,
@@ -226,6 +227,8 @@
ngx_str_t *s);
ngx_int_t ngx_ssl_get_ciphers(ngx_connection_t *c, ngx_pool_t *pool,
ngx_str_t *s);
+ngx_int_t ngx_ssl_get_ciphers_tls13(ngx_connection_t *c, ngx_pool_t *pool,
+ ngx_str_t *s);
ngx_int_t ngx_ssl_get_curves(ngx_connection_t *c, ngx_pool_t *pool,
ngx_str_t *s);
ngx_int_t ngx_ssl_get_session_id(ngx_connection_t *c, ngx_pool_t *pool,
diff -Naru ./src/nginx-1.15.3/src/http/modules/ngx_http_ssl_module.c ./nginx-1.15.3/src/http/modules/ngx_http_ssl_module.c
--- a/src/http/modules/ngx_http_ssl_module.c 2018-09-03 10:28:43.005844720 +0000
+++ b/src/http/modules/ngx_http_ssl_module.c 2018-09-17 12:02:47.192725258 +0000
@@ -15,6 +15,7 @@
#define NGX_DEFAULT_CIPHERS "HIGH:!aNULL:!MD5"
+#define NGX_DEFAULT_CIPHERS_TLS13 "TLS_AES_128_GCM_SHA256"
#define NGX_DEFAULT_ECDH_CURVE "auto"
#define NGX_HTTP_NPN_ADVERTISE "\x08http/1.1"
@@ -134,6 +135,14 @@
offsetof(ngx_http_ssl_srv_conf_t, ciphers),
NULL },
+ // TBD
+ { ngx_string("ssl_ciphers_tls13"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_str_slot,
+ NGX_HTTP_SRV_CONF_OFFSET,
+ offsetof(ngx_http_ssl_srv_conf_t, ciphers_tls13),
+ NULL },
+
{ ngx_string("ssl_buffer_size"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
@@ -327,6 +336,10 @@
{ ngx_string("ssl_ciphers"), NULL, ngx_http_ssl_variable,
(uintptr_t) ngx_ssl_get_ciphers, NGX_HTTP_VAR_CHANGEABLE, 0 },
+ //TBD
+ { ngx_string("ssl_ciphers_tls13"), NULL, ngx_http_ssl_variable,
+ (uintptr_t) ngx_ssl_get_ciphers_tls13, NGX_HTTP_VAR_CHANGEABLE, 0 },
+
{ ngx_string("ssl_curves"), NULL, ngx_http_ssl_variable,
(uintptr_t) ngx_ssl_get_curves, NGX_HTTP_VAR_CHANGEABLE, 0 },
@@ -721,6 +734,8 @@
NGX_DEFAULT_ECDH_CURVE);
ngx_conf_merge_str_value(conf->ciphers, prev->ciphers, NGX_DEFAULT_CIPHERS);
+ // TBD
+ ngx_conf_merge_str_value(conf->ciphers_tls13, prev->ciphers_tls13, NGX_DEFAULT_CIPHERS_TLS13);
ngx_conf_merge_value(conf->stapling, prev->stapling, 0);
ngx_conf_merge_value(conf->stapling_verify, prev->stapling_verify, 0);
@@ -840,6 +855,14 @@
return NGX_CONF_ERROR;
}
+ // TBD
+ if (ngx_ssl_ciphers_tls13(cf, &conf->ssl, &conf->ciphers_tls13)
+ != NGX_OK)
+ {
+ return NGX_CONF_ERROR;
+ }
+
+
conf->ssl.buffer_size = conf->buffer_size;
if (conf->verify) {
diff -Naru ./src/nginx-1.15.3/src/http/modules/ngx_http_ssl_module.h ./nginx-1.15.3/src/http/modules/ngx_http_ssl_module.h
--- a/src/http/modules/ngx_http_ssl_module.h 2018-09-03 10:28:43.005844720 +0000
+++ b/src/http/modules/ngx_http_ssl_module.h 2018-09-13 14:30:36.000000000 +0000
@@ -43,6 +43,7 @@
ngx_str_t crl;
ngx_str_t ciphers;
+ ngx_str_t ciphers_tls13;
ngx_array_t *passwords;