crypt32(5/20): Add tests for updating signed encoded messages
Juan Lang
juan.lang at gmail.com
Mon Jul 23 20:27:47 CDT 2007
--Juan
-------------- next part --------------
From 99504485173190e0546e9724537a4bd6740caa99 Mon Sep 17 00:00:00 2001
From: Juan Lang <juanlang at juan.corp.google.com>
Date: Mon, 23 Jul 2007 17:26:14 -0700
Subject: [PATCH] Add tests for updating signed encoded messages
---
dlls/crypt32/tests/msg.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 116 insertions(+), 0 deletions(-)
diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c
index d2d9488..250ac9f 100644
--- a/dlls/crypt32/tests/msg.c
+++ b/dlls/crypt32/tests/msg.c
@@ -1061,9 +1061,125 @@ static void test_signed_msg_open(void)
PROV_RSA_FULL, CRYPT_DELETEKEYSET);
}
+static const BYTE privKey[] = {
+ 0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00,
+ 0x02, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x79, 0x10, 0x1c, 0xd0, 0x6b, 0x10,
+ 0x18, 0x30, 0x94, 0x61, 0xdc, 0x0e, 0xcb, 0x96, 0x4e, 0x21, 0x3f, 0x79, 0xcd,
+ 0xa9, 0x17, 0x62, 0xbc, 0xbb, 0x61, 0x4c, 0xe0, 0x75, 0x38, 0x6c, 0xf3, 0xde,
+ 0x60, 0x86, 0x03, 0x97, 0x65, 0xeb, 0x1e, 0x6b, 0xdb, 0x53, 0x85, 0xad, 0x68,
+ 0x21, 0xf1, 0x5d, 0xe7, 0x1f, 0xe6, 0x53, 0xb4, 0xbb, 0x59, 0x3e, 0x14, 0x27,
+ 0xb1, 0x83, 0xa7, 0x3a, 0x54, 0xe2, 0x8f, 0x65, 0x8e, 0x6a, 0x4a, 0xcf, 0x3b,
+ 0x1f, 0x65, 0xff, 0xfe, 0xf1, 0x31, 0x3a, 0x37, 0x7a, 0x8b, 0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x53, 0x52, 0x97, 0x9a, 0x76, 0x79, 0xda,
+ 0x93, 0x32, 0x16, 0xec, 0x69, 0x51, 0x1a, 0x4e, 0xc3, 0xf1, 0x72, 0x80, 0x78,
+ 0x5e, 0x66, 0x4a, 0x8d, 0x85, 0x2f, 0x3f, 0xb2, 0xa7 };
+
+static void test_signed_msg_update(void)
+{
+ HCRYPTMSG msg;
+ BOOL ret;
+ CMSG_SIGNED_ENCODE_INFO signInfo = { sizeof(signInfo), 0 };
+ CMSG_SIGNER_ENCODE_INFO signer = { sizeof(signer), 0 };
+ CERT_INFO certInfo = { 0 };
+ HCRYPTKEY key;
+ char oid_rsa_md5[] = szOID_RSA_MD5;
+
+ certInfo.SerialNumber.cbData = sizeof(serialNum);
+ certInfo.SerialNumber.pbData = serialNum;
+ certInfo.Issuer.cbData = sizeof(encodedCommonName);
+ certInfo.Issuer.pbData = encodedCommonName;
+ signer.pCertInfo = &certInfo;
+ signer.HashAlgorithm.pszObjId = oid_rsa_md5;
+ signInfo.cSigners = 1;
+ signInfo.rgSigners = &signer;
+ ret = CryptAcquireContextW(&signer.hCryptProv, cspNameW, NULL,
+ PROV_RSA_FULL, CRYPT_NEWKEYSET);
+ if (!ret && GetLastError() == NTE_EXISTS)
+ ret = CryptAcquireContextW(&signer.hCryptProv, cspNameW, NULL,
+ PROV_RSA_FULL, 0);
+ ok(ret, "CryptAcquireContextW failed: %x\n", GetLastError());
+ msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING,
+ CMSG_DETACHED_FLAG, CMSG_SIGNED, &signInfo, NULL, NULL);
+ ok(msg != NULL, "CryptMsgOpenToEncode failed: %x\n", GetLastError());
+ /* CMSG_SIGNED allows non-final updates. */
+ ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
+ todo_wine
+ ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
+ /* CMSG_SIGNED also allows non-final updates with no data. */
+ ret = CryptMsgUpdate(msg, NULL, 0, FALSE);
+ todo_wine
+ ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
+ /* The final update requires a private key in the hCryptProv, in order to
+ * generate the signature.
+ */
+ SetLastError(0xdeadbeef);
+ ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
+ todo_wine
+ ok(!ret && GetLastError() == NTE_BAD_KEYSET,
+ "Expected NTE_BAD_KEYSET, got %x\n", GetLastError());
+ ret = CryptImportKey(signer.hCryptProv, (LPBYTE)privKey, sizeof(privKey),
+ 0, 0, &key);
+ ok(ret, "CryptImportKey failed: %08x\n", GetLastError());
+ /* The final update should be able to succeed now that a key exists, but
+ * the previous (invalid) final update prevents it.
+ */
+ SetLastError(0xdeadbeef);
+ ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
+ ok(!ret && GetLastError() == CRYPT_E_MSG_ERROR,
+ "Expected CRYPT_E_MSG_ERROR, got %x\n", GetLastError());
+ CryptMsgClose(msg);
+
+ msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING,
+ CMSG_DETACHED_FLAG, CMSG_SIGNED, &signInfo, NULL, NULL);
+ ok(msg != NULL, "CryptMsgOpenToEncode failed: %x\n", GetLastError());
+ /* CMSG_SIGNED allows non-final updates. */
+ ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
+ todo_wine
+ ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
+ /* CMSG_SIGNED also allows non-final updates with no data. */
+ ret = CryptMsgUpdate(msg, NULL, 0, FALSE);
+ todo_wine
+ ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
+ /* Now that the private key exists, the final update can succeed (even
+ * with no data.)
+ */
+ ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
+ todo_wine
+ ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
+ /* But no updates are allowed after the final update. */
+ SetLastError(0xdeadbeef);
+ ret = CryptMsgUpdate(msg, NULL, 0, FALSE);
+ ok(!ret && GetLastError() == CRYPT_E_MSG_ERROR,
+ "Expected CRYPT_E_MSG_ERROR, got %x\n", GetLastError());
+ SetLastError(0xdeadbeef);
+ ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
+ ok(!ret && GetLastError() == CRYPT_E_MSG_ERROR,
+ "Expected CRYPT_E_MSG_ERROR, got %x\n", GetLastError());
+ CryptMsgClose(msg);
+
+ CryptDestroyKey(key);
+ CryptReleaseContext(signer.hCryptProv, 0);
+ CryptAcquireContextW(&signer.hCryptProv, cspNameW, NULL, PROV_RSA_FULL,
+ CRYPT_DELETEKEYSET);
+}
+
static void test_signed_msg(void)
{
test_signed_msg_open();
+ test_signed_msg_update();
}
static CRYPT_DATA_BLOB b4 = { 0, NULL };
--
1.4.1
More information about the wine-patches
mailing list