1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

[EC-598] feat: extend return from authenticator

This commit is contained in:
Andreas Coroiu
2023-03-30 15:57:46 +02:00
parent 6fd5801739
commit 43a13cb451
3 changed files with 36 additions and 13 deletions

View File

@@ -4,13 +4,17 @@ export abstract class Fido2AuthenticatorService {
*
* @return {Uint8Array} Attestation object
**/
makeCredential: (params: Fido2AuthenticatorMakeCredentialsParams) => Promise<Uint8Array>;
makeCredential: (
params: Fido2AuthenticatorMakeCredentialsParams,
abortController?: AbortController
) => Promise<Fido2AuthenticatorMakeCredentialResult>;
/**
* Generate an assertion using an existing credential
*/
getAssertion: (
params: Fido2AuthenticatorGetAssertionParams
params: Fido2AuthenticatorGetAssertionParams,
abortController?: AbortController
) => Promise<Fido2AuthenticatorGetAssertionResult>;
}
@@ -84,6 +88,13 @@ export interface Fido2AuthenticatorMakeCredentialsParams {
// requireUserPresence: true; // Always required
}
export interface Fido2AuthenticatorMakeCredentialResult {
credentialId: BufferSource;
attestationObject: BufferSource;
authData: BufferSource;
publicKeyAlgorithm: number;
}
export interface Fido2AuthenticatorGetAssertionParams {
/** The callers RP ID, as determined by the user agent and the client. */
rpId: string;

View File

@@ -435,7 +435,9 @@ describe("FidoAuthenticatorService", () => {
it("should return attestation object", async () => {
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 rpIdHash = encAuthData.slice(0, 32);

View File

@@ -10,6 +10,7 @@ import {
Fido2AutenticatorErrorCode,
Fido2AuthenticatorGetAssertionParams,
Fido2AuthenticatorGetAssertionResult,
Fido2AuthenticatorMakeCredentialResult,
Fido2AuthenticatorMakeCredentialsParams,
Fido2AuthenticatorService as Fido2AuthenticatorServiceAbstraction,
} from "../abstractions/fido2-authenticator.service.abstraction";
@@ -35,7 +36,9 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
private cipherService: CipherService,
private userInterface: Fido2UserInterfaceService
) {}
async makeCredential(params: Fido2AuthenticatorMakeCredentialsParams): Promise<Uint8Array> {
async makeCredential(
params: Fido2AuthenticatorMakeCredentialsParams
): Promise<Fido2AuthenticatorMakeCredentialResult> {
if (params.credTypesAndPubKeyAlgs.every((p) => p.alg !== Fido2AlgorithmIdentifier.ES256)) {
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(
CBOR.encode({
fmt: "none",
attStmt: {},
authData: await generateAuthData({
rpId: params.rpEntity.id,
credentialId: params.requireResidentKey ? cipher.id : cipher.fido2Key.nonDiscoverableId,
counter: cipher.fido2Key.counter,
userPresence: true,
userVerification: false,
keyPair,
}),
authData,
})
);
return attestationObject;
return {
credentialId: Fido2Utils.stringToBuffer(credentialId),
attestationObject,
authData,
publicKeyAlgorithm: -7,
};
}
async getAssertion(