From 51e4b9c2095ee7f00ba5f963b35775ae079e98d7 Mon Sep 17 00:00:00 2001 From: siepra Date: Wed, 15 Nov 2023 14:20:54 +0100 Subject: [PATCH] chore: postpone validation work --- .../certificates/certificates.store.ts | 52 ++++--------------- 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/packages/backend/src/nest/storage/certificates/certificates.store.ts b/packages/backend/src/nest/storage/certificates/certificates.store.ts index 4ce24bec9b..0d126226c0 100644 --- a/packages/backend/src/nest/storage/certificates/certificates.store.ts +++ b/packages/backend/src/nest/storage/certificates/certificates.store.ts @@ -1,5 +1,3 @@ -import { getCrypto } from 'pkijs' - import { EventEmitter } from 'events' import { StorageEvents } from '../storage.types' @@ -8,21 +6,12 @@ import OrbitDB from 'orbit-db' import { loadCertificate, keyFromCertificate } from '@quiet/identity' -import { ConnectionProcessInfo, NoCryptoEngineError, SocketActionTypes } from '@quiet/types' - -import { IsNotEmpty, IsBase64, validate } from 'class-validator' -import { ValidationError } from '@nestjs/common' +import { ConnectionProcessInfo, SocketActionTypes } from '@quiet/types' import createLogger from '../../common/logger' const logger = createLogger('CertificatesStore') -class UserCertificateData { - @IsNotEmpty() - @IsBase64() - certificate: string -} - export class CertificatesStore { public orbitDb: OrbitDB public store: EventStore @@ -75,39 +64,20 @@ export class CertificatesStore { } - private async validateCertificate(certificate: string): Promise { + /* + * In order to split up the work scope, we mock validating function, + * until we move the certificates section into it's own store + */ + private async validateCertificate(_certificate: string): Promise { logger('Validating certificate') - try { - const crypto = getCrypto() - - if (!crypto) { - throw new NoCryptoEngineError() - } - - const parsedCertificate = loadCertificate(certificate) - await parsedCertificate.verify() - - await this.validateCertificateFormat(certificate) - - // Validate - - } catch (err) { - logger.error('Failed to validate user certificate:', certificate, err?.message) - return false - } - return true } - private async validateCertificateFormat(certificate: string): Promise { - const data = new UserCertificateData() - data.certificate = certificate - - const validationErrors = await validate(data) - - return validationErrors - } - + /* + * Method returning store entries, filtered by validation result + * as specified in the comment section of + * https://github.com/TryQuiet/quiet/issues/1899 + */ protected async getCertificates() { const filteredCertificatesMap: Map = new Map()