crypt32: Add tests for signed message encoding.

This commit is contained in:
Juan Lang 2007-07-23 17:29:06 -07:00 committed by Alexandre Julliard
parent cc4005829d
commit 014f282b72
1 changed files with 160 additions and 6 deletions

View File

@ -27,6 +27,8 @@
#include "wine/test.h"
static char oid_rsa_md5[] = szOID_RSA_MD5;
static void test_msg_open_to_encode(void)
{
HCRYPTMSG msg;
@ -657,7 +659,6 @@ static void test_hash_msg_open(void)
{
HCRYPTMSG msg;
CMSG_HASHED_ENCODE_INFO hashInfo = { 0 };
static char oid_rsa_md5[] = szOID_RSA_MD5;
CMSG_STREAM_INFO streamInfo = { 0, nop_stream_output, NULL };
SetLastError(0xdeadbeef);
@ -690,7 +691,6 @@ static void test_hash_msg_update(void)
{
HCRYPTMSG msg;
BOOL ret;
static char oid_rsa_md5[] = szOID_RSA_MD5;
CMSG_HASHED_ENCODE_INFO hashInfo = { sizeof(hashInfo), 0,
{ oid_rsa_md5, { 0, NULL } }, NULL };
CMSG_STREAM_INFO streamInfo = { 0, nop_stream_output, NULL };
@ -756,7 +756,6 @@ static void test_hash_msg_get_param(void)
{
HCRYPTMSG msg;
BOOL ret;
static char oid_rsa_md5[] = szOID_RSA_MD5;
CMSG_HASHED_ENCODE_INFO hashInfo = { sizeof(hashInfo), 0,
{ oid_rsa_md5, { 0, NULL } }, NULL };
DWORD size, value;
@ -875,7 +874,6 @@ static void test_hash_msg_encoding(void)
BOOL ret;
struct update_accum accum = { 0, NULL }, empty_accum = { 0, NULL };
CMSG_STREAM_INFO streamInfo = { 0, accumulating_stream_output, &accum };
static char oid_rsa_md5[] = szOID_RSA_MD5;
hashInfo.HashAlgorithm.pszObjId = oid_rsa_md5;
msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, 0, CMSG_HASHED, &hashInfo,
@ -984,7 +982,6 @@ static void test_signed_msg_open(void)
CMSG_SIGNED_ENCODE_INFO signInfo = { 0 };
CMSG_SIGNER_ENCODE_INFO signer = { sizeof(signer), 0 };
CERT_INFO certInfo = { 0 };
static char oid_rsa_md5[] = szOID_RSA_MD5;
SetLastError(0xdeadbeef);
msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, 0, CMSG_SIGNED, &signInfo,
@ -1095,7 +1092,6 @@ static void test_signed_msg_update(void)
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;
@ -1176,10 +1172,168 @@ static void test_signed_msg_update(void)
CRYPT_DELETEKEYSET);
}
static const BYTE signedEmptyBareContent[] = {
0x30,0x50,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,
0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x02,0x06,0x00,0x31,0x37,0x30,0x35,0x02,
0x01,0x01,0x30,0x1a,0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,
0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,
0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,
0x04,0x06,0x00,0x05,0x00,0x04,0x00 };
static const BYTE signedEmptyContent[] = {
0x30,0x5f,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,0xa0,0x52,
0x30,0x50,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,
0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x02,0x06,0x00,0x31,0x37,0x30,0x35,0x02,
0x01,0x01,0x30,0x1a,0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,
0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,
0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,
0x04,0x06,0x00,0x05,0x00,0x04,0x00 };
static const BYTE detachedSignedBareContent[] = {
0x30,0x81,0x99,0x02,0x01,0x01,0x31,0x0e,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,0x31,0x77,0x30,0x75,0x02,0x01,0x01,0x30,0x1a,0x30,
0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,
0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,0x30,0x0c,0x06,0x08,0x2a,
0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x04,0x06,0x00,0x05,0x00,
0x04,0x40,0x81,0xa6,0x70,0xb3,0xef,0x59,0xd1,0x66,0xd1,0x9b,0xc0,0x9a,0xb6,
0x9a,0x5e,0x6d,0x6f,0x6d,0x0d,0x59,0xa9,0xaa,0x6e,0xe9,0x2c,0xa0,0x1e,0xee,
0xc2,0x60,0xbc,0x59,0xbe,0x3f,0x63,0x06,0x8d,0xc9,0x11,0x1d,0x23,0x64,0x92,
0xef,0x2e,0xfc,0x57,0x29,0xa4,0xaf,0xe0,0xee,0x93,0x19,0x39,0x51,0xe4,0x44,
0xb8,0x0b,0x28,0xf4,0xa8,0x0d };
static const BYTE detachedSignedContent[] = {
0x30,0x81,0xaa,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,0xa0,
0x81,0x9c,0x30,0x81,0x99,0x02,0x01,0x01,0x31,0x0e,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,0x31,0x77,0x30,0x75,0x02,0x01,0x01,0x30,
0x1a,0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,
0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,0x30,0x0c,0x06,
0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x04,0x06,0x00,
0x05,0x00,0x04,0x40,0x81,0xa6,0x70,0xb3,0xef,0x59,0xd1,0x66,0xd1,0x9b,0xc0,
0x9a,0xb6,0x9a,0x5e,0x6d,0x6f,0x6d,0x0d,0x59,0xa9,0xaa,0x6e,0xe9,0x2c,0xa0,
0x1e,0xee,0xc2,0x60,0xbc,0x59,0xbe,0x3f,0x63,0x06,0x8d,0xc9,0x11,0x1d,0x23,
0x64,0x92,0xef,0x2e,0xfc,0x57,0x29,0xa4,0xaf,0xe0,0xee,0x93,0x19,0x39,0x51,
0xe4,0x44,0xb8,0x0b,0x28,0xf4,0xa8,0x0d };
static const BYTE signedBareContent[] = {
0x30,0x81,0xa1,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,
0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x13,0x06,0x09,0x2a,0x86,0x48,0x86,
0xf7,0x0d,0x01,0x07,0x01,0xa0,0x06,0x04,0x04,0x01,0x02,0x03,0x04,0x31,0x77,
0x30,0x75,0x02,0x01,0x01,0x30,0x1a,0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,
0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,
0x02,0x01,0x01,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,
0x05,0x00,0x30,0x04,0x06,0x00,0x05,0x00,0x04,0x40,0x81,0xa6,0x70,0xb3,0xef,
0x59,0xd1,0x66,0xd1,0x9b,0xc0,0x9a,0xb6,0x9a,0x5e,0x6d,0x6f,0x6d,0x0d,0x59,
0xa9,0xaa,0x6e,0xe9,0x2c,0xa0,0x1e,0xee,0xc2,0x60,0xbc,0x59,0xbe,0x3f,0x63,
0x06,0x8d,0xc9,0x11,0x1d,0x23,0x64,0x92,0xef,0x2e,0xfc,0x57,0x29,0xa4,0xaf,
0xe0,0xee,0x93,0x19,0x39,0x51,0xe4,0x44,0xb8,0x0b,0x28,0xf4,0xa8,0x0d };
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,
0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x13,0x06,0x09,0x2a,0x86,
0x48,0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x06,0x04,0x04,0x01,0x02,0x03,0x04,
0x31,0x77,0x30,0x75,0x02,0x01,0x01,0x30,0x1a,0x30,0x15,0x31,0x13,0x30,0x11,
0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
0x67,0x00,0x02,0x01,0x01,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,
0x02,0x05,0x05,0x00,0x30,0x04,0x06,0x00,0x05,0x00,0x04,0x40,0x81,0xa6,0x70,
0xb3,0xef,0x59,0xd1,0x66,0xd1,0x9b,0xc0,0x9a,0xb6,0x9a,0x5e,0x6d,0x6f,0x6d,
0x0d,0x59,0xa9,0xaa,0x6e,0xe9,0x2c,0xa0,0x1e,0xee,0xc2,0x60,0xbc,0x59,0xbe,
0x3f,0x63,0x06,0x8d,0xc9,0x11,0x1d,0x23,0x64,0x92,0xef,0x2e,0xfc,0x57,0x29,
0xa4,0xaf,0xe0,0xee,0x93,0x19,0x39,0x51,0xe4,0x44,0xb8,0x0b,0x28,0xf4,0xa8,
0x0d };
static const BYTE signedHash[] = {
0x08,0xd6,0xc0,0x5a,0x21,0x51,0x2a,0x79,0xa1,0xdf,0xeb,0x9d,0x2a,0x8f,0x26,
0x2f };
static void test_signed_msg_encoding(void)
{
HCRYPTMSG msg;
CMSG_SIGNED_ENCODE_INFO signInfo = { sizeof(signInfo), 0 };
CMSG_SIGNER_ENCODE_INFO signer = { sizeof(signer), 0 };
CERT_INFO certInfo = { 0 };
BOOL ret;
HCRYPTKEY key;
DWORD size;
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());
ret = CryptImportKey(signer.hCryptProv, (LPBYTE)privKey, sizeof(privKey),
0, 0, &key);
ok(ret, "CryptImportKey failed: %08x\n", GetLastError());
msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING,
CMSG_DETACHED_FLAG, CMSG_SIGNED, &signInfo, NULL, NULL);
ok(msg != NULL, "CryptMsgOpenToEncode failed: %x\n", GetLastError());
todo_wine
check_param("detached signed empty bare content", msg,
CMSG_BARE_CONTENT_PARAM, signedEmptyBareContent,
sizeof(signedEmptyBareContent));
todo_wine
check_param("detached signed empty content", msg, CMSG_CONTENT_PARAM,
signedEmptyContent, sizeof(signedEmptyContent));
ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE);
todo_wine
ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
todo_wine
check_param("detached signed hash", msg, CMSG_COMPUTED_HASH_PARAM,
signedHash, sizeof(signedHash));
todo_wine
check_param("detached signed bare content", msg, CMSG_BARE_CONTENT_PARAM,
detachedSignedBareContent, sizeof(detachedSignedBareContent));
todo_wine
check_param("detached signed content", msg, CMSG_CONTENT_PARAM,
detachedSignedContent, sizeof(detachedSignedContent));
SetLastError(0xdeadbeef);
ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 1, NULL, &size);
todo_wine
ok(!ret && GetLastError() == CRYPT_E_INVALID_INDEX,
"Expected CRYPT_E_INVALID_INDEX, got %x\n", GetLastError());
CryptMsgClose(msg);
msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, 0, CMSG_SIGNED, &signInfo,
NULL, NULL);
ok(msg != NULL, "CryptMsgOpenToEncode failed: %x\n", GetLastError());
todo_wine
check_param("signed empty bare content", msg, CMSG_BARE_CONTENT_PARAM,
signedEmptyBareContent, sizeof(signedEmptyBareContent));
todo_wine
check_param("signed empty content", msg, CMSG_CONTENT_PARAM,
signedEmptyContent, sizeof(signedEmptyContent));
ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE);
todo_wine
ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
todo_wine
check_param("signed bare content", msg, CMSG_BARE_CONTENT_PARAM,
signedBareContent, sizeof(signedBareContent));
todo_wine
check_param("signed content", msg, CMSG_CONTENT_PARAM,
signedContent, sizeof(signedContent));
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();
test_signed_msg_encoding();
}
static CRYPT_DATA_BLOB b4 = { 0, NULL };