shell32: Fix descriptions being applied to wrong entries in control panel.
[wine/multimedia.git] / dlls / crypt32 / tests / oid.c
blob0ec6c298caa6705de10ade3983e77b0ad27847e7
1 /*
2 * Unit test suite for crypt32.dll's OID support functions.
4 * Copyright 2005 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdio.h>
21 #include <stdarg.h>
22 #include <windef.h>
23 #include <winbase.h>
24 #include <winerror.h>
25 #include <wincrypt.h>
26 #include <winreg.h>
28 #include "wine/test.h"
31 static BOOL (WINAPI *pCryptEnumOIDInfo)(DWORD,DWORD,void*,PFN_CRYPT_ENUM_OID_INFO);
34 struct OIDToAlgID
36 LPCSTR oid;
37 DWORD algID;
40 static const struct OIDToAlgID oidToAlgID[] = {
41 { szOID_RSA_RSA, CALG_RSA_KEYX },
42 { szOID_RSA_MD2RSA, CALG_MD2 },
43 { szOID_RSA_MD4RSA, CALG_MD4 },
44 { szOID_RSA_MD5RSA, CALG_MD5 },
45 { szOID_RSA_SHA1RSA, CALG_SHA },
46 { szOID_RSA_DH, CALG_DH_SF },
47 { szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM },
48 { szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES },
49 { szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2 },
50 { szOID_RSA_MD2, CALG_MD2 },
51 { szOID_RSA_MD4, CALG_MD4 },
52 { szOID_RSA_MD5, CALG_MD5 },
53 { szOID_RSA_RC2CBC, CALG_RC2 },
54 { szOID_RSA_RC4, CALG_RC4 },
55 { szOID_RSA_DES_EDE3_CBC, CALG_3DES },
56 { szOID_ANSI_X942_DH, CALG_DH_SF },
57 { szOID_X957_DSA, CALG_DSS_SIGN },
58 { szOID_X957_SHA1DSA, CALG_SHA },
59 { szOID_OIWSEC_md4RSA, CALG_MD4 },
60 { szOID_OIWSEC_md5RSA, CALG_MD5 },
61 { szOID_OIWSEC_md4RSA2, CALG_MD4 },
62 { szOID_OIWSEC_desCBC, CALG_DES },
63 { szOID_OIWSEC_dsa, CALG_DSS_SIGN },
64 { szOID_OIWSEC_shaDSA, CALG_SHA },
65 { szOID_OIWSEC_shaRSA, CALG_SHA },
66 { szOID_OIWSEC_sha, CALG_SHA },
67 { szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX },
68 { szOID_OIWSEC_sha1, CALG_SHA },
69 { szOID_OIWSEC_dsaSHA1, CALG_SHA },
70 { szOID_OIWSEC_sha1RSASign, CALG_SHA },
71 { szOID_OIWDIR_md2RSA, CALG_MD2 },
72 { szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA },
73 { szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN },
76 static const struct OIDToAlgID algIDToOID[] = {
77 { szOID_RSA_RSA, CALG_RSA_KEYX },
78 { szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM },
79 { szOID_RSA_MD2, CALG_MD2 },
80 { szOID_RSA_MD4, CALG_MD4 },
81 { szOID_RSA_MD5, CALG_MD5 },
82 { szOID_RSA_RC2CBC, CALG_RC2 },
83 { szOID_RSA_RC4, CALG_RC4 },
84 { szOID_RSA_DES_EDE3_CBC, CALG_3DES },
85 { szOID_ANSI_X942_DH, CALG_DH_SF },
86 { szOID_X957_DSA, CALG_DSS_SIGN },
87 { szOID_OIWSEC_desCBC, CALG_DES },
88 { szOID_OIWSEC_sha1, CALG_SHA },
91 static const WCHAR bogusDll[] = { 'b','o','g','u','s','.','d','l','l',0 };
92 static const WCHAR bogus2Dll[] = { 'b','o','g','u','s','2','.','d','l','l',0 };
94 static void testOIDToAlgID(void)
96 int i;
97 DWORD alg;
99 /* Test with a bogus one */
100 SetLastError(0xdeadbeef);
101 alg = CertOIDToAlgId("1.2.3");
102 ok(!alg, "Expected failure, got %d\n", alg);
103 ok(GetLastError() == 0xdeadbeef ||
104 GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND ||
105 GetLastError() == ERROR_SUCCESS, /* win2k */
106 "Expected ERROR_RESOURCE_NAME_NOT_FOUND, ERROR_SUCCESS "
107 "or no error set, got %08x\n", GetLastError());
109 for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++)
111 alg = CertOIDToAlgId(oidToAlgID[i].oid);
112 /* Not all Windows installations support all these, so make sure it's
113 * at least not the wrong one.
115 ok(alg == 0 || alg == oidToAlgID[i].algID,
116 "Expected %d, got %d\n", oidToAlgID[i].algID, alg);
120 static void testAlgIDToOID(void)
122 int i;
123 LPCSTR oid;
125 /* Test with a bogus one */
126 SetLastError(0xdeadbeef);
127 oid = CertAlgIdToOID(ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | 80);
128 ok(!oid && GetLastError() == 0xdeadbeef,
129 "Didn't expect last error (%08x) to be set\n", GetLastError());
130 for (i = 0; i < sizeof(algIDToOID) / sizeof(algIDToOID[0]); i++)
132 oid = CertAlgIdToOID(algIDToOID[i].algID);
133 /* Allow failure, not every version of Windows supports every algo */
134 if (oid)
135 ok(!strcmp(oid, algIDToOID[i].oid),
136 "Expected %s, got %s\n", algIDToOID[i].oid, oid);
140 static void test_oidFunctionSet(void)
142 HCRYPTOIDFUNCSET set1, set2;
143 BOOL ret;
144 LPWSTR buf = NULL;
145 DWORD size;
147 /* This crashes
148 set = CryptInitOIDFunctionSet(NULL, 0);
151 /* The name doesn't mean much */
152 set1 = CryptInitOIDFunctionSet("funky", 0);
153 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
154 if (set1)
156 /* These crash
157 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
158 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
160 size = 0;
161 ret = CryptGetDefaultOIDDllList(set1, 0, NULL, &size);
162 ok(ret, "CryptGetDefaultOIDDllList failed: %08x\n", GetLastError());
163 if (ret)
165 buf = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
166 if (buf)
168 ret = CryptGetDefaultOIDDllList(set1, 0, buf, &size);
169 ok(ret, "CryptGetDefaultOIDDllList failed: %08x\n",
170 GetLastError());
171 ok(!*buf, "Expected empty DLL list\n");
172 HeapFree(GetProcessHeap(), 0, buf);
177 /* MSDN says flags must be 0, but it's not checked */
178 set1 = CryptInitOIDFunctionSet("", 1);
179 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
180 set2 = CryptInitOIDFunctionSet("", 0);
181 ok(set2 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
182 /* There isn't a free function, so there must be only one set per name to
183 * limit leaks. (I guess the sets are freed when crypt32 is unloaded.)
185 ok(set1 == set2, "Expected identical sets\n");
186 if (set1)
188 /* The empty name function set used here seems to correspond to
189 * DEFAULT.
193 /* There's no installed function for a built-in encoding. */
194 set1 = CryptInitOIDFunctionSet("CryptDllEncodeObject", 0);
195 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
196 if (set1)
198 void *funcAddr;
199 HCRYPTOIDFUNCADDR hFuncAddr;
201 ret = CryptGetOIDFunctionAddress(set1, X509_ASN_ENCODING, X509_CERT, 0,
202 &funcAddr, &hFuncAddr);
203 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
204 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
208 typedef int (*funcY)(int);
210 static int funky(int x)
212 return x;
215 static void test_installOIDFunctionAddress(void)
217 BOOL ret;
218 CRYPT_OID_FUNC_ENTRY entry = { CRYPT_DEFAULT_OID, funky };
219 HCRYPTOIDFUNCSET set;
221 /* This crashes
222 ret = CryptInstallOIDFunctionAddress(NULL, 0, NULL, 0, NULL, 0);
225 /* Installing zero functions should work */
226 SetLastError(0xdeadbeef);
227 ret = CryptInstallOIDFunctionAddress(NULL, 0, "CryptDllEncodeObject", 0,
228 NULL, 0);
229 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
230 GetLastError());
232 /* The function name doesn't much matter */
233 SetLastError(0xdeadbeef);
234 ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 0, NULL, 0);
235 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
236 GetLastError());
237 SetLastError(0xdeadbeef);
238 entry.pszOID = X509_CERT;
239 ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 1, &entry, 0);
240 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
241 GetLastError());
242 set = CryptInitOIDFunctionSet("OhSoFunky", 0);
243 ok(set != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
244 if (set)
246 funcY funcAddr = NULL;
247 HCRYPTOIDFUNCADDR hFuncAddr = NULL;
249 /* This crashes
250 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, NULL,
251 NULL);
253 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0,
254 (void **)&funcAddr, &hFuncAddr);
255 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
256 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
257 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, X509_CERT, 0,
258 (void **)&funcAddr, &hFuncAddr);
259 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
260 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
261 ret = CryptGetOIDFunctionAddress(set, 0, X509_CERT, 0,
262 (void **)&funcAddr, &hFuncAddr);
263 ok(ret, "CryptGetOIDFunctionAddress failed: %d\n", GetLastError());
264 if (funcAddr)
266 int y = funcAddr(0xabadc0da);
268 ok(y == 0xabadc0da, "Unexpected return (%d) from function\n", y);
269 CryptFreeOIDFunctionAddress(hFuncAddr, 0);
274 static void test_registerOIDFunction(void)
276 BOOL ret;
278 /* oddly, this succeeds under WinXP; the function name key is merely
279 * omitted. This may be a side effect of the registry code, I don't know.
280 * I don't check it because I doubt anyone would depend on it.
281 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
282 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
284 /* On windows XP, GetLastError is incorrectly being set with an HRESULT,
285 * E_INVALIDARG
287 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "foo", NULL, bogusDll,
288 NULL);
289 ok(!ret && GetLastError() == E_INVALIDARG,
290 "Expected E_INVALIDARG: %d\n", GetLastError());
291 /* This has no effect, but "succeeds" on XP */
292 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "foo",
293 "1.2.3.4.5.6.7.8.9.10", NULL, NULL);
294 ok(ret, "Expected pseudo-success, got %d\n", GetLastError());
295 SetLastError(0xdeadbeef);
296 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
297 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
298 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
300 skip("Need admin rights\n");
301 return;
303 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
304 ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
305 "1.2.3.4.5.6.7.8.9.10");
306 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
307 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "bogus",
308 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
309 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
310 ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "bogus",
311 "1.2.3.4.5.6.7.8.9.10");
312 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
313 /* Unwanted Cryptography\OID\EncodingType 1\bogus\ will still be there */
314 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
315 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 1\\bogus"),
316 "Could not delete bogus key\n");
317 /* Shouldn't have effect but registry keys are created */
318 ret = CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
319 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
320 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
321 ret = CryptUnregisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
322 "1.2.3.4.5.6.7.8.9.10");
323 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
324 /* Check with bogus encoding type. Registry keys are still created */
325 ret = CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
326 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
327 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
328 ret = CryptUnregisterOIDFunction(0, "CryptDllEncodeObject",
329 "1.2.3.4.5.6.7.8.9.10");
330 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
331 /* Unwanted Cryptography\OID\EncodingType 0\CryptDllEncodeObject\
332 * will still be there
334 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
335 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllEncodeObject"),
336 "Could not delete CryptDllEncodeObject key\n");
337 /* This is written with value 3 verbatim. Thus, the encoding type isn't
338 * (for now) treated as a mask. Registry keys are created.
340 ret = CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
341 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
342 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
343 ret = CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
344 "1.2.3.4.5.6.7.8.9.10");
345 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
346 /* Unwanted Cryptography\OID\EncodingType 3\CryptDllEncodeObject
347 * will still be there.
349 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
350 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3\\CryptDllEncodeObject"),
351 "Could not delete CryptDllEncodeObject key\n");
352 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
353 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3"),
354 "Could not delete 'EncodingType 3' key\n");
357 static void test_registerDefaultOIDFunction(void)
359 static const char fmt[] =
360 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\DEFAULT";
361 static const char func[] = "CertDllOpenStoreProv";
362 char buf[MAX_PATH];
363 BOOL ret;
364 long rc;
365 HKEY key;
367 ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, NULL);
368 ok(!ret && GetLastError() == E_INVALIDARG,
369 "Expected E_INVALIDARG, got %08x\n", GetLastError());
370 /* This succeeds on WinXP, although the bogus entry is unusable.
371 ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, bogusDll);
373 /* Register one at index 0 */
374 SetLastError(0xdeadbeef);
375 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
376 bogusDll);
377 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
379 skip("Need admin rights\n");
380 return;
382 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
383 /* Reregistering should fail */
384 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
385 bogusDll);
386 ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
387 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
388 /* Registering the same one at index 1 should also fail */
389 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
390 bogusDll);
391 ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
392 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
393 /* Registering a different one at index 1 succeeds */
394 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
395 bogus2Dll);
396 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
397 sprintf(buf, fmt, 0, func);
398 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, buf, &key);
399 ok(rc == 0, "Expected key to exist, RegOpenKeyA failed: %ld\n", rc);
400 if (rc == 0)
402 static const CHAR dllA[] = "Dll";
403 static const CHAR bogusDll_A[] = "bogus.dll";
404 static const CHAR bogus2Dll_A[] = "bogus2.dll";
405 CHAR dllBuf[MAX_PATH];
406 DWORD type, size;
407 LPSTR ptr;
409 size = sizeof(dllBuf) / sizeof(dllBuf[0]);
410 rc = RegQueryValueExA(key, dllA, NULL, &type, (LPBYTE)dllBuf, &size);
411 ok(rc == 0,
412 "Expected Dll value to exist, RegQueryValueExA failed: %ld\n", rc);
413 ok(type == REG_MULTI_SZ, "Expected type REG_MULTI_SZ, got %d\n", type);
414 /* bogusDll was registered first, so that should be first */
415 ptr = dllBuf;
416 ok(!lstrcmpiA(ptr, bogusDll_A), "Unexpected dll\n");
417 ptr += lstrlenA(ptr) + 1;
418 ok(!lstrcmpiA(ptr, bogus2Dll_A), "Unexpected dll\n");
419 RegCloseKey(key);
421 /* Unregister both of them */
422 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
423 bogusDll);
424 ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
425 GetLastError());
426 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
427 bogus2Dll);
428 ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
429 GetLastError());
430 /* Now that they're both unregistered, unregistering should fail */
431 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
432 bogusDll);
433 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
434 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
436 /* Repeat a few tests on the normal encoding type */
437 ret = CryptRegisterDefaultOIDFunction(X509_ASN_ENCODING,
438 "CertDllOpenStoreProv", 0, bogusDll);
439 ret = CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING,
440 "CertDllOpenStoreProv", bogusDll);
441 ok(ret, "CryptUnregisterDefaultOIDFunction failed\n");
442 ret = CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING,
443 "CertDllOpenStoreProv", bogusDll);
444 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
445 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
448 static void test_getDefaultOIDFunctionAddress(void)
450 BOOL ret;
451 HCRYPTOIDFUNCSET set;
452 void *funcAddr;
453 HCRYPTOIDFUNCADDR hFuncAddr;
455 /* Crash
456 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, NULL);
457 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr, NULL);
458 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, &hFuncAddr);
459 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr,
460 &hFuncAddr);
462 set = CryptInitOIDFunctionSet("CertDllOpenStoreProv", 0);
463 ok(set != 0, "CryptInitOIDFunctionSet failed: %d\n", GetLastError());
464 /* This crashes if hFuncAddr is not 0 to begin with */
465 hFuncAddr = 0;
466 ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
467 &hFuncAddr);
468 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
469 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
470 /* This fails with the normal encoding too, so built-in functions aren't
471 * returned.
473 ret = CryptGetDefaultOIDFunctionAddress(set, X509_ASN_ENCODING, NULL, 0,
474 &funcAddr, &hFuncAddr);
475 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
476 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
478 /* Even with a registered dll, this fails (since the dll doesn't exist) */
479 SetLastError(0xdeadbeef);
480 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
481 bogusDll);
482 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
483 skip("Need admin rights\n");
484 else
485 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
486 ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
487 &hFuncAddr);
488 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
489 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
490 CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv", bogusDll);
493 static BOOL WINAPI countOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
495 (*(DWORD *)pvArg)++;
496 return TRUE;
499 static BOOL WINAPI noOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
501 return FALSE;
504 static void test_enumOIDInfo(void)
506 BOOL ret;
507 DWORD count = 0;
509 if (!pCryptEnumOIDInfo)
511 skip("CryptEnumOIDInfo() is not available\n");
512 return;
515 /* This crashes
516 ret = pCryptEnumOIDInfo(7, 0, NULL, NULL);
519 /* Silly tests, check that more than one thing is enumerated */
520 ret = pCryptEnumOIDInfo(0, 0, &count, countOidInfo);
521 ok(ret && count > 0, "Expected more than item enumerated\n");
522 ret = pCryptEnumOIDInfo(0, 0, NULL, noOidInfo);
523 ok(!ret, "Expected FALSE\n");
526 static void test_findOIDInfo(void)
528 static WCHAR sha1[] = { 's','h','a','1',0 };
529 static CHAR oid_rsa_md5[] = szOID_RSA_MD5;
530 ALG_ID alg = CALG_SHA1;
531 ALG_ID algs[2] = { CALG_MD5, CALG_RSA_SIGN };
532 PCCRYPT_OID_INFO info;
534 info = CryptFindOIDInfo(0, NULL, 0);
535 ok(info == NULL, "Expected NULL\n");
536 info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_rsa_md5, 0);
537 ok(info != NULL, "Expected to find szOID_RSA_MD5\n");
538 if (info)
540 ok(!strcmp(info->pszOID, szOID_RSA_MD5), "Expected %s, got %s\n",
541 szOID_RSA_MD5, info->pszOID);
542 ok(U(*info).Algid == CALG_MD5, "Expected CALG_MD5, got %d\n",
543 U(*info).Algid);
545 info = CryptFindOIDInfo(CRYPT_OID_INFO_NAME_KEY, sha1, 0);
546 ok(info != NULL, "Expected to find sha1\n");
547 if (info)
549 ok(!strcmp(info->pszOID, szOID_OIWSEC_sha1), "Expected %s, got %s\n",
550 szOID_OIWSEC_sha1, info->pszOID);
551 ok(U(*info).Algid == CALG_SHA1, "Expected CALG_SHA1, got %d\n",
552 U(*info).Algid);
554 info = CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY, &alg, 0);
555 ok(info != NULL, "Expected to find sha1\n");
556 if (info)
558 ok(!strcmp(info->pszOID, szOID_OIWSEC_sha1), "Expected %s, got %s\n",
559 szOID_OIWSEC_sha1, info->pszOID);
560 ok(U(*info).Algid == CALG_SHA1, "Expected CALG_SHA1, got %d\n",
561 U(*info).Algid);
563 info = CryptFindOIDInfo(CRYPT_OID_INFO_SIGN_KEY, algs, 0);
564 ok(info != NULL, "Expected to find md5RSA\n");
565 if (info)
567 ok(!strcmp(info->pszOID, szOID_RSA_MD5RSA), "Expected %s, got %s\n",
568 szOID_RSA_MD5RSA, info->pszOID);
569 ok(U(*info).Algid == CALG_MD5, "Expected CALG_MD5, got %d\n",
570 U(*info).Algid);
574 START_TEST(oid)
576 HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
577 pCryptEnumOIDInfo = (void*)GetProcAddress(hCrypt32, "CryptEnumOIDInfo");
579 testOIDToAlgID();
580 testAlgIDToOID();
581 test_enumOIDInfo();
582 test_findOIDInfo();
583 test_oidFunctionSet();
584 test_installOIDFunctionAddress();
585 test_registerOIDFunction();
586 test_registerDefaultOIDFunction();
587 test_getDefaultOIDFunctionAddress();