Skip to content

Commit

Permalink
Ps/pm-8003/handle-dekstop-invalidated-message-encryption (#9181)
Browse files Browse the repository at this point in the history
* Do not initialize symmetric crypto keys with null

* Require new message on invalid native message encryption

Handling of this error is to require the user to retry, so the promise needs to resolve.
  • Loading branch information
MGibson1 committed May 15, 2024
1 parent b14bb92 commit 426bacf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions apps/browser/src/background/nativeMessaging.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ export class NativeMessagingBackground {
cancelButtonText: null,
type: "danger",
});

if (this.resolver) {
this.resolver(message);
}

break;
case "verifyFingerprint": {
if (this.sharedSecret == null) {
Expand Down
9 changes: 7 additions & 2 deletions apps/desktop/src/platform/services/electron-crypto.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export class ElectronCryptoService extends CryptoService {
if (keySuffix === KeySuffixOptions.Biometric) {
await this.migrateBiometricKeyIfNeeded(userId);
const userKey = await this.stateService.getUserKeyBiometric({ userId: userId });
return new SymmetricCryptoKey(Utils.fromB64ToArray(userKey)) as UserKey;
return userKey == null
? null
: (new SymmetricCryptoKey(Utils.fromB64ToArray(userKey)) as UserKey);
}
return await super.getKeyFromStorage(keySuffix, userId);
}
Expand Down Expand Up @@ -169,7 +171,9 @@ export class ElectronCryptoService extends CryptoService {
// decrypt
const masterKey = new SymmetricCryptoKey(Utils.fromB64ToArray(oldBiometricKey)) as MasterKey;
userId ??= (await firstValueFrom(this.accountService.activeAccount$))?.id;
const encUserKeyPrim = await this.stateService.getEncryptedCryptoSymmetricKey();
const encUserKeyPrim = await this.stateService.getEncryptedCryptoSymmetricKey({
userId: userId,
});
const encUserKey =
encUserKeyPrim != null
? new EncString(encUserKeyPrim)
Expand All @@ -180,6 +184,7 @@ export class ElectronCryptoService extends CryptoService {
const userKey = await this.masterPasswordService.decryptUserKeyWithMasterKey(
masterKey,
encUserKey,
userId,
);
// migrate
await this.storeBiometricKey(userKey, userId);
Expand Down

0 comments on commit 426bacf

Please sign in to comment.