mirror of
https://github.com/bitwarden/desktop.git
synced 2025-01-07 18:58:37 +01:00
Wire up desktop -> browser communication. Add initial biometry support for browser integration
This commit is contained in:
parent
45302e5bd5
commit
c80b538674
@ -15,6 +15,8 @@ class Proxy {
|
|||||||
run() {
|
run() {
|
||||||
this.ipc.connect();
|
this.ipc.connect();
|
||||||
this.nativeMessage.listen();
|
this.nativeMessage.listen();
|
||||||
|
|
||||||
|
this.ipc.onMessage = this.nativeMessage.send;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ ipc.config.logger = console.warn; // Stdout is used for native messaging
|
|||||||
|
|
||||||
export default class IPC {
|
export default class IPC {
|
||||||
private connected = false;
|
private connected = false;
|
||||||
|
public onMessage: (message: object) => void
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
ipc.connectTo('bitwarden', () => {
|
ipc.connectTo('bitwarden', () => {
|
||||||
@ -24,8 +25,8 @@ export default class IPC {
|
|||||||
console.error('disconnected from world');
|
console.error('disconnected from world');
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc.of.bitwarden.on('message', (data: any) => {
|
ipc.of.bitwarden.on('message', (message: any) => {
|
||||||
console.error('got a message from world : ', data);
|
this.onMessage(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -61,7 +61,6 @@ export default class NativeMessage {
|
|||||||
flushChunksQueue();
|
flushChunksQueue();
|
||||||
|
|
||||||
const json = JSON.parse(contentWithoutSize);
|
const json = JSON.parse(contentWithoutSize);
|
||||||
console.error(json);
|
|
||||||
|
|
||||||
// Forward to desktop application
|
// Forward to desktop application
|
||||||
this.ipc.send(json);
|
this.ipc.send(json);
|
||||||
|
@ -119,7 +119,7 @@ export class Main {
|
|||||||
this.biometricMain = new BiometricDarwinMain(this.storageService, this.i18nService);
|
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() {
|
bootstrap() {
|
||||||
|
@ -4,11 +4,12 @@ import * as path from 'path';
|
|||||||
import * as util from 'util';
|
import * as util from 'util';
|
||||||
|
|
||||||
import { LogService } from 'jslib/abstractions/log.service';
|
import { LogService } from 'jslib/abstractions/log.service';
|
||||||
|
import { BiometricMain } from 'jslib/abstractions/biometric.main';
|
||||||
|
|
||||||
export class NativeMessagingService {
|
export class NativeMessagingService {
|
||||||
private connected = false;
|
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() {
|
listen() {
|
||||||
ipc.config.id = 'bitwarden';
|
ipc.config.id = 'bitwarden';
|
||||||
@ -16,8 +17,7 @@ export class NativeMessagingService {
|
|||||||
|
|
||||||
ipc.serve(() => {
|
ipc.serve(() => {
|
||||||
ipc.server.on('message', (data: any, socket: any) => {
|
ipc.server.on('message', (data: any, socket: any) => {
|
||||||
ipc.log('got a message : ', data);
|
this.messageHandler(data, socket);
|
||||||
ipc.server.emit(socket, 'message', data + ' world!');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc.server.on('connect', () => {
|
ipc.server.on('connect', () => {
|
||||||
@ -42,6 +42,10 @@ export class NativeMessagingService {
|
|||||||
ipc.server.stop();
|
ipc.server.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
send(message: object, socket: any) {
|
||||||
|
ipc.server.emit(socket, 'message', message);
|
||||||
|
}
|
||||||
|
|
||||||
generateManifests() {
|
generateManifests() {
|
||||||
const baseJson = {
|
const baseJson = {
|
||||||
'name': 'com.8bit.bitwarden',
|
'name': 'com.8bit.bitwarden',
|
||||||
@ -163,7 +167,7 @@ export class NativeMessagingService {
|
|||||||
const obj: any = {};
|
const obj: any = {};
|
||||||
obj[location] = {
|
obj[location] = {
|
||||||
'default': {
|
'default': {
|
||||||
value: path.join(this.userPath, 'browsers', jsonFile),
|
value: jsonFile,
|
||||||
type: 'REG_DEFAULT',
|
type: 'REG_DEFAULT',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -175,18 +179,39 @@ export class NativeMessagingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async deleteWindowsRegistry(key: string) {
|
private async deleteWindowsRegistry(key: string) {
|
||||||
const regedit = require("regedit");
|
const regedit = require('regedit');
|
||||||
|
|
||||||
const list = util.promisify(regedit.list);
|
const list = util.promisify(regedit.list);
|
||||||
const deleteKey = util.promisify(regedit.deleteKey);
|
const deleteKey = util.promisify(regedit.deleteKey);
|
||||||
|
|
||||||
this.logService.debug(`Removing registry: ${location}`)
|
this.logService.debug(`Removing registry: ${key}`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await list(key);
|
await list(key);
|
||||||
await deleteKey(key);
|
await deleteKey(key);
|
||||||
} catch {
|
} catch {
|
||||||
// Do nothing
|
// 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user