diff --git a/apps/browser/src/autofill/fido2/utils/webauthn-utils.ts b/apps/browser/src/autofill/fido2/utils/webauthn-utils.ts index 07ffa553b07..795e35e1e80 100644 --- a/apps/browser/src/autofill/fido2/utils/webauthn-utils.ts +++ b/apps/browser/src/autofill/fido2/utils/webauthn-utils.ts @@ -27,9 +27,11 @@ export class WebauthnUtils { residentKey: keyOptions.authenticatorSelection?.residentKey, userVerification: keyOptions.authenticatorSelection?.userVerification, }, - challenge: Fido2Utils.bufferToString(keyOptions.challenge), + challenge: Fido2Utils.arrayToString( + Fido2Utils.bufferSourceToUint8Array(keyOptions.challenge), + ), excludeCredentials: keyOptions.excludeCredentials?.map((credential) => ({ - id: Fido2Utils.bufferToString(credential.id), + id: Fido2Utils.arrayToString(Fido2Utils.bufferSourceToUint8Array(credential.id)), transports: credential.transports, type: credential.type, })), @@ -48,7 +50,7 @@ export class WebauthnUtils { name: keyOptions.rp.name, }, user: { - id: Fido2Utils.bufferToString(keyOptions.user.id), + id: Fido2Utils.arrayToString(Fido2Utils.bufferSourceToUint8Array(keyOptions.user.id)), displayName: keyOptions.user.displayName, name: keyOptions.user.name, }, @@ -60,19 +62,19 @@ export class WebauthnUtils { static mapCredentialRegistrationResult(result: CreateCredentialResult): PublicKeyCredential { const credential = { id: result.credentialId, - rawId: Fido2Utils.stringToBuffer(result.credentialId), + rawId: Fido2Utils.stringToArray(result.credentialId).buffer, type: "public-key", authenticatorAttachment: "platform", response: { - clientDataJSON: Fido2Utils.stringToBuffer(result.clientDataJSON), - attestationObject: Fido2Utils.stringToBuffer(result.attestationObject), + clientDataJSON: Fido2Utils.stringToArray(result.clientDataJSON).buffer, + attestationObject: Fido2Utils.stringToArray(result.attestationObject).buffer, getAuthenticatorData(): ArrayBuffer { - return Fido2Utils.stringToBuffer(result.authData); + return Fido2Utils.stringToArray(result.authData).buffer; }, getPublicKey(): ArrayBuffer { - return Fido2Utils.stringToBuffer(result.publicKey); + return Fido2Utils.stringToArray(result.publicKey).buffer; }, getPublicKeyAlgorithm(): number { @@ -110,8 +112,12 @@ export class WebauthnUtils { return { allowedCredentialIds: - keyOptions.allowCredentials?.map((c) => Fido2Utils.bufferToString(c.id)) ?? [], - challenge: Fido2Utils.bufferToString(keyOptions.challenge), + keyOptions.allowCredentials?.map((c) => + Fido2Utils.arrayToString(Fido2Utils.bufferSourceToUint8Array(c.id)), + ) ?? [], + challenge: Fido2Utils.arrayToString( + Fido2Utils.bufferSourceToUint8Array(keyOptions.challenge), + ), rpId: keyOptions.rpId, userVerification: keyOptions.userVerification, timeout: keyOptions.timeout, @@ -123,13 +129,13 @@ export class WebauthnUtils { static mapCredentialAssertResult(result: AssertCredentialResult): PublicKeyCredential { const credential = { id: result.credentialId, - rawId: Fido2Utils.stringToBuffer(result.credentialId), + rawId: Fido2Utils.stringToArray(result.credentialId).buffer, type: "public-key", response: { - authenticatorData: Fido2Utils.stringToBuffer(result.authenticatorData), - clientDataJSON: Fido2Utils.stringToBuffer(result.clientDataJSON), - signature: Fido2Utils.stringToBuffer(result.signature), - userHandle: Fido2Utils.stringToBuffer(result.userHandle), + authenticatorData: Fido2Utils.stringToArray(result.authenticatorData).buffer, + clientDataJSON: Fido2Utils.stringToArray(result.clientDataJSON).buffer, + signature: Fido2Utils.stringToArray(result.signature).buffer, + userHandle: Fido2Utils.stringToArray(result.userHandle).buffer, } as AuthenticatorAssertionResponse, getClientExtensionResults: () => ({}), authenticatorAttachment: "platform", diff --git a/apps/desktop/src/autofill/modal/credentials/fido2-create.component.ts b/apps/desktop/src/autofill/modal/credentials/fido2-create.component.ts index d5b4984fae5..87452664729 100644 --- a/apps/desktop/src/autofill/modal/credentials/fido2-create.component.ts +++ b/apps/desktop/src/autofill/modal/credentials/fido2-create.component.ts @@ -165,9 +165,7 @@ export class Fido2CreateComponent implements OnInit, OnDestroy { return; } - const userHandle = Fido2Utils.bufferToString( - new Uint8Array(lastRegistrationRequest.userHandle), - ); + const userHandle = Fido2Utils.arrayToString(new Uint8Array(lastRegistrationRequest.userHandle)); this.ciphers$ = combineLatest([ this.accountService.activeAccount$.pipe(map((a) => a?.id)), diff --git a/apps/desktop/src/autofill/services/desktop-autofill.service.ts b/apps/desktop/src/autofill/services/desktop-autofill.service.ts index 24052a20b3c..b84720bb3c1 100644 --- a/apps/desktop/src/autofill/services/desktop-autofill.service.ts +++ b/apps/desktop/src/autofill/services/desktop-autofill.service.ts @@ -380,13 +380,13 @@ export class DesktopAutofillService implements OnDestroy { if ("credentialId" in request) { allowedCredentials = [ { - id: new Uint8Array(request.credentialId).buffer, + id: new Uint8Array(request.credentialId), type: "public-key" as const, }, ]; } else { allowedCredentials = request.allowedCredentials.map((credentialId) => ({ - id: new Uint8Array(credentialId).buffer, + id: new Uint8Array(credentialId), type: "public-key" as const, })); } diff --git a/libs/common/src/platform/abstractions/fido2/fido2-authenticator.service.abstraction.ts b/libs/common/src/platform/abstractions/fido2/fido2-authenticator.service.abstraction.ts index 427266522e9..a4a75d277b7 100644 --- a/libs/common/src/platform/abstractions/fido2/fido2-authenticator.service.abstraction.ts +++ b/libs/common/src/platform/abstractions/fido2/fido2-authenticator.service.abstraction.ts @@ -68,7 +68,7 @@ export class Fido2AuthenticatorError extends Error { } export interface PublicKeyCredentialDescriptor { - id: ArrayBuffer; + id: Uint8Array; transports?: ("ble" | "hybrid" | "internal" | "nfc" | "usb")[]; type: "public-key"; } @@ -89,7 +89,7 @@ export interface Fido2AuthenticatorMakeCredentialsParams { }; /** The user account’s PublicKeyCredentialUserEntity, containing the user handle given by the Relying Party. */ userEntity: { - id: BufferSource; + id: Uint8Array; name?: string; displayName?: string; icon?: string; @@ -120,10 +120,10 @@ export interface Fido2AuthenticatorMakeCredentialsParams { } export interface Fido2AuthenticatorMakeCredentialResult { - credentialId: BufferSource; - attestationObject: BufferSource; - authData: BufferSource; - publicKey: BufferSource; + credentialId: Uint8Array; + attestationObject: Uint8Array; + authData: Uint8Array; + publicKey: Uint8Array; publicKeyAlgorithm: number; } @@ -153,9 +153,9 @@ export interface Fido2AuthenticatorGetAssertionParams { export interface Fido2AuthenticatorGetAssertionResult { selectedCredential: { - id: ArrayBuffer; - userHandle?: ArrayBuffer; + id: Uint8Array; + userHandle?: Uint8Array; }; - authenticatorData: ArrayBuffer; - signature: ArrayBuffer; + authenticatorData: Uint8Array; + signature: Uint8Array; } diff --git a/libs/common/src/platform/services/fido2/credential-id-utils.spec.ts b/libs/common/src/platform/services/fido2/credential-id-utils.spec.ts index 1f2217ccd63..76e068ac01c 100644 --- a/libs/common/src/platform/services/fido2/credential-id-utils.spec.ts +++ b/libs/common/src/platform/services/fido2/credential-id-utils.spec.ts @@ -9,7 +9,7 @@ describe("credential-id-utils", () => { new Uint8Array([ 0x08, 0xd7, 0x0b, 0x74, 0xe9, 0xf5, 0x45, 0x22, 0xa4, 0x25, 0xe5, 0xdc, 0xd4, 0x01, 0x07, 0xe7, - ]).buffer, + ]), ); }); @@ -20,7 +20,7 @@ describe("credential-id-utils", () => { new Uint8Array([ 0x08, 0xd7, 0x0b, 0x74, 0xe9, 0xf5, 0x45, 0x22, 0xa4, 0x25, 0xe5, 0xdc, 0xd4, 0x01, 0x07, 0xe7, - ]).buffer, + ]), ); }); diff --git a/libs/common/src/platform/services/fido2/credential-id-utils.ts b/libs/common/src/platform/services/fido2/credential-id-utils.ts index 08ea33114f5..7bd662cf540 100644 --- a/libs/common/src/platform/services/fido2/credential-id-utils.ts +++ b/libs/common/src/platform/services/fido2/credential-id-utils.ts @@ -3,13 +3,13 @@ import { Fido2Utils } from "./fido2-utils"; import { guidToRawFormat } from "./guid-utils"; -export function parseCredentialId(encodedCredentialId: string): ArrayBuffer { +export function parseCredentialId(encodedCredentialId: string): Uint8Array { try { if (encodedCredentialId.startsWith("b64.")) { - return Fido2Utils.stringToBuffer(encodedCredentialId.slice(4)); + return Fido2Utils.stringToArray(encodedCredentialId.slice(4)); } - return guidToRawFormat(encodedCredentialId).buffer; + return guidToRawFormat(encodedCredentialId); } catch { return undefined; } @@ -18,16 +18,16 @@ export function parseCredentialId(encodedCredentialId: string): ArrayBuffer { /** * Compares two credential IDs for equality. */ -export function compareCredentialIds(a: ArrayBuffer, b: ArrayBuffer): boolean { +export function compareCredentialIds( + a: Uint8Array, + b: Uint8Array, +): boolean { if (a.byteLength !== b.byteLength) { return false; } - const viewA = new Uint8Array(a); - const viewB = new Uint8Array(b); - - for (let i = 0; i < viewA.length; i++) { - if (viewA[i] !== viewB[i]) { + for (let i = 0; i < a.length; i++) { + if (a[i] !== b[i]) { return false; } } diff --git a/libs/common/src/platform/services/fido2/fido2-authenticator.service.spec.ts b/libs/common/src/platform/services/fido2/fido2-authenticator.service.spec.ts index 6223e4274bf..d76bf74f4e9 100644 --- a/libs/common/src/platform/services/fido2/fido2-authenticator.service.spec.ts +++ b/libs/common/src/platform/services/fido2/fido2-authenticator.service.spec.ts @@ -246,7 +246,7 @@ describe("FidoAuthenticatorService", () => { expect(userInterfaceSession.confirmNewCredential).toHaveBeenCalledWith({ credentialName: params.rpEntity.name, userName: params.userEntity.name, - userHandle: Fido2Utils.bufferToString(params.userEntity.id), + userHandle: Fido2Utils.arrayToString(params.userEntity.id), userVerification, rpId: params.rpEntity.id, } as NewCredentialParams); @@ -278,7 +278,7 @@ describe("FidoAuthenticatorService", () => { keyCurve: "P-256", rpId: params.rpEntity.id, rpName: params.rpEntity.name, - userHandle: Fido2Utils.bufferToString(params.userEntity.id), + userHandle: Fido2Utils.arrayToString(params.userEntity.id), userName: params.userEntity.name, counter: 0, userDisplayName: params.userEntity.displayName, @@ -669,8 +669,8 @@ describe("FidoAuthenticatorService", () => { const init = async () => { keyPair = await createKeyPair(); credentialIds = [Utils.newGuid(), Utils.newGuid()]; - const keyValue = Fido2Utils.bufferToString( - await crypto.subtle.exportKey("pkcs8", keyPair.privateKey), + const keyValue = Fido2Utils.arrayToString( + new Uint8Array(await crypto.subtle.exportKey("pkcs8", keyPair.privateKey)), ); ciphers = credentialIds.map((id) => createCipherView( @@ -735,7 +735,7 @@ describe("FidoAuthenticatorService", () => { expect(result.selectedCredential.id).toEqual(parseCredentialId(selectedCredentialId)); expect(result.selectedCredential.userHandle).toEqual( - Fido2Utils.stringToBuffer(fido2Credentials[0].userHandle), + Fido2Utils.stringToArray(fido2Credentials[0].userHandle), ); expect(rpIdHash).toEqual( new Uint8Array([ @@ -772,7 +772,7 @@ describe("FidoAuthenticatorService", () => { const counter = result.authenticatorData.slice(33, 37); expect(counter).toEqual(new Uint8Array([0, 0, 0x23, 0x29])); // double check that the counter doesn't change - const signature = Fido2Utils.bufferToString(result.signature); + const signature = Fido2Utils.arrayToString(result.signature); if (signatures.has(signature)) { throw new Error("Found duplicate signature"); } @@ -847,7 +847,7 @@ function createCipherView( fido2CredentialView.rpId = fido2Credential.rpId ?? RpId; fido2CredentialView.counter = fido2Credential.counter ?? 0; fido2CredentialView.userHandle = - fido2Credential.userHandle ?? Fido2Utils.bufferToString(randomBytes(16)); + fido2Credential.userHandle ?? Fido2Utils.arrayToString(randomBytes(16)); fido2CredentialView.userName = fido2Credential.userName; fido2CredentialView.keyAlgorithm = fido2Credential.keyAlgorithm ?? "ECDSA"; fido2CredentialView.keyCurve = fido2Credential.keyCurve ?? "P-256"; @@ -867,7 +867,7 @@ async function createClientDataHash() { const clientData = encoder.encode( JSON.stringify({ type: "webauthn.create", - challenge: Fido2Utils.bufferToString(randomBytes(16)), + challenge: Fido2Utils.arrayToString(randomBytes(16)), origin: RpId, crossOrigin: false, }), diff --git a/libs/common/src/platform/services/fido2/fido2-authenticator.service.ts b/libs/common/src/platform/services/fido2/fido2-authenticator.service.ts index 1b150207290..9207e0ac95c 100644 --- a/libs/common/src/platform/services/fido2/fido2-authenticator.service.ts +++ b/libs/common/src/platform/services/fido2/fido2-authenticator.service.ts @@ -127,11 +127,11 @@ export class Fido2AuthenticatorService< let keyPair: CryptoKeyPair; let userVerified = false; let credentialId: string; - let pubKeyDer: ArrayBuffer; + let pubKeyDer: Uint8Array; const response = await userInterfaceSession.confirmNewCredential({ credentialName: params.rpEntity.name, userName: params.userEntity.name, - userHandle: Fido2Utils.bufferToString(params.userEntity.id), + userHandle: Fido2Utils.arrayToString(params.userEntity.id), userVerification: params.requireUserVerification, rpId: params.rpEntity.id, }); @@ -147,7 +147,7 @@ export class Fido2AuthenticatorService< try { keyPair = await createKeyPair(); - pubKeyDer = await crypto.subtle.exportKey("spki", keyPair.publicKey); + pubKeyDer = new Uint8Array(await crypto.subtle.exportKey("spki", keyPair.publicKey)); const activeUserId = await firstValueFrom( this.accountService.activeAccount$.pipe(getUserId), ); @@ -349,7 +349,7 @@ export class Fido2AuthenticatorService< authenticatorData, selectedCredential: { id: parseCredentialId(selectedCredentialId), - userHandle: Fido2Utils.stringToBuffer(selectedFido2Credential.userHandle), + userHandle: Fido2Utils.stringToArray(selectedFido2Credential.userHandle), }, signature, }; @@ -487,15 +487,15 @@ async function createKeyView( throw new Fido2AuthenticatorError(Fido2AuthenticatorErrorCode.Unknown); } - const pkcs8Key = await crypto.subtle.exportKey("pkcs8", keyValue); + const pkcs8Key = new Uint8Array(await crypto.subtle.exportKey("pkcs8", keyValue)); const fido2Credential = new Fido2CredentialView(); fido2Credential.credentialId = Utils.newGuid(); fido2Credential.keyType = "public-key"; fido2Credential.keyAlgorithm = "ECDSA"; fido2Credential.keyCurve = "P-256"; - fido2Credential.keyValue = Fido2Utils.bufferToString(pkcs8Key); + fido2Credential.keyValue = Fido2Utils.arrayToString(pkcs8Key); fido2Credential.rpId = params.rpEntity.id; - fido2Credential.userHandle = Fido2Utils.bufferToString(params.userEntity.id); + fido2Credential.userHandle = Fido2Utils.arrayToString(params.userEntity.id); fido2Credential.userName = params.userEntity.name; fido2Credential.counter = 0; fido2Credential.rpName = params.rpEntity.name; @@ -509,7 +509,7 @@ async function createKeyView( async function getPrivateKeyFromFido2Credential( fido2Credential: Fido2CredentialView, ): Promise { - const keyBuffer = Fido2Utils.stringToBuffer(fido2Credential.keyValue); + const keyBuffer = Fido2Utils.stringToArray(fido2Credential.keyValue); return await crypto.subtle.importKey( "pkcs8", new Uint8Array(keyBuffer), @@ -535,7 +535,10 @@ async function generateAuthData(params: AuthDataParams) { const authData: Array = []; const rpIdHash = new Uint8Array( - await crypto.subtle.digest({ name: "SHA-256" }, Utils.fromByteStringToArray(params.rpId)), + await crypto.subtle.digest( + { name: "SHA-256" }, + Utils.fromByteStringToArray(params.rpId) as BufferSource, + ), ); authData.push(...rpIdHash); diff --git a/libs/common/src/platform/services/fido2/fido2-client.service.spec.ts b/libs/common/src/platform/services/fido2/fido2-client.service.spec.ts index 7b298110040..08f8abb1549 100644 --- a/libs/common/src/platform/services/fido2/fido2-client.service.spec.ts +++ b/libs/common/src/platform/services/fido2/fido2-client.service.spec.ts @@ -572,9 +572,9 @@ describe("FidoAuthenticatorService", () => { describe("assert non-discoverable credential", () => { it("should call authenticator.assertCredential", async () => { const allowedCredentialIds = [ - Fido2Utils.bufferToString(guidToRawFormat(Utils.newGuid())), - Fido2Utils.bufferToString(guidToRawFormat(Utils.newGuid())), - Fido2Utils.bufferToString(Utils.fromByteStringToArray("not-a-guid")), + Fido2Utils.arrayToString(guidToRawFormat(Utils.newGuid())), + Fido2Utils.arrayToString(guidToRawFormat(Utils.newGuid())), + Fido2Utils.arrayToString(Utils.fromByteStringToArray("not-a-guid")), ]; const params = createParams({ userVerification: "required", @@ -590,13 +590,13 @@ describe("FidoAuthenticatorService", () => { rpId: RpId, allowCredentialDescriptorList: [ expect.objectContaining({ - id: Fido2Utils.stringToBuffer(allowedCredentialIds[0]), + id: Fido2Utils.stringToArray(allowedCredentialIds[0]), }), expect.objectContaining({ - id: Fido2Utils.stringToBuffer(allowedCredentialIds[1]), + id: Fido2Utils.stringToArray(allowedCredentialIds[1]), }), expect.objectContaining({ - id: Fido2Utils.stringToBuffer(allowedCredentialIds[2]), + id: Fido2Utils.stringToArray(allowedCredentialIds[2]), }), ], }), @@ -688,7 +688,7 @@ describe("FidoAuthenticatorService", () => { function createParams(params: Partial = {}): AssertCredentialParams { return { allowedCredentialIds: params.allowedCredentialIds ?? [], - challenge: params.challenge ?? Fido2Utils.bufferToString(randomBytes(16)), + challenge: params.challenge ?? Fido2Utils.arrayToString(randomBytes(16)), origin: params.origin ?? Origin, rpId: params.rpId ?? RpId, timeout: params.timeout, diff --git a/libs/common/src/platform/services/fido2/fido2-client.service.ts b/libs/common/src/platform/services/fido2/fido2-client.service.ts index 8fabed450f8..b80023b8bc2 100644 --- a/libs/common/src/platform/services/fido2/fido2-client.service.ts +++ b/libs/common/src/platform/services/fido2/fido2-client.service.ts @@ -130,7 +130,7 @@ export class Fido2ClientService< throw new DOMException("Invalid 'sameOriginWithAncestors' value", "NotAllowedError"); } - const userId = Fido2Utils.stringToBuffer(params.user.id); + const userId = Fido2Utils.stringToArray(params.user.id); if (userId.byteLength < 1 || userId.byteLength > 64) { this.logService?.warning( `[Fido2Client] Invalid 'user.id' length: ${params.user.id} (${userId.byteLength})`, @@ -195,7 +195,7 @@ export class Fido2ClientService< const makeCredentialParams = mapToMakeCredentialParams({ params, credTypesAndPubKeyAlgs, - clientDataHash, + clientDataHash: new Uint8Array(clientDataHash), }); // Set timeout before invoking authenticator @@ -255,11 +255,11 @@ export class Fido2ClientService< timeoutSubscription?.unsubscribe(); return { - credentialId: Fido2Utils.bufferToString(makeCredentialResult.credentialId), - attestationObject: Fido2Utils.bufferToString(makeCredentialResult.attestationObject), - authData: Fido2Utils.bufferToString(makeCredentialResult.authData), - clientDataJSON: Fido2Utils.bufferToString(clientDataJSONBytes), - publicKey: Fido2Utils.bufferToString(makeCredentialResult.publicKey), + credentialId: Fido2Utils.arrayToString(makeCredentialResult.credentialId), + attestationObject: Fido2Utils.arrayToString(makeCredentialResult.attestationObject), + authData: Fido2Utils.arrayToString(makeCredentialResult.authData), + clientDataJSON: Fido2Utils.arrayToString(clientDataJSONBytes), + publicKey: Fido2Utils.arrayToString(makeCredentialResult.publicKey), publicKeyAlgorithm: makeCredentialResult.publicKeyAlgorithm, transports: ["internal", "hybrid"], extensions: { credProps }, @@ -383,7 +383,7 @@ export class Fido2ClientService< params: AssertCredentialParams, tab: ParentWindowReference, abortController: AbortController, - clientDataJSONBytes: Uint8Array, + clientDataJSONBytes: Uint8Array, ): Promise { let getAssertionResult; let assumeUserPresence = false; @@ -414,7 +414,7 @@ export class Fido2ClientService< } params.allowedCredentialIds = [ - Fido2Utils.bufferToString(guidToRawFormat(requestResult.credentialId)), + Fido2Utils.arrayToString(guidToRawFormat(requestResult.credentialId)), ]; assumeUserPresence = true; @@ -441,17 +441,17 @@ export class Fido2ClientService< private generateAssertCredentialResult( getAssertionResult: Fido2AuthenticatorGetAssertionResult, - clientDataJSONBytes: Uint8Array, + clientDataJSONBytes: Uint8Array, ): AssertCredentialResult { return { - authenticatorData: Fido2Utils.bufferToString(getAssertionResult.authenticatorData), - clientDataJSON: Fido2Utils.bufferToString(clientDataJSONBytes), - credentialId: Fido2Utils.bufferToString(getAssertionResult.selectedCredential.id), + authenticatorData: Fido2Utils.arrayToString(getAssertionResult.authenticatorData), + clientDataJSON: Fido2Utils.arrayToString(clientDataJSONBytes), + credentialId: Fido2Utils.arrayToString(getAssertionResult.selectedCredential.id), userHandle: getAssertionResult.selectedCredential.userHandle !== undefined - ? Fido2Utils.bufferToString(getAssertionResult.selectedCredential.userHandle) + ? Fido2Utils.arrayToString(getAssertionResult.selectedCredential.userHandle) : undefined, - signature: Fido2Utils.bufferToString(getAssertionResult.signature), + signature: Fido2Utils.arrayToString(getAssertionResult.signature), }; } @@ -489,11 +489,11 @@ function mapToMakeCredentialParams({ }: { params: CreateCredentialParams; credTypesAndPubKeyAlgs: PublicKeyCredentialParam[]; - clientDataHash: ArrayBuffer; + clientDataHash: Uint8Array; }): Fido2AuthenticatorMakeCredentialsParams { const excludeCredentialDescriptorList: PublicKeyCredentialDescriptor[] = params.excludeCredentials?.map((credential) => ({ - id: Fido2Utils.stringToBuffer(credential.id), + id: Fido2Utils.stringToArray(credential.id), transports: credential.transports, type: credential.type, })) ?? []; @@ -525,7 +525,7 @@ function mapToMakeCredentialParams({ name: params.rp.name, }, userEntity: { - id: Fido2Utils.stringToBuffer(params.user.id), + id: Fido2Utils.stringToArray(params.user.id), displayName: params.user.displayName, name: params.user.name, }, @@ -547,7 +547,7 @@ function mapToGetAssertionParams({ }): Fido2AuthenticatorGetAssertionParams { const allowCredentialDescriptorList: PublicKeyCredentialDescriptor[] = params.allowedCredentialIds.map((id) => ({ - id: Fido2Utils.stringToBuffer(id), + id: Fido2Utils.stringToArray(id), type: "public-key", })); diff --git a/libs/common/src/platform/services/fido2/fido2-utils.ts b/libs/common/src/platform/services/fido2/fido2-utils.ts index 8efd4734d81..91a772a2b5f 100644 --- a/libs/common/src/platform/services/fido2/fido2-utils.ts +++ b/libs/common/src/platform/services/fido2/fido2-utils.ts @@ -42,18 +42,18 @@ export class Fido2Utils { }; } - static bufferToString(bufferSource: BufferSource): string { - return Fido2Utils.fromBufferToB64(Fido2Utils.bufferSourceToUint8Array(bufferSource)) + static arrayToString(array: Uint8Array): string { + return Fido2Utils.fromBufferToB64(Fido2Utils.bufferSourceToUint8Array(array)) .replace(/\+/g, "-") .replace(/\//g, "_") .replace(/=/g, ""); } - static stringToBuffer(str: string): ArrayBuffer { - return Fido2Utils.fromB64ToArray(Fido2Utils.fromUrlB64ToB64(str)).buffer; + static stringToArray(str: string): Uint8Array { + return Fido2Utils.fromB64ToArray(Fido2Utils.fromUrlB64ToB64(str)); } - static bufferSourceToUint8Array(bufferSource: BufferSource): Uint8Array { + static bufferSourceToUint8Array(bufferSource: BufferSource): Uint8Array { if (Fido2Utils.isArrayBuffer(bufferSource)) { return new Uint8Array(bufferSource); } else { @@ -70,7 +70,7 @@ export class Fido2Utils { return b64Str.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ""); } - static fromBufferToB64(buffer: ArrayBuffer): string { + static fromBufferToB64(buffer: Uint8Array | ArrayBuffer): string { if (buffer == null) { return null; } @@ -83,7 +83,7 @@ export class Fido2Utils { return globalThis.btoa(binary); } - static fromB64ToArray(str: string): Uint8Array { + static fromB64ToArray(str: string): Uint8Array { if (str == null) { return null; } diff --git a/libs/common/src/platform/services/file-upload/azure-file-upload.service.ts b/libs/common/src/platform/services/file-upload/azure-file-upload.service.ts index 02adcfee22e..8f7626b3c06 100644 --- a/libs/common/src/platform/services/file-upload/azure-file-upload.service.ts +++ b/libs/common/src/platform/services/file-upload/azure-file-upload.service.ts @@ -31,7 +31,7 @@ export class AzureFileUploadService { }); const request = new Request(url, { - body: data.buffer, + body: data.buffer as BodyInit, cache: "no-store", method: "PUT", headers: headers, diff --git a/libs/common/src/platform/services/file-upload/bitwarden-file-upload.service.ts b/libs/common/src/platform/services/file-upload/bitwarden-file-upload.service.ts index 93594405302..b129f1d5eeb 100644 --- a/libs/common/src/platform/services/file-upload/bitwarden-file-upload.service.ts +++ b/libs/common/src/platform/services/file-upload/bitwarden-file-upload.service.ts @@ -10,7 +10,9 @@ export class BitwardenFileUploadService { const fd = new FormData(); if (Utils.isBrowser) { - const blob = new Blob([encryptedFileData.buffer], { type: "application/octet-stream" }); + const blob = new Blob([encryptedFileData.buffer as BlobPart], { + type: "application/octet-stream", + }); fd.append("data", blob, encryptedFileName); } else if (Utils.isNode) { fd.append( diff --git a/libs/key-management-ui/src/lock/services/default-webauthn-prf-unlock.service.ts b/libs/key-management-ui/src/lock/services/default-webauthn-prf-unlock.service.ts index b3bbf392d0a..ae3d4584d6e 100644 --- a/libs/key-management-ui/src/lock/services/default-webauthn-prf-unlock.service.ts +++ b/libs/key-management-ui/src/lock/services/default-webauthn-prf-unlock.service.ts @@ -154,7 +154,7 @@ export class DefaultWebAuthnPrfUnlockService implements WebAuthnPrfUnlockService allowCredentials: credentials.map(({ credentialId, transports }) => { // The credential ID is already base64url encoded from login storage // We need to decode it to ArrayBuffer for WebAuthn - const decodedId = Fido2Utils.stringToBuffer(credentialId); + const decodedId = Fido2Utils.stringToArray(credentialId); return { type: "public-key", id: decodedId,