From 10975136970b03183bf2fa31c2452e0c30f768ed Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Tue, 26 Aug 2008 09:38:38 -0700 Subject: [PATCH] crypt32: Add tests for CryptVerifyDetachedHashMessage. --- dlls/crypt32/tests/message.c | 110 +++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/dlls/crypt32/tests/message.c b/dlls/crypt32/tests/message.c index 11b8c1c1fce..b3b6abeba0a 100644 --- a/dlls/crypt32/tests/message.c +++ b/dlls/crypt32/tests/message.c @@ -84,6 +84,115 @@ static void test_msg_get_signer_count(void) ok(count == 1, "Expected 1, got %d\n", count); } +static BYTE detachedHashContent[] = { +0x30,0x3f,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x05,0xa0,0x32, +0x30,0x30,0x02,0x01,0x00,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d, +0x02,0x05,0x05,0x00,0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01, +0x07,0x01,0x04,0x10,0x08,0xd6,0xc0,0x5a,0x21,0x51,0x2a,0x79,0xa1,0xdf,0xeb, +0x9d,0x2a,0x8f,0x26,0x2f }; +static const BYTE msgData[] = { 1, 2, 3, 4 }; + +static void test_verify_detached_message_hash(void) +{ + BOOL ret; + CRYPT_HASH_MESSAGE_PARA para; + DWORD size, hashSize; + const BYTE *pMsgData = msgData; + BYTE hash[16]; + + if (0) + { + ret = CryptVerifyDetachedMessageHash(NULL, NULL, 0, 0, NULL, NULL, NULL, + NULL); + } + memset(¶, 0, sizeof(para)); + SetLastError(0xdeadbeef); + ret = CryptVerifyDetachedMessageHash(¶, NULL, 0, 0, NULL, NULL, NULL, + NULL); + todo_wine + ok(!ret && GetLastError() == E_INVALIDARG, + "expected E_INVALIDARG, got %08x\n", GetLastError()); + para.cbSize = sizeof(para); + SetLastError(0xdeadbeef); + ret = CryptVerifyDetachedMessageHash(¶, NULL, 0, 0, NULL, NULL, NULL, + NULL); + todo_wine + ok(!ret && GetLastError() == E_INVALIDARG, + "expected E_INVALIDARG, got %08x\n", GetLastError()); + para.dwMsgEncodingType = PKCS_7_ASN_ENCODING; + SetLastError(0xdeadbeef); + ret = CryptVerifyDetachedMessageHash(¶, NULL, 0, 0, NULL, NULL, NULL, + NULL); + todo_wine + ok(!ret && GetLastError() == CRYPT_E_ASN1_EOD, + "expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError()); + para.dwMsgEncodingType = X509_ASN_ENCODING; + SetLastError(0xdeadbeef); + ret = CryptVerifyDetachedMessageHash(¶, NULL, 0, 0, NULL, NULL, NULL, + NULL); + todo_wine + ok(!ret && GetLastError() == E_INVALIDARG, + "expected E_INVALIDARG, got %08x\n", GetLastError()); + para.dwMsgEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING; + SetLastError(0xdeadbeef); + ret = CryptVerifyDetachedMessageHash(¶, NULL, 0, 0, NULL, NULL, NULL, + NULL); + todo_wine + ok(!ret && GetLastError() == CRYPT_E_ASN1_EOD, + "expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError()); + /* Curiously, passing no data to hash succeeds.. */ + ret = CryptVerifyDetachedMessageHash(¶, detachedHashContent, + sizeof(detachedHashContent), 0, NULL, NULL, NULL, NULL); + todo_wine + ok(ret, "CryptVerifyDetachedMessageHash failed: %08x\n", GetLastError()); + /* as does passing the actual content of the message to hash.. */ + size = sizeof(msgData); + pMsgData = msgData; + ret = CryptVerifyDetachedMessageHash(¶, detachedHashContent, + sizeof(detachedHashContent), 1, &pMsgData, &size, NULL, NULL); + todo_wine + ok(ret, "CryptVerifyDetachedMessageHash failed: %08x\n", GetLastError()); + /* while passing data to hash that isn't the content of the message fails. + */ + size = sizeof(detachedHashContent); + pMsgData = detachedHashContent; + SetLastError(0xdeadbeef); + ret = CryptVerifyDetachedMessageHash(¶, detachedHashContent, + sizeof(detachedHashContent), 1, &pMsgData, &size, NULL, NULL); + todo_wine + ok(!ret && GetLastError() == CRYPT_E_HASH_VALUE, + "expected CRYPT_E_HASH_VALUE, got %08x\n", GetLastError()); + /* Getting the size of the hash while passing no hash data causes the + * hash to be checked (and fail.) + */ + SetLastError(0xdeadbeef); + ret = CryptVerifyDetachedMessageHash(¶, detachedHashContent, + sizeof(detachedHashContent), 0, NULL, NULL, NULL, &hashSize); + todo_wine + ok(!ret && GetLastError() == CRYPT_E_HASH_VALUE, + "expected CRYPT_E_HASH_VALUE, got %08x\n", GetLastError()); + size = sizeof(msgData); + pMsgData = msgData; + ret = CryptVerifyDetachedMessageHash(¶, detachedHashContent, + sizeof(detachedHashContent), 1, &pMsgData, &size, NULL, &hashSize); + todo_wine { + ok(ret, "CryptVerifyDetachedMessageHash failed: %08x\n", GetLastError()); + ok(hashSize == sizeof(hash), "unexpected size %d\n", hashSize); + } + hashSize = 1; + SetLastError(0xdeadbeef); + ret = CryptVerifyDetachedMessageHash(¶, detachedHashContent, + sizeof(detachedHashContent), 1, &pMsgData, &size, hash, &hashSize); + todo_wine + ok(!ret && GetLastError() == ERROR_MORE_DATA, + "expected ERROR_MORE_DATA, got %08x\n", GetLastError()); + hashSize = sizeof(hash); + ret = CryptVerifyDetachedMessageHash(¶, detachedHashContent, + sizeof(detachedHashContent), 1, &pMsgData, &size, hash, &hashSize); + todo_wine + ok(ret, "CryptVerifyDetachedMessageHash failed: %08x\n", GetLastError()); +} + static const BYTE signedContent[] = { 0x30,0x81,0xb2,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,0xa0, 0x81,0xa4,0x30,0x81,0xa1,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,0x2a, @@ -404,6 +513,7 @@ static void test_hash_message(void) START_TEST(message) { test_msg_get_signer_count(); + test_verify_detached_message_hash(); test_verify_message_signature(); test_hash_message(); }