1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

[PM-8933] Require userId on setUserKey (#9675)

* Updated all sets of user key to pass in userId

* Added userId on auth request login.

* Fixed tests.

* Fixed tests to pass in UserId

* Added parameter to tests.

* Addressed PR feedback.

* Merged main
This commit is contained in:
Todd Martin
2024-08-13 08:07:36 -04:00
committed by GitHub
parent cdc82f13b0
commit 7b508b1ad7
15 changed files with 65 additions and 39 deletions

View File

@@ -1067,7 +1067,6 @@ export default class MainBackground {
this.messagingService,
this.appIdService,
this.platformUtilsService,
this.stateService,
this.logService,
this.authService,
this.biometricStateService,

View File

@@ -9,7 +9,6 @@ import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.se
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 { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
@@ -79,7 +78,6 @@ export class NativeMessagingBackground {
private messagingService: MessagingService,
private appIdService: AppIdService,
private platformUtilsService: PlatformUtilsService,
private stateService: StateService,
private logService: LogService,
private authService: AuthService,
private biometricStateService: BiometricStateService,
@@ -214,7 +212,7 @@ export class NativeMessagingBackground {
await this.connect();
}
message.userId = await this.stateService.getUserId();
message.userId = (await firstValueFrom(this.accountService.activeAccount$))?.id;
message.timestamp = Date.now();
if (this.platformUtilsService.isSafari()) {
@@ -367,13 +365,14 @@ export class NativeMessagingBackground {
const [publicKey, privateKey] = await this.cryptoFunctionService.rsaGenerateKeyPair(2048);
this.publicKey = publicKey;
this.privateKey = privateKey;
const userId = (await firstValueFrom(this.accountService.activeAccount$))?.id;
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.sendUnencrypted({
command: "setupEncryption",
publicKey: Utils.fromBufferToB64(publicKey),
userId: await this.stateService.getUserId(),
userId: userId,
});
return new Promise((resolve, reject) => (this.secureSetupResolve = resolve));
@@ -391,7 +390,7 @@ export class NativeMessagingBackground {
private async showFingerprintDialog() {
const fingerprint = await this.cryptoService.getFingerprint(
await this.stateService.getUserId(),
(await firstValueFrom(this.accountService.activeAccount$))?.id,
this.publicKey,
);

View File

@@ -69,7 +69,7 @@ export class UnlockCommand {
}
const userKey = await this.masterPasswordService.decryptUserKeyWithMasterKey(masterKey);
await this.cryptoService.setUserKey(userKey);
await this.cryptoService.setUserKey(userKey, userId);
if (await this.keyConnectorService.getConvertAccountRequired()) {
const convertToKeyConnectorCommand = new ConvertToKeyConnectorCommand(

View File

@@ -69,7 +69,7 @@ export class ElectronCryptoService extends CryptoService {
await super.clearStoredUserKey(keySuffix, userId);
}
protected override async storeAdditionalKeys(key: UserKey, userId?: UserId) {
protected override async storeAdditionalKeys(key: UserKey, userId: UserId) {
await super.storeAdditionalKeys(key, userId);
const storeBiometricKey = await this.shouldStoreKey(KeySuffixOptions.Biometric, userId);