1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-21 11:53:34 +00:00

[PM-30846] Fix incorrect log for private key regen in data recovery tool (#18356)

* Fix no log

* Fix prettier
This commit is contained in:
Bernd Schoolmann
2026-01-16 10:24:57 +01:00
committed by GitHub
parent 7150283d7c
commit d410706b45
3 changed files with 16 additions and 7 deletions

View File

@@ -85,9 +85,14 @@ export class PrivateKeyStep implements RecoveryStep {
}
logger.record("Replacing private key");
await this.privateKeyRegenerationService.regenerateUserPublicKeyEncryptionKeyPair(
workingData.userId!,
);
logger.record("Private key replaced successfully");
const recovered =
await this.privateKeyRegenerationService.regenerateUserPublicKeyEncryptionKeyPair(
workingData.userId!,
);
if (!recovered) {
logger.record("Private key replacement could not be performed");
} else {
logger.record("Private key replacement replaced successfully");
}
}
}

View File

@@ -12,6 +12,8 @@ export abstract class UserAsymmetricKeysRegenerationService {
* Performs the regeneration of the user's public/private key pair without checking any preconditions.
* This should only be used for V1 encryption accounts
* @param userId The user id.
* @returns True if regeneration was performed, false otherwise.
* @throws An error if the regeneration could not be attempted due to missing state
*/
abstract regenerateUserPublicKeyEncryptionKeyPair(userId: UserId): Promise<void>;
abstract regenerateUserPublicKeyEncryptionKeyPair(userId: UserId): Promise<boolean>;
}

View File

@@ -123,7 +123,7 @@ export class DefaultUserAsymmetricKeysRegenerationService implements UserAsymmet
return false;
}
async regenerateUserPublicKeyEncryptionKeyPair(userId: UserId): Promise<void> {
async regenerateUserPublicKeyEncryptionKeyPair(userId: UserId): Promise<boolean> {
const userKey = await firstValueFrom(this.keyService.userKey$(userId));
if (userKey == null) {
throw new Error("User key not found");
@@ -152,19 +152,21 @@ export class DefaultUserAsymmetricKeysRegenerationService implements UserAsymmet
this.logService.info(
"[UserAsymmetricKeyRegeneration] Regeneration not supported for this user at this time.",
);
return false;
} else {
this.logService.error(
"[UserAsymmetricKeyRegeneration] Regeneration error when submitting the request to the server: " +
error,
);
return false;
}
return;
}
await this.keyService.setPrivateKey(makeKeyPairResponse.userKeyEncryptedPrivateKey, userId);
this.logService.info(
"[UserAsymmetricKeyRegeneration] User's asymmetric keys successfully regenerated.",
);
return true;
}
private async userKeyCanDecrypt(userKey: UserKey, userId: UserId): Promise<boolean> {