crypt32: Use consistent types for storing and encoding signed encode data.
This commit is contained in:
parent
2d359268e6
commit
99c475417a
|
@ -767,13 +767,8 @@ typedef struct _CSignedEncodeMsg
|
||||||
{
|
{
|
||||||
CryptMsgBase base;
|
CryptMsgBase base;
|
||||||
CRYPT_DATA_BLOB data;
|
CRYPT_DATA_BLOB data;
|
||||||
DWORD cSigners;
|
CRYPT_SIGNED_INFO info;
|
||||||
CSignerHandles *signerHandles;
|
CSignerHandles *signerHandles;
|
||||||
PCMSG_SIGNER_INFO rgSignerInfo;
|
|
||||||
DWORD cCertEncoded;
|
|
||||||
PCERT_BLOB rgCertEncoded;
|
|
||||||
DWORD cCrlEncoded;
|
|
||||||
PCRL_BLOB rgCrlEncoded;
|
|
||||||
} CSignedEncodeMsg;
|
} CSignedEncodeMsg;
|
||||||
|
|
||||||
static void CSignedEncodeMsg_Close(HCRYPTMSG hCryptMsg)
|
static void CSignedEncodeMsg_Close(HCRYPTMSG hCryptMsg)
|
||||||
|
@ -782,17 +777,17 @@ static void CSignedEncodeMsg_Close(HCRYPTMSG hCryptMsg)
|
||||||
DWORD i;
|
DWORD i;
|
||||||
|
|
||||||
CryptMemFree(msg->data.pbData);
|
CryptMemFree(msg->data.pbData);
|
||||||
CRYPT_FreeBlobArray((BlobArray *)&msg->cCertEncoded);
|
CRYPT_FreeBlobArray((BlobArray *)&msg->info.cCertEncoded);
|
||||||
CRYPT_FreeBlobArray((BlobArray *)&msg->cCrlEncoded);
|
CRYPT_FreeBlobArray((BlobArray *)&msg->info.cCrlEncoded);
|
||||||
for (i = 0; i < msg->cSigners; i++)
|
for (i = 0; i < msg->info.cSignerInfo; i++)
|
||||||
{
|
{
|
||||||
CSignerInfo_Free(&msg->rgSignerInfo[i]);
|
CSignerInfo_Free(&msg->info.rgSignerInfo[i]);
|
||||||
CryptDestroyKey(msg->signerHandles[i].key);
|
CryptDestroyKey(msg->signerHandles[i].key);
|
||||||
CryptDestroyHash(msg->signerHandles[i].hash);
|
CryptDestroyHash(msg->signerHandles[i].hash);
|
||||||
CryptReleaseContext(msg->signerHandles[i].prov, 0);
|
CryptReleaseContext(msg->signerHandles[i].prov, 0);
|
||||||
}
|
}
|
||||||
CryptMemFree(msg->signerHandles);
|
CryptMemFree(msg->signerHandles);
|
||||||
CryptMemFree(msg->rgSignerInfo);
|
CryptMemFree(msg->info.rgSignerInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL CSignedEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
|
static BOOL CSignedEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
|
||||||
|
@ -836,14 +831,7 @@ static BOOL CSignedEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
|
||||||
CRYPT_SIGNED_INFO info;
|
CRYPT_SIGNED_INFO info;
|
||||||
char oid_rsa_data[] = szOID_RSA_data;
|
char oid_rsa_data[] = szOID_RSA_data;
|
||||||
|
|
||||||
/* Note: needs to change if CMS fields are supported */
|
memcpy(&info, &msg->info, sizeof(info));
|
||||||
info.version = CMSG_SIGNED_DATA_V1;
|
|
||||||
info.cCertEncoded = msg->cCertEncoded;
|
|
||||||
info.rgCertEncoded = msg->rgCertEncoded;
|
|
||||||
info.cCrlEncoded = msg->cCrlEncoded;
|
|
||||||
info.rgCrlEncoded = msg->rgCrlEncoded;
|
|
||||||
info.cAttrCertEncoded = 0;
|
|
||||||
info.cSignerInfo = msg->cSigners;
|
|
||||||
/* Quirk: OID is only encoded messages if an update has happened */
|
/* Quirk: OID is only encoded messages if an update has happened */
|
||||||
if (msg->base.state != MsgStateInit)
|
if (msg->base.state != MsgStateInit)
|
||||||
info.content.pszObjId = oid_rsa_data;
|
info.content.pszObjId = oid_rsa_data;
|
||||||
|
@ -865,14 +853,13 @@ static BOOL CSignedEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
|
||||||
}
|
}
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
info.rgSignerInfo = msg->rgSignerInfo;
|
ret = CRYPT_AsnEncodePKCSSignedInfo(&info, pvData, pcbData);
|
||||||
ret = CRYPT_AsnEncodePKCSSignedInfo(&info, pvData, pcbData);
|
|
||||||
LocalFree(info.content.Content.pbData);
|
LocalFree(info.content.Content.pbData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMSG_COMPUTED_HASH_PARAM:
|
case CMSG_COMPUTED_HASH_PARAM:
|
||||||
if (dwIndex >= msg->cSigners)
|
if (dwIndex >= msg->info.cSignerInfo)
|
||||||
SetLastError(CRYPT_E_INVALID_INDEX);
|
SetLastError(CRYPT_E_INVALID_INDEX);
|
||||||
else
|
else
|
||||||
ret = CryptGetHashParam(msg->signerHandles[dwIndex].hash,
|
ret = CryptGetHashParam(msg->signerHandles[dwIndex].hash,
|
||||||
|
@ -893,7 +880,7 @@ static BOOL CSignedEncodeMsg_UpdateHash(CSignedEncodeMsg *msg,
|
||||||
|
|
||||||
TRACE("(%p, %p, %d)\n", msg, pbData, cbData);
|
TRACE("(%p, %p, %d)\n", msg, pbData, cbData);
|
||||||
|
|
||||||
for (i = 0; ret && i < msg->cSigners; i++)
|
for (i = 0; ret && i < msg->info.cSignerInfo; i++)
|
||||||
ret = CryptHashData(msg->signerHandles[i].hash, pbData, cbData, 0);
|
ret = CryptHashData(msg->signerHandles[i].hash, pbData, cbData, 0);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -918,21 +905,21 @@ static BOOL CSignedEncodeMsg_Sign(CSignedEncodeMsg *msg)
|
||||||
|
|
||||||
TRACE("(%p)\n", msg);
|
TRACE("(%p)\n", msg);
|
||||||
|
|
||||||
for (i = 0; ret && i < msg->cSigners; i++)
|
for (i = 0; ret && i < msg->info.cSignerInfo; i++)
|
||||||
{
|
{
|
||||||
ret = CryptSignHashW(msg->signerHandles[i].hash, AT_SIGNATURE, NULL, 0,
|
ret = CryptSignHashW(msg->signerHandles[i].hash, AT_SIGNATURE, NULL, 0,
|
||||||
NULL, &msg->rgSignerInfo[i].EncryptedHash.cbData);
|
NULL, &msg->info.rgSignerInfo[i].EncryptedHash.cbData);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
msg->rgSignerInfo[i].EncryptedHash.pbData =
|
msg->info.rgSignerInfo[i].EncryptedHash.pbData =
|
||||||
CryptMemAlloc(msg->rgSignerInfo[i].EncryptedHash.cbData);
|
CryptMemAlloc(msg->info.rgSignerInfo[i].EncryptedHash.cbData);
|
||||||
if (msg->rgSignerInfo[i].EncryptedHash.pbData)
|
if (msg->info.rgSignerInfo[i].EncryptedHash.pbData)
|
||||||
{
|
{
|
||||||
ret = CryptSignHashW(msg->signerHandles[i].hash, AT_SIGNATURE,
|
ret = CryptSignHashW(msg->signerHandles[i].hash, AT_SIGNATURE,
|
||||||
NULL, 0, msg->rgSignerInfo[i].EncryptedHash.pbData,
|
NULL, 0, msg->info.rgSignerInfo[i].EncryptedHash.pbData,
|
||||||
&msg->rgSignerInfo[i].EncryptedHash.cbData);
|
&msg->info.rgSignerInfo[i].EncryptedHash.cbData);
|
||||||
if (ret)
|
if (ret)
|
||||||
CRYPT_ReverseBytes(&msg->rgSignerInfo[i].EncryptedHash);
|
CRYPT_ReverseBytes(&msg->info.rgSignerInfo[i].EncryptedHash);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
|
@ -1017,38 +1004,39 @@ static HCRYPTMSG CSignedEncodeMsg_Open(DWORD dwFlags,
|
||||||
CSignedEncodeMsg_Update);
|
CSignedEncodeMsg_Update);
|
||||||
msg->data.cbData = 0;
|
msg->data.cbData = 0;
|
||||||
msg->data.pbData = NULL;
|
msg->data.pbData = NULL;
|
||||||
msg->cSigners = 0;
|
memset(&msg->info, 0, sizeof(msg->info));
|
||||||
|
msg->info.version = CMSG_SIGNED_DATA_V1;
|
||||||
if (info->cSigners)
|
if (info->cSigners)
|
||||||
{
|
{
|
||||||
msg->signerHandles =
|
msg->signerHandles =
|
||||||
CryptMemAlloc(info->cSigners * sizeof(CSignerHandles));
|
CryptMemAlloc(info->cSigners * sizeof(CSignerHandles));
|
||||||
if (msg->signerHandles)
|
if (msg->signerHandles)
|
||||||
msg->rgSignerInfo =
|
msg->info.rgSignerInfo =
|
||||||
CryptMemAlloc(info->cSigners * sizeof(CMSG_SIGNER_INFO));
|
CryptMemAlloc(info->cSigners * sizeof(CMSG_SIGNER_INFO));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
msg->rgSignerInfo = NULL;
|
msg->info.rgSignerInfo = NULL;
|
||||||
}
|
}
|
||||||
if (msg->rgSignerInfo)
|
if (msg->info.rgSignerInfo)
|
||||||
{
|
{
|
||||||
msg->cSigners = info->cSigners;
|
msg->info.cSignerInfo = info->cSigners;
|
||||||
memset(msg->signerHandles, 0,
|
memset(msg->signerHandles, 0,
|
||||||
msg->cSigners * sizeof(CSignerHandles));
|
msg->info.cSignerInfo * sizeof(CSignerHandles));
|
||||||
memset(msg->rgSignerInfo, 0,
|
memset(msg->info.rgSignerInfo, 0,
|
||||||
msg->cSigners * sizeof(CMSG_SIGNER_INFO));
|
msg->info.cSignerInfo * sizeof(CMSG_SIGNER_INFO));
|
||||||
for (i = 0; ret && i < msg->cSigners; i++)
|
for (i = 0; ret && i < msg->info.cSignerInfo; i++)
|
||||||
ret = CSignerInfo_Construct(&msg->signerHandles[i],
|
ret = CSignerInfo_Construct(&msg->signerHandles[i],
|
||||||
&msg->rgSignerInfo[i], &info->rgSigners[i], dwFlags);
|
&msg->info.rgSignerInfo[i], &info->rgSigners[i], dwFlags);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
}
|
}
|
||||||
if (ret)
|
if (ret)
|
||||||
ret = CRYPT_CopyBlobArray((BlobArray *)&msg->cCertEncoded,
|
ret = CRYPT_CopyBlobArray((BlobArray *)&msg->info.cCertEncoded,
|
||||||
(const BlobArray *)&info->cCertEncoded);
|
(const BlobArray *)&info->cCertEncoded);
|
||||||
if (ret)
|
if (ret)
|
||||||
ret = CRYPT_CopyBlobArray((BlobArray *)&msg->cCrlEncoded,
|
ret = CRYPT_CopyBlobArray((BlobArray *)&msg->info.cCrlEncoded,
|
||||||
(const BlobArray *)&info->cCrlEncoded);
|
(const BlobArray *)&info->cCrlEncoded);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue