Skip to content

Commit 839e122

Browse files
committed
Add export_keying_material support to pingora-s2n
Adds ssl_export_keying_material function to pingora-s2n ext module, wrapping s2n-tls's built-in tls_exporter method for RFC 5705.
1 parent a6dbd1a commit 839e122

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

pingora-s2n/src/ext.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2025 Cloudflare, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//! Extended functionalities for s2n-tls
16+
17+
use s2n_tls::connection::Connection;
18+
use s2n_tls::error::Error;
19+
20+
/// Export keying material from a TLS connection
21+
///
22+
/// Derives keying material for application use in accordance with RFC 5705.
23+
///
24+
/// Note: Currently only available with TLS 1.3 connections.
25+
///
26+
/// See [tls_exporter](https://docs.rs/s2n-tls/latest/s2n_tls/connection/struct.Connection.html#method.tls_exporter).
27+
pub fn ssl_export_keying_material(
28+
conn: &Connection,
29+
out: &mut [u8],
30+
label: &str,
31+
context: Option<&[u8]>,
32+
) -> Result<(), Error> {
33+
let context_bytes = context.unwrap_or(&[]);
34+
conn.tls_exporter(label.as_bytes(), context_bytes, out)
35+
}
36+
37+
#[cfg(test)]
38+
mod tests {
39+
use super::*;
40+
use s2n_tls::config::Builder;
41+
use s2n_tls::enums::Mode;
42+
43+
#[test]
44+
fn test_ssl_export_keying_material_exists() {
45+
// This test verifies that ssl_export_keying_material function exists
46+
// and has the correct signature. Actual functional testing requires
47+
// an established TLS connection.
48+
let config = Builder::new().build().unwrap();
49+
let mut conn = s2n_tls::connection::Connection::new(Mode::Client);
50+
conn.set_config(config).unwrap();
51+
let mut out = [0u8; 32];
52+
53+
// This will fail since there's no established connection, but verifies
54+
// the function signature is correct
55+
let _ = ssl_export_keying_material(&conn, &mut out, "test", None);
56+
}
57+
}

pingora-s2n/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
pub mod ext;
16+
1517
use pingora_error::{Error, ErrorType, Result};
1618
use std::fs;
1719

0 commit comments

Comments
 (0)