crypt32/tests: Get the tests running on Windows 98.

This commit is contained in:
Francois Gouget 2007-11-20 13:48:48 +01:00 committed by Alexandre Julliard
parent 10e738f236
commit c69d47fa49
7 changed files with 652 additions and 451 deletions

View File

@ -29,6 +29,11 @@
#include "wine/test.h"
static BOOL (WINAPI *pCertAddStoreToCollection)(HCERTSTORE,HCERTSTORE,DWORD,DWORD);
static PCCERT_CONTEXT (WINAPI *pCertCreateSelfSignCertificate)(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE,PCERT_NAME_BLOB,DWORD,PCRYPT_KEY_PROV_INFO,PCRYPT_ALGORITHM_IDENTIFIER,PSYSTEMTIME,PSYSTEMTIME,PCERT_EXTENSIONS);
static BOOL (WINAPI *pCertGetValidUsages)(DWORD,PCCERT_CONTEXT*,int*,LPSTR*,DWORD*);
static BOOL (WINAPI *pCryptAcquireCertificatePrivateKey)(PCCERT_CONTEXT,DWORD,void*,HCRYPTPROV_OR_NCRYPT_KEY_HANDLE*,DWORD*,BOOL*);
static BOOL (WINAPI *pCryptEncodeObjectEx)(DWORD,LPCSTR,const void*,DWORD,PCRYPT_ENCODE_PARA,void*,DWORD*);
static BOOL (WINAPI * pCryptVerifyCertificateSignatureEx)
(HCRYPTPROV, DWORD, DWORD, void *, DWORD, void *, DWORD, void *);
@ -45,6 +50,11 @@ static void init_function_pointers(void)
if(!p ## func) \
trace("GetProcAddress(%s) failed\n", #func);
GET_PROC(hCrypt32, CertAddStoreToCollection)
GET_PROC(hCrypt32, CertCreateSelfSignCertificate)
GET_PROC(hCrypt32, CertGetValidUsages)
GET_PROC(hCrypt32, CryptAcquireCertificatePrivateKey)
GET_PROC(hCrypt32, CryptEncodeObjectEx)
GET_PROC(hCrypt32, CryptVerifyCertificateSignatureEx)
GET_PROC(hAdvapi32, CryptAcquireContextW)
@ -256,10 +266,10 @@ static void testAddCert(void)
collection = CertOpenStore(CERT_STORE_PROV_COLLECTION, 0, 0,
CERT_STORE_CREATE_NEW_FLAG, NULL);
ok(collection != NULL, "CertOpenStore failed: %08x\n", GetLastError());
if (collection)
if (collection && pCertAddStoreToCollection)
{
/* Add store to the collection, but disable updates */
CertAddStoreToCollection(collection, store, 0, 0);
pCertAddStoreToCollection(collection, store, 0, 0);
context = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert2,
sizeof(bigCert2));
@ -1587,6 +1597,11 @@ static void testVerifyCertSig(HCRYPTPROV csp, const CRYPT_DATA_BLOB *toBeSigned,
skip("no CryptVerifyCertificateSignatureEx support\n");
return;
}
if (!pCryptEncodeObjectEx)
{
skip("no CryptEncodeObjectEx support\n");
return;
}
ret = pCryptVerifyCertificateSignatureEx(0, 0, 0, NULL, 0, NULL, 0, NULL);
ok(!ret && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %08x\n", GetLastError());
@ -1608,7 +1623,7 @@ static void testVerifyCertSig(HCRYPTPROV csp, const CRYPT_DATA_BLOB *toBeSigned,
info.Signature.cbData = sigLen;
info.Signature.pbData = (BYTE *)sig;
info.Signature.cUnusedBits = 0;
ret = CryptEncodeObjectEx(X509_ASN_ENCODING, X509_CERT, &info,
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, X509_CERT, &info,
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&cert, &size);
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
if (cert)
@ -1791,13 +1806,19 @@ static void testCreateSelfSignCert(void)
HCRYPTKEY key;
CRYPT_KEY_PROV_INFO info;
if (!pCertCreateSelfSignCertificate)
{
skip("CertCreateSelfSignCertificate() is not available\n");
return;
}
/* This crashes:
context = CertCreateSelfSignCertificate(0, NULL, 0, NULL, NULL, NULL, NULL,
context = pCertCreateSelfSignCertificate(0, NULL, 0, NULL, NULL, NULL, NULL,
NULL);
* Calling this with no first parameter creates a new key container, which
* lasts beyond the test, so I don't test that. Nb: the generated key
* name is a GUID.
context = CertCreateSelfSignCertificate(0, &name, 0, NULL, NULL, NULL, NULL,
context = pCertCreateSelfSignCertificate(0, &name, 0, NULL, NULL, NULL, NULL,
NULL);
*/
@ -1808,7 +1829,7 @@ static void testCreateSelfSignCert(void)
CRYPT_NEWKEYSET);
ok(ret, "CryptAcquireContext failed: %08x\n", GetLastError());
context = CertCreateSelfSignCertificate(csp, &name, 0, NULL, NULL, NULL,
context = pCertCreateSelfSignCertificate(csp, &name, 0, NULL, NULL, NULL,
NULL, NULL);
ok(!context && GetLastError() == NTE_NO_KEY,
"Expected NTE_NO_KEY, got %08x\n", GetLastError());
@ -1816,7 +1837,7 @@ static void testCreateSelfSignCert(void)
ok(ret, "CryptGenKey failed: %08x\n", GetLastError());
if (ret)
{
context = CertCreateSelfSignCertificate(csp, &name, 0, NULL, NULL, NULL,
context = pCertCreateSelfSignCertificate(csp, &name, 0, NULL, NULL, NULL,
NULL, NULL);
ok(context != NULL, "CertCreateSelfSignCertificate failed: %08x\n",
GetLastError());
@ -1868,7 +1889,7 @@ static void testCreateSelfSignCert(void)
info.dwKeySpec = AT_KEYEXCHANGE;
info.pwszProvName = (LPWSTR) MS_DEF_PROV_W;
info.pwszContainerName = cspNameW;
context = CertCreateSelfSignCertificate(0, &name, 0, &info, NULL, NULL,
context = pCertCreateSelfSignCertificate(0, &name, 0, &info, NULL, NULL,
NULL, NULL);
ok(context != NULL, "CertCreateSelfSignCertificate failed: %08x\n",
GetLastError());
@ -2220,14 +2241,20 @@ static void testGetValidUsages(void)
LPSTR *oids = NULL;
PCCERT_CONTEXT contexts[3];
if (!pCertGetValidUsages)
{
skip("CertGetValidUsages() is not available\n");
return;
}
/* Crash
ret = CertGetValidUsages(0, NULL, NULL, NULL, NULL);
ret = CertGetValidUsages(0, NULL, NULL, NULL, &size);
ret = pCertGetValidUsages(0, NULL, NULL, NULL, NULL);
ret = pCertGetValidUsages(0, NULL, NULL, NULL, &size);
*/
contexts[0] = NULL;
numOIDs = size = 0xdeadbeef;
SetLastError(0xdeadbeef);
ret = CertGetValidUsages(1, &contexts[0], &numOIDs, NULL, &size);
ret = pCertGetValidUsages(1, &contexts[0], &numOIDs, NULL, &size);
ok(ret, "CertGetValidUsages failed: %d\n", GetLastError());
ok(numOIDs == -1, "Expected -1, got %d\n", numOIDs);
ok(size == 0, "Expected size 0, got %d\n", size);
@ -2238,16 +2265,16 @@ static void testGetValidUsages(void)
contexts[2] = CertCreateCertificateContext(X509_ASN_ENCODING,
cert2WithUsage, sizeof(cert2WithUsage));
numOIDs = size = 0xdeadbeef;
ret = CertGetValidUsages(0, NULL, &numOIDs, NULL, &size);
ret = pCertGetValidUsages(0, NULL, &numOIDs, NULL, &size);
ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
ok(numOIDs == -1, "Expected -1, got %d\n", numOIDs);
ok(size == 0, "Expected size 0, got %d\n", size);
numOIDs = size = 0xdeadbeef;
ret = CertGetValidUsages(1, contexts, &numOIDs, NULL, &size);
ret = pCertGetValidUsages(1, contexts, &numOIDs, NULL, &size);
ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
ok(numOIDs == -1, "Expected -1, got %d\n", numOIDs);
ok(size == 0, "Expected size 0, got %d\n", size);
ret = CertGetValidUsages(1, &contexts[1], &numOIDs, NULL, &size);
ret = pCertGetValidUsages(1, &contexts[1], &numOIDs, NULL, &size);
ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
ok(numOIDs == 3, "Expected 3, got %d\n", numOIDs);
ok(size, "Expected non-zero size\n");
@ -2258,10 +2285,10 @@ static void testGetValidUsages(void)
DWORD smallSize = 1;
SetLastError(0xdeadbeef);
ret = CertGetValidUsages(1, &contexts[1], &numOIDs, oids, &smallSize);
ret = pCertGetValidUsages(1, &contexts[1], &numOIDs, oids, &smallSize);
ok(!ret && GetLastError() == ERROR_MORE_DATA,
"Expected ERROR_MORE_DATA, got %d\n", GetLastError());
ret = CertGetValidUsages(1, &contexts[1], &numOIDs, oids, &size);
ret = pCertGetValidUsages(1, &contexts[1], &numOIDs, oids, &size);
ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
for (i = 0; i < numOIDs; i++)
ok(!lstrcmpA(oids[i], expectedOIDs[i]), "unexpected OID %s\n",
@ -2270,11 +2297,11 @@ static void testGetValidUsages(void)
}
numOIDs = size = 0xdeadbeef;
/* Oddly enough, this crashes when the number of contexts is not 1:
ret = CertGetValidUsages(2, contexts, &numOIDs, NULL, &size);
ret = pCertGetValidUsages(2, contexts, &numOIDs, NULL, &size);
* but setting size to 0 allows it to succeed:
*/
size = 0;
ret = CertGetValidUsages(2, contexts, &numOIDs, NULL, &size);
ret = pCertGetValidUsages(2, contexts, &numOIDs, NULL, &size);
ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
ok(numOIDs == 3, "Expected 3, got %d\n", numOIDs);
ok(size, "Expected non-zero size\n");
@ -2283,7 +2310,7 @@ static void testGetValidUsages(void)
{
int i;
ret = CertGetValidUsages(1, &contexts[1], &numOIDs, oids, &size);
ret = pCertGetValidUsages(1, &contexts[1], &numOIDs, oids, &size);
ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
for (i = 0; i < numOIDs; i++)
ok(!lstrcmpA(oids[i], expectedOIDs[i]), "unexpected OID %s\n",
@ -2292,7 +2319,7 @@ static void testGetValidUsages(void)
}
numOIDs = 0xdeadbeef;
size = 0;
ret = CertGetValidUsages(1, &contexts[2], &numOIDs, NULL, &size);
ret = pCertGetValidUsages(1, &contexts[2], &numOIDs, NULL, &size);
ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
ok(numOIDs == 2, "Expected 2, got %d\n", numOIDs);
ok(size, "Expected non-zero size\n");
@ -2301,7 +2328,7 @@ static void testGetValidUsages(void)
{
int i;
ret = CertGetValidUsages(1, &contexts[2], &numOIDs, oids, &size);
ret = pCertGetValidUsages(1, &contexts[2], &numOIDs, oids, &size);
ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
for (i = 0; i < numOIDs; i++)
ok(!lstrcmpA(oids[i], expectedOIDs2[i]), "unexpected OID %s\n",
@ -2310,7 +2337,7 @@ static void testGetValidUsages(void)
}
numOIDs = 0xdeadbeef;
size = 0;
ret = CertGetValidUsages(3, contexts, &numOIDs, NULL, &size);
ret = pCertGetValidUsages(3, contexts, &numOIDs, NULL, &size);
ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
ok(numOIDs == 2, "Expected 2, got %d\n", numOIDs);
ok(size, "Expected non-zero size\n");
@ -2319,7 +2346,7 @@ static void testGetValidUsages(void)
{
int i;
ret = CertGetValidUsages(3, contexts, &numOIDs, oids, &size);
ret = pCertGetValidUsages(3, contexts, &numOIDs, oids, &size);
ok(ret, "CertGetValidUsages failed: %08x\n", GetLastError());
for (i = 0; i < numOIDs; i++)
ok(!lstrcmpA(oids[i], expectedOIDs2[i]), "unexpected OID %s\n",
@ -2679,6 +2706,12 @@ static void testAcquireCertPrivateKey(void)
HCRYPTKEY key;
WCHAR ms_def_prov_w[MAX_PATH];
if (!pCryptAcquireCertificatePrivateKey)
{
skip("CryptAcquireCertificatePrivateKey() is not available\n");
return;
}
lstrcpyW(ms_def_prov_w, MS_DEF_PROV_W);
keyProvInfo.pwszContainerName = cspNameW;
@ -2696,28 +2729,28 @@ static void testAcquireCertPrivateKey(void)
sizeof(selfSignedCert));
/* Crash
ret = CryptAcquireCertificatePrivateKey(NULL, 0, NULL, NULL, NULL, NULL);
ret = CryptAcquireCertificatePrivateKey(NULL, 0, NULL, NULL, NULL,
ret = pCryptAcquireCertificatePrivateKey(NULL, 0, NULL, NULL, NULL, NULL);
ret = pCryptAcquireCertificatePrivateKey(NULL, 0, NULL, NULL, NULL,
&callerFree);
ret = CryptAcquireCertificatePrivateKey(NULL, 0, NULL, NULL, &keySpec,
ret = pCryptAcquireCertificatePrivateKey(NULL, 0, NULL, NULL, &keySpec,
NULL);
ret = CryptAcquireCertificatePrivateKey(NULL, 0, NULL, &csp, NULL, NULL);
ret = CryptAcquireCertificatePrivateKey(NULL, 0, NULL, &csp, &keySpec,
ret = pCryptAcquireCertificatePrivateKey(NULL, 0, NULL, &csp, NULL, NULL);
ret = pCryptAcquireCertificatePrivateKey(NULL, 0, NULL, &csp, &keySpec,
&callerFree);
ret = CryptAcquireCertificatePrivateKey(cert, 0, NULL, NULL, NULL, NULL);
ret = pCryptAcquireCertificatePrivateKey(cert, 0, NULL, NULL, NULL, NULL);
*/
/* Missing private key */
ret = CryptAcquireCertificatePrivateKey(cert, 0, NULL, &csp, NULL, NULL);
ret = pCryptAcquireCertificatePrivateKey(cert, 0, NULL, &csp, NULL, NULL);
ok(!ret && GetLastError() == CRYPT_E_NO_KEY_PROPERTY,
"Expected CRYPT_E_NO_KEY_PROPERTY, got %08x\n", GetLastError());
ret = CryptAcquireCertificatePrivateKey(cert, 0, NULL, &csp, &keySpec,
ret = pCryptAcquireCertificatePrivateKey(cert, 0, NULL, &csp, &keySpec,
&callerFree);
ok(!ret && GetLastError() == CRYPT_E_NO_KEY_PROPERTY,
"Expected CRYPT_E_NO_KEY_PROPERTY, got %08x\n", GetLastError());
CertSetCertificateContextProperty(cert, CERT_KEY_PROV_INFO_PROP_ID, 0,
&keyProvInfo);
ret = CryptAcquireCertificatePrivateKey(cert, 0, NULL, &csp, &keySpec,
ret = pCryptAcquireCertificatePrivateKey(cert, 0, NULL, &csp, &keySpec,
&callerFree);
ok(!ret && GetLastError() == CRYPT_E_NO_KEY_PROPERTY,
"Expected CRYPT_E_NO_KEY_PROPERTY, got %08x\n", GetLastError());
@ -2733,20 +2766,20 @@ static void testAcquireCertPrivateKey(void)
CERT_KEY_CONTEXT keyContext;
/* Don't cache provider */
ret = CryptAcquireCertificatePrivateKey(cert, 0, NULL, &certCSP,
ret = pCryptAcquireCertificatePrivateKey(cert, 0, NULL, &certCSP,
&keySpec, &callerFree);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08x\n",
GetLastError());
ok(callerFree, "Expected callerFree to be TRUE\n");
CryptReleaseContext(certCSP, 0);
ret = CryptAcquireCertificatePrivateKey(cert, 0, NULL, &certCSP,
ret = pCryptAcquireCertificatePrivateKey(cert, 0, NULL, &certCSP,
NULL, NULL);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08x\n",
GetLastError());
CryptReleaseContext(certCSP, 0);
/* Use the key prov info's caching (there shouldn't be any) */
ret = CryptAcquireCertificatePrivateKey(cert,
ret = pCryptAcquireCertificatePrivateKey(cert,
CRYPT_ACQUIRE_USE_PROV_INFO_FLAG, NULL, &certCSP, &keySpec,
&callerFree);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08x\n",
@ -2755,7 +2788,7 @@ static void testAcquireCertPrivateKey(void)
CryptReleaseContext(certCSP, 0);
/* Cache it (and check that it's cached) */
ret = CryptAcquireCertificatePrivateKey(cert,
ret = pCryptAcquireCertificatePrivateKey(cert,
CRYPT_ACQUIRE_CACHE_FLAG, NULL, &certCSP, &keySpec, &callerFree);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08x\n",
GetLastError());
@ -2775,7 +2808,7 @@ static void testAcquireCertPrivateKey(void)
CertSetCertificateContextProperty(cert, CERT_KEY_PROV_INFO_PROP_ID, 0,
&keyProvInfo);
/* Now use the key prov info's caching */
ret = CryptAcquireCertificatePrivateKey(cert,
ret = pCryptAcquireCertificatePrivateKey(cert,
CRYPT_ACQUIRE_USE_PROV_INFO_FLAG, NULL, &certCSP, &keySpec,
&callerFree);
ok(ret, "CryptAcquireCertificatePrivateKey failed: %08x\n",
@ -2808,7 +2841,7 @@ static void testAcquireCertPrivateKey(void)
ok(size == sizeof(exportedPublicKeyBlob), "Unexpected size %d\n",
size);
ok(!memcmp(buf, exportedPublicKeyBlob, size), "Unexpected value\n");
ret = CryptEncodeObjectEx(X509_ASN_ENCODING, RSA_CSP_PUBLICKEYBLOB,
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, RSA_CSP_PUBLICKEYBLOB,
buf, CRYPT_ENCODE_ALLOC_FLAG, NULL, &encodedKey, &size);
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
if (ret)

View File

@ -52,6 +52,13 @@ static const BYTE selfSignedCert[] = {
0x0a, 0x8c, 0xb4, 0x5c, 0x34, 0x78, 0xe0, 0x3c, 0x9c, 0xe9, 0xf3, 0x30, 0x9f,
0xa8, 0x76, 0x57, 0x92, 0x36 };
static BOOL (WINAPI *pCertCreateCertificateChainEngine)(PCERT_CHAIN_ENGINE_CONFIG,HCERTCHAINENGINE*);
static BOOL (WINAPI *pCertGetCertificateChain)(HCERTCHAINENGINE,PCCERT_CONTEXT,LPFILETIME,HCERTSTORE,PCERT_CHAIN_PARA,DWORD,LPVOID,PCCERT_CHAIN_CONTEXT*);
static VOID (WINAPI *pCertFreeCertificateChain)(PCCERT_CHAIN_CONTEXT);
static VOID (WINAPI *pCertFreeCertificateChainEngine)(HCERTCHAINENGINE);
static BOOL (WINAPI *pCertVerifyCertificateChainPolicy)(LPCSTR,PCCERT_CHAIN_CONTEXT,PCERT_CHAIN_POLICY_PARA,PCERT_CHAIN_POLICY_STATUS);
static void testCreateCertChainEngine(void)
{
BOOL ret;
@ -59,43 +66,49 @@ static void testCreateCertChainEngine(void)
HCERTCHAINENGINE engine;
HCERTSTORE store;
if (!pCertCreateCertificateChainEngine || !pCertFreeCertificateChainEngine)
{
skip("Cert*CertificateChainEngine() functions are not available\n");
return;
}
/* Crash
ret = CertCreateCertificateChainEngine(NULL, NULL);
ret = CertCreateCertificateChainEngine(NULL, &engine);
ret = pCertCreateCertificateChainEngine(NULL, NULL);
ret = pCertCreateCertificateChainEngine(NULL, &engine);
*/
ret = CertCreateCertificateChainEngine(&config, NULL);
ret = pCertCreateCertificateChainEngine(&config, NULL);
ok(!ret && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %08x\n", GetLastError());
ret = CertCreateCertificateChainEngine(&config, &engine);
ret = pCertCreateCertificateChainEngine(&config, &engine);
ok(!ret && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %08x\n", GetLastError());
/* Crashes
config.cbSize = sizeof(config);
ret = CertCreateCertificateChainEngine(&config, NULL);
ret = pCertCreateCertificateChainEngine(&config, NULL);
*/
config.cbSize = sizeof(config);
ret = CertCreateCertificateChainEngine(&config, &engine);
ret = pCertCreateCertificateChainEngine(&config, &engine);
ok(ret, "CertCreateCertificateChainEngine failed: %08x\n", GetLastError());
CertFreeCertificateChainEngine(engine);
pCertFreeCertificateChainEngine(engine);
config.dwFlags = 0xff000000;
ret = CertCreateCertificateChainEngine(&config, &engine);
ret = pCertCreateCertificateChainEngine(&config, &engine);
ok(ret, "CertCreateCertificateChainEngine failed: %08x\n", GetLastError());
CertFreeCertificateChainEngine(engine);
pCertFreeCertificateChainEngine(engine);
/* Creating a cert with no root certs at all is allowed.. */
store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
CERT_STORE_CREATE_NEW_FLAG, NULL);
config.hRestrictedRoot = store;
ret = CertCreateCertificateChainEngine(&config, &engine);
ret = pCertCreateCertificateChainEngine(&config, &engine);
ok(ret, "CertCreateCertificateChainEngine failed: %08x\n", GetLastError());
CertFreeCertificateChainEngine(engine);
pCertFreeCertificateChainEngine(engine);
/* but creating one with a restricted root with a cert that isn't a member
* of the Root store isn't allowed.
*/
CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING, selfSignedCert,
sizeof(selfSignedCert), CERT_STORE_ADD_ALWAYS, NULL);
ret = CertCreateCertificateChainEngine(&config, &engine);
ret = pCertCreateCertificateChainEngine(&config, &engine);
ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
"Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
@ -1129,7 +1142,7 @@ static PCCERT_CHAIN_CONTEXT getChain(const CONST_BLOB_ARRAY *certArray,
FILETIME fileTime;
SystemTimeToFileTime(checkTime, &fileTime);
ret = CertGetCertificateChain(NULL, endCert, &fileTime,
ret = pCertGetCertificateChain(NULL, endCert, &fileTime,
includeStore ? store : NULL, &chainPara, flags, NULL, &chain);
if (todo & TODO_CHAIN)
todo_wine ok(ret, "Chain %d: CertGetCertificateChain failed: %08x\n",
@ -1566,36 +1579,36 @@ static void testGetCertChain(void)
DWORD i;
/* Basic parameter checks */
ret = CertGetCertificateChain(NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL);
ret = pCertGetCertificateChain(NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL);
ok(!ret && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %08x\n", GetLastError());
ret = CertGetCertificateChain(NULL, NULL, NULL, NULL, NULL, 0, NULL,
ret = pCertGetCertificateChain(NULL, NULL, NULL, NULL, NULL, 0, NULL,
&chain);
ok(!ret && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %08x\n", GetLastError());
/* Crash
ret = CertGetCertificateChain(NULL, NULL, NULL, NULL, &para, 0, NULL, NULL);
ret = CertGetCertificateChain(NULL, NULL, NULL, NULL, &para, 0, NULL,
ret = pCertGetCertificateChain(NULL, NULL, NULL, NULL, &para, 0, NULL, NULL);
ret = pCertGetCertificateChain(NULL, NULL, NULL, NULL, &para, 0, NULL,
&chain);
*/
cert = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert,
sizeof(bigCert));
ret = CertGetCertificateChain(NULL, cert, NULL, NULL, NULL, 0, NULL, NULL);
ret = pCertGetCertificateChain(NULL, cert, NULL, NULL, NULL, 0, NULL, NULL);
ok(!ret && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %08x\n", GetLastError());
/* Crash
ret = CertGetCertificateChain(NULL, cert, NULL, NULL, &para, 0, NULL, NULL);
ret = pCertGetCertificateChain(NULL, cert, NULL, NULL, &para, 0, NULL, NULL);
*/
/* Tests with an invalid cert (one whose signature is bad) */
SetLastError(0xdeadbeef);
ret = CertGetCertificateChain(NULL, cert, NULL, NULL, &para, 0, NULL,
ret = pCertGetCertificateChain(NULL, cert, NULL, NULL, &para, 0, NULL,
&chain);
ok(!ret && GetLastError() == ERROR_INVALID_DATA,
"Expected ERROR_INVALID_DATA, got %d\n", GetLastError());
para.cbSize = sizeof(para);
SetLastError(0xdeadbeef);
ret = CertGetCertificateChain(NULL, cert, NULL, NULL, &para, 0, NULL,
ret = pCertGetCertificateChain(NULL, cert, NULL, NULL, &para, 0, NULL,
&chain);
ok(!ret && GetLastError() == ERROR_INVALID_DATA,
"Expected ERROR_INVALID_DATA, got %d\n", GetLastError());
@ -1609,7 +1622,7 @@ static void testGetCertChain(void)
{
checkChainStatus(chain, &chainCheck[i].status, chainCheck[i].todo,
i);
CertFreeCertificateChain(chain);
pCertFreeCertificateChain(chain);
}
}
for (i = 0; i < sizeof(chainCheckNoStore) / sizeof(chainCheckNoStore[0]);
@ -1621,7 +1634,7 @@ static void testGetCertChain(void)
{
checkChainStatus(chain, &chainCheckNoStore[i].status,
chainCheckNoStore[i].todo, i);
CertFreeCertificateChain(chain);
pCertFreeCertificateChain(chain);
}
}
}
@ -1737,7 +1750,7 @@ static void checkChainPolicyStatus(LPCSTR policy, ChainPolicyCheck *check,
if (chain)
{
CERT_CHAIN_POLICY_STATUS policyStatus = { 0 };
BOOL ret = CertVerifyCertificateChainPolicy(policy, chain, NULL,
BOOL ret = pCertVerifyCertificateChainPolicy(policy, chain, NULL,
&policyStatus);
if (check->todo & TODO_POLICY)
@ -1775,7 +1788,7 @@ static void checkChainPolicyStatus(LPCSTR policy, ChainPolicyCheck *check,
"%d: expected %d, got %d\n", testIndex,
check->status.lElementIndex, policyStatus.lElementIndex);
}
CertFreeCertificateChain(chain);
pCertFreeCertificateChain(chain);
}
}
@ -1789,34 +1802,40 @@ static void testVerifyCertChainPolicy(void)
CERT_CHAIN_POLICY_PARA policyPara = { 0 };
DWORD i;
if (!pCertVerifyCertificateChainPolicy)
{
skip("CertVerifyCertificateChainPolicy() is not available\n");
return;
}
/* Crash
ret = CertVerifyCertificateChainPolicy(NULL, NULL, NULL, NULL);
ret = CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, NULL, NULL,
ret = pCertVerifyCertificateChainPolicy(NULL, NULL, NULL, NULL);
ret = pCertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, NULL, NULL,
NULL);
ret = CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, NULL,
ret = pCertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, NULL,
&chainPara, NULL);
*/
SetLastError(0xdeadbeef);
ret = CertVerifyCertificateChainPolicy(NULL, NULL, NULL, &policyStatus);
ret = pCertVerifyCertificateChainPolicy(NULL, NULL, NULL, &policyStatus);
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
"Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
/* Crashes
ret = CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, NULL, NULL,
ret = pCertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, NULL, NULL,
&policyStatus);
*/
cert = CertCreateCertificateContext(X509_ASN_ENCODING, selfSignedCert,
sizeof(selfSignedCert));
CertGetCertificateChain(NULL, cert, NULL, NULL, &chainPara, 0, NULL,
pCertGetCertificateChain(NULL, cert, NULL, NULL, &chainPara, 0, NULL,
&chain);
/* Crash
ret = CertVerifyCertificateChainPolicy(NULL, chain, NULL, NULL);
ret = CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, chain, NULL,
ret = pCertVerifyCertificateChainPolicy(NULL, chain, NULL, NULL);
ret = pCertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, chain, NULL,
NULL);
ret = CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, chain,
ret = pCertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, chain,
&chainPara, NULL);
*/
/* Size of policy status is apparently ignored, as is pChainPolicyPara */
ret = CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, chain, NULL,
ret = pCertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, chain, NULL,
&policyStatus);
ok(ret, "CertVerifyCertificateChainPolicy failed: %08x\n", GetLastError());
ok(policyStatus.dwError == CERT_E_UNTRUSTEDROOT,
@ -1824,7 +1843,7 @@ static void testVerifyCertChainPolicy(void)
ok(policyStatus.lChainIndex == 0 && policyStatus.lElementIndex == 0,
"Expected both indexes 0, got %d, %d\n", policyStatus.lChainIndex,
policyStatus.lElementIndex);
ret = CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, chain,
ret = pCertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, chain,
&policyPara, &policyStatus);
ok(ret, "CertVerifyCertificateChainPolicy failed: %08x\n", GetLastError());
ok(policyStatus.dwError == CERT_E_UNTRUSTEDROOT,
@ -1832,7 +1851,7 @@ static void testVerifyCertChainPolicy(void)
ok(policyStatus.lChainIndex == 0 && policyStatus.lElementIndex == 0,
"Expected both indexes 0, got %d, %d\n", policyStatus.lChainIndex,
policyStatus.lElementIndex);
CertFreeCertificateChain(chain);
pCertFreeCertificateChain(chain);
CertFreeCertificateContext(cert);
for (i = 0;
@ -1855,7 +1874,21 @@ static void testVerifyCertChainPolicy(void)
START_TEST(chain)
{
HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
pCertCreateCertificateChainEngine = (void*)GetProcAddress(hCrypt32, "CertCreateCertificateChainEngine");
pCertGetCertificateChain = (void*)GetProcAddress(hCrypt32, "CertGetCertificateChain");
pCertFreeCertificateChain = (void*)GetProcAddress(hCrypt32, "CertFreeCertificateChain");
pCertFreeCertificateChainEngine = (void*)GetProcAddress(hCrypt32, "CertFreeCertificateChainEngine");
pCertVerifyCertificateChainPolicy = (void*)GetProcAddress(hCrypt32, "CertVerifyCertificateChainPolicy");
testCreateCertChainEngine();
testVerifyCertChainPolicy();
testGetCertChain();
if (!pCertGetCertificateChain)
{
skip("CertGetCertificateChain() is not available\n");
}
else
{
testVerifyCertChainPolicy();
testGetCertChain();
}
}

View File

@ -29,6 +29,7 @@
#include "wine/test.h"
static const BYTE bigCert[] = { 0x30, 0x7a, 0x02, 0x01, 0x01, 0x30, 0x02, 0x06,
0x00, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13,
0x0a, 0x4a, 0x75, 0x61, 0x6e, 0x20, 0x4c, 0x61, 0x6e, 0x67, 0x00, 0x30, 0x22,
@ -76,11 +77,15 @@ static const BYTE signedCRL[] = { 0x30, 0x45, 0x30, 0x2c, 0x30, 0x02, 0x06,
0x30, 0x5a, 0x30, 0x02, 0x06, 0x00, 0x03, 0x11, 0x00, 0x0f, 0x0e, 0x0d, 0x0c,
0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 };
static BOOL (WINAPI *pCertFindCertificateInCRL)(PCCERT_CONTEXT,PCCRL_CONTEXT,DWORD,void*,PCRL_ENTRY*);
static PCCRL_CONTEXT (WINAPI *pCertFindCRLInStore)(HCERTSTORE,DWORD,DWORD,DWORD,const void*,PCCRL_CONTEXT);
static BOOL (WINAPI *pCertIsValidCRLForCertificate)(PCCERT_CONTEXT, PCCRL_CONTEXT, DWORD, void*);
static void init_function_pointers(void)
{
HMODULE hdll = GetModuleHandleA("crypt32.dll");
pCertFindCertificateInCRL = (void*)GetProcAddress(hdll, "CertFindCertificateInCRL");
pCertFindCRLInStore = (void*)GetProcAddress(hdll, "CertFindCRLInStore");
pCertIsValidCRLForCertificate = (void*)GetProcAddress(hdll, "CertIsValidCRLForCertificate");
}
@ -205,33 +210,38 @@ static void testFindCRL(void)
BOOL ret;
if (!store) return;
if (!pCertFindCRLInStore)
{
skip("CertFindCRLInStore() is not available\n");
return;
}
ret = CertAddEncodedCRLToStore(store, X509_ASN_ENCODING, signedCRL,
sizeof(signedCRL), CERT_STORE_ADD_ALWAYS, NULL);
ok(ret, "CertAddEncodedCRLToStore failed: %08x\n", GetLastError());
/* Crashes
context = CertFindCRLInStore(NULL, 0, 0, 0, NULL, NULL);
context = pCertFindCRLInStore(NULL, 0, 0, 0, NULL, NULL);
*/
/* Find any context */
context = CertFindCRLInStore(store, 0, 0, CRL_FIND_ANY, NULL, NULL);
context = pCertFindCRLInStore(store, 0, 0, CRL_FIND_ANY, NULL, NULL);
ok(context != NULL, "Expected a context\n");
if (context)
CertFreeCRLContext(context);
/* Bogus flags are ignored */
context = CertFindCRLInStore(store, 0, 1234, CRL_FIND_ANY, NULL, NULL);
context = pCertFindCRLInStore(store, 0, 1234, CRL_FIND_ANY, NULL, NULL);
ok(context != NULL, "Expected a context\n");
if (context)
CertFreeCRLContext(context);
/* CRL encoding type is ignored too */
context = CertFindCRLInStore(store, 1234, 0, CRL_FIND_ANY, NULL, NULL);
context = pCertFindCRLInStore(store, 1234, 0, CRL_FIND_ANY, NULL, NULL);
ok(context != NULL, "Expected a context\n");
if (context)
CertFreeCRLContext(context);
/* This appears to match any cert */
context = CertFindCRLInStore(store, 0, 0, CRL_FIND_ISSUED_BY, NULL, NULL);
context = pCertFindCRLInStore(store, 0, 0, CRL_FIND_ISSUED_BY, NULL, NULL);
ok(context != NULL, "Expected a context\n");
if (context)
CertFreeCRLContext(context);
@ -241,7 +251,7 @@ static void testFindCRL(void)
sizeof(bigCert2));
ok(cert != NULL, "CertCreateCertificateContext failed: %08x\n",
GetLastError());
context = CertFindCRLInStore(store, 0, 0, CRL_FIND_ISSUED_BY, cert, NULL);
context = pCertFindCRLInStore(store, 0, 0, CRL_FIND_ISSUED_BY, cert, NULL);
ok(context == NULL, "Expected no matching context\n");
CertFreeCertificateContext(cert);
@ -250,7 +260,7 @@ static void testFindCRL(void)
sizeof(bigCert));
ok(cert != NULL, "CertCreateCertificateContext failed: %08x\n",
GetLastError());
context = CertFindCRLInStore(store, 0, 0, CRL_FIND_ISSUED_BY, cert, NULL);
context = pCertFindCRLInStore(store, 0, 0, CRL_FIND_ISSUED_BY, cert, NULL);
ok(context != NULL, "Expected a context\n");
if (context)
CertFreeCRLContext(context);
@ -600,31 +610,37 @@ static void testFindCertInCRL(void)
PCCRL_CONTEXT crl;
PCRL_ENTRY entry;
if (!pCertFindCertificateInCRL)
{
skip("CertFindCertificateInCRL() is not available\n");
return;
}
cert = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert,
sizeof(bigCert));
ok(cert != NULL, "CertCreateCertificateContext failed: %08x\n",
GetLastError());
/* Crash
ret = CertFindCertificateInCRL(NULL, NULL, 0, NULL, NULL);
ret = CertFindCertificateInCRL(NULL, crl, 0, NULL, NULL);
ret = CertFindCertificateInCRL(cert, NULL, 0, NULL, NULL);
ret = CertFindCertificateInCRL(cert, crl, 0, NULL, NULL);
ret = CertFindCertificateInCRL(NULL, NULL, 0, NULL, &entry);
ret = CertFindCertificateInCRL(NULL, crl, 0, NULL, &entry);
ret = CertFindCertificateInCRL(cert, NULL, 0, NULL, &entry);
ret = pCertFindCertificateInCRL(NULL, NULL, 0, NULL, NULL);
ret = pCertFindCertificateInCRL(NULL, crl, 0, NULL, NULL);
ret = pCertFindCertificateInCRL(cert, NULL, 0, NULL, NULL);
ret = pCertFindCertificateInCRL(cert, crl, 0, NULL, NULL);
ret = pCertFindCertificateInCRL(NULL, NULL, 0, NULL, &entry);
ret = pCertFindCertificateInCRL(NULL, crl, 0, NULL, &entry);
ret = pCertFindCertificateInCRL(cert, NULL, 0, NULL, &entry);
*/
crl = CertCreateCRLContext(X509_ASN_ENCODING, verisignCRL,
sizeof(verisignCRL));
ret = CertFindCertificateInCRL(cert, crl, 0, NULL, &entry);
ret = pCertFindCertificateInCRL(cert, crl, 0, NULL, &entry);
ok(ret, "CertFindCertificateInCRL failed: %08x\n", GetLastError());
ok(entry == NULL, "Expected not to find an entry in CRL\n");
CertFreeCRLContext(crl);
crl = CertCreateCRLContext(X509_ASN_ENCODING, v1CRLWithIssuerAndEntry,
sizeof(v1CRLWithIssuerAndEntry));
ret = CertFindCertificateInCRL(cert, crl, 0, NULL, &entry);
ret = pCertFindCertificateInCRL(cert, crl, 0, NULL, &entry);
ok(ret, "CertFindCertificateInCRL failed: %08x\n", GetLastError());
ok(entry != NULL, "Expected to find an entry in CRL\n");
CertFreeCRLContext(crl);
@ -632,7 +648,7 @@ static void testFindCertInCRL(void)
/* Entry found even though CRL issuer doesn't match cert issuer */
crl = CertCreateCRLContext(X509_ASN_ENCODING, crlWithDifferentIssuer,
sizeof(crlWithDifferentIssuer));
ret = CertFindCertificateInCRL(cert, crl, 0, NULL, &entry);
ret = pCertFindCertificateInCRL(cert, crl, 0, NULL, &entry);
ok(ret, "CertFindCertificateInCRL failed: %08x\n", GetLastError());
ok(entry != NULL, "Expected to find an entry in CRL\n");
CertFreeCRLContext(crl);

File diff suppressed because it is too large Load Diff

View File

@ -27,6 +27,10 @@
#include "wine/test.h"
static BOOL (WINAPI *pCryptEnumOIDInfo)(DWORD,DWORD,void*,PFN_CRYPT_ENUM_OID_INFO);
struct OIDToAlgID
{
LPCSTR oid;
@ -471,14 +475,20 @@ static void test_enumOIDInfo(void)
BOOL ret;
DWORD count = 0;
if (!pCryptEnumOIDInfo)
{
skip("CryptEnumOIDInfo() is not available\n");
return;
}
/* This crashes
ret = CryptEnumOIDInfo(7, 0, NULL, NULL);
ret = pCryptEnumOIDInfo(7, 0, NULL, NULL);
*/
/* Silly tests, check that more than one thing is enumerated */
ret = CryptEnumOIDInfo(0, 0, &count, countOidInfo);
ret = pCryptEnumOIDInfo(0, 0, &count, countOidInfo);
ok(ret && count > 0, "Expected more than item enumerated\n");
ret = CryptEnumOIDInfo(0, 0, NULL, noOidInfo);
ret = pCryptEnumOIDInfo(0, 0, NULL, noOidInfo);
ok(!ret, "Expected FALSE\n");
}
@ -532,6 +542,9 @@ static void test_findOIDInfo(void)
START_TEST(oid)
{
HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
pCryptEnumOIDInfo = (void*)GetProcAddress(hCrypt32, "CryptEnumOIDInfo");
testOIDToAlgID();
testAlgIDToOID();
test_enumOIDInfo();

View File

@ -27,6 +27,9 @@
#include "wine/test.h"
static BOOL (WINAPI *pCryptProtectData)(DATA_BLOB*,LPCWSTR,DATA_BLOB*,PVOID,CRYPTPROTECT_PROMPTSTRUCT*,DWORD,DATA_BLOB*);
static BOOL (WINAPI *pCryptUnprotectData)(DATA_BLOB*,LPWSTR*,DATA_BLOB*,PVOID,CRYPTPROTECT_PROMPTSTRUCT*,DWORD,DATA_BLOB*);
static char secret[] = "I am a super secret string that no one can see!";
static char secret2[] = "I am a super secret string indescribable string";
static char key[] = "Wibble wibble wibble";
@ -49,13 +52,13 @@ static void test_cryptprotectdata(void)
entropy.cbData=strlen(key)+1;
SetLastError(0xDEADBEEF);
protected = CryptProtectData(NULL,desc,NULL,NULL,NULL,0,&cipher);
protected = pCryptProtectData(NULL,desc,NULL,NULL,NULL,0,&cipher);
ok(!protected, "Encrypting without plain data source.\n");
r = GetLastError();
ok(r == ERROR_INVALID_PARAMETER, "Wrong (%u) GetLastError seen\n",r);
SetLastError(0xDEADBEEF);
protected = CryptProtectData(&plain,desc,NULL,NULL,NULL,0,NULL);
protected = pCryptProtectData(&plain,desc,NULL,NULL,NULL,0,NULL);
ok(!protected, "Encrypting without cipher destination.\n");
r = GetLastError();
ok(r == ERROR_INVALID_PARAMETER, "Wrong (%u) GetLastError seen\n",r);
@ -65,7 +68,7 @@ static void test_cryptprotectdata(void)
/* without entropy */
SetLastError(0xDEADBEEF);
protected = CryptProtectData(&plain,desc,NULL,NULL,NULL,0,&cipher);
protected = pCryptProtectData(&plain,desc,NULL,NULL,NULL,0,&cipher);
ok(protected, "Encrypting without entropy.\n");
r = GetLastError();
ok(r == ERROR_SUCCESS, "Wrong (%u) GetLastError seen\n",r);
@ -75,7 +78,7 @@ static void test_cryptprotectdata(void)
/* with entropy */
SetLastError(0xDEADBEEF);
protected = CryptProtectData(&plain,desc,&entropy,NULL,NULL,0,&cipher_entropy);
protected = pCryptProtectData(&plain,desc,&entropy,NULL,NULL,0,&cipher_entropy);
ok(protected, "Encrypting with entropy.\n");
r = GetLastError();
ok(r == ERROR_SUCCESS, "Wrong (%u) GetLastError seen\n",r);
@ -87,7 +90,7 @@ static void test_cryptprotectdata(void)
plain.pbData=(void*)secret2;
plain.cbData=strlen(secret2)+1;
SetLastError(0xDEADBEEF);
protected = CryptProtectData(&plain,NULL,&entropy,NULL,NULL,0,&cipher_no_desc);
protected = pCryptProtectData(&plain,NULL,&entropy,NULL,NULL,0,&cipher_no_desc);
ok(protected, "Encrypting with entropy and no description.\n");
r = GetLastError();
ok(r == ERROR_SUCCESS, "Wrong (%u) GetLastError seen\n",r);
@ -111,13 +114,13 @@ static void test_cryptunprotectdata(void)
plain.cbData=0;
SetLastError(0xDEADBEEF);
okay = CryptUnprotectData(&cipher,NULL,NULL,NULL,NULL,0,NULL);
okay = pCryptUnprotectData(&cipher,NULL,NULL,NULL,NULL,0,NULL);
ok(!okay,"Decrypting without destination\n");
r = GetLastError();
ok(r == ERROR_INVALID_PARAMETER, "Wrong (%u) GetLastError seen\n",r);
SetLastError(0xDEADBEEF);
okay = CryptUnprotectData(NULL,NULL,NULL,NULL,NULL,0,&plain);
okay = pCryptUnprotectData(NULL,NULL,NULL,NULL,NULL,0,&plain);
ok(!okay,"Decrypting without source\n");
r = GetLastError();
ok(r == ERROR_INVALID_PARAMETER, "Wrong (%u) GetLastError seen\n",r);
@ -126,7 +129,7 @@ static void test_cryptunprotectdata(void)
plain.cbData=0;
SetLastError(0xDEADBEEF);
okay = CryptUnprotectData(&cipher_entropy,NULL,NULL,NULL,NULL,0,&plain);
okay = pCryptUnprotectData(&cipher_entropy,NULL,NULL,NULL,NULL,0,&plain);
ok(!okay,"Decrypting without needed entropy\n");
r = GetLastError();
ok(r == ERROR_INVALID_DATA, "Wrong (%u) GetLastError seen\n", r);
@ -137,7 +140,7 @@ static void test_cryptunprotectdata(void)
/* without entropy */
SetLastError(0xDEADBEEF);
okay = CryptUnprotectData(&cipher,&data_desc,NULL,NULL,NULL,0,&plain);
okay = pCryptUnprotectData(&cipher,&data_desc,NULL,NULL,NULL,0,&plain);
ok(okay,"Decrypting without entropy\n");
r = GetLastError();
ok(r == ERROR_SUCCESS, "Wrong (%u) GetLastError seen\n",r);
@ -157,14 +160,14 @@ static void test_cryptunprotectdata(void)
/* with wrong entropy */
SetLastError(0xDEADBEEF);
okay = CryptUnprotectData(&cipher_entropy,&data_desc,&cipher_entropy,NULL,NULL,0,&plain);
okay = pCryptUnprotectData(&cipher_entropy,&data_desc,&cipher_entropy,NULL,NULL,0,&plain);
ok(!okay,"Decrypting with wrong entropy\n");
r = GetLastError();
ok(r == ERROR_INVALID_DATA, "Wrong (%u) GetLastError seen\n",r);
/* with entropy */
SetLastError(0xDEADBEEF);
okay = CryptUnprotectData(&cipher_entropy,&data_desc,&entropy,NULL,NULL,0,&plain);
okay = pCryptUnprotectData(&cipher_entropy,&data_desc,&entropy,NULL,NULL,0,&plain);
ok(okay,"Decrypting with entropy\n");
r = GetLastError();
ok(r == ERROR_SUCCESS, "Wrong (%u) GetLastError seen\n",r);
@ -184,7 +187,7 @@ static void test_cryptunprotectdata(void)
/* with entropy but no description */
SetLastError(0xDEADBEEF);
okay = CryptUnprotectData(&cipher_no_desc,&data_desc,&entropy,NULL,NULL,0,&plain);
okay = pCryptUnprotectData(&cipher_no_desc,&data_desc,&entropy,NULL,NULL,0,&plain);
ok(okay,"Decrypting with entropy and no description\n");
r = GetLastError();
ok(r == ERROR_SUCCESS, "Wrong (%u) GetLastError seen\n",r);
@ -204,8 +207,17 @@ static void test_cryptunprotectdata(void)
START_TEST(protectdata)
{
protected=FALSE;
HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
hCrypt32 = GetModuleHandleA("crypt32.dll");
pCryptProtectData = (void*)GetProcAddress(hCrypt32, "CryptProtectData");
pCryptUnprotectData = (void*)GetProcAddress(hCrypt32, "CryptUnprotectData");
if (!pCryptProtectData || !pCryptUnprotectData)
{
skip("Crypt(Un)ProtectData() is not available\n");
return;
}
protected=FALSE;
test_cryptprotectdata();
test_cryptunprotectdata();

View File

@ -94,6 +94,15 @@ static const BYTE bigCert2[] = { 0x30, 0x7a, 0x02, 0x01, 0x01, 0x30, 0x02, 0x06,
0x00, 0xa3, 0x16, 0x30, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01,
0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x01 };
static BOOL (WINAPI *pCertAddStoreToCollection)(HCERTSTORE,HCERTSTORE,DWORD,DWORD);
static BOOL (WINAPI *pCertControlStore)(HCERTSTORE,DWORD,DWORD,void const*);
static PCCRL_CONTEXT (WINAPI *pCertEnumCRLsInStore)(HCERTSTORE,PCCRL_CONTEXT);
static BOOL (WINAPI *pCertEnumSystemStore)(DWORD,void*,void*,PFN_CERT_ENUM_SYSTEM_STORE);
static BOOL (WINAPI *pCertGetStoreProperty)(HCERTSTORE,DWORD,void*,DWORD*);
static void (WINAPI *pCertRemoveStoreFromCollection)(HCERTSTORE,HCERTSTORE);
static BOOL (WINAPI *pCertSetStoreProperty)(HCERTSTORE,DWORD,DWORD,const void*);
static void testMemStore(void)
{
HCERTSTORE store1, store2;
@ -274,6 +283,12 @@ static void testCollectionStore(void)
PCCERT_CONTEXT context;
BOOL ret;
if (!pCertAddStoreToCollection)
{
skip("CertAddStoreToCollection() is not available\n");
return;
}
collection = CertOpenStore(CERT_STORE_PROV_COLLECTION, 0, 0,
CERT_STORE_CREATE_NEW_FLAG, NULL);
@ -290,7 +305,7 @@ static void testCollectionStore(void)
bigCert, sizeof(bigCert), CERT_STORE_ADD_ALWAYS, NULL);
ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
/* Add the memory store to the collection, without allowing adding */
ret = CertAddStoreToCollection(collection, store1, 0, 0);
ret = pCertAddStoreToCollection(collection, store1, 0, 0);
ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
/* Verify the cert is in the collection */
context = CertEnumCertificatesInStore(collection, NULL);
@ -310,26 +325,26 @@ static void testCollectionStore(void)
store2 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
CERT_STORE_CREATE_NEW_FLAG, NULL);
/* Try adding a store to a non-collection store */
ret = CertAddStoreToCollection(store1, store2,
ret = pCertAddStoreToCollection(store1, store2,
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
ok(!ret && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %08x\n", GetLastError());
/* Try adding some bogus stores */
/* This crashes in Windows
ret = CertAddStoreToCollection(0, store2,
ret = pCertAddStoreToCollection(0, store2,
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
*/
/* This "succeeds"... */
ret = CertAddStoreToCollection(collection, 0,
ret = pCertAddStoreToCollection(collection, 0,
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
/* while this crashes.
ret = CertAddStoreToCollection(collection, 1,
ret = pCertAddStoreToCollection(collection, 1,
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
*/
/* Add it to the collection, this time allowing adding */
ret = CertAddStoreToCollection(collection, store2,
ret = pCertAddStoreToCollection(collection, store2,
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
/* Check that adding to the collection is allowed */
@ -397,7 +412,7 @@ static void testCollectionStore(void)
/* Adding a collection to a collection is legal */
collection2 = CertOpenStore(CERT_STORE_PROV_COLLECTION, 0, 0,
CERT_STORE_CREATE_NEW_FLAG, NULL);
ret = CertAddStoreToCollection(collection2, collection,
ret = pCertAddStoreToCollection(collection2, collection,
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
/* check the contents of collection2 */
@ -457,10 +472,10 @@ static void testCollectionStore(void)
CERT_STORE_CREATE_NEW_FLAG, NULL);
ok(collection != 0, "CertOpenStore failed: %08x\n", GetLastError());
ret = CertAddStoreToCollection(collection, store1,
ret = pCertAddStoreToCollection(collection, store1,
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
ret = CertAddStoreToCollection(collection, store2,
ret = pCertAddStoreToCollection(collection, store2,
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
@ -528,25 +543,32 @@ static void testCollectionStore(void)
ok(context == NULL, "Unexpected cert\n");
}
/* Finally, test removing stores from the collection. No return value, so
* it's a bit funny to test.
*/
/* This crashes
CertRemoveStoreFromCollection(NULL, NULL);
*/
/* This "succeeds," no crash, no last error set */
SetLastError(0xdeadbeef);
CertRemoveStoreFromCollection(store2, collection);
ok(GetLastError() == 0xdeadbeef,
"Didn't expect an error to be set: %08x\n", GetLastError());
if (!pCertRemoveStoreFromCollection)
{
skip("CertRemoveStoreFromCollection() is not available\n");
}
else
{
/* Finally, test removing stores from the collection. No return
* value, so it's a bit funny to test.
*/
/* This crashes
* pCertRemoveStoreFromCollection(NULL, NULL);
*/
/* This "succeeds," no crash, no last error set */
SetLastError(0xdeadbeef);
pCertRemoveStoreFromCollection(store2, collection);
ok(GetLastError() == 0xdeadbeef,
"Didn't expect an error to be set: %08x\n", GetLastError());
/* After removing store2, the collection should be empty */
SetLastError(0xdeadbeef);
CertRemoveStoreFromCollection(collection, store2);
ok(GetLastError() == 0xdeadbeef,
"Didn't expect an error to be set: %08x\n", GetLastError());
context = CertEnumCertificatesInStore(collection, NULL);
ok(!context, "Unexpected cert\n");
/* After removing store2, the collection should be empty */
SetLastError(0xdeadbeef);
pCertRemoveStoreFromCollection(collection, store2);
ok(GetLastError() == 0xdeadbeef,
"Didn't expect an error to be set: %08x\n", GetLastError());
context = CertEnumCertificatesInStore(collection, NULL);
ok(!context, "Unexpected cert\n");
}
CertCloseStore(collection, 0);
CertCloseStore(store2, 0);
@ -614,6 +636,13 @@ static void testRegStore(void)
todo_wine ok(store != 0, "CertOpenStore failed: %08x\n", GetLastError());
CertCloseStore(store, 0);
/* It looks like the remainder pretty much needs CertControlStore() */
if (!pCertControlStore)
{
skip("CertControlStore() is not available\n");
return;
}
rc = RegCreateKeyExA(HKEY_CURRENT_USER, tempKey, 0, NULL, 0, KEY_ALL_ACCESS,
NULL, &key, NULL);
ok(!rc, "RegCreateKeyExA failed: %d\n", rc);
@ -637,7 +666,7 @@ static void testRegStore(void)
ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
GetLastError());
/* so flush the cache to force a commit.. */
ret = CertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ret = pCertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ok(ret, "CertControlStore failed: %08x\n", GetLastError());
/* and check that the expected subkey was written. */
size = sizeof(hash);
@ -696,7 +725,7 @@ static void testRegStore(void)
ok(context != NULL, "Expected a cert context\n");
if (context)
CertDeleteCertificateFromStore(context);
ret = CertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ret = pCertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ok(ret, "CertControlStore failed: %08x\n", GetLastError());
/* Add a serialized cert with a bogus hash directly to the registry */
@ -733,7 +762,7 @@ static void testRegStore(void)
sizeof(buf));
ok(!rc, "RegSetValueExA failed: %d\n", rc);
ret = CertControlStore(store, 0, CERT_STORE_CTRL_RESYNC, NULL);
ret = pCertControlStore(store, 0, CERT_STORE_CTRL_RESYNC, NULL);
ok(ret, "CertControlStore failed: %08x\n", GetLastError());
/* Make sure the bogus hash cert gets loaded. */
@ -790,7 +819,7 @@ static void testRegStore(void)
sizeof(buf));
ok(!rc, "RegSetValueExA failed: %d\n", rc);
ret = CertControlStore(store, 0, CERT_STORE_CTRL_RESYNC, NULL);
ret = pCertControlStore(store, 0, CERT_STORE_CTRL_RESYNC, NULL);
ok(ret, "CertControlStore failed: %08x\n", GetLastError());
/* and make sure just one cert still gets loaded. */
@ -811,7 +840,7 @@ static void testRegStore(void)
sizeof(buf));
ok(!rc, "RegSetValueExA failed: %d\n", rc);
ret = CertControlStore(store, 0, CERT_STORE_CTRL_RESYNC, NULL);
ret = pCertControlStore(store, 0, CERT_STORE_CTRL_RESYNC, NULL);
ok(ret, "CertControlStore failed: %08x\n", GetLastError());
/* and make sure two certs get loaded. */
@ -893,10 +922,12 @@ static void testSystemRegStore(void)
CERT_STORE_CREATE_NEW_FLAG, NULL);
if (memStore)
{
BOOL ret = CertAddStoreToCollection(store, memStore, 0, 0);
ok(!ret && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %08x\n", GetLastError());
if (pCertAddStoreToCollection)
{
BOOL ret = pCertAddStoreToCollection(store, memStore, 0, 0);
ok(!ret && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %08x\n", GetLastError());
}
CertCloseStore(memStore, 0);
}
CertCloseStore(store, 0);
@ -984,10 +1015,12 @@ static void testSystemStore(void)
/* Check that it's a collection store */
if (memStore)
{
BOOL ret = CertAddStoreToCollection(store, memStore, 0, 0);
/* FIXME: this'll fail on NT4, but what error will it give? */
ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
if (pCertAddStoreToCollection)
{
BOOL ret = pCertAddStoreToCollection(store, memStore, 0, 0);
/* FIXME: this'll fail on NT4, but what error will it give? */
ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
}
CertCloseStore(memStore, 0);
}
CertCloseStore(store, 0);
@ -1073,7 +1106,13 @@ static void testFileStore(void)
BOOL ret;
PCCERT_CONTEXT cert;
HANDLE file;
if (!pCertControlStore)
{
skip("CertControlStore() is not available\n");
return;
}
store = CertOpenStore(CERT_STORE_PROV_FILE, 0, 0, 0, NULL);
ok(!store && GetLastError() == ERROR_INVALID_HANDLE,
"Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
@ -1109,7 +1148,7 @@ static void testFileStore(void)
/* apparently allows adding certificates.. */
ok(ret, "CertAddEncodedCertificateToStore failed: %d\n", ret);
/* but not commits.. */
ret = CertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ret = pCertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ok(!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED,
"Expected ERROR_CALL_NOT_IMPLEMENTED, got %08x\n", GetLastError());
/* It still has certs in memory.. */
@ -1133,7 +1172,7 @@ static void testFileStore(void)
ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
bigCert, sizeof(bigCert), CERT_STORE_ADD_ALWAYS, NULL);
ok(ret, "CertAddEncodedCertificateToStore failed: %d\n", ret);
ret = CertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ret = pCertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ok(!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED,
"Expected ERROR_CALL_NOT_IMPLEMENTED, got %08x\n", GetLastError());
CertCloseStore(store, 0);
@ -1148,7 +1187,7 @@ static void testFileStore(void)
ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
bigCert, sizeof(bigCert), CERT_STORE_ADD_ALWAYS, NULL);
ok(ret, "CertAddEncodedCertificateToStore failed: %d\n", ret);
ret = CertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ret = pCertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ok(!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED,
"Expected ERROR_CALL_NOT_IMPLEMENTED, got %08x\n", GetLastError());
CertCloseStore(store, 0);
@ -1164,7 +1203,7 @@ static void testFileStore(void)
ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
GetLastError());
/* with commits enabled, commit is allowed */
ret = CertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ret = pCertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ok(ret, "CertControlStore failed: %d\n", ret);
compareFile(filename, serializedStoreWithCert,
sizeof(serializedStoreWithCert));
@ -1248,8 +1287,11 @@ static void testFileNameStore(void)
GetLastError());
cert = CertEnumCertificatesInStore(store, cert);
ok(!cert, "Expected only one cert\n");
crl = CertEnumCRLsInStore(store, NULL);
ok(!crl, "Expected no CRLs\n");
if (pCertEnumCRLsInStore)
{
crl = pCertEnumCRLsInStore(store, NULL);
ok(!crl, "Expected no CRLs\n");
}
CertCloseStore(store, 0);
DeleteFileW(filename);
@ -1269,8 +1311,11 @@ static void testFileNameStore(void)
GetLastError());
cert = CertEnumCertificatesInStore(store, cert);
ok(!cert, "Expected only one cert\n");
crl = CertEnumCRLsInStore(store, NULL);
ok(!crl, "Expected no CRLs\n");
if (pCertEnumCRLsInStore)
{
crl = pCertEnumCRLsInStore(store, NULL);
ok(!crl, "Expected no CRLs\n");
}
CertCloseStore(store, 0);
DeleteFileW(filename);
@ -1290,10 +1335,13 @@ static void testFileNameStore(void)
GetLastError());
cert = CertEnumCertificatesInStore(store, cert);
ok(!cert, "Expected only one cert\n");
crl = CertEnumCRLsInStore(store, NULL);
ok(crl != NULL, "CertEnumCRLsInStore failed: %08x\n", GetLastError());
crl = CertEnumCRLsInStore(store, crl);
ok(!crl, "Expected only one CRL\n");
if (pCertEnumCRLsInStore)
{
crl = pCertEnumCRLsInStore(store, NULL);
ok(crl != NULL, "CertEnumCRLsInStore failed: %08x\n", GetLastError());
crl = pCertEnumCRLsInStore(store, crl);
ok(!crl, "Expected only one CRL\n");
}
CertCloseStore(store, 0);
/* Don't delete it this time, the next test uses it */
@ -1416,13 +1464,16 @@ static void testMessageStore(void)
} while (cert);
ok(count == 0, "Expected 0 certificates, got %d\n", count);
count = 0;
do {
crl = CertEnumCRLsInStore(store, crl);
if (crl)
count++;
} while (crl);
ok(count == 0, "Expected 0 CRLs, got %d\n", count);
if (pCertEnumCRLsInStore)
{
count = 0;
do {
crl = pCertEnumCRLsInStore(store, crl);
if (crl)
count++;
} while (crl);
ok(count == 0, "Expected 0 CRLs, got %d\n", count);
}
/* Can add certs to a message store */
ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
@ -1464,13 +1515,16 @@ static void testMessageStore(void)
} while (cert);
ok(count == 1, "Expected 1 certificate, got %d\n", count);
count = 0;
do {
crl = CertEnumCRLsInStore(store, crl);
if (crl)
count++;
} while (crl);
ok(count == 1, "Expected 1 CRL, got %d\n", count);
if (pCertEnumCRLsInStore)
{
count = 0;
do {
crl = pCertEnumCRLsInStore(store, crl);
if (crl)
count++;
} while (crl);
ok(count == 1, "Expected 1 CRL, got %d\n", count);
}
CertCloseStore(store, 0);
}
/* Encoding appears to be ignored */
@ -1534,17 +1588,23 @@ static void testCertEnumSystemStore(void)
BOOL ret;
struct EnumSystemStoreInfo info = { FALSE, 0 };
if (!pCertEnumSystemStore)
{
skip("CertEnumSystemStore() is not available\n");
return;
}
SetLastError(0xdeadbeef);
ret = CertEnumSystemStore(0, NULL, NULL, NULL);
ret = pCertEnumSystemStore(0, NULL, NULL, NULL);
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
"Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
/* Crashes
ret = CertEnumSystemStore(CERT_SYSTEM_STORE_LOCAL_MACHINE, NULL, NULL,
ret = pCertEnumSystemStore(CERT_SYSTEM_STORE_LOCAL_MACHINE, NULL, NULL,
NULL);
*/
SetLastError(0xdeadbeef);
ret = CertEnumSystemStore(CERT_SYSTEM_STORE_LOCAL_MACHINE, NULL, &info,
ret = pCertEnumSystemStore(CERT_SYSTEM_STORE_LOCAL_MACHINE, NULL, &info,
enumSystemStoreCB);
/* Callback returning FALSE stops enumeration */
ok(!ret, "Expected CertEnumSystemStore to stop\n");
@ -1553,7 +1613,7 @@ static void testCertEnumSystemStore(void)
info.goOn = TRUE;
info.storeCount = 0;
ret = CertEnumSystemStore(CERT_SYSTEM_STORE_LOCAL_MACHINE, NULL, &info,
ret = pCertEnumSystemStore(CERT_SYSTEM_STORE_LOCAL_MACHINE, NULL, &info,
enumSystemStoreCB);
ok(ret, "CertEnumSystemStore failed: %08x\n", GetLastError());
/* There should always be at least My, Root, and CA stores */
@ -1568,52 +1628,58 @@ static void testStoreProperty(void)
DWORD propID, size = 0, state;
CRYPT_DATA_BLOB blob;
if (!pCertGetStoreProperty || !pCertSetStoreProperty)
{
skip("CertGet/SetStoreProperty() is not available\n");
return;
}
/* Crash
ret = CertGetStoreProperty(NULL, 0, NULL, NULL);
ret = CertGetStoreProperty(NULL, 0, NULL, &size);
ret = CertGetStoreProperty(store, 0, NULL, NULL);
ret = pCertGetStoreProperty(NULL, 0, NULL, NULL);
ret = pCertGetStoreProperty(NULL, 0, NULL, &size);
ret = pCertGetStoreProperty(store, 0, NULL, NULL);
*/
store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
CERT_STORE_CREATE_NEW_FLAG, NULL);
/* Check a missing prop ID */
SetLastError(0xdeadbeef);
ret = CertGetStoreProperty(store, 0, NULL, &size);
ret = pCertGetStoreProperty(store, 0, NULL, &size);
ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
"Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
/* Contrary to MSDN, CERT_ACCESS_STATE_PROP_ID is supported for stores.. */
size = sizeof(state);
ret = CertGetStoreProperty(store, CERT_ACCESS_STATE_PROP_ID, &state, &size);
ret = pCertGetStoreProperty(store, CERT_ACCESS_STATE_PROP_ID, &state, &size);
ok(ret, "CertGetStoreProperty failed for CERT_ACCESS_STATE_PROP_ID: %08x\n",
GetLastError());
ok(!state, "Expected a non-persisted store\n");
/* and CERT_STORE_LOCALIZED_NAME_PROP_ID isn't supported by default. */
size = 0;
ret = CertGetStoreProperty(store, CERT_STORE_LOCALIZED_NAME_PROP_ID, NULL,
ret = pCertGetStoreProperty(store, CERT_STORE_LOCALIZED_NAME_PROP_ID, NULL,
&size);
ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
"Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
/* Delete an arbitrary property on a store */
ret = CertSetStoreProperty(store, CERT_FIRST_USER_PROP_ID, 0, NULL);
ret = pCertSetStoreProperty(store, CERT_FIRST_USER_PROP_ID, 0, NULL);
ok(ret, "CertSetStoreProperty failed: %08x\n", GetLastError());
/* Set an arbitrary property on a store */
blob.pbData = (LPBYTE)&state;
blob.cbData = sizeof(state);
ret = CertSetStoreProperty(store, CERT_FIRST_USER_PROP_ID, 0, &blob);
ret = pCertSetStoreProperty(store, CERT_FIRST_USER_PROP_ID, 0, &blob);
ok(ret, "CertSetStoreProperty failed: %08x\n", GetLastError());
/* Get an arbitrary property that's been set */
ret = CertGetStoreProperty(store, CERT_FIRST_USER_PROP_ID, NULL, &size);
ret = pCertGetStoreProperty(store, CERT_FIRST_USER_PROP_ID, NULL, &size);
ok(ret, "CertGetStoreProperty failed: %08x\n", GetLastError());
ok(size == sizeof(state), "Unexpected data size %d\n", size);
ret = CertGetStoreProperty(store, CERT_FIRST_USER_PROP_ID, &propID, &size);
ret = pCertGetStoreProperty(store, CERT_FIRST_USER_PROP_ID, &propID, &size);
ok(ret, "CertGetStoreProperty failed: %08x\n", GetLastError());
ok(propID == state, "CertGetStoreProperty got the wrong value\n");
/* Delete it again */
ret = CertSetStoreProperty(store, CERT_FIRST_USER_PROP_ID, 0, NULL);
ret = pCertSetStoreProperty(store, CERT_FIRST_USER_PROP_ID, 0, NULL);
ok(ret, "CertSetStoreProperty failed: %08x\n", GetLastError());
/* And check that it's missing */
SetLastError(0xdeadbeef);
ret = CertGetStoreProperty(store, CERT_FIRST_USER_PROP_ID, NULL, &size);
ret = pCertGetStoreProperty(store, CERT_FIRST_USER_PROP_ID, NULL, &size);
ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
"Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
CertCloseStore(store, 0);
@ -1621,13 +1687,13 @@ static void testStoreProperty(void)
/* Recheck on the My store.. */
store = CertOpenSystemStoreW(0, MyW);
size = sizeof(state);
ret = CertGetStoreProperty(store, CERT_ACCESS_STATE_PROP_ID, &state, &size);
ret = pCertGetStoreProperty(store, CERT_ACCESS_STATE_PROP_ID, &state, &size);
ok(ret, "CertGetStoreProperty failed for CERT_ACCESS_STATE_PROP_ID: %08x\n",
GetLastError());
ok(state, "Expected a persisted store\n");
SetLastError(0xdeadbeef);
size = 0;
ret = CertGetStoreProperty(store, CERT_STORE_LOCALIZED_NAME_PROP_ID, NULL,
ret = pCertGetStoreProperty(store, CERT_STORE_LOCALIZED_NAME_PROP_ID, NULL,
&size);
ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
"Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
@ -1807,7 +1873,7 @@ static DWORD countCRLsInStore(HCERTSTORE store)
DWORD crls = 0;
do {
crl = CertEnumCRLsInStore(store, crl);
crl = pCertEnumCRLsInStore(store, crl);
if (crl)
crls++;
} while (crl);
@ -1869,8 +1935,11 @@ static void test_I_UpdateStore(void)
ok(ret, "I_CertUpdateStore failed: %08x\n", GetLastError());
certs = countCertsInStore(store1);
ok(certs == 1, "Expected 1 cert, got %d\n", certs);
certs = countCRLsInStore(store1);
ok(certs == 1, "Expected 1 CRL, got %d\n", certs);
if (pCertEnumCRLsInStore)
{
certs = countCRLsInStore(store1);
ok(certs == 1, "Expected 1 CRL, got %d\n", certs);
}
CertDeleteCertificateFromStore(cert);
/* If a context is deleted from store2, I_CertUpdateStore delets it
@ -1888,6 +1957,17 @@ static void test_I_UpdateStore(void)
START_TEST(store)
{
HMODULE hdll;
hdll = GetModuleHandleA("Crypt32.dll");
pCertAddStoreToCollection = (void*)GetProcAddress(hdll, "CertAddStoreToCollection");
pCertControlStore = (void*)GetProcAddress(hdll, "CertControlStore");
pCertEnumCRLsInStore = (void*)GetProcAddress(hdll, "CertEnumCRLsInStore");
pCertEnumSystemStore = (void*)GetProcAddress(hdll, "CertEnumSystemStore");
pCertGetStoreProperty = (void*)GetProcAddress(hdll, "CertGetStoreProperty");
pCertRemoveStoreFromCollection = (void*)GetProcAddress(hdll, "CertRemoveStoreFromCollection");
pCertSetStoreProperty = (void*)GetProcAddress(hdll, "CertSetStoreProperty");
/* various combinations of CertOpenStore */
testMemStore();
testCollectionStore();