Commit c69d47fa authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

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

parent 10e738f2
......@@ -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);
......
......@@ -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();
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment