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
25 #define CRYPT_OID_INFO_HAS_EXTRA_FIELDS
29 #include "wine/test.h"
32 static BOOL (WINAPI
*pCryptEnumOIDInfo
)(DWORD
,DWORD
,void*,PFN_CRYPT_ENUM_OID_INFO
);
43 static const struct OIDToAlgID oidToAlgID
[] = {
44 { szOID_RSA_RSA
, NULL
, CALG_RSA_KEYX
},
45 { szOID_RSA_MD2RSA
, NULL
, CALG_MD2
},
46 { szOID_RSA_MD4RSA
, NULL
, CALG_MD4
},
47 { szOID_RSA_MD5RSA
, NULL
, CALG_MD5
},
48 { szOID_RSA_SHA1RSA
, NULL
, CALG_SHA
},
49 { szOID_RSA_DH
, NULL
, CALG_DH_SF
},
50 { szOID_RSA_SMIMEalgESDH
, NULL
, CALG_DH_EPHEM
},
51 { szOID_RSA_SMIMEalgCMS3DESwrap
, NULL
, CALG_3DES
},
52 { szOID_RSA_SMIMEalgCMSRC2wrap
, NULL
, CALG_RC2
},
53 { szOID_RSA_MD2
, NULL
, CALG_MD2
},
54 { szOID_RSA_MD4
, NULL
, CALG_MD4
},
55 { szOID_RSA_MD5
, NULL
, CALG_MD5
},
56 { szOID_RSA_RC2CBC
, NULL
, CALG_RC2
},
57 { szOID_RSA_RC4
, NULL
, CALG_RC4
},
58 { szOID_RSA_DES_EDE3_CBC
, NULL
, CALG_3DES
},
59 { szOID_ANSI_X942_DH
, NULL
, CALG_DH_SF
},
60 { szOID_X957_DSA
, NULL
, CALG_DSS_SIGN
},
61 { szOID_X957_SHA1DSA
, NULL
, CALG_SHA
},
62 { szOID_OIWSEC_md4RSA
, NULL
, CALG_MD4
},
63 { szOID_OIWSEC_md5RSA
, NULL
, CALG_MD5
},
64 { szOID_OIWSEC_md4RSA2
, NULL
, CALG_MD4
},
65 { szOID_OIWSEC_desCBC
, NULL
, CALG_DES
},
66 { szOID_OIWSEC_dsa
, NULL
, CALG_DSS_SIGN
},
67 { szOID_OIWSEC_shaDSA
, NULL
, CALG_SHA
},
68 { szOID_OIWSEC_shaRSA
, NULL
, CALG_SHA
},
69 { szOID_OIWSEC_sha
, NULL
, CALG_SHA
},
70 { szOID_OIWSEC_rsaXchg
, NULL
, CALG_RSA_KEYX
},
71 { szOID_OIWSEC_sha1
, NULL
, CALG_SHA
},
72 { szOID_OIWSEC_dsaSHA1
, NULL
, CALG_SHA
},
73 { szOID_OIWSEC_sha1RSASign
, NULL
, CALG_SHA
},
74 { szOID_OIWDIR_md2RSA
, NULL
, CALG_MD2
},
75 { szOID_INFOSEC_mosaicUpdatedSig
, NULL
, CALG_SHA
},
76 { szOID_INFOSEC_mosaicKMandUpdSig
, NULL
, CALG_DSS_SIGN
},
77 { szOID_NIST_sha256
, NULL
, CALG_SHA_256
, -1 },
78 { szOID_NIST_sha384
, NULL
, CALG_SHA_384
, -1 },
79 { szOID_NIST_sha512
, NULL
, CALG_SHA_512
, -1 }
82 static const struct OIDToAlgID algIDToOID
[] = {
83 { szOID_RSA_RSA
, NULL
, CALG_RSA_KEYX
},
84 { szOID_RSA_SMIMEalgESDH
, NULL
, CALG_DH_EPHEM
},
85 { szOID_RSA_MD2
, NULL
, CALG_MD2
},
86 { szOID_RSA_MD4
, NULL
, CALG_MD4
},
87 { szOID_RSA_MD5
, NULL
, CALG_MD5
},
88 { szOID_RSA_RC2CBC
, NULL
, CALG_RC2
},
89 { szOID_RSA_RC4
, NULL
, CALG_RC4
},
90 { szOID_RSA_DES_EDE3_CBC
, NULL
, CALG_3DES
},
91 { szOID_ANSI_X942_DH
, NULL
, CALG_DH_SF
},
92 { szOID_X957_DSA
, szOID_OIWSEC_dsa
/* some Win98 */, CALG_DSS_SIGN
},
93 { szOID_OIWSEC_desCBC
, NULL
, CALG_DES
},
94 { szOID_OIWSEC_sha1
, NULL
, CALG_SHA
},
97 static const WCHAR bogusDll
[] = { 'b','o','g','u','s','.','d','l','l',0 };
98 static const WCHAR bogus2Dll
[] = { 'b','o','g','u','s','2','.','d','l','l',0 };
100 static void testOIDToAlgID(void)
105 /* Test with a bogus one */
106 alg
= CertOIDToAlgId("1.2.3");
107 ok(!alg
, "Expected failure, got %d\n", alg
);
109 for (i
= 0; i
< ARRAY_SIZE(oidToAlgID
); i
++)
111 alg
= CertOIDToAlgId(oidToAlgID
[i
].oid
);
112 ok(alg
== oidToAlgID
[i
].algID
|| (oidToAlgID
[i
].altAlgID
&& alg
== oidToAlgID
[i
].altAlgID
),
113 "Expected %d, got %d\n", oidToAlgID
[i
].algID
, alg
);
117 static void testAlgIDToOID(void)
122 /* Test with a bogus one */
123 SetLastError(0xdeadbeef);
124 oid
= CertAlgIdToOID(ALG_CLASS_SIGNATURE
| ALG_TYPE_ANY
| 80);
125 ok(!oid
&& GetLastError() == 0xdeadbeef,
126 "Didn't expect last error (%08x) to be set\n", GetLastError());
127 for (i
= 0; i
< ARRAY_SIZE(algIDToOID
); i
++)
129 oid
= CertAlgIdToOID(algIDToOID
[i
].algID
);
130 /* Allow failure, not every version of Windows supports every algo */
131 ok(oid
!= NULL
|| broken(!oid
), "CertAlgIdToOID failed, expected %s\n", algIDToOID
[i
].oid
);
134 if (strcmp(oid
, algIDToOID
[i
].oid
))
136 if (algIDToOID
[i
].altOid
)
137 ok(!strcmp(oid
, algIDToOID
[i
].altOid
),
138 "Expected %s or %s, got %s\n", algIDToOID
[i
].oid
,
139 algIDToOID
[i
].altOid
, oid
);
142 /* No need to rerun the test, we already know it failed. */
143 ok(0, "Expected %s, got %s\n", algIDToOID
[i
].oid
, oid
);
148 /* No need to rerun the test, we already know it succeeded. */
149 ok(1, "Expected %s, got %s\n", algIDToOID
[i
].oid
, oid
);
155 static void test_oidFunctionSet(void)
157 HCRYPTOIDFUNCSET set1
, set2
;
163 set = CryptInitOIDFunctionSet(NULL, 0);
166 /* The name doesn't mean much */
167 set1
= CryptInitOIDFunctionSet("funky", 0);
168 ok(set1
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
172 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
173 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
176 ret
= CryptGetDefaultOIDDllList(set1
, 0, NULL
, &size
);
177 ok(ret
, "CryptGetDefaultOIDDllList failed: %08x\n", GetLastError());
180 buf
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
183 ret
= CryptGetDefaultOIDDllList(set1
, 0, buf
, &size
);
184 ok(ret
, "CryptGetDefaultOIDDllList failed: %08x\n",
186 ok(!*buf
, "Expected empty DLL list\n");
187 HeapFree(GetProcessHeap(), 0, buf
);
192 /* MSDN says flags must be 0, but it's not checked */
193 set1
= CryptInitOIDFunctionSet("", 1);
194 ok(set1
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
195 set2
= CryptInitOIDFunctionSet("", 0);
196 ok(set2
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
197 /* There isn't a free function, so there must be only one set per name to
198 * limit leaks. (I guess the sets are freed when crypt32 is unloaded.)
200 ok(set1
== set2
, "Expected identical sets\n");
203 /* The empty name function set used here seems to correspond to
208 /* There's no installed function for a built-in encoding. */
209 set1
= CryptInitOIDFunctionSet("CryptDllEncodeObject", 0);
210 ok(set1
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
214 HCRYPTOIDFUNCADDR hFuncAddr
;
216 ret
= CryptGetOIDFunctionAddress(set1
, X509_ASN_ENCODING
, X509_CERT
, 0,
217 &funcAddr
, &hFuncAddr
);
218 ok((!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
) ||
219 broken(ret
) /* some Win98 */,
220 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
224 typedef int (*funcY
)(int);
226 static int funky(int x
)
231 static void test_installOIDFunctionAddress(void)
234 CRYPT_OID_FUNC_ENTRY entry
= { CRYPT_DEFAULT_OID
, funky
};
235 HCRYPTOIDFUNCSET set
;
238 ret = CryptInstallOIDFunctionAddress(NULL, 0, NULL, 0, NULL, 0);
241 /* Installing zero functions should work */
242 SetLastError(0xdeadbeef);
243 ret
= CryptInstallOIDFunctionAddress(NULL
, 0, "CryptDllEncodeObject", 0,
245 ok(ret
&& GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
248 /* The function name doesn't much matter */
249 SetLastError(0xdeadbeef);
250 ret
= CryptInstallOIDFunctionAddress(NULL
, 0, "OhSoFunky", 0, NULL
, 0);
251 ok(ret
&& GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
253 SetLastError(0xdeadbeef);
254 entry
.pszOID
= X509_CERT
;
255 ret
= CryptInstallOIDFunctionAddress(NULL
, 0, "OhSoFunky", 1, &entry
, 0);
256 ok(ret
&& GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
258 set
= CryptInitOIDFunctionSet("OhSoFunky", 0);
259 ok(set
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
262 funcY funcAddr
= NULL
;
263 HCRYPTOIDFUNCADDR hFuncAddr
= NULL
;
266 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, NULL,
269 ret
= CryptGetOIDFunctionAddress(set
, X509_ASN_ENCODING
, 0, 0,
270 (void **)&funcAddr
, &hFuncAddr
);
271 ok(!ret
&& (GetLastError() == ERROR_FILE_NOT_FOUND
||
272 GetLastError() == E_INVALIDARG
/* some Win98 */),
273 "Expected ERROR_FILE_NOT_FOUND or E_INVALIDARG, got %d\n",
275 ret
= CryptGetOIDFunctionAddress(set
, X509_ASN_ENCODING
, X509_CERT
, 0,
276 (void **)&funcAddr
, &hFuncAddr
);
277 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
278 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
279 ret
= CryptGetOIDFunctionAddress(set
, 0, X509_CERT
, 0,
280 (void **)&funcAddr
, &hFuncAddr
);
281 ok(ret
, "CryptGetOIDFunctionAddress failed: %d\n", GetLastError());
284 int y
= funcAddr(0xabadc0da);
286 ok(y
== 0xabadc0da, "Unexpected return (%d) from function\n", y
);
287 CryptFreeOIDFunctionAddress(hFuncAddr
, 0);
292 static void test_registerOIDFunction(void)
296 /* oddly, this succeeds under WinXP; the function name key is merely
297 * omitted. This may be a side effect of the registry code, I don't know.
298 * I don't check it because I doubt anyone would depend on it.
299 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
300 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
302 /* On windows XP, GetLastError is incorrectly being set with an HRESULT,
305 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "foo", NULL
, bogusDll
,
307 ok(!ret
&& GetLastError() == E_INVALIDARG
,
308 "Expected E_INVALIDARG: %d\n", GetLastError());
309 /* This has no effect, but "succeeds" on XP */
310 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "foo",
311 "1.2.3.4.5.6.7.8.9.10", NULL
, NULL
);
312 ok(ret
, "Expected pseudo-success, got %d\n", GetLastError());
313 SetLastError(0xdeadbeef);
314 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "CryptDllEncodeObject",
315 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
316 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
318 skip("Need admin rights\n");
321 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
322 ret
= CryptUnregisterOIDFunction(X509_ASN_ENCODING
, "CryptDllEncodeObject",
323 "1.2.3.4.5.6.7.8.9.10");
324 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
325 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "bogus",
326 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
327 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
328 ret
= CryptUnregisterOIDFunction(X509_ASN_ENCODING
, "bogus",
329 "1.2.3.4.5.6.7.8.9.10");
330 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
331 /* Unwanted Cryptography\OID\EncodingType 1\bogus\ will still be there */
332 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
,
333 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 1\\bogus"),
334 "Could not delete bogus key\n");
335 /* Shouldn't have effect but registry keys are created */
336 ret
= CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING
, "CryptDllEncodeObject",
337 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
338 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
339 ret
= CryptUnregisterOIDFunction(PKCS_7_ASN_ENCODING
, "CryptDllEncodeObject",
340 "1.2.3.4.5.6.7.8.9.10");
341 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
342 /* Check with bogus encoding type. Registry keys are still created */
343 ret
= CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
344 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
345 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
346 ret
= CryptUnregisterOIDFunction(0, "CryptDllEncodeObject",
347 "1.2.3.4.5.6.7.8.9.10");
348 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
349 /* Unwanted Cryptography\OID\EncodingType 0\CryptDllEncodeObject\
350 * will still be there
352 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
,
353 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllEncodeObject"),
354 "Could not delete CryptDllEncodeObject key\n");
355 /* This is written with value 3 verbatim. Thus, the encoding type isn't
356 * (for now) treated as a mask. Registry keys are created.
358 ret
= CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
359 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
360 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
361 ret
= CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
362 "1.2.3.4.5.6.7.8.9.10");
363 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
364 /* Unwanted Cryptography\OID\EncodingType 3\CryptDllEncodeObject
365 * will still be there.
367 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
,
368 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3\\CryptDllEncodeObject"),
369 "Could not delete CryptDllEncodeObject key\n");
370 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
,
371 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3"),
372 "Could not delete 'EncodingType 3' key\n");
375 static void test_registerDefaultOIDFunction(void)
377 static const char fmt
[] =
378 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\DEFAULT";
379 static const char func
[] = "CertDllOpenStoreProv";
385 ret
= CryptRegisterDefaultOIDFunction(0, NULL
, 0, NULL
);
386 ok(!ret
&& GetLastError() == E_INVALIDARG
,
387 "Expected E_INVALIDARG, got %08x\n", GetLastError());
388 /* This succeeds on WinXP, although the bogus entry is unusable.
389 ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, bogusDll);
391 /* Register one at index 0 */
392 SetLastError(0xdeadbeef);
393 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
395 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
397 skip("Need admin rights\n");
400 ok(ret
, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
401 /* Reregistering should fail */
402 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
404 ok(!ret
&& GetLastError() == ERROR_FILE_EXISTS
,
405 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
406 /* Registering the same one at index 1 should also fail */
407 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
409 ok(!ret
&& GetLastError() == ERROR_FILE_EXISTS
,
410 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
411 /* Registering a different one at index 1 succeeds */
412 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
414 ok(ret
, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
415 sprintf(buf
, fmt
, 0, func
);
416 rc
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, buf
, &key
);
417 ok(rc
== 0, "Expected key to exist, RegOpenKeyA failed: %d\n", rc
);
420 static const CHAR dllA
[] = "Dll";
421 static const CHAR bogusDll_A
[] = "bogus.dll";
422 static const CHAR bogus2Dll_A
[] = "bogus2.dll";
423 CHAR dllBuf
[MAX_PATH
];
427 size
= ARRAY_SIZE(dllBuf
);
428 rc
= RegQueryValueExA(key
, dllA
, NULL
, &type
, (LPBYTE
)dllBuf
, &size
);
430 "Expected Dll value to exist, RegQueryValueExA failed: %d\n", rc
);
431 ok(type
== REG_MULTI_SZ
, "Expected type REG_MULTI_SZ, got %d\n", type
);
432 /* bogusDll was registered first, so that should be first */
434 ok(!lstrcmpiA(ptr
, bogusDll_A
), "Unexpected dll\n");
435 ptr
+= lstrlenA(ptr
) + 1;
436 ok(!lstrcmpiA(ptr
, bogus2Dll_A
), "Unexpected dll\n");
439 /* Unregister both of them */
440 ret
= CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
442 ok(ret
, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
444 ret
= CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
446 ok(ret
, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
448 /* Now that they're both unregistered, unregistering should fail */
449 ret
= CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
451 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
452 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
454 /* Repeat a few tests on the normal encoding type */
455 ret
= CryptRegisterDefaultOIDFunction(X509_ASN_ENCODING
,
456 "CertDllOpenStoreProv", 0, bogusDll
);
457 ok(ret
, "CryptRegisterDefaultOIDFunction failed\n");
458 ret
= CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING
,
459 "CertDllOpenStoreProv", bogusDll
);
460 ok(ret
, "CryptUnregisterDefaultOIDFunction failed\n");
461 ret
= CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING
,
462 "CertDllOpenStoreProv", bogusDll
);
463 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
464 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
467 static void test_getDefaultOIDFunctionAddress(void)
470 HCRYPTOIDFUNCSET set
;
472 HCRYPTOIDFUNCADDR hFuncAddr
;
475 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, NULL);
476 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr, NULL);
477 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, &hFuncAddr);
478 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr,
481 set
= CryptInitOIDFunctionSet("CertDllOpenStoreProv", 0);
482 ok(set
!= 0, "CryptInitOIDFunctionSet failed: %d\n", GetLastError());
483 /* This crashes if hFuncAddr is not 0 to begin with */
485 ret
= CryptGetDefaultOIDFunctionAddress(set
, 0, NULL
, 0, &funcAddr
,
487 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
488 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
489 /* This fails with the normal encoding too, so built-in functions aren't
492 ret
= CryptGetDefaultOIDFunctionAddress(set
, X509_ASN_ENCODING
, NULL
, 0,
493 &funcAddr
, &hFuncAddr
);
494 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
495 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
497 /* Even with a registered dll, this fails (since the dll doesn't exist) */
498 SetLastError(0xdeadbeef);
499 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
501 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
502 skip("Need admin rights\n");
504 ok(ret
, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
505 ret
= CryptGetDefaultOIDFunctionAddress(set
, 0, NULL
, 0, &funcAddr
,
507 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
508 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
509 CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv", bogusDll
);
512 static BOOL WINAPI
countOidInfo(PCCRYPT_OID_INFO pInfo
, void *pvArg
)
518 static BOOL WINAPI
noOidInfo(PCCRYPT_OID_INFO pInfo
, void *pvArg
)
523 static void test_enumOIDInfo(void)
528 if (!pCryptEnumOIDInfo
)
530 win_skip("CryptEnumOIDInfo() is not available\n");
535 ret = pCryptEnumOIDInfo(7, 0, NULL, NULL);
538 /* Silly tests, check that more than one thing is enumerated */
539 ret
= pCryptEnumOIDInfo(0, 0, &count
, countOidInfo
);
540 ok(ret
&& count
> 0, "Expected more than item enumerated\n");
541 ret
= pCryptEnumOIDInfo(0, 0, NULL
, noOidInfo
);
542 ok(!ret
, "Expected FALSE\n");
545 static void test_findOIDInfo(void)
547 static WCHAR sha256ECDSA
[] = { 's','h','a','2','5','6','E','C','D','S','A',0 };
548 static WCHAR sha1
[] = { 's','h','a','1',0 };
549 static CHAR oid_rsa_md5
[] = szOID_RSA_MD5
, oid_sha256
[] = szOID_NIST_sha256
;
550 static CHAR oid_ecdsa_sha256
[] = szOID_ECDSA_SHA256
;
551 ALG_ID alg
= CALG_SHA1
;
552 ALG_ID algs
[2] = { CALG_MD5
, CALG_RSA_SIGN
};
553 const struct oid_info
562 { CRYPT_OID_INFO_OID_KEY
, oid_rsa_md5
, szOID_RSA_MD5
, CALG_MD5
},
563 { CRYPT_OID_INFO_NAME_KEY
, sha1
, szOID_OIWSEC_sha1
, CALG_SHA1
},
564 { CRYPT_OID_INFO_ALGID_KEY
, &alg
, szOID_OIWSEC_sha1
, CALG_SHA1
},
565 { CRYPT_OID_INFO_SIGN_KEY
, algs
, szOID_RSA_MD5RSA
, CALG_MD5
},
566 { CRYPT_OID_INFO_OID_KEY
, oid_sha256
, szOID_NIST_sha256
, CALG_SHA_256
, -1 },
568 PCCRYPT_OID_INFO info
;
571 info
= CryptFindOIDInfo(0, NULL
, 0);
572 ok(info
== NULL
, "Expected NULL\n");
574 for (i
= 0; i
< ARRAY_SIZE(oid_test_info
); i
++)
576 const struct oid_info
*test
= &oid_test_info
[i
];
578 info
= CryptFindOIDInfo(test
->key_type
, test
->key
, 0);
579 ok(info
!= NULL
, "Failed to find %s.\n", test
->oid
);
582 ok(!strcmp(info
->pszOID
, test
->oid
), "Unexpected OID %s, expected %s\n", info
->pszOID
, test
->oid
);
583 ok(U(*info
).Algid
== test
->algid
|| broken(U(*info
).Algid
== test
->broken_algid
),
584 "Unexpected Algid %d, expected %d\n", U(*info
).Algid
, test
->algid
);
588 info
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
, oid_ecdsa_sha256
, 0);
593 ok(info
->cbSize
== sizeof(*info
), "Unexpected structure size %d.\n", info
->cbSize
);
594 ok(!strcmp(info
->pszOID
, oid_ecdsa_sha256
), "Expected %s, got %s\n", oid_ecdsa_sha256
, info
->pszOID
);
595 ok(!lstrcmpW(info
->pwszName
, sha256ECDSA
), "Expected %s, got %s\n",
596 wine_dbgstr_w(sha256ECDSA
), wine_dbgstr_w(info
->pwszName
));
597 ok(info
->dwGroupId
== CRYPT_SIGN_ALG_OID_GROUP_ID
,
598 "Expected CRYPT_SIGN_ALG_OID_GROUP_ID, got %u\n", info
->dwGroupId
);
599 ok(U(*info
).Algid
== CALG_OID_INFO_CNG_ONLY
,
600 "Expected CALG_OID_INFO_CNG_ONLY, got %d\n", U(*info
).Algid
);
602 data
= (DWORD
*)info
->ExtraInfo
.pbData
;
603 ok(info
->ExtraInfo
.cbData
== 8, "Expected 8, got %d\n", info
->ExtraInfo
.cbData
);
604 ok(data
[0] == CALG_OID_INFO_PARAMETERS
, "Expected CALG_OID_INFO_PARAMETERS, got %x\n", data
[0]);
605 ok(data
[1] == CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG
,
606 "Expected CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG, got %x\n", data
[1]);
608 ok(!lstrcmpW(info
->pwszCNGAlgid
, BCRYPT_SHA256_ALGORITHM
), "Expected %s, got %s\n",
609 wine_dbgstr_w(BCRYPT_SHA256_ALGORITHM
), wine_dbgstr_w(info
->pwszCNGAlgid
));
610 ok(!lstrcmpW(info
->pwszCNGExtraAlgid
, CRYPT_OID_INFO_ECC_PARAMETERS_ALGORITHM
), "Expected %s, got %s\n",
611 wine_dbgstr_w(CRYPT_OID_INFO_ECC_PARAMETERS_ALGORITHM
), wine_dbgstr_w(info
->pwszCNGExtraAlgid
));
614 win_skip("Host does not support ECDSA_SHA256, skipping test\n");
619 HMODULE hCrypt32
= GetModuleHandleA("crypt32.dll");
620 pCryptEnumOIDInfo
= (void*)GetProcAddress(hCrypt32
, "CryptEnumOIDInfo");
626 test_oidFunctionSet();
627 test_installOIDFunctionAddress();
628 test_registerOIDFunction();
629 test_registerDefaultOIDFunction();
630 test_getDefaultOIDFunctionAddress();