summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2022-07-20 13:35:05 +0000
committertb <>2022-07-20 13:35:05 +0000
commitdbae5c40b8895f3b49634f79c8ff8fb9e7ae7064 (patch)
treee2964705fcaab534cb0031cc474b50f615a22537 /src
parentccb4f685d743447d79e76e1380f93ba28b5b8e1e (diff)
downloadopenbsd-dbae5c40b8895f3b49634f79c8ff8fb9e7ae7064.tar.gz
openbsd-dbae5c40b8895f3b49634f79c8ff8fb9e7ae7064.tar.bz2
openbsd-dbae5c40b8895f3b49634f79c8ff8fb9e7ae7064.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.c38
-rw-r--r--src/lib/libssl/ssl_tlsext.h3
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
65int 65int
66tlsext_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
86int
66tlsext_alpn_server_parse(SSL *s, uint16_t msg_types, CBS *cbs, int *alert) 87tlsext_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
34int tlsext_alpn_check_format(CBS *cbs);
34int tlsext_alpn_client_needs(SSL *s, uint16_t msg_type); 35int tlsext_alpn_client_needs(SSL *s, uint16_t msg_type);
35int tlsext_alpn_client_build(SSL *s, uint16_t msg_type, CBB *cbb); 36int tlsext_alpn_client_build(SSL *s, uint16_t msg_type, CBB *cbb);
36int tlsext_alpn_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert); 37int tlsext_alpn_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert);