From 32466b3a83bb88ba4b91a3af23dce5e9a5a8fa93 Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Mon, 8 Sep 2008 12:46:04 -0700 Subject: [PATCH] crypt32: Test verifying the signature of a detached signed message. --- dlls/crypt32/tests/msg.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c index 2783815fdb6..b03f5a41891 100644 --- a/dlls/crypt32/tests/msg.c +++ b/dlls/crypt32/tests/msg.c @@ -2841,6 +2841,37 @@ static void test_msg_control(void) ret = CryptMsgControl(msg, 0, CMSG_CTRL_VERIFY_SIGNATURE, &certInfo); ok(ret, "CryptMsgControl failed: %08x\n", GetLastError()); CryptMsgClose(msg); + + /* Test verifying signature of a detached signed message */ + msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, CMSG_DETACHED_FLAG, 0, 0, + NULL, NULL); + ret = CryptMsgUpdate(msg, detachedSignedContent, + sizeof(detachedSignedContent), TRUE); + ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError()); + /* Can't verify the sig without having updated the data */ + SetLastError(0xdeadbeef); + ret = CryptMsgControl(msg, 0, CMSG_CTRL_VERIFY_SIGNATURE, &certInfo); + ok(!ret && GetLastError() == NTE_BAD_SIGNATURE, + "expected NTE_BAD_SIGNATURE, got %08x\n", GetLastError()); + /* Now that the signature's been checked, can't do the final update */ + 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); + /* Updating with the detached portion of the message and the data of the + * the message allows the sig to be verified. + */ + msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, CMSG_DETACHED_FLAG, 0, 0, + NULL, NULL); + ret = CryptMsgUpdate(msg, detachedSignedContent, + sizeof(detachedSignedContent), TRUE); + ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError()); + ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE); + ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError()); + ret = CryptMsgControl(msg, 0, CMSG_CTRL_VERIFY_SIGNATURE, &certInfo); + ok(ret, "CryptMsgControl failed: %08x\n", GetLastError()); + CryptMsgClose(msg); } /* win9x has much less parameter checks and will crash on many tests -- 2.11.4.GIT