crypt32(1/9): A decoded message's parameters are dependent on its
type
Juan Lang
juan.lang at gmail.com
Fri Jul 27 13:00:40 CDT 2007
--Juan
-------------- next part --------------
From f88f8b773613ebff2cf5765300e6ec77264014bf Mon Sep 17 00:00:00 2001
From: Juan Lang <juanlang at juan.corp.google.com>
Date: Fri, 27 Jul 2007 10:55:15 -0700
Subject: [PATCH] A decoded message's parameters are dependent on its type
---
dlls/crypt32/msg.c | 61 ++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/dlls/crypt32/msg.c b/dlls/crypt32/msg.c
index d932815..f6cddbb 100644
--- a/dlls/crypt32/msg.c
+++ b/dlls/crypt32/msg.c
@@ -1239,7 +1239,9 @@ typedef struct _CDecodeMsg
CryptMsgBase base;
DWORD type;
HCRYPTPROV crypt_prov;
- HCRYPTHASH hash;
+ union {
+ HCRYPTHASH hash;
+ } u;
CRYPT_DATA_BLOB msg_data;
PCONTEXT_PROPERTY_LIST properties;
} CDecodeMsg;
@@ -1250,7 +1252,12 @@ static void CDecodeMsg_Close(HCRYPTMSG h
if (msg->base.open_flags & CMSG_CRYPT_RELEASE_CONTEXT_FLAG)
CryptReleaseContext(msg->crypt_prov, 0);
- CryptDestroyHash(msg->hash);
+ switch (msg->type)
+ {
+ case CMSG_HASHED:
+ CryptDestroyHash(msg->u.hash);
+ break;
+ }
CryptMemFree(msg->msg_data.pbData);
ContextPropertyList_Free(msg->properties);
}
@@ -1479,10 +1486,9 @@ static BOOL CDecodeMsg_Update(HCRYPTMSG
return ret;
}
-static BOOL CDecodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
+static BOOL CDecodeHashMsg_GetParam(CDecodeMsg *msg, DWORD dwParamType,
DWORD dwIndex, void *pvData, DWORD *pcbData)
{
- CDecodeMsg *msg = (CDecodeMsg *)hCryptMsg;
BOOL ret = FALSE;
switch (dwParamType)
@@ -1508,7 +1514,7 @@ static BOOL CDecodeMsg_GetParam(HCRYPTMS
break;
}
case CMSG_COMPUTED_HASH_PARAM:
- if (!msg->hash)
+ if (!msg->u.hash)
{
CRYPT_ALGORITHM_IDENTIFIER *hashAlgoID = NULL;
DWORD size = 0;
@@ -1520,7 +1526,7 @@ static BOOL CDecodeMsg_GetParam(HCRYPTMS
hashAlgoID, &size);
if (ret)
algID = CertOIDToAlgId(hashAlgoID->pszObjId);
- ret = CryptCreateHash(msg->crypt_prov, algID, 0, 0, &msg->hash);
+ ret = CryptCreateHash(msg->crypt_prov, algID, 0, 0, &msg->u.hash);
if (ret)
{
CRYPT_DATA_BLOB content;
@@ -1528,7 +1534,7 @@ static BOOL CDecodeMsg_GetParam(HCRYPTMS
ret = ContextPropertyList_FindProperty(msg->properties,
CMSG_CONTENT_PARAM, &content);
if (ret)
- ret = CryptHashData(msg->hash, content.pbData,
+ ret = CryptHashData(msg->u.hash, content.pbData,
content.cbData, 0);
}
CryptMemFree(hashAlgoID);
@@ -1536,7 +1542,8 @@ static BOOL CDecodeMsg_GetParam(HCRYPTMS
else
ret = TRUE;
if (ret)
- ret = CryptGetHashParam(msg->hash, HP_HASHVAL, pvData, pcbData, 0);
+ ret = CryptGetHashParam(msg->u.hash, HP_HASHVAL, pvData, pcbData,
+ 0);
break;
default:
{
@@ -1553,6 +1560,42 @@ static BOOL CDecodeMsg_GetParam(HCRYPTMS
return ret;
}
+static BOOL CDecodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
+ DWORD dwIndex, void *pvData, DWORD *pcbData)
+{
+ CDecodeMsg *msg = (CDecodeMsg *)hCryptMsg;
+ BOOL ret = FALSE;
+
+ switch (msg->type)
+ {
+ case CMSG_HASHED:
+ ret = CDecodeHashMsg_GetParam(msg, dwParamType, dwIndex, pvData,
+ pcbData);
+ break;
+ default:
+ switch (dwParamType)
+ {
+ case CMSG_TYPE_PARAM:
+ ret = CRYPT_CopyParam(pvData, pcbData, (const BYTE *)&msg->type,
+ sizeof(msg->type));
+ break;
+ default:
+ {
+ CRYPT_DATA_BLOB blob;
+
+ ret = ContextPropertyList_FindProperty(msg->properties, dwParamType,
+ &blob);
+ if (ret)
+ ret = CRYPT_CopyParam(pvData, pcbData, blob.pbData,
+ blob.cbData);
+ else
+ SetLastError(CRYPT_E_INVALID_MSG_TYPE);
+ }
+ }
+ }
+ return ret;
+}
+
HCRYPTMSG WINAPI CryptMsgOpenToDecode(DWORD dwMsgEncodingType, DWORD dwFlags,
DWORD dwMsgType, HCRYPTPROV hCryptProv, PCERT_INFO pRecipientInfo,
PCMSG_STREAM_INFO pStreamInfo)
@@ -1580,7 +1623,7 @@ HCRYPTMSG WINAPI CryptMsgOpenToDecode(DW
msg->crypt_prov = CRYPT_GetDefaultProvider();
msg->base.open_flags &= ~CMSG_CRYPT_RELEASE_CONTEXT_FLAG;
}
- msg->hash = 0;
+ memset(&msg->u, 0, sizeof(msg->u));
msg->msg_data.cbData = 0;
msg->msg_data.pbData = NULL;
msg->properties = ContextPropertyList_Create();
--
1.4.1
More information about the wine-patches
mailing list