1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

PM-5001 - WebAuthn-Login.strategy - set user key should set the master key encrypted user key if it exists so that the passkey authN + MP decryption flow can work. (#6978)

This commit is contained in:
Jared Snider
2023-11-27 13:33:15 -05:00
committed by GitHub
parent aac4177a6c
commit 687ec0c4c0
2 changed files with 12 additions and 1 deletions

View File

@@ -179,7 +179,11 @@ describe("WebAuthnLoginStrategy", () => {
// Act
await webAuthnLoginStrategy.logIn(webAuthnCredentials);
// // Assert
// Assert
// Master key encrypted user key should be set
expect(cryptoService.setMasterKeyEncryptedUserKey).toHaveBeenCalledTimes(1);
expect(cryptoService.setMasterKeyEncryptedUserKey).toHaveBeenCalledWith(idTokenResponse.key);
expect(cryptoService.decryptToBytes).toHaveBeenCalledTimes(1);
expect(cryptoService.decryptToBytes).toHaveBeenCalledWith(
idTokenResponse.userDecryptionOptions.webAuthnPrfOption.encryptedPrivateKey,

View File

@@ -15,6 +15,13 @@ export class WebAuthnLoginStrategy extends LoginStrategy {
}
protected override async setUserKey(idTokenResponse: IdentityTokenResponse) {
const masterKeyEncryptedUserKey = idTokenResponse.key;
if (masterKeyEncryptedUserKey) {
// set the master key encrypted user key if it exists
await this.cryptoService.setMasterKeyEncryptedUserKey(masterKeyEncryptedUserKey);
}
const userDecryptionOptions = idTokenResponse?.userDecryptionOptions;
if (userDecryptionOptions?.webAuthnPrfOption) {