1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-03 18:28:13 +01:00

[PM-3687] Remove ipcRenderer from native-messaging (#6893)

This commit is contained in:
Daniel García 2023-11-21 16:40:43 +01:00 committed by GitHub
parent f6c2e0b6c0
commit 1ecf019397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 11 deletions

View File

@ -1,8 +1,14 @@
import { ipcRenderer } from "electron"; import { ipcRenderer } from "electron";
import { DeviceType, ThemeType, KeySuffixOptions } from "@bitwarden/common/enums"; import { DeviceType, ThemeType, KeySuffixOptions } from "@bitwarden/common/enums";
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
import { EncryptedMessageResponse, UnencryptedMessageResponse } from "../models/native-messaging"; import {
EncryptedMessageResponse,
LegacyMessageWrapper,
Message,
UnencryptedMessageResponse,
} from "../models/native-messaging";
import { BiometricMessage, BiometricAction } from "../types/biometric-message"; import { BiometricMessage, BiometricAction } from "../types/biometric-message";
import { isDev, isWindowsStore } from "../utils"; import { isDev, isWindowsStore } from "../utils";
@ -56,6 +62,17 @@ const nativeMessaging = {
sendReply: (message: EncryptedMessageResponse | UnencryptedMessageResponse) => { sendReply: (message: EncryptedMessageResponse | UnencryptedMessageResponse) => {
ipcRenderer.send("nativeMessagingReply", message); ipcRenderer.send("nativeMessagingReply", message);
}, },
sendMessage: (message: {
appId: string;
command?: string;
sharedSecret?: string;
message?: EncString;
}) => {
ipcRenderer.send("nativeMessagingReply", message);
},
onMessage: (callback: (message: LegacyMessageWrapper | Message) => void) => {
ipcRenderer.on("nativeMessaging", (_event, message) => callback(message));
},
}; };
export default { export default {

View File

@ -1,5 +1,4 @@
import { Injectable, NgZone } from "@angular/core"; import { Injectable, NgZone } from "@angular/core";
import { ipcRenderer } from "electron";
import { firstValueFrom } from "rxjs"; import { firstValueFrom } from "rxjs";
import { KeySuffixOptions } from "@bitwarden/common/enums"; import { KeySuffixOptions } from "@bitwarden/common/enums";
@ -43,9 +42,7 @@ export class NativeMessagingService {
) {} ) {}
init() { init() {
ipcRenderer.on("nativeMessaging", async (_event: any, message: any) => { ipc.platform.nativeMessaging.onMessage((message) => this.messageHandler(message));
this.messageHandler(message);
});
} }
private async messageHandler(msg: LegacyMessageWrapper | Message) { private async messageHandler(msg: LegacyMessageWrapper | Message) {
@ -65,12 +62,18 @@ export class NativeMessagingService {
const accounts = await firstValueFrom(this.stateService.accounts$); const accounts = await firstValueFrom(this.stateService.accounts$);
const userIds = Object.keys(accounts); const userIds = Object.keys(accounts);
if (!userIds.includes(rawMessage.userId)) { if (!userIds.includes(rawMessage.userId)) {
ipcRenderer.send("nativeMessagingReply", { command: "wrongUserId", appId: appId }); ipc.platform.nativeMessaging.sendMessage({
command: "wrongUserId",
appId: appId,
});
return; return;
} }
if (await this.stateService.getEnableBrowserIntegrationFingerprint()) { if (await this.stateService.getEnableBrowserIntegrationFingerprint()) {
ipcRenderer.send("nativeMessagingReply", { command: "verifyFingerprint", appId: appId }); ipc.platform.nativeMessaging.sendMessage({
command: "verifyFingerprint",
appId: appId,
});
const fingerprint = await this.cryptoService.getFingerprint( const fingerprint = await this.cryptoService.getFingerprint(
await this.stateService.getUserId(), await this.stateService.getUserId(),
@ -95,7 +98,10 @@ export class NativeMessagingService {
} }
if (this.sharedSecrets.get(appId) == null) { if (this.sharedSecrets.get(appId) == null) {
ipcRenderer.send("nativeMessagingReply", { command: "invalidateEncryption", appId: appId }); ipc.platform.nativeMessaging.sendMessage({
command: "invalidateEncryption",
appId: appId,
});
return; return;
} }
@ -105,7 +111,10 @@ export class NativeMessagingService {
// Shared secret is invalidated, force re-authentication // Shared secret is invalidated, force re-authentication
if (message == null) { if (message == null) {
ipcRenderer.send("nativeMessagingReply", { command: "invalidateEncryption", appId: appId }); ipc.platform.nativeMessaging.sendMessage({
command: "invalidateEncryption",
appId: appId,
});
return; return;
} }
@ -174,7 +183,7 @@ export class NativeMessagingService {
this.sharedSecrets.get(appId) this.sharedSecrets.get(appId)
); );
ipcRenderer.send("nativeMessagingReply", { appId: appId, message: encrypted }); ipc.platform.nativeMessaging.sendMessage({ appId: appId, message: encrypted });
} }
private async secureCommunication(remotePublicKey: Uint8Array, appId: string) { private async secureCommunication(remotePublicKey: Uint8Array, appId: string) {
@ -186,7 +195,7 @@ export class NativeMessagingService {
remotePublicKey, remotePublicKey,
EncryptionAlgorithm EncryptionAlgorithm
); );
ipcRenderer.send("nativeMessagingReply", { ipc.platform.nativeMessaging.sendMessage({
appId: appId, appId: appId,
command: "setupEncryption", command: "setupEncryption",
sharedSecret: Utils.fromBufferToB64(encryptedSecret), sharedSecret: Utils.fromBufferToB64(encryptedSecret),