mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
[EC-598] feat: extend return from authenticator
This commit is contained in:
@@ -4,13 +4,17 @@ export abstract class Fido2AuthenticatorService {
|
|||||||
*
|
*
|
||||||
* @return {Uint8Array} Attestation object
|
* @return {Uint8Array} Attestation object
|
||||||
**/
|
**/
|
||||||
makeCredential: (params: Fido2AuthenticatorMakeCredentialsParams) => Promise<Uint8Array>;
|
makeCredential: (
|
||||||
|
params: Fido2AuthenticatorMakeCredentialsParams,
|
||||||
|
abortController?: AbortController
|
||||||
|
) => Promise<Fido2AuthenticatorMakeCredentialResult>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate an assertion using an existing credential
|
* Generate an assertion using an existing credential
|
||||||
*/
|
*/
|
||||||
getAssertion: (
|
getAssertion: (
|
||||||
params: Fido2AuthenticatorGetAssertionParams
|
params: Fido2AuthenticatorGetAssertionParams,
|
||||||
|
abortController?: AbortController
|
||||||
) => Promise<Fido2AuthenticatorGetAssertionResult>;
|
) => Promise<Fido2AuthenticatorGetAssertionResult>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +88,13 @@ export interface Fido2AuthenticatorMakeCredentialsParams {
|
|||||||
// requireUserPresence: true; // Always required
|
// requireUserPresence: true; // Always required
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Fido2AuthenticatorMakeCredentialResult {
|
||||||
|
credentialId: BufferSource;
|
||||||
|
attestationObject: BufferSource;
|
||||||
|
authData: BufferSource;
|
||||||
|
publicKeyAlgorithm: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Fido2AuthenticatorGetAssertionParams {
|
export interface Fido2AuthenticatorGetAssertionParams {
|
||||||
/** The caller’s RP ID, as determined by the user agent and the client. */
|
/** The caller’s RP ID, as determined by the user agent and the client. */
|
||||||
rpId: string;
|
rpId: string;
|
||||||
|
|||||||
@@ -435,7 +435,9 @@ describe("FidoAuthenticatorService", () => {
|
|||||||
it("should return attestation object", async () => {
|
it("should return attestation object", async () => {
|
||||||
const result = await authenticator.makeCredential(params);
|
const result = await authenticator.makeCredential(params);
|
||||||
|
|
||||||
const attestationObject = CBOR.decode(result.buffer);
|
const attestationObject = CBOR.decode(
|
||||||
|
Fido2Utils.bufferSourceToUint8Array(result.attestationObject).buffer
|
||||||
|
);
|
||||||
|
|
||||||
const encAuthData: Uint8Array = attestationObject.authData;
|
const encAuthData: Uint8Array = attestationObject.authData;
|
||||||
const rpIdHash = encAuthData.slice(0, 32);
|
const rpIdHash = encAuthData.slice(0, 32);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
Fido2AutenticatorErrorCode,
|
Fido2AutenticatorErrorCode,
|
||||||
Fido2AuthenticatorGetAssertionParams,
|
Fido2AuthenticatorGetAssertionParams,
|
||||||
Fido2AuthenticatorGetAssertionResult,
|
Fido2AuthenticatorGetAssertionResult,
|
||||||
|
Fido2AuthenticatorMakeCredentialResult,
|
||||||
Fido2AuthenticatorMakeCredentialsParams,
|
Fido2AuthenticatorMakeCredentialsParams,
|
||||||
Fido2AuthenticatorService as Fido2AuthenticatorServiceAbstraction,
|
Fido2AuthenticatorService as Fido2AuthenticatorServiceAbstraction,
|
||||||
} from "../abstractions/fido2-authenticator.service.abstraction";
|
} from "../abstractions/fido2-authenticator.service.abstraction";
|
||||||
@@ -35,7 +36,9 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
|
|||||||
private cipherService: CipherService,
|
private cipherService: CipherService,
|
||||||
private userInterface: Fido2UserInterfaceService
|
private userInterface: Fido2UserInterfaceService
|
||||||
) {}
|
) {}
|
||||||
async makeCredential(params: Fido2AuthenticatorMakeCredentialsParams): Promise<Uint8Array> {
|
async makeCredential(
|
||||||
|
params: Fido2AuthenticatorMakeCredentialsParams
|
||||||
|
): Promise<Fido2AuthenticatorMakeCredentialResult> {
|
||||||
if (params.credTypesAndPubKeyAlgs.every((p) => p.alg !== Fido2AlgorithmIdentifier.ES256)) {
|
if (params.credTypesAndPubKeyAlgs.every((p) => p.alg !== Fido2AlgorithmIdentifier.ES256)) {
|
||||||
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.NotSupported);
|
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.NotSupported);
|
||||||
}
|
}
|
||||||
@@ -116,22 +119,29 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const credentialId = params.requireResidentKey ? cipher.id : cipher.fido2Key.nonDiscoverableId;
|
||||||
|
const authData = await generateAuthData({
|
||||||
|
rpId: params.rpEntity.id,
|
||||||
|
credentialId,
|
||||||
|
counter: cipher.fido2Key.counter,
|
||||||
|
userPresence: true,
|
||||||
|
userVerification: false,
|
||||||
|
keyPair,
|
||||||
|
});
|
||||||
const attestationObject = new Uint8Array(
|
const attestationObject = new Uint8Array(
|
||||||
CBOR.encode({
|
CBOR.encode({
|
||||||
fmt: "none",
|
fmt: "none",
|
||||||
attStmt: {},
|
attStmt: {},
|
||||||
authData: await generateAuthData({
|
authData,
|
||||||
rpId: params.rpEntity.id,
|
|
||||||
credentialId: params.requireResidentKey ? cipher.id : cipher.fido2Key.nonDiscoverableId,
|
|
||||||
counter: cipher.fido2Key.counter,
|
|
||||||
userPresence: true,
|
|
||||||
userVerification: false,
|
|
||||||
keyPair,
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
return attestationObject;
|
return {
|
||||||
|
credentialId: Fido2Utils.stringToBuffer(credentialId),
|
||||||
|
attestationObject,
|
||||||
|
authData,
|
||||||
|
publicKeyAlgorithm: -7,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAssertion(
|
async getAssertion(
|
||||||
|
|||||||
Reference in New Issue
Block a user