Skip to content

Commit bd160c0

Browse files
authored
feat: Remove unencryptedDataKeyLength (#201)
It is a feature that is not being used. This was created to let callers confirm that the unencrypted data key matched the algorithm suite, but this checking is done directly into the cryptographic material now. The hasUnencryptedDataKey is the best way to check for existence, and the materials themselves will ensure that algorithm suite specifications are meet. NOTE: This change is **ONLY** done because the project is in beta. Otherwise there would be a major version bump.
1 parent d3118d7 commit bd160c0

File tree

3 files changed

+0
-39
lines changed

3 files changed

+0
-39
lines changed

modules/material-management/src/cryptographic_material.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export interface CryptographicMaterial<T extends CryptographicMaterial<T>> {
109109
getUnencryptedDataKey: () => Uint8Array|AwsEsdkKeyObject
110110
zeroUnencryptedDataKey: () => T
111111
hasUnencryptedDataKey: boolean
112-
unencryptedDataKeyLength: number
113112
keyringTrace: KeyringTrace[]
114113
encryptionContext: Readonly<EncryptionContext>
115114
}
@@ -141,7 +140,6 @@ export class NodeEncryptionMaterial implements
141140
getUnencryptedDataKey!: () => Uint8Array|AwsEsdkKeyObject
142141
zeroUnencryptedDataKey!: () => NodeEncryptionMaterial
143142
hasUnencryptedDataKey!: boolean
144-
unencryptedDataKeyLength!: number
145143
keyringTrace: KeyringTrace[] = []
146144
encryptedDataKeys!: EncryptedDataKey[]
147145
addEncryptedDataKey!: (edk: EncryptedDataKey, flags: KeyringTraceFlag) => NodeEncryptionMaterial
@@ -176,7 +174,6 @@ export class NodeDecryptionMaterial implements
176174
getUnencryptedDataKey!: () => Uint8Array|AwsEsdkKeyObject
177175
zeroUnencryptedDataKey!: () => NodeDecryptionMaterial
178176
hasUnencryptedDataKey!: boolean
179-
unencryptedDataKeyLength!: number
180177
keyringTrace: KeyringTrace[] = []
181178
setVerificationKey!: (key: VerificationKey) => NodeDecryptionMaterial
182179
verificationKey?: VerificationKey
@@ -210,7 +207,6 @@ export class WebCryptoEncryptionMaterial implements
210207
getUnencryptedDataKey!: () => Uint8Array|AwsEsdkKeyObject
211208
zeroUnencryptedDataKey!: () => WebCryptoEncryptionMaterial
212209
hasUnencryptedDataKey!: boolean
213-
unencryptedDataKeyLength!: number
214210
keyringTrace: KeyringTrace[] = []
215211
encryptedDataKeys!: EncryptedDataKey[]
216212
addEncryptedDataKey!: (edk: EncryptedDataKey, flags: KeyringTraceFlag) => WebCryptoEncryptionMaterial
@@ -252,7 +248,6 @@ export class WebCryptoDecryptionMaterial implements
252248
getUnencryptedDataKey!: () => Uint8Array|AwsEsdkKeyObject
253249
zeroUnencryptedDataKey!: () => WebCryptoDecryptionMaterial
254250
hasUnencryptedDataKey!: boolean
255-
unencryptedDataKeyLength!: number
256251
keyringTrace: KeyringTrace[] = []
257252
setVerificationKey!: (key: VerificationKey) => WebCryptoDecryptionMaterial
258253
verificationKey?: VerificationKey
@@ -367,21 +362,6 @@ export function decorateCryptographicMaterial<T extends CryptographicMaterial<T>
367362
needs(unsetCount === 0 || unsetCount === 2, 'Either unencryptedDataKey or udkForVerification was not set.')
368363
return material
369364
}
370-
Object.defineProperty(material, 'unencryptedDataKeyLength', {
371-
get: () => {
372-
/* Precondition: The unencryptedDataKey must be set to have a length. */
373-
needs(unencryptedDataKey, 'unencryptedDataKey has not been set')
374-
/* Precondition: the unencryptedDataKey must not be Zeroed out.
375-
* returning information about the data key,
376-
* while not the worst thing may indicate misuse.
377-
* Checking the algorithm specification is the proper way
378-
* to do this
379-
*/
380-
needs(!unencryptedDataKeyZeroed, 'unencryptedDataKey has been zeroed.')
381-
return unwrapDataKey(unencryptedDataKey).byteLength
382-
},
383-
enumerable: true
384-
})
385365

386366
readOnlyProperty(material, 'setUnencryptedDataKey', setUnencryptedDataKey)
387367
readOnlyProperty(material, 'getUnencryptedDataKey', getUnencryptedDataKey)

