1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 11:13:46 +00:00

[EC-598] feat: add check for unsupported algorithms

This commit is contained in:
Andreas Coroiu
2023-03-21 16:59:26 +01:00
parent 078bf9dcb5
commit 696e036ca8
3 changed files with 61 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
import { CipherService } from "../../vault/services/cipher.service";
import {
Fido2AlgorithmIdentifier,
Fido2AutenticatorError,
Fido2AutenticatorErrorCode,
Fido2AuthenticatorMakeCredentialsParams,
@@ -19,16 +20,36 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
) {}
async makeCredential(params: Fido2AuthenticatorMakeCredentialsParams): Promise<void> {
const userConfirmation = await this.userInterface.confirmDuplicateCredential(
[Fido2Utils.bufferToString(params.excludeList[0].id)],
{
credentialName: params.rp.name,
userName: params.user.name,
}
const duplicateExists = await this.vaultContainsId(
params.excludeList.map((key) => Fido2Utils.bufferToString(key.id))
);
if (!userConfirmation) {
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.CTAP2_ERR_CREDENTIAL_EXCLUDED);
if (duplicateExists) {
const userConfirmation = await this.userInterface.confirmDuplicateCredential(
[Fido2Utils.bufferToString(params.excludeList[0].id)],
{
credentialName: params.rp.name,
userName: params.user.name,
}
);
if (!userConfirmation) {
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.CTAP2_ERR_CREDENTIAL_EXCLUDED);
}
}
if (params.pubKeyCredParams.every((p) => p.alg !== Fido2AlgorithmIdentifier.ES256)) {
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.CTAP2_ERR_UNSUPPORTED_ALGORITHM);
}
}
private async vaultContainsId(ids: string[]): Promise<boolean> {
for (const id of ids) {
if ((await this.cipherService.get(id)) != undefined) {
return true;
}
}
return false;
}
}