1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-12 14:34:02 +00:00

Add procinfo for windows

This commit is contained in:
Bernd Schoolmann
2024-11-20 03:55:14 -08:00
parent 624e19c691
commit ac0ea3c60f
3 changed files with 42 additions and 15 deletions

View File

@@ -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]

View File

@@ -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<peerinfo::models::PeerInfo> 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

View File

@@ -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();
}
}