mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-01 11:44:38 +02:00
fix for compressedData eContent encoding with PKCS7
This commit is contained in:
@@ -12672,15 +12672,40 @@ int wc_PKCS7_EncodeCompressedData(PKCS7* pkcs7, byte* output, word32 outputSz)
|
|||||||
compressedDataSeqSz = SetSequence(totalSz, compressedDataSeq);
|
compressedDataSeqSz = SetSequence(totalSz, compressedDataSeq);
|
||||||
totalSz += compressedDataSeqSz;
|
totalSz += compressedDataSeqSz;
|
||||||
|
|
||||||
/* ContentInfo content EXPLICIT SEQUENCE */
|
if (pkcs7->version == 3 && pkcs7->contentOID == COMPRESSED_DATA) {
|
||||||
contentInfoContentSeqSz = SetExplicit(0, totalSz, contentInfoContentSeq);
|
/* RFC 4108 section 2
|
||||||
totalSz += contentInfoContentSeqSz;
|
* When the SignedData is version 3 and eContent is compressedData then
|
||||||
|
* the encoding is :
|
||||||
/* ContentInfo ContentType (compressedData) */
|
* CompressedData {
|
||||||
if (pkcs7->version == 3) {
|
* version
|
||||||
contentInfoTypeOidSz = 0;
|
* compressionAlgorithm
|
||||||
|
* encapContentInfo
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
contentInfoSeqSz = 0;
|
||||||
|
contentInfoTypeOidSz = 0;
|
||||||
|
contentInfoContentSeqSz = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* pkcs7->contentOID should be ENCRYPTED_DATA, FIRMWARE_PKG_DATA is just
|
||||||
|
* an octet string for eContent.
|
||||||
|
*
|
||||||
|
* EncryptedData eContent type is encoded with:
|
||||||
|
* EncryptedData {
|
||||||
|
* version
|
||||||
|
* EncryptedContentInfo {
|
||||||
|
* contentType (i.e id-ct-compressedData)
|
||||||
|
* contentEncryptionAlgorithm
|
||||||
|
* octet string of CompressedData or FirmwarePkgData
|
||||||
|
* }
|
||||||
|
* attributes
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* ContentInfo content EXPLICIT SEQUENCE */
|
||||||
|
contentInfoContentSeqSz = SetExplicit(0, totalSz, contentInfoContentSeq);
|
||||||
|
totalSz += contentInfoContentSeqSz;
|
||||||
|
|
||||||
ret = wc_SetContentType(COMPRESSED_DATA, contentInfoTypeOid,
|
ret = wc_SetContentType(COMPRESSED_DATA, contentInfoTypeOid,
|
||||||
sizeof(contentInfoTypeOid));
|
sizeof(contentInfoTypeOid));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@@ -12690,11 +12715,11 @@ int wc_PKCS7_EncodeCompressedData(PKCS7* pkcs7, byte* output, word32 outputSz)
|
|||||||
|
|
||||||
contentInfoTypeOidSz = ret;
|
contentInfoTypeOidSz = ret;
|
||||||
totalSz += contentInfoTypeOidSz;
|
totalSz += contentInfoTypeOidSz;
|
||||||
}
|
|
||||||
|
|
||||||
/* ContentInfo SEQUENCE */
|
/* ContentInfo SEQUENCE */
|
||||||
contentInfoSeqSz = SetSequence(totalSz, contentInfoSeq);
|
contentInfoSeqSz = SetSequence(totalSz, contentInfoSeq);
|
||||||
totalSz += contentInfoSeqSz;
|
totalSz += contentInfoSeqSz;
|
||||||
|
}
|
||||||
|
|
||||||
if (outputSz < totalSz) {
|
if (outputSz < totalSz) {
|
||||||
XFREE(compressed, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
|
XFREE(compressed, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
|
||||||
@@ -12702,12 +12727,18 @@ int wc_PKCS7_EncodeCompressedData(PKCS7* pkcs7, byte* output, word32 outputSz)
|
|||||||
}
|
}
|
||||||
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
XMEMCPY(output + idx, contentInfoSeq, contentInfoSeqSz);
|
if (contentInfoSeqSz > 0) {
|
||||||
idx += contentInfoSeqSz;
|
XMEMCPY(output + idx, contentInfoSeq, contentInfoSeqSz);
|
||||||
XMEMCPY(output + idx, contentInfoTypeOid, contentInfoTypeOidSz);
|
idx += contentInfoSeqSz;
|
||||||
idx += contentInfoTypeOidSz;
|
}
|
||||||
XMEMCPY(output + idx, contentInfoContentSeq, contentInfoContentSeqSz);
|
if (contentInfoTypeOidSz > 0) {
|
||||||
idx += contentInfoContentSeqSz;
|
XMEMCPY(output + idx, contentInfoTypeOid, contentInfoTypeOidSz);
|
||||||
|
idx += contentInfoTypeOidSz;
|
||||||
|
}
|
||||||
|
if (contentInfoContentSeqSz > 0) {
|
||||||
|
XMEMCPY(output + idx, contentInfoContentSeq, contentInfoContentSeqSz);
|
||||||
|
idx += contentInfoContentSeqSz;
|
||||||
|
}
|
||||||
XMEMCPY(output + idx, compressedDataSeq, compressedDataSeqSz);
|
XMEMCPY(output + idx, compressedDataSeq, compressedDataSeqSz);
|
||||||
idx += compressedDataSeqSz;
|
idx += compressedDataSeqSz;
|
||||||
XMEMCPY(output + idx, cmsVersion, cmsVersionSz);
|
XMEMCPY(output + idx, cmsVersion, cmsVersionSz);
|
||||||
|
Reference in New Issue
Block a user