mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-10-24 04:09:07 +03:00
wc_PKCS7_DecodeAuthEnvelopedData() failed with ASN_PARSE_E on the output of openssl cms -encrypt -aes-256-gcm -stream. It read at most one OCTET STRING out of a constructed encryptedContent, rejected an indefinite length there, and expected the authenticated attributes or the tag straight after the content, where BER puts the end-of-contents of the content and of the EncryptedContentInfo. The fragments are now joined into one buffer before the AEAD runs, since GCM and CCM need the whole ciphertext to check the tag, and both end-of-contents are consumed when present. An empty fragment or an empty content is rejected with ASN_PARSE_E, as an empty definite-length content already was, and the join stops with BUFFER_E as soon as the content outgrows the output buffer. Fed in chunks it also failed in two places. The indefinite EncryptedContentInfo gave no length to size the read by, so too little was buffered to parse the content type and algorithm; the worst case is now buffered, as the EnvelopedData decoder already does. And the bytes still expected after the tag were computed as maxLen minus the total read, which an indefinite message has already passed, so the unsigned result wrapped and the decoder asked for 4 GB more input. It now waits only for what is buffered. test_wc_PKCS7_DecodeAuthEnvelopedData_fragmented re-encodes AES-256-GCM messages, with and without authenticated attributes, in 16, 7, 1, 33 and 4096-byte fragments, decodes them whole and in 1 and 13-byte chunks, and checks that a flipped tag bit and an indefinite [0] with no content are rejected and that too small an output stops the join early. test_wc_PKCS7_DecodeOpenSslStream gains certs/test-stream-dec-aes256gcm.p7b from renewcerts.sh.
5.9 KiB
5.9 KiB