mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-04 21:24:43 +02:00
use SetContentType() to set SignedData content type
This commit is contained in:
committed by
David Garske
parent
ce1381dc9a
commit
56f1b68442
@@ -1064,11 +1064,6 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
|
|||||||
const byte* hashBuf, word32 hashSz, byte* output, word32* outputSz,
|
const byte* hashBuf, word32 hashSz, byte* output, word32* outputSz,
|
||||||
byte* output2, word32* output2Sz)
|
byte* output2, word32* output2Sz)
|
||||||
{
|
{
|
||||||
/* id-signedData (1.2.840.113549.1.7.2) */
|
|
||||||
static const byte outerOid[] =
|
|
||||||
{ ASN_OBJECT_ID, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01,
|
|
||||||
0x07, 0x02 };
|
|
||||||
|
|
||||||
/* contentType OID (1.2.840.113549.1.9.3) */
|
/* contentType OID (1.2.840.113549.1.9.3) */
|
||||||
const byte contentTypeOid[] =
|
const byte contentTypeOid[] =
|
||||||
{ ASN_OBJECT_ID, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xF7, 0x0d, 0x01,
|
{ ASN_OBJECT_ID, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xF7, 0x0d, 0x01,
|
||||||
@@ -1085,8 +1080,9 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
|
|||||||
int digEncAlgoId, digEncAlgoType;
|
int digEncAlgoId, digEncAlgoType;
|
||||||
byte* flatSignedAttribs = NULL;
|
byte* flatSignedAttribs = NULL;
|
||||||
word32 flatSignedAttribsSz = 0;
|
word32 flatSignedAttribsSz = 0;
|
||||||
word32 innerOidSz = sizeof(innerOid);
|
|
||||||
word32 outerOidSz = sizeof(outerOid);
|
byte signedDataOid[MAX_OID_SZ];
|
||||||
|
word32 signedDataOidSz;
|
||||||
|
|
||||||
if (pkcs7 == NULL || pkcs7->contentSz == 0 ||
|
if (pkcs7 == NULL || pkcs7->contentSz == 0 ||
|
||||||
pkcs7->encryptOID == 0 || pkcs7->hashOID == 0 || pkcs7->rng == 0 ||
|
pkcs7->encryptOID == 0 || pkcs7->hashOID == 0 || pkcs7->rng == 0 ||
|
||||||
@@ -1116,12 +1112,25 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
|
|||||||
|
|
||||||
ret = wc_SetContentType(pkcs7->contentOID, pkcs7->contentType,
|
ret = wc_SetContentType(pkcs7->contentOID, pkcs7->contentType,
|
||||||
sizeof(pkcs7->contentType));
|
sizeof(pkcs7->contentType));
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
XFREE(esd, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
pkcs7->contentTypeSz = ret;
|
pkcs7->contentTypeSz = ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set signedData outer content type */
|
||||||
|
ret = wc_SetContentType(SIGNED_DATA, signedDataOid, sizeof(signedDataOid));
|
||||||
|
if (ret < 0) {
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
XFREE(esd, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
signedDataOidSz = ret;
|
||||||
|
|
||||||
esd->hashType = wc_OidGetHash(pkcs7->hashOID);
|
esd->hashType = wc_OidGetHash(pkcs7->hashOID);
|
||||||
if (wc_HashGetDigestSize(esd->hashType) != (int)hashSz) {
|
if (wc_HashGetDigestSize(esd->hashType) != (int)hashSz) {
|
||||||
WOLFSSL_MSG("hashSz did not match hashOID");
|
WOLFSSL_MSG("hashSz did not match hashOID");
|
||||||
@@ -1238,14 +1247,14 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
|
|||||||
esd->versionSz = SetMyVersion(1, esd->version, 0);
|
esd->versionSz = SetMyVersion(1, esd->version, 0);
|
||||||
|
|
||||||
totalSz = esd->versionSz + esd->singleDigAlgoIdSz + esd->digAlgoIdSetSz +
|
totalSz = esd->versionSz + esd->singleDigAlgoIdSz + esd->digAlgoIdSetSz +
|
||||||
esd->contentInfoSeqSz + innerOidSz + esd->innerContSeqSz +
|
esd->contentInfoSeqSz + pkcs7->contentTypeSz +
|
||||||
esd->innerOctetsSz + pkcs7->contentSz;
|
esd->innerContSeqSz + esd->innerOctetsSz + pkcs7->contentSz;
|
||||||
total2Sz = esd->certsSetSz + pkcs7->singleCertSz + signerInfoSz;
|
total2Sz = esd->certsSetSz + pkcs7->singleCertSz + signerInfoSz;
|
||||||
|
|
||||||
esd->innerSeqSz = SetSequence(totalSz + total2Sz, esd->innerSeq);
|
esd->innerSeqSz = SetSequence(totalSz + total2Sz, esd->innerSeq);
|
||||||
totalSz += esd->innerSeqSz;
|
totalSz += esd->innerSeqSz;
|
||||||
esd->outerContentSz = SetExplicit(0, totalSz + total2Sz, esd->outerContent);
|
esd->outerContentSz = SetExplicit(0, totalSz + total2Sz, esd->outerContent);
|
||||||
totalSz += esd->outerContentSz + outerOidSz;
|
totalSz += esd->outerContentSz + signedDataOidSz;
|
||||||
esd->outerSeqSz = SetSequence(totalSz + total2Sz, esd->outerSeq);
|
esd->outerSeqSz = SetSequence(totalSz + total2Sz, esd->outerSeq);
|
||||||
totalSz += esd->outerSeqSz;
|
totalSz += esd->outerSeqSz;
|
||||||
|
|
||||||
@@ -1268,8 +1277,8 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
|
|||||||
idx = 0;
|
idx = 0;
|
||||||
XMEMCPY(output + idx, esd->outerSeq, esd->outerSeqSz);
|
XMEMCPY(output + idx, esd->outerSeq, esd->outerSeqSz);
|
||||||
idx += esd->outerSeqSz;
|
idx += esd->outerSeqSz;
|
||||||
XMEMCPY(output + idx, outerOid, outerOidSz);
|
XMEMCPY(output + idx, signedDataOid, signedDataOidSz);
|
||||||
idx += outerOidSz;
|
idx += signedDataOidSz;
|
||||||
XMEMCPY(output + idx, esd->outerContent, esd->outerContentSz);
|
XMEMCPY(output + idx, esd->outerContent, esd->outerContentSz);
|
||||||
idx += esd->outerContentSz;
|
idx += esd->outerContentSz;
|
||||||
XMEMCPY(output + idx, esd->innerSeq, esd->innerSeqSz);
|
XMEMCPY(output + idx, esd->innerSeq, esd->innerSeqSz);
|
||||||
|
Reference in New Issue
Block a user