mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 08:43:33 +00:00
[EC-598] feat: allow user to confirm duplication
This commit is contained in:
@@ -2,6 +2,16 @@ export abstract class Fido2AuthenticatorService {
|
|||||||
makeCredential: (params: Fido2AuthenticatorMakeCredentialsParams) => void;
|
makeCredential: (params: Fido2AuthenticatorMakeCredentialsParams) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum Fido2AutenticatorErrorCode {
|
||||||
|
CTAP2_ERR_CREDENTIAL_EXCLUDED,
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Fido2AutenticatorError extends Error {
|
||||||
|
constructor(readonly errorCode: Fido2AutenticatorErrorCode) {
|
||||||
|
super(Fido2AutenticatorErrorCode[errorCode]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters for {@link Fido2AuthenticatorService.makeCredential}
|
* Parameters for {@link Fido2AuthenticatorService.makeCredential}
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import { Utils } from "../../misc/utils";
|
|||||||
import { CipherService } from "../../vault/abstractions/cipher.service";
|
import { CipherService } from "../../vault/abstractions/cipher.service";
|
||||||
import { CipherType } from "../../vault/enums/cipher-type";
|
import { CipherType } from "../../vault/enums/cipher-type";
|
||||||
import { CipherView } from "../../vault/models/view/cipher.view";
|
import { CipherView } from "../../vault/models/view/cipher.view";
|
||||||
import { Fido2AuthenticatorMakeCredentialsParams } from "../abstractions/fido2-authenticator.service.abstraction";
|
import {
|
||||||
|
Fido2AutenticatorErrorCode,
|
||||||
|
Fido2AuthenticatorMakeCredentialsParams,
|
||||||
|
} from "../abstractions/fido2-authenticator.service.abstraction";
|
||||||
import { Fido2UserInterfaceService } from "../abstractions/fido2-user-interface.service.abstraction";
|
import { Fido2UserInterfaceService } from "../abstractions/fido2-user-interface.service.abstraction";
|
||||||
import { Fido2Utils } from "../abstractions/fido2-utils";
|
import { Fido2Utils } from "../abstractions/fido2-utils";
|
||||||
import { Fido2KeyView } from "../models/view/fido2-key.view";
|
import { Fido2KeyView } from "../models/view/fido2-key.view";
|
||||||
@@ -40,13 +43,24 @@ describe("FidoAuthenticatorService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/** Spec: wait for user presence */
|
/** Spec: wait for user presence */
|
||||||
it("should wait for confirmation from user", async () => {
|
it("should request confirmation from user", async () => {
|
||||||
userInterface.confirmDuplicateCredential.mockResolvedValue(true);
|
userInterface.confirmDuplicateCredential.mockResolvedValue(true);
|
||||||
|
|
||||||
await authenticator.makeCredential(params);
|
await authenticator.makeCredential(params);
|
||||||
|
|
||||||
expect(userInterface.confirmDuplicateCredential).toHaveBeenCalled();
|
expect(userInterface.confirmDuplicateCredential).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** Spec: then terminate this procedure and return error code */
|
||||||
|
it("should throw error if user denies duplication", async () => {
|
||||||
|
userInterface.confirmDuplicateCredential.mockResolvedValue(false);
|
||||||
|
|
||||||
|
const result = async () => await authenticator.makeCredential(params);
|
||||||
|
|
||||||
|
await expect(result).rejects.toThrowError(
|
||||||
|
Fido2AutenticatorErrorCode[Fido2AutenticatorErrorCode.CTAP2_ERR_CREDENTIAL_EXCLUDED]
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { CipherService } from "../../vault/services/cipher.service";
|
import { CipherService } from "../../vault/services/cipher.service";
|
||||||
import {
|
import {
|
||||||
|
Fido2AutenticatorError,
|
||||||
|
Fido2AutenticatorErrorCode,
|
||||||
Fido2AuthenticatorMakeCredentialsParams,
|
Fido2AuthenticatorMakeCredentialsParams,
|
||||||
Fido2AuthenticatorService as Fido2AuthenticatorServiceAbstraction,
|
Fido2AuthenticatorService as Fido2AuthenticatorServiceAbstraction,
|
||||||
} from "../abstractions/fido2-authenticator.service.abstraction";
|
} from "../abstractions/fido2-authenticator.service.abstraction";
|
||||||
@@ -17,12 +19,16 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async makeCredential(params: Fido2AuthenticatorMakeCredentialsParams): Promise<void> {
|
async makeCredential(params: Fido2AuthenticatorMakeCredentialsParams): Promise<void> {
|
||||||
this.userInterface.confirmDuplicateCredential(
|
const userConfirmation = await this.userInterface.confirmDuplicateCredential(
|
||||||
[Fido2Utils.bufferToString(params.excludeList[0].id)],
|
[Fido2Utils.bufferToString(params.excludeList[0].id)],
|
||||||
{
|
{
|
||||||
credentialName: params.rp.name,
|
credentialName: params.rp.name,
|
||||||
userName: params.user.name,
|
userName: params.user.name,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!userConfirmation) {
|
||||||
|
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.CTAP2_ERR_CREDENTIAL_EXCLUDED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user