Juan Lang : crypt32: Fix verifying the hash of a detached hash message.
Alexandre Julliard
julliard at winehq.org
Wed Aug 27 08:24:10 CDT 2008
Module: wine
Branch: master
Commit: 13545bee2ddbc2201ea52fb15fe90e6b4fc6d378
URL: http://source.winehq.org/git/wine.git/?a=commit;h=13545bee2ddbc2201ea52fb15fe90e6b4fc6d378
Author: Juan Lang <juan.lang at gmail.com>
Date: Wed Aug 20 17:17:52 2008 -0700
crypt32: Fix verifying the hash of a detached hash message.
---
dlls/crypt32/msg.c | 43 +++++++++++++++++++++++++++++++++++--------
dlls/crypt32/tests/msg.c | 3 ---
2 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/dlls/crypt32/msg.c b/dlls/crypt32/msg.c
index 53fff29..82bed31 100644
--- a/dlls/crypt32/msg.c
+++ b/dlls/crypt32/msg.c
@@ -1607,12 +1607,15 @@ static BOOL CDecodeMsg_DecodeHashedContent(CDecodeMsg *msg,
(const BYTE *)digestedData->ContentInfo.pszObjId,
digestedData->ContentInfo.pszObjId ?
strlen(digestedData->ContentInfo.pszObjId) + 1 : 0);
- if (digestedData->ContentInfo.Content.cbData)
- CDecodeMsg_DecodeDataContent(msg,
- &digestedData->ContentInfo.Content);
- else
- ContextPropertyList_SetProperty(msg->properties,
- CMSG_CONTENT_PARAM, NULL, 0);
+ if (!(msg->base.open_flags & CMSG_DETACHED_FLAG))
+ {
+ if (digestedData->ContentInfo.Content.cbData)
+ CDecodeMsg_DecodeDataContent(msg,
+ &digestedData->ContentInfo.Content);
+ else
+ ContextPropertyList_SetProperty(msg->properties,
+ CMSG_CONTENT_PARAM, NULL, 0);
+ }
ContextPropertyList_SetProperty(msg->properties, CMSG_HASH_DATA_PARAM,
digestedData->hash.pbData, digestedData->hash.cbData);
LocalFree(digestedData);
@@ -1715,6 +1718,17 @@ static BOOL CDecodeMsg_FinalizeHashedContent(CDecodeMsg *msg,
{
CRYPT_DATA_BLOB content;
+ if (msg->base.open_flags & CMSG_DETACHED_FLAG)
+ {
+ /* Unlike for non-detached messages, the data were never stored as
+ * the content param, but were saved in msg->detached_data instead.
+ * Set the content property with the detached data so the data may
+ * be hashed.
+ */
+ ContextPropertyList_SetProperty(msg->properties,
+ CMSG_CONTENT_PARAM, msg->detached_data.pbData,
+ msg->detached_data.cbData);
+ }
ret = ContextPropertyList_FindProperty(msg->properties,
CMSG_CONTENT_PARAM, &content);
if (ret)
@@ -2480,12 +2494,25 @@ static BOOL CDecodeHashMsg_VerifyHash(CDecodeMsg *msg)
ret = CDecodeHashMsg_GetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0,
computedHash, &computedHashSize);
if (ret)
- ret = !memcmp(hashBlob.pbData, computedHash,
- hashBlob.cbData);
+ {
+ if (memcmp(hashBlob.pbData, computedHash, hashBlob.cbData))
+ {
+ SetLastError(CRYPT_E_HASH_VALUE);
+ ret = FALSE;
+ }
+ }
CryptMemFree(computedHash);
}
else
+ {
+ SetLastError(ERROR_OUTOFMEMORY);
ret = FALSE;
+ }
+ }
+ else
+ {
+ SetLastError(CRYPT_E_HASH_VALUE);
+ ret = FALSE;
}
}
return ret;
diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c
index 8cab0eb..c734e6f 100644
--- a/dlls/crypt32/tests/msg.c
+++ b/dlls/crypt32/tests/msg.c
@@ -2660,7 +2660,6 @@ static void test_msg_control(void)
TRUE);
/* Oddly enough, this fails */
ret = CryptMsgControl(msg, 0, CMSG_CTRL_VERIFY_HASH, NULL);
- todo_wine
ok(!ret, "Expected failure\n");
CryptMsgClose(msg);
msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, 0, CMSG_HASHED, 0, NULL,
@@ -2690,7 +2689,6 @@ static void test_msg_control(void)
*/
SetLastError(0xdeadbeef);
ret = CryptMsgControl(msg, 0, CMSG_CTRL_VERIFY_HASH, NULL);
- todo_wine
ok(!ret && GetLastError() == CRYPT_E_HASH_VALUE,
"Expected CRYPT_E_HASH_VALUE, got %08x\n", GetLastError());
/* and giving the content of the message after attempting to verify the
@@ -2718,7 +2716,6 @@ static void test_msg_control(void)
ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError());
SetLastError(0xdeadbeef);
ret = CryptMsgControl(msg, 0, CMSG_CTRL_VERIFY_HASH, NULL);
- todo_wine
ok(ret, "CryptMsgControl failed: %08x\n", GetLastError());
CryptMsgClose(msg);
More information about the wine-cvs
mailing list