summaryrefslogtreecommitdiff
path: root/src/lib/libssl
diff options
context:
space:
mode:
authortb <>2026-06-06 08:45:41 +0000
committertb <>2026-06-06 08:45:41 +0000
commit93c5a7dd0add95919ba07556309ed8db9d396005 (patch)
treea470598d3597d847e54629eaedfd8a48342bddeb /src/lib/libssl
parent959cf9ab5ba19116c52ad633faab70292d4c6858 (diff)
downloadopenbsd-93c5a7dd0add95919ba07556309ed8db9d396005.tar.gz
openbsd-93c5a7dd0add95919ba07556309ed8db9d396005.tar.bz2
openbsd-93c5a7dd0add95919ba07556309ed8db9d396005.zip
libssl: don't break TLSv1.2 with X25519MLKEM768
If the list of 'groups' starts with X25519MLKEM768 for a TLSv1.2 server, ssl3_send_server_kex_ecdhe() attempts to use NID_X25519MLKEM768, which it receives from tls1_get_supported_groups(). This does not work because it never received the peer's public keys, which causes an error return from tls_key_share_server_generate_mlkem768x25519(). For a TLSv1.2-only client with custom supported group list we will currently send ML-KEM if configured. We should not do this. There is more to fix here: if a TLSv1.2 client is misconfigured with only X25519MLKEM768, we should not send a supported groups extension (with this commit we'll send an empty one, which is an RFC violation). This commit simply filters X25519MLKEM768 out of the supported groups list if we're configured to be TLSv1.2-only. feedback/ok jsing kenjiro (on an earlier version)
Diffstat (limited to 'src/lib/libssl')
-rw-r--r--src/lib/libssl/ssl_tlsext.c8
-rw-r--r--src/lib/libssl/t1_lib.c25
2 files changed, 30 insertions, 3 deletions
diff --git a/src/lib/libssl/ssl_tlsext.c b/src/lib/libssl/ssl_tlsext.c
index f6fbf43dfd..ccdb5d1dfa 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.160 2026/05/09 11:45:50 tb Exp $ */ 1/* $OpenBSD: ssl_tlsext.c,v 1.161 2026/06/06 08:45:41 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>
@@ -193,6 +193,10 @@ tlsext_alpn_client_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
193static int 193static int
194tlsext_supportedgroups_client_needs(SSL *s, uint16_t msg_type) 194tlsext_supportedgroups_client_needs(SSL *s, uint16_t msg_type)
195{ 195{
196 /*
197 * XXX - Don't send an empty named_group_list. For TLSv1.3 we error
198 * earlier; for TLSv1.2 ensure we don't send the extension.
199 */
196 return ssl_has_ecc_ciphers(s) || 200 return ssl_has_ecc_ciphers(s) ||
197 (s->s3->hs.our_max_tls_version >= TLS1_3_VERSION); 201 (s->s3->hs.our_max_tls_version >= TLS1_3_VERSION);
198} 202}
@@ -215,7 +219,7 @@ tlsext_supportedgroups_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
215 return 0; 219 return 0;
216 220
217 for (i = 0; i < groups_len; i++) { 221 for (i = 0; i < groups_len; i++) {
218 if (!ssl_security_supported_group(s, groups[i])) 222 if (!tls1_check_group(s, groups[i]))
219 continue; 223 continue;
220 if (!CBB_add_u16(&grouplist, groups[i])) 224 if (!CBB_add_u16(&grouplist, groups[i]))
221 return 0; 225 return 0;
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c
index 9947dcba1d..9dfcc0c0f3 100644
--- a/src/lib/libssl/t1_lib.c
+++ b/src/lib/libssl/t1_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t1_lib.c,v 1.208 2026/06/04 18:02:52 tb Exp $ */ 1/* $OpenBSD: t1_lib.c,v 1.209 2026/06/06 08:45:41 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -154,6 +154,7 @@ struct supported_group {
154 uint16_t group_id; 154 uint16_t group_id;
155 int nid; 155 int nid;
156 int bits; 156 int bits;
157 uint16_t min_version;
157}; 158};
158 159
159/* 160/*
@@ -310,6 +311,7 @@ static const struct supported_group nid_list[] = {
310 .group_id = 4588, 311 .group_id = 4588,
311 .nid = NID_X25519MLKEM768, 312 .nid = NID_X25519MLKEM768,
312 .bits = 128, 313 .bits = 128,
314 .min_version = TLS1_3_VERSION,
313 }, 315 },
314}; 316};
315 317
@@ -512,6 +514,17 @@ tls1_group_id_present(uint16_t group_id, const uint16_t *list, size_t list_len)
512 return 0; 514 return 0;
513} 515}
514 516
517static int
518tls1_group_id_allowed(const SSL *ssl, uint16_t group_id)
519{
520 const struct supported_group *sg;
521
522 if ((sg = tls1_supported_group_by_id(group_id)) == NULL)
523 return 0;
524
525 return ssl_effective_tls_version(ssl) >= sg->min_version;
526}
527
515int 528int
516tls1_count_shared_groups(const SSL *ssl, size_t *out_count) 529tls1_count_shared_groups(const SSL *ssl, size_t *out_count)
517{ 530{
@@ -529,6 +542,9 @@ tls1_count_shared_groups(const SSL *ssl, size_t *out_count)
529 if (!ssl_security_shared_group(ssl, pref[i])) 542 if (!ssl_security_shared_group(ssl, pref[i]))
530 continue; 543 continue;
531 544
545 if (!tls1_group_id_allowed(ssl, pref[i]))
546 continue;
547
532 count++; 548 count++;
533 } 549 }
534 550
@@ -555,6 +571,9 @@ tls1_group_by_index(const SSL *ssl, size_t n, int *out_nid,
555 if (!ssl_security_fn(ssl, pref[i])) 571 if (!ssl_security_fn(ssl, pref[i]))
556 continue; 572 continue;
557 573
574 if (!tls1_group_id_allowed(ssl, pref[i]))
575 continue;
576
558 if (count++ == n) 577 if (count++ == n)
559 return tls1_ec_group_id2nid(pref[i], out_nid); 578 return tls1_ec_group_id2nid(pref[i], out_nid);
560 } 579 }
@@ -659,6 +678,10 @@ tls1_check_group(SSL *s, uint16_t group_id)
659 for (i = 0; i < groupslen; i++) { 678 for (i = 0; i < groupslen; i++) {
660 if (!ssl_security_supported_group(s, groups[i])) 679 if (!ssl_security_supported_group(s, groups[i]))
661 continue; 680 continue;
681
682 if (!tls1_group_id_allowed(s, groups[i]))
683 continue;
684
662 if (groups[i] == group_id) 685 if (groups[i] == group_id)
663 return 1; 686 return 1;
664 } 687 }