From 9db120d0153b109c36015c70dbea7e64fc5b7df7 Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Wed, 20 Aug 2008 13:12:59 -0700 Subject: [PATCH] crypt32: Add tests for verifying the hash of a detached hash message. --- dlls/crypt32/tests/msg.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c index ba35b891311..8cab0eb2520 100644 --- a/dlls/crypt32/tests/msg.c +++ b/dlls/crypt32/tests/msg.c @@ -2675,6 +2675,53 @@ static void test_msg_control(void) "Expected CRYPT_E_INVALID_MSG_TYPE, got %08x\n", GetLastError()); CryptMsgClose(msg); + msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, CMSG_DETACHED_FLAG, 0, 0, + NULL, NULL); + /* Can't verify the hash of a detached message before it's been updated. */ + SetLastError(0xdeadbeef); + ret = CryptMsgControl(msg, 0, CMSG_CTRL_VERIFY_HASH, NULL); + ok(!ret && GetLastError() == CRYPT_E_INVALID_MSG_TYPE, + "Expected CRYPT_E_INVALID_MSG_TYPE, got %08x\n", GetLastError()); + ret = CryptMsgUpdate(msg, detachedHashContent, sizeof(detachedHashContent), + TRUE); + ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError()); + /* Still can't verify the hash of a detached message with the content + * of the detached hash given.. + */ + 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 + * hash fails. + */ + SetLastError(0xdeadbeef); + ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE); + todo_wine + ok(!ret && GetLastError() == NTE_BAD_HASH_STATE, + "Expected NTE_BAD_HASH_STATE, got %08x\n", GetLastError()); + CryptMsgClose(msg); + + /* Finally, verifying the hash of a detached message in the correct order: + * 1. Update with the detached hash message + * 2. Update with the content of the message + * 3. Verifying the hash of the message + * succeeds. + */ + msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, CMSG_DETACHED_FLAG, 0, 0, + NULL, NULL); + ret = CryptMsgUpdate(msg, detachedHashContent, sizeof(detachedHashContent), + TRUE); + ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError()); + ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE); + 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); + msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, 0, CMSG_SIGNED, 0, NULL, NULL); /* Can't verify the hash of a signed message */ -- 2.11.4.GIT