1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-12 06:23:38 +00:00

Fix chromium paths, hard linking instead of copying, add logs

This commit is contained in:
Bernd Schoolmann
2025-05-30 15:28:14 +02:00
parent 6a785575b9
commit afa0aa9c56
4 changed files with 30 additions and 13 deletions

View File

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

View File

@@ -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::<GenericFilePath>()?;
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();

View File

@@ -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:?}"
))
})?;

View File

@@ -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/`,
};
}