Slave/client crypto #7
@@ -1,3 +1,4 @@
|
|||||||
|
import { AES_GCM_AUTH_TAG_BYTE_LENGTH } from '../consts/crypto/aesGcmAuthTagByteLength';
|
||||||
import { AltchaConfig } from '../types/config/AltchaConfig';
|
import { AltchaConfig } from '../types/config/AltchaConfig';
|
||||||
import { AppConfig } from '../types/config/AppConfig';
|
import { AppConfig } from '../types/config/AppConfig';
|
||||||
import { NodeEnv } from '../types/NodeEnv';
|
import { NodeEnv } from '../types/NodeEnv';
|
||||||
@@ -34,7 +35,6 @@ export const getAltchaConfig = (): AltchaConfig => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getAppConfig = (): AppConfig => {
|
export const getAppConfig = (): AppConfig => {
|
||||||
const aesGcmCiphertextOverheadBytes = 16;
|
|
||||||
const jsonBase64ByteRatioNumerator = 4;
|
const jsonBase64ByteRatioNumerator = 4;
|
||||||
const jsonBase64ByteRatioDenominator = 3;
|
const jsonBase64ByteRatioDenominator = 3;
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ export const getAppConfig = (): AppConfig => {
|
|||||||
upload: {
|
upload: {
|
||||||
maxViewsMax: envInt('VALIDATION_UPLOAD_MAX_VIEWS_MAX'),
|
maxViewsMax: envInt('VALIDATION_UPLOAD_MAX_VIEWS_MAX'),
|
||||||
maxImageBytes,
|
maxImageBytes,
|
||||||
maxCiphertextBytes: maxImageBytes + aesGcmCiphertextOverheadBytes,
|
maxCiphertextBytes: maxImageBytes + AES_GCM_AUTH_TAG_BYTE_LENGTH,
|
||||||
maxRequestBodyBytes:
|
maxRequestBodyBytes:
|
||||||
Math.ceil((maxImageBytes * jsonBase64ByteRatioNumerator) / jsonBase64ByteRatioDenominator) +
|
Math.ceil((maxImageBytes * jsonBase64ByteRatioNumerator) / jsonBase64ByteRatioDenominator) +
|
||||||
jsonBodyPaddingBytes
|
jsonBodyPaddingBytes
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export const AES_GCM_AUTH_TAG_BYTE_LENGTH = 16;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export const AES_GCM_IV_BYTE_LENGTH = 12;
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { IsBoolean, IsNotEmpty, ValidateIf } from 'class-validator';
|
import { IsBoolean, IsNotEmpty, ValidateIf } from 'class-validator';
|
||||||
|
import { AES_GCM_IV_BYTE_LENGTH } from '../../../consts/crypto/aesGcmIvByteLength';
|
||||||
import { IsBase64 } from '../../../validation/decorators/isBase64';
|
import { IsBase64 } from '../../../validation/decorators/isBase64';
|
||||||
import { UploadCiphertextOptionsDto } from './UploadCiphertextOptionsDto';
|
import { UploadCiphertextOptionsDto } from './UploadCiphertextOptionsDto';
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ export class CreateZkUploadDto extends UploadCiphertextOptionsDto {
|
|||||||
|
|
||||||
@ValidateIf((dto: CreateZkUploadDto) => dto.passwordProtected === true)
|
@ValidateIf((dto: CreateZkUploadDto) => dto.passwordProtected === true)
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsBase64({ byteLength: 12 })
|
@IsBase64({ byteLength: AES_GCM_IV_BYTE_LENGTH })
|
||||||
wrapIv?: string;
|
wrapIv?: string;
|
||||||
|
|
||||||
@ValidateIf((dto: CreateZkUploadDto) => dto.passwordProtected === true)
|
@ValidateIf((dto: CreateZkUploadDto) => dto.passwordProtected === true)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { IsNotEmpty } from 'class-validator';
|
import { IsNotEmpty } from 'class-validator';
|
||||||
|
import { AES_GCM_IV_BYTE_LENGTH } from '../../../consts/crypto/aesGcmIvByteLength';
|
||||||
import { getAppConfig } from '../../../config';
|
import { getAppConfig } from '../../../config';
|
||||||
import { IsBase64 } from '../../../validation/decorators/isBase64';
|
import { IsBase64 } from '../../../validation/decorators/isBase64';
|
||||||
import { UploadOptionsDto } from './UploadOptionsDto';
|
import { UploadOptionsDto } from './UploadOptionsDto';
|
||||||
@@ -11,7 +12,7 @@ const {
|
|||||||
|
|
||||||
export class UploadCiphertextOptionsDto extends UploadOptionsDto {
|
export class UploadCiphertextOptionsDto extends UploadOptionsDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsBase64({ byteLength: 12 })
|
@IsBase64({ byteLength: AES_GCM_IV_BYTE_LENGTH })
|
||||||
iv: string;
|
iv: string;
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
|||||||
Reference in New Issue
Block a user