From 52ce5f3a2f3790042793ac73ddad70cd1b578a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20S=C3=B3jko?= Date: Mon, 23 Jan 2023 11:28:36 +0100 Subject: [PATCH] fix(auth): upgrade simplewebauthn types --- .../Controller/AuthenticatorsController.ts | 4 +-- .../Authenticator/AuthenticatorProps.ts | 4 +-- ...uthenticatorAuthenticationResponse.spec.ts | 12 ++++---- ...rifyAuthenticatorAuthenticationResponse.ts | 6 ++-- ...yAuthenticatorAuthenticationResponseDTO.ts | 2 +- ...yAuthenticatorRegistrationResponse.spec.ts | 28 +++++++++---------- ...VerifyAuthenticatorRegistrationResponse.ts | 2 +- ...ifyAuthenticatorRegistrationResponseDTO.ts | 2 +- ...atorAuthenticationResponseRequestParams.ts | 2 +- ...icatorRegistrationResponseRequestParams.ts | 2 +- ...nversifyExpressAuthenticatorsController.ts | 4 +-- .../src/Infra/TypeORM/TypeORMAuthenticator.ts | 4 +-- 12 files changed, 36 insertions(+), 36 deletions(-) diff --git a/packages/auth/src/Controller/AuthenticatorsController.ts b/packages/auth/src/Controller/AuthenticatorsController.ts index e819b29e8..059a25e56 100644 --- a/packages/auth/src/Controller/AuthenticatorsController.ts +++ b/packages/auth/src/Controller/AuthenticatorsController.ts @@ -93,7 +93,7 @@ export class AuthenticatorsController { const result = await this.verifyAuthenticatorRegistrationResponse.execute({ userUuid: params.userUuid, name: params.name, - registrationCredential: params.registrationCredential, + attestationResponse: params.attestationResponse, }) if (result.isFailed()) { @@ -142,7 +142,7 @@ export class AuthenticatorsController { ): Promise { const result = await this.verifyAuthenticatorAuthenticationResponse.execute({ userUuid: params.userUuid, - authenticationCredential: params.authenticationCredential, + authenticatorResponse: params.authenticatorResponse, }) if (result.isFailed()) { diff --git a/packages/auth/src/Domain/Authenticator/AuthenticatorProps.ts b/packages/auth/src/Domain/Authenticator/AuthenticatorProps.ts index def60bae7..5f6573e75 100644 --- a/packages/auth/src/Domain/Authenticator/AuthenticatorProps.ts +++ b/packages/auth/src/Domain/Authenticator/AuthenticatorProps.ts @@ -3,8 +3,8 @@ import { Dates, Uuid } from '@standardnotes/domain-core' export interface AuthenticatorProps { name: string userUuid: Uuid - credentialId: Buffer - credentialPublicKey: Buffer + credentialId: Uint8Array + credentialPublicKey: Uint8Array counter: number credentialDeviceType: string credentialBackedUp: boolean diff --git a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts index c025a68ed..319de1225 100644 --- a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts +++ b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts @@ -49,7 +49,7 @@ describe('VerifyAuthenticatorAuthenticationResponse', () => { const result = await useCase.execute({ userUuid: 'invalid', - authenticationCredential: { + authenticatorResponse: { authenticatorAttachment: 'platform', clientExtensionResults: {}, id: 'id', @@ -77,7 +77,7 @@ describe('VerifyAuthenticatorAuthenticationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', - authenticationCredential: { + authenticatorResponse: { authenticatorAttachment: 'platform', clientExtensionResults: {}, id: 'id', @@ -105,7 +105,7 @@ describe('VerifyAuthenticatorAuthenticationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', - authenticationCredential: { + authenticatorResponse: { authenticatorAttachment: 'platform', clientExtensionResults: {}, id: 'id', @@ -134,7 +134,7 @@ describe('VerifyAuthenticatorAuthenticationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', - authenticationCredential: { + authenticatorResponse: { authenticatorAttachment: 'platform', clientExtensionResults: {}, id: 'id', @@ -167,7 +167,7 @@ describe('VerifyAuthenticatorAuthenticationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', - authenticationCredential: { + authenticatorResponse: { authenticatorAttachment: 'platform', clientExtensionResults: {}, id: 'id', @@ -203,7 +203,7 @@ describe('VerifyAuthenticatorAuthenticationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', - authenticationCredential: { + authenticatorResponse: { authenticatorAttachment: 'platform', clientExtensionResults: {}, id: 'id', diff --git a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.ts b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.ts index c4f481b05..2d884d270 100644 --- a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.ts +++ b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.ts @@ -27,18 +27,18 @@ export class VerifyAuthenticatorAuthenticationResponse implements UseCaseInterfa const authenticator = await this.authenticatorRepository.findByUserUuidAndCredentialId( userUuid, - Buffer.from(dto.authenticationCredential.id as string), + Buffer.from(dto.authenticatorResponse.id as string), ) if (!authenticator) { return Result.fail( - `Could not verify authenticator authentication response: authenticator ${dto.authenticationCredential.id} not found`, + `Could not verify authenticator authentication response: authenticator ${dto.authenticatorResponse.id} not found`, ) } let verification: VerifiedAuthenticationResponse try { verification = await verifyAuthenticationResponse({ - credential: dto.authenticationCredential, + response: dto.authenticatorResponse, expectedChallenge: authenticatorChallenge.props.challenge.toString(), expectedOrigin: `https://${this.relyingPartyId}`, expectedRPID: this.relyingPartyId, diff --git a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponseDTO.ts b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponseDTO.ts index 950f625e6..e097d2848 100644 --- a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponseDTO.ts +++ b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponseDTO.ts @@ -1,4 +1,4 @@ export interface VerifyAuthenticatorAuthenticationResponseDTO { userUuid: string - authenticationCredential: Record + authenticatorResponse: Record } diff --git a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.spec.ts b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.spec.ts index a02d55d23..4855c25f5 100644 --- a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.spec.ts +++ b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.spec.ts @@ -37,7 +37,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: 'invalid', name: 'name', - registrationCredential: { + attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), response: { @@ -60,7 +60,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', name: '', - registrationCredential: { + attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), response: { @@ -83,7 +83,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', name: 'name', - registrationCredential: { + attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), response: { @@ -115,8 +115,8 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { counter: 1, credentialBackedUp: true, credentialDeviceType: 'singleDevice', - credentialID: Buffer.from('test'), - credentialPublicKey: Buffer.from('test'), + credentialID: Uint8Array.from([1, 2, 3]), + credentialPublicKey: Uint8Array.from([1, 2, 3]), }, } as jest.Mocked) }) @@ -124,7 +124,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', name: 'name', - registrationCredential: { + attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), response: { @@ -158,7 +158,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', name: 'name', - registrationCredential: { + attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), response: { @@ -194,7 +194,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', name: 'name', - registrationCredential: { + attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), response: { @@ -230,8 +230,8 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { counter: 1, credentialBackedUp: true, credentialDeviceType: 'singleDevice', - credentialID: Buffer.from('test'), - credentialPublicKey: Buffer.from('test'), + credentialID: Uint8Array.from([1, 2, 3]), + credentialPublicKey: Uint8Array.from([1, 2, 3]), }, } as jest.Mocked) }) @@ -244,7 +244,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', name: 'name', - registrationCredential: { + attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), response: { @@ -279,8 +279,8 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { counter: 1, credentialBackedUp: true, credentialDeviceType: 'singleDevice', - credentialID: Buffer.from('test'), - credentialPublicKey: Buffer.from('test'), + credentialID: Uint8Array.from([1, 2, 3]), + credentialPublicKey: Uint8Array.from([1, 2, 3]), }, } as jest.Mocked) }) @@ -288,7 +288,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', name: 'name', - registrationCredential: { + attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), response: { diff --git a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.ts b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.ts index a907668fc..da923caf6 100644 --- a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.ts +++ b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.ts @@ -33,7 +33,7 @@ export class VerifyAuthenticatorRegistrationResponse implements UseCaseInterface let verification: VerifiedRegistrationResponse try { verification = await verifyRegistrationResponse({ - credential: dto.registrationCredential, + response: dto.attestationResponse, expectedChallenge: authenticatorChallenge.props.challenge.toString(), expectedOrigin: `https://${this.relyingPartyId}`, expectedRPID: this.relyingPartyId, diff --git a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponseDTO.ts b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponseDTO.ts index cdc82a3df..358c450d9 100644 --- a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponseDTO.ts +++ b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponseDTO.ts @@ -1,5 +1,5 @@ export interface VerifyAuthenticatorRegistrationResponseDTO { userUuid: string name: string - registrationCredential: Record + attestationResponse: Record } diff --git a/packages/auth/src/Infra/Http/Request/VerifyAuthenticatorAuthenticationResponseRequestParams.ts b/packages/auth/src/Infra/Http/Request/VerifyAuthenticatorAuthenticationResponseRequestParams.ts index 3851b375b..3348aa955 100644 --- a/packages/auth/src/Infra/Http/Request/VerifyAuthenticatorAuthenticationResponseRequestParams.ts +++ b/packages/auth/src/Infra/Http/Request/VerifyAuthenticatorAuthenticationResponseRequestParams.ts @@ -1,4 +1,4 @@ export interface VerifyAuthenticatorAuthenticationResponseRequestParams { userUuid: string - authenticationCredential: Record + authenticatorResponse: Record } diff --git a/packages/auth/src/Infra/Http/Request/VerifyAuthenticatorRegistrationResponseRequestParams.ts b/packages/auth/src/Infra/Http/Request/VerifyAuthenticatorRegistrationResponseRequestParams.ts index c0ffe0992..1f443b9b3 100644 --- a/packages/auth/src/Infra/Http/Request/VerifyAuthenticatorRegistrationResponseRequestParams.ts +++ b/packages/auth/src/Infra/Http/Request/VerifyAuthenticatorRegistrationResponseRequestParams.ts @@ -1,5 +1,5 @@ export interface VerifyAuthenticatorRegistrationResponseRequestParams { userUuid: string name: string - registrationCredential: Record + attestationResponse: Record } diff --git a/packages/auth/src/Infra/InversifyExpressUtils/InversifyExpressAuthenticatorsController.ts b/packages/auth/src/Infra/InversifyExpressUtils/InversifyExpressAuthenticatorsController.ts index f763847e5..9c14bf89a 100644 --- a/packages/auth/src/Infra/InversifyExpressUtils/InversifyExpressAuthenticatorsController.ts +++ b/packages/auth/src/Infra/InversifyExpressUtils/InversifyExpressAuthenticatorsController.ts @@ -51,7 +51,7 @@ export class InversifyExpressAuthenticatorsController extends BaseHttpController async verifyRegistration(request: Request, response: Response): Promise { const result = await this.authenticatorsController.verifyRegistrationResponse({ userUuid: response.locals.user.uuid, - registrationCredential: request.body.registrationCredential, + attestationResponse: request.body.attestationResponse, name: request.body.name, }) @@ -71,7 +71,7 @@ export class InversifyExpressAuthenticatorsController extends BaseHttpController async verifyAuthentication(request: Request, response: Response): Promise { const result = await this.authenticatorsController.verifyAuthenticationResponse({ userUuid: response.locals.user.uuid, - authenticationCredential: request.body, + authenticatorResponse: request.body, }) return this.json(result.data, result.status) diff --git a/packages/auth/src/Infra/TypeORM/TypeORMAuthenticator.ts b/packages/auth/src/Infra/TypeORM/TypeORMAuthenticator.ts index f619d5593..0188b4524 100644 --- a/packages/auth/src/Infra/TypeORM/TypeORMAuthenticator.ts +++ b/packages/auth/src/Infra/TypeORM/TypeORMAuthenticator.ts @@ -23,13 +23,13 @@ export class TypeORMAuthenticator { type: 'varbinary', length: 1024, }) - declare credentialId: Buffer + declare credentialId: Uint8Array @Column({ name: 'credential_public_key', type: 'blob', }) - declare credentialPublicKey: Buffer + declare credentialPublicKey: Uint8Array @Column({ name: 'counter',