1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

Added full synce service to the fido2 authenticator to ensure the full sync is completed before getting all decrypted ciphers

This commit is contained in:
gbubemismith
2023-08-09 13:15:56 -04:00
parent b603a45fea
commit 6e86b25e82
4 changed files with 30 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ import {
Fido2UserInterfaceSession,
NewCredentialParams,
} from "../../abstractions/fido2/fido2-user-interface.service.abstraction";
import { SyncService } from "../../abstractions/sync/sync.service.abstraction";
import { CipherType } from "../../enums/cipher-type";
import { Cipher } from "../../models/domain/cipher";
import { CipherView } from "../../models/view/cipher.view";
@@ -30,6 +31,7 @@ describe("FidoAuthenticatorService", () => {
let cipherService!: MockProxy<CipherService>;
let userInterface!: MockProxy<Fido2UserInterfaceService>;
let userInterfaceSession!: MockProxy<Fido2UserInterfaceSession>;
let syncService!: MockProxy<SyncService>;
let authenticator!: Fido2AuthenticatorService;
beforeEach(async () => {
@@ -37,7 +39,8 @@ describe("FidoAuthenticatorService", () => {
userInterface = mock<Fido2UserInterfaceService>();
userInterfaceSession = mock<Fido2UserInterfaceSession>();
userInterface.newSession.mockResolvedValue(userInterfaceSession);
authenticator = new Fido2AuthenticatorService(cipherService, userInterface);
syncService = mock<SyncService>();
authenticator = new Fido2AuthenticatorService(cipherService, userInterface, syncService);
});
describe("makeCredential", () => {

View File

@@ -15,6 +15,7 @@ import {
PublicKeyCredentialDescriptor,
} from "../../abstractions/fido2/fido2-authenticator.service.abstraction";
import { Fido2UserInterfaceService } from "../../abstractions/fido2/fido2-user-interface.service.abstraction";
import { SyncService } from "../../abstractions/sync/sync.service.abstraction";
import { CipherType } from "../../enums/cipher-type";
import { CipherView } from "../../models/view/cipher.view";
import { Fido2KeyView } from "../../models/view/fido2-key.view";
@@ -37,6 +38,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
constructor(
private cipherService: CipherService,
private userInterface: Fido2UserInterfaceService,
private syncService: SyncService,
private logService?: LogService
) {}
async makeCredential(
@@ -81,6 +83,9 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.Unknown);
}
//TODO: uncomment this when working on the login flow ticket
// await userInterfaceSession.ensureUnlockedVault();
const existingCipherIds = await this.findExcludedCredentials(
params.excludeCredentialDescriptorList
);
@@ -376,6 +381,11 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
return [];
}
//ensure full sync has completed before getting the ciphers
if ((await this.syncService.getLastSync()) == null) {
await this.syncService.fullSync(false);
}
const ciphers = await this.cipherService.getAllDecrypted();
return ciphers.filter(
(cipher) =>
@@ -391,6 +401,11 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
}
private async findCredentialsByRp(rpId: string): Promise<CipherView[]> {
//ensure full sync has completed before getting the ciphers
if ((await this.syncService.getLastSync()) == null) {
await this.syncService.fullSync(false);
}
const ciphers = await this.cipherService.getAllDecrypted();
return ciphers.filter(
(cipher) =>