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

[EC-598] feat: ability to abort from page script

This commit is contained in:
Andreas Coroiu
2023-01-31 11:10:36 +01:00
parent 1ad0bc547a
commit c7e7ce832b
5 changed files with 101 additions and 30 deletions

View File

@@ -4,7 +4,10 @@ export interface NewCredentialParams {
}
export abstract class Fido2UserInterfaceService {
confirmCredential: (cipherId: string) => Promise<boolean>;
pickCredential: (cipherIds: string[]) => Promise<string>;
confirmNewCredential: (params: NewCredentialParams) => Promise<boolean>;
confirmCredential: (cipherId: string, abortController?: AbortController) => Promise<boolean>;
pickCredential: (cipherIds: string[], abortController?: AbortController) => Promise<string>;
confirmNewCredential: (
params: NewCredentialParams,
abortController?: AbortController
) => Promise<boolean>;
}

View File

@@ -48,10 +48,13 @@ export class Fido2Service implements Fido2ServiceAbstraction {
params: CredentialRegistrationParams,
abortController?: AbortController
): Promise<CredentialRegistrationResult> {
const presence = await this.fido2UserInterfaceService.confirmNewCredential({
credentialName: params.rp.name,
userName: params.user.displayName,
});
const presence = await this.fido2UserInterfaceService.confirmNewCredential(
{
credentialName: params.rp.name,
userName: params.user.displayName,
},
abortController
);
const attestationFormat = STANDARD_ATTESTATION_FORMAT;
const encoder = new TextEncoder();
@@ -122,7 +125,10 @@ export class Fido2Service implements Fido2ServiceAbstraction {
};
}
async assertCredential(params: CredentialAssertParams): Promise<CredentialAssertResult> {
async assertCredential(
params: CredentialAssertParams,
abortController?: AbortController
): Promise<CredentialAssertResult> {
let credential: BitCredential | undefined;
if (params.allowedCredentialIds && params.allowedCredentialIds.length > 0) {
@@ -138,7 +144,10 @@ export class Fido2Service implements Fido2ServiceAbstraction {
// throw new OriginMismatchError();
// }
await this.fido2UserInterfaceService.confirmCredential(credential.credentialId.encoded);
await this.fido2UserInterfaceService.confirmCredential(
credential.credentialId.encoded,
abortController
);
} else {
// We're looking for a resident key
const credentials = await this.getCredentialsByRp(params.rpId);
@@ -148,7 +157,8 @@ export class Fido2Service implements Fido2ServiceAbstraction {
}
const pickedId = await this.fido2UserInterfaceService.pickCredential(
credentials.map((c) => c.credentialId.encoded)
credentials.map((c) => c.credentialId.encoded),
abortController
);
credential = credentials.find((c) => c.credentialId.encoded === pickedId);
}
@@ -184,7 +194,10 @@ export class Fido2Service implements Fido2ServiceAbstraction {
};
}
private async getCredential(allowedCredentialIds: string[]): Promise<BitCredential | undefined> {
private async getCredential(
allowedCredentialIds: string[],
abortController?: AbortController
): Promise<BitCredential | undefined> {
let cipher: Cipher | undefined;
for (const allowedCredential of allowedCredentialIds) {
cipher = await this.cipherService.get(allowedCredential);