mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-28 12:45:45 +01:00
wip
This commit is contained in:
parent
d83e2bc117
commit
74b51c9a6c
@ -129,7 +129,7 @@ const environmentService = new EnvironmentService(apiService, storageService, no
|
|||||||
const eventService = new EventService(storageService, apiService, userService, cipherService);
|
const eventService = new EventService(storageService, apiService, userService, cipherService);
|
||||||
const systemService = new SystemService(storageService, vaultTimeoutService, messagingService, platformUtilsService,
|
const systemService = new SystemService(storageService, vaultTimeoutService, messagingService, platformUtilsService,
|
||||||
null);
|
null);
|
||||||
const nativeMessagingService = new NativeMessagingService(cryptoService, platformUtilsService, logService);
|
const nativeMessagingService = new NativeMessagingService(cryptoFunctionService, cryptoService, platformUtilsService, logService);
|
||||||
|
|
||||||
const analytics = new Analytics(window, () => isDev(), platformUtilsService, storageService, appIdService);
|
const analytics = new Analytics(window, () => isDev(), platformUtilsService, storageService, appIdService);
|
||||||
containerService.attachToGlobal(window);
|
containerService.attachToGlobal(window);
|
||||||
|
@ -1,22 +1,36 @@
|
|||||||
import { ipcRenderer } from 'electron';
|
import { ipcRenderer } from 'electron';
|
||||||
|
|
||||||
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
||||||
|
import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service';
|
||||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||||
import { LogService } from 'jslib/abstractions/log.service';
|
import { LogService } from 'jslib/abstractions/log.service';
|
||||||
|
import { Utils } from 'jslib/misc/utils';
|
||||||
|
|
||||||
const MessageValidTimeout = 10 * 1000;
|
const MessageValidTimeout = 10 * 1000;
|
||||||
|
const EncryptionAlgorithm = 'sha256';
|
||||||
|
|
||||||
export class NativeMessagingService {
|
export class NativeMessagingService {
|
||||||
|
private publicKey: ArrayBuffer;
|
||||||
|
private privateKey: ArrayBuffer;
|
||||||
|
private remotePublicKey: ArrayBuffer;
|
||||||
|
|
||||||
constructor(private cryptoService: CryptoService, private platformUtilService: PlatformUtilsService, private logService: LogService) {
|
constructor(private cryptoFunctionService: CryptoFunctionService, private cryptoService: CryptoService,
|
||||||
|
private platformUtilService: PlatformUtilsService, private logService: LogService) {
|
||||||
ipcRenderer.on('nativeMessaging', async (event: any, message: any) => {
|
ipcRenderer.on('nativeMessaging', async (event: any, message: any) => {
|
||||||
this.messageHandler(message);
|
this.messageHandler(message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async messageHandler(rawMessage: any) {
|
private async messageHandler(rawMessage: any) {
|
||||||
const message = JSON.parse(await this.cryptoService.decryptToUtf8(rawMessage));
|
if (rawMessage.command == 'setupEncryption') {
|
||||||
|
this.remotePublicKey = Utils.fromB64ToArray(rawMessage.publicKey).buffer;
|
||||||
|
this.secureCommunication();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
debugger;
|
||||||
|
const message = JSON.parse(Utils.fromBufferToUtf8(await this.cryptoFunctionService.rsaDecrypt(rawMessage, this.privateKey, EncryptionAlgorithm)));
|
||||||
|
console.log(message);
|
||||||
if (Math.abs(message.timestamp - Date.now()) > MessageValidTimeout) {
|
if (Math.abs(message.timestamp - Date.now()) > MessageValidTimeout) {
|
||||||
this.logService.error('NativeMessage is to old, ignoring.');
|
this.logService.error('NativeMessage is to old, ignoring.');
|
||||||
return;
|
return;
|
||||||
@ -44,8 +58,14 @@ export class NativeMessagingService {
|
|||||||
|
|
||||||
private async send(message: any) {
|
private async send(message: any) {
|
||||||
message.timestamp = Date.now();
|
message.timestamp = Date.now();
|
||||||
const encrypted = await this.cryptoService.encrypt(JSON.stringify(message));
|
const encrypted = await this.cryptoFunctionService.rsaEncrypt(Utils.fromUtf8ToArray(JSON.stringify(message)), this.remotePublicKey, EncryptionAlgorithm);
|
||||||
|
|
||||||
ipcRenderer.send('nativeMessagingReply', encrypted);
|
ipcRenderer.send('nativeMessagingReply', encrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async secureCommunication() {
|
||||||
|
[this.publicKey, this.privateKey] = await this.cryptoFunctionService.rsaGenerateKeyPair(2048);
|
||||||
|
|
||||||
|
this.send({command: 'setupEncryption', publicKey: Utils.fromBufferToB64(this.publicKey)});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user