modules/material-management/test/cryptographic_material.test.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ describe('decorateCryptographicMaterial', () => {
6161
const dataKey = new Uint8Array(suite.keyLengthBytes).fill(1)
6262
test.setUnencryptedDataKey(new Uint8Array(dataKey), { keyNamespace: 'k', keyName: 'k', flags: KeyringTraceFlag.WRAPPING_KEY_GENERATED_DATA_KEY })
6363
expect(test.hasUnencryptedDataKey).to.equal(true)
64-
expect(test.unencryptedDataKeyLength).to.equal(dataKey.byteLength)
6564
const udk = unwrapDataKey(test.getUnencryptedDataKey())
6665
expect(udk).to.deep.equal(dataKey)
6766
})
@@ -101,29 +100,13 @@ describe('decorateCryptographicMaterial', () => {
101100
test.setUnencryptedDataKey(new Uint8Array(dataKey), { keyNamespace: 'k', keyName: 'k', flags: KeyringTraceFlag.WRAPPING_KEY_GENERATED_DATA_KEY })
102101
test.zeroUnencryptedDataKey()
103102
expect(() => test.getUnencryptedDataKey()).to.throw()
104-
expect(() => test.unencryptedDataKeyLength).to.throw()
105103
})
106104

107105
it('Precondition: unencryptedDataKey must be set before we can return it.', () => {
108106
const test: any = decorateCryptographicMaterial((<any>{}), KeyringTraceFlag.WRAPPING_KEY_GENERATED_DATA_KEY)
109107
expect(() => test.getUnencryptedDataKey()).to.throw()
110108
})
111109

112-
it('Precondition: The unencryptedDataKey must be set to have a length.', () => {
113-
const test: any = decorateCryptographicMaterial((<any>{}), KeyringTraceFlag.WRAPPING_KEY_GENERATED_DATA_KEY)
114-
expect(() => test.unencryptedDataKeyLength).to.throw()
115-
})
116-
117-
it('Precondition: the unencryptedDataKey must not be Zeroed out.', () => {
118-
const suite = new NodeAlgorithmSuite(AlgorithmSuiteIdentifier.ALG_AES128_GCM_IV12_TAG16)
119-
const test = decorateCryptographicMaterial((<any>{ suite, keyringTrace: [] }), KeyringTraceFlag.WRAPPING_KEY_GENERATED_DATA_KEY)
120-
const dataKey = new Uint8Array(suite.keyLengthBytes).fill(1)
121-
const trace = { keyNamespace: 'k', keyName: 'k', flags: KeyringTraceFlag.WRAPPING_KEY_GENERATED_DATA_KEY }
122-
test.setUnencryptedDataKey(dataKey, trace)
123-
test.zeroUnencryptedDataKey()
124-
expect(() => test.unencryptedDataKeyLength).to.throw('unencryptedDataKey has been zeroed.')
125-
})
126-
127110
it(`Precondition: If the unencryptedDataKey has not been set, it should not be settable later.
128111
Precondition: If the udkForVerification has not been set, it should not be settable later.`, () => {
129112
const suite = new NodeAlgorithmSuite(AlgorithmSuiteIdentifier.ALG_AES128_GCM_IV12_TAG16)

modules/raw-keyring/src/raw_aes_material.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export class NodeRawAesMaterial implements
5050
getUnencryptedDataKey!: () => Uint8Array|AwsEsdkKeyObject
5151
zeroUnencryptedDataKey!: () => NodeRawAesMaterial
5252
hasUnencryptedDataKey!: boolean
53-
unencryptedDataKeyLength!: number
5453
keyringTrace: KeyringTrace[] = []
5554
encryptionContext: EncryptionContext = Object.freeze({})
5655
constructor (suiteId: WrappingSuiteIdentifier) {
@@ -80,7 +79,6 @@ export class WebCryptoRawAesMaterial implements
8079
getUnencryptedDataKey!: () => Uint8Array|AwsEsdkKeyObject
8180
zeroUnencryptedDataKey!: () => WebCryptoRawAesMaterial
8281
hasUnencryptedDataKey!: boolean
83-
unencryptedDataKeyLength!: number
8482
keyringTrace: KeyringTrace[] = []
8583
setCryptoKey!: (dataKey: AwsEsdkJsCryptoKey|MixedBackendCryptoKey, trace: KeyringTrace) => WebCryptoRawAesMaterial
8684
getCryptoKey!: () => AwsEsdkJsCryptoKey|MixedBackendCryptoKey

0 commit comments

Comments
 (0)