diff options
| author | tb <> | 2022-07-20 13:35:05 +0000 |
|---|---|---|
| committer | tb <> | 2022-07-20 13:35:05 +0000 |
| commit | c02e9022095ee758d22525cc2a119b410ca01322 (patch) | |
| tree | e2964705fcaab534cb0031cc474b50f615a22537 /src | |
| parent | c883f86bc052054b4a1fc92fd72cc4c7ea17657e (diff) | |
| download | openbsd-c02e9022095ee758d22525cc2a119b410ca01322.tar.gz openbsd-c02e9022095ee758d22525cc2a119b410ca01322.tar.bz2 openbsd-c02e9022095ee758d22525cc2a119b410ca01322.zip | |
Factor out ALPN extension format check
The ALPN extension must contain a non-empty list of protocol names.
Split a check of this out of tlsext_alpn_server_parse() so that it
can be reused elsewhere in the library.
ok jsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libssl/ssl_tlsext.c | 38 | ||||
| -rw-r--r-- | src/lib/libssl/ssl_tlsext.h | 3 |
2 files changed, 27 insertions, 14 deletions
diff --git a/src/lib/libssl/ssl_tlsext.c b/src/lib/libssl/ssl_tlsext.c index 6063991306..781d40d03a 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.121 2022/07/17 14:54:10 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_tlsext.c,v 1.122 2022/07/20 13:35:05 tb 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> |
| @@ -63,29 +63,41 @@ tlsext_alpn_client_build(SSL *s, uint16_t msg_type, CBB *cbb) | |||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | int | 65 | int |
| 66 | tlsext_alpn_check_format(CBS *cbs) | ||
| 67 | { | ||
| 68 | CBS proto_name_list; | ||
| 69 | |||
| 70 | if (CBS_len(cbs) == 0) | ||
| 71 | return 0; | ||
| 72 | |||
| 73 | CBS_dup(cbs, &proto_name_list); | ||
| 74 | while (CBS_len(&proto_name_list) > 0) { | ||
| 75 | CBS proto_name; | ||
| 76 | |||
| 77 | if (!CBS_get_u8_length_prefixed(&proto_name_list, &proto_name)) | ||
| 78 | return 0; | ||
| 79 | if (CBS_len(&proto_name) == 0) | ||
| 80 | return 0; | ||
| 81 | } | ||
| 82 | |||
| 83 | return 1; | ||
| 84 | } | ||
| 85 | |||
| 86 | int | ||
| 66 | tlsext_alpn_server_parse(SSL *s, uint16_t msg_types, CBS *cbs, int *alert) | 87 | tlsext_alpn_server_parse(SSL *s, uint16_t msg_types, CBS *cbs, int *alert) |
| 67 | { | 88 | { |
| 68 | CBS proto_name_list, alpn; | 89 | CBS alpn; |
| 69 | const unsigned char *selected; | 90 | const unsigned char *selected; |
| 70 | unsigned char selected_len; | 91 | unsigned char selected_len; |
| 71 | int r; | 92 | int r; |
| 72 | 93 | ||
| 73 | if (!CBS_get_u16_length_prefixed(cbs, &alpn)) | 94 | if (!CBS_get_u16_length_prefixed(cbs, &alpn)) |
| 74 | goto err; | 95 | goto err; |
| 75 | if (CBS_len(&alpn) < 2) | ||
| 76 | goto err; | ||
| 77 | if (CBS_len(cbs) != 0) | 96 | if (CBS_len(cbs) != 0) |
| 78 | goto err; | 97 | goto err; |
| 79 | 98 | ||
| 80 | CBS_dup(&alpn, &proto_name_list); | 99 | if (!tlsext_alpn_check_format(&alpn)) |
| 81 | while (CBS_len(&proto_name_list) > 0) { | 100 | goto err; |
| 82 | CBS proto_name; | ||
| 83 | |||
| 84 | if (!CBS_get_u8_length_prefixed(&proto_name_list, &proto_name)) | ||
| 85 | goto err; | ||
| 86 | if (CBS_len(&proto_name) == 0) | ||
| 87 | goto err; | ||
| 88 | } | ||
| 89 | 101 | ||
| 90 | if (s->ctx->internal->alpn_select_cb == NULL) | 102 | if (s->ctx->internal->alpn_select_cb == NULL) |
| 91 | return 1; | 103 | return 1; |
diff --git a/src/lib/libssl/ssl_tlsext.h b/src/lib/libssl/ssl_tlsext.h index 268b274948..393ee5d90d 100644 --- a/src/lib/libssl/ssl_tlsext.h +++ b/src/lib/libssl/ssl_tlsext.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ssl_tlsext.h,v 1.30 2022/06/29 17:39:20 beck Exp $ */ | 1 | /* $OpenBSD: ssl_tlsext.h,v 1.31 2022/07/20 13:35:05 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org> |
| 4 | * Copyright (c) 2017 Doug Hogan <doug@openbsd.org> | 4 | * Copyright (c) 2017 Doug Hogan <doug@openbsd.org> |
| @@ -31,6 +31,7 @@ | |||
| 31 | 31 | ||
| 32 | __BEGIN_HIDDEN_DECLS | 32 | __BEGIN_HIDDEN_DECLS |
| 33 | 33 | ||
| 34 | int tlsext_alpn_check_format(CBS *cbs); | ||
| 34 | int tlsext_alpn_client_needs(SSL *s, uint16_t msg_type); | 35 | int tlsext_alpn_client_needs(SSL *s, uint16_t msg_type); |
| 35 | int tlsext_alpn_client_build(SSL *s, uint16_t msg_type, CBB *cbb); | 36 | int tlsext_alpn_client_build(SSL *s, uint16_t msg_type, CBB *cbb); |
| 36 | int tlsext_alpn_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert); | 37 | int tlsext_alpn_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert); |
