mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
[PM-3687] Remove ipcRenderer from native-messaging (#6893)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { Injectable, NgZone } from "@angular/core";
|
||||
import { ipcRenderer } from "electron";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { KeySuffixOptions } from "@bitwarden/common/enums";
|
||||
@@ -43,9 +42,7 @@ export class NativeMessagingService {
|
||||
) {}
|
||||
|
||||
init() {
|
||||
ipcRenderer.on("nativeMessaging", async (_event: any, message: any) => {
|
||||
this.messageHandler(message);
|
||||
});
|
||||
ipc.platform.nativeMessaging.onMessage((message) => this.messageHandler(message));
|
||||
}
|
||||
|
||||
private async messageHandler(msg: LegacyMessageWrapper | Message) {
|
||||
@@ -65,12 +62,18 @@ export class NativeMessagingService {
|
||||
const accounts = await firstValueFrom(this.stateService.accounts$);
|
||||
const userIds = Object.keys(accounts);
|
||||
if (!userIds.includes(rawMessage.userId)) {
|
||||
ipcRenderer.send("nativeMessagingReply", { command: "wrongUserId", appId: appId });
|
||||
ipc.platform.nativeMessaging.sendMessage({
|
||||
command: "wrongUserId",
|
||||
appId: appId,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
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(
|
||||
await this.stateService.getUserId(),
|
||||
@@ -95,7 +98,10 @@ export class NativeMessagingService {
|
||||
}
|
||||
|
||||
if (this.sharedSecrets.get(appId) == null) {
|
||||
ipcRenderer.send("nativeMessagingReply", { command: "invalidateEncryption", appId: appId });
|
||||
ipc.platform.nativeMessaging.sendMessage({
|
||||
command: "invalidateEncryption",
|
||||
appId: appId,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -105,7 +111,10 @@ export class NativeMessagingService {
|
||||
|
||||
// Shared secret is invalidated, force re-authentication
|
||||
if (message == null) {
|
||||
ipcRenderer.send("nativeMessagingReply", { command: "invalidateEncryption", appId: appId });
|
||||
ipc.platform.nativeMessaging.sendMessage({
|
||||
command: "invalidateEncryption",
|
||||
appId: appId,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -174,7 +183,7 @@ export class NativeMessagingService {
|
||||
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) {
|
||||
@@ -186,7 +195,7 @@ export class NativeMessagingService {
|
||||
remotePublicKey,
|
||||
EncryptionAlgorithm
|
||||
);
|
||||
ipcRenderer.send("nativeMessagingReply", {
|
||||
ipc.platform.nativeMessaging.sendMessage({
|
||||
appId: appId,
|
||||
command: "setupEncryption",
|
||||
sharedSecret: Utils.fromBufferToB64(encryptedSecret),
|
||||
|
||||
Reference in New Issue
Block a user