Skip to content

Commit d2b352c

Browse files
authored
fix: caching cmm export and material (#186)
* WebCryptoDecryptionMaterial do not have an unencrypted data key This is because the CrypoKey offers better security, and some unwrapping algorithms can directly return a CryptoKey without exposing the unencrypted data key. Update test for WebCryptoDecryptionMaterial. * Caching CMMs need to be able to create a local cryptographic materials cache export the function.
1 parent b60f653 commit d2b352c

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

modules/cache-material/src/clone_cryptographic_material.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ export function cloneMaterial<M extends Material> (source: M): M {
3737
? new WebCryptoEncryptionMaterial(suite, encryptionContext)
3838
: new WebCryptoDecryptionMaterial(suite, encryptionContext)
3939

40-
const udk = new Uint8Array(source.getUnencryptedDataKey())
41-
clone.setUnencryptedDataKey(udk, source.keyringTrace[0])
40+
if (source.hasUnencryptedDataKey) {
41+
const udk = new Uint8Array(source.getUnencryptedDataKey())
42+
clone.setUnencryptedDataKey(udk, source.keyringTrace[0])
43+
}
44+
4245
if ((<WebCryptoDecryptionMaterial>source).hasCryptoKey) {
4346
const cryptoKey = (<WebCryptoDecryptionMaterial>source).getCryptoKey()
4447
;(<WebCryptoDecryptionMaterial>clone)
45-
.setCryptoKey(cryptoKey, clone.keyringTrace[0])
48+
.setCryptoKey(cryptoKey, source.keyringTrace[0])
4649
}
4750

4851
if (isEncryptionMaterial(source) && isEncryptionMaterial(clone)) {

modules/cache-material/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ export * from './cryptographic_materials_cache'
1717
export * from './caching_cryptographic_materials_decorators'
1818
export * from './build_cryptographic_materials_cache_key_helpers'
1919
export * from './clone_cryptographic_material'
20+
export * from './get_local_cryptographic_materials_cache'

modules/cache-material/test/clone_cryptographic_material.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,12 @@ describe('cloneMaterial', () => {
8787
})
8888

8989
it('clone WebCryptoDecryptionMaterial', () => {
90+
/* WebCryptoDecryptionMaterial do not have an unencrypted data key. */
9091
const material = new WebCryptoDecryptionMaterial(webCryptoSuite, { some: 'context' })
91-
.setUnencryptedDataKey(udk128, trace)
9292
.setCryptoKey(cryptoKey, trace)
9393

9494
const test = cloneMaterial(material)
9595
expect(test).to.be.instanceOf(WebCryptoDecryptionMaterial)
96-
expect(test.getUnencryptedDataKey()).to.deep.equal(udk128)
9796
expect(test.getCryptoKey()).to.deep.equal(cryptoKey)
9897
expect(test.keyringTrace).to.deep.equal(material.keyringTrace)
9998
expect(test.encryptionContext).to.deep.equal(material.encryptionContext)

modules/caching-materials-manager-browser/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
*/
1515

1616
export * from './caching_materials_manager_browser'
17+
export { getLocalCryptographicMaterialsCache } from '@aws-crypto/cache-material'

modules/caching-materials-manager-node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
*/
1515

1616
export * from './caching_materials_manager_node'
17+
export { getLocalCryptographicMaterialsCache } from '@aws-crypto/cache-material'

0 commit comments

Comments
 (0)