Skip to content

Commit 0b3478c

Browse files
committed
librustls: expose named_groups in rustls_client_hello
1 parent 30fb11d commit 0b3478c

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

librustls/src/rustls.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,13 @@ typedef struct rustls_slice_u16 {
672672
*
673673
* `signature_schemes` carries the values supplied by the client or, if the
674674
* client did not send this TLS extension, the default schemes in the rustls library. See:
675-
* <https://docs.rs/rustls/latest/rustls/internal/msgs/enums/enum.SignatureScheme.html>.
675+
* <https://docs.rs/rustls/latest/rustls/enum.SignatureScheme.html>.
676+
*
677+
* `named_groups` carries the values of the `named_groups` extension sent by the
678+
* client. If the client did not send a `named_groups` extension, the length of
679+
* this `rustls_slice_u16` will be 0. The meaning of this extension differ
680+
* based on TLS version. See the Rustls documentation for more information:
681+
* <https://rustls.dev/docs/server/struct.ClientHello.html#method.named_groups>
676682
*
677683
* `alpn` carries the list of ALPN protocol names that the client proposed to
678684
* the server. Again, the length of this list will be 0 if none were supplied.
@@ -687,6 +693,7 @@ typedef struct rustls_slice_u16 {
687693
typedef struct rustls_client_hello {
688694
struct rustls_str server_name;
689695
struct rustls_slice_u16 signature_schemes;
696+
struct rustls_slice_u16 named_groups;
690697
const struct rustls_slice_slice_bytes *alpn;
691698
} rustls_client_hello;
692699

librustls/src/server.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,13 @@ impl ResolvesServerCert for ResolvesServerCertFromChoices {
512512
///
513513
/// `signature_schemes` carries the values supplied by the client or, if the
514514
/// client did not send this TLS extension, the default schemes in the rustls library. See:
515-
/// <https://docs.rs/rustls/latest/rustls/internal/msgs/enums/enum.SignatureScheme.html>.
515+
/// <https://docs.rs/rustls/latest/rustls/enum.SignatureScheme.html>.
516+
///
517+
/// `named_groups` carries the values of the `named_groups` extension sent by the
518+
/// client. If the client did not send a `named_groups` extension, the length of
519+
/// this `rustls_slice_u16` will be 0. The meaning of this extension differ
520+
/// based on TLS version. See the Rustls documentation for more information:
521+
/// <https://rustls.dev/docs/server/struct.ClientHello.html#method.named_groups>
516522
///
517523
/// `alpn` carries the list of ALPN protocol names that the client proposed to
518524
/// the server. Again, the length of this list will be 0 if none were supplied.
@@ -527,6 +533,7 @@ impl ResolvesServerCert for ResolvesServerCertFromChoices {
527533
pub struct rustls_client_hello<'a> {
528534
server_name: rustls_str<'a>,
529535
signature_schemes: rustls_slice_u16<'a>,
536+
named_groups: rustls_slice_u16<'a>,
530537
alpn: *const rustls_slice_slice_bytes<'a>,
531538
}
532539

@@ -596,6 +603,10 @@ impl ResolvesServerCert for ClientHelloResolver {
596603
.iter()
597604
.map(|s| u16::from(*s))
598605
.collect();
606+
let mapped_groups = match client_hello.named_groups() {
607+
Some(groups) => groups.iter().map(|g| u16::from(*g)).collect(),
608+
None => Vec::new(),
609+
};
599610
// Unwrap the Option. None becomes an empty slice.
600611
let alpn = match client_hello.alpn() {
601612
Some(iter) => iter.collect(),
@@ -604,9 +615,11 @@ impl ResolvesServerCert for ClientHelloResolver {
604615

605616
let alpn = rustls_slice_slice_bytes { inner: &alpn };
606617
let signature_schemes = (&*mapped_sigs).into();
618+
let named_groups = (&*mapped_groups).into();
607619
let hello = rustls_client_hello {
608620
server_name,
609621
signature_schemes,
622+
named_groups,
610623
alpn: &alpn,
611624
};
612625

0 commit comments

Comments
 (0)