mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-25 12:15:18 +01:00
[PM-1674] let node-ipc use individual pipes on Windows (#4020)
* let node-ipc use individual pipes on Windows This fixes an issue with multiple users on Windows. There should be an individual Windows pipe used for communication between browser plugin and desktop for each user. However, the naming scheme used the same name for every user. This change adds some uniqueness with a hash over username and unique directory name. * Fix ipc socket root for native-messaging too * use only homedir as unique
This commit is contained in:
parent
8d34bc9ad9
commit
1f026da924
@ -6,6 +6,7 @@ import * as util from "util";
|
|||||||
|
|
||||||
import { ipcMain } from "electron";
|
import { ipcMain } from "electron";
|
||||||
import * as ipc from "node-ipc";
|
import * as ipc from "node-ipc";
|
||||||
|
import { getIpcSocketRoot } from "../proxy/ipc";
|
||||||
|
|
||||||
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
||||||
|
|
||||||
@ -25,11 +26,9 @@ export class NativeMessagingMain {
|
|||||||
async listen() {
|
async listen() {
|
||||||
ipc.config.id = "bitwarden";
|
ipc.config.id = "bitwarden";
|
||||||
ipc.config.retry = 1500;
|
ipc.config.retry = 1500;
|
||||||
if (process.platform === "darwin") {
|
const ipcSocketRoot = getIpcSocketRoot();
|
||||||
if (!existsSync(`${homedir()}/tmp`)) {
|
if (ipcSocketRoot != null) {
|
||||||
await fs.mkdir(`${homedir()}/tmp`);
|
ipc.config.socketRoot = ipcSocketRoot;
|
||||||
}
|
|
||||||
ipc.config.socketRoot = `${homedir()}/tmp/`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ipc.serve(() => {
|
ipc.serve(() => {
|
||||||
|
@ -1,13 +1,38 @@
|
|||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
|
import { createHash } from "crypto";
|
||||||
|
import { existsSync, mkdirSync } from "fs";
|
||||||
import { homedir } from "os";
|
import { homedir } from "os";
|
||||||
|
import { join as path_join } from "path";
|
||||||
|
|
||||||
import * as ipc from "node-ipc";
|
import * as ipc from "node-ipc";
|
||||||
|
|
||||||
|
export function getIpcSocketRoot(): string | null {
|
||||||
|
let socketRoot = null;
|
||||||
|
|
||||||
|
switch (process.platform) {
|
||||||
|
case "darwin": {
|
||||||
|
const ipcSocketRootDir = path_join(homedir(), "tmp");
|
||||||
|
if (!existsSync(ipcSocketRootDir)) {
|
||||||
|
mkdirSync(ipcSocketRootDir);
|
||||||
|
}
|
||||||
|
socketRoot = ipcSocketRootDir + "/";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "win32": {
|
||||||
|
// Let node-ipc use a unique IPC pipe //./pipe/xxxxxxxxxxxxxxxxx.app.bitwarden per user.
|
||||||
|
// Hashing prevents problems with reserved characters and file length limitations.
|
||||||
|
socketRoot = createHash("sha1").update(homedir()).digest("hex") + ".";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return socketRoot;
|
||||||
|
}
|
||||||
|
|
||||||
ipc.config.id = "proxy";
|
ipc.config.id = "proxy";
|
||||||
ipc.config.retry = 1500;
|
ipc.config.retry = 1500;
|
||||||
ipc.config.logger = console.warn; // Stdout is used for native messaging
|
ipc.config.logger = console.warn; // Stdout is used for native messaging
|
||||||
if (process.platform === "darwin") {
|
const ipcSocketRoot = getIpcSocketRoot();
|
||||||
ipc.config.socketRoot = `${homedir()}/tmp/`;
|
if (ipcSocketRoot != null) {
|
||||||
|
ipc.config.socketRoot = ipcSocketRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class IPC {
|
export default class IPC {
|
||||||
|
Loading…
Reference in New Issue
Block a user