From e70d6cdcd4af93d564cc4885b08ed91e6862e128 Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Mon, 20 Mar 2023 11:09:48 +0100 Subject: [PATCH] [EC-598] feat: start creating separate authenticator service --- ...fido2-authenticator.service.abstraction.ts | 44 +++++++++++++++++++ .../fido2-authenticator.service.spec.ts | 5 +++ .../services/fido2-authenticator.service.ts | 12 +++++ 3 files changed, 61 insertions(+) create mode 100644 libs/common/src/webauthn/abstractions/fido2-authenticator.service.abstraction.ts create mode 100644 libs/common/src/webauthn/services/fido2-authenticator.service.spec.ts create mode 100644 libs/common/src/webauthn/services/fido2-authenticator.service.ts diff --git a/libs/common/src/webauthn/abstractions/fido2-authenticator.service.abstraction.ts b/libs/common/src/webauthn/abstractions/fido2-authenticator.service.abstraction.ts new file mode 100644 index 00000000000..bd397f570dd --- /dev/null +++ b/libs/common/src/webauthn/abstractions/fido2-authenticator.service.abstraction.ts @@ -0,0 +1,44 @@ +export abstract class Fido2AuthenticatorService { + makeCredential: (params: Fido2AuthenticatorMakeCredentialsParams) => void; +} + +/** + * Parameters for {@link Fido2AuthenticatorService.makeCredential} + * + * @note + * This interface uses the parameter names defined in `fido-v2.0-ps-20190130` + * but the parameter values use the corresponding data structures defined in + * `WD-webauthn-3-20210427`. This is to avoid the unnecessary complexity of + * converting data to CBOR and back. + */ +export interface Fido2AuthenticatorMakeCredentialsParams { + clientDataHash: BufferSource; + rp: { + name: string; + id?: string; + }; + user: { + name: string; + displayName: string; + id: BufferSource; + }; + pubKeyCredParams: { + alg: number; + // type: "public-key"; // not used + }[]; + excludeList?: { + id: BufferSource; + transports?: ("ble" | "internal" | "nfc" | "usb")[]; + // type: "public-key"; // not used + }[]; + extensions?: { + appid?: string; + appidExclude?: string; + credProps?: boolean; + uvm?: boolean; + }; + options?: { + rk?: boolean; + uv?: boolean; + }; +} diff --git a/libs/common/src/webauthn/services/fido2-authenticator.service.spec.ts b/libs/common/src/webauthn/services/fido2-authenticator.service.spec.ts new file mode 100644 index 00000000000..46f239aab6e --- /dev/null +++ b/libs/common/src/webauthn/services/fido2-authenticator.service.spec.ts @@ -0,0 +1,5 @@ +describe("FidoAuthenticatorService", () => { + describe("authenticatorMakeCredential", () => { + test.skip("To be implemented"); + }); +}); diff --git a/libs/common/src/webauthn/services/fido2-authenticator.service.ts b/libs/common/src/webauthn/services/fido2-authenticator.service.ts new file mode 100644 index 00000000000..be8384e55d0 --- /dev/null +++ b/libs/common/src/webauthn/services/fido2-authenticator.service.ts @@ -0,0 +1,12 @@ +import { + Fido2AuthenticatorMakeCredentialsParams, + Fido2AuthenticatorService as Fido2AuthenticatorServiceAbstraction, +} from "../abstractions/fido2-authenticator.service.abstraction"; + +/** + * Bitwarden implementation of the Authenticator API described by the FIDO Alliance + * https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html + */ +export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstraction { + makeCredential: (params: Fido2AuthenticatorMakeCredentialsParams) => void; +}