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
28 #include "wine/test.h"
31 static BOOL (WINAPI
*pCryptEnumOIDInfo
)(DWORD
,DWORD
,void*,PFN_CRYPT_ENUM_OID_INFO
);
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)
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)
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 */
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
);
147 /* No need to rerun the test, we already know it failed. */
148 ok(0, "Expected %s, got %s\n", algIDToOID
[i
].oid
, oid
);
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
;
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());
177 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
178 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
181 ret
= CryptGetDefaultOIDDllList(set1
, 0, NULL
, &size
);
182 ok(ret
, "CryptGetDefaultOIDDllList failed: %08x\n", GetLastError());
185 buf
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
188 ret
= CryptGetDefaultOIDDllList(set1
, 0, buf
, &size
);
189 ok(ret
, "CryptGetDefaultOIDDllList failed: %08x\n",
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");
208 /* The empty name function set used here seems to correspond to
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());
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
)
236 static void test_installOIDFunctionAddress(void)
239 CRYPT_OID_FUNC_ENTRY entry
= { CRYPT_DEFAULT_OID
, funky
};
240 HCRYPTOIDFUNCSET set
;
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,
250 ok(ret
&& GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
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",
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",
263 set
= CryptInitOIDFunctionSet("OhSoFunky", 0);
264 ok(set
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
267 funcY funcAddr
= NULL
;
268 HCRYPTOIDFUNCADDR hFuncAddr
= NULL
;
271 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, 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",
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());
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)
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,
310 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "foo", NULL
, bogusDll
,
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");
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";
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,
400 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
402 skip("Need admin rights\n");
405 ok(ret
, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
406 /* Reregistering should fail */
407 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
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,
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,
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
);
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
];
432 size
= sizeof(dllBuf
) / sizeof(dllBuf
[0]);
433 rc
= RegQueryValueExA(key
, dllA
, NULL
, &type
, (LPBYTE
)dllBuf
, &size
);
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 */
439 ok(!lstrcmpiA(ptr
, bogusDll_A
), "Unexpected dll\n");
440 ptr
+= lstrlenA(ptr
) + 1;
441 ok(!lstrcmpiA(ptr
, bogus2Dll_A
), "Unexpected dll\n");
444 /* Unregister both of them */
445 ret
= CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
447 ok(ret
, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
449 ret
= CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
451 ok(ret
, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
453 /* Now that they're both unregistered, unregistering should fail */
454 ret
= CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
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)
474 HCRYPTOIDFUNCSET set
;
476 HCRYPTOIDFUNCADDR hFuncAddr
;
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,
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 */
489 ret
= CryptGetDefaultOIDFunctionAddress(set
, 0, NULL
, 0, &funcAddr
,
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
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,
505 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
506 skip("Need admin rights\n");
508 ok(ret
, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
509 ret
= CryptGetDefaultOIDFunctionAddress(set
, 0, NULL
, 0, &funcAddr
,
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
)
522 static BOOL WINAPI
noOidInfo(PCCRYPT_OID_INFO pInfo
, void *pvArg
)
527 static void test_enumOIDInfo(void)
532 if (!pCryptEnumOIDInfo
)
534 win_skip("CryptEnumOIDInfo() is not available\n");
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");
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",
568 info
= CryptFindOIDInfo(CRYPT_OID_INFO_NAME_KEY
, sha1
, 0);
569 ok(info
!= NULL
, "Expected to find sha1\n");
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",
577 info
= CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY
, &alg
, 0);
578 ok(info
!= NULL
, "Expected to find sha1\n");
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",
586 info
= CryptFindOIDInfo(CRYPT_OID_INFO_SIGN_KEY
, algs
, 0);
587 ok(info
!= NULL
, "Expected to find md5RSA\n");
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",
599 HMODULE hCrypt32
= GetModuleHandleA("crypt32.dll");
600 pCryptEnumOIDInfo
= (void*)GetProcAddress(hCrypt32
, "CryptEnumOIDInfo");
606 test_oidFunctionSet();
607 test_installOIDFunctionAddress();
608 test_registerOIDFunction();
609 test_registerDefaultOIDFunction();
610 test_getDefaultOIDFunctionAddress();