diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 32c8a9c..c39b5b7 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -1,3 +1,4 @@ +import { AES_GCM_AUTH_TAG_BYTE_LENGTH } from '../consts/crypto/aesGcmAuthTagByteLength'; import { AltchaConfig } from '../types/config/AltchaConfig'; import { AppConfig } from '../types/config/AppConfig'; import { NodeEnv } from '../types/NodeEnv'; @@ -34,7 +35,6 @@ export const getAltchaConfig = (): AltchaConfig => { }; export const getAppConfig = (): AppConfig => { - const aesGcmCiphertextOverheadBytes = 16; const jsonBase64ByteRatioNumerator = 4; const jsonBase64ByteRatioDenominator = 3; @@ -61,7 +61,7 @@ export const getAppConfig = (): AppConfig => { upload: { maxViewsMax: envInt('VALIDATION_UPLOAD_MAX_VIEWS_MAX'), maxImageBytes, - maxCiphertextBytes: maxImageBytes + aesGcmCiphertextOverheadBytes, + maxCiphertextBytes: maxImageBytes + AES_GCM_AUTH_TAG_BYTE_LENGTH, maxRequestBodyBytes: Math.ceil((maxImageBytes * jsonBase64ByteRatioNumerator) / jsonBase64ByteRatioDenominator) + jsonBodyPaddingBytes diff --git a/backend/src/consts/crypto/aesGcmAuthTagByteLength.ts b/backend/src/consts/crypto/aesGcmAuthTagByteLength.ts new file mode 100644 index 0000000..d80fc31 --- /dev/null +++ b/backend/src/consts/crypto/aesGcmAuthTagByteLength.ts @@ -0,0 +1 @@ +export const AES_GCM_AUTH_TAG_BYTE_LENGTH = 16; diff --git a/backend/src/consts/crypto/aesGcmIvByteLength.ts b/backend/src/consts/crypto/aesGcmIvByteLength.ts new file mode 100644 index 0000000..4c332a1 --- /dev/null +++ b/backend/src/consts/crypto/aesGcmIvByteLength.ts @@ -0,0 +1 @@ +export const AES_GCM_IV_BYTE_LENGTH = 12; diff --git a/backend/src/modules/upload/dto/CreateZkUploadDto.ts b/backend/src/modules/upload/dto/CreateZkUploadDto.ts index 9e5ca8f..d915096 100644 --- a/backend/src/modules/upload/dto/CreateZkUploadDto.ts +++ b/backend/src/modules/upload/dto/CreateZkUploadDto.ts @@ -1,4 +1,5 @@ import { IsBoolean, IsNotEmpty, ValidateIf } from 'class-validator'; +import { AES_GCM_IV_BYTE_LENGTH } from '../../../consts/crypto/aesGcmIvByteLength'; import { IsBase64 } from '../../../validation/decorators/isBase64'; import { UploadCiphertextOptionsDto } from './UploadCiphertextOptionsDto'; @@ -14,7 +15,7 @@ export class CreateZkUploadDto extends UploadCiphertextOptionsDto { @ValidateIf((dto: CreateZkUploadDto) => dto.passwordProtected === true) @IsNotEmpty() - @IsBase64({ byteLength: 12 }) + @IsBase64({ byteLength: AES_GCM_IV_BYTE_LENGTH }) wrapIv?: string; @ValidateIf((dto: CreateZkUploadDto) => dto.passwordProtected === true) diff --git a/backend/src/modules/upload/dto/UploadCiphertextOptionsDto.ts b/backend/src/modules/upload/dto/UploadCiphertextOptionsDto.ts index 5414cf9..01bc070 100644 --- a/backend/src/modules/upload/dto/UploadCiphertextOptionsDto.ts +++ b/backend/src/modules/upload/dto/UploadCiphertextOptionsDto.ts @@ -1,4 +1,5 @@ import { IsNotEmpty } from 'class-validator'; +import { AES_GCM_IV_BYTE_LENGTH } from '../../../consts/crypto/aesGcmIvByteLength'; import { getAppConfig } from '../../../config'; import { IsBase64 } from '../../../validation/decorators/isBase64'; import { UploadOptionsDto } from './UploadOptionsDto'; @@ -11,7 +12,7 @@ const { export class UploadCiphertextOptionsDto extends UploadOptionsDto { @IsNotEmpty() - @IsBase64({ byteLength: 12 }) + @IsBase64({ byteLength: AES_GCM_IV_BYTE_LENGTH }) iv: string; @IsNotEmpty()