Skip to content

Commit ffacc6f

Browse files
authored
Migrate PQ Rust code to TLS 1.3 (#4998)
1 parent 61c2a66 commit ffacc6f

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed

bindings/rust/extended/s2n-tls/src/connection.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ impl Connection {
972972
}
973973
}
974974

975+
#[deprecated = "PQ TLS 1.2 KEM Names are no longer supported. Use kem_group_name() to retrieve PQ TLS 1.3 Group name."]
975976
pub fn kem_name(&self) -> Option<&str> {
976977
let name_bytes = {
977978
let name = unsafe { s2n_connection_get_kem_name(self.connection.as_ptr()) };
@@ -1000,6 +1001,34 @@ impl Connection {
10001001
}
10011002
}
10021003

1004+
pub fn kem_group_name(&self) -> Option<&str> {
1005+
let name_bytes = {
1006+
let name = unsafe { s2n_connection_get_kem_group_name(self.connection.as_ptr()) };
1007+
if name.is_null() {
1008+
return None;
1009+
}
1010+
name
1011+
};
1012+
1013+
let name_str = unsafe {
1014+
// SAFETY: The data is null terminated because it is declared as a C
1015+
// string literal.
1016+
// SAFETY: kem_name has a static lifetime because it lives on a const
1017+
// struct s2n_kem with file scope.
1018+
const_str!(name_bytes)
1019+
};
1020+
1021+
match name_str {
1022+
Ok("NONE") => None,
1023+
Ok(name) => Some(name),
1024+
Err(_) => {
1025+
// Unreachable: This would indicate a non-utf-8 string literal in
1026+
// the s2n-tls C codebase.
1027+
None
1028+
}
1029+
}
1030+
}
1031+
10031032
pub fn selected_curve(&self) -> Result<&str, Error> {
10041033
let curve = unsafe { s2n_connection_get_curve(self.connection.as_ptr()).into_result()? };
10051034
unsafe {

bindings/rust/extended/s2n-tls/src/testing/s2n_tls.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@ mod tests {
2828
}
2929

3030
#[test]
31-
fn kem_name_retrieval() -> Result<(), Error> {
31+
fn kem_group_name_retrieval() -> Result<(), Error> {
3232
// PQ isn't supported
3333
{
3434
let policy = Policy::from_version("20240501")?;
3535
let config = build_config(&policy)?;
3636
let mut pair = TestPair::from_config(&config);
3737

38-
// before negotiation, kem_name is none
39-
assert!(pair.client.kem_name().is_none());
38+
// before negotiation, kem_group_name is none
39+
assert!(pair.client.kem_group_name().is_none());
4040

4141
pair.handshake().unwrap();
42-
assert!(pair.client.kem_name().is_none());
42+
assert!(pair.client.kem_group_name().is_none());
4343
}
4444

4545
// PQ is supported
4646
{
47-
let policy = Policy::from_version("KMS-PQ-TLS-1-0-2020-07")?;
47+
let policy = Policy::from_version("default_pq")?;
4848
let config = build_config(&policy)?;
4949
let mut pair = TestPair::from_config(&config);
5050

5151
pair.handshake().unwrap();
52-
assert_eq!(pair.client.kem_name(), Some("kyber512r3"));
52+
assert_eq!(pair.client.kem_group_name(), Some("X25519MLKEM768"));
5353
}
5454

5555
Ok(())

bindings/rust/standard/integration/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ mod tests {
1616
#[cfg(feature = "pq")]
1717
#[test]
1818
fn pq_sanity_check() -> Result<(), Box<dyn std::error::Error>> {
19-
let config = testing::build_config(&Policy::from_version("KMS-PQ-TLS-1-0-2020-07")?)?;
19+
let config = testing::build_config(&Policy::from_version("default_pq")?)?;
2020
let mut pair = TestPair::from_config(&config);
2121
pair.handshake()?;
2222

23-
if pair.client.kem_name().is_none() {
23+
if pair.client.kem_group_name().is_none() {
2424
panic!(
2525
"PQ tests are enabled, but PQ functionality is unavailable. \
2626
Are you sure that the libcrypto supports PQ?"

bindings/rust/standard/integration/src/network/tls_client.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,38 +46,17 @@ mod kms_pq {
4646
// supports ML-KEM.
4747
#[test_log::test(tokio::test)]
4848
async fn pq_handshake() -> Result<(), Box<dyn std::error::Error>> {
49-
let policy = Policy::from_version("KMS-PQ-TLS-1-0-2020-07")?;
49+
let policy = Policy::from_version("PQ-TLS-1-2-2023-10-09")?;
5050
let tls = handshake_with_domain(DOMAIN, &policy).await?;
5151

5252
assert_eq!(
5353
tls.as_ref().cipher_suite()?,
54-
"ECDHE-KYBER-RSA-AES256-GCM-SHA384"
54+
"TLS_AES_256_GCM_SHA384"
5555
);
56-
assert_eq!(tls.as_ref().kem_name(), Some("kyber512r3"));
56+
assert_eq!(tls.as_ref().kem_group_name(), Some("x25519_kyber-512-r3"));
5757

5858
Ok(())
5959
}
60-
61-
// We want to confirm that non-supported kyber drafts successfully fall
62-
// back to a full handshake.
63-
#[test_log::test(tokio::test)]
64-
async fn early_draft_falls_back_to_classical() -> Result<(), Box<dyn std::error::Error>> {
65-
const EARLY_DRAFT_PQ_POLICIES: &[&str] = &[
66-
"KMS-PQ-TLS-1-0-2019-06",
67-
"PQ-SIKE-TEST-TLS-1-0-2019-11",
68-
"KMS-PQ-TLS-1-0-2020-02",
69-
"PQ-SIKE-TEST-TLS-1-0-2020-02",
70-
];
71-
72-
for security_policy in EARLY_DRAFT_PQ_POLICIES {
73-
let policy = Policy::from_version(security_policy)?;
74-
let tls = handshake_with_domain(DOMAIN, &policy).await?;
75-
76-
assert_eq!(tls.as_ref().cipher_suite()?, "ECDHE-RSA-AES256-GCM-SHA384");
77-
assert_eq!(tls.as_ref().kem_name(), None);
78-
}
79-
Ok(())
80-
}
8160
}
8261

8362
#[test_log::test(tokio::test)]

0 commit comments

Comments
 (0)