From 1ea5e4e071c3e89ab911c0e7c76af098fd2c3c99 Mon Sep 17 00:00:00 2001 From: Dhanuka Warusadura Date: Thu, 29 Feb 2024 15:38:01 +0530 Subject: [PATCH] Adds proper key generation and exchange This change adds proper key generation and exchange to Session::new() and removes the garbage key. Signed-off-by: Dhanuka Warusadura --- server/src/daemon/session.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/src/daemon/session.rs b/server/src/daemon/session.rs index b1621b804..0ba8242ef 100644 --- a/server/src/daemon/session.rs +++ b/server/src/daemon/session.rs @@ -35,8 +35,14 @@ impl Session { manager: Arc>, sessions_counter: i32, ) -> (Self, Option) { - // make use of the keys - let service_key = vec![0]; + let service_key = if client_public_key.is_none() { + Some(Key::new(vec![0])) + } else { + let private_key = Key::generate_private_key(); + let public_key = Key::generate_public_key(&private_key); + Some(Key::from(public_key)) + }; + let instance = Self { client_public_key: Arc::new(client_public_key), path: OwnedObjectPath::try_from(format!( @@ -47,7 +53,7 @@ impl Session { manager, }; - (instance, Some(Key::new(service_key))) + (instance, service_key) } pub fn path(&self) -> ObjectPath<'_> {