crypt32/tests: Add a test for CryptEncryptMessage.
This commit is contained in:
parent
bffe120f4b
commit
476552c5b5
|
@ -794,7 +794,7 @@ static const BYTE publicPrivateKeyPair[] = {
|
|||
0xb1,0x8c,0xea,0x33,0x54,0x08,0x38,0xc9,0xcd,0xac,0x10,0x19,0x4a,0xba,0x89,
|
||||
0xdc,0xb6,0x73,0xef,0xec,0x56,0x93,0xd6,0xf2,0x4b,0xba,0x50,0x2d,0x8f,0x15,
|
||||
0xed,0x8b,0xb5,0x67,0xc8,0xfc,0x51,0x5f };
|
||||
static const BYTE certForSigning[] = {
|
||||
static const BYTE cert1[] = {
|
||||
0x30,0x81,0xd0,0x30,0x81,0xbe,0xa0,0x03,0x02,0x01,0x02,0x02,0x10,0x20,0x42,
|
||||
0x68,0x69,0xe9,0xea,0x61,0x83,0x11,0xdf,0xc0,0x24,0x2f,0x3b,0xad,0x40,0x30,
|
||||
0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x30,0x0c,0x31,0x0a,0x30,
|
||||
|
@ -810,6 +810,26 @@ static const BYTE certForSigning[] = {
|
|||
0x1e,0x94,0x09,0x9e,0x50,0x09,0x5b,0xd9,0x60,0xd9,0x9b,0x02,0x03,0x01,0x00,
|
||||
0x01,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x03,0x02,0x00,
|
||||
0xc1 };
|
||||
static const BYTE cert2[] = {
|
||||
0x30,0x82,0x01,0x15,0x30,0x82,0x01,0x02,0xa0,0x03,0x02,0x01,0x02,0x02,0x10,
|
||||
0x1c,0xf2,0x1f,0xec,0x6b,0xdc,0x36,0xbf,0x4a,0xd7,0xe1,0x6c,0x84,0x85,0xcd,
|
||||
0x2e,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x30,0x0c,0x31,
|
||||
0x0a,0x30,0x08,0x06,0x03,0x55,0x04,0x03,0x13,0x01,0x58,0x30,0x20,0x17,0x0d,
|
||||
0x31,0x30,0x30,0x37,0x31,0x32,0x31,0x31,0x33,0x37,0x35,0x36,0x5a,0x18,0x0f,
|
||||
0x33,0x30,0x31,0x30,0x30,0x37,0x31,0x32,0x31,0x31,0x33,0x37,0x35,0x36,0x5a,
|
||||
0x30,0x0c,0x31,0x0a,0x30,0x08,0x06,0x03,0x55,0x04,0x03,0x13,0x01,0x58,0x30,
|
||||
0x81,0x9f,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,
|
||||
0x05,0x00,0x03,0x81,0x8d,0x00,0x30,0x81,0x89,0x02,0x81,0x81,0x00,0xab,0xed,
|
||||
0x6e,0xe0,0x00,0x3c,0xcf,0x2d,0x2b,0xda,0x05,0x88,0x6a,0x7e,0xed,0x60,0x30,
|
||||
0x24,0xef,0x6c,0x6b,0xad,0x28,0x9b,0x14,0x90,0xf6,0xd0,0x96,0x79,0x6d,0xad,
|
||||
0xac,0x46,0x14,0x7b,0x0e,0xfe,0xa9,0x8a,0x05,0x5a,0xc8,0x84,0x38,0x44,0xf9,
|
||||
0xce,0xb2,0xe6,0xde,0x5b,0x80,0x0b,0x15,0xff,0x1b,0x60,0x3f,0xba,0xb2,0xfe,
|
||||
0x6e,0xf5,0xdc,0x54,0x33,0xfc,0xfc,0x79,0x0a,0x10,0xa4,0x23,0x6d,0x67,0xeb,
|
||||
0x16,0xb2,0x92,0xbf,0x63,0x42,0x17,0x0a,0xde,0xe6,0xab,0x8e,0xf7,0x8e,0x41,
|
||||
0x8c,0x04,0xe8,0xe2,0x38,0x73,0xd3,0x82,0xd7,0xd1,0xee,0xd3,0xa6,0x54,0x8c,
|
||||
0xcd,0x0b,0x93,0xda,0x63,0x55,0x0d,0x1f,0x68,0x5c,0x30,0xee,0xad,0x2d,0xd5,
|
||||
0x40,0x56,0xe0,0xd8,0xc7,0xef,0x02,0x03,0x01,0x00,0x01,0x30,0x09,0x06,0x05,
|
||||
0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x03,0x02,0x00,0x06 };
|
||||
static const BYTE crl[] = {
|
||||
0x30,0x81,0xc2,0x30,0x7e,0x02,0x01,0x01,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,
|
||||
0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,0x3c,0x31,0x0b,0x30,0x09,0x06,
|
||||
|
@ -999,7 +1019,7 @@ static void test_sign_message(void)
|
|||
para.dwMsgEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
|
||||
SetLastError(0xdeadbeef);
|
||||
para.pSigningCert = CertCreateCertificateContext(X509_ASN_ENCODING |
|
||||
PKCS_7_ASN_ENCODING, certForSigning, sizeof(certForSigning));
|
||||
PKCS_7_ASN_ENCODING, cert1, sizeof(cert1));
|
||||
ok(para.pSigningCert != NULL, "CertCreateCertificateContext failed: %08x\n",
|
||||
GetLastError());
|
||||
para.HashAlgorithm.pszObjId = oid_rsa_md5;
|
||||
|
@ -1150,6 +1170,177 @@ static void test_sign_message(void)
|
|||
CryptReleaseContext(hCryptProv, 0);
|
||||
}
|
||||
|
||||
static const BYTE encryptedMessage[] = {
|
||||
0x30,0x31,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x03,0xa0,0x24,
|
||||
0x30,0x22,0x02,0x01,0x00,0x31,0x00,0x30,0x1b,0x06,0x09,0x2a,0x86,0x48,0x86,
|
||||
0xf7,0x0d,0x01,0x07,0x01,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,
|
||||
0x03,0x04,0x05,0x00,0x80,0x00 };
|
||||
|
||||
static void test_encrypt_message(void)
|
||||
{
|
||||
BOOL ret;
|
||||
CRYPT_ENCRYPT_MESSAGE_PARA para;
|
||||
static char oid_rsa_rc4[] = szOID_RSA_RC4;
|
||||
static const BYTE blob[] = { 0x01, 0x02, 0x03, 0x04 };
|
||||
PCCERT_CONTEXT certs[2];
|
||||
HCRYPTPROV hCryptProv = 0;
|
||||
LPBYTE encryptedBlob;
|
||||
DWORD encryptedBlobSize;
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = CryptAcquireContextA(&hCryptProv, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT);
|
||||
ok(ret, "CryptAcquireContextA failed: %08x\n", GetLastError());
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING |
|
||||
PKCS_7_ASN_ENCODING, cert1, sizeof(cert1));
|
||||
ok(certs[0] != NULL, "CertCreateCertificateContext failed: %08x\n",
|
||||
GetLastError());
|
||||
SetLastError(0xdeadbeef);
|
||||
certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING |
|
||||
PKCS_7_ASN_ENCODING, cert2, sizeof(cert2));
|
||||
ok(certs[1] != NULL, "CertCreateCertificateContext failed: %08x\n",
|
||||
GetLastError());
|
||||
|
||||
memset(¶, 0, sizeof(para));
|
||||
SetLastError(0xdeadbeef);
|
||||
encryptedBlobSize = 255;
|
||||
ret = CryptEncryptMessage(¶, 0, NULL, NULL, 0, NULL,
|
||||
&encryptedBlobSize);
|
||||
todo_wine
|
||||
ok(!ret && GetLastError() == E_INVALIDARG,
|
||||
"expected E_INVALIDARG, got %08x\n", GetLastError());
|
||||
todo_wine
|
||||
ok(!encryptedBlobSize, "unexpected size %d\n", encryptedBlobSize);
|
||||
para.cbSize = sizeof(para);
|
||||
para.dwMsgEncodingType = X509_ASN_ENCODING;
|
||||
SetLastError(0xdeadbeef);
|
||||
encryptedBlobSize = 255;
|
||||
ret = CryptEncryptMessage(¶, 0, NULL, NULL, 0, NULL,
|
||||
&encryptedBlobSize);
|
||||
todo_wine
|
||||
ok(!ret && GetLastError() == E_INVALIDARG,
|
||||
"expected E_INVALIDARG, got %08x\n", GetLastError());
|
||||
todo_wine
|
||||
ok(!encryptedBlobSize, "unexpected size %d\n", encryptedBlobSize);
|
||||
para.dwMsgEncodingType = PKCS_7_ASN_ENCODING;
|
||||
SetLastError(0xdeadbeef);
|
||||
encryptedBlobSize = 255;
|
||||
ret = CryptEncryptMessage(¶, 0, NULL, NULL, 0, NULL,
|
||||
&encryptedBlobSize);
|
||||
todo_wine
|
||||
ok(!ret &&
|
||||
(GetLastError() == CRYPT_E_UNKNOWN_ALGO ||
|
||||
GetLastError() == E_INVALIDARG), /* Win9x */
|
||||
"expected CRYPT_E_UNKNOWN_ALGO or E_INVALIDARG, got %08x\n",
|
||||
GetLastError());
|
||||
todo_wine
|
||||
ok(!encryptedBlobSize, "unexpected size %d\n", encryptedBlobSize);
|
||||
|
||||
para.hCryptProv = hCryptProv;
|
||||
para.ContentEncryptionAlgorithm.pszObjId = oid_rsa_rc4;
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
encryptedBlobSize = 0;
|
||||
ret = CryptEncryptMessage(¶, 0, NULL, NULL, 0, NULL,
|
||||
&encryptedBlobSize);
|
||||
todo_wine
|
||||
ok(ret ||
|
||||
broken(!ret) /* Win9x */,
|
||||
"CryptEncryptMessage failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
encryptedBlob = CryptMemAlloc(encryptedBlobSize);
|
||||
if (encryptedBlob)
|
||||
{
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = CryptEncryptMessage(¶, 0, NULL, NULL, 0, encryptedBlob,
|
||||
&encryptedBlobSize);
|
||||
todo_wine
|
||||
ok(ret, "CryptEncryptMessage failed: %08x\n", GetLastError());
|
||||
todo_wine
|
||||
ok(encryptedBlobSize == sizeof(encryptedMessage),
|
||||
"unexpected size of encrypted blob %d\n", encryptedBlobSize);
|
||||
ok(!memcmp(encryptedBlob, encryptedMessage, encryptedBlobSize),
|
||||
"unexpected value\n");
|
||||
CryptMemFree(encryptedBlob);
|
||||
}
|
||||
}
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
encryptedBlobSize = 0;
|
||||
ret = CryptEncryptMessage(¶, 2, certs, NULL, 0, NULL,
|
||||
&encryptedBlobSize);
|
||||
todo_wine
|
||||
ok(ret, "CryptEncryptMessage failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
encryptedBlob = CryptMemAlloc(encryptedBlobSize);
|
||||
if (encryptedBlob)
|
||||
{
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = CryptEncryptMessage(¶, 2, certs, NULL, 0, encryptedBlob,
|
||||
&encryptedBlobSize);
|
||||
todo_wine
|
||||
ok(ret, "CryptEncryptMessage failed: %08x\n", GetLastError());
|
||||
CryptMemFree(encryptedBlob);
|
||||
}
|
||||
}
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
encryptedBlobSize = 0;
|
||||
ret = CryptEncryptMessage(¶, 0, NULL, blob, sizeof(blob), NULL,
|
||||
&encryptedBlobSize);
|
||||
todo_wine
|
||||
ok(ret ||
|
||||
broken(!ret) /* Win9x */,
|
||||
"CryptEncryptMessage failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
encryptedBlob = CryptMemAlloc(encryptedBlobSize);
|
||||
if (encryptedBlob)
|
||||
{
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = CryptEncryptMessage(¶, 0, NULL, blob, sizeof(blob),
|
||||
encryptedBlob, &encryptedBlobSize);
|
||||
todo_wine
|
||||
ok(ret, "CryptEncryptMessage failed: %08x\n", GetLastError());
|
||||
todo_wine
|
||||
ok(encryptedBlobSize == 55,
|
||||
"unexpected size of encrypted blob %d\n", encryptedBlobSize);
|
||||
CryptMemFree(encryptedBlob);
|
||||
}
|
||||
}
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
encryptedBlobSize = 0;
|
||||
ret = CryptEncryptMessage(¶, 2, certs, blob, sizeof(blob), NULL,
|
||||
&encryptedBlobSize);
|
||||
todo_wine
|
||||
ok(ret, "CryptEncryptMessage failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
encryptedBlob = CryptMemAlloc(encryptedBlobSize);
|
||||
if (encryptedBlob)
|
||||
{
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = CryptEncryptMessage(¶, 2, certs, blob, sizeof(blob),
|
||||
encryptedBlob, &encryptedBlobSize);
|
||||
todo_wine
|
||||
ok(ret, "CryptEncryptMessage failed: %08x\n", GetLastError());
|
||||
CryptMemFree(encryptedBlob);
|
||||
}
|
||||
}
|
||||
|
||||
if (certs[0])
|
||||
CertFreeCertificateContext(certs[0]);
|
||||
if (certs[1])
|
||||
CertFreeCertificateContext(certs[1]);
|
||||
if (hCryptProv)
|
||||
CryptReleaseContext(hCryptProv, 0);
|
||||
}
|
||||
|
||||
START_TEST(message)
|
||||
{
|
||||
test_msg_get_signer_count();
|
||||
|
@ -1159,4 +1350,5 @@ START_TEST(message)
|
|||
test_verify_message_signature();
|
||||
test_hash_message();
|
||||
test_sign_message();
|
||||
test_encrypt_message();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue