1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-15 10:35:20 +01: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
No known key found for this signature in database
4 changed files with 30 additions and 3 deletions

View File

@ -535,6 +535,7 @@ export default class MainBackground {
this.fido2AuthenticatorService = new Fido2AuthenticatorService(
this.cipherService,
this.fido2UserInterfaceService,
this.syncService,
this.logService
);
this.fido2ClientService = new Fido2ClientService(

View File

@ -1,4 +1,4 @@
import { NgZone } from "@angular/core";
import type { NgZone } from "@angular/core";
import { Observable } from "rxjs";
import { DeviceType } from "@bitwarden/common/enums";
@ -213,7 +213,15 @@ export class BrowserApi {
}
}
//Ngzone run is added to fix the issue on Fido2Component, where the message listener is not running in the angular zone
/**
* Creates an observable that listens for messages. If an Angular zone is provided,
* ensures that the message processing runs within that zone, triggering change detection.
* This solution was devised to address an issue in the `Fido2Component`, where the
* original message listener operated outside the Angular zone.
*
* @param {NgZone} [zone] - An optional Angular zone to ensure UI updates and change
* detection are triggered. If omitted, operates outside the Angular zone.
*/
static messageListener$(zone?: NgZone) {
return new Observable<unknown>((subscriber) => {
const handler = (message: unknown) => {

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) =>