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
);
42 static const struct OIDToAlgID oidToAlgID
[] = {
43 { szOID_RSA_RSA
, NULL
, CALG_RSA_KEYX
},
44 { szOID_RSA_MD2RSA
, NULL
, CALG_MD2
},
45 { szOID_RSA_MD4RSA
, NULL
, CALG_MD4
},
46 { szOID_RSA_MD5RSA
, NULL
, CALG_MD5
},
47 { szOID_RSA_SHA1RSA
, NULL
, CALG_SHA
},
48 { szOID_RSA_DH
, NULL
, CALG_DH_SF
},
49 { szOID_RSA_SMIMEalgESDH
, NULL
, CALG_DH_EPHEM
},
50 { szOID_RSA_SMIMEalgCMS3DESwrap
, NULL
, CALG_3DES
},
51 { szOID_RSA_SMIMEalgCMSRC2wrap
, NULL
, CALG_RC2
},
52 { szOID_RSA_MD2
, NULL
, CALG_MD2
},
53 { szOID_RSA_MD4
, NULL
, CALG_MD4
},
54 { szOID_RSA_MD5
, NULL
, CALG_MD5
},
55 { szOID_RSA_RC2CBC
, NULL
, CALG_RC2
},
56 { szOID_RSA_RC4
, NULL
, CALG_RC4
},
57 { szOID_RSA_DES_EDE3_CBC
, NULL
, CALG_3DES
},
58 { szOID_ANSI_X942_DH
, NULL
, CALG_DH_SF
},
59 { szOID_X957_DSA
, NULL
, CALG_DSS_SIGN
},
60 { szOID_X957_SHA1DSA
, NULL
, CALG_SHA
},
61 { szOID_OIWSEC_md4RSA
, NULL
, CALG_MD4
},
62 { szOID_OIWSEC_md5RSA
, NULL
, CALG_MD5
},
63 { szOID_OIWSEC_md4RSA2
, NULL
, CALG_MD4
},
64 { szOID_OIWSEC_desCBC
, NULL
, CALG_DES
},
65 { szOID_OIWSEC_dsa
, NULL
, CALG_DSS_SIGN
},
66 { szOID_OIWSEC_shaDSA
, NULL
, CALG_SHA
},
67 { szOID_OIWSEC_shaRSA
, NULL
, CALG_SHA
},
68 { szOID_OIWSEC_sha
, NULL
, CALG_SHA
},
69 { szOID_OIWSEC_rsaXchg
, NULL
, CALG_RSA_KEYX
},
70 { szOID_OIWSEC_sha1
, NULL
, CALG_SHA
},
71 { szOID_OIWSEC_dsaSHA1
, NULL
, CALG_SHA
},
72 { szOID_OIWSEC_sha1RSASign
, NULL
, CALG_SHA
},
73 { szOID_OIWDIR_md2RSA
, NULL
, CALG_MD2
},
74 { szOID_INFOSEC_mosaicUpdatedSig
, NULL
, CALG_SHA
},
75 { szOID_INFOSEC_mosaicKMandUpdSig
, NULL
, CALG_DSS_SIGN
},
76 { szOID_NIST_sha256
, NULL
, CALG_SHA_256
, -1 },
77 { szOID_NIST_sha384
, NULL
, CALG_SHA_384
, -1 },
78 { szOID_NIST_sha512
, NULL
, CALG_SHA_512
, -1 }
81 static const struct OIDToAlgID algIDToOID
[] = {
82 { szOID_RSA_RSA
, NULL
, CALG_RSA_KEYX
},
83 { szOID_RSA_SMIMEalgESDH
, NULL
, CALG_DH_EPHEM
},
84 { szOID_RSA_MD2
, NULL
, CALG_MD2
},
85 { szOID_RSA_MD4
, NULL
, CALG_MD4
},
86 { szOID_RSA_MD5
, NULL
, CALG_MD5
},
87 { szOID_RSA_RC2CBC
, NULL
, CALG_RC2
},
88 { szOID_RSA_RC4
, NULL
, CALG_RC4
},
89 { szOID_RSA_DES_EDE3_CBC
, NULL
, CALG_3DES
},
90 { szOID_ANSI_X942_DH
, NULL
, CALG_DH_SF
},
91 { szOID_X957_DSA
, szOID_OIWSEC_dsa
/* some Win98 */, CALG_DSS_SIGN
},
92 { szOID_OIWSEC_desCBC
, NULL
, CALG_DES
},
93 { szOID_OIWSEC_sha1
, NULL
, CALG_SHA
},
96 static const WCHAR bogusDll
[] = { 'b','o','g','u','s','.','d','l','l',0 };
97 static const WCHAR bogus2Dll
[] = { 'b','o','g','u','s','2','.','d','l','l',0 };
99 static void testOIDToAlgID(void)
104 /* Test with a bogus one */
105 alg
= CertOIDToAlgId("1.2.3");
106 ok(!alg
, "Expected failure, got %d\n", alg
);
108 for (i
= 0; i
< sizeof(oidToAlgID
) / sizeof(oidToAlgID
[0]); i
++)
110 alg
= CertOIDToAlgId(oidToAlgID
[i
].oid
);
111 ok(alg
== oidToAlgID
[i
].algID
|| (oidToAlgID
[i
].altAlgID
&& alg
== oidToAlgID
[i
].altAlgID
),
112 "Expected %d, got %d\n", oidToAlgID
[i
].algID
, alg
);
116 static void testAlgIDToOID(void)
121 /* Test with a bogus one */
122 SetLastError(0xdeadbeef);
123 oid
= CertAlgIdToOID(ALG_CLASS_SIGNATURE
| ALG_TYPE_ANY
| 80);
124 ok(!oid
&& GetLastError() == 0xdeadbeef,
125 "Didn't expect last error (%08x) to be set\n", GetLastError());
126 for (i
= 0; i
< sizeof(algIDToOID
) / sizeof(algIDToOID
[0]); i
++)
128 oid
= CertAlgIdToOID(algIDToOID
[i
].algID
);
129 /* Allow failure, not every version of Windows supports every algo */
130 ok(oid
!= NULL
|| broken(!oid
), "CertAlgIdToOID failed, expected %s\n", algIDToOID
[i
].oid
);
133 if (strcmp(oid
, algIDToOID
[i
].oid
))
135 if (algIDToOID
[i
].altOid
)
136 ok(!strcmp(oid
, algIDToOID
[i
].altOid
),
137 "Expected %s or %s, got %s\n", algIDToOID
[i
].oid
,
138 algIDToOID
[i
].altOid
, oid
);
141 /* No need to rerun the test, we already know it failed. */
142 ok(0, "Expected %s, got %s\n", algIDToOID
[i
].oid
, oid
);
147 /* No need to rerun the test, we already know it succeeded. */
148 ok(1, "Expected %s, got %s\n", algIDToOID
[i
].oid
, oid
);
154 static void test_oidFunctionSet(void)
156 HCRYPTOIDFUNCSET set1
, set2
;
162 set = CryptInitOIDFunctionSet(NULL, 0);
165 /* The name doesn't mean much */
166 set1
= CryptInitOIDFunctionSet("funky", 0);
167 ok(set1
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
171 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
172 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
175 ret
= CryptGetDefaultOIDDllList(set1
, 0, NULL
, &size
);
176 ok(ret
, "CryptGetDefaultOIDDllList failed: %08x\n", GetLastError());
179 buf
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
182 ret
= CryptGetDefaultOIDDllList(set1
, 0, buf
, &size
);
183 ok(ret
, "CryptGetDefaultOIDDllList failed: %08x\n",
185 ok(!*buf
, "Expected empty DLL list\n");
186 HeapFree(GetProcessHeap(), 0, buf
);
191 /* MSDN says flags must be 0, but it's not checked */
192 set1
= CryptInitOIDFunctionSet("", 1);
193 ok(set1
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
194 set2
= CryptInitOIDFunctionSet("", 0);
195 ok(set2
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
196 /* There isn't a free function, so there must be only one set per name to
197 * limit leaks. (I guess the sets are freed when crypt32 is unloaded.)
199 ok(set1
== set2
, "Expected identical sets\n");
202 /* The empty name function set used here seems to correspond to
207 /* There's no installed function for a built-in encoding. */
208 set1
= CryptInitOIDFunctionSet("CryptDllEncodeObject", 0);
209 ok(set1
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
213 HCRYPTOIDFUNCADDR hFuncAddr
;
215 ret
= CryptGetOIDFunctionAddress(set1
, X509_ASN_ENCODING
, X509_CERT
, 0,
216 &funcAddr
, &hFuncAddr
);
217 ok((!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
) ||
218 broken(ret
) /* some Win98 */,
219 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
223 typedef int (*funcY
)(int);
225 static int funky(int x
)
230 static void test_installOIDFunctionAddress(void)
233 CRYPT_OID_FUNC_ENTRY entry
= { CRYPT_DEFAULT_OID
, funky
};
234 HCRYPTOIDFUNCSET set
;
237 ret = CryptInstallOIDFunctionAddress(NULL, 0, NULL, 0, NULL, 0);
240 /* Installing zero functions should work */
241 SetLastError(0xdeadbeef);
242 ret
= CryptInstallOIDFunctionAddress(NULL
, 0, "CryptDllEncodeObject", 0,
244 ok(ret
&& GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
247 /* The function name doesn't much matter */
248 SetLastError(0xdeadbeef);
249 ret
= CryptInstallOIDFunctionAddress(NULL
, 0, "OhSoFunky", 0, NULL
, 0);
250 ok(ret
&& GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
252 SetLastError(0xdeadbeef);
253 entry
.pszOID
= X509_CERT
;
254 ret
= CryptInstallOIDFunctionAddress(NULL
, 0, "OhSoFunky", 1, &entry
, 0);
255 ok(ret
&& GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
257 set
= CryptInitOIDFunctionSet("OhSoFunky", 0);
258 ok(set
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
261 funcY funcAddr
= NULL
;
262 HCRYPTOIDFUNCADDR hFuncAddr
= NULL
;
265 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, NULL,
268 ret
= CryptGetOIDFunctionAddress(set
, X509_ASN_ENCODING
, 0, 0,
269 (void **)&funcAddr
, &hFuncAddr
);
270 ok(!ret
&& (GetLastError() == ERROR_FILE_NOT_FOUND
||
271 GetLastError() == E_INVALIDARG
/* some Win98 */),
272 "Expected ERROR_FILE_NOT_FOUND or E_INVALIDARG, got %d\n",
274 ret
= CryptGetOIDFunctionAddress(set
, X509_ASN_ENCODING
, X509_CERT
, 0,
275 (void **)&funcAddr
, &hFuncAddr
);
276 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
277 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
278 ret
= CryptGetOIDFunctionAddress(set
, 0, X509_CERT
, 0,
279 (void **)&funcAddr
, &hFuncAddr
);
280 ok(ret
, "CryptGetOIDFunctionAddress failed: %d\n", GetLastError());
283 int y
= funcAddr(0xabadc0da);
285 ok(y
== 0xabadc0da, "Unexpected return (%d) from function\n", y
);
286 CryptFreeOIDFunctionAddress(hFuncAddr
, 0);
291 static void test_registerOIDFunction(void)
295 /* oddly, this succeeds under WinXP; the function name key is merely
296 * omitted. This may be a side effect of the registry code, I don't know.
297 * I don't check it because I doubt anyone would depend on it.
298 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
299 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
301 /* On windows XP, GetLastError is incorrectly being set with an HRESULT,
304 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "foo", NULL
, bogusDll
,
306 ok(!ret
&& GetLastError() == E_INVALIDARG
,
307 "Expected E_INVALIDARG: %d\n", GetLastError());
308 /* This has no effect, but "succeeds" on XP */
309 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "foo",
310 "1.2.3.4.5.6.7.8.9.10", NULL
, NULL
);
311 ok(ret
, "Expected pseudo-success, got %d\n", GetLastError());
312 SetLastError(0xdeadbeef);
313 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "CryptDllEncodeObject",
314 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
315 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
317 skip("Need admin rights\n");
320 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
321 ret
= CryptUnregisterOIDFunction(X509_ASN_ENCODING
, "CryptDllEncodeObject",
322 "1.2.3.4.5.6.7.8.9.10");
323 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
324 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "bogus",
325 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
326 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
327 ret
= CryptUnregisterOIDFunction(X509_ASN_ENCODING
, "bogus",
328 "1.2.3.4.5.6.7.8.9.10");
329 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
330 /* Unwanted Cryptography\OID\EncodingType 1\bogus\ will still be there */
331 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
,
332 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 1\\bogus"),
333 "Could not delete bogus key\n");
334 /* Shouldn't have effect but registry keys are created */
335 ret
= CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING
, "CryptDllEncodeObject",
336 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
337 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
338 ret
= CryptUnregisterOIDFunction(PKCS_7_ASN_ENCODING
, "CryptDllEncodeObject",
339 "1.2.3.4.5.6.7.8.9.10");
340 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
341 /* Check with bogus encoding type. Registry keys are still created */
342 ret
= CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
343 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
344 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
345 ret
= CryptUnregisterOIDFunction(0, "CryptDllEncodeObject",
346 "1.2.3.4.5.6.7.8.9.10");
347 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
348 /* Unwanted Cryptography\OID\EncodingType 0\CryptDllEncodeObject\
349 * will still be there
351 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
,
352 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllEncodeObject"),
353 "Could not delete CryptDllEncodeObject key\n");
354 /* This is written with value 3 verbatim. Thus, the encoding type isn't
355 * (for now) treated as a mask. Registry keys are created.
357 ret
= CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
358 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
359 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
360 ret
= CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
361 "1.2.3.4.5.6.7.8.9.10");
362 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
363 /* Unwanted Cryptography\OID\EncodingType 3\CryptDllEncodeObject
364 * will still be there.
366 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
,
367 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3\\CryptDllEncodeObject"),
368 "Could not delete CryptDllEncodeObject key\n");
369 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
,
370 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3"),
371 "Could not delete 'EncodingType 3' key\n");
374 static void test_registerDefaultOIDFunction(void)
376 static const char fmt
[] =
377 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\DEFAULT";
378 static const char func
[] = "CertDllOpenStoreProv";
384 ret
= CryptRegisterDefaultOIDFunction(0, NULL
, 0, NULL
);
385 ok(!ret
&& GetLastError() == E_INVALIDARG
,
386 "Expected E_INVALIDARG, got %08x\n", GetLastError());
387 /* This succeeds on WinXP, although the bogus entry is unusable.
388 ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, bogusDll);
390 /* Register one at index 0 */
391 SetLastError(0xdeadbeef);
392 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
394 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
396 skip("Need admin rights\n");
399 ok(ret
, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
400 /* Reregistering should fail */
401 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
403 ok(!ret
&& GetLastError() == ERROR_FILE_EXISTS
,
404 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
405 /* Registering the same one at index 1 should also fail */
406 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
408 ok(!ret
&& GetLastError() == ERROR_FILE_EXISTS
,
409 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
410 /* Registering a different one at index 1 succeeds */
411 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
413 ok(ret
, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
414 sprintf(buf
, fmt
, 0, func
);
415 rc
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, buf
, &key
);
416 ok(rc
== 0, "Expected key to exist, RegOpenKeyA failed: %d\n", rc
);
419 static const CHAR dllA
[] = "Dll";
420 static const CHAR bogusDll_A
[] = "bogus.dll";
421 static const CHAR bogus2Dll_A
[] = "bogus2.dll";
422 CHAR dllBuf
[MAX_PATH
];
426 size
= sizeof(dllBuf
) / sizeof(dllBuf
[0]);
427 rc
= RegQueryValueExA(key
, dllA
, NULL
, &type
, (LPBYTE
)dllBuf
, &size
);
429 "Expected Dll value to exist, RegQueryValueExA failed: %d\n", rc
);
430 ok(type
== REG_MULTI_SZ
, "Expected type REG_MULTI_SZ, got %d\n", type
);
431 /* bogusDll was registered first, so that should be first */
433 ok(!lstrcmpiA(ptr
, bogusDll_A
), "Unexpected dll\n");
434 ptr
+= lstrlenA(ptr
) + 1;
435 ok(!lstrcmpiA(ptr
, bogus2Dll_A
), "Unexpected dll\n");
438 /* Unregister both of them */
439 ret
= CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
441 ok(ret
, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
443 ret
= CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
445 ok(ret
, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
447 /* Now that they're both unregistered, unregistering should fail */
448 ret
= CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
450 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
451 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
453 /* Repeat a few tests on the normal encoding type */
454 ret
= CryptRegisterDefaultOIDFunction(X509_ASN_ENCODING
,
455 "CertDllOpenStoreProv", 0, bogusDll
);
456 ok(ret
, "CryptRegisterDefaultOIDFunction failed\n");
457 ret
= CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING
,
458 "CertDllOpenStoreProv", bogusDll
);
459 ok(ret
, "CryptUnregisterDefaultOIDFunction failed\n");
460 ret
= CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING
,
461 "CertDllOpenStoreProv", bogusDll
);
462 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
463 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
466 static void test_getDefaultOIDFunctionAddress(void)
469 HCRYPTOIDFUNCSET set
;
471 HCRYPTOIDFUNCADDR hFuncAddr
;
474 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, NULL);
475 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr, NULL);
476 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, &hFuncAddr);
477 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr,
480 set
= CryptInitOIDFunctionSet("CertDllOpenStoreProv", 0);
481 ok(set
!= 0, "CryptInitOIDFunctionSet failed: %d\n", GetLastError());
482 /* This crashes if hFuncAddr is not 0 to begin with */
484 ret
= CryptGetDefaultOIDFunctionAddress(set
, 0, NULL
, 0, &funcAddr
,
486 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
487 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
488 /* This fails with the normal encoding too, so built-in functions aren't
491 ret
= CryptGetDefaultOIDFunctionAddress(set
, X509_ASN_ENCODING
, NULL
, 0,
492 &funcAddr
, &hFuncAddr
);
493 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
494 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
496 /* Even with a registered dll, this fails (since the dll doesn't exist) */
497 SetLastError(0xdeadbeef);
498 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
500 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
501 skip("Need admin rights\n");
503 ok(ret
, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
504 ret
= CryptGetDefaultOIDFunctionAddress(set
, 0, NULL
, 0, &funcAddr
,
506 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
507 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
508 CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv", bogusDll
);
511 static BOOL WINAPI
countOidInfo(PCCRYPT_OID_INFO pInfo
, void *pvArg
)
517 static BOOL WINAPI
noOidInfo(PCCRYPT_OID_INFO pInfo
, void *pvArg
)
522 static void test_enumOIDInfo(void)
527 if (!pCryptEnumOIDInfo
)
529 win_skip("CryptEnumOIDInfo() is not available\n");
534 ret = pCryptEnumOIDInfo(7, 0, NULL, NULL);
537 /* Silly tests, check that more than one thing is enumerated */
538 ret
= pCryptEnumOIDInfo(0, 0, &count
, countOidInfo
);
539 ok(ret
&& count
> 0, "Expected more than item enumerated\n");
540 ret
= pCryptEnumOIDInfo(0, 0, NULL
, noOidInfo
);
541 ok(!ret
, "Expected FALSE\n");
544 static void test_findOIDInfo(void)
546 static WCHAR sha1
[] = { 's','h','a','1',0 };
547 static CHAR oid_rsa_md5
[] = szOID_RSA_MD5
, oid_sha256
[] = szOID_NIST_sha256
;
548 ALG_ID alg
= CALG_SHA1
;
549 ALG_ID algs
[2] = { CALG_MD5
, CALG_RSA_SIGN
};
550 PCCRYPT_OID_INFO info
;
552 static const WCHAR sha256W
[] = {'s','h','a','2','5','6',0};
554 info
= CryptFindOIDInfo(0, NULL
, 0);
555 ok(info
== NULL
, "Expected NULL\n");
556 info
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
, oid_rsa_md5
, 0);
557 ok(info
!= NULL
, "Expected to find szOID_RSA_MD5\n");
560 ok(!strcmp(info
->pszOID
, szOID_RSA_MD5
), "Expected %s, got %s\n",
561 szOID_RSA_MD5
, info
->pszOID
);
562 ok(U(*info
).Algid
== CALG_MD5
, "Expected CALG_MD5, got %d\n",
565 info
= CryptFindOIDInfo(CRYPT_OID_INFO_NAME_KEY
, sha1
, 0);
566 ok(info
!= NULL
, "Expected to find sha1\n");
569 ok(!strcmp(info
->pszOID
, szOID_OIWSEC_sha1
), "Expected %s, got %s\n",
570 szOID_OIWSEC_sha1
, info
->pszOID
);
571 ok(U(*info
).Algid
== CALG_SHA1
, "Expected CALG_SHA1, got %d\n",
574 info
= CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY
, &alg
, 0);
575 ok(info
!= NULL
, "Expected to find sha1\n");
578 ok(!strcmp(info
->pszOID
, szOID_OIWSEC_sha1
), "Expected %s, got %s\n",
579 szOID_OIWSEC_sha1
, info
->pszOID
);
580 ok(U(*info
).Algid
== CALG_SHA1
, "Expected CALG_SHA1, got %d\n",
583 info
= CryptFindOIDInfo(CRYPT_OID_INFO_SIGN_KEY
, algs
, 0);
584 ok(info
!= NULL
, "Expected to find md5RSA\n");
587 ok(!strcmp(info
->pszOID
, szOID_RSA_MD5RSA
), "Expected %s, got %s\n",
588 szOID_RSA_MD5RSA
, info
->pszOID
);
589 ok(U(*info
).Algid
== CALG_MD5
, "Expected CALG_MD5, got %d\n",
593 info
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
, oid_sha256
, 0);
594 ok(info
!= NULL
, "Expected to find szOID_RSA_MD5\n");
597 ok(!strcmp(info
->pszOID
, szOID_NIST_sha256
), "Expected %s, got %s\n",
598 szOID_NIST_sha256
, info
->pszOID
);
599 ok(!lstrcmpW(info
->pwszName
, sha256W
), "pwszName = %s\n", wine_dbgstr_w(info
->pwszName
));
600 ok(U(*info
).Algid
== CALG_SHA_256
|| U(*info
).Algid
== -1,
601 "Expected CALG_MD5 or -1, got %d\n", U(*info
).Algid
);
607 HMODULE hCrypt32
= GetModuleHandleA("crypt32.dll");
608 pCryptEnumOIDInfo
= (void*)GetProcAddress(hCrypt32
, "CryptEnumOIDInfo");
614 test_oidFunctionSet();
615 test_installOIDFunctionAddress();
616 test_registerOIDFunction();
617 test_registerDefaultOIDFunction();
618 test_getDefaultOIDFunctionAddress();