[CRYPT32_WINETEST] Sync with Wine Staging 4.0. CORE-15682

This commit is contained in:
Amine Khaldi 2019-01-25 13:19:36 +01:00
parent b1b70ef9ed
commit b807af385e
5 changed files with 208 additions and 13 deletions

View file

@ -3196,9 +3196,12 @@ static void testComparePublicKeyInfo(void)
static BYTE bits1[] = { 1, 0 };
static BYTE bits2[] = { 0 };
static BYTE bits3[] = { 1 };
static BYTE bits4[] = { 0x30,8, 2,1,0x81, 2,3,1,0,1 };
static BYTE bits5[] = { 0x30,9, 2,2,0,0x81, 2,3,1,0,1 };
static BYTE bits6[] = { 0x30,9, 2,2,0,0x82, 2,3,1,0,1 };
static BYTE bits4[] = { 0x30,8, 2,1,0x81, 2,3,1,0,1 }; /* ASN_SEQUENCE */
static BYTE bits5[] = { 0x30,9, 2,2,0,0x81, 2,3,1,0,1 }; /* ASN_SEQUENCE */
static BYTE bits6[] = { 0x30,9, 2,2,0,0x82, 2,3,1,0,1 }; /* ASN_SEQUENCE */
static BYTE bits7[] = { 0x04,8, 2,1,0x81, 2,3,1,0,1 }; /* ASN_OCTETSTRING */
static BYTE bits8[] = { 0x04,9, 2,2,0,0x81, 2,3,1,0,1 }; /* ASN_OCTETSTRING */
static BYTE bits9[] = { 0x04,9, 2,2,0,0x82, 2,3,1,0,1 }; /* ASN_OCTETSTRING */
/* crashes
ret = CertComparePublicKeyInfo(0, NULL, NULL);
@ -3206,14 +3209,23 @@ static void testComparePublicKeyInfo(void)
/* Empty public keys compare */
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
/* Different OIDs appear to compare */
info1.Algorithm.pszObjId = oid_rsa_rsa;
info2.Algorithm.pszObjId = oid_rsa_sha1rsa;
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
info2.Algorithm.pszObjId = oid_x957_dsa;
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
info1.PublicKey.cbData = sizeof(bits1);
info1.PublicKey.pbData = bits1;
info1.PublicKey.cUnusedBits = 0;
@ -3222,6 +3234,9 @@ static void testComparePublicKeyInfo(void)
info2.PublicKey.cUnusedBits = 0;
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
info2.Algorithm.pszObjId = oid_rsa_rsa;
info1.PublicKey.cbData = sizeof(bits4);
info1.PublicKey.pbData = bits4;
@ -3232,15 +3247,12 @@ static void testComparePublicKeyInfo(void)
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(!ret, "CertComparePublicKeyInfo: as raw binary: keys should be unequal\n");
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(ret ||
broken(!ret), /* win9x */
"CertComparePublicKeyInfo: as ASN.1 encoded: keys should be equal\n");
ok(ret, "CertComparePublicKeyInfo: as ASN.1 encoded: keys should be equal\n");
info1.PublicKey.cUnusedBits = 1;
info2.PublicKey.cUnusedBits = 5;
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(ret ||
broken(!ret), /* win9x */
"CertComparePublicKeyInfo: ASN.1 encoding should ignore cUnusedBits\n");
ok(ret, "CertComparePublicKeyInfo: ASN.1 encoding should ignore cUnusedBits\n");
info1.PublicKey.cUnusedBits = 0;
info2.PublicKey.cUnusedBits = 0;
info1.PublicKey.cbData--; /* kill one byte, make ASN.1 encoded data invalid */
@ -3256,11 +3268,36 @@ static void testComparePublicKeyInfo(void)
ret = CertComparePublicKeyInfo(0, &info1, &info2);
/* Simple (non-comparing) case */
ok(!ret, "Expected keys not to compare\n");
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(!ret, "Expected keys not to compare\n");
info2.PublicKey.cbData = sizeof(bits1);
info2.PublicKey.pbData = bits1;
info2.PublicKey.cUnusedBits = 0;
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(!ret, "Expected keys not to compare\n");
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(!ret, "Expected keys not to compare\n");
info1.PublicKey.cbData = sizeof(bits7);
info1.PublicKey.pbData = bits7;
info1.PublicKey.cUnusedBits = 0;
info2.PublicKey.cbData = sizeof(bits8);
info2.PublicKey.pbData = bits8;
info2.PublicKey.cUnusedBits = 0;
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(!ret, "CertComparePublicKeyInfo: as raw binary: keys should be unequal\n");
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(!ret, "CertComparePublicKeyInfo: as ASN.1 encoded: keys should be unequal\n");
ret = CertComparePublicKeyInfo(0, &info1, &info1);
ok(ret, "CertComparePublicKeyInfo: as raw binary: keys should be equal\n");
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info1);
ok(ret, "CertComparePublicKeyInfo: as ASN.1 encoded: keys should be equal\n");
info1.PublicKey.cbData--; /* kill one byte, make ASN.1 encoded data invalid */
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info1);
ok(ret, "CertComparePublicKeyInfo: as ASN.1 encoded: keys should be equal\n");
/* ASN.1 encoded non-comparing case */
info1.PublicKey.cbData = sizeof(bits5);
info1.PublicKey.pbData = bits5;
@ -3270,6 +3307,16 @@ static void testComparePublicKeyInfo(void)
info2.PublicKey.cUnusedBits = 0;
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(!ret, "CertComparePublicKeyInfo: different keys should be unequal\n");
/* ASN.1 encoded non-comparing case */
info1.PublicKey.cbData = sizeof(bits8);
info1.PublicKey.pbData = bits8;
info1.PublicKey.cUnusedBits = 0;
info2.PublicKey.cbData = sizeof(bits9);
info2.PublicKey.pbData = bits9;
info2.PublicKey.cUnusedBits = 0;
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(!ret, "CertComparePublicKeyInfo: different keys should be unequal\n");
}
static void testHashPublicKeyInfo(void)

