mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 17:23:37 +00:00
Show fingerprint message
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { ipcRenderer } from 'electron';
|
||||
import Swal from 'sweetalert2';
|
||||
|
||||
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
||||
import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service';
|
||||
@@ -6,16 +7,17 @@ import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { LogService } from 'jslib/abstractions/log.service';
|
||||
import { Utils } from 'jslib/misc/utils';
|
||||
import { SymmetricCryptoKey } from 'jslib/models/domain/symmetricCryptoKey';
|
||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||
import { UserService } from 'jslib/abstractions/user.service';
|
||||
|
||||
const MessageValidTimeout = 10 * 1000;
|
||||
const EncryptionAlgorithm = 'sha1';
|
||||
|
||||
export class NativeMessagingService {
|
||||
private remotePublicKey: ArrayBuffer;
|
||||
private sharedSecret: any;
|
||||
|
||||
constructor(private cryptoFunctionService: CryptoFunctionService, private cryptoService: CryptoService,
|
||||
private platformUtilService: PlatformUtilsService, private logService: LogService) {
|
||||
private platformUtilService: PlatformUtilsService, private logService: LogService, private i18nService: I18nService, private userService: UserService) {
|
||||
ipcRenderer.on('nativeMessaging', async (event: any, message: any) => {
|
||||
this.messageHandler(message);
|
||||
});
|
||||
@@ -23,8 +25,24 @@ export class NativeMessagingService {
|
||||
|
||||
private async messageHandler(rawMessage: any) {
|
||||
if (rawMessage.command == 'setupEncryption') {
|
||||
this.remotePublicKey = Utils.fromB64ToArray(rawMessage.publicKey).buffer;
|
||||
this.secureCommunication();
|
||||
const remotePublicKey = Utils.fromB64ToArray(rawMessage.publicKey).buffer;
|
||||
const fingerprint = (await this.cryptoService.getFingerprint(await this.userService.getUserId(), remotePublicKey)).join(' ');
|
||||
|
||||
const submitted = await Swal.fire({
|
||||
title: this.i18nService.t('verifyBrowserTitle'),
|
||||
html: `${this.i18nService.t('verifyBrowserDescription')}<br><br><strong>${fingerprint}</strong>`,
|
||||
showCancelButton: true,
|
||||
cancelButtonText: this.i18nService.t('cancel'),
|
||||
showConfirmButton: true,
|
||||
confirmButtonText: this.i18nService.t('approve'),
|
||||
allowOutsideClick: false,
|
||||
});
|
||||
|
||||
if (submitted.value !== true) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.secureCommunication(remotePublicKey);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -64,11 +82,11 @@ export class NativeMessagingService {
|
||||
ipcRenderer.send('nativeMessagingReply', encrypted);
|
||||
}
|
||||
|
||||
private async secureCommunication() {
|
||||
private async secureCommunication(remotePublicKey: ArrayBuffer) {
|
||||
const secret = await this.cryptoFunctionService.randomBytes(64);
|
||||
this.sharedSecret = new SymmetricCryptoKey(secret);
|
||||
|
||||
const encryptedSecret = await this.cryptoFunctionService.rsaEncrypt(secret, this.remotePublicKey, EncryptionAlgorithm);
|
||||
const encryptedSecret = await this.cryptoFunctionService.rsaEncrypt(secret, remotePublicKey, EncryptionAlgorithm);
|
||||
ipcRenderer.send('nativeMessagingReply', {command: 'setupEncryption', sharedSecret: Utils.fromBufferToB64(encryptedSecret)});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user