Skip to content

Commit 3744e94

Browse files
committed
add function to export key data from dtls connection
Signed-off-by: Elliot Levin <[email protected]>
1 parent 86cbbb7 commit 3744e94

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

dtls/src/state.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ struct SerializedState {
6565
is_client: bool,
6666
}
6767

68+
#[derive(Serialize, Deserialize, Debug, Clone)]
69+
pub struct KeyLogData {
70+
pub local_random: Vec<u8>,
71+
pub remote_random: Vec<u8>,
72+
pub master_secret: Vec<u8>,
73+
}
74+
6875
impl Default for State {
6976
fn default() -> Self {
7077
State {
@@ -249,6 +256,26 @@ impl State {
249256

250257
Ok(())
251258
}
259+
260+
/// key_log_data returns the key log data for the current state.
261+
pub fn key_log_data(&self) -> Result<KeyLogData> {
262+
let mut local_random = vec![];
263+
{
264+
let mut writer = BufWriter::<&mut Vec<u8>>::new(local_random.as_mut());
265+
self.local_random.marshal(&mut writer)?;
266+
}
267+
let mut remote_random = vec![];
268+
{
269+
let mut writer = BufWriter::<&mut Vec<u8>>::new(remote_random.as_mut());
270+
self.remote_random.marshal(&mut writer)?;
271+
}
272+
273+
Ok(KeyLogData {
274+
local_random,
275+
remote_random,
276+
master_secret: self.master_secret.clone(),
277+
})
278+
}
252279
}
253280

254281
#[async_trait]

0 commit comments

Comments
 (0)