1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-12-28 17:18:24 +01:00

Disconnect active connections when closing native messaging. Fix exe path on windows (#865)

This commit is contained in:
Oscar Hinton 2021-05-03 09:59:40 +02:00 committed by GitHub
parent 163fa2aa41
commit 20b8a83dd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 14 deletions

9
package-lock.json generated
View File

@ -1139,6 +1139,15 @@
"@types/node": "*"
}
},
"@types/node-ipc": {
"version": "9.1.3",
"resolved": "https://registry.npmjs.org/@types/node-ipc/-/node-ipc-9.1.3.tgz",
"integrity": "sha512-ka7CPX9Dk2lwe4PxoZMLOwcQrtdcYe/7OKmH75fQbmt0jdKltWVkdGA81D5l55d0wNhkweHa3XmzFbt5C0ieOQ==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/normalize-package-data": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz",

View File

@ -251,6 +251,7 @@
"@types/lunr": "^2.3.3",
"@types/node": "^10.17.58",
"@types/node-forge": "^0.9.7",
"@types/node-ipc": "^9.1.3",
"@types/papaparse": "^5.2.0",
"@types/webcrypto": "^0.0.28",
"@types/webpack": "^4.4.27",

4
src/global.d.ts vendored
View File

@ -1,6 +1,2 @@
declare function escape(s: string): string;
declare function unescape(s: string): string;
declare module 'node-ipc' {
const x: any;
export = x;
}

View File

@ -1,4 +1,5 @@
import { existsSync, promises as fs } from 'fs';
import { Socket } from 'net';
import * as ipc from 'node-ipc';
import { homedir, userInfo } from 'os';
import * as path from 'path';
@ -9,7 +10,7 @@ import { LogService } from 'jslib/abstractions/log.service';
import { WindowMain } from 'jslib/electron/window.main';
export class NativeMessagingMain {
private connected = false;
private connected: Socket[] = [];
private socket: any;
constructor(private logService: LogService, private windowMain: WindowMain, private userPath: string, private exePath: string) {}
@ -36,14 +37,18 @@ export class NativeMessagingMain {
}
});
ipc.server.on('connect', () => {
this.connected = true;
ipc.server.on('connect', (socket: Socket) => {
this.connected.push(socket);
});
ipc.server.on(
'socket.disconnected',
(socket: any, destroyedSocketID: any) => {
this.connected = false;
(socket, destroyedSocketID) => {
const index = this.connected.indexOf(socket);
if (index > -1) {
this.connected.splice(index, 1);
}
this.socket = null;
ipc.log(
'client ' + destroyedSocketID + ' has disconnected!'
@ -57,6 +62,12 @@ export class NativeMessagingMain {
stop() {
ipc.server.stop();
// Kill all existing connections
this.connected.forEach(socket => {
if (!socket.destroyed) {
socket.destroy();
}
});
}
send(message: object, socket: any) {
@ -184,7 +195,7 @@ export class NativeMessagingMain {
private binaryPath() {
if (process.platform === 'win32') {
return path.join(path.basename(this.exePath), 'resources', 'native-messaging.bat');
return path.join(path.dirname(this.exePath), 'resources', 'native-messaging.bat');
}
return this.exePath;

View File

@ -18,10 +18,7 @@ export default class IPC {
ipc.connectTo('bitwarden', () => {
ipc.of.bitwarden.on('connect', () => {
this.connected = true;
console.error(
'## connected to bitwarden desktop ##',
ipc.config.delay
);
console.error('## connected to bitwarden desktop ##');
// Notify browser extension, connection is established to desktop application.
this.onMessage({command: 'connected'});