1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

[EC-598] feat: half-implemented params mapping

This commit is contained in:
Andreas Coroiu
2022-11-18 17:01:36 +01:00
parent dc91cfda69
commit def0015188
5 changed files with 89 additions and 6 deletions

View File

@@ -0,0 +1,47 @@
import { Fido2Utils } from "@bitwarden/common/abstractions/fido2/fido2-utils";
import { CredentialRegistrationParams } from "@bitwarden/common/abstractions/fido2/fido2.service.abstraction";
export class WebauthnUtils {
static mapCredentialCreationOptions(
options: CredentialCreationOptions,
origin: string
): CredentialRegistrationParams {
const keyOptions = options.publicKey;
if (keyOptions == undefined) {
throw new Error("Public-key options not found");
}
return {
origin,
attestation: keyOptions.attestation,
authenticatorSelection: {
requireResidentKey: keyOptions.authenticatorSelection?.requireResidentKey,
residentKey: keyOptions.authenticatorSelection?.residentKey,
userVerification: keyOptions.authenticatorSelection?.userVerification,
},
challenge: Fido2Utils.bufferToString(keyOptions.challenge),
excludeCredentials: keyOptions.excludeCredentials?.map((credential) => ({
id: Fido2Utils.bufferToString(credential.id),
transports: credential.transports,
})),
extensions: {
appid: keyOptions.extensions?.appid,
appidExclude: keyOptions.extensions?.appidExclude,
credProps: keyOptions.extensions?.credProps,
uvm: keyOptions.extensions?.uvm,
},
pubKeyCredParams: keyOptions.pubKeyCredParams.map((params) => ({
alg: params.alg,
})),
rp: {
id: keyOptions.rp.id,
name: keyOptions.rp.name,
},
user: {
id: Fido2Utils.bufferToString(keyOptions.user.id),
displayName: keyOptions.user.displayName,
},
};
}
}

View File

@@ -1,3 +1,5 @@
import { WebauthnUtils } from "../../browser/webauthn-utils";
import { MessageType } from "./messaging/message";
import { Messenger } from "./messaging/messenger";
@@ -14,11 +16,7 @@ const messenger = Messenger.forDOMCommunication(window);
navigator.credentials.create = async (options?: CredentialCreationOptions): Promise<Credential> => {
await messenger.request({
type: MessageType.CredentialCreationRequest,
data: {
rp: {
id: options.publicKey.rp.id,
},
},
data: WebauthnUtils.mapCredentialCreationOptions(options, window.location.origin),
});
return await browserCredentials.create(options);