From c45653a50a9d25de1e0fc86127ff6931dc98406d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20S=C3=B3jko?= Date: Thu, 9 Mar 2023 06:46:35 +0100 Subject: [PATCH] fix(auth): remove authenticator names from server --- ...-remove-authenticator-names-from-server.ts | 13 +++++++++ .../Controller/AuthenticatorsController.ts | 1 - .../Authenticator/Authenticator.spec.ts | 1 - .../Authenticator/AuthenticatorProps.ts | 1 - .../DeleteAuthenticator.spec.ts | 1 - ...AuthenticatorAuthenticationOptions.spec.ts | 1 - ...teAuthenticatorRegistrationOptions.spec.ts | 1 - ...uthenticatorAuthenticationResponse.spec.ts | 1 - ...yAuthenticatorRegistrationResponse.spec.ts | 28 ------------------- ...VerifyAuthenticatorRegistrationResponse.ts | 8 +----- ...ifyAuthenticatorRegistrationResponseDTO.ts | 1 - .../Projection/AuthenticatorHttpProjection.ts | 1 - ...icatorRegistrationResponseRequestParams.ts | 1 - ...nversifyExpressAuthenticatorsController.ts | 1 - .../src/Infra/TypeORM/TypeORMAuthenticator.ts | 7 ----- .../src/Mapping/AuthenticatorHttpMapper.ts | 1 - .../Mapping/AuthenticatorPersistenceMapper.ts | 2 -- 17 files changed, 14 insertions(+), 56 deletions(-) create mode 100644 packages/auth/migrations/1678340701766-remove-authenticator-names-from-server.ts diff --git a/packages/auth/migrations/1678340701766-remove-authenticator-names-from-server.ts b/packages/auth/migrations/1678340701766-remove-authenticator-names-from-server.ts new file mode 100644 index 000000000..de57ce0f5 --- /dev/null +++ b/packages/auth/migrations/1678340701766-remove-authenticator-names-from-server.ts @@ -0,0 +1,13 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class removeAuthenticatorNamesFromServer1678340701766 implements MigrationInterface { + name = 'removeAuthenticatorNamesFromServer1678340701766' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query('ALTER TABLE `authenticators` DROP COLUMN `name`') + } + + public async down(): Promise { + return + } +} diff --git a/packages/auth/src/Controller/AuthenticatorsController.ts b/packages/auth/src/Controller/AuthenticatorsController.ts index 1a424bae6..2d87f6977 100644 --- a/packages/auth/src/Controller/AuthenticatorsController.ts +++ b/packages/auth/src/Controller/AuthenticatorsController.ts @@ -88,7 +88,6 @@ export class AuthenticatorsController { ): Promise> { const result = await this.verifyAuthenticatorRegistrationResponse.execute({ userUuid: params.userUuid, - name: params.name, attestationResponse: params.attestationResponse, }) diff --git a/packages/auth/src/Domain/Authenticator/Authenticator.spec.ts b/packages/auth/src/Domain/Authenticator/Authenticator.spec.ts index 16c555110..c0fa4c7a4 100644 --- a/packages/auth/src/Domain/Authenticator/Authenticator.spec.ts +++ b/packages/auth/src/Domain/Authenticator/Authenticator.spec.ts @@ -6,7 +6,6 @@ describe('Authenticator', () => { it('should create an entity', () => { const entityOrError = Authenticator.create({ counter: 1, - name: 'my-key', credentialBackedUp: true, credentialDeviceType: 'singleDevice', credentialId: Buffer.from('credentialId'), diff --git a/packages/auth/src/Domain/Authenticator/AuthenticatorProps.ts b/packages/auth/src/Domain/Authenticator/AuthenticatorProps.ts index 5f6573e75..696fb0ddb 100644 --- a/packages/auth/src/Domain/Authenticator/AuthenticatorProps.ts +++ b/packages/auth/src/Domain/Authenticator/AuthenticatorProps.ts @@ -1,7 +1,6 @@ import { Dates, Uuid } from '@standardnotes/domain-core' export interface AuthenticatorProps { - name: string userUuid: Uuid credentialId: Uint8Array credentialPublicKey: Uint8Array diff --git a/packages/auth/src/Domain/UseCase/DeleteAuthenticator/DeleteAuthenticator.spec.ts b/packages/auth/src/Domain/UseCase/DeleteAuthenticator/DeleteAuthenticator.spec.ts index ac540de2c..a67e48971 100644 --- a/packages/auth/src/Domain/UseCase/DeleteAuthenticator/DeleteAuthenticator.spec.ts +++ b/packages/auth/src/Domain/UseCase/DeleteAuthenticator/DeleteAuthenticator.spec.ts @@ -12,7 +12,6 @@ describe('DeleteAuthenticator', () => { beforeEach(() => { authenticator = Authenticator.create({ counter: 1, - name: 'my-key', credentialBackedUp: true, credentialDeviceType: 'singleDevice', credentialId: Buffer.from('credentialId'), diff --git a/packages/auth/src/Domain/UseCase/GenerateAuthenticatorAuthenticationOptions/GenerateAuthenticatorAuthenticationOptions.spec.ts b/packages/auth/src/Domain/UseCase/GenerateAuthenticatorAuthenticationOptions/GenerateAuthenticatorAuthenticationOptions.spec.ts index a87f52db5..421740f69 100644 --- a/packages/auth/src/Domain/UseCase/GenerateAuthenticatorAuthenticationOptions/GenerateAuthenticatorAuthenticationOptions.spec.ts +++ b/packages/auth/src/Domain/UseCase/GenerateAuthenticatorAuthenticationOptions/GenerateAuthenticatorAuthenticationOptions.spec.ts @@ -24,7 +24,6 @@ describe('GenerateAuthenticatorAuthenticationOptions', () => { beforeEach(() => { const authenticator = Authenticator.create({ counter: 1, - name: 'my-key', credentialBackedUp: true, credentialDeviceType: 'singleDevice', credentialId: Buffer.from('credentialId'), diff --git a/packages/auth/src/Domain/UseCase/GenerateAuthenticatorRegistrationOptions/GenerateAuthenticatorRegistrationOptions.spec.ts b/packages/auth/src/Domain/UseCase/GenerateAuthenticatorRegistrationOptions/GenerateAuthenticatorRegistrationOptions.spec.ts index 0ae9f5f66..17ebac431 100644 --- a/packages/auth/src/Domain/UseCase/GenerateAuthenticatorRegistrationOptions/GenerateAuthenticatorRegistrationOptions.spec.ts +++ b/packages/auth/src/Domain/UseCase/GenerateAuthenticatorRegistrationOptions/GenerateAuthenticatorRegistrationOptions.spec.ts @@ -21,7 +21,6 @@ describe('GenerateAuthenticatorRegistrationOptions', () => { beforeEach(() => { const authenticator = Authenticator.create({ counter: 1, - name: 'my-key', credentialBackedUp: true, credentialDeviceType: 'singleDevice', credentialId: Buffer.from('credentialId'), diff --git a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts index 42ef36afa..8b4807a4c 100644 --- a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts +++ b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts @@ -24,7 +24,6 @@ describe('VerifyAuthenticatorAuthenticationResponse', () => { beforeEach(() => { const authenticator = Authenticator.create({ counter: 1, - name: 'my-key', credentialBackedUp: true, credentialDeviceType: 'singleDevice', credentialId: Buffer.from('credentialId'), diff --git a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.spec.ts b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.spec.ts index 1f20033c0..fe7446064 100644 --- a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.spec.ts +++ b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.spec.ts @@ -38,7 +38,6 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: 'invalid', - name: 'name', attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), @@ -56,27 +55,6 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { ) }) - it('should return error if name is invalid', async () => { - const useCase = createUseCase() - - const result = await useCase.execute({ - userUuid: '00000000-0000-0000-0000-000000000000', - name: '', - attestationResponse: { - id: Buffer.from('id'), - rawId: Buffer.from('rawId'), - response: { - attestationObject: Buffer.from('attestationObject'), - clientDataJSON: Buffer.from('clientDataJSON'), - }, - type: 'type', - }, - }) - - expect(result.isFailed()).toBeTruthy() - expect(result.getError()).toEqual('Could not verify authenticator registration response: Given value is empty: ') - }) - it('should return error if challenge is not found', async () => { authenticatorChallengeRepository.findByUserUuid = jest.fn().mockReturnValue(null) @@ -84,7 +62,6 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', - name: 'name', attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), @@ -125,7 +102,6 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', - name: 'name', attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), @@ -159,7 +135,6 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', - name: 'name', attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), @@ -195,7 +170,6 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', - name: 'name', attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), @@ -245,7 +219,6 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', - name: 'name', attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), @@ -289,7 +262,6 @@ describe('VerifyAuthenticatorRegistrationResponse', () => { const result = await useCase.execute({ userUuid: '00000000-0000-0000-0000-000000000000', - name: 'name', attestationResponse: { id: Buffer.from('id'), rawId: Buffer.from('rawId'), diff --git a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.ts b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.ts index 5d71406e2..c9c9a9de2 100644 --- a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.ts +++ b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.ts @@ -1,4 +1,4 @@ -import { Dates, Result, UseCaseInterface, Uuid, Validator } from '@standardnotes/domain-core' +import { Dates, Result, UseCaseInterface, Uuid } from '@standardnotes/domain-core' import { VerifiedRegistrationResponse, verifyRegistrationResponse } from '@simplewebauthn/server' import { AuthenticatorChallengeRepositoryInterface } from '../../Authenticator/AuthenticatorChallengeRepositoryInterface' @@ -22,11 +22,6 @@ export class VerifyAuthenticatorRegistrationResponse implements UseCaseInterface } const userUuid = userUuidOrError.getValue() - const nameValidation = Validator.isNotEmpty(dto.name) - if (nameValidation.isFailed()) { - return Result.fail(`Could not verify authenticator registration response: ${nameValidation.getError()}`) - } - const authenticatorChallenge = await this.authenticatorChallengeRepository.findByUserUuid(userUuid) if (!authenticatorChallenge) { return Result.fail('Could not verify authenticator registration response: challenge not found') @@ -55,7 +50,6 @@ export class VerifyAuthenticatorRegistrationResponse implements UseCaseInterface const authenticatorOrError = Authenticator.create({ userUuid, - name: dto.name, counter: verification.registrationInfo.counter, credentialBackedUp: verification.registrationInfo.credentialBackedUp, credentialDeviceType: verification.registrationInfo.credentialDeviceType, diff --git a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponseDTO.ts b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponseDTO.ts index 358c450d9..2f3ac3740 100644 --- a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponseDTO.ts +++ b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponseDTO.ts @@ -1,5 +1,4 @@ export interface VerifyAuthenticatorRegistrationResponseDTO { userUuid: string - name: string attestationResponse: Record } diff --git a/packages/auth/src/Infra/Http/Projection/AuthenticatorHttpProjection.ts b/packages/auth/src/Infra/Http/Projection/AuthenticatorHttpProjection.ts index e7bdafb2e..bc5974794 100644 --- a/packages/auth/src/Infra/Http/Projection/AuthenticatorHttpProjection.ts +++ b/packages/auth/src/Infra/Http/Projection/AuthenticatorHttpProjection.ts @@ -1,4 +1,3 @@ export interface AuthenticatorHttpProjection { id: string - name: string } diff --git a/packages/auth/src/Infra/Http/Request/VerifyAuthenticatorRegistrationResponseRequestParams.ts b/packages/auth/src/Infra/Http/Request/VerifyAuthenticatorRegistrationResponseRequestParams.ts index 1f443b9b3..5307c954e 100644 --- a/packages/auth/src/Infra/Http/Request/VerifyAuthenticatorRegistrationResponseRequestParams.ts +++ b/packages/auth/src/Infra/Http/Request/VerifyAuthenticatorRegistrationResponseRequestParams.ts @@ -1,5 +1,4 @@ export interface VerifyAuthenticatorRegistrationResponseRequestParams { userUuid: string - name: string attestationResponse: Record } diff --git a/packages/auth/src/Infra/InversifyExpressUtils/InversifyExpressAuthenticatorsController.ts b/packages/auth/src/Infra/InversifyExpressUtils/InversifyExpressAuthenticatorsController.ts index 3a1ebb19b..5af70e1a1 100644 --- a/packages/auth/src/Infra/InversifyExpressUtils/InversifyExpressAuthenticatorsController.ts +++ b/packages/auth/src/Infra/InversifyExpressUtils/InversifyExpressAuthenticatorsController.ts @@ -52,7 +52,6 @@ export class InversifyExpressAuthenticatorsController extends BaseHttpController const result = await this.authenticatorsController.verifyRegistrationResponse({ userUuid: response.locals.user.uuid, attestationResponse: request.body.attestationResponse, - name: request.body.name, }) 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 6b6d130a4..ba8a03e3c 100644 --- a/packages/auth/src/Infra/TypeORM/TypeORMAuthenticator.ts +++ b/packages/auth/src/Infra/TypeORM/TypeORMAuthenticator.ts @@ -11,13 +11,6 @@ export class TypeORMAuthenticator { }) declare userUuid: string - @Column({ - name: 'name', - type: 'varchar', - length: 255, - }) - declare name: string - @Column({ name: 'credential_id', type: 'text', diff --git a/packages/auth/src/Mapping/AuthenticatorHttpMapper.ts b/packages/auth/src/Mapping/AuthenticatorHttpMapper.ts index 6e1951ee5..0bfd14e75 100644 --- a/packages/auth/src/Mapping/AuthenticatorHttpMapper.ts +++ b/packages/auth/src/Mapping/AuthenticatorHttpMapper.ts @@ -11,7 +11,6 @@ export class AuthenticatorHttpMapper implements MapperInterface