diff --git a/apps/desktop/desktop_native/core/Cargo.toml b/apps/desktop/desktop_native/core/Cargo.toml index 72bddf1262f..046a658fb1f 100644 --- a/apps/desktop/desktop_native/core/Cargo.toml +++ b/apps/desktop/desktop_native/core/Cargo.toml @@ -65,15 +65,16 @@ sysinfo = { version = "0.32.0", features = ["windows"] } [target.'cfg(windows)'.dependencies] widestring = { version = "=1.1.0", optional = true } windows = { version = "=0.57.0", features = [ - "Foundation", - "Security_Credentials_UI", - "Security_Cryptography", - "Storage_Streams", - "Win32_Foundation", - "Win32_Security_Credentials", - "Win32_System_WinRT", - "Win32_UI_Input_KeyboardAndMouse", - "Win32_UI_WindowsAndMessaging", + "Foundation", + "Security_Credentials_UI", + "Security_Cryptography", + "Storage_Streams", + "Win32_Foundation", + "Win32_Security_Credentials", + "Win32_System_WinRT", + "Win32_UI_Input_KeyboardAndMouse", + "Win32_UI_WindowsAndMessaging", + "Win32_System_Pipes", ], optional = true } [target.'cfg(windows)'.dev-dependencies] diff --git a/apps/desktop/desktop_native/core/src/ssh_agent/mod.rs b/apps/desktop/desktop_native/core/src/ssh_agent/mod.rs index b826cb0d512..e201b49f6d4 100644 --- a/apps/desktop/desktop_native/core/src/ssh_agent/mod.rs +++ b/apps/desktop/desktop_native/core/src/ssh_agent/mod.rs @@ -10,9 +10,12 @@ use bitwarden_russh::ssh_agent::{self, Key}; #[cfg_attr(target_os = "linux", path = "unix.rs")] mod platform_ssh_agent; +#[cfg(target_os="linux")] +#[cfg(target_os="macos")] +mod peercred_unix_listener_stream; + pub mod generator; pub mod importer; -mod peercred_unix_listener_stream; pub mod peerinfo; #[derive(Clone)] pub struct BitwardenDesktopAgent { @@ -32,8 +35,9 @@ impl BitwardenDesktopAgent { } impl ssh_agent::Agent for BitwardenDesktopAgent { - async fn confirm(&self, ssh_key: Key, _info: &peerinfo::models::PeerInfo) -> bool { + async fn confirm(&self, ssh_key: Key, info: &peerinfo::models::PeerInfo) -> bool { let request_id = self.get_request_id().await; + println!("[SSH Agent] Confirming request from application: {}", info.process_name()); let mut rx_channel = self.get_ui_response_rx.lock().await.resubscribe(); self.show_ui_request_tx diff --git a/apps/desktop/desktop_native/core/src/ssh_agent/named_pipe_listener_stream.rs b/apps/desktop/desktop_native/core/src/ssh_agent/named_pipe_listener_stream.rs index e50498b200d..098c0a3b9f0 100644 --- a/apps/desktop/desktop_native/core/src/ssh_agent/named_pipe_listener_stream.rs +++ b/apps/desktop/desktop_native/core/src/ssh_agent/named_pipe_listener_stream.rs @@ -3,16 +3,16 @@ use std::{ pin::Pin, task::{Context, Poll}, }; - +use std::os::windows::prelude::AsRawHandle as _; use futures::Stream; use tokio::{ net::windows::named_pipe::{NamedPipeServer, ServerOptions}, select, }; use tokio_util::sync::CancellationToken; +use windows::Win32::{Foundation::HANDLE, System::Pipes::GetNamedPipeClientProcessId}; -use super::peerinfo; -use super::peerinfo::models::PeerInfo; +use crate::ssh_agent::peerinfo::{self, models::PeerInfo}; const PIPE_NAME: &str = r"\\.\pipe\openssh-ssh-agent"; @@ -40,7 +40,29 @@ impl NamedPipeServerStream { } _ = listener.connect() => { println!("[SSH Agent Native Module] Incoming connection"); - tx.send(listener).await.unwrap(); + + let handle = HANDLE(listener.as_raw_handle() as isize); + let mut pid = 0; + unsafe { + match GetNamedPipeClientProcessId(handle, &mut pid) { + Err(e) => { + println!("Error getting named pipe client process id {}", e); + continue + }, + Ok(_) => {} + } + }; + + let peer_info = peerinfo::gather::get_peer_info(pid as u32); + let peer_info = match peer_info { + Err(err) => { + println!("Failed getting process info for pid {} {}", pid, err); + continue + }, + Ok(info) => info, + }; + + tx.send((listener, peer_info)).await.unwrap(); listener = ServerOptions::new().create(PIPE_NAME).unwrap(); } }