Module: wine Branch: master Commit: 31bcb3f6f4b6974062cf271bec24ecc0fc6a80b5 URL: http://source.winehq.org/git/wine.git/?a=commit;h=31bcb3f6f4b6974062cf271bec...
Author: Francois Gouget fgouget@free.fr Date: Tue Dec 18 10:00:10 2007 +0100
secur32/tests: Dynamically load various APIs and don't link with crypt32.dll to make the test run on Windows 95.
---
dlls/secur32/tests/Makefile.in | 2 +- dlls/secur32/tests/schannel.c | 90 ++++++++++++++++++++++++++++------------ 2 files changed, 64 insertions(+), 28 deletions(-)
diff --git a/dlls/secur32/tests/Makefile.in b/dlls/secur32/tests/Makefile.in index 45cfeab..0053d73 100644 --- a/dlls/secur32/tests/Makefile.in +++ b/dlls/secur32/tests/Makefile.in @@ -3,7 +3,7 @@ TOPOBJDIR = ../../.. SRCDIR = @srcdir@ VPATH = @srcdir@ TESTDLL = secur32.dll -IMPORTS = crypt32 advapi32 kernel32 +IMPORTS = advapi32 kernel32
CTESTS = \ main.c \ diff --git a/dlls/secur32/tests/schannel.c b/dlls/secur32/tests/schannel.c index 785ad26..3d3eb7f 100644 --- a/dlls/secur32/tests/schannel.c +++ b/dlls/secur32/tests/schannel.c @@ -27,12 +27,18 @@
#include "wine/test.h"
-static HMODULE secdll; +static HMODULE secdll, crypt32dll; static SECURITY_STATUS (SEC_ENTRY * pAcquireCredentialsHandleA)(SEC_CHAR*, SEC_CHAR*, ULONG, PLUID, PVOID, SEC_GET_KEY_FN, PVOID, PCredHandle, PTimeStamp); +static PCCERT_CONTEXT (WINAPI *pCertCreateCertificateContext)(DWORD,const BYTE*,DWORD); +static BOOL (WINAPI *pCertFreeCertificateContext)(PCCERT_CONTEXT); +static BOOL (WINAPI *pCertSetCertificateContextProperty)(PCCERT_CONTEXT,DWORD,DWORD,const void*); static SECURITY_STATUS (SEC_ENTRY * pFreeCredentialsHandle)(PCredHandle);
static BOOL (WINAPI * pCryptAcquireContextW)(HCRYPTPROV*, LPCWSTR, LPCWSTR, DWORD, DWORD); +static BOOL (WINAPI *pCryptDestroyKey)(HCRYPTKEY); +static BOOL (WINAPI *pCryptImportKey)(HCRYPTPROV,CONST BYTE*,DWORD,HCRYPTKEY,DWORD,HCRYPTKEY*); +static BOOL (WINAPI *pCryptReleaseContext)(HCRYPTPROV,ULONG_PTR);
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, @@ -100,17 +106,29 @@ static const BYTE selfSignedCert[] = { static void InitFunctionPtrs(void) { HMODULE advapi32dll = GetModuleHandleA("advapi32.dll"); + HMODULE crypt32dll = LoadLibraryA("crypt32.dll");
secdll = LoadLibraryA("secur32.dll"); if(!secdll) secdll = LoadLibraryA("security.dll"); + +#define GET_PROC(h, func) p ## func = (void*)GetProcAddress(h, #func) + if(secdll) { - pAcquireCredentialsHandleA = (PVOID)GetProcAddress(secdll, "AcquireCredentialsHandleA"); - pFreeCredentialsHandle = (PVOID)GetProcAddress(secdll, "FreeCredentialsHandle"); + GET_PROC(secdll, AcquireCredentialsHandleA); + GET_PROC(secdll, FreeCredentialsHandle); }
- pCryptAcquireContextW = (void *)GetProcAddress(advapi32dll, "CryptAcquireContextW"); + GET_PROC(advapi32dll, CryptAcquireContextW); + GET_PROC(advapi32dll, CryptDestroyKey); + GET_PROC(advapi32dll, CryptImportKey); + GET_PROC(advapi32dll, CryptReleaseContext); + + GET_PROC(crypt32dll, CertFreeCertificateContext); + GET_PROC(crypt32dll, CertSetCertificateContextProperty); + +#undef GET_PROC }
static void testAcquireSecurityContext(void) @@ -127,6 +145,13 @@ static void testAcquireSecurityContext(void) HCRYPTKEY key; CRYPT_KEY_PROV_INFO keyProvInfo;
+ if (!pAcquireCredentialsHandleA || !pCertCreateCertificateContext || + !pFreeCredentialsHandle || !pCryptAcquireContextW) + { + skip("Needed functions are not available\n"); + return; + } + lstrcpyW(ms_def_prov_w, MS_DEF_PROV_W);
keyProvInfo.pwszContainerName = cspNameW; @@ -137,9 +162,9 @@ static void testAcquireSecurityContext(void) keyProvInfo.rgProvParam = NULL; keyProvInfo.dwKeySpec = AT_SIGNATURE;
- certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert, + certs[0] = pCertCreateCertificateContext(X509_ASN_ENCODING, bigCert, sizeof(bigCert)); - certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING, selfSignedCert, + certs[1] = pCertCreateCertificateContext(X509_ASN_ENCODING, selfSignedCert, sizeof(selfSignedCert));
pCryptAcquireContextW(&csp, cspNameW, MS_DEF_PROV_W, PROV_RSA_FULL, @@ -247,23 +272,30 @@ static void testAcquireSecurityContext(void) st);
/* Good cert, with CRYPT_KEY_PROV_INFO set before it's had a key loaded. */ - ret = CertSetCertificateContextProperty(certs[1], - CERT_KEY_PROV_INFO_PROP_ID, 0, &keyProvInfo); - schanCred.dwVersion = SCH_CRED_V3; - st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND, - NULL, &schanCred, NULL, NULL, &cred, NULL); - ok(st == SEC_E_UNKNOWN_CREDENTIALS, - "Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st); - st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND, - NULL, &schanCred, NULL, NULL, &cred, NULL); - ok(st == SEC_E_UNKNOWN_CREDENTIALS, - "Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st); + if (pCertSetCertificateContextProperty) + { + ret = pCertSetCertificateContextProperty(certs[1], + CERT_KEY_PROV_INFO_PROP_ID, 0, &keyProvInfo); + schanCred.dwVersion = SCH_CRED_V3; + st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_OUTBOUND, + NULL, &schanCred, NULL, NULL, &cred, NULL); + ok(st == SEC_E_UNKNOWN_CREDENTIALS, + "Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st); + st = pAcquireCredentialsHandleA(NULL, unisp_name_a, SECPKG_CRED_INBOUND, + NULL, &schanCred, NULL, NULL, &cred, NULL); + ok(st == SEC_E_UNKNOWN_CREDENTIALS, + "Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st); + }
ret = pCryptAcquireContextW(&csp, cspNameW, MS_DEF_PROV_W, PROV_RSA_FULL, CRYPT_NEWKEYSET); ok(ret, "CryptAcquireContextW failed: %08x\n", GetLastError()); - ret = CryptImportKey(csp, privKey, sizeof(privKey), 0, 0, &key); - ok(ret, "CryptImportKey failed: %08x\n", GetLastError()); + ret = 0; + if (pCryptImportKey) + { + ret = pCryptImportKey(csp, privKey, sizeof(privKey), 0, 0, &key); + ok(ret, "CryptImportKey failed: %08x\n", GetLastError()); + } if (ret) { PCCERT_CONTEXT tmp; @@ -338,26 +370,30 @@ static void testAcquireSecurityContext(void) "Expected SEC_E_UNKNOWN_CREDENTIALS, got %08x\n", st); /* FIXME: what about two valid certs? */
- CryptDestroyKey(key); + if (pCryptDestroyKey) + pCryptDestroyKey(key); }
- CryptReleaseContext(csp, 0); + if (pCryptReleaseContext) + pCryptReleaseContext(csp, 0); pCryptAcquireContextW(&csp, cspNameW, MS_DEF_PROV_W, PROV_RSA_FULL, CRYPT_DELETEKEYSET);
- CertFreeCertificateContext(certs[0]); - CertFreeCertificateContext(certs[1]); + if (pCertFreeCertificateContext) + { + pCertFreeCertificateContext(certs[0]); + pCertFreeCertificateContext(certs[1]); + } }
START_TEST(schannel) { InitFunctionPtrs();
- if (pAcquireCredentialsHandleA && pFreeCredentialsHandle && pCryptAcquireContextW) - testAcquireSecurityContext(); - else - skip("Needed functions are not available\n"); + testAcquireSecurityContext();
if(secdll) FreeLibrary(secdll); + if(crypt32dll) + FreeLibrary(crypt32dll); }