Skip to content

feat: Message ID should be defined in serialize #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions modules/encrypt-browser/src/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions modules/encrypt-node/src/encrypt_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions modules/serialize/src/identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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