Skip to content

Commit 6866824

Browse files
ajbozartht8m
authored andcommitted
Add SSL_get0_group_name() to get name of the group used for KEX
Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from #20866)
1 parent 8229874 commit 6866824

8 files changed

Lines changed: 85 additions & 0 deletions

File tree

doc/build.info

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,10 @@ DEPEND[html/man3/SSL_get0_connection.html]=man3/SSL_get0_connection.pod
24952495
GENERATE[html/man3/SSL_get0_connection.html]=man3/SSL_get0_connection.pod
24962496
DEPEND[man/man3/SSL_get0_connection.3]=man3/SSL_get0_connection.pod
24972497
GENERATE[man/man3/SSL_get0_connection.3]=man3/SSL_get0_connection.pod
2498+
DEPEND[html/man3/SSL_get0_group_name.html]=man3/SSL_get0_group_name.pod
2499+
GENERATE[html/man3/SSL_get0_group_name.html]=man3/SSL_get0_group_name.pod
2500+
DEPEND[man/man3/SSL_get0_group_name.3]=man3/SSL_get0_group_name.pod
2501+
GENERATE[man/man3/SSL_get0_group_name.3]=man3/SSL_get0_group_name.pod
24982502
DEPEND[html/man3/SSL_get0_peer_rpk.html]=man3/SSL_get0_peer_rpk.pod
24992503
GENERATE[html/man3/SSL_get0_peer_rpk.html]=man3/SSL_get0_peer_rpk.pod
25002504
DEPEND[man/man3/SSL_get0_peer_rpk.3]=man3/SSL_get0_peer_rpk.pod
@@ -3523,6 +3527,7 @@ html/man3/SSL_export_keying_material.html \
35233527
html/man3/SSL_extension_supported.html \
35243528
html/man3/SSL_free.html \
35253529
html/man3/SSL_get0_connection.html \
3530+
html/man3/SSL_get0_group_name.html \
35263531
html/man3/SSL_get0_peer_rpk.html \
35273532
html/man3/SSL_get0_peer_scts.html \
35283533
html/man3/SSL_get_SSL_CTX.html \
@@ -4160,6 +4165,7 @@ man/man3/SSL_export_keying_material.3 \
41604165
man/man3/SSL_extension_supported.3 \
41614166
man/man3/SSL_free.3 \
41624167
man/man3/SSL_get0_connection.3 \
4168+
man/man3/SSL_get0_group_name.3 \
41634169
man/man3/SSL_get0_peer_rpk.3 \
41644170
man/man3/SSL_get0_peer_scts.3 \
41654171
man/man3/SSL_get_SSL_CTX.3 \

doc/man3/SSL_get0_group_name.pod

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
=pod
2+
3+
=head1 NAME
4+
5+
SSL_get0_group_name - get name of the group that was used for the key
6+
agreement of the current TLS session establishment
7+
8+
=head1 SYNOPSIS
9+
10+
#include <openssl/ssl.h>
11+
12+
const char *SSL_get0_group_name(SSL *s);
13+
14+
=head1 DESCRIPTION
15+
16+
SSL_get0_group_name() returns the name of the group that was used for
17+
the key agreement of the current TLS session establishment.
18+
19+
20+
=head1 RETURN VALUES
21+
22+
If non-NULL, SSL_get0_group_name() returns the name of the group that was used for
23+
the key agreement of the current TLS session establishment.
24+
If SSL_get0_group_name() returns NULL, an error occurred; possibly no TLS session
25+
has been established.
26+
27+
Note that the return value is valid only during the lifetime of the
28+
SSL object I<ssl>.
29+
30+
=head1 SEE ALSO
31+
32+
L<ssl(7)>
33+
34+
=head1 COPYRIGHT
35+
36+
Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
37+
38+
Licensed under the Apache License 2.0 (the "License"). You may not use
39+
this file except in compliance with the License. You can obtain a copy
40+
in the file LICENSE in the source distribution or at
41+
L<https://www.openssl.org/source/license.html>.
42+
43+
=cut

include/openssl/ssl.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,7 @@ DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION)
15041504
# define SSL_get_max_proto_version(s) \
15051505
SSL_ctrl(s, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL)
15061506