View file

@ -1017,7 +1017,7 @@ static void compareNameValues(const CERT_NAME_VALUE *expected,
static void compareRDNAttrs(const CERT_RDN_ATTR *expected,
const CERT_RDN_ATTR *got)
{
if (expected->pszObjId && strlen(expected->pszObjId))
if (expected->pszObjId && *expected->pszObjId)
{
ok(got->pszObjId != NULL, "Expected OID %s, got NULL\n",
expected->pszObjId);
@ -8435,7 +8435,7 @@ static void testImportPublicKey(HCRYPTPROV csp, PCERT_PUBLIC_KEY_INFO info)
ok(ret, "CryptImportPublicKeyInfoEx failed: %08x\n", GetLastError());
dwSize = sizeof(ai);
CryptGetKeyParam(key, KP_ALGID, (LPVOID)&ai, &dwSize, 0);
ret = CryptGetKeyParam(key, KP_ALGID, (LPVOID)&ai, &dwSize, 0);
ok(ret, "CryptGetKeyParam failed: %08x\n", GetLastError());
if(ret)
{
@ -8451,7 +8451,7 @@ static void testImportPublicKey(HCRYPTPROV csp, PCERT_PUBLIC_KEY_INFO info)
ok(ret, "CryptImportPublicKeyInfoEx failed: %08x\n", GetLastError());
dwSize = sizeof(ai);
CryptGetKeyParam(key, KP_ALGID, (LPVOID)&ai, &dwSize, 0);
ret = CryptGetKeyParam(key, KP_ALGID, (LPVOID)&ai, &dwSize, 0);
ok(ret, "CryptGetKeyParam failed: %08x\n", GetLastError());
if(ret)
{

View file

@ -305,8 +305,32 @@ static void test_readTrustedPublisherDWORD(void)
static void test_getDefaultCryptProv(void)
{
#define ALG(id) id, #id
static const struct
{
ALG_ID algid;
const char *name;
BOOL optional;
} test_prov[] =
{
{ ALG(CALG_MD2), TRUE },
{ ALG(CALG_MD4), TRUE },
{ ALG(CALG_MD5), TRUE },
{ ALG(CALG_SHA), TRUE },
{ ALG(CALG_RSA_SIGN) },
{ ALG(CALG_DSS_SIGN) },
{ ALG(CALG_NO_SIGN) },
{ ALG(CALG_ECDSA), TRUE },
{ ALG(CALG_ECDH), TRUE },
{ ALG(CALG_RSA_KEYX) },
{ ALG(CALG_RSA_KEYX) },
};
#undef ALG
HCRYPTPROV (WINAPI *pI_CryptGetDefaultCryptProv)(DWORD w);
HCRYPTPROV prov;
BOOL ret;
DWORD size, i;
LPSTR name;
pI_CryptGetDefaultCryptProv = (void *)GetProcAddress(hCrypt, "I_CryptGetDefaultCryptProv");
if (!pI_CryptGetDefaultCryptProv) return;
@ -323,6 +347,34 @@ static void test_getDefaultCryptProv(void)
prov = pI_CryptGetDefaultCryptProv(0);
ok(prov != 0, "I_CryptGetDefaultCryptProv failed: %08x\n", GetLastError());
CryptReleaseContext(prov, 0);
for (i = 0; i < ARRAY_SIZE(test_prov); i++)
{
if (winetest_debug > 1)
trace("%u: algid %#x (%s): class %u, type %u, sid %u\n", i, test_prov[i].algid, test_prov[i].name,
GET_ALG_CLASS(test_prov[i].algid) >> 13, GET_ALG_TYPE(test_prov[i].algid) >> 9, GET_ALG_SID(test_prov[i].algid));
prov = pI_CryptGetDefaultCryptProv(test_prov[i].algid);
if (!prov)
{
todo_wine_if(test_prov[i].algid == CALG_DSS_SIGN || test_prov[i].algid == CALG_NO_SIGN)
ok(test_prov[i].optional, "%u: I_CryptGetDefaultCryptProv(%#x) failed\n", i, test_prov[i].algid);
continue;
}
ret = CryptGetProvParam(prov, PP_NAME, NULL, &size, 0);
if (ret) /* some provders don't support PP_NAME */
{
name = CryptMemAlloc(size);
ret = CryptGetProvParam(prov, PP_NAME, (BYTE *)name, &size, 0);
ok(ret, "%u: CryptGetProvParam failed %#x\n", i, GetLastError());
if (winetest_debug > 1)
trace("%u: algid %#x, name %s\n", i, test_prov[i].algid, name);
CryptMemFree(name);
}
CryptReleaseContext(prov, 0);
}
}
static void test_CryptInstallOssGlobal(void)

View file

@ -2,6 +2,7 @@
* Unit test suite for crypt32.dll's OID support functions.
*
* Copyright 2005 Juan Lang
* Copyright 2018 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -614,6 +615,97 @@ static void test_findOIDInfo(void)
win_skip("Host does not support ECDSA_SHA256, skipping test\n");
}
static void test_registerOIDInfo(void)
{
static const WCHAR winetestW[] = { 'w','i','n','e','t','e','s','t',0 };
static char test_oid[] = "1.2.3.4.5.6.7.8.9.10";
CRYPT_OID_INFO info1;
const CRYPT_OID_INFO *info2;
HKEY key;
DWORD ret, size, type, value;
char buf[256];
SetLastError(0xdeadbeef);
ret = CryptUnregisterOIDInfo(NULL);
ok(!ret, "should fail\n");
ok(GetLastError() == E_INVALIDARG, "got %#x\n", GetLastError());
memset(&info1, 0, sizeof(info1));
SetLastError(0xdeadbeef);
ret = CryptUnregisterOIDInfo(&info1);
ok(!ret, "should fail\n");
ok(GetLastError() == E_INVALIDARG, "got %#x\n", GetLastError());
info1.cbSize = sizeof(info1);
SetLastError(0xdeadbeef);
ret = CryptUnregisterOIDInfo(&info1);
ok(!ret, "should fail\n");
ok(GetLastError() == E_INVALIDARG, "got %#x\n", GetLastError());
info1.pszOID = test_oid;
SetLastError(0xdeadbeef);
ret = CryptUnregisterOIDInfo(&info1);
ok(!ret, "should fail\n");
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "got %u\n", GetLastError());
info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
ok(!info2, "should fail\n");
SetLastError(0xdeadbeef);
/* While it succeeds, the next call does not write anything to the
* registry on Windows because dwGroupId == 0.
*/
ret = CryptRegisterOIDInfo(&info1, 0);
ok(ret, "got %u\n", GetLastError());
ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
ok(ret == ERROR_FILE_NOT_FOUND, "got %u\n", ret);
info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
ok(!info2, "should fail\n");
info1.pwszName = winetestW;
info1.dwGroupId = CRYPT_HASH_ALG_OID_GROUP_ID;
SetLastError(0xdeadbeef);
ret = CryptRegisterOIDInfo(&info1, CRYPT_INSTALL_OID_INFO_BEFORE_FLAG);
if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
{
skip("Need admin rights\n");
return;
}
ok(ret, "got %u\n", GetLastError());
/* It looks like crypt32 reads the OID info from registry only on load,
* and CryptFindOIDInfo will find the registered OID on next run
*/
info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
ok(!info2, "should fail\n");
ret = RegCreateKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
ok(!ret, "got %u\n", ret);
memset(buf, 0, sizeof(buf));
size = sizeof(buf);
ret = RegQueryValueExA(key, "Name", NULL, &type, (BYTE *)buf, &size);
ok(!ret, "got %u\n", ret);
ok(type == REG_SZ, "got %u\n", type);
ok(!strcmp(buf, "winetest"), "got %s\n", buf);
value = 0xdeadbeef;
size = sizeof(value);
ret = RegQueryValueExA(key, "Flags", NULL, &type, (BYTE *)&value, &size);
ok(!ret, "got %u\n", ret);
ok(type == REG_DWORD, "got %u\n", type);
ok(value == 1, "got %u\n", value);
RegCloseKey(key);
CryptUnregisterOIDInfo(&info1);
ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
ok(ret == ERROR_FILE_NOT_FOUND, "got %u\n", ret);
}
START_TEST(oid)
{
HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
@ -623,6 +715,7 @@ START_TEST(oid)
testAlgIDToOID();
test_enumOIDInfo();
test_findOIDInfo();
test_registerOIDInfo();
test_oidFunctionSet();
test_installOIDFunctionAddress();
test_registerOIDFunction();

View file

@ -541,7 +541,7 @@ static void testStoresInCollection(void)
cert2 = CertCreateCertificateContext(X509_ASN_ENCODING, signedBigCert, sizeof(signedBigCert));
ok (cert2 != NULL, "Failed to create cert context %x\n", GetLastError());
ret = CertAddCertificateContextToStore(collection, cert2, CERT_STORE_ADD_REPLACE_EXISTING, NULL);
ok (ret, "Failed to add cert3 to the store %x\n",GetLastError());
ok (ret, "Failed to add cert2 to the store %x\n",GetLastError());
/** checking certificates in the stores */
tcert1 = CertEnumCertificatesInStore(ro_store, 0);
@ -2834,6 +2834,8 @@ static void testEmptyStore(void)
ok(res, "CertDeleteCertificateContextFromStore failed\n");
ok(cert3->hCertStore == cert->hCertStore, "Unexpected hCertStore\n");
CertFreeCertificateContext(cert3);
store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL);
ok(store != NULL, "CertOpenStore failed\n");
@ -2847,6 +2849,7 @@ static void testEmptyStore(void)
ok(cert3->hCertStore == store, "Unexpected hCertStore\n");
CertCloseStore(store, 0);
CertFreeCertificateContext(cert3);
res = CertCloseStore(cert->hCertStore, CERT_CLOSE_STORE_CHECK_FLAG);
ok(!res && GetLastError() == E_UNEXPECTED, "CertCloseStore returned: %x(%x)\n", res, GetLastError());