mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00:00
[EC-598] feat: half-implemented params mapping
This commit is contained in:
47
apps/browser/src/browser/webauthn-utils.ts
Normal file
47
apps/browser/src/browser/webauthn-utils.ts
Normal 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,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { WebauthnUtils } from "../../browser/webauthn-utils";
|
||||||
|
|
||||||
import { MessageType } from "./messaging/message";
|
import { MessageType } from "./messaging/message";
|
||||||
import { Messenger } from "./messaging/messenger";
|
import { Messenger } from "./messaging/messenger";
|
||||||
|
|
||||||
@@ -14,11 +16,7 @@ const messenger = Messenger.forDOMCommunication(window);
|
|||||||
navigator.credentials.create = async (options?: CredentialCreationOptions): Promise<Credential> => {
|
navigator.credentials.create = async (options?: CredentialCreationOptions): Promise<Credential> => {
|
||||||
await messenger.request({
|
await messenger.request({
|
||||||
type: MessageType.CredentialCreationRequest,
|
type: MessageType.CredentialCreationRequest,
|
||||||
data: {
|
data: WebauthnUtils.mapCredentialCreationOptions(options, window.location.origin),
|
||||||
rp: {
|
|
||||||
id: options.publicKey.rp.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return await browserCredentials.create(options);
|
return await browserCredentials.create(options);
|
||||||
|
|||||||
9
libs/common/src/abstractions/fido2/fido2-utils.ts
Normal file
9
libs/common/src/abstractions/fido2/fido2-utils.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export class Fido2Utils {
|
||||||
|
static bufferToString(buffer: BufferSource): string {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
static stringToBuffer(str: string): Uint8Array {
|
||||||
|
return new Uint8Array(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,35 @@
|
|||||||
export interface CredentialRegistrationParams {
|
export interface CredentialRegistrationParams {
|
||||||
|
origin: string;
|
||||||
|
attestation?: "direct" | "enterprise" | "indirect" | "none";
|
||||||
|
authenticatorSelection?: {
|
||||||
|
// authenticatorAttachment?: AuthenticatorAttachment; // not used
|
||||||
|
requireResidentKey?: boolean;
|
||||||
|
residentKey?: "discouraged" | "preferred" | "required";
|
||||||
|
userVerification?: "discouraged" | "preferred" | "required";
|
||||||
|
};
|
||||||
|
challenge: string; // b64 encoded
|
||||||
|
excludeCredentials?: {
|
||||||
|
id: string; // b64 encoded
|
||||||
|
transports?: ("ble" | "internal" | "nfc" | "usb")[];
|
||||||
|
// type: "public-key"; // not used
|
||||||
|
}[];
|
||||||
|
extensions?: {
|
||||||
|
appid?: string;
|
||||||
|
appidExclude?: string;
|
||||||
|
credProps?: boolean;
|
||||||
|
uvm?: boolean;
|
||||||
|
};
|
||||||
|
pubKeyCredParams: {
|
||||||
|
alg: number;
|
||||||
|
// type: "public-key"; // not used
|
||||||
|
}[];
|
||||||
rp: {
|
rp: {
|
||||||
id?: string;
|
id?: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
user: {
|
||||||
|
id: string; // b64 encoded
|
||||||
|
displayName: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
export class Fido2Service implements Fido2ServiceAbstraction {
|
export class Fido2Service implements Fido2ServiceAbstraction {
|
||||||
createCredential(params: CredentialRegistrationParams): unknown {
|
createCredential(params: CredentialRegistrationParams): unknown {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log("Fido2Service.registerCredential");
|
console.log("Fido2Service.registerCredential", params);
|
||||||
return "createCredential response";
|
return "createCredential response";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user