From 44d854e03a09ea7e28ddd78e0e11d8d8e0d14218 Mon Sep 17 00:00:00 2001 From: monica Date: Wed, 4 Jan 2023 15:22:44 -0500 Subject: [PATCH 1/3] added explicit lifetime for session refs --- zssp/src/applicationlayer.rs | 4 ++-- zssp/src/tests.rs | 4 ++-- zssp/src/zssp.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zssp/src/applicationlayer.rs b/zssp/src/applicationlayer.rs index 68358aa95..b07af5d67 100644 --- a/zssp/src/applicationlayer.rs +++ b/zssp/src/applicationlayer.rs @@ -19,7 +19,7 @@ pub trait ApplicationLayer: Sized { type Data; /// Arbitrary object that dereferences to the session, such as Arc>. - type SessionRef: Deref>; + type SessionRef<'a>: Deref>; /// A buffer containing data read from the network that can be cached. /// @@ -57,7 +57,7 @@ pub trait ApplicationLayer: Sized { fn extract_s_public_from_raw(static_public: &[u8]) -> Option; /// Look up a local session by local session ID or return None if not found. - fn lookup_session(&self, local_session_id: SessionId) -> Option; + fn lookup_session<'a>(&self, local_session_id: SessionId) -> Option>; /// Rate limit and check an attempted new session (called before accept_new_session). fn check_new_session(&self, rc: &ReceiveContext, remote_address: &Self::RemoteAddress) -> bool; diff --git a/zssp/src/tests.rs b/zssp/src/tests.rs index 96e4e62bb..3ba061c12 100644 --- a/zssp/src/tests.rs +++ b/zssp/src/tests.rs @@ -45,7 +45,7 @@ mod tests { impl ApplicationLayer for Box { type Data = u32; - type SessionRef = Arc>>; + type SessionRef<'a> = Arc>>; type IncomingPacketBuffer = Vec; type RemoteAddress = u32; @@ -67,7 +67,7 @@ mod tests { P384PublicKey::from_bytes(static_public) } - fn lookup_session(&self, local_session_id: SessionId) -> Option { + fn lookup_session<'a>(&self, local_session_id: SessionId) -> Option> { self.session.lock().unwrap().as_ref().and_then(|s| { if s.id == local_session_id { Some(s.clone()) diff --git a/zssp/src/zssp.rs b/zssp/src/zssp.rs index b34184dd0..ff1d561d3 100644 --- a/zssp/src/zssp.rs +++ b/zssp/src/zssp.rs @@ -638,7 +638,7 @@ impl ReceiveContext { canonical_header_bytes: &[u8; 12], fragments: &[Application::IncomingPacketBuffer], packet_type: u8, - session: Option, + session: Option>, mtu: usize, current_time: i64, ) -> Result, Error> { From 392d0a2b2ab4c18033a967be40b4c8a2f50a3246 Mon Sep 17 00:00:00 2001 From: monica Date: Wed, 4 Jan 2023 15:24:19 -0500 Subject: [PATCH 2/3] removed unnecessary boxing --- zssp/src/tests.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/zssp/src/tests.rs b/zssp/src/tests.rs index 3ba061c12..d0f65efbc 100644 --- a/zssp/src/tests.rs +++ b/zssp/src/tests.rs @@ -17,7 +17,7 @@ mod tests { local_s: P384KeyPair, local_s_hash: [u8; 48], psk: Secret<64>, - session: Mutex>>>>, + session: Mutex>>>, session_id_counter: Mutex, queue: Mutex>>, key_id: Mutex<[u8; 16]>, @@ -43,9 +43,9 @@ mod tests { } } - impl ApplicationLayer for Box { + impl ApplicationLayer for TestHost { type Data = u32; - type SessionRef<'a> = Arc>>; + type SessionRef<'a> = Arc>; type IncomingPacketBuffer = Vec; type RemoteAddress = u32; @@ -98,10 +98,10 @@ mod tests { let mut psk: Secret<64> = Secret::default(); random::fill_bytes_secure(&mut psk.0); - let alice_host = Box::new(TestHost::new(psk.clone(), "alice", "bob")); - let bob_host = Box::new(TestHost::new(psk.clone(), "bob", "alice")); - let alice_rc: Box>> = Box::new(ReceiveContext::new(&alice_host)); - let bob_rc: Box>> = Box::new(ReceiveContext::new(&bob_host)); + let alice_host = TestHost::new(psk.clone(), "alice", "bob"); + let bob_host = TestHost::new(psk.clone(), "bob", "alice"); + let alice_rc: ReceiveContext = ReceiveContext::new(&alice_host); + let bob_rc: ReceiveContext = ReceiveContext::new(&bob_host); //println!("zssp: size of session (bytes): {}", std::mem::size_of::>>()); From a178a23ee724d3041c2401e2c20ccad97962d8c8 Mon Sep 17 00:00:00 2001 From: monica Date: Wed, 4 Jan 2023 16:43:06 -0500 Subject: [PATCH 3/3] corrected comment --- zssp/src/applicationlayer.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/zssp/src/applicationlayer.rs b/zssp/src/applicationlayer.rs index b07af5d67..80810944b 100644 --- a/zssp/src/applicationlayer.rs +++ b/zssp/src/applicationlayer.rs @@ -64,9 +64,8 @@ pub trait ApplicationLayer: Sized { /// Check whether a new session should be accepted. /// - /// On success a tuple of local session ID, static secret, and associated object is returned. The - /// static secret is whatever results from agreement between the local and remote static public - /// keys. + /// On success a tuple of local session ID, psk, and associated object is returned. + /// Set psk to all zeros if one is not in use with the remote party. /// /// When `accept_new_session` is called, `remote_static_public` and `remote_metadata` have not yet been /// authenticated. As such avoid mutating state until OkNewSession(Session) is returned, as the connection