1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-09-27 03:53:00 +02:00

Wire up desktop -> browser communication. Add initial biometry support for browser integration

This commit is contained in:
Hinton 2020-10-11 20:41:10 +02:00
parent 45302e5bd5
commit c80b538674
5 changed files with 38 additions and 11 deletions

View File

@ -15,6 +15,8 @@ class Proxy {
run() {
this.ipc.connect();
this.nativeMessage.listen();
this.ipc.onMessage = this.nativeMessage.send;
}
}

View File

@ -7,6 +7,7 @@ ipc.config.logger = console.warn; // Stdout is used for native messaging
export default class IPC {
private connected = false;
public onMessage: (message: object) => void
connect() {
ipc.connectTo('bitwarden', () => {
@ -24,8 +25,8 @@ export default class IPC {
console.error('disconnected from world');
});
ipc.of.bitwarden.on('message', (data: any) => {
console.error('got a message from world : ', data);
ipc.of.bitwarden.on('message', (message: any) => {
this.onMessage(message);
});
/*

View File

@ -61,7 +61,6 @@ export default class NativeMessage {
flushChunksQueue();
const json = JSON.parse(contentWithoutSize);
console.error(json);
// Forward to desktop application
this.ipc.send(json);

View File

@ -119,7 +119,7 @@ export class Main {
this.biometricMain = new BiometricDarwinMain(this.storageService, this.i18nService);
}
this.nativeMessagingService = new NativeMessagingService(this.logService, app.getPath('userData'), app.getAppPath());
this.nativeMessagingService = new NativeMessagingService(this.logService, this.biometricMain, app.getPath('userData'), app.getAppPath());
}
bootstrap() {

View File

@ -4,11 +4,12 @@ import * as path from 'path';
import * as util from 'util';
import { LogService } from 'jslib/abstractions/log.service';
import { BiometricMain } from 'jslib/abstractions/biometric.main';
export class NativeMessagingService {
private connected = false;
constructor(private logService: LogService, private userPath: string, private appPath: string) {}
constructor(private logService: LogService, private biometricMain: BiometricMain, private userPath: string, private appPath: string) {}
listen() {
ipc.config.id = 'bitwarden';
@ -16,8 +17,7 @@ export class NativeMessagingService {
ipc.serve(() => {
ipc.server.on('message', (data: any, socket: any) => {
ipc.log('got a message : ', data);
ipc.server.emit(socket, 'message', data + ' world!');
this.messageHandler(data, socket);
});
ipc.server.on('connect', () => {
@ -42,6 +42,10 @@ export class NativeMessagingService {
ipc.server.stop();
}
send(message: object, socket: any) {
ipc.server.emit(socket, 'message', message);
}
generateManifests() {
const baseJson = {
'name': 'com.8bit.bitwarden',
@ -163,7 +167,7 @@ export class NativeMessagingService {
const obj: any = {};
obj[location] = {
'default': {
value: path.join(this.userPath, 'browsers', jsonFile),
value: jsonFile,
type: 'REG_DEFAULT',
},
}
@ -175,18 +179,39 @@ export class NativeMessagingService {
}
private async deleteWindowsRegistry(key: string) {
const regedit = require("regedit");
const regedit = require('regedit');
const list = util.promisify(regedit.list);
const deleteKey = util.promisify(regedit.deleteKey);
this.logService.debug(`Removing registry: ${location}`)
this.logService.debug(`Removing registry: ${key}`)
try {
await list(key);
await deleteKey(key);
await deleteKey(key);
} catch {
// Do nothing
}
}
private async messageHandler(message: any, socket: any) {
switch (message.command) {
case 'biometricUnlock':
if (! this.biometricMain) {
return this.send({command: 'biometricUnlock', response: 'not supported'}, socket)
}
const response = await this.biometricMain.requestCreate();
if (response) {
this.send({command: 'biometricUnlock', response: 'unlocked'}, socket);
} else {
this.send({command: 'biometricUnlock', response: 'canceled'}, socket);
}
break;
default:
console.error("UNKNOWN COMMAND")
}
}
}