diff options
author | beck <> | 2022-06-29 17:39:21 +0000 |
---|---|---|
committer | beck <> | 2022-06-29 17:39:21 +0000 |
commit | fc8a9f3799769566fe4b424c43a81a1a71f91328 (patch) | |
tree | 3406a8350556d9a6c42a2677a30e2dabf013942c /src/lib/libssl/ssl_tlsext.c | |
parent | 6f4618c6c03ccd1d0f1b55dd8ff05af4a05abe78 (diff) | |
download | openbsd-fc8a9f3799769566fe4b424c43a81a1a71f91328.tar.gz openbsd-fc8a9f3799769566fe4b424c43a81a1a71f91328.tar.bz2 openbsd-fc8a9f3799769566fe4b424c43a81a1a71f91328.zip |
Add support for sending QUIC transport parameters
This is the start of adding the boringssl API for QUIC support,
and the TLS extensions necessary to send and receive QUIC transport
data.
Inspired by boringssl's https://boringssl-review.googlesource.com/24464
ok jsing@ tb@
Diffstat (limited to 'src/lib/libssl/ssl_tlsext.c')
-rw-r--r-- | src/lib/libssl/ssl_tlsext.c | 122 |
1 files changed, 121 insertions, 1 deletions
diff --git a/src/lib/libssl/ssl_tlsext.c b/src/lib/libssl/ssl_tlsext.c index 8faf90fde0..fc6c11daa6 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.114 2022/06/29 07:53:58 tb Exp $ */ | 1 | /* $OpenBSD: ssl_tlsext.c,v 1.115 2022/06/29 17:39:20 beck 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> |
@@ -1943,6 +1943,112 @@ tlsext_psk_server_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
1943 | return CBS_skip(cbs, CBS_len(cbs)); | 1943 | return CBS_skip(cbs, CBS_len(cbs)); |
1944 | } | 1944 | } |
1945 | 1945 | ||
1946 | /* | ||
1947 | * QUIC transport parameters extension. | ||
1948 | */ | ||
1949 | |||
1950 | int | ||
1951 | tlsext_quic_transport_parameters_client_needs(SSL *s, uint16_t msg_type) | ||
1952 | { | ||
1953 | return (s->internal->quic_transport_params_len > 0 && | ||
1954 | s->s3->hs.our_max_tls_version >= TLS1_3_VERSION); | ||
1955 | } | ||
1956 | |||
1957 | int | ||
1958 | tlsext_quic_transport_parameters_client_build(SSL *s, uint16_t msg_type, | ||
1959 | CBB *cbb) | ||
1960 | { | ||
1961 | CBB contents; | ||
1962 | |||
1963 | if (!CBB_add_u16_length_prefixed(cbb, &contents)) | ||
1964 | return 0; | ||
1965 | |||
1966 | if (!CBB_add_bytes(&contents, s->internal->quic_transport_params, | ||
1967 | s->internal->quic_transport_params_len)) | ||
1968 | return 0; | ||
1969 | |||
1970 | if (!CBB_flush(cbb)) | ||
1971 | return 0; | ||
1972 | |||
1973 | return 1; | ||
1974 | } | ||
1975 | |||
1976 | int | ||
1977 | tlsext_quic_transport_parameters_client_parse(SSL *s, uint16_t msg_type, | ||
1978 | CBS *cbs, int *alert) | ||
1979 | { | ||
1980 | CBS transport_data; | ||
1981 | |||
1982 | /* QUIC requires TLS 1.3. */ | ||
1983 | if (ssl_effective_tls_version(s) < TLS1_3_VERSION) { | ||
1984 | *alert = SSL_AD_UNSUPPORTED_EXTENSION; | ||
1985 | return 0; | ||
1986 | } | ||
1987 | |||
1988 | if (!CBS_get_u16_length_prefixed(cbs, &transport_data)) | ||
1989 | return 0; | ||
1990 | |||
1991 | if (!CBS_stow(&transport_data, &s->s3->peer_quic_transport_params, | ||
1992 | &s->s3->peer_quic_transport_params_len)) | ||
1993 | return 0; | ||
1994 | |||
1995 | return 1; | ||
1996 | } | ||
1997 | |||
1998 | int | ||
1999 | tlsext_quic_transport_parameters_server_needs(SSL *s, uint16_t msg_type) | ||
2000 | { | ||
2001 | return s->internal->quic_transport_params_len > 0; | ||
2002 | } | ||
2003 | |||
2004 | int | ||
2005 | tlsext_quic_transport_parameters_server_build(SSL *s, uint16_t msg_type, | ||
2006 | CBB *cbb) | ||
2007 | { | ||
2008 | CBB contents; | ||
2009 | |||
2010 | if (!CBB_add_u16_length_prefixed(cbb, &contents)) | ||
2011 | return 0; | ||
2012 | |||
2013 | if (!CBB_add_bytes(&contents, s->internal->quic_transport_params, | ||
2014 | s->internal->quic_transport_params_len)) | ||
2015 | return 0; | ||
2016 | |||
2017 | if (!CBB_flush(cbb)) | ||
2018 | return 0; | ||
2019 | |||
2020 | return 1; | ||
2021 | } | ||
2022 | |||
2023 | int | ||
2024 | tlsext_quic_transport_parameters_server_parse(SSL *s, uint16_t msg_type, | ||
2025 | CBS *cbs, int *alert) | ||
2026 | { | ||
2027 | CBS transport_data; | ||
2028 | |||
2029 | /* | ||
2030 | * Ignore this extension if we don't have configured quic transport data | ||
2031 | * or if we are not TLS 1.3. | ||
2032 | */ | ||
2033 | if (s->internal->quic_transport_params_len == 0 || | ||
2034 | ssl_effective_tls_version(s) < TLS1_3_VERSION) { | ||
2035 | if (!CBS_skip(cbs, CBS_len(cbs))) { | ||
2036 | *alert = SSL_AD_INTERNAL_ERROR; | ||
2037 | return 0; | ||
2038 | } | ||
2039 | return 1; | ||
2040 | } | ||
2041 | |||
2042 | if (!CBS_get_u16_length_prefixed(cbs, &transport_data)) | ||
2043 | return 0; | ||
2044 | |||
2045 | if (!CBS_stow(&transport_data, &s->s3->peer_quic_transport_params, | ||
2046 | &s->s3->peer_quic_transport_params_len)) | ||
2047 | return 0; | ||
2048 | |||
2049 | return 1; | ||
2050 | } | ||
2051 | |||
1946 | struct tls_extension_funcs { | 2052 | struct tls_extension_funcs { |
1947 | int (*needs)(SSL *s, uint16_t msg_type); | 2053 | int (*needs)(SSL *s, uint16_t msg_type); |
1948 | int (*build)(SSL *s, uint16_t msg_type, CBB *cbb); | 2054 | int (*build)(SSL *s, uint16_t msg_type, CBB *cbb); |
@@ -2132,6 +2238,20 @@ static const struct tls_extension tls_extensions[] = { | |||
2132 | }, | 2238 | }, |
2133 | #endif /* OPENSSL_NO_SRTP */ | 2239 | #endif /* OPENSSL_NO_SRTP */ |
2134 | { | 2240 | { |
2241 | .type = TLSEXT_TYPE_quic_transport_parameters, | ||
2242 | .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_SH, | ||
2243 | .client = { | ||
2244 | .needs = tlsext_quic_transport_parameters_client_needs, | ||
2245 | .build = tlsext_quic_transport_parameters_client_build, | ||
2246 | .parse = tlsext_quic_transport_parameters_client_parse, | ||
2247 | }, | ||
2248 | .server = { | ||
2249 | .needs = tlsext_quic_transport_parameters_server_needs, | ||
2250 | .build = tlsext_quic_transport_parameters_server_build, | ||
2251 | .parse = tlsext_quic_transport_parameters_server_parse, | ||
2252 | }, | ||
2253 | }, | ||
2254 | { | ||
2135 | .type = TLSEXT_TYPE_psk_key_exchange_modes, | 2255 | .type = TLSEXT_TYPE_psk_key_exchange_modes, |
2136 | .messages = SSL_TLSEXT_MSG_CH, | 2256 | .messages = SSL_TLSEXT_MSG_CH, |
2137 | .client = { | 2257 | .client = { |