mirror of
https://github.com/bitwarden/browser
synced 2025-12-21 02:33:46 +00:00
[PM-24745] Decrypt ciphers using decryptManyWithFailures from SDK (#16190)
* Add SDK call to decryptManyWithFailures instead of decryptMany * Move logic back to decryptCiphersWithSdk * Fix return type of decryptCiphersWithSdk * Add unit tests for decryptCiphers() * Add unit tests for decryptManyWithFailures * Filter out undefined objects from failedCiphers * Update name for failed-decryption ciphers * Fix type checking errors in tests * Fix tests with new changes from main * Migrate decryptMany call to use decryptManyWithFailures * Remove deprecated decryptMany function, along with all calls ot the function
This commit is contained in:
@@ -158,11 +158,9 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
),
|
||||
),
|
||||
switchMap(async (ciphers) => {
|
||||
// TODO: remove this once failed decrypted ciphers are handled in the SDK
|
||||
await this.setFailedDecryptedCiphers([], userId);
|
||||
return this.cipherEncryptionService
|
||||
.decryptMany(ciphers, userId)
|
||||
.then((ciphers) => ciphers.sort(this.getLocaleSortingFunction()));
|
||||
const [decrypted, failures] = await this.decryptCiphersWithSdk(ciphers, userId);
|
||||
await this.setFailedDecryptedCiphers(failures, userId);
|
||||
return decrypted.sort(this.getLocaleSortingFunction());
|
||||
}),
|
||||
);
|
||||
}),
|
||||
@@ -489,14 +487,14 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
): Promise<[CipherView[], CipherView[]] | null> {
|
||||
if (await this.configService.getFeatureFlag(FeatureFlag.PM19941MigrateCipherDomainToSdk)) {
|
||||
const decryptStartTime = performance.now();
|
||||
const decrypted = await this.decryptCiphersWithSdk(ciphers, userId);
|
||||
|
||||
const result = await this.decryptCiphersWithSdk(ciphers, userId);
|
||||
|
||||
this.logService.measure(decryptStartTime, "Vault", "CipherService", "decrypt complete", [
|
||||
["Items", ciphers.length],
|
||||
]);
|
||||
|
||||
// With SDK, failed ciphers are not returned
|
||||
return [decrypted, []];
|
||||
return result;
|
||||
}
|
||||
|
||||
const keys = await firstValueFrom(this.keyService.cipherDecryptionKeys$(userId));
|
||||
@@ -2034,10 +2032,23 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
* @returns The decrypted ciphers.
|
||||
* @private
|
||||
*/
|
||||
private async decryptCiphersWithSdk(ciphers: Cipher[], userId: UserId): Promise<CipherView[]> {
|
||||
const decryptedViews = await this.cipherEncryptionService.decryptManyLegacy(ciphers, userId);
|
||||
private async decryptCiphersWithSdk(
|
||||
ciphers: Cipher[],
|
||||
userId: UserId,
|
||||
): Promise<[CipherView[], CipherView[]]> {
|
||||
const [decrypted, failures] = await this.cipherEncryptionService.decryptManyWithFailures(
|
||||
ciphers,
|
||||
userId,
|
||||
);
|
||||
const decryptedViews = await Promise.all(decrypted.map((c) => this.getFullCipherView(c)));
|
||||
const failedViews = failures.map((c) => {
|
||||
const cipher_view = new CipherView(c);
|
||||
cipher_view.name = "[error: cannot decrypt]";
|
||||
cipher_view.decryptionFailure = true;
|
||||
return cipher_view;
|
||||
});
|
||||
|
||||
return decryptedViews.sort(this.getLocaleSortingFunction());
|
||||
return [decryptedViews.sort(this.getLocaleSortingFunction()), failedViews];
|
||||
}
|
||||
|
||||
/** Fetches the full `CipherView` when a `CipherListView` is passed. */
|
||||
|
||||
Reference in New Issue
Block a user