2023-02-06 22:53:37 +01:00
|
|
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
|
|
|
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
2023-06-06 22:34:53 +02:00
|
|
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
|
|
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
|
|
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
|
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
|
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
|
|
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
|
|
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
|
|
|
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
|
|
|
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2023-06-06 22:34:53 +02:00
|
|
|
import { BrowserApi } from "../platform/browser/browser-api";
|
2022-02-24 18:14:04 +01:00
|
|
|
|
2020-10-12 18:01:34 +02:00
|
|
|
import RuntimeBackground from "./runtime.background";
|
2020-10-09 17:16:15 +02:00
|
|
|
|
2020-10-16 11:09:49 +02:00
|
|
|
const MessageValidTimeout = 10 * 1000;
|
2020-10-19 12:20:45 +02:00
|
|
|
const EncryptionAlgorithm = "sha1";
|
2020-10-16 11:09:49 +02:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
type Message = {
|
|
|
|
command: string;
|
|
|
|
|
|
|
|
// Filled in by this service
|
|
|
|
userId?: string;
|
|
|
|
timestamp?: number;
|
|
|
|
|
|
|
|
// Used for sharing secret
|
|
|
|
publicKey?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
type OuterMessage = {
|
|
|
|
message: Message | EncString;
|
|
|
|
appId: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
type ReceiveMessage = {
|
|
|
|
timestamp: number;
|
|
|
|
command: string;
|
|
|
|
response?: any;
|
|
|
|
|
|
|
|
// Unlock key
|
|
|
|
keyB64?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
type ReceiveMessageOuter = {
|
|
|
|
command: string;
|
|
|
|
appId: string;
|
|
|
|
|
|
|
|
// Should only have one of these.
|
|
|
|
message?: EncString;
|
|
|
|
sharedSecret?: string;
|
|
|
|
};
|
|
|
|
|
2020-10-09 17:16:15 +02:00
|
|
|
export class NativeMessagingBackground {
|
|
|
|
private connected = false;
|
2020-10-21 15:56:10 +02:00
|
|
|
private connecting: boolean;
|
2020-10-09 17:16:15 +02:00
|
|
|
private port: browser.runtime.Port | chrome.runtime.Port;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2020-10-09 17:16:15 +02:00
|
|
|
private resolver: any = null;
|
2020-10-19 12:20:45 +02:00
|
|
|
private privateKey: ArrayBuffer = null;
|
2020-12-18 16:06:36 +01:00
|
|
|
private publicKey: ArrayBuffer = null;
|
2020-10-16 17:08:53 +02:00
|
|
|
private secureSetupResolve: any = null;
|
2020-10-19 12:20:45 +02:00
|
|
|
private sharedSecret: SymmetricCryptoKey;
|
2020-12-16 15:47:30 +01:00
|
|
|
private appId: string;
|
2021-01-13 23:31:44 +01:00
|
|
|
private validatingFingerprint: boolean;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2020-10-12 18:01:34 +02:00
|
|
|
constructor(
|
|
|
|
private cryptoService: CryptoService,
|
2020-10-16 17:08:53 +02:00
|
|
|
private cryptoFunctionService: CryptoFunctionService,
|
2020-10-19 16:50:25 +02:00
|
|
|
private runtimeBackground: RuntimeBackground,
|
|
|
|
private i18nService: I18nService,
|
2021-04-07 17:39:59 +02:00
|
|
|
private messagingService: MessagingService,
|
|
|
|
private appIdService: AppIdService,
|
2022-01-27 22:22:51 +01:00
|
|
|
private platformUtilsService: PlatformUtilsService,
|
|
|
|
private stateService: StateService,
|
2022-02-11 10:44:35 +01:00
|
|
|
private logService: LogService,
|
2022-05-01 23:57:40 +02:00
|
|
|
private authService: AuthService
|
2021-04-07 17:39:59 +02:00
|
|
|
) {
|
2022-01-27 22:22:51 +01:00
|
|
|
this.stateService.setBiometricFingerprintValidated(false);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-03-15 15:44:10 +01:00
|
|
|
if (chrome?.permissions?.onAdded) {
|
2021-01-29 23:31:36 +01:00
|
|
|
// Reload extension to activate nativeMessaging
|
2021-02-10 16:40:15 +01:00
|
|
|
chrome.permissions.onAdded.addListener((permissions) => {
|
2021-01-29 23:31:36 +01:00
|
|
|
BrowserApi.reloadExtension(null);
|
|
|
|
});
|
|
|
|
}
|
2021-01-13 23:31:44 +01:00
|
|
|
}
|
2020-10-12 18:01:34 +02:00
|
|
|
|
2020-10-21 15:56:10 +02:00
|
|
|
async connect() {
|
2020-12-16 15:47:30 +01:00
|
|
|
this.appId = await this.appIdService.getAppId();
|
2022-01-27 22:22:51 +01:00
|
|
|
this.stateService.setBiometricFingerprintValidated(false);
|
2020-12-16 15:47:30 +01:00
|
|
|
|
2021-04-07 17:39:59 +02:00
|
|
|
return new Promise<void>((resolve, reject) => {
|
2020-10-21 15:56:10 +02:00
|
|
|
this.port = BrowserApi.connectNative("com.8bit.bitwarden");
|
|
|
|
|
|
|
|
this.connecting = true;
|
|
|
|
|
2021-04-07 17:39:59 +02:00
|
|
|
const connectedCallback = () => {
|
|
|
|
this.connected = true;
|
|
|
|
this.connecting = false;
|
|
|
|
resolve();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Safari has a bundled native component which is always available, no need to
|
|
|
|
// check if the desktop app is running.
|
|
|
|
if (this.platformUtilsService.isSafari()) {
|
|
|
|
connectedCallback();
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
this.port.onMessage.addListener(async (message: ReceiveMessageOuter) => {
|
2020-10-21 17:18:04 +02:00
|
|
|
switch (message.command) {
|
|
|
|
case "connected":
|
2021-04-07 17:39:59 +02:00
|
|
|
connectedCallback();
|
2021-12-21 15:43:35 +01:00
|
|
|
break;
|
2020-10-21 17:18:04 +02:00
|
|
|
case "disconnected":
|
|
|
|
if (this.connecting) {
|
2022-03-15 13:13:39 +01:00
|
|
|
reject("startDesktop");
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2020-10-21 17:18:04 +02:00
|
|
|
this.connected = false;
|
|
|
|
this.port.disconnect();
|
2021-12-21 15:43:35 +01:00
|
|
|
break;
|
2022-02-24 18:14:04 +01:00
|
|
|
case "setupEncryption": {
|
2020-12-16 15:47:30 +01:00
|
|
|
// Ignore since it belongs to another device
|
|
|
|
if (message.appId !== this.appId) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return;
|
2021-04-07 17:39:59 +02:00
|
|
|
}
|
|
|
|
|
2020-10-21 17:18:04 +02:00
|
|
|
const encrypted = Utils.fromB64ToArray(message.sharedSecret);
|
|
|
|
const decrypted = await this.cryptoFunctionService.rsaDecrypt(
|
|
|
|
encrypted.buffer,
|
2020-10-23 14:40:50 +02:00
|
|
|
this.privateKey,
|
|
|
|
EncryptionAlgorithm
|
2020-12-16 15:47:30 +01:00
|
|
|
);
|
2020-10-21 15:56:10 +02:00
|
|
|
|
2020-10-21 19:23:27 +02:00
|
|
|
if (this.validatingFingerprint) {
|
2020-10-21 15:56:10 +02:00
|
|
|
this.validatingFingerprint = false;
|
2022-01-27 22:22:51 +01:00
|
|
|
this.stateService.setBiometricFingerprintValidated(true);
|
2020-10-21 15:56:10 +02:00
|
|
|
}
|
2020-10-23 14:40:50 +02:00
|
|
|
this.sharedSecret = new SymmetricCryptoKey(decrypted);
|
2020-10-21 15:56:10 +02:00
|
|
|
this.secureSetupResolve();
|
2021-12-21 15:43:35 +01:00
|
|
|
break;
|
2022-02-24 18:14:04 +01:00
|
|
|
}
|
2020-10-21 15:56:10 +02:00
|
|
|
case "invalidateEncryption":
|
2020-12-16 15:47:30 +01:00
|
|
|
// Ignore since it belongs to another device
|
2020-10-21 15:56:10 +02:00
|
|
|
if (message.appId !== this.appId) {
|
|
|
|
return;
|
2020-10-09 17:16:15 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 17:39:59 +02:00
|
|
|
this.sharedSecret = null;
|
|
|
|
this.privateKey = null;
|
|
|
|
this.connected = false;
|
|
|
|
|
2020-10-12 21:18:47 +02:00
|
|
|
this.messagingService.send("showDialog", {
|
2023-05-02 18:46:03 +02:00
|
|
|
title: { key: "nativeMessagingInvalidEncryptionTitle" },
|
|
|
|
content: { key: "nativeMessagingInvalidEncryptionDesc" },
|
|
|
|
acceptButtonText: { key: "ok" },
|
|
|
|
cancelButtonText: null,
|
|
|
|
type: "danger",
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
|
|
|
break;
|
2020-10-12 21:18:47 +02:00
|
|
|
case "verifyFingerprint": {
|
2020-10-09 17:16:15 +02:00
|
|
|
if (this.sharedSecret == null) {
|
2021-01-13 23:31:44 +01:00
|
|
|
this.validatingFingerprint = true;
|
2020-12-18 16:06:36 +01:00
|
|
|
this.showFingerprintDialog();
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-10-09 17:16:15 +02:00
|
|
|
case "wrongUserId":
|
2020-10-21 15:56:10 +02:00
|
|
|
this.showWrongUserDialog();
|
2022-02-24 18:14:04 +01:00
|
|
|
break;
|
2021-12-21 15:43:35 +01:00
|
|
|
default:
|
2020-10-21 15:56:10 +02:00
|
|
|
// Ignore since it belongs to another device
|
2021-04-07 17:39:59 +02:00
|
|
|
if (!this.platformUtilsService.isSafari() && message.appId !== this.appId) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-16 15:47:30 +01:00
|
|
|
this.onMessage(message.message);
|
2020-10-09 17:16:15 +02:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
2020-10-09 17:16:15 +02:00
|
|
|
|
2021-04-07 17:39:59 +02:00
|
|
|
this.port.onDisconnect.addListener((p: any) => {
|
2020-10-21 19:23:27 +02:00
|
|
|
let error;
|
2021-04-07 17:39:59 +02:00
|
|
|
if (BrowserApi.isWebExtensionsApi) {
|
|
|
|
error = p.error.message;
|
|
|
|
} else {
|
|
|
|
error = chrome.runtime.lastError.message;
|
|
|
|
}
|
|
|
|
|
2021-01-05 15:12:48 +01:00
|
|
|
this.sharedSecret = null;
|
2020-10-23 14:40:50 +02:00
|
|
|
this.privateKey = null;
|
2021-01-05 15:12:48 +01:00
|
|
|
this.connected = false;
|
2022-03-15 13:13:39 +01:00
|
|
|
|
|
|
|
const reason = error != null ? "desktopIntegrationDisabled" : null;
|
|
|
|
reject(reason);
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-07 17:39:59 +02:00
|
|
|
showWrongUserDialog() {
|
2021-01-05 15:12:48 +01:00
|
|
|
this.messagingService.send("showDialog", {
|
2023-05-02 18:46:03 +02:00
|
|
|
title: { key: "nativeMessagingWrongUserTitle" },
|
|
|
|
content: { key: "nativeMessagingWrongUserDesc" },
|
|
|
|
acceptButtonText: { key: "ok" },
|
|
|
|
cancelButtonText: null,
|
|
|
|
type: "danger",
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
async send(message: Message) {
|
2020-10-16 17:08:53 +02:00
|
|
|
if (!this.connected) {
|
2020-10-21 15:56:10 +02:00
|
|
|
await this.connect();
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2020-10-16 17:08:53 +02:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
message.userId = await this.stateService.getUserId();
|
|
|
|
message.timestamp = Date.now();
|
|
|
|
|
2020-10-12 21:18:47 +02:00
|
|
|
if (this.platformUtilsService.isSafari()) {
|
2022-01-27 22:22:51 +01:00
|
|
|
this.postMessage(message as any);
|
2021-04-07 17:39:59 +02:00
|
|
|
} else {
|
|
|
|
this.postMessage({ appId: this.appId, message: await this.encryptMessage(message) });
|
2020-10-09 17:16:15 +02:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2020-10-09 17:16:15 +02:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
async encryptMessage(message: Message) {
|
2020-10-09 17:16:15 +02:00
|
|
|
if (this.sharedSecret == null) {
|
|
|
|
await this.secureCommunication();
|
|
|
|
}
|
2020-10-12 18:01:34 +02:00
|
|
|
|
2021-04-07 17:39:59 +02:00
|
|
|
return await this.cryptoService.encrypt(JSON.stringify(message), this.sharedSecret);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2020-10-21 17:18:04 +02:00
|
|
|
getResponse(): Promise<any> {
|
2020-10-16 17:08:53 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
this.resolver = resolve;
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
private postMessage(message: OuterMessage) {
|
2021-01-05 15:12:48 +01:00
|
|
|
// Wrap in try-catch to when the port disconnected without triggering `onDisconnect`.
|
|
|
|
try {
|
2022-09-03 05:42:52 +02:00
|
|
|
const msg: any = message;
|
|
|
|
if (message.message instanceof EncString) {
|
|
|
|
// Alternative, backwards-compatible serialization of EncString
|
|
|
|
msg.message = {
|
|
|
|
encryptedString: message.message.encryptedString,
|
|
|
|
encryptionType: message.message.encryptionType,
|
|
|
|
data: message.message.data,
|
|
|
|
iv: message.message.iv,
|
|
|
|
mac: message.message.mac,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
this.port.postMessage(msg);
|
2021-01-05 15:12:48 +01:00
|
|
|
} catch (e) {
|
2022-01-27 22:22:51 +01:00
|
|
|
this.logService.error("NativeMessaging port disconnected, disconnecting.");
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-01-05 15:12:48 +01:00
|
|
|
this.sharedSecret = null;
|
|
|
|
this.privateKey = null;
|
|
|
|
this.connected = false;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-01-05 15:12:48 +01:00
|
|
|
this.messagingService.send("showDialog", {
|
2023-05-02 18:46:03 +02:00
|
|
|
title: { key: "nativeMessagingInvalidEncryptionTitle" },
|
|
|
|
content: { key: "nativeMessagingInvalidEncryptionDesc" },
|
|
|
|
acceptButtonText: { key: "ok" },
|
|
|
|
cancelButtonText: null,
|
|
|
|
type: "danger",
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-01-05 15:12:48 +01:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
private async onMessage(rawMessage: ReceiveMessage | EncString) {
|
|
|
|
let message = rawMessage as ReceiveMessage;
|
2021-04-07 17:39:59 +02:00
|
|
|
if (!this.platformUtilsService.isSafari()) {
|
2022-01-27 22:22:51 +01:00
|
|
|
message = JSON.parse(
|
|
|
|
await this.cryptoService.decryptToUtf8(rawMessage as EncString, this.sharedSecret)
|
|
|
|
);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2021-01-05 15:12:48 +01:00
|
|
|
|
|
|
|
if (Math.abs(message.timestamp - Date.now()) > MessageValidTimeout) {
|
2022-01-27 22:22:51 +01:00
|
|
|
this.logService.error("NativeMessage is to old, ignoring.");
|
2021-01-05 15:12:48 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-12 21:18:47 +02:00
|
|
|
switch (message.command) {
|
2022-02-24 18:14:04 +01:00
|
|
|
case "biometricUnlock": {
|
2022-01-27 22:22:51 +01:00
|
|
|
await this.stateService.setBiometricAwaitingAcceptance(null);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2020-12-16 17:32:51 +01:00
|
|
|
if (message.response === "not enabled") {
|
|
|
|
this.messagingService.send("showDialog", {
|
2023-05-02 18:46:03 +02:00
|
|
|
title: { key: "biometricsNotEnabledTitle" },
|
|
|
|
content: { key: "biometricsNotEnabledDesc" },
|
|
|
|
acceptButtonText: { key: "ok" },
|
|
|
|
cancelButtonText: null,
|
|
|
|
type: "danger",
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
|
|
|
break;
|
2021-04-07 17:39:59 +02:00
|
|
|
} else if (message.response === "not supported") {
|
|
|
|
this.messagingService.send("showDialog", {
|
2023-05-02 18:46:03 +02:00
|
|
|
title: { key: "biometricsNotSupportedTitle" },
|
|
|
|
content: { key: "biometricsNotSupportedDesc" },
|
|
|
|
acceptButtonText: { key: "ok" },
|
|
|
|
cancelButtonText: null,
|
|
|
|
type: "danger",
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
|
|
|
break;
|
2021-04-07 17:39:59 +02:00
|
|
|
}
|
2020-10-12 21:18:47 +02:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
const enabled = await this.stateService.getBiometricUnlock();
|
2020-10-16 11:09:49 +02:00
|
|
|
if (enabled === null || enabled === false) {
|
|
|
|
if (message.response === "unlocked") {
|
2022-01-27 22:22:51 +01:00
|
|
|
await this.stateService.setBiometricUnlock(true);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2020-10-12 21:18:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
// Ignore unlock if already unlocked
|
2022-05-01 23:57:40 +02:00
|
|
|
if ((await this.authService.getAuthStatus()) === AuthenticationStatus.Unlocked) {
|
2021-04-07 17:39:59 +02:00
|
|
|
break;
|
2020-10-12 18:01:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (message.response === "unlocked") {
|
|
|
|
await this.cryptoService.setKey(
|
2020-10-12 21:18:47 +02:00
|
|
|
new SymmetricCryptoKey(Utils.fromB64ToArray(message.keyB64).buffer)
|
|
|
|
);
|
2020-10-16 17:08:53 +02:00
|
|
|
|
|
|
|
// Verify key is correct by attempting to decrypt a secret
|
|
|
|
try {
|
2022-01-27 22:22:51 +01:00
|
|
|
await this.cryptoService.getFingerprint(await this.stateService.getUserId());
|
2020-10-21 17:18:04 +02:00
|
|
|
} catch (e) {
|
2022-01-27 22:22:51 +01:00
|
|
|
this.logService.error("Unable to verify key: " + e);
|
2020-12-18 16:06:36 +01:00
|
|
|
await this.cryptoService.clearKey();
|
2020-10-21 17:18:04 +02:00
|
|
|
this.showWrongUserDialog();
|
2020-10-16 17:08:53 +02:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
// Exit early
|
|
|
|
if (this.resolver) {
|
|
|
|
this.resolver(message);
|
|
|
|
}
|
|
|
|
return;
|
2021-01-15 16:44:27 +01:00
|
|
|
}
|
2020-10-16 17:08:53 +02:00
|
|
|
|
|
|
|
this.runtimeBackground.processMessage({ command: "unlocked" }, null, null);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2020-10-16 17:08:53 +02:00
|
|
|
break;
|
2022-02-24 18:14:04 +01:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
default:
|
2022-01-27 22:22:51 +01:00
|
|
|
this.logService.error("NativeMessage, got unknown command: " + message.command);
|
2022-02-24 18:14:04 +01:00
|
|
|
break;
|
2020-10-16 17:08:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.resolver) {
|
2020-10-21 15:56:10 +02:00
|
|
|
this.resolver(message);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2020-10-16 17:08:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private async secureCommunication() {
|
|
|
|
const [publicKey, privateKey] = await this.cryptoFunctionService.rsaGenerateKeyPair(2048);
|
2020-12-18 16:06:36 +01:00
|
|
|
this.publicKey = publicKey;
|
2020-10-21 17:18:04 +02:00
|
|
|
this.privateKey = privateKey;
|
2020-10-16 17:08:53 +02:00
|
|
|
|
2021-01-05 15:12:48 +01:00
|
|
|
this.sendUnencrypted({
|
|
|
|
command: "setupEncryption",
|
2021-01-15 16:44:27 +01:00
|
|
|
publicKey: Utils.fromBufferToB64(publicKey),
|
2022-01-27 22:22:51 +01:00
|
|
|
userId: await this.stateService.getUserId(),
|
2021-01-05 15:12:48 +01:00
|
|
|
});
|
2020-12-18 16:06:36 +01:00
|
|
|
|
|
|
|
return new Promise((resolve, reject) => (this.secureSetupResolve = resolve));
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2020-12-18 16:06:36 +01:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
private async sendUnencrypted(message: Message) {
|
2020-12-18 16:06:36 +01:00
|
|
|
if (!this.connected) {
|
|
|
|
await this.connect();
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2020-10-16 17:08:53 +02:00
|
|
|
message.timestamp = Date.now();
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-04-07 17:39:59 +02:00
|
|
|
this.postMessage({ appId: this.appId, message: message });
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:06:36 +01:00
|
|
|
private async showFingerprintDialog() {
|
|
|
|
const fingerprint = (
|
2022-01-27 22:22:51 +01:00
|
|
|
await this.cryptoService.getFingerprint(await this.stateService.getUserId(), this.publicKey)
|
2021-12-21 15:43:35 +01:00
|
|
|
).join(" ");
|
|
|
|
|
2023-05-02 18:46:03 +02:00
|
|
|
this.messagingService.send("showNativeMessagingFinterprintDialog", {
|
|
|
|
fingerprint: fingerprint,
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
|
|
|
}
|
2020-10-09 17:16:15 +02:00
|
|
|
}
|