diff --git a/apps/desktop/desktop_native/ssh_agent/src/knownhosts/mod.rs b/apps/desktop/desktop_native/ssh_agent/src/knownhosts/mod.rs index f7e431b51f1..0c19362bbc0 100644 --- a/apps/desktop/desktop_native/ssh_agent/src/knownhosts/mod.rs +++ b/apps/desktop/desktop_native/ssh_agent/src/knownhosts/mod.rs @@ -85,18 +85,6 @@ impl KnownHostsReader { Ok(entries) } - - /// Finds host entries by hostname pattern - pub fn find_host(entries: &[KnownHostEntry], hostname: &str) -> Option { - entries - .iter() - .find(|entry| { - entry.hostname.split(',').any(|h| { - h == hostname || h == "*" || h.starts_with("*.") && hostname.ends_with(&h[1..]) - }) - }) - .cloned() - } } #[cfg(test)] diff --git a/apps/desktop/desktop_native/ssh_agent/src/protocol/agent_listener.rs b/apps/desktop/desktop_native/ssh_agent/src/protocol/agent_listener.rs index baecd65cf17..740bf8f5de8 100644 --- a/apps/desktop/desktop_native/ssh_agent/src/protocol/agent_listener.rs +++ b/apps/desktop/desktop_native/ssh_agent/src/protocol/agent_listener.rs @@ -72,7 +72,7 @@ async fn handle_connection( }; let response = match request { - Request::IdentitiesRequest => { + Request::Identities => { span.in_scope(|| info!("Received IdentitiesRequest")); let Ok(true) = agent.request_can_list(connection).await else { @@ -86,7 +86,7 @@ async fn handle_connection( .encode() .map_err(|e| anyhow::anyhow!("Failed to encode identities reply: {e}")) } - Request::SignRequest(sign_request) => { + Request::Sign(sign_request) => { span.in_scope(|| info!("Received SignRequest {:?}", sign_request)); let Ok(true) = agent @@ -115,7 +115,7 @@ async fn handle_connection( } .map_err(|e| anyhow::anyhow!("Failed to create sign reply: {e}")) } - Request::SessionBindRequest(request) => { + Request::SessionBind(request) => { span.in_scope(|| info!("Received SessionBind {:?}", request)); connection.set_host_key(request.host_key().clone()); info!( diff --git a/apps/desktop/desktop_native/ssh_agent/src/protocol/requests.rs b/apps/desktop/desktop_native/ssh_agent/src/protocol/requests.rs index 052d8f7c522..cfebf19538e 100644 --- a/apps/desktop/desktop_native/ssh_agent/src/protocol/requests.rs +++ b/apps/desktop/desktop_native/ssh_agent/src/protocol/requests.rs @@ -47,11 +47,11 @@ pub(crate) enum SshSignFlags { #[derive(Debug)] pub(crate) enum Request { /// Request the list of keys the agent is holding - IdentitiesRequest, + Identities, /// Sign an authentication request or SSHSIG request - SignRequest(SshSignRequest), + Sign(SshSignRequest), /// Session bind request - SessionBindRequest(SessionBindRequest), + SessionBind(SessionBindRequest), } impl TryFrom<&[u8]> for Request { @@ -74,9 +74,9 @@ impl TryFrom<&[u8]> for Request { let contents = message[1..].to_vec(); match r#type { - RequestType::SSH_AGENTC_REQUEST_IDENTITIES => Ok(Request::IdentitiesRequest), + RequestType::SSH_AGENTC_REQUEST_IDENTITIES => Ok(Request::Identities), RequestType::SSH_AGENTC_SIGN_REQUEST => { - Ok(Request::SignRequest(contents.as_slice().try_into()?)) + Ok(Request::Sign(contents.as_slice().try_into()?)) } RequestType::SSH_AGENTC_EXTENSION => { // Only support session bind for now @@ -85,7 +85,7 @@ impl TryFrom<&[u8]> for Request { info!("Invalid session bind signature"); return Err(anyhow::anyhow!("Invalid session bind signature")); } - Ok(Request::SessionBindRequest(extension_request)) + Ok(Request::SessionBind(extension_request)) } _ => Err(anyhow::anyhow!("Unsupported request type: {:?}", r#type)), } @@ -355,13 +355,13 @@ mod tests { #[test] fn test_parse_identities_request() { let req = Request::try_from(TEST_VECTOR_REQUEST_LIST).expect("Should parse"); - assert!(matches!(req, Request::IdentitiesRequest)); + assert!(matches!(req, Request::Identities)); } #[test] fn test_parse_sign_request() { let req = Request::try_from(TEST_VECTOR_REQUEST_SIGN).expect("Should parse"); - assert!(matches!(req, Request::SignRequest { .. })); + assert!(matches!(req, Request::Sign { .. })); } #[test] diff --git a/apps/desktop/desktop_native/ssh_agent/src/protocol/types.rs b/apps/desktop/desktop_native/ssh_agent/src/protocol/types.rs index 244020d1267..966885b8c88 100644 --- a/apps/desktop/desktop_native/ssh_agent/src/protocol/types.rs +++ b/apps/desktop/desktop_native/ssh_agent/src/protocol/types.rs @@ -1,4 +1,5 @@ use std::fmt::Debug; +use std::fmt::Display; use std::fmt::Formatter; use base64::prelude::BASE64_STANDARD; @@ -334,13 +335,15 @@ impl PublicKey { let blob = read_bytes(&mut bytes)?; Ok(PublicKey { alg, blob }) } +} - fn to_string(&self) -> String { +impl Display for PublicKey { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let mut buf = Vec::new(); - self.alg().as_bytes().encode(&mut buf).unwrap(); - self.blob().encode(&mut buf).unwrap(); - let buf_b64 = BASE64_STANDARD.encode(&buf); - format!("{} {}", self.alg(), buf_b64) + // Failure to encode is ignored + let _ = self.alg().as_bytes().encode(&mut buf); + let _ = self.blob().encode(&mut buf); + write!(f, "{}", BASE64_STANDARD.encode(&buf)) } } @@ -377,7 +380,7 @@ impl TryFrom for PublicKey { impl Debug for PublicKey { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "SshPublicKey(\"{}\")", self.to_string()) + write!(f, "SshPublicKey(\"{}\")", self) } }