diff options
author | jsing <> | 2020-05-09 10:51:55 +0000 |
---|---|---|
committer | jsing <> | 2020-05-09 10:51:55 +0000 |
commit | 190f1484ef8374330be8981661b8d25def86e00c (patch) | |
tree | b97b45a780f622f1ccf322dcbb75cf7670f70aed | |
parent | 6756aba59638ad46b3092b90f8dbf472bae375ac (diff) | |
download | openbsd-190f1484ef8374330be8981661b8d25def86e00c.tar.gz openbsd-190f1484ef8374330be8981661b8d25def86e00c.tar.bz2 openbsd-190f1484ef8374330be8981661b8d25def86e00c.zip |
Add support for HelloRetryRequests in the TLSv1.3 server.
ok inoguchi@ tb@
-rw-r--r-- | src/lib/libssl/ssl_tlsext.c | 34 | ||||
-rw-r--r-- | src/lib/libssl/tls13_server.c | 49 |
2 files changed, 73 insertions, 10 deletions
diff --git a/src/lib/libssl/ssl_tlsext.c b/src/lib/libssl/ssl_tlsext.c index a0e2f7320b..cb2b2cadc7 100644 --- a/src/lib/libssl/ssl_tlsext.c +++ b/src/lib/libssl/ssl_tlsext.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_tlsext.c,v 1.63 2020/04/21 17:06:16 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_tlsext.c,v 1.64 2020/05/09 10:51:55 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2016, 2017, 2019 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2016, 2017, 2019 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2017 Doug Hogan <doug@openbsd.org> | 4 | * Copyright (c) 2017 Doug Hogan <doug@openbsd.org> |
@@ -222,6 +222,31 @@ tlsext_supportedgroups_server_parse(SSL *s, CBS *cbs, int *alert) | |||
222 | uint16_t *groups; | 222 | uint16_t *groups; |
223 | int i; | 223 | int i; |
224 | 224 | ||
225 | if (SSI(s)->tlsext_supportedgroups != NULL) { | ||
226 | /* | ||
227 | * We should only end up here in the case of a TLSv1.3 | ||
228 | * HelloRetryRequest... and the client cannot change | ||
229 | * supported groups. | ||
230 | */ | ||
231 | /* XXX - we should know this is a HRR. */ | ||
232 | if (groups_len != SSI(s)->tlsext_supportedgroups_length) { | ||
233 | *alert = SSL_AD_ILLEGAL_PARAMETER; | ||
234 | return 0; | ||
235 | } | ||
236 | for (i = 0; i < groups_len; i++) { | ||
237 | uint16_t group; | ||
238 | |||
239 | if (!CBS_get_u16(&grouplist, &group)) | ||
240 | goto err; | ||
241 | if (SSI(s)->tlsext_supportedgroups[i] != group) { | ||
242 | *alert = SSL_AD_ILLEGAL_PARAMETER; | ||
243 | return 0; | ||
244 | } | ||
245 | } | ||
246 | |||
247 | return 1; | ||
248 | } | ||
249 | |||
225 | if (SSI(s)->tlsext_supportedgroups != NULL) | 250 | if (SSI(s)->tlsext_supportedgroups != NULL) |
226 | goto err; | 251 | goto err; |
227 | 252 | ||
@@ -672,7 +697,7 @@ tlsext_sni_server_parse(SSL *s, CBS *cbs, int *alert) | |||
672 | return 0; | 697 | return 0; |
673 | } | 698 | } |
674 | 699 | ||
675 | if (s->internal->hit) { | 700 | if (s->internal->hit || S3I(s)->hs_tls13.hrr) { |
676 | if (s->session->tlsext_hostname == NULL) { | 701 | if (s->session->tlsext_hostname == NULL) { |
677 | *alert = TLS1_AD_UNRECOGNIZED_NAME; | 702 | *alert = TLS1_AD_UNRECOGNIZED_NAME; |
678 | return 0; | 703 | return 0; |
@@ -1333,6 +1358,11 @@ tlsext_keyshare_server_needs(SSL *s) | |||
1333 | int | 1358 | int |
1334 | tlsext_keyshare_server_build(SSL *s, CBB *cbb) | 1359 | tlsext_keyshare_server_build(SSL *s, CBB *cbb) |
1335 | { | 1360 | { |
1361 | /* In the case of a HRR, we only send the server selected group. */ | ||
1362 | /* XXX - we should know this is a HRR. */ | ||
1363 | if (S3I(s)->hs_tls13.server_group != 0) | ||
1364 | return CBB_add_u16(cbb, S3I(s)->hs_tls13.server_group); | ||
1365 | |||
1336 | if (S3I(s)->hs_tls13.key_share == NULL) | 1366 | if (S3I(s)->hs_tls13.key_share == NULL) |
1337 | return 0; | 1367 | return 0; |
1338 | 1368 | ||
diff --git a/src/lib/libssl/tls13_server.c b/src/lib/libssl/tls13_server.c index 029dd7211b..313c5026d0 100644 --- a/src/lib/libssl/tls13_server.c +++ b/src/lib/libssl/tls13_server.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_server.c,v 1.36 2020/05/09 10:17:58 tb Exp $ */ | 1 | /* $OpenBSD: tls13_server.c,v 1.37 2020/05/09 10:51:55 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2020 Bob Beck <beck@openbsd.org> | 4 | * Copyright (c) 2020 Bob Beck <beck@openbsd.org> |
@@ -210,17 +210,25 @@ tls13_client_hello_recv(struct tls13_ctx *ctx, CBS *cbs) | |||
210 | } | 210 | } |
211 | 211 | ||
212 | static int | 212 | static int |
213 | tls13_server_hello_build(struct tls13_ctx *ctx, CBB *cbb) | 213 | tls13_server_hello_build(struct tls13_ctx *ctx, CBB *cbb, int hrr) |
214 | { | 214 | { |
215 | uint16_t tlsext_msg_type = SSL_TLSEXT_MSG_SH; | ||
216 | const uint8_t *server_random; | ||
215 | CBB session_id; | 217 | CBB session_id; |
216 | SSL *s = ctx->ssl; | 218 | SSL *s = ctx->ssl; |
217 | uint16_t cipher; | 219 | uint16_t cipher; |
218 | 220 | ||
219 | cipher = SSL_CIPHER_get_value(S3I(s)->hs.new_cipher); | 221 | cipher = SSL_CIPHER_get_value(S3I(s)->hs.new_cipher); |
222 | server_random = s->s3->server_random; | ||
223 | |||
224 | if (hrr) { | ||
225 | server_random = tls13_hello_retry_request_hash; | ||
226 | tlsext_msg_type = SSL_TLSEXT_MSG_HRR; | ||
227 | } | ||
220 | 228 | ||
221 | if (!CBB_add_u16(cbb, TLS1_2_VERSION)) | 229 | if (!CBB_add_u16(cbb, TLS1_2_VERSION)) |
222 | goto err; | 230 | goto err; |
223 | if (!CBB_add_bytes(cbb, s->s3->server_random, SSL3_RANDOM_SIZE)) | 231 | if (!CBB_add_bytes(cbb, server_random, SSL3_RANDOM_SIZE)) |
224 | goto err; | 232 | goto err; |
225 | if (!CBB_add_u8_length_prefixed(cbb, &session_id)) | 233 | if (!CBB_add_u8_length_prefixed(cbb, &session_id)) |
226 | goto err; | 234 | goto err; |
@@ -231,7 +239,7 @@ tls13_server_hello_build(struct tls13_ctx *ctx, CBB *cbb) | |||
231 | goto err; | 239 | goto err; |
232 | if (!CBB_add_u8(cbb, 0)) | 240 | if (!CBB_add_u8(cbb, 0)) |
233 | goto err; | 241 | goto err; |
234 | if (!tlsext_server_build(s, cbb, SSL_TLSEXT_MSG_SH)) | 242 | if (!tlsext_server_build(s, cbb, tlsext_msg_type)) |
235 | goto err; | 243 | goto err; |
236 | 244 | ||
237 | if (!CBB_flush(cbb)) | 245 | if (!CBB_flush(cbb)) |
@@ -313,13 +321,37 @@ tls13_server_engage_record_protection(struct tls13_ctx *ctx) | |||
313 | int | 321 | int |
314 | tls13_server_hello_retry_request_send(struct tls13_ctx *ctx, CBB *cbb) | 322 | tls13_server_hello_retry_request_send(struct tls13_ctx *ctx, CBB *cbb) |
315 | { | 323 | { |
316 | return 0; | 324 | int nid; |
325 | |||
326 | if (!tls13_synthetic_handshake_message(ctx)) | ||
327 | return 0; | ||
328 | |||
329 | if (ctx->hs->key_share != NULL) | ||
330 | return 0; | ||
331 | if ((nid = tls1_get_shared_curve(ctx->ssl)) == NID_undef) | ||
332 | return 0; | ||
333 | if ((ctx->hs->server_group = tls1_ec_nid2curve_id(nid)) == 0) | ||
334 | return 0; | ||
335 | |||
336 | if (!tls13_server_hello_build(ctx, cbb, 1)) | ||
337 | return 0; | ||
338 | |||
339 | return 1; | ||
317 | } | 340 | } |
318 | 341 | ||
319 | int | 342 | int |
320 | tls13_client_hello_retry_recv(struct tls13_ctx *ctx, CBS *cbs) | 343 | tls13_client_hello_retry_recv(struct tls13_ctx *ctx, CBS *cbs) |
321 | { | 344 | { |
322 | return 0; | 345 | SSL *s = ctx->ssl; |
346 | |||
347 | if (!tls13_client_hello_process(ctx, cbs)) | ||
348 | return 0; | ||
349 | |||
350 | /* XXX - need further checks. */ | ||
351 | if (s->method->internal->version < TLS1_3_VERSION) | ||
352 | return 0; | ||
353 | |||
354 | return 1; | ||
323 | } | 355 | } |
324 | 356 | ||
325 | int | 357 | int |
@@ -327,11 +359,12 @@ tls13_server_hello_send(struct tls13_ctx *ctx, CBB *cbb) | |||
327 | { | 359 | { |
328 | if (ctx->hs->key_share == NULL) | 360 | if (ctx->hs->key_share == NULL) |
329 | return 0; | 361 | return 0; |
330 | |||
331 | if (!tls13_key_share_generate(ctx->hs->key_share)) | 362 | if (!tls13_key_share_generate(ctx->hs->key_share)) |
332 | return 0; | 363 | return 0; |
333 | 364 | ||
334 | if (!tls13_server_hello_build(ctx, cbb)) | 365 | ctx->hs->server_group = 0; |
366 | |||
367 | if (!tls13_server_hello_build(ctx, cbb, 0)) | ||
335 | return 0; | 368 | return 0; |
336 | 369 | ||
337 | return 1; | 370 | return 1; |