diff --git a/apps/desktop/desktop_native/core/src/ipc/mod.rs b/apps/desktop/desktop_native/core/src/ipc/mod.rs index d568e136445..7152e16bc4a 100644 --- a/apps/desktop/desktop_native/core/src/ipc/mod.rs +++ b/apps/desktop/desktop_native/core/src/ipc/mod.rs @@ -24,9 +24,9 @@ pub const MESSAGE_CHANNEL_BUFFER: usize = 32; #[cfg(target_os = "linux")] pub const FLATPAK_PATHS: [&str; 4] = [ "org.mozilla.firefox/.mozilla/native-messaging-hosts", - "com.google.Chrome/.config/google-chrome/NativeMessagingHosts", - "org.chromium.Chromium/.config/chromium/NativeMessagingHosts", - "com.microsoft.Edge/.config/microsoft-edge/NativeMessagingHosts", + "com.google.Chrome/config/google-chrome/NativeMessagingHosts", + "org.chromium.Chromium/config/chromium/NativeMessagingHosts", + "com.microsoft.Edge/config/microsoft-edge/NativeMessagingHosts", ]; /// This is the codec used for communication through the UNIX socket / Windows named pipe. diff --git a/apps/desktop/desktop_native/core/src/ipc/server.rs b/apps/desktop/desktop_native/core/src/ipc/server.rs index e1ed3bcb90f..b623b4d30f9 100644 --- a/apps/desktop/desktop_native/core/src/ipc/server.rs +++ b/apps/desktop/desktop_native/core/src/ipc/server.rs @@ -58,12 +58,16 @@ impl Server { // If the unix socket file already exists, we get an error when trying to bind to it. So we remove it first. // Any processes that were using the old socket should remain connected to it but any new connections will use the new socket. if !cfg!(windows) && path.exists() { + println!("Removing existing IPC socket at: {}", path.display()); std::fs::remove_file(path)?; } let name = path.as_os_str().to_fs_name::()?; let opts = ListenerOptions::new().name(name); - let listener = opts.create_tokio()?; + let Ok(listener) = opts.create_tokio() else { + println!("Failed to create IPC listener for path: {}", path.display()); + continue; + }; let client_to_server_send = client_to_server_send.clone(); let server_to_clients_recv = server_to_clients_recv.resubscribe(); diff --git a/apps/desktop/desktop_native/napi/src/lib.rs b/apps/desktop/desktop_native/napi/src/lib.rs index c60b3ac8f88..26274b562a6 100644 --- a/apps/desktop/desktop_native/napi/src/lib.rs +++ b/apps/desktop/desktop_native/napi/src/lib.rs @@ -441,7 +441,7 @@ pub mod ipc { let server = desktop_core::ipc::server::Server::start(path.clone(), send).map_err(|e| { napi::Error::from_reason(format!( - "Error listening to server - Path: {path:?} - Error: {e} - {e:?}" + "Error listening to server - Paths: {path:?} - Error: {e} - {e:?}" )) })?; diff --git a/apps/desktop/src/main/native-messaging.main.ts b/apps/desktop/src/main/native-messaging.main.ts index fb93c9e41ec..240be749459 100644 --- a/apps/desktop/src/main/native-messaging.main.ts +++ b/apps/desktop/src/main/native-messaging.main.ts @@ -212,8 +212,13 @@ export class NativeMessagingMain { const browserBinaryPath = path.join(nhmsPath, ".bitwarden_desktop_proxy"); await fs.mkdir(nhmsPath, { recursive: true }); - await fs.copyFile(binaryPath, browserBinaryPath); - this.logService.info(`Copied ${binaryPath} to ${browserBinaryPath}`); + if (existsSync(browserBinaryPath)) { + await fs.unlink(browserBinaryPath); + } + await fs.link(binaryPath, browserBinaryPath); + this.logService.info( + `[Native messaging] Hard-linked ${binaryPath} to ${browserBinaryPath}`, + ); if (key === "Firefox") { await this.writeManifest( @@ -233,10 +238,13 @@ export class NativeMessagingMain { for (const [key, value] of Object.entries(this.getFlatpakNMHS())) { if (existsSync(value)) { - const sandboxedProxyBinaryPath = path.join(value, "bitwarden_desktop_proxy"); - await fs.copyFile(binaryPath, path.join(value, ".bitwarden_desktop_proxy")); + const sandboxedProxyBinaryPath = path.join(value, ".bitwarden_desktop_proxy"); + if (existsSync(sandboxedProxyBinaryPath)) { + await fs.unlink(sandboxedProxyBinaryPath); + } + await fs.link(binaryPath, path.join(value, ".bitwarden_desktop_proxy")); this.logService.info( - `Copied ${sandboxedProxyBinaryPath} to ${path.join(value, "bitwarden_desktop_proxy")}`, + `[Native messaging] Hard-linked ${binaryPath} to ${sandboxedProxyBinaryPath}`, ); if (key === "Firefox") { @@ -244,6 +252,11 @@ export class NativeMessagingMain { path.join(value, "com.8bit.bitwarden.json"), await this.generateFirefoxJson(sandboxedProxyBinaryPath), ); + } else if (key === "Chrome" || key === "Chromium" || key === "Microsoft Edge") { + await this.writeManifest( + path.join(value, "com.8bit.bitwarden.json"), + await this.generateChromeJson(sandboxedProxyBinaryPath), + ); } else { this.logService.warning(`Flatpak ${key} not supported, skipping.`); } @@ -386,9 +399,9 @@ export class NativeMessagingMain { private getFlatpakNMHS() { return { Firefox: `${this.homedir()}/.var/app/org.mozilla.firefox/.mozilla/native-messaging-hosts/`, - Chrome: `${this.homedir()}/.var/app/com.google.Chrome/.config/google-chrome/`, - Chromium: `${this.homedir()}/.var/app/org.chromium.Chromium/.config/chromium/`, - "Microsoft Edge": `${this.homedir()}/.var/app/com.microsoft.Edge/.config/microsoft-edge/`, + Chrome: `${this.homedir()}/.var/app/com.google.Chrome/config/google-chrome/NativeMessagingHosts/`, + Chromium: `${this.homedir()}/.var/app/org.chromium.Chromium/config/chromium/NativeMessagingHosts/`, + "Microsoft Edge": `${this.homedir()}/.var/app/com.microsoft.Edge/config/microsoft-edge/NativeMessagingHosts/`, }; }