mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-01 13:13:36 +01:00
ed4d481e4d
* Revert "Remove unnecessary plist keys in desktop_proxy (#10933)" This reverts commit4dbb036df1
. * Revert "Fix TestFlight errors caused by desktop_proxy (#10928)" This reverts commit40cb4b5353
. * Revert "[PM-5506] Enable electron fuses (#10073)" This reverts commit78c5e9c706
. * Revert "[PM-7846] Implement a rust based native messaging proxy and IPC system (#9894)" This reverts commit55874b72bf
.
79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
/* eslint-disable no-console */
|
|
import { createHash } from "crypto";
|
|
import { existsSync, mkdirSync } from "fs";
|
|
import { homedir } from "os";
|
|
import { join as path_join } from "path";
|
|
|
|
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.retry = 1500;
|
|
ipc.config.logger = console.warn; // Stdout is used for native messaging
|
|
const ipcSocketRoot = getIpcSocketRoot();
|
|
if (ipcSocketRoot != null) {
|
|
ipc.config.socketRoot = ipcSocketRoot;
|
|
}
|
|
|
|
export default class IPC {
|
|
onMessage: (message: object) => void;
|
|
|
|
private connected = false;
|
|
|
|
connect() {
|
|
ipc.connectTo("bitwarden", () => {
|
|
ipc.of.bitwarden.on("connect", () => {
|
|
this.connected = true;
|
|
console.error("## connected to bitwarden desktop ##");
|
|
|
|
// Notify browser extension, connection is established to desktop application.
|
|
this.onMessage({ command: "connected" });
|
|
});
|
|
|
|
ipc.of.bitwarden.on("disconnect", () => {
|
|
this.connected = false;
|
|
console.error("disconnected from world");
|
|
|
|
// Notify browser extension, no connection to desktop application.
|
|
this.onMessage({ command: "disconnected" });
|
|
});
|
|
|
|
ipc.of.bitwarden.on("message", (message: any) => {
|
|
this.onMessage(message);
|
|
});
|
|
|
|
ipc.of.bitwarden.on("error", (err: any) => {
|
|
console.error("error", err);
|
|
});
|
|
});
|
|
}
|
|
|
|
isConnected(): boolean {
|
|
return this.connected;
|
|
}
|
|
|
|
send(json: object) {
|
|
ipc.of.bitwarden.emit("message", json);
|
|
}
|
|
}
|