From: Christoph von Wittich Date: Sun, 15 Nov 2009 23:25:01 +0000 (+0000) Subject: sync rsaenh winetest with wine 1.1.33 X-Git-Tag: ReactOS-0.3.11~44 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=25f74e7771159b259280d7de6e117a01a3f3a8a6 sync rsaenh winetest with wine 1.1.33 svn path=/trunk/; revision=44187 --- diff --git a/rostests/winetests/rsaenh/rsaenh.c b/rostests/winetests/rsaenh/rsaenh.c index bfe2b5a6a54..e59ad95a8c2 100644 --- a/rostests/winetests/rsaenh/rsaenh.c +++ b/rostests/winetests/rsaenh/rsaenh.c @@ -176,7 +176,7 @@ static int init_aes_environment(void) result = CryptAcquireContext(&hProv, szContainer, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT); if (!result && GetLastError() == NTE_PROV_TYPE_NOT_DEF) { - win_skip("RSA_ASE provider not supported\n"); + win_skip("RSA_AES provider not supported\n"); return 0; } ok(!result && GetLastError()==NTE_BAD_FLAGS, "%d, %08x\n", result, GetLastError()); @@ -459,7 +459,7 @@ static void test_block_cipher_modes(void) result = derive_key(CALG_RC2, &hKey, 40); if (!result) return; - memcpy(abData, plain, sizeof(abData)); + memcpy(abData, plain, sizeof(plain)); dwMode = CRYPT_MODE_ECB; result = CryptSetKeyParam(hKey, KP_MODE, (BYTE*)&dwMode, 0); @@ -1632,10 +1632,10 @@ static void test_rsa_encrypt(void) static void test_import_export(void) { DWORD dwLen, dwDataLen, dwVal; - HCRYPTKEY hPublicKey; + HCRYPTKEY hPublicKey, hPrivKey; BOOL result; ALG_ID algID; - BYTE emptyKey[2048]; + BYTE emptyKey[2048], *exported_key; static BYTE abPlainPublicKey[84] = { 0x06, 0x02, 0x00, 0x00, 0x00, 0xa4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x31, 0x00, 0x02, 0x00, 0x00, @@ -1649,6 +1649,160 @@ static void test_import_export(void) 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 }; + static BYTE priv_key_with_high_bit[] = { + 0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, + 0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00, + 0x01, 0x00, 0x01, 0x00, 0xd5, 0xa2, 0x0d, 0x66, + 0xfe, 0x65, 0xb5, 0xf1, 0xc9, 0x6b, 0xf5, 0x58, + 0x04, 0x38, 0x2d, 0xf4, 0xa3, 0x5a, 0xda, 0x9e, + 0x95, 0x81, 0x85, 0x3d, 0x01, 0x07, 0xb2, 0x03, + 0x77, 0x70, 0x79, 0x6e, 0x6c, 0x26, 0x42, 0xa4, + 0x12, 0xfd, 0xaa, 0x29, 0x83, 0x04, 0xce, 0x91, + 0x90, 0x39, 0x5e, 0x49, 0x56, 0xfd, 0x0a, 0xe5, + 0xb1, 0xea, 0x3b, 0xb2, 0x70, 0xb0, 0x20, 0xc1, + 0x1f, 0x22, 0x07, 0x3e, 0x4d, 0xc0, 0x73, 0xfd, + 0x92, 0x8f, 0x87, 0xd8, 0xd1, 0xd1, 0x28, 0xd8, + 0x19, 0xd1, 0x93, 0x83, 0xe0, 0xb8, 0x9f, 0x53, + 0xf4, 0x6a, 0x7c, 0xcb, 0x10, 0x53, 0xd0, 0x37, + 0x02, 0xb4, 0xa5, 0xf7, 0xa2, 0x28, 0x6e, 0x26, + 0xef, 0x5c, 0x14, 0x01, 0x40, 0x1e, 0xa3, 0xe1, + 0xda, 0x76, 0xd0, 0x12, 0x84, 0xb7, 0x48, 0x7d, + 0xc8, 0x67, 0x5c, 0xb2, 0xd5, 0x2e, 0xaf, 0x8e, + 0x7d, 0x32, 0x59, 0x92, 0x01, 0xd6, 0x5b, 0x68, + 0x28, 0x9b, 0xb1, 0x6c, 0x69, 0xeb, 0x61, 0x5b, + 0x4b, 0x13, 0xe2, 0xbd, 0x7d, 0xbe, 0xce, 0xe8, + 0x41, 0x54, 0xca, 0xa8, 0xdd, 0xc7, 0xfe, 0x8b, + 0xdf, 0xf6, 0x55, 0x6c, 0x50, 0x11, 0xc8, 0x15, + 0x13, 0x42, 0x59, 0x9f, 0xbb, 0xea, 0x73, 0x78, + 0x7b, 0x22, 0x8d, 0x96, 0x62, 0xe5, 0xda, 0xa2, + 0x85, 0x5c, 0x20, 0x74, 0x9f, 0x1c, 0x12, 0xf2, + 0x48, 0x06, 0x1a, 0xc6, 0xd5, 0x94, 0xec, 0x31, + 0x6b, 0xb6, 0x7b, 0x54, 0x61, 0x77, 0xec, 0x7c, + 0x6f, 0xb7, 0x55, 0x3d, 0x6b, 0x98, 0x05, 0xd7, + 0x8a, 0x73, 0x25, 0xf2, 0x8f, 0xe4, 0xb8, 0x8d, + 0x27, 0x18, 0x0d, 0x05, 0xba, 0x23, 0x54, 0x37, + 0x10, 0xf0, 0x1c, 0x41, 0xa6, 0xae, 0x4c, 0x2a, + 0x6a, 0x2f, 0x7f, 0x68, 0x43, 0x86, 0xe7, 0x9c, + 0xfd, 0x9e, 0xf1, 0xfe, 0x84, 0xe3, 0xb6, 0x99, + 0x51, 0xfe, 0x1e, 0xbd, 0x01, 0xc6, 0x10, 0xef, + 0x88, 0xa4, 0xd8, 0x53, 0x14, 0x88, 0x15, 0xc9, + 0xe5, 0x86, 0xe2, 0x8d, 0x85, 0x2e, 0x0d, 0xec, + 0x15, 0xa7, 0x48, 0xfa, 0x18, 0xfb, 0x01, 0x8d, + 0x2b, 0x90, 0x70, 0x7f, 0x78, 0xb1, 0x33, 0x7e, + 0xfe, 0x82, 0x40, 0x5f, 0x4a, 0x97, 0xc2, 0x42, + 0x22, 0xd5, 0x5f, 0xbc, 0xbd, 0xab, 0x26, 0x98, + 0xcd, 0xb5, 0xdf, 0x7e, 0xa0, 0x68, 0xa7, 0x12, + 0x9e, 0xa5, 0xa2, 0x90, 0x85, 0xc5, 0xca, 0x73, + 0x4a, 0x59, 0x8a, 0xec, 0xcf, 0xdd, 0x65, 0x5d, + 0xc1, 0xaa, 0x86, 0x53, 0xd5, 0xde, 0xbb, 0x23, + 0x24, 0xb8, 0x9b, 0x74, 0x03, 0x20, 0xb4, 0xf0, + 0xe4, 0xdd, 0xd2, 0x03, 0xfd, 0x67, 0x55, 0x19, + 0x28, 0x1d, 0xc1, 0xb8, 0xa5, 0x89, 0x0e, 0xc0, + 0x80, 0x9d, 0xdd, 0xda, 0x9d, 0x30, 0x5c, 0xc8, + 0xbb, 0xfe, 0x8f, 0xce, 0xd5, 0xf6, 0xdf, 0xfa, + 0x14, 0xaf, 0xe4, 0xba, 0xb0, 0x84, 0x45, 0xd8, + 0x67, 0xa7, 0xd0, 0xce, 0x89, 0x2a, 0x30, 0x8c, + 0xfa, 0xe9, 0x65, 0xa4, 0x21, 0x2d, 0x6b, 0xa2, + 0x9b, 0x8f, 0x92, 0xbd, 0x3a, 0x10, 0x71, 0x12, + 0xc2, 0x02, 0x3d, 0xd5, 0x83, 0x1d, 0xfa, 0x42, + 0xb7, 0x48, 0x1b, 0x31, 0xe3, 0x82, 0x90, 0x2d, + 0x91, 0x59, 0xf9, 0x38, 0x52, 0xe5, 0xdb, 0xc1, + 0x4d, 0x3a, 0xe6, 0x9b, 0x6a, 0xbb, 0xea, 0xa4, + 0x8d, 0x5e, 0xc4, 0x00, 0x01, 0xb8, 0xec, 0x91, + 0xc1, 0xdb, 0x63, 0xbd, 0x57, 0xb6, 0x26, 0x15, + 0xb6, 0x3e, 0xa2, 0xdf, 0x62, 0x8d, 0xa8, 0xbe, + 0xe1, 0xf1, 0x39, 0xbd, 0x18, 0xd2, 0x6f, 0xd7, + 0xda, 0xdc, 0x71, 0x30, 0xf1, 0x21, 0x71, 0xa4, + 0x08, 0x43, 0x46, 0xdf, 0x50, 0xbd, 0x3c, 0x60, + 0x5b, 0x63, 0x35, 0xe3, 0x37, 0x5b, 0x25, 0x17, + 0x54, 0x5e, 0x68, 0x60, 0xb6, 0x49, 0xef, 0x6e, + 0x09, 0xef, 0xda, 0x90, 0x3e, 0xd4, 0x09, 0x33, + 0x36, 0x57, 0x9a, 0x14, 0xbd, 0xf7, 0xb1, 0x98, + 0x30, 0x42, 0x03, 0x84, 0x61, 0xeb, 0x8e, 0x50, + 0xdc, 0x6a, 0x93, 0x1b, 0x32, 0x51, 0xf9, 0xc6, + 0xc2, 0x19, 0xb3, 0x5d, 0xe2, 0xf8, 0xc5, 0x8f, + 0x68, 0xaa, 0x1d, 0xdb, 0xd3, 0x7f, 0x8d, 0x98, + 0x9c, 0x16, 0x8c, 0xc3, 0xcd, 0xd9, 0xdb, 0x08, + 0xe6, 0x36, 0x60, 0xb6, 0x36, 0xdc, 0x1d, 0x59, + 0xb6, 0x5f, 0x01, 0x5e + }; + static const BYTE expected_exported_priv_key[] = { + 0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, + 0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00, + 0x01, 0x00, 0x01, 0x00, 0xd5, 0xa2, 0x0d, 0x66, + 0xfe, 0x65, 0xb5, 0xf1, 0xc9, 0x6b, 0xf5, 0x58, + 0x04, 0x38, 0x2d, 0xf4, 0xa3, 0x5a, 0xda, 0x9e, + 0x95, 0x81, 0x85, 0x3d, 0x01, 0x07, 0xb2, 0x03, + 0x77, 0x70, 0x79, 0x6e, 0x6c, 0x26, 0x42, 0xa4, + 0x12, 0xfd, 0xaa, 0x29, 0x83, 0x04, 0xce, 0x91, + 0x90, 0x39, 0x5e, 0x49, 0x56, 0xfd, 0x0a, 0xe5, + 0xb1, 0xea, 0x3b, 0xb2, 0x70, 0xb0, 0x20, 0xc1, + 0x1f, 0x22, 0x07, 0x3e, 0x4d, 0xc0, 0x73, 0xfd, + 0x92, 0x8f, 0x87, 0xd8, 0xd1, 0xd1, 0x28, 0xd8, + 0x19, 0xd1, 0x93, 0x83, 0xe0, 0xb8, 0x9f, 0x53, + 0xf4, 0x6a, 0x7c, 0xcb, 0x10, 0x53, 0xd0, 0x37, + 0x02, 0xb4, 0xa5, 0xf7, 0xa2, 0x28, 0x6e, 0x26, + 0xef, 0x5c, 0x14, 0x01, 0x40, 0x1e, 0xa3, 0xe1, + 0xda, 0x76, 0xd0, 0x12, 0x84, 0xb7, 0x48, 0x7d, + 0xc8, 0x67, 0x5c, 0xb2, 0xd5, 0x2e, 0xaf, 0x8e, + 0x7d, 0x32, 0x59, 0x92, 0x01, 0xd6, 0x5b, 0x68, + 0x28, 0x9b, 0xb1, 0x6c, 0x69, 0xeb, 0x61, 0x5b, + 0x4b, 0x13, 0xe2, 0xbd, 0x7d, 0xbe, 0xce, 0xe8, + 0x41, 0x54, 0xca, 0xa8, 0xdd, 0xc7, 0xfe, 0x8b, + 0xdf, 0xf6, 0x55, 0x6c, 0x50, 0x11, 0xc8, 0x15, + 0x13, 0x42, 0x59, 0x9f, 0xbb, 0xea, 0x73, 0x78, + 0x7b, 0x22, 0x8d, 0x96, 0x62, 0xe5, 0xda, 0xa2, + 0x85, 0x5c, 0x20, 0x74, 0x9f, 0x1c, 0x12, 0xf2, + 0x48, 0x06, 0x1a, 0xc6, 0xd5, 0x94, 0xec, 0x31, + 0x6b, 0xb6, 0x7b, 0x54, 0x61, 0x77, 0xec, 0x7c, + 0x6f, 0xb7, 0x55, 0x3d, 0x6b, 0x98, 0x05, 0xd7, + 0x8a, 0x73, 0x25, 0xf2, 0x8f, 0xe4, 0xb8, 0x8d, + 0x27, 0x18, 0x0d, 0x05, 0xba, 0x23, 0x54, 0x37, + 0x10, 0xf0, 0x1c, 0x41, 0xa6, 0xae, 0x4c, 0x2a, + 0x6a, 0x2f, 0x7f, 0x68, 0x43, 0x86, 0xe7, 0x9c, + 0xfd, 0x9e, 0xf1, 0xfe, 0x84, 0xe3, 0xb6, 0x99, + 0x51, 0xfe, 0x1e, 0xbd, 0x01, 0xc6, 0x10, 0xef, + 0x88, 0xa4, 0xd8, 0x53, 0x14, 0x88, 0x15, 0xc9, + 0xe5, 0x86, 0xe2, 0x8d, 0x85, 0x2e, 0x0d, 0xec, + 0x15, 0xa7, 0x48, 0xf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 0x15, + 0xb6, 0x3e, 0xa2, 0xdf, 0x62, 0x8d, 0xa8, 0xbe, + 0xe1, 0xf1, 0x39, 0xbd, 0x18, 0xd2, 0x6f, 0xd7, + 0xda, 0xdc, 0x71, 0x30, 0xf1, 0x21, 0x71, 0xa4, + 0x08, 0x43, 0x46, 0xdf, 0x50, 0xbd, 0x3c, 0x60, + 0x5b, 0x63, 0x35, 0xe3, 0x37, 0x5b, 0x25, 0x17, + 0x54, 0x5e, 0x68, 0x60, 0xb6, 0x49, 0xef, 0x6e, + 0x09, 0xef, 0xda, 0x90, 0x3e, 0xd4, 0x09, 0x33, + 0x36, 0x57, 0x9a, 0x14, 0xbd, 0xf7, 0xb1, 0x98, + 0x30, 0x42, 0x03, 0x84, 0x61, 0xeb, 0x8e, 0x50, + 0xdc, 0x6a, 0x93, 0x1b, 0x32, 0x51, 0xf9, 0xc6, + 0xc2, 0x19, 0xb3, 0x5d, 0xe2, 0xf8, 0xc5, 0x8f, + 0x68, 0xaa, 0x1d, 0xdb, 0xd3, 0x7f, 0x8d, 0x98, + 0x9c, 0x16, 0x8c, 0xc3, 0xcd, 0xd9, 0xdb, 0x08, + 0xe6, 0x36, 0x60, 0xb6, 0x36, 0xdc, 0x1d, 0x59, + 0xb6, 0x5f, 0x01, 0x5e + }; dwLen=84; result = CryptImportKey(hProv, abPlainPublicKey, dwLen, 0, 0, &hPublicKey); @@ -1674,6 +1828,26 @@ static void test_import_export(void) ok(!memcmp(emptyKey, abPlainPublicKey, dwLen), "exported key is different from the imported key\n"); CryptDestroyKey(hPublicKey); + + result = CryptImportKey(hProv, priv_key_with_high_bit, + sizeof(priv_key_with_high_bit), 0, CRYPT_EXPORTABLE, &hPrivKey); + ok(result, "CryptImportKey failed: %08x\n", GetLastError()); + + result = CryptExportKey(hPrivKey, 0, PRIVATEKEYBLOB, 0, NULL, &dwDataLen); + ok(result, "CryptExportKey failed: %08x\n", GetLastError()); + exported_key = HeapAlloc(GetProcessHeap(), 0, dwDataLen); + result = CryptExportKey(hPrivKey, 0, PRIVATEKEYBLOB, 0, exported_key, + &dwDataLen); + ok(result, "CryptExportKey failed: %08x\n", GetLastError()); + + ok(dwDataLen == sizeof(expected_exported_priv_key), "unexpected size %d\n", + dwDataLen); + ok(!memcmp(exported_key, expected_exported_priv_key, dwDataLen), + "unexpected value\n"); + + HeapFree(GetProcessHeap(), 0, exported_key); + + CryptDestroyKey(hPrivKey); } static void test_schannel_provider(void) @@ -1857,6 +2031,68 @@ static void test_schannel_provider(void) CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_SCHANNEL, CRYPT_DELETEKEYSET); } +/* Test that a key can be used to encrypt data and exported, and that, when + * the exported key is imported again, can be used to decrypt the original + * data again. + */ +static void test_rsa_round_trip(void) +{ + static const char test_string[] = "Well this is a fine how-do-you-do."; + HCRYPTPROV prov; + HCRYPTKEY signKey, keyExchangeKey; + BOOL result; + BYTE data[256], *exportedKey; + DWORD dataLen, keyLen; + + CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL, + CRYPT_DELETEKEYSET); + + /* Generate a new key... */ + result = CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL, + CRYPT_NEWKEYSET); + ok(result, "CryptAcquireContext failed: %08x\n", GetLastError()); + result = CryptGenKey(prov, CALG_RSA_KEYX, CRYPT_EXPORTABLE, &signKey); + ok(result, "CryptGenKey with CALG_RSA_KEYX failed with error %08x\n", GetLastError()); + result = CryptGetUserKey(prov, AT_KEYEXCHANGE, &keyExchangeKey); + ok(result, "CryptGetUserKey failed: %08x\n", GetLastError()); + /* encrypt some data with it... */ + memcpy(data, test_string, strlen(test_string) + 1); + dataLen = strlen(test_string) + 1; + result = CryptEncrypt(keyExchangeKey, 0, TRUE, 0, data, &dataLen, + sizeof(data)); + ok(result || broken(GetLastError() == NTE_BAD_KEY /* Win9x/2000 */), + "CryptEncrypt failed: %08x\n", GetLastError()); + /* export the key... */ + result = CryptExportKey(keyExchangeKey, 0, PRIVATEKEYBLOB, 0, NULL, + &keyLen); + ok(result, "CryptExportKey failed: %08x\n", GetLastError()); + exportedKey = HeapAlloc(GetProcessHeap(), 0, keyLen); + result = CryptExportKey(keyExchangeKey, 0, PRIVATEKEYBLOB, 0, exportedKey, + &keyLen); + /* destroy the key... */ + CryptDestroyKey(keyExchangeKey); + CryptDestroyKey(signKey); + /* import the key again... */ + result = CryptImportKey(prov, exportedKey, keyLen, 0, 0, &keyExchangeKey); + ok(result, "CryptImportKey failed: %08x\n", GetLastError()); + HeapFree(GetProcessHeap(), 0, exportedKey); + /* and decrypt the data encrypted with the original key with the imported + * key. + */ + result = CryptDecrypt(keyExchangeKey, 0, TRUE, 0, data, &dataLen); + ok(result || broken(GetLastError() == NTE_BAD_KEY /* Win9x/2000 */), + "CryptDecrypt failed: %08x\n", GetLastError()); + if (result) + { + ok(dataLen == sizeof(test_string), "unexpected size %d\n", dataLen); + ok(!memcmp(data, test_string, sizeof(test_string)), "unexpected value"); + } + CryptReleaseContext(prov, 0); + + CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL, + CRYPT_DELETEKEYSET); +} + static void test_enum_container(void) { BYTE abContainerName[MAX_PATH + 2]; /* Larger than maximum name len */ @@ -2071,7 +2307,7 @@ static void test_null_provider(void) ok(result, "CryptAcquireContext failed: %08x\n", GetLastError()); if (!result) return; result = CryptImportKey(prov, signBlob, sizeof(signBlob), 0, 0, &key); - ok(result, "CryptGenKey failed: %08x\n", GetLastError()); + ok(result, "CryptImportKey failed: %08x\n", GetLastError()); CryptDestroyKey(key); /* doesn't allow access to the key exchange key.. */ result = CryptGetUserKey(prov, AT_KEYEXCHANGE, &key); @@ -2319,6 +2555,7 @@ START_TEST(rsaenh) test_key_initialization(); test_schannel_provider(); test_null_provider(); + test_rsa_round_trip(); if (!init_aes_environment()) return; test_aes(128);