push 297972334720102b8c295c34d3cd5b0b9aafc558
[wine/hacks.git] / dlls / crypt32 / tests / oid.c
blob9b50129fd1dfd6ab8b3b2248a780a9a5eee3c363
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 LPCSTR altOid;
38 DWORD algID;
41 static const struct OIDToAlgID oidToAlgID[] = {
42 { szOID_RSA_RSA, NULL, CALG_RSA_KEYX },
43 { szOID_RSA_MD2RSA, NULL, CALG_MD2 },
44 { szOID_RSA_MD4RSA, NULL, CALG_MD4 },
45 { szOID_RSA_MD5RSA, NULL, CALG_MD5 },
46 { szOID_RSA_SHA1RSA, NULL, CALG_SHA },
47 { szOID_RSA_DH, NULL, CALG_DH_SF },
48 { szOID_RSA_SMIMEalgESDH, NULL, CALG_DH_EPHEM },
49 { szOID_RSA_SMIMEalgCMS3DESwrap, NULL, CALG_3DES },
50 { szOID_RSA_SMIMEalgCMSRC2wrap, NULL, CALG_RC2 },
51 { szOID_RSA_MD2, NULL, CALG_MD2 },
52 { szOID_RSA_MD4, NULL, CALG_MD4 },
53 { szOID_RSA_MD5, NULL, CALG_MD5 },
54 { szOID_RSA_RC2CBC, NULL, CALG_RC2 },
55 { szOID_RSA_RC4, NULL, CALG_RC4 },
56 { szOID_RSA_DES_EDE3_CBC, NULL, CALG_3DES },
57 { szOID_ANSI_X942_DH, NULL, CALG_DH_SF },
58 { szOID_X957_DSA, NULL, CALG_DSS_SIGN },
59 { szOID_X957_SHA1DSA, NULL, CALG_SHA },
60 { szOID_OIWSEC_md4RSA, NULL, CALG_MD4 },
61 { szOID_OIWSEC_md5RSA, NULL, CALG_MD5 },
62 { szOID_OIWSEC_md4RSA2, NULL, CALG_MD4 },
63 { szOID_OIWSEC_desCBC, NULL, CALG_DES },
64 { szOID_OIWSEC_dsa, NULL, CALG_DSS_SIGN },
65 { szOID_OIWSEC_shaDSA, NULL, CALG_SHA },
66 { szOID_OIWSEC_shaRSA, NULL, CALG_SHA },
67 { szOID_OIWSEC_sha, NULL, CALG_SHA },
68 { szOID_OIWSEC_rsaXchg, NULL, CALG_RSA_KEYX },
69 { szOID_OIWSEC_sha1, NULL, CALG_SHA },
70 { szOID_OIWSEC_dsaSHA1, NULL, CALG_SHA },
71 { szOID_OIWSEC_sha1RSASign, NULL, CALG_SHA },
72 { szOID_OIWDIR_md2RSA, NULL, CALG_MD2 },
73 { szOID_INFOSEC_mosaicUpdatedSig, NULL, CALG_SHA },
74 { szOID_INFOSEC_mosaicKMandUpdSig, NULL, CALG_DSS_SIGN },
77 static const struct OIDToAlgID algIDToOID[] = {
78 { szOID_RSA_RSA, NULL, CALG_RSA_KEYX },
79 { szOID_RSA_SMIMEalgESDH, NULL, CALG_DH_EPHEM },
80 { szOID_RSA_MD2, NULL, CALG_MD2 },
81 { szOID_RSA_MD4, NULL, CALG_MD4 },
82 { szOID_RSA_MD5, NULL, CALG_MD5 },
83 { szOID_RSA_RC2CBC, NULL, CALG_RC2 },
84 { szOID_RSA_RC4, NULL, CALG_RC4 },
85 { szOID_RSA_DES_EDE3_CBC, NULL, CALG_3DES },
86 { szOID_ANSI_X942_DH, NULL, CALG_DH_SF },
87 { szOID_X957_DSA, szOID_OIWSEC_dsa /* some Win98 */, CALG_DSS_SIGN },
88 { szOID_OIWSEC_desCBC, NULL, CALG_DES },
89 { szOID_OIWSEC_sha1, NULL, CALG_SHA },
92 static const WCHAR bogusDll[] = { 'b','o','g','u','s','.','d','l','l',0 };
93 static const WCHAR bogus2Dll[] = { 'b','o','g','u','s','2','.','d','l','l',0 };
95 static void testOIDToAlgID(void)
97 int i;
98 DWORD alg;
100 /* Test with a bogus one */
101 SetLastError(0xdeadbeef);
102 alg = CertOIDToAlgId("1.2.3");
103 ok(!alg, "Expected failure, got %d\n", alg);
104 ok(GetLastError() == 0xdeadbeef ||
105 GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND ||
106 GetLastError() == ERROR_INVALID_PARAMETER || /* Vista */
107 GetLastError() == ERROR_SUCCESS || /* win2k */
108 GetLastError() == ERROR_FILE_INVALID, /* another Vista */
109 "Expected ERROR_RESOURCE_NAME_NOT_FOUND, ERROR_INVALID_PARAMETER, "
110 "ERROR_SUCCESS or no error set, got %08x\n", GetLastError());
112 for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++)
114 alg = CertOIDToAlgId(oidToAlgID[i].oid);
115 /* Not all Windows installations support all these, so make sure it's
116 * at least not the wrong one.
118 ok(alg == 0 || alg == oidToAlgID[i].algID,
119 "Expected %d, got %d\n", oidToAlgID[i].algID, alg);
123 static void testAlgIDToOID(void)
125 int i;
126 LPCSTR oid;
128 /* Test with a bogus one */
129 SetLastError(0xdeadbeef);
130 oid = CertAlgIdToOID(ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | 80);
131 ok(!oid && GetLastError() == 0xdeadbeef,
132 "Didn't expect last error (%08x) to be set\n", GetLastError());
133 for (i = 0; i < sizeof(algIDToOID) / sizeof(algIDToOID[0]); i++)
135 oid = CertAlgIdToOID(algIDToOID[i].algID);
136 /* Allow failure, not every version of Windows supports every algo */
137 if (oid)
139 if (strcmp(oid, algIDToOID[i].oid))
141 if (algIDToOID[i].altOid)
142 ok(!strcmp(oid, algIDToOID[i].altOid),
143 "Expected %s or %s, got %s\n", algIDToOID[i].oid,
144 algIDToOID[i].altOid, oid);
145 else
147 /* No need to rerun the test, we already know it failed. */
148 ok(0, "Expected %s, got %s\n", algIDToOID[i].oid, oid);
151 else
153 /* No need to rerun the test, we already know it succeeded. */
154 ok(1, "Expected %s, got %s\n", algIDToOID[i].oid, oid);
160 static void test_oidFunctionSet(void)
162 HCRYPTOIDFUNCSET set1, set2;
163 BOOL ret;
164 LPWSTR buf = NULL;
165 DWORD size;
167 /* This crashes
168 set = CryptInitOIDFunctionSet(NULL, 0);
171 /* The name doesn't mean much */
172 set1 = CryptInitOIDFunctionSet("funky", 0);
173 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
174 if (set1)
176 /* These crash
177 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
178 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
180 size = 0;
181 ret = CryptGetDefaultOIDDllList(set1, 0, NULL, &size);
182 ok(ret, "CryptGetDefaultOIDDllList failed: %08x\n", GetLastError());
183 if (ret)
185 buf = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
186 if (buf)
188 ret = CryptGetDefaultOIDDllList(set1, 0, buf, &size);
189 ok(ret, "CryptGetDefaultOIDDllList failed: %08x\n",
190 GetLastError());
191 ok(!*buf, "Expected empty DLL list\n");
192 HeapFree(GetProcessHeap(), 0, buf);
197 /* MSDN says flags must be 0, but it's not checked */
198 set1 = CryptInitOIDFunctionSet("", 1);
199 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
200 set2 = CryptInitOIDFunctionSet("", 0);
201 ok(set2 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
202 /* There isn't a free function, so there must be only one set per name to
203 * limit leaks. (I guess the sets are freed when crypt32 is unloaded.)
205 ok(set1 == set2, "Expected identical sets\n");
206 if (set1)
208 /* The empty name function set used here seems to correspond to
209 * DEFAULT.
213 /* There's no installed function for a built-in encoding. */
214 set1 = CryptInitOIDFunctionSet("CryptDllEncodeObject", 0);
215 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
216 if (set1)
218 void *funcAddr;
219 HCRYPTOIDFUNCADDR hFuncAddr;
221 ret = CryptGetOIDFunctionAddress(set1, X509_ASN_ENCODING, X509_CERT, 0,
222 &funcAddr, &hFuncAddr);
223 ok((!ret && GetLastError() == ERROR_FILE_NOT_FOUND) ||
224 broken(ret) /* some Win98 */,
225 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
229 typedef int (*funcY)(int);
231 static int funky(int x)
233 return x;
236 static void test_installOIDFunctionAddress(void)
238 BOOL ret;
239 CRYPT_OID_FUNC_ENTRY entry = { CRYPT_DEFAULT_OID, funky };
240 HCRYPTOIDFUNCSET set;
242 /* This crashes
243 ret = CryptInstallOIDFunctionAddress(NULL, 0, NULL, 0, NULL, 0);
246 /* Installing zero functions should work */
247 SetLastError(0xdeadbeef);
248 ret = CryptInstallOIDFunctionAddress(NULL, 0, "CryptDllEncodeObject", 0,
249 NULL, 0);
250 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
251 GetLastError());
253 /* The function name doesn't much matter */
254 SetLastError(0xdeadbeef);
255 ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 0, NULL, 0);
256 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
257 GetLastError());
258 SetLastError(0xdeadbeef);
259 entry.pszOID = X509_CERT;
260 ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 1, &entry, 0);
261 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
262 GetLastError());
263 set = CryptInitOIDFunctionSet("OhSoFunky", 0);
264 ok(set != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
265 if (set)
267 funcY funcAddr = NULL;
268 HCRYPTOIDFUNCADDR hFuncAddr = NULL;
270 /* This crashes
271 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, NULL,
272 NULL);
274 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0,
275 (void **)&funcAddr, &hFuncAddr);
276 ok(!ret && (GetLastError() == ERROR_FILE_NOT_FOUND ||
277 GetLastError() == E_INVALIDARG /* some Win98 */),
278 "Expected ERROR_FILE_NOT_FOUND or E_INVALIDARG, got %d\n",
279 GetLastError());
280 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, X509_CERT, 0,
281 (void **)&funcAddr, &hFuncAddr);
282 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
283 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
284 ret = CryptGetOIDFunctionAddress(set, 0, X509_CERT, 0,
285 (void **)&funcAddr, &hFuncAddr);
286 ok(ret, "CryptGetOIDFunctionAddress failed: %d\n", GetLastError());
287 if (funcAddr)
289 int y = funcAddr(0xabadc0da);
291 ok(y == 0xabadc0da, "Unexpected return (%d) from function\n", y);
292 CryptFreeOIDFunctionAddress(hFuncAddr, 0);
297 static void test_registerOIDFunction(void)
299 BOOL ret;
301 /* oddly, this succeeds under WinXP; the function name key is merely
302 * omitted. This may be a side effect of the registry code, I don't know.
303 * I don't check it because I doubt anyone would depend on it.
304 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
305 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
307 /* On windows XP, GetLastError is incorrectly being set with an HRESULT,
308 * E_INVALIDARG
310 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "foo", NULL, bogusDll,
311 NULL);
312 ok(!ret && GetLastError() == E_INVALIDARG,
313 "Expected E_INVALIDARG: %d\n", GetLastError());
314 /* This has no effect, but "succeeds" on XP */
315 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "foo",
316 "1.2.3.4.5.6.7.8.9.10", NULL, NULL);
317 ok(ret, "Expected pseudo-success, got %d\n", GetLastError());
318 SetLastError(0xdeadbeef);
319 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
320 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
321 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
323 skip("Need admin rights\n");
324 return;
326 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
327 ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
328 "1.2.3.4.5.6.7.8.9.10");
329 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
330 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "bogus",
331 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
332 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
333 ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "bogus",
334 "1.2.3.4.5.6.7.8.9.10");
335 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
336 /* Unwanted Cryptography\OID\EncodingType 1\bogus\ will still be there */
337 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
338 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 1\\bogus"),
339 "Could not delete bogus key\n");
340 /* Shouldn't have effect but registry keys are created */
341 ret = CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
342 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
343 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
344 ret = CryptUnregisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
345 "1.2.3.4.5.6.7.8.9.10");
346 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
347 /* Check with bogus encoding type. Registry keys are still created */
348 ret = CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
349 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
350 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
351 ret = CryptUnregisterOIDFunction(0, "CryptDllEncodeObject",
352 "1.2.3.4.5.6.7.8.9.10");
353 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
354 /* Unwanted Cryptography\OID\EncodingType 0\CryptDllEncodeObject\
355 * will still be there
357 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
358 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllEncodeObject"),
359 "Could not delete CryptDllEncodeObject key\n");
360 /* This is written with value 3 verbatim. Thus, the encoding type isn't
361 * (for now) treated as a mask. Registry keys are created.
363 ret = CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
364 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
365 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
366 ret = CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
367 "1.2.3.4.5.6.7.8.9.10");
368 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
369 /* Unwanted Cryptography\OID\EncodingType 3\CryptDllEncodeObject
370 * will still be there.
372 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
373 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3\\CryptDllEncodeObject"),
374 "Could not delete CryptDllEncodeObject key\n");
375 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
376 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3"),
377 "Could not delete 'EncodingType 3' key\n");
380 static void test_registerDefaultOIDFunction(void)
382 static const char fmt[] =
383 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\DEFAULT";
384 static const char func[] = "CertDllOpenStoreProv";
385 char buf[MAX_PATH];
386 BOOL ret;
387 long rc;
388 HKEY key;
390 ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, NULL);
391 ok(!ret && GetLastError() == E_INVALIDARG,
392 "Expected E_INVALIDARG, got %08x\n", GetLastError());
393 /* This succeeds on WinXP, although the bogus entry is unusable.
394 ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, bogusDll);
396 /* Register one at index 0 */
397 SetLastError(0xdeadbeef);
398 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
399 bogusDll);
400 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
402 skip("Need admin rights\n");
403 return;
405 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
406 /* Reregistering should fail */
407 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
408 bogusDll);
409 ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
410 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
411 /* Registering the same one at index 1 should also fail */
412 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
413 bogusDll);
414 ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
415 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
416 /* Registering a different one at index 1 succeeds */
417 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
418 bogus2Dll);
419 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
420 sprintf(buf, fmt, 0, func);
421 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, buf, &key);
422 ok(rc == 0, "Expected key to exist, RegOpenKeyA failed: %ld\n", rc);
423 if (rc == 0)
425 static const CHAR dllA[] = "Dll";
426 static const CHAR bogusDll_A[] = "bogus.dll";
427 static const CHAR bogus2Dll_A[] = "bogus2.dll";
428 CHAR dllBuf[MAX_PATH];
429 DWORD type, size;
430 LPSTR ptr;
432 size = sizeof(dllBuf) / sizeof(dllBuf[0]);
433 rc = RegQueryValueExA(key, dllA, NULL, &type, (LPBYTE)dllBuf, &size);
434 ok(rc == 0,
435 "Expected Dll value to exist, RegQueryValueExA failed: %ld\n", rc);
436 ok(type == REG_MULTI_SZ, "Expected type REG_MULTI_SZ, got %d\n", type);
437 /* bogusDll was registered first, so that should be first */
438 ptr = dllBuf;
439 ok(!lstrcmpiA(ptr, bogusDll_A), "Unexpected dll\n");
440 ptr += lstrlenA(ptr) + 1;
441 ok(!lstrcmpiA(ptr, bogus2Dll_A), "Unexpected dll\n");
442 RegCloseKey(key);
444 /* Unregister both of them */
445 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
446 bogusDll);
447 ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
448 GetLastError());
449 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
450 bogus2Dll);
451 ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
452 GetLastError());
453 /* Now that they're both unregistered, unregistering should fail */
454 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
455 bogusDll);
456 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
457 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
459 /* Repeat a few tests on the normal encoding type */
460 ret = CryptRegisterDefaultOIDFunction(X509_ASN_ENCODING,
461 "CertDllOpenStoreProv", 0, bogusDll);
462 ret = CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING,
463 "CertDllOpenStoreProv", bogusDll);
464 ok(ret, "CryptUnregisterDefaultOIDFunction failed\n");
465 ret = CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING,
466 "CertDllOpenStoreProv", bogusDll);
467 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
468 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
471 static void test_getDefaultOIDFunctionAddress(void)
473 BOOL ret;
474 HCRYPTOIDFUNCSET set;
475 void *funcAddr;
476 HCRYPTOIDFUNCADDR hFuncAddr;
478 /* Crash
479 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, NULL);
480 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr, NULL);
481 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, &hFuncAddr);
482 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr,
483 &hFuncAddr);
485 set = CryptInitOIDFunctionSet("CertDllOpenStoreProv", 0);
486 ok(set != 0, "CryptInitOIDFunctionSet failed: %d\n", GetLastError());
487 /* This crashes if hFuncAddr is not 0 to begin with */
488 hFuncAddr = 0;
489 ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
490 &hFuncAddr);
491 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
492 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
493 /* This fails with the normal encoding too, so built-in functions aren't
494 * returned.
496 ret = CryptGetDefaultOIDFunctionAddress(set, X509_ASN_ENCODING, NULL, 0,
497 &funcAddr, &hFuncAddr);
498 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
499 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
501 /* Even with a registered dll, this fails (since the dll doesn't exist) */
502 SetLastError(0xdeadbeef);
503 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
504 bogusDll);
505 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
506 skip("Need admin rights\n");
507 else
508 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
509 ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
510 &hFuncAddr);
511 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
512 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
513 CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv", bogusDll);
516 static BOOL WINAPI countOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
518 (*(DWORD *)pvArg)++;
519 return TRUE;
522 static BOOL WINAPI noOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
524 return FALSE;
527 static void test_enumOIDInfo(void)
529 BOOL ret;
530 DWORD count = 0;
532 if (!pCryptEnumOIDInfo)
534 win_skip("CryptEnumOIDInfo() is not available\n");
535 return;
538 /* This crashes
539 ret = pCryptEnumOIDInfo(7, 0, NULL, NULL);
542 /* Silly tests, check that more than one thing is enumerated */
543 ret = pCryptEnumOIDInfo(0, 0, &count, countOidInfo);
544 ok(ret && count > 0, "Expected more than item enumerated\n");
545 ret = pCryptEnumOIDInfo(0, 0, NULL, noOidInfo);
546 ok(!ret, "Expected FALSE\n");
549 static void test_findOIDInfo(void)
551 static WCHAR sha1[] = { 's','h','a','1',0 };
552 static CHAR oid_rsa_md5[] = szOID_RSA_MD5;
553 ALG_ID alg = CALG_SHA1;
554 ALG_ID algs[2] = { CALG_MD5, CALG_RSA_SIGN };
555 PCCRYPT_OID_INFO info;
557 info = CryptFindOIDInfo(0, NULL, 0);
558 ok(info == NULL, "Expected NULL\n");
559 info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_rsa_md5, 0);
560 ok(info != NULL, "Expected to find szOID_RSA_MD5\n");
561 if (info)
563 ok(!strcmp(info->pszOID, szOID_RSA_MD5), "Expected %s, got %s\n",
564 szOID_RSA_MD5, info->pszOID);
565 ok(U(*info).Algid == CALG_MD5, "Expected CALG_MD5, got %d\n",
566 U(*info).Algid);
568 info = CryptFindOIDInfo(CRYPT_OID_INFO_NAME_KEY, sha1, 0);
569 ok(info != NULL, "Expected to find sha1\n");
570 if (info)
572 ok(!strcmp(info->pszOID, szOID_OIWSEC_sha1), "Expected %s, got %s\n",
573 szOID_OIWSEC_sha1, info->pszOID);
574 ok(U(*info).Algid == CALG_SHA1, "Expected CALG_SHA1, got %d\n",
575 U(*info).Algid);
577 info = CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY, &alg, 0);
578 ok(info != NULL, "Expected to find sha1\n");
579 if (info)
581 ok(!strcmp(info->pszOID, szOID_OIWSEC_sha1), "Expected %s, got %s\n",
582 szOID_OIWSEC_sha1, info->pszOID);
583 ok(U(*info).Algid == CALG_SHA1, "Expected CALG_SHA1, got %d\n",
584 U(*info).Algid);
586 info = CryptFindOIDInfo(CRYPT_OID_INFO_SIGN_KEY, algs, 0);
587 ok(info != NULL, "Expected to find md5RSA\n");
588 if (info)
590 ok(!strcmp(info->pszOID, szOID_RSA_MD5RSA), "Expected %s, got %s\n",
591 szOID_RSA_MD5RSA, info->pszOID);
592 ok(U(*info).Algid == CALG_MD5, "Expected CALG_MD5, got %d\n",
593 U(*info).Algid);
597 START_TEST(oid)
599 HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
600 pCryptEnumOIDInfo = (void*)GetProcAddress(hCrypt32, "CryptEnumOIDInfo");
602 testOIDToAlgID();
603 testAlgIDToOID();
604 test_enumOIDInfo();
605 test_findOIDInfo();
606 test_oidFunctionSet();
607 test_installOIDFunctionAddress();
608 test_registerOIDFunction();
609 test_registerDefaultOIDFunction();
610 test_getDefaultOIDFunctionAddress();