Browse Source

fix(auth): remove authenticator names from server

Karol Sójko 2 years ago
parent
commit
c45653a50a
17 changed files with 14 additions and 56 deletions
  1. 13 0
      packages/auth/migrations/1678340701766-remove-authenticator-names-from-server.ts
  2. 0 1
      packages/auth/src/Controller/AuthenticatorsController.ts
  3. 0 1
      packages/auth/src/Domain/Authenticator/Authenticator.spec.ts
  4. 0 1
      packages/auth/src/Domain/Authenticator/AuthenticatorProps.ts
  5. 0 1
      packages/auth/src/Domain/UseCase/DeleteAuthenticator/DeleteAuthenticator.spec.ts
  6. 0 1
      packages/auth/src/Domain/UseCase/GenerateAuthenticatorAuthenticationOptions/GenerateAuthenticatorAuthenticationOptions.spec.ts
  7. 0 1
      packages/auth/src/Domain/UseCase/GenerateAuthenticatorRegistrationOptions/GenerateAuthenticatorRegistrationOptions.spec.ts
  8. 0 1
      packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts
  9. 0 28
      packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.spec.ts
  10. 1 7
      packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponse.ts
  11. 0 1
      packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponseDTO.ts
  12. 0 1
      packages/auth/src/Infra/Http/Projection/AuthenticatorHttpProjection.ts
  13. 0 1
      packages/auth/src/Infra/Http/Request/VerifyAuthenticatorRegistrationResponseRequestParams.ts
  14. 0 1
      packages/auth/src/Infra/InversifyExpressUtils/InversifyExpressAuthenticatorsController.ts
  15. 0 7
      packages/auth/src/Infra/TypeORM/TypeORMAuthenticator.ts
  16. 0 1
      packages/auth/src/Mapping/AuthenticatorHttpMapper.ts
  17. 0 2
      packages/auth/src/Mapping/AuthenticatorPersistenceMapper.ts

+ 13 - 0
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<void> {
+    await queryRunner.query('ALTER TABLE `authenticators` DROP COLUMN `name`')
+  }
+
+  public async down(): Promise<void> {
+    return
+  }
+}

+ 0 - 1
packages/auth/src/Controller/AuthenticatorsController.ts

@@ -88,7 +88,6 @@ export class AuthenticatorsController {
   ): Promise<HttpResponse<VerifyAuthenticatorRegistrationResponseResponseBody>> {
     const result = await this.verifyAuthenticatorRegistrationResponse.execute({
       userUuid: params.userUuid,
-      name: params.name,
       attestationResponse: params.attestationResponse,
     })
 

+ 0 - 1
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'),

+ 0 - 1
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

+ 0 - 1
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'),

+ 0 - 1
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'),

+ 0 - 1
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'),

+ 0 - 1
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'),

+ 0 - 28
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'),

+ 1 - 7
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,

+ 0 - 1
packages/auth/src/Domain/UseCase/VerifyAuthenticatorRegistrationResponse/VerifyAuthenticatorRegistrationResponseDTO.ts

@@ -1,5 +1,4 @@
 export interface VerifyAuthenticatorRegistrationResponseDTO {
   userUuid: string
-  name: string
   attestationResponse: Record<string, unknown>
 }

+ 0 - 1
packages/auth/src/Infra/Http/Projection/AuthenticatorHttpProjection.ts

@@ -1,4 +1,3 @@
 export interface AuthenticatorHttpProjection {
   id: string
-  name: string
 }

+ 0 - 1
packages/auth/src/Infra/Http/Request/VerifyAuthenticatorRegistrationResponseRequestParams.ts

@@ -1,5 +1,4 @@
 export interface VerifyAuthenticatorRegistrationResponseRequestParams {
   userUuid: string
-  name: string
   attestationResponse: Record<string, unknown>
 }

+ 0 - 1
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)

+ 0 - 7
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',

+ 0 - 1
packages/auth/src/Mapping/AuthenticatorHttpMapper.ts

@@ -11,7 +11,6 @@ export class AuthenticatorHttpMapper implements MapperInterface<Authenticator, A
   toProjection(domain: Authenticator): AuthenticatorHttpProjection {
     return {
       id: domain.id.toString(),
-      name: domain.props.name,
     }
   }
 }

+ 0 - 2
packages/auth/src/Mapping/AuthenticatorPersistenceMapper.ts

@@ -20,7 +20,6 @@ export class AuthenticatorPersistenceMapper implements MapperInterface<Authentic
     const authenticatorOrError = Authenticator.create(
       {
         userUuid,
-        name: projection.name,
         counter: projection.counter,
         credentialBackedUp: projection.credentialBackedUp,
         credentialDeviceType: projection.credentialDeviceType,
@@ -43,7 +42,6 @@ export class AuthenticatorPersistenceMapper implements MapperInterface<Authentic
     const typeorm = new TypeORMAuthenticator()
 
     typeorm.uuid = domain.id.toString()
-    typeorm.name = domain.props.name
     typeorm.userUuid = domain.props.userUuid.value
     typeorm.credentialId = Buffer.from(domain.props.credentialId).toString('base64url')
     typeorm.credentialPublicKey = Buffer.from(domain.props.credentialPublicKey.buffer)