Commit 2ef62f90 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

crypt32: Make sure that the provider supports algorithm of the message being decoded.

parent 2a356bc1
...@@ -926,17 +926,25 @@ typedef struct _CSignedMsgData ...@@ -926,17 +926,25 @@ typedef struct _CSignedMsgData
* been constructed. * been constructed.
*/ */
static BOOL CSignedMsgData_ConstructSignerHandles(CSignedMsgData *msg_data, static BOOL CSignedMsgData_ConstructSignerHandles(CSignedMsgData *msg_data,
DWORD signerIndex, HCRYPTPROV crypt_prov) DWORD signerIndex, HCRYPTPROV *crypt_prov, DWORD *flags)
{ {
ALG_ID algID; ALG_ID algID;
BOOL ret; BOOL ret;
algID = CertOIDToAlgId( algID = CertOIDToAlgId(
msg_data->info->rgSignerInfo[signerIndex].HashAlgorithm.pszObjId); msg_data->info->rgSignerInfo[signerIndex].HashAlgorithm.pszObjId);
ret = CryptCreateHash(crypt_prov, algID, 0, 0,
if (!*crypt_prov)
{
*crypt_prov = I_CryptGetDefaultCryptProv(algID);
if (!*crypt_prov) return FALSE;
*flags &= ~CMSG_CRYPT_RELEASE_CONTEXT_FLAG;
}
ret = CryptCreateHash(*crypt_prov, algID, 0, 0,
&msg_data->signerHandles->contentHash); &msg_data->signerHandles->contentHash);
if (ret && msg_data->info->rgSignerInfo[signerIndex].AuthAttrs.cAttr > 0) if (ret && msg_data->info->rgSignerInfo[signerIndex].AuthAttrs.cAttr > 0)
ret = CryptCreateHash(crypt_prov, algID, 0, 0, ret = CryptCreateHash(*crypt_prov, algID, 0, 0,
&msg_data->signerHandles->authAttrHash); &msg_data->signerHandles->authAttrHash);
return ret; return ret;
} }
...@@ -1434,7 +1442,7 @@ static HCRYPTMSG CSignedEncodeMsg_Open(DWORD dwFlags, ...@@ -1434,7 +1442,7 @@ static HCRYPTMSG CSignedEncodeMsg_Open(DWORD dwFlags,
if (ret) if (ret)
{ {
ret = CSignedMsgData_ConstructSignerHandles( ret = CSignedMsgData_ConstructSignerHandles(
&msg->msg_data, i, info->rgSigners[i].hCryptProv); &msg->msg_data, i, &info->rgSigners[i].hCryptProv, &dwFlags);
if (dwFlags & CMSG_CRYPT_RELEASE_CONTEXT_FLAG) if (dwFlags & CMSG_CRYPT_RELEASE_CONTEXT_FLAG)
CryptReleaseContext(info->rgSigners[i].hCryptProv, CryptReleaseContext(info->rgSigners[i].hCryptProv,
0); 0);
...@@ -2092,7 +2100,7 @@ static void CDecodeMsg_Close(HCRYPTMSG hCryptMsg) ...@@ -2092,7 +2100,7 @@ static void CDecodeMsg_Close(HCRYPTMSG hCryptMsg)
{ {
CDecodeMsg *msg = hCryptMsg; CDecodeMsg *msg = hCryptMsg;
if (msg->base.open_flags & CMSG_CRYPT_RELEASE_CONTEXT_FLAG) if (msg->crypt_prov && msg->base.open_flags & CMSG_CRYPT_RELEASE_CONTEXT_FLAG)
CryptReleaseContext(msg->crypt_prov, 0); CryptReleaseContext(msg->crypt_prov, 0);
switch (msg->type) switch (msg->type)
{ {
...@@ -2343,6 +2351,14 @@ static BOOL CDecodeMsg_FinalizeHashedContent(CDecodeMsg *msg, ...@@ -2343,6 +2351,14 @@ static BOOL CDecodeMsg_FinalizeHashedContent(CDecodeMsg *msg,
&size); &size);
if (ret) if (ret)
algID = CertOIDToAlgId(hashAlgoID->pszObjId); algID = CertOIDToAlgId(hashAlgoID->pszObjId);
if (!msg->crypt_prov)
{
msg->crypt_prov = I_CryptGetDefaultCryptProv(algID);
if (msg->crypt_prov)
msg->base.open_flags &= ~CMSG_CRYPT_RELEASE_CONTEXT_FLAG;
}
ret = CryptCreateHash(msg->crypt_prov, algID, 0, 0, &msg->u.hash); ret = CryptCreateHash(msg->crypt_prov, algID, 0, 0, &msg->u.hash);
if (ret) if (ret)
{ {
...@@ -2389,7 +2405,7 @@ static BOOL CDecodeMsg_FinalizeSignedContent(CDecodeMsg *msg, ...@@ -2389,7 +2405,7 @@ static BOOL CDecodeMsg_FinalizeSignedContent(CDecodeMsg *msg,
ret = CSignedMsgData_AllocateHandles(&msg->u.signed_data); ret = CSignedMsgData_AllocateHandles(&msg->u.signed_data);
for (i = 0; ret && i < msg->u.signed_data.info->cSignerInfo; i++) for (i = 0; ret && i < msg->u.signed_data.info->cSignerInfo; i++)
ret = CSignedMsgData_ConstructSignerHandles(&msg->u.signed_data, i, ret = CSignedMsgData_ConstructSignerHandles(&msg->u.signed_data, i,
msg->crypt_prov); &msg->crypt_prov, &msg->base.open_flags);
if (ret) if (ret)
{ {
CRYPT_DATA_BLOB *content; CRYPT_DATA_BLOB *content;
...@@ -3555,13 +3571,7 @@ HCRYPTMSG WINAPI CryptMsgOpenToDecode(DWORD dwMsgEncodingType, DWORD dwFlags, ...@@ -3555,13 +3571,7 @@ HCRYPTMSG WINAPI CryptMsgOpenToDecode(DWORD dwMsgEncodingType, DWORD dwFlags,
CDecodeMsg_Close, CDecodeMsg_GetParam, CDecodeMsg_Update, CDecodeMsg_Close, CDecodeMsg_GetParam, CDecodeMsg_Update,
CDecodeMsg_Control); CDecodeMsg_Control);
msg->type = dwMsgType; msg->type = dwMsgType;
if (hCryptProv) msg->crypt_prov = hCryptProv;
msg->crypt_prov = hCryptProv;
else
{
msg->crypt_prov = I_CryptGetDefaultCryptProv(0);
msg->base.open_flags &= ~CMSG_CRYPT_RELEASE_CONTEXT_FLAG;
}
memset(&msg->u, 0, sizeof(msg->u)); memset(&msg->u, 0, sizeof(msg->u));
msg->msg_data.cbData = 0; msg->msg_data.cbData = 0;
msg->msg_data.pbData = NULL; msg->msg_data.pbData = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment