From 183af554918a185690ebae45fccbf39ddd87e18e Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Wed, 5 Apr 2023 16:28:46 +0200 Subject: [PATCH] [EC-598] feat: make fallback working again --- .../browser-fido2-user-interface.service.ts | 4 +++- .../fido2-client.service.abstraction.ts | 13 ++++--------- .../webauthn/services/fido2-client.service.ts | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/apps/browser/src/services/fido2/browser-fido2-user-interface.service.ts b/apps/browser/src/services/fido2/browser-fido2-user-interface.service.ts index c79ab20de7..6a348fef40 100644 --- a/apps/browser/src/services/fido2/browser-fido2-user-interface.service.ts +++ b/apps/browser/src/services/fido2/browser-fido2-user-interface.service.ts @@ -147,7 +147,9 @@ export class BrowserFido2UserInterfaceSession implements Fido2UserInterfaceSessi .subscribe((msg) => { if (msg.type === "AbortResponse") { this.close(); - this.abortController.abort(UserRequestedFallbackAbortReason); + this.abortController.abort( + msg.fallbackRequested ? UserRequestedFallbackAbortReason : undefined + ); } }); diff --git a/libs/common/src/webauthn/abstractions/fido2-client.service.abstraction.ts b/libs/common/src/webauthn/abstractions/fido2-client.service.abstraction.ts index 8fb2197dc8..61fba18364 100644 --- a/libs/common/src/webauthn/abstractions/fido2-client.service.abstraction.ts +++ b/libs/common/src/webauthn/abstractions/fido2-client.service.abstraction.ts @@ -79,14 +79,9 @@ export interface PublicKeyCredentialParam { type: "public-key"; } -export class Fido2Error extends Error { - constructor(message: string, readonly fallbackRequested = false) { - super(message); - } -} - -export class RequestAbortedError extends Fido2Error { - constructor(fallbackRequested = false) { - super("Fido2 request was aborted", fallbackRequested); +export class FallbackRequestedError extends Error { + readonly fallbackRequested = true; + constructor() { + super("FallbackRequested"); } } diff --git a/libs/common/src/webauthn/services/fido2-client.service.ts b/libs/common/src/webauthn/services/fido2-client.service.ts index 49718c82ba..f4703e0ccf 100644 --- a/libs/common/src/webauthn/services/fido2-client.service.ts +++ b/libs/common/src/webauthn/services/fido2-client.service.ts @@ -14,8 +14,10 @@ import { AssertCredentialResult, CreateCredentialParams, CreateCredentialResult, + FallbackRequestedError, Fido2ClientService as Fido2ClientServiceAbstraction, PublicKeyCredentialParam, + UserRequestedFallbackAbortReason, UserVerification, } from "../abstractions/fido2-client.service.abstraction"; import { Fido2Utils } from "../abstractions/fido2-utils"; @@ -116,12 +118,20 @@ export class Fido2ClientService implements Fido2ClientServiceAbstraction { abortController ); } catch (error) { + if ( + abortController.signal.aborted && + abortController.signal.reason === UserRequestedFallbackAbortReason + ) { + throw new FallbackRequestedError(); + } + if ( error instanceof Fido2AutenticatorError && error.errorCode === Fido2AutenticatorErrorCode.InvalidState ) { throw new DOMException(undefined, "InvalidStateError"); } + throw new DOMException(undefined, "NotAllowedError"); } @@ -198,6 +208,13 @@ export class Fido2ClientService implements Fido2ClientServiceAbstraction { abortController ); } catch (error) { + if ( + abortController.signal.aborted && + abortController.signal.reason === UserRequestedFallbackAbortReason + ) { + throw new FallbackRequestedError(); + } + if ( error instanceof Fido2AutenticatorError && error.errorCode === Fido2AutenticatorErrorCode.InvalidState