1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-02 18:17:46 +01:00
This commit is contained in:
Jonathan Prusik 2023-10-18 12:14:16 -04:00 committed by GitHub
parent 2850a6723a
commit 82553ebb13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 43 deletions

View File

@ -39,7 +39,7 @@ export enum Fido2AlgorithmIdentifier {
RS256 = -257, RS256 = -257,
} }
export enum Fido2AutenticatorErrorCode { export enum Fido2AuthenticatorErrorCode {
Unknown = "UnknownError", Unknown = "UnknownError",
NotSupported = "NotSupportedError", NotSupported = "NotSupportedError",
InvalidState = "InvalidStateError", InvalidState = "InvalidStateError",
@ -47,8 +47,8 @@ export enum Fido2AutenticatorErrorCode {
Constraint = "ConstraintError", Constraint = "ConstraintError",
} }
export class Fido2AutenticatorError extends Error { export class Fido2AuthenticatorError extends Error {
constructor(readonly errorCode: Fido2AutenticatorErrorCode) { constructor(readonly errorCode: Fido2AuthenticatorErrorCode) {
super(errorCode); super(errorCode);
} }
} }

View File

@ -5,7 +5,7 @@ import { mock, MockProxy } from "jest-mock-extended";
import { Utils } from "../../../platform/misc/utils"; import { Utils } from "../../../platform/misc/utils";
import { CipherService } from "../../abstractions/cipher.service"; import { CipherService } from "../../abstractions/cipher.service";
import { import {
Fido2AutenticatorErrorCode, Fido2AuthenticatorErrorCode,
Fido2AuthenticatorGetAssertionParams, Fido2AuthenticatorGetAssertionParams,
Fido2AuthenticatorMakeCredentialsParams, Fido2AuthenticatorMakeCredentialsParams,
} from "../../abstractions/fido2/fido2-authenticator.service.abstraction"; } from "../../abstractions/fido2/fido2-authenticator.service.abstraction";
@ -60,19 +60,19 @@ describe("FidoAuthenticatorService", () => {
const result = async () => const result = async () =>
await authenticator.makeCredential(invalidParams.unsupportedAlgorithm, tab); await authenticator.makeCredential(invalidParams.unsupportedAlgorithm, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.NotSupported); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.NotSupported);
}); });
it("should throw error when requireResidentKey has invalid value", async () => { it("should throw error when requireResidentKey has invalid value", async () => {
const result = async () => await authenticator.makeCredential(invalidParams.invalidRk, tab); const result = async () => await authenticator.makeCredential(invalidParams.invalidRk, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.Unknown); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.Unknown);
}); });
it("should throw error when requireUserVerification has invalid value", async () => { it("should throw error when requireUserVerification has invalid value", async () => {
const result = async () => await authenticator.makeCredential(invalidParams.invalidUv, tab); const result = async () => await authenticator.makeCredential(invalidParams.invalidUv, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.Unknown); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.Unknown);
}); });
/** /**
@ -85,7 +85,7 @@ describe("FidoAuthenticatorService", () => {
const result = async () => await authenticator.makeCredential(params, tab); const result = async () => await authenticator.makeCredential(params, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.Constraint); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.Constraint);
}); });
it("should not request confirmation from user", async () => { it("should not request confirmation from user", async () => {
@ -151,7 +151,7 @@ describe("FidoAuthenticatorService", () => {
const result = async () => await authenticator.makeCredential(params, tab); const result = async () => await authenticator.makeCredential(params, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.NotAllowed); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.NotAllowed);
}); });
/** Devation: Organization ciphers are not checked against excluded credentials, even if the user has access to them. */ /** Devation: Organization ciphers are not checked against excluded credentials, even if the user has access to them. */
@ -267,7 +267,7 @@ describe("FidoAuthenticatorService", () => {
const result = async () => await authenticator.makeCredential(params, tab); const result = async () => await authenticator.makeCredential(params, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.NotAllowed); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.NotAllowed);
}); });
it("should throw error if user verification fails and cipher requires reprompt", async () => { it("should throw error if user verification fails and cipher requires reprompt", async () => {
@ -281,7 +281,7 @@ describe("FidoAuthenticatorService", () => {
const result = async () => await authenticator.makeCredential(params, tab); const result = async () => await authenticator.makeCredential(params, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.Unknown); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.Unknown);
}); });
/** Spec: If any error occurred while creating the new credential object, return an error code equivalent to "UnknownError" and terminate the operation. */ /** Spec: If any error occurred while creating the new credential object, return an error code equivalent to "UnknownError" and terminate the operation. */
@ -296,7 +296,7 @@ describe("FidoAuthenticatorService", () => {
const result = async () => await authenticator.makeCredential(params, tab); const result = async () => await authenticator.makeCredential(params, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.Unknown); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.Unknown);
}); });
}); });
@ -434,7 +434,7 @@ describe("FidoAuthenticatorService", () => {
it("should throw error when requireUserVerification has invalid value", async () => { it("should throw error when requireUserVerification has invalid value", async () => {
const result = async () => await authenticator.getAssertion(invalidParams.invalidUv, tab); const result = async () => await authenticator.getAssertion(invalidParams.invalidUv, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.Unknown); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.Unknown);
}); });
/** /**
@ -447,7 +447,7 @@ describe("FidoAuthenticatorService", () => {
const result = async () => await authenticator.getAssertion(params, tab); const result = async () => await authenticator.getAssertion(params, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.Constraint); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.Constraint);
}); });
}); });
@ -512,7 +512,7 @@ describe("FidoAuthenticatorService", () => {
it("should throw error", async () => { it("should throw error", async () => {
const result = async () => await authenticator.getAssertion(params, tab); const result = async () => await authenticator.getAssertion(params, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.NotAllowed); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.NotAllowed);
}); });
}); });
@ -600,7 +600,7 @@ describe("FidoAuthenticatorService", () => {
const result = async () => await authenticator.getAssertion(params, tab); const result = async () => await authenticator.getAssertion(params, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.NotAllowed); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.NotAllowed);
}); });
it("should throw error if user verification fails and cipher requires reprompt", async () => { it("should throw error if user verification fails and cipher requires reprompt", async () => {
@ -612,7 +612,7 @@ describe("FidoAuthenticatorService", () => {
const result = async () => await authenticator.getAssertion(params, tab); const result = async () => await authenticator.getAssertion(params, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.NotAllowed); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.NotAllowed);
}); });
}); });
@ -737,7 +737,7 @@ describe("FidoAuthenticatorService", () => {
const result = async () => await authenticator.getAssertion(params, tab); const result = async () => await authenticator.getAssertion(params, tab);
await expect(result).rejects.toThrowError(Fido2AutenticatorErrorCode.Unknown); await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.Unknown);
}); });
}); });

View File

@ -3,8 +3,8 @@ import { Utils } from "../../../platform/misc/utils";
import { CipherService } from "../../abstractions/cipher.service"; import { CipherService } from "../../abstractions/cipher.service";
import { import {
Fido2AlgorithmIdentifier, Fido2AlgorithmIdentifier,
Fido2AutenticatorError, Fido2AuthenticatorError,
Fido2AutenticatorErrorCode, Fido2AuthenticatorErrorCode,
Fido2AuthenticatorGetAssertionParams, Fido2AuthenticatorGetAssertionParams,
Fido2AuthenticatorGetAssertionResult, Fido2AuthenticatorGetAssertionResult,
Fido2AuthenticatorMakeCredentialResult, Fido2AuthenticatorMakeCredentialResult,
@ -62,7 +62,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
this.logService?.warning( this.logService?.warning(
`[Fido2Authenticator] No compatible algorithms found, RP requested: ${requestedAlgorithms}` `[Fido2Authenticator] No compatible algorithms found, RP requested: ${requestedAlgorithms}`
); );
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.NotSupported); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.NotSupported);
} }
if ( if (
@ -74,7 +74,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
params.requireResidentKey params.requireResidentKey
)}` )}`
); );
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.Unknown); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.Unknown);
} }
if ( if (
@ -86,7 +86,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
params.requireUserVerification params.requireUserVerification
)}` )}`
); );
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.Unknown); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.Unknown);
} }
await userInterfaceSession.ensureUnlockedVault(); await userInterfaceSession.ensureUnlockedVault();
@ -100,7 +100,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
`[Fido2Authenticator] Aborting due to excluded credential found in vault.` `[Fido2Authenticator] Aborting due to excluded credential found in vault.`
); );
await userInterfaceSession.informExcludedCredential(existingCipherIds); await userInterfaceSession.informExcludedCredential(existingCipherIds);
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.NotAllowed); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.NotAllowed);
} }
let cipher: CipherView; let cipher: CipherView;
@ -120,7 +120,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
this.logService?.warning( this.logService?.warning(
`[Fido2Authenticator] Aborting because user confirmation was not recieved.` `[Fido2Authenticator] Aborting because user confirmation was not recieved.`
); );
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.NotAllowed); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.NotAllowed);
} }
try { try {
@ -138,7 +138,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
this.logService?.warning( this.logService?.warning(
`[Fido2Authenticator] Aborting because user verification was unsuccessful.` `[Fido2Authenticator] Aborting because user verification was unsuccessful.`
); );
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.NotAllowed); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.NotAllowed);
} }
fido2Credential = await createKeyView(params, keyPair.privateKey); fido2Credential = await createKeyView(params, keyPair.privateKey);
@ -150,7 +150,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
this.logService?.error( this.logService?.error(
`[Fido2Authenticator] Aborting because of unknown error when creating credential: ${error}` `[Fido2Authenticator] Aborting because of unknown error when creating credential: ${error}`
); );
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.Unknown); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.Unknown);
} }
const authData = await generateAuthData({ const authData = await generateAuthData({
@ -200,7 +200,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
params.requireUserVerification params.requireUserVerification
)}` )}`
); );
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.Unknown); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.Unknown);
} }
let cipherOptions: CipherView[]; let cipherOptions: CipherView[];
@ -222,7 +222,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
`[Fido2Authenticator] Aborting because no matching credentials were found in the vault.` `[Fido2Authenticator] Aborting because no matching credentials were found in the vault.`
); );
await userInterfaceSession.informCredentialNotFound(); await userInterfaceSession.informCredentialNotFound();
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.NotAllowed); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.NotAllowed);
} }
const response = await userInterfaceSession.pickCredential({ const response = await userInterfaceSession.pickCredential({
@ -237,7 +237,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
this.logService?.error( this.logService?.error(
`[Fido2Authenticator] Aborting because the selected credential could not be found.` `[Fido2Authenticator] Aborting because the selected credential could not be found.`
); );
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.NotAllowed); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.NotAllowed);
} }
if ( if (
@ -247,7 +247,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
this.logService?.warning( this.logService?.warning(
`[Fido2Authenticator] Aborting because user verification was unsuccessful.` `[Fido2Authenticator] Aborting because user verification was unsuccessful.`
); );
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.NotAllowed); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.NotAllowed);
} }
try { try {
@ -289,7 +289,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
this.logService?.error( this.logService?.error(
`[Fido2Authenticator] Aborting because of unknown error when asserting credential: ${error}` `[Fido2Authenticator] Aborting because of unknown error when asserting credential: ${error}`
); );
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.Unknown); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.Unknown);
} }
} finally { } finally {
userInterfaceSession.close(); userInterfaceSession.close();
@ -383,7 +383,7 @@ async function createKeyView(
keyValue: CryptoKey keyValue: CryptoKey
): Promise<Fido2CredentialView> { ): Promise<Fido2CredentialView> {
if (keyValue.algorithm.name !== "ECDSA" && (keyValue.algorithm as any).namedCurve !== "P-256") { if (keyValue.algorithm.name !== "ECDSA" && (keyValue.algorithm as any).namedCurve !== "P-256") {
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.Unknown); throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.Unknown);
} }
const pkcs8Key = await crypto.subtle.exportKey("pkcs8", keyValue); const pkcs8Key = await crypto.subtle.exportKey("pkcs8", keyValue);

View File

@ -5,8 +5,8 @@ import { AuthenticationStatus } from "../../../auth/enums/authentication-status"
import { ConfigServiceAbstraction } from "../../../platform/abstractions/config/config.service.abstraction"; import { ConfigServiceAbstraction } from "../../../platform/abstractions/config/config.service.abstraction";
import { Utils } from "../../../platform/misc/utils"; import { Utils } from "../../../platform/misc/utils";
import { import {
Fido2AutenticatorError, Fido2AuthenticatorError,
Fido2AutenticatorErrorCode, Fido2AuthenticatorErrorCode,
Fido2AuthenticatorGetAssertionResult, Fido2AuthenticatorGetAssertionResult,
Fido2AuthenticatorMakeCredentialResult, Fido2AuthenticatorMakeCredentialResult,
} from "../../abstractions/fido2/fido2-authenticator.service.abstraction"; } from "../../abstractions/fido2/fido2-authenticator.service.abstraction";
@ -181,7 +181,7 @@ describe("FidoAuthenticatorService", () => {
it("should throw error if authenticator throws InvalidState", async () => { it("should throw error if authenticator throws InvalidState", async () => {
const params = createParams(); const params = createParams();
authenticator.makeCredential.mockRejectedValue( authenticator.makeCredential.mockRejectedValue(
new Fido2AutenticatorError(Fido2AutenticatorErrorCode.InvalidState) new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.InvalidState)
); );
const result = async () => await client.createCredential(params, tab); const result = async () => await client.createCredential(params, tab);
@ -329,7 +329,7 @@ describe("FidoAuthenticatorService", () => {
it("should throw error if authenticator throws InvalidState", async () => { it("should throw error if authenticator throws InvalidState", async () => {
const params = createParams(); const params = createParams();
authenticator.getAssertion.mockRejectedValue( authenticator.getAssertion.mockRejectedValue(
new Fido2AutenticatorError(Fido2AutenticatorErrorCode.InvalidState) new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.InvalidState)
); );
const result = async () => await client.assertCredential(params, tab); const result = async () => await client.assertCredential(params, tab);

View File

@ -7,8 +7,8 @@ import { ConfigServiceAbstraction } from "../../../platform/abstractions/config/
import { LogService } from "../../../platform/abstractions/log.service"; import { LogService } from "../../../platform/abstractions/log.service";
import { Utils } from "../../../platform/misc/utils"; import { Utils } from "../../../platform/misc/utils";
import { import {
Fido2AutenticatorError, Fido2AuthenticatorError,
Fido2AutenticatorErrorCode, Fido2AuthenticatorErrorCode,
Fido2AuthenticatorGetAssertionParams, Fido2AuthenticatorGetAssertionParams,
Fido2AuthenticatorMakeCredentialsParams, Fido2AuthenticatorMakeCredentialsParams,
Fido2AuthenticatorService, Fido2AuthenticatorService,
@ -162,8 +162,8 @@ export class Fido2ClientService implements Fido2ClientServiceAbstraction {
} }
if ( if (
error instanceof Fido2AutenticatorError && error instanceof Fido2AuthenticatorError &&
error.errorCode === Fido2AutenticatorErrorCode.InvalidState error.errorCode === Fido2AuthenticatorErrorCode.InvalidState
) { ) {
this.logService?.warning(`[Fido2Client] Unknown error: ${error}`); this.logService?.warning(`[Fido2Client] Unknown error: ${error}`);
throw new DOMException("Unknown error occured.", "InvalidStateError"); throw new DOMException("Unknown error occured.", "InvalidStateError");
@ -268,8 +268,8 @@ export class Fido2ClientService implements Fido2ClientServiceAbstraction {
} }
if ( if (
error instanceof Fido2AutenticatorError && error instanceof Fido2AuthenticatorError &&
error.errorCode === Fido2AutenticatorErrorCode.InvalidState error.errorCode === Fido2AuthenticatorErrorCode.InvalidState
) { ) {
this.logService?.warning(`[Fido2Client] Unknown error: ${error}`); this.logService?.warning(`[Fido2Client] Unknown error: ${error}`);
throw new DOMException("Unknown error occured.", "InvalidStateError"); throw new DOMException("Unknown error occured.", "InvalidStateError");