diff --git a/modules/encrypt-browser/src/encrypt.ts b/modules/encrypt-browser/src/encrypt.ts index 97d5783b8..33ef913e7 100644 --- a/modules/encrypt-browser/src/encrypt.ts +++ b/modules/encrypt-browser/src/encrypt.ts @@ -34,6 +34,7 @@ import { ContentType, serializeSignatureInfo, FRAME_LENGTH, + MESSAGE_ID_LENGTH, raw2der } from '@aws-crypto/serialize' import { fromUtf8 } from '@aws-sdk/util-utf8-browser' @@ -81,9 +82,7 @@ export async function encrypt ( const { material, context } = await cmm.getEncryptionMaterials(encryptionRequest) const { kdfGetSubtleEncrypt, subtleSign, dispose } = await getEncryptHelper(material) - // Why is this here? - const idLength = 16 - const messageId = await backend.randomValues(idLength) + const messageId = await backend.randomValues(MESSAGE_ID_LENGTH) const { id, ivLength } = material.suite diff --git a/modules/encrypt-node/src/encrypt_stream.ts b/modules/encrypt-node/src/encrypt_stream.ts index 9e261b269..0d126d896 100644 --- a/modules/encrypt-node/src/encrypt_stream.ts +++ b/modules/encrypt-node/src/encrypt_stream.ts @@ -25,7 +25,8 @@ import { randomBytes } from 'crypto' import { MessageHeader, // eslint-disable-line no-unused-vars serializeFactory, kdfInfo, ContentType, SerializationVersion, ObjectType, - FRAME_LENGTH + FRAME_LENGTH, + MESSAGE_ID_LENGTH } from '@aws-crypto/serialize' // @ts-ignore @@ -92,7 +93,7 @@ export function encryptStream ( export function getEncryptionInfo (material : NodeEncryptionMaterial, frameLength: number, context: EncryptionContext) { const { kdfGetCipher } = getEncryptHelper(material) - const messageId = randomBytes(16) + const messageId = randomBytes(MESSAGE_ID_LENGTH) const { id, ivLength } = material.suite const messageHeader: MessageHeader = Object.freeze({ version: SerializationVersion.V1, diff --git a/modules/serialize/src/identifiers.ts b/modules/serialize/src/identifiers.ts index 945e54b9e..a92e28318 100644 --- a/modules/serialize/src/identifiers.ts +++ b/modules/serialize/src/identifiers.ts @@ -78,3 +78,5 @@ Object.freeze(Maximum) // Default frame length when using framing export const FRAME_LENGTH = 4096 +// Message ID length as defined in specification +export const MESSAGE_ID_LENGTH = 16