From 79e3b1cd529d586c8a4de27c47da3ce052b2f18a Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Sat, 27 Sep 2014 10:36:54 +0000 Subject: [PATCH] [CRYPT32_WINETEST] * Sync with Wine 1.7.27. CORE-8540 svn path=/trunk/; revision=64330 --- rostests/winetests/crypt32/cert.c | 54 +++++++++++++++++++++++++++-- rostests/winetests/crypt32/chain.c | 12 ------- rostests/winetests/crypt32/encode.c | 1 - rostests/winetests/crypt32/sip.c | 3 ++ rostests/winetests/crypt32/str.c | 19 +++++++++- 5 files changed, 72 insertions(+), 17 deletions(-) diff --git a/rostests/winetests/crypt32/cert.c b/rostests/winetests/crypt32/cert.c index b5486f2b841..e6af145c4a2 100644 --- a/rostests/winetests/crypt32/cert.c +++ b/rostests/winetests/crypt32/cert.c @@ -797,7 +797,7 @@ static void testLinkCert(void) ok(link->pCertInfo == context->pCertInfo, "unexpected pCertInfo\n"); CertFreeCertificateContext(link); - + CertFreeCertificateContext(context); CertCloseStore(store, 0); } @@ -1564,8 +1564,12 @@ static const BYTE chain7_1[] = { static void testGetIssuerCert(void) { BOOL ret; - PCCERT_CONTEXT parent, child, cert1, cert2; - DWORD flags = 0xffffffff; + PCCERT_CONTEXT parent, child, cert1, cert2, cert3; + DWORD flags = 0xffffffff, size; + CERT_NAME_BLOB certsubject; + BYTE *certencoded; + WCHAR rootW[] = {'R', 'O', 'O', 'T', '\0'}, + certname[] = {'C', 'N', '=', 'd', 'u', 'm', 'm', 'y', ',', ' ', 'T', '=', 'T', 'e', 's', 't', '\0'}; HCERTSTORE store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL); @@ -1640,6 +1644,7 @@ static void testGetIssuerCert(void) ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError()); parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags); ok(parent == NULL, "Expected no issuer\n"); + ok(GetLastError() == CRYPT_E_NOT_FOUND, "Expected CRYPT_E_NOT_FOUND, got %08X\n", GetLastError()); /* Adding an issuer allows one (and only one) issuer to be found */ ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING, chain10_1, sizeof(chain10_1), CERT_STORE_ADD_ALWAYS, &cert1); @@ -1648,6 +1653,7 @@ static void testGetIssuerCert(void) ok(parent == cert1, "Expected cert1 to be the issuer\n"); parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags); ok(parent == NULL, "Expected only one issuer\n"); + ok(GetLastError() == CRYPT_E_NOT_FOUND, "Expected CRYPT_E_NOT_FOUND, got %08X\n", GetLastError()); /* Adding a second issuer allows two issuers to be found - and the second * issuer is found before the first, implying certs are added to the head * of a list. @@ -1661,6 +1667,7 @@ static void testGetIssuerCert(void) ok(parent == cert1, "Expected cert1 to be the second issuer\n"); parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags); ok(parent == NULL, "Expected no more than two issuers\n"); + ok(GetLastError() == CRYPT_E_NOT_FOUND, "Expected CRYPT_E_NOT_FOUND, got %08X\n", GetLastError()); CertFreeCertificateContext(child); CertFreeCertificateContext(cert1); CertFreeCertificateContext(cert2); @@ -1677,6 +1684,7 @@ static void testGetIssuerCert(void) ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError()); parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags); ok(parent == NULL, "Expected no issuer\n"); + ok(GetLastError() == CRYPT_E_NOT_FOUND, "Expected CRYPT_E_NOT_FOUND, got %08X\n", GetLastError()); /* Adding an issuer allows one (and only one) issuer to be found */ ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING, chain10_0, sizeof(chain10_0), CERT_STORE_ADD_ALWAYS, &cert1); @@ -1685,6 +1693,7 @@ static void testGetIssuerCert(void) ok(parent == cert1, "Expected cert1 to be the issuer\n"); parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags); ok(parent == NULL, "Expected only one issuer\n"); + ok(GetLastError() == CRYPT_E_NOT_FOUND, "Expected CRYPT_E_NOT_FOUND, got %08X\n", GetLastError()); /* Adding a second issuer allows two issuers to be found - and the second * issuer is found before the first, implying certs are added to the head * of a list. @@ -1698,10 +1707,48 @@ static void testGetIssuerCert(void) ok(parent == cert1, "Expected cert1 to be the second issuer\n"); parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags); ok(parent == NULL, "Expected no more than two issuers\n"); + ok(GetLastError() == CRYPT_E_NOT_FOUND, "Expected CRYPT_E_NOT_FOUND, got %08X\n", GetLastError()); + + /* Self-sign a certificate, add to the store and test getting the issuer */ + size = 0; + ok(CertStrToNameW(X509_ASN_ENCODING, certname, CERT_X500_NAME_STR, NULL, NULL, &size, NULL), + "CertStrToName should have worked\n"); + certencoded = HeapAlloc(GetProcessHeap(), 0, size); + ok(CertStrToNameW(X509_ASN_ENCODING, certname, CERT_X500_NAME_STR, NULL, certencoded, &size, NULL), + "CertStrToName should have worked\n"); + certsubject.pbData = certencoded; + certsubject.cbData = size; + cert3 = CertCreateSelfSignCertificate(0, &certsubject, 0, NULL, NULL, NULL, NULL, NULL); + ok(cert3 != NULL, "CertCreateSelfSignCertificate should have worked\n"); + ret = CertAddCertificateContextToStore(store, cert3, CERT_STORE_ADD_REPLACE_EXISTING, 0); + ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError()); + CertFreeCertificateContext(cert3); + cert3 = CertEnumCertificatesInStore(store, NULL); + ok(cert3 != NULL, "CertEnumCertificatesInStore should have worked\n"); + SetLastError(0xdeadbeef); + flags = 0; + parent = CertGetIssuerCertificateFromStore(store, cert3, NULL, &flags); + ok(!parent, "Expected NULL\n"); + ok(GetLastError() == CRYPT_E_SELF_SIGNED, + "Expected CRYPT_E_SELF_SIGNED, got %08X\n", GetLastError()); CertFreeCertificateContext(child); CertFreeCertificateContext(cert1); CertFreeCertificateContext(cert2); CertCloseStore(store, 0); + HeapFree(GetProcessHeap(), 0, certencoded); + + /* Test root storage self-signed certificate */ + store = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER, rootW); + ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError()); + flags = 0; + cert1 = CertEnumCertificatesInStore(store, NULL); + ok(cert1 != NULL, "CertEnumCertificatesInStore should have worked\n"); + SetLastError(0xdeadbeef); + parent = CertGetIssuerCertificateFromStore(store, cert1, NULL, &flags); + ok(!parent, "Expected NULL\n"); + ok(GetLastError() == CRYPT_E_SELF_SIGNED, + "Expected CRYPT_E_SELF_SIGNED, got %08X\n", GetLastError()); + CertCloseStore(store, 0); } static void testCryptHashCert(void) @@ -2343,6 +2390,7 @@ static void testCreateSelfSignCert(void) "Expected NTE_NO_KEY, got %08x\n", GetLastError()); ret = CryptGenKey(csp, AT_KEYEXCHANGE, 0, &key); ok(ret, "CryptGenKey failed: %08x\n", GetLastError()); + CryptDestroyKey(key); memset(&info,0,sizeof(info)); info.dwProvType = PROV_RSA_FULL; diff --git a/rostests/winetests/crypt32/chain.c b/rostests/winetests/crypt32/chain.c index 2d8667a0db9..2d209f97bfa 100644 --- a/rostests/winetests/crypt32/chain.c +++ b/rostests/winetests/crypt32/chain.c @@ -3347,14 +3347,6 @@ static CONST_DATA_BLOB chain29[] = { { sizeof(chain0_0), chain0_0 }, { sizeof(chain29_1), chain29_1 }, }; -static const CERT_TRUST_STATUS elementStatus29[] = { - { CERT_TRUST_NO_ERROR, CERT_TRUST_HAS_NAME_MATCH_ISSUER }, - { CERT_TRUST_IS_UNTRUSTED_ROOT | CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT, - CERT_TRUST_IS_SELF_SIGNED | CERT_TRUST_HAS_NAME_MATCH_ISSUER }, -}; -static const SimpleChainStatusCheck simpleStatus29[] = { - { sizeof(elementStatus29) / sizeof(elementStatus29[0]), elementStatus29 }, -}; static CONST_DATA_BLOB chain30[] = { { sizeof(chain0_0), chain0_0 }, { sizeof(chain30_1), chain30_1 }, @@ -4228,10 +4220,6 @@ static const ChainPolicyCheck googlePolicyCheckWithMatchingName = { { 0, 0, -1, -1, NULL}, &expiredStatus, 0 }; -/* Windows NT 4 has a different error code when the name doesn't match. */ -static const CERT_CHAIN_POLICY_STATUS noMatchingNameBrokenStatus = - { 0, CERT_E_ROLE, 0, 0, NULL }; - /* Win98 does not trust the root of the OpenSSL chain or the Stanford chain */ static const CERT_CHAIN_POLICY_STATUS untrustedRootStatus = { 0, CERT_E_UNTRUSTEDROOT, 0, 0, NULL }; diff --git a/rostests/winetests/crypt32/encode.c b/rostests/winetests/crypt32/encode.c index d1cb42f0cd8..03d007ae498 100644 --- a/rostests/winetests/crypt32/encode.c +++ b/rostests/winetests/crypt32/encode.c @@ -2055,7 +2055,6 @@ static const unsigned char bin54[] = { 0x03,0x03,0x01,0xff,0xfe }; static const unsigned char bin55[] = { 0xff,0xfe }; static const unsigned char bin56[] = { 0x03,0x02,0x01,0xfe }; static const unsigned char bin57[] = { 0xfe }; -static const unsigned char bin58[] = { 0x03,0x01,0x00 }; static const struct encodedBits bits[] = { /* normal test cases */ diff --git a/rostests/winetests/crypt32/sip.c b/rostests/winetests/crypt32/sip.c index 753e4e74903..8a70d811873 100644 --- a/rostests/winetests/crypt32/sip.c +++ b/rostests/winetests/crypt32/sip.c @@ -119,6 +119,9 @@ static void test_AddRemoveProvider(void) newprov.pwszRemoveFuncName = dummyfunction; newprov.pwszIsFunctionNameFmt2 = dummyfunction; newprov.pwszIsFunctionName = dummyfunction; + /* If GetCapFuncName set to NULL, then CryptSIPRemoveProvider fails on win 8 */ + newprov.pwszGetCapFuncName = dummyfunction; + SetLastError(0xdeadbeef); ret = CryptSIPAddProvider(&newprov); ok ( ret, "CryptSIPAddProvider should have succeeded, last error %d\n", GetLastError()); diff --git a/rostests/winetests/crypt32/str.c b/rostests/winetests/crypt32/str.c index 528ca484932..86290c0084d 100644 --- a/rostests/winetests/crypt32/str.c +++ b/rostests/winetests/crypt32/str.c @@ -450,6 +450,15 @@ static BYTE encodedSemiCN[] = { static BYTE encodedNewlineCN[] = { 0x30,0x11,0x31,0x0f,0x30,0x0d,0x06,0x03,0x55,0x04,0x03,0x1e,0x06,0x00,0x61, 0x00,0x0a,0x00,0x62 }; +static BYTE encodedDummyCN[] = { +0x30,0x1F,0x31,0x0E,0x30,0x0C,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x64,0x75, +0x6D,0x6D,0x79,0x31,0x0D,0x30,0x0B,0x06,0x03,0x55,0x04,0x0C,0x13,0x04,0x74, +0x65,0x73,0x74 }; +static BYTE encodedFields[] = { +0x30,0x2F,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x57,0x69, +0x6E,0x65,0x20,0x54,0x65,0x73,0x74,0x31,0x0C,0x30,0x0A,0x06,0x03,0x55,0x04, +0x0C,0x13,0x03,0x31,0x32,0x33,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06, +0x13,0x02,0x42,0x52 }; static void test_CertNameToStrA(void) { @@ -756,6 +765,8 @@ static const struct StrToNameA namesA[] = { { "CN=\">\"", sizeof(encodedGreaterThanCN), encodedGreaterThanCN }, { "CN=\"#\"", sizeof(encodedHashCN), encodedHashCN }, { "CN=\";\"", sizeof(encodedSemiCN), encodedSemiCN }, + { "CN=dummy,T=test", sizeof(encodedDummyCN), encodedDummyCN }, + { " CN = Wine Test,T = 123, C = BR", sizeof(encodedFields), encodedFields }, }; static void test_CertStrToNameA(void) @@ -849,6 +860,10 @@ static const WCHAR badlyQuotedCN_W[] = { 'C','N','=','"','"','1','"','"',0 }; static const WCHAR simpleCN2_W[] = { 'C','N','=','"','1','"',0 }; static const WCHAR simpleCN3_W[] = { 'C','N',' ','=',' ','"','1','"',0 }; static const WCHAR japaneseCN_W[] = { 'C','N','=',0x226f,0x575b,0 }; +static const WCHAR dummyCN_W[] = { 'C','N','=','d','u','m','m','y',',','T','=','t','e','s','t',0 }; +static const WCHAR encodedFields_W[] = { ' ','C','N',' ','=',' ',' ',' ','W','i','n','e',' ','T', + 'e','s','t',',','T',' ','=',' ','1','2','3',',',' ','C', + ' ','=',' ','B','R',0 }; static const BYTE encodedJapaneseCN[] = { 0x30,0x0f,0x31,0x0d,0x30,0x0b,0x06, 0x03,0x55,0x04,0x03,0x1e,0x04,0x22,0x6f,0x57,0x5b }; @@ -867,6 +882,8 @@ static const struct StrToNameW namesW[] = { { greaterThanCN_W, sizeof(encodedGreaterThanCN), encodedGreaterThanCN }, { hashCN_W, sizeof(encodedHashCN), encodedHashCN }, { semiCN_W, sizeof(encodedSemiCN), encodedSemiCN }, + { dummyCN_W, sizeof(encodedDummyCN), encodedDummyCN }, + { encodedFields_W, sizeof(encodedFields), encodedFields }, }; static void test_CertStrToNameW(void) @@ -922,7 +939,7 @@ static void test_CertStrToNameW(void) size); if (ret) ok(!memcmp(buf, namesW[i].encoded, size), - "Index %d: unexpected value\n", i); + "Index %d: unexpected value for string %s\n", i, wine_dbgstr_w(namesW[i].x500)); } }