Skip to content

Commit 8c81013

Browse files
authored
fix: resource exhaustion from an incomplete encrypted message (#348)
Decrypt needs to actively verify that it has reached the end of the encrypted message. This fix ensures an error on an incomplete encrypted message Also, the signature_info parsing needed to be updated, to handle an incomplete signature block. Browsers were never impacted, but the tests were included for completeness.
1 parent c103fa4 commit 8c81013

File tree

10 files changed

+968
-13
lines changed

10 files changed

+968
-13
lines changed

modules/decrypt-browser/test/decrypt.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
/* eslint-env mocha */
55

6-
import { expect } from 'chai'
6+
import * as chai from 'chai'
7+
import chaiAsPromised from 'chai-as-promised'
78
import { decrypt } from '../src/index'
89
import { AlgorithmSuiteIdentifier } from '@aws-crypto/material-management-browser'
910
import * as fixtures from './fixtures'
11+
chai.use(chaiAsPromised)
12+
const { expect } = chai
1013

1114
describe('decrypt', () => {
1215
it('buffer', async () => {
@@ -52,4 +55,34 @@ describe('decrypt', () => {
5255
}
5356
)
5457
})
58+
59+
it('verify incomplete chipertext will fail for an un-signed algorithm suite', async () => {
60+
const data = fixtures.base64CiphertextAlgAes256GcmIv12Tag16HkdfWith4Frames()
61+
const keyring = fixtures.decryptKeyring()
62+
63+
// First we make sure that the test vector is well formed
64+
await decrypt(keyring, data)
65+
66+
// This is the real test:
67+
// trying to decrypt
68+
// on EVERY boundary
69+
for (let i = 0; data.byteLength > i; i++) {
70+
await expect(decrypt(keyring, data.slice(0, i))).to.rejectedWith(Error)
71+
}
72+
})
73+
74+
it('verify incomplete chipertext will fail for a signed algorithm suite', async () => {
75+
const data = fixtures.base64CiphertextAlgAes256GcmIv12Tag16HkdfSha384EcdsaP384With4Frames()
76+
const keyring = fixtures.decryptKeyring()
77+
78+
// First we make sure that the test vector is well formed
79+
await decrypt(keyring, data)
80+
81+
// This is the real test:
82+
// trying to decrypt
83+
// on EVERY boundary
84+
for (let i = 0; data.byteLength > i; i++) {
85+
await expect(decrypt(keyring, data.slice(0, i))).to.rejectedWith(Error)
86+
}
87+
})
5588
})

0 commit comments

Comments
 (0)