1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

Merge branch 'master' into Permissions

This commit is contained in:
addison
2021-01-12 18:51:36 -05:00
11 changed files with 86 additions and 30 deletions

View File

@@ -115,9 +115,7 @@ export class NativeMessagingBackground {
error = chrome.runtime.lastError.message;
}
if (error === 'Specified native messaging host not found.' ||
error === 'Access to the specified native messaging host is forbidden.' ||
error === 'An unexpected error occurred') {
if (error != null) {
this.messagingService.send('showDialog', {
text: this.i18nService.t('desktopIntegrationDisabledDesc'),
title: this.i18nService.t('desktopIntegrationDisabledTitle'),
@@ -145,7 +143,7 @@ export class NativeMessagingBackground {
message.timestamp = Date.now();
const encrypted = await this.cryptoService.encrypt(JSON.stringify(message), this.sharedSecret);
this.port.postMessage({appId: this.appId, message: encrypted});
this.postMessage({appId: this.appId, message: encrypted});
}
getResponse(): Promise<any> {
@@ -154,6 +152,27 @@ export class NativeMessagingBackground {
});
}
private postMessage(message: any) {
// Wrap in try-catch to when the port disconnected without triggering `onDisconnect`.
try {
this.port.postMessage(message);
} catch (e) {
// tslint:disable-next-line
console.error("NativeMessaging port disconnected, disconnecting.");
this.sharedSecret = null;
this.privateKey = null;
this.connected = false;
this.messagingService.send('showDialog', {
text: this.i18nService.t('nativeMessagingInvalidEncryptionDesc'),
title: this.i18nService.t('nativeMessagingInvalidEncryptionTitle'),
confirmText: this.i18nService.t('ok'),
type: 'error',
});
}
}
private async onMessage(rawMessage: any) {
const message = JSON.parse(await this.cryptoService.decryptToUtf8(rawMessage, this.sharedSecret));
@@ -231,7 +250,7 @@ export class NativeMessagingBackground {
message.timestamp = Date.now();
this.port.postMessage({appId: this.appId, message: message});
this.postMessage({appId: this.appId, message: message});
}
private async showFingerprintDialog() {