1507+
const char *SSL_get0_group_name(SSL *s);
15071508
const char *SSL_group_to_name(SSL *s, int id);
15081509

15091510
/* Backwards compatibility, original 1.1.0 names */

ssl/s3_lib.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5022,6 +5022,22 @@ int ssl_encapsulate(SSL_CONNECTION *s, EVP_PKEY *pubkey,
50225022
return rv;
50235023
}
50245024

5025+
const char *SSL_get0_group_name(SSL *s)
5026+
{
5027+
SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
5028+
unsigned int id;
5029+
5030+
if (sc == NULL)
5031+
return NULL;
5032+
5033+
if (SSL_CONNECTION_IS_TLS13(sc) && sc->s3.did_kex)
5034+
id = sc->s3.group_id;
5035+
else
5036+
id = sc->session->kex_group;
5037+
5038+
return tls1_group_id2name(s->ctx, id);
5039+
}
5040+
50255041
const char *SSL_group_to_name(SSL *s, int nid) {
50265042
int group_id = 0;
50275043
const TLS_GROUP_INFO *cinf = NULL;

ssl/ssl_local.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,6 +2767,7 @@ __owur int ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL_CONNECTION *s);
27672767
SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
27682768

27692769
__owur const TLS_GROUP_INFO *tls1_group_id_lookup(SSL_CTX *ctx, uint16_t curve_id);
2770+
__owur const char *tls1_group_id2name(SSL_CTX *ctx, uint16_t group_id);
27702771
__owur int tls1_group_id2nid(uint16_t group_id, int include_unknown);
27712772
__owur uint16_t tls1_nid2group_id(int nid);
27722773
__owur int tls1_check_group_id(SSL_CONNECTION *s, uint16_t group_id,

ssl/t1_lib.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,16 @@ const TLS_GROUP_INFO *tls1_group_id_lookup(SSL_CTX *ctx, uint16_t group_id)
755755
return NULL;
756756
}
757757

758+
const char *tls1_group_id2name(SSL_CTX *ctx, uint16_t group_id)
759+
{
760+
const TLS_GROUP_INFO *tls_group_info = tls1_group_id_lookup(ctx, group_id);
761+
762+
if (tls_group_info == NULL)
763+
return NULL;
764+
765+
return tls_group_info->tlsname;
766+
}
767+
758768
int tls1_group_id2nid(uint16_t group_id, int include_unknown)
759769
{
760770
size_t i;

test/sslapitest.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5037,6 +5037,9 @@ static int test_key_exchange(int idx)
50375037

50385038
/* We don't implement RFC 7919 named groups for TLS 1.2. */
50395039
if (idx != 13) {
5040+
if (!TEST_str_eq(SSL_get0_group_name(serverssl), kexch_name0)
5041+
|| !TEST_str_eq(SSL_get0_group_name(clientssl), kexch_name0))
5042+
goto end;
50405043
if (!TEST_int_eq(SSL_get_negotiated_group(serverssl), kexch_groups[0]))
50415044
goto end;
50425045
if (!TEST_int_eq(SSL_get_negotiated_group(clientssl), kexch_groups[0]))
@@ -9495,6 +9498,10 @@ static int test_pluggable_group(int idx)
94959498
SSL_group_to_name(serverssl, SSL_get_shared_group(serverssl, 0))))
94969499
goto end;
94979500

9501+
if (!TEST_str_eq(group_name, SSL_get0_group_name(serverssl))
9502+
|| !TEST_str_eq(group_name, SSL_get0_group_name(clientssl)))
9503+
goto end;
9504+
94989505
testresult = 1;
94999506

95009507
end:

util/libssl.num

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,3 +576,4 @@ SSL_get_conn_close_info ? 3_2_0 EXIST::FUNCTION:
576576
SSL_set_incoming_stream_policy ? 3_2_0 EXIST::FUNCTION:
577577
SSL_handle_events ? 3_2_0 EXIST::FUNCTION:
578578
SSL_get_event_timeout ? 3_2_0 EXIST::FUNCTION:
579+
SSL_get0_group_name ? 3_2_0 EXIST::FUNCTION:

0 commit comments

Comments
 (0)