ReactOS  0.4.13-dev-99-g7e18b6d
oid.c
Go to the documentation of this file.
1 /*
2  * Unit test suite for crypt32.dll's OID support functions.
3  *
4  * Copyright 2005 Juan Lang
5  * Copyright 2018 Dmitry Timoshkov
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <windef.h>
24 #include <winbase.h>
25 #include <winerror.h>
26 #define CRYPT_OID_INFO_HAS_EXTRA_FIELDS
27 #include <wincrypt.h>
28 #include <winreg.h>
29 
30 #include "wine/test.h"
31 
32 
33 static BOOL (WINAPI *pCryptEnumOIDInfo)(DWORD,DWORD,void*,PFN_CRYPT_ENUM_OID_INFO);
34 
35 
36 struct OIDToAlgID
37 {
42 };
43 
44 static const struct OIDToAlgID oidToAlgID[] = {
81 };
82 
83 static const struct OIDToAlgID algIDToOID[] = {
93  { szOID_X957_DSA, szOID_OIWSEC_dsa /* some Win98 */, CALG_DSS_SIGN },
96 };
97 
98 static const WCHAR bogusDll[] = { 'b','o','g','u','s','.','d','l','l',0 };
99 static const WCHAR bogus2Dll[] = { 'b','o','g','u','s','2','.','d','l','l',0 };
100 
101 static void testOIDToAlgID(void)
102 {
103  int i;
104  DWORD alg;
105 
106  /* Test with a bogus one */
107  alg = CertOIDToAlgId("1.2.3");
108  ok(!alg, "Expected failure, got %d\n", alg);
109 
110  for (i = 0; i < ARRAY_SIZE(oidToAlgID); i++)
111  {
112  alg = CertOIDToAlgId(oidToAlgID[i].oid);
113  ok(alg == oidToAlgID[i].algID || (oidToAlgID[i].altAlgID && alg == oidToAlgID[i].altAlgID),
114  "Expected %d, got %d\n", oidToAlgID[i].algID, alg);
115  }
116 }
117 
118 static void testAlgIDToOID(void)
119 {
120  int i;
121  LPCSTR oid;
122 
123  /* Test with a bogus one */
124  SetLastError(0xdeadbeef);
126  ok(!oid && GetLastError() == 0xdeadbeef,
127  "Didn't expect last error (%08x) to be set\n", GetLastError());
128  for (i = 0; i < ARRAY_SIZE(algIDToOID); i++)
129  {
131  /* Allow failure, not every version of Windows supports every algo */
132  ok(oid != NULL || broken(!oid), "CertAlgIdToOID failed, expected %s\n", algIDToOID[i].oid);
133  if (oid)
134  {
135  if (strcmp(oid, algIDToOID[i].oid))
136  {
137  if (algIDToOID[i].altOid)
139  "Expected %s or %s, got %s\n", algIDToOID[i].oid,
140  algIDToOID[i].altOid, oid);
141  else
142  {
143  /* No need to rerun the test, we already know it failed. */
144  ok(0, "Expected %s, got %s\n", algIDToOID[i].oid, oid);
145  }
146  }
147  else
148  {
149  /* No need to rerun the test, we already know it succeeded. */
150  ok(1, "Expected %s, got %s\n", algIDToOID[i].oid, oid);
151  }
152  }
153  }
154 }
155 
156 static void test_oidFunctionSet(void)
157 {
158  HCRYPTOIDFUNCSET set1, set2;
159  BOOL ret;
160  LPWSTR buf = NULL;
161  DWORD size;
162 
163  /* This crashes
164  set = CryptInitOIDFunctionSet(NULL, 0);
165  */
166 
167  /* The name doesn't mean much */
168  set1 = CryptInitOIDFunctionSet("funky", 0);
169  ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
170  if (set1)
171  {
172  /* These crash
173  ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
174  ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
175  */
176  size = 0;
178  ok(ret, "CryptGetDefaultOIDDllList failed: %08x\n", GetLastError());
179  if (ret)
180  {
181  buf = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
182  if (buf)
183  {
185  ok(ret, "CryptGetDefaultOIDDllList failed: %08x\n",
186  GetLastError());
187  ok(!*buf, "Expected empty DLL list\n");
188  HeapFree(GetProcessHeap(), 0, buf);
189  }
190  }
191  }
192 
193  /* MSDN says flags must be 0, but it's not checked */
194  set1 = CryptInitOIDFunctionSet("", 1);
195  ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
196  set2 = CryptInitOIDFunctionSet("", 0);
197  ok(set2 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
198  /* There isn't a free function, so there must be only one set per name to
199  * limit leaks. (I guess the sets are freed when crypt32 is unloaded.)
200  */
201  ok(set1 == set2, "Expected identical sets\n");
202  if (set1)
203  {
204  /* The empty name function set used here seems to correspond to
205  * DEFAULT.
206  */
207  }
208 
209  /* There's no installed function for a built-in encoding. */
210  set1 = CryptInitOIDFunctionSet("CryptDllEncodeObject", 0);
211  ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
212  if (set1)
213  {
214  void *funcAddr;
215  HCRYPTOIDFUNCADDR hFuncAddr;
216 
218  &funcAddr, &hFuncAddr);
220  broken(ret) /* some Win98 */,
221  "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
222  }
223 }
224 
225 typedef int (*funcY)(int);
226 
227 static int funky(int x)
228 {
229  return x;
230 }
231 
233 {
234  BOOL ret;
237 
238  /* This crashes
239  ret = CryptInstallOIDFunctionAddress(NULL, 0, NULL, 0, NULL, 0);
240  */
241 
242  /* Installing zero functions should work */
243  SetLastError(0xdeadbeef);
244  ret = CryptInstallOIDFunctionAddress(NULL, 0, "CryptDllEncodeObject", 0,
245  NULL, 0);
246  ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
247  GetLastError());
248 
249  /* The function name doesn't much matter */
250  SetLastError(0xdeadbeef);
251  ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 0, NULL, 0);
252  ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
253  GetLastError());
254  SetLastError(0xdeadbeef);
255  entry.pszOID = X509_CERT;
256  ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 1, &entry, 0);
257  ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
258  GetLastError());
259  set = CryptInitOIDFunctionSet("OhSoFunky", 0);
260  ok(set != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
261  if (set)
262  {
263  funcY funcAddr = NULL;
264  HCRYPTOIDFUNCADDR hFuncAddr = NULL;
265 
266  /* This crashes
267  ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, NULL,
268  NULL);
269  */
271  (void **)&funcAddr, &hFuncAddr);
273  GetLastError() == E_INVALIDARG /* some Win98 */),
274  "Expected ERROR_FILE_NOT_FOUND or E_INVALIDARG, got %d\n",
275  GetLastError());
277  (void **)&funcAddr, &hFuncAddr);
279  "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
281  (void **)&funcAddr, &hFuncAddr);
282  ok(ret, "CryptGetOIDFunctionAddress failed: %d\n", GetLastError());
283  if (funcAddr)
284  {
285  int y = funcAddr(0xabadc0da);
286 
287  ok(y == 0xabadc0da, "Unexpected return (%d) from function\n", y);
288  CryptFreeOIDFunctionAddress(hFuncAddr, 0);
289  }
290  }
291 }
292 
293 static void test_registerOIDFunction(void)
294 {
295  BOOL ret;
296 
297  /* oddly, this succeeds under WinXP; the function name key is merely
298  * omitted. This may be a side effect of the registry code, I don't know.
299  * I don't check it because I doubt anyone would depend on it.
300  ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
301  "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
302  */
303  /* On windows XP, GetLastError is incorrectly being set with an HRESULT,
304  * E_INVALIDARG
305  */
307  NULL);
308  ok(!ret && GetLastError() == E_INVALIDARG,
309  "Expected E_INVALIDARG: %d\n", GetLastError());
310  /* This has no effect, but "succeeds" on XP */
312  "1.2.3.4.5.6.7.8.9.10", NULL, NULL);
313  ok(ret, "Expected pseudo-success, got %d\n", GetLastError());
314  SetLastError(0xdeadbeef);
315  ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
316  "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
317  if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
318  {
319  skip("Need admin rights\n");
320  return;
321  }
322  ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
323  ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
324  "1.2.3.4.5.6.7.8.9.10");
325  ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
327  "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
328  ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
330  "1.2.3.4.5.6.7.8.9.10");
331  ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
332  /* Unwanted Cryptography\OID\EncodingType 1\bogus\ will still be there */
334  "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 1\\bogus"),
335  "Could not delete bogus key\n");
336  /* Shouldn't have effect but registry keys are created */
337  ret = CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
338  "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
339  ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
340  ret = CryptUnregisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
341  "1.2.3.4.5.6.7.8.9.10");
342  ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
343  /* Check with bogus encoding type. Registry keys are still created */
344  ret = CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
345  "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
346  ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
347  ret = CryptUnregisterOIDFunction(0, "CryptDllEncodeObject",
348  "1.2.3.4.5.6.7.8.9.10");
349  ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
350  /* Unwanted Cryptography\OID\EncodingType 0\CryptDllEncodeObject\
351  * will still be there
352  */
354  "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllEncodeObject"),
355  "Could not delete CryptDllEncodeObject key\n");
356  /* This is written with value 3 verbatim. Thus, the encoding type isn't
357  * (for now) treated as a mask. Registry keys are created.
358  */
359  ret = CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
360  "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
361  ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
362  ret = CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
363  "1.2.3.4.5.6.7.8.9.10");
364  ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
365  /* Unwanted Cryptography\OID\EncodingType 3\CryptDllEncodeObject
366  * will still be there.
367  */
369  "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3\\CryptDllEncodeObject"),
370  "Could not delete CryptDllEncodeObject key\n");
372  "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3"),
373  "Could not delete 'EncodingType 3' key\n");
374 }
375 
377 {
378  static const char fmt[] =
379  "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\DEFAULT";
380  static const char func[] = "CertDllOpenStoreProv";
381  char buf[MAX_PATH];
382  BOOL ret;
383  LSTATUS rc;
384  HKEY key;
385 
387  ok(!ret && GetLastError() == E_INVALIDARG,
388  "Expected E_INVALIDARG, got %08x\n", GetLastError());
389  /* This succeeds on WinXP, although the bogus entry is unusable.
390  ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, bogusDll);
391  */
392  /* Register one at index 0 */
393  SetLastError(0xdeadbeef);
394  ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
395  bogusDll);
396  if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
397  {
398  skip("Need admin rights\n");
399  return;
400  }
401  ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
402  /* Reregistering should fail */
403  ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
404  bogusDll);
406  "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
407  /* Registering the same one at index 1 should also fail */
408  ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
409  bogusDll);
411  "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
412  /* Registering a different one at index 1 succeeds */
413  ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
414  bogus2Dll);
415  ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
416  sprintf(buf, fmt, 0, func);
418  ok(rc == 0, "Expected key to exist, RegOpenKeyA failed: %d\n", rc);
419  if (rc == 0)
420  {
421  static const CHAR dllA[] = "Dll";
422  static const CHAR bogusDll_A[] = "bogus.dll";
423  static const CHAR bogus2Dll_A[] = "bogus2.dll";
424  CHAR dllBuf[MAX_PATH];
425  DWORD type, size;
426  LPSTR ptr;
427 
428  size = ARRAY_SIZE(dllBuf);
429  rc = RegQueryValueExA(key, dllA, NULL, &type, (LPBYTE)dllBuf, &size);
430  ok(rc == 0,
431  "Expected Dll value to exist, RegQueryValueExA failed: %d\n", rc);
432  ok(type == REG_MULTI_SZ, "Expected type REG_MULTI_SZ, got %d\n", type);
433  /* bogusDll was registered first, so that should be first */
434  ptr = dllBuf;
435  ok(!lstrcmpiA(ptr, bogusDll_A), "Unexpected dll\n");
436  ptr += lstrlenA(ptr) + 1;
437  ok(!lstrcmpiA(ptr, bogus2Dll_A), "Unexpected dll\n");
438  RegCloseKey(key);
439  }
440  /* Unregister both of them */
441  ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
442  bogusDll);
443  ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
444  GetLastError());
445  ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
446  bogus2Dll);
447  ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
448  GetLastError());
449  /* Now that they're both unregistered, unregistering should fail */
450  ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
451  bogusDll);
453  "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
454 
455  /* Repeat a few tests on the normal encoding type */
457  "CertDllOpenStoreProv", 0, bogusDll);
458  ok(ret, "CryptRegisterDefaultOIDFunction failed\n");
460  "CertDllOpenStoreProv", bogusDll);
461  ok(ret, "CryptUnregisterDefaultOIDFunction failed\n");
463  "CertDllOpenStoreProv", bogusDll);
465  "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
466 }
467 
469 {
470  BOOL ret;
472  void *funcAddr;
473  HCRYPTOIDFUNCADDR hFuncAddr;
474 
475  /* Crash
476  ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, NULL);
477  ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr, NULL);
478  ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, &hFuncAddr);
479  ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr,
480  &hFuncAddr);
481  */
482  set = CryptInitOIDFunctionSet("CertDllOpenStoreProv", 0);
483  ok(set != 0, "CryptInitOIDFunctionSet failed: %d\n", GetLastError());
484  /* This crashes if hFuncAddr is not 0 to begin with */
485  hFuncAddr = 0;
486  ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
487  &hFuncAddr);
489  "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
490  /* This fails with the normal encoding too, so built-in functions aren't
491  * returned.
492  */
494  &funcAddr, &hFuncAddr);
496  "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
497 
498  /* Even with a registered dll, this fails (since the dll doesn't exist) */
499  SetLastError(0xdeadbeef);
500  ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
501  bogusDll);
502  if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
503  skip("Need admin rights\n");
504  else
505  ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
506  ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
507  &hFuncAddr);
509  "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
510  CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv", bogusDll);
511 }
512 
513 static BOOL WINAPI countOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
514 {
515  (*(DWORD *)pvArg)++;
516  return TRUE;
517 }
518 
519 static BOOL WINAPI noOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
520 {
521  return FALSE;
522 }
523 
524 static void test_enumOIDInfo(void)
525 {
526  BOOL ret;
527  DWORD count = 0;
528 
529  if (!pCryptEnumOIDInfo)
530  {
531  win_skip("CryptEnumOIDInfo() is not available\n");
532  return;
533  }
534 
535  /* This crashes
536  ret = pCryptEnumOIDInfo(7, 0, NULL, NULL);
537  */
538 
539  /* Silly tests, check that more than one thing is enumerated */
540  ret = pCryptEnumOIDInfo(0, 0, &count, countOidInfo);
541  ok(ret && count > 0, "Expected more than item enumerated\n");
542  ret = pCryptEnumOIDInfo(0, 0, NULL, noOidInfo);
543  ok(!ret, "Expected FALSE\n");
544 }
545 
546 static void test_findOIDInfo(void)
547 {
548  static WCHAR sha256ECDSA[] = { 's','h','a','2','5','6','E','C','D','S','A',0 };
549  static WCHAR sha1[] = { 's','h','a','1',0 };
550  static CHAR oid_rsa_md5[] = szOID_RSA_MD5, oid_sha256[] = szOID_NIST_sha256;
551  static CHAR oid_ecdsa_sha256[] = szOID_ECDSA_SHA256;
552  ALG_ID alg = CALG_SHA1;
553  ALG_ID algs[2] = { CALG_MD5, CALG_RSA_SIGN };
554  const struct oid_info
555  {
556  DWORD key_type;
557  void *key;
558  const char *oid;
559  ALG_ID algid;
560  ALG_ID broken_algid;
561  } oid_test_info [] =
562  {
568  };
570  int i;
571 
572  info = CryptFindOIDInfo(0, NULL, 0);
573  ok(info == NULL, "Expected NULL\n");
574 
575  for (i = 0; i < ARRAY_SIZE(oid_test_info); i++)
576  {
577  const struct oid_info *test = &oid_test_info[i];
578 
579  info = CryptFindOIDInfo(test->key_type, test->key, 0);
580  ok(info != NULL, "Failed to find %s.\n", test->oid);
581  if (info)
582  {
583  ok(!strcmp(info->pszOID, test->oid), "Unexpected OID %s, expected %s\n", info->pszOID, test->oid);
584  ok(U(*info).Algid == test->algid || broken(U(*info).Algid == test->broken_algid),
585  "Unexpected Algid %d, expected %d\n", U(*info).Algid, test->algid);
586  }
587  }
588 
589  info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_ecdsa_sha256, 0);
590  if (info)
591  {
592  DWORD *data;
593 
594  ok(info->cbSize == sizeof(*info), "Unexpected structure size %d.\n", info->cbSize);
595  ok(!strcmp(info->pszOID, oid_ecdsa_sha256), "Expected %s, got %s\n", oid_ecdsa_sha256, info->pszOID);
596  ok(!lstrcmpW(info->pwszName, sha256ECDSA), "Expected %s, got %s\n",
598  ok(info->dwGroupId == CRYPT_SIGN_ALG_OID_GROUP_ID,
599  "Expected CRYPT_SIGN_ALG_OID_GROUP_ID, got %u\n", info->dwGroupId);
600  ok(U(*info).Algid == CALG_OID_INFO_CNG_ONLY,
601  "Expected CALG_OID_INFO_CNG_ONLY, got %d\n", U(*info).Algid);
602 
603  data = (DWORD *)info->ExtraInfo.pbData;
604  ok(info->ExtraInfo.cbData == 8, "Expected 8, got %d\n", info->ExtraInfo.cbData);
605  ok(data[0] == CALG_OID_INFO_PARAMETERS, "Expected CALG_OID_INFO_PARAMETERS, got %x\n", data[0]);
607  "Expected CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG, got %x\n", data[1]);
608 
609  ok(!lstrcmpW(info->pwszCNGAlgid, BCRYPT_SHA256_ALGORITHM), "Expected %s, got %s\n",
611  ok(!lstrcmpW(info->pwszCNGExtraAlgid, CRYPT_OID_INFO_ECC_PARAMETERS_ALGORITHM), "Expected %s, got %s\n",
613  }
614  else
615  win_skip("Host does not support ECDSA_SHA256, skipping test\n");
616 }
617 
618 static void test_registerOIDInfo(void)
619 {
620  static const WCHAR winetestW[] = { 'w','i','n','e','t','e','s','t',0 };
621  static char test_oid[] = "1.2.3.4.5.6.7.8.9.10";
622  CRYPT_OID_INFO info1;
623  const CRYPT_OID_INFO *info2;
624  HKEY key;
625  DWORD ret, size, type, value;
626  char buf[256];
627 
628  SetLastError(0xdeadbeef);
630  ok(!ret, "should fail\n");
631  ok(GetLastError() == E_INVALIDARG, "got %#x\n", GetLastError());
632 
633  memset(&info1, 0, sizeof(info1));
634  SetLastError(0xdeadbeef);
635  ret = CryptUnregisterOIDInfo(&info1);
636  ok(!ret, "should fail\n");
637  ok(GetLastError() == E_INVALIDARG, "got %#x\n", GetLastError());
638 
639  info1.cbSize = sizeof(info1);
640  SetLastError(0xdeadbeef);
641  ret = CryptUnregisterOIDInfo(&info1);
642  ok(!ret, "should fail\n");
643  ok(GetLastError() == E_INVALIDARG, "got %#x\n", GetLastError());
644 
645  info1.pszOID = test_oid;
646  SetLastError(0xdeadbeef);
647  ret = CryptUnregisterOIDInfo(&info1);
648  ok(!ret, "should fail\n");
649  ok(GetLastError() == ERROR_FILE_NOT_FOUND, "got %u\n", GetLastError());
650 
651  info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
652  ok(!info2, "should fail\n");
653 
654  SetLastError(0xdeadbeef);
655  /* While it succeeds, the next call does not write anything to the
656  * registry on Windows because dwGroupId == 0.
657  */
658  ret = CryptRegisterOIDInfo(&info1, 0);
659  ok(ret, "got %u\n", GetLastError());
660 
661  ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
662  ok(ret == ERROR_FILE_NOT_FOUND, "got %u\n", ret);
663 
664  info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
665  ok(!info2, "should fail\n");
666 
667  info1.pwszName = winetestW;
669  SetLastError(0xdeadbeef);
671  if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
672  {
673  skip("Need admin rights\n");
674  return;
675  }
676  ok(ret, "got %u\n", GetLastError());
677 
678  /* It looks like crypt32 reads the OID info from registry only on load,
679  * and CryptFindOIDInfo will find the registered OID on next run
680  */
681  info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
682  ok(!info2, "should fail\n");
683 
684  ret = RegCreateKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
685  ok(!ret, "got %u\n", ret);
686 
687  memset(buf, 0, sizeof(buf));
688  size = sizeof(buf);
689  ret = RegQueryValueExA(key, "Name", NULL, &type, (BYTE *)buf, &size);
690  ok(!ret, "got %u\n", ret);
691  ok(type == REG_SZ, "got %u\n", type);
692  ok(!strcmp(buf, "winetest"), "got %s\n", buf);
693 
694  value = 0xdeadbeef;
695  size = sizeof(value);
696  ret = RegQueryValueExA(key, "Flags", NULL, &type, (BYTE *)&value, &size);
697  ok(!ret, "got %u\n", ret);
698  ok(type == REG_DWORD, "got %u\n", type);
699  ok(value == 1, "got %u\n", value);
700 
701  RegCloseKey(key);
702 
703  CryptUnregisterOIDInfo(&info1);
704 
705  ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
706  ok(ret == ERROR_FILE_NOT_FOUND, "got %u\n", ret);
707 }
708 
710 {
711  HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
712  pCryptEnumOIDInfo = (void*)GetProcAddress(hCrypt32, "CryptEnumOIDInfo");
713 
714  testOIDToAlgID();
715  testAlgIDToOID();
724 }
GLenum func
Definition: glext.h:6028
LONG WINAPI RegOpenKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3272
static char oid_rsa_md5[]
Definition: msg.c:34
HCRYPTOIDFUNCSET WINAPI CryptInitOIDFunctionSet(LPCSTR pszFuncName, DWORD dwFlags)
Definition: oid.c:114
static int funky(int x)
Definition: oid.c:227
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4041
#define CALG_RC2
Definition: wincrypt.h:1829
#define szOID_OIWSEC_rsaXchg
Definition: wincrypt.h:3096
static const struct OIDToAlgID oidToAlgID[]
Definition: oid.c:44
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define szOID_RSA_MD4RSA
Definition: wincrypt.h:3020
#define szOID_NIST_sha256
Definition: wincrypt.h:3351
#define szOID_X957_DSA
Definition: wincrypt.h:3061
BOOL WINAPI CryptUnregisterDefaultOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, LPCWSTR pwszDll)
Definition: oid.c:1142
#define TRUE
Definition: types.h:120
#define CALG_3DES
Definition: wincrypt.h:1830
#define CRYPT_HASH_ALG_OID_GROUP_ID
Definition: wincrypt.h:1684
static void test_installOIDFunctionAddress(void)
Definition: oid.c:232
int WINAPI lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:42
unsigned int ALG_ID
Definition: wincrypt.h:45
LPCSTR oid
Definition: oid.c:38
static void test_findOIDInfo(void)
Definition: oid.c:546
BOOL WINAPI CryptRegisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, LPCSTR pszOID, LPCWSTR pwszDll, LPCSTR pszOverrideFuncName)
Definition: oid.c:647
#define szOID_OIWSEC_desCBC
Definition: wincrypt.h:3081
static const WCHAR sha256ECDSA[]
Definition: oid.c:1247
#define CALG_DSS_SIGN
Definition: wincrypt.h:1817
BOOL WINAPI CryptRegisterOIDInfo(PCCRYPT_OID_INFO info, DWORD flags)
Definition: oid.c:750
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define CALG_SHA_384
Definition: wincrypt.h:1814
Definition: wincrypt.h:1354
static const WCHAR bogus2Dll[]
Definition: oid.c:99
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
#define szOID_OIWSEC_shaRSA
Definition: wincrypt.h:3089
GLuint GLuint GLsizei count
Definition: gl.h:1545
static void test_getDefaultOIDFunctionAddress(void)
Definition: oid.c:468
#define CRYPT_OID_INFO_SIGN_KEY
Definition: wincrypt.h:1705
char CHAR
Definition: xmlstorage.h:175
uint8_t entry
Definition: isohybrid.c:63
#define U(x)
Definition: wordpad.c:44
#define szOID_OIWSEC_md4RSA
Definition: wincrypt.h:3077
#define szOID_OIWSEC_dsa
Definition: wincrypt.h:3086
#define szOID_RSA_RC4
Definition: wincrypt.h:3055
#define szOID_RSA_SMIMEalgCMS3DESwrap
Definition: wincrypt.h:3049
#define wine_dbgstr_w
Definition: kernel32.h:34
static const WCHAR CRYPT_OID_INFO_ECC_PARAMETERS_ALGORITHM[]
Definition: wincrypt.h:1394
#define CALG_RSA_SIGN
Definition: wincrypt.h:1816
#define CALG_RC4
Definition: wincrypt.h:1837
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define szOID_OIWSEC_sha1
Definition: wincrypt.h:3100
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define BCRYPT_SHA256_ALGORITHM
Definition: bcrypt.h:75
#define test
Definition: rosglue.h:37
#define PKCS_7_ASN_ENCODING
Definition: wincrypt.h:2299
BOOL WINAPI CryptInstallOIDFunctionAddress(HMODULE hModule, DWORD dwEncodingType, LPCSTR pszFuncName, DWORD cFuncEntry, const CRYPT_OID_FUNC_ENTRY rgFuncEntry[], DWORD dwFlags)
Definition: oid.c:237
static void testOIDToAlgID(void)
Definition: oid.c:101
char * LPSTR
Definition: xmlstorage.h:182
DWORD altAlgID
Definition: oid.c:41
#define szOID_RSA_SMIMEalgCMSRC2wrap
Definition: wincrypt.h:3050
#define szOID_INFOSEC_mosaicKMandUpdSig
Definition: wincrypt.h:3132
struct _test_info info[]
Definition: SetCursorPos.c:19
static const WCHAR sha1[]
Definition: oid.c:1219
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
BOOL WINAPI CryptGetDefaultOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet, DWORD dwEncodingType, LPCWSTR pwszDll, DWORD dwFlags, void **ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
Definition: oid.c:511
#define CRYPT_INSTALL_OID_INFO_BEFORE_FLAG
Definition: wincrypt.h:2538
static const WCHAR bogusDll[]
Definition: oid.c:98
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define szOID_NIST_sha384
Definition: wincrypt.h:3352
unsigned char * LPBYTE
Definition: typedefs.h:52
#define CALG_MD2
Definition: wincrypt.h:1803
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
#define szOID_RSA_MD2
Definition: wincrypt.h:3051
#define szOID_RSA_SMIMEalgESDH
Definition: wincrypt.h:3048
unsigned int BOOL
Definition: ntddk_ex.h:94
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define szOID_OIWDIR_md2RSA
Definition: wincrypt.h:3109
static PVOID ptr
Definition: dispmode.c:27
#define ok(value,...)
#define E_INVALIDARG
Definition: ddrawi.h:101
BOOL WINAPI CryptGetDefaultOIDDllList(HCRYPTOIDFUNCSET hFuncSet, DWORD dwEncodingType, LPWSTR pwszDllList, DWORD *pcchDllList)
Definition: oid.c:193
smooth NULL
Definition: ftsmooth.c:416
static void test_oidFunctionSet(void)
Definition: oid.c:156
#define CALG_DES
Definition: wincrypt.h:1828
#define CALG_RSA_KEYX
Definition: wincrypt.h:1824
#define szOID_RSA_MD4
Definition: wincrypt.h:3052
static const WCHAR winetestW[]
Definition: shelldispatch.c:47
const char * LPCSTR
Definition: xmlstorage.h:183
#define CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG
Definition: wincrypt.h:1700
#define szOID_ECDSA_SHA256
Definition: wincrypt.h:3066
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1180
BOOL WINAPI CryptUnregisterOIDInfo(PCCRYPT_OID_INFO info)
Definition: oid.c:708
#define szOID_OIWSEC_md5RSA
Definition: wincrypt.h:3078
#define szOID_RSA_RC2CBC
Definition: wincrypt.h:3054
GLsizeiptr size
Definition: glext.h:5919
#define CALG_DH_SF
Definition: wincrypt.h:1819
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
BOOL WINAPI CryptUnregisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, LPCSTR pszOID)
Definition: oid.c:831
__wchar_t WCHAR
Definition: xmlstorage.h:180
LPCWSTR pwszName
Definition: wincrypt.h:1405
static BOOL WINAPI countOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
Definition: oid.c:513
static const struct OIDToAlgID algIDToOID[]
Definition: oid.c:83
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:8
static UINT set(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device, struct ctab_constant *constant, const void **indata, D3DXPARAMETER_TYPE intype, UINT *size, UINT incol, D3DXPARAMETER_CLASS inclass, UINT index, BOOL is_pointer)
Definition: shader.c:1095
#define szOID_OIWSEC_shaDSA
Definition: wincrypt.h:3087
unsigned long DWORD
Definition: ntddk_ex.h:95
#define CALG_SHA_256
Definition: wincrypt.h:1813
#define SetLastError(x)
Definition: compat.h:409
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
DWORD algID
Definition: oid.c:40
Definition: oid.c:36
int ret
LPCSTR altOid
Definition: oid.c:39
#define szOID_OIWSEC_sha1RSASign
Definition: wincrypt.h:3103
HKEY key
Definition: reg.c:42
#define CALG_OID_INFO_PARAMETERS
Definition: wincrypt.h:1374
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
unsigned char BYTE
Definition: mem.h:68
#define CALG_MD5
Definition: wincrypt.h:1805
#define szOID_OIWSEC_md4RSA2
Definition: wincrypt.h:3079
#define CRYPT_OID_INFO_OID_KEY
Definition: wincrypt.h:1702
#define szOID_RSA_SHA1RSA
Definition: wincrypt.h:3022
#define szOID_RSA_MD5
Definition: wincrypt.h:3053
#define szOID_NIST_sha512
Definition: wincrypt.h:3353
GLsizei const GLfloat * value
Definition: glext.h:6069
static void set1(uint8 *data, int x, int y)
Definition: nanoxwin.c:811
#define szOID_RSA_MD5RSA
Definition: wincrypt.h:3021
#define broken(x)
Definition: _sntprintf.h:21
#define szOID_OIWSEC_sha
Definition: wincrypt.h:3092
START_TEST(oid)
Definition: oid.c:709
LONG WINAPI RegDeleteKeyA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey)
Definition: reg.c:1225
static void test_enumOIDInfo(void)
Definition: oid.c:524
#define szOID_RSA_DES_EDE3_CBC
Definition: wincrypt.h:3056
#define CALG_OID_INFO_CNG_ONLY
Definition: wincrypt.h:1373
DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId)
Definition: oid.c:1901
#define ALG_CLASS_SIGNATURE
Definition: wincrypt.h:1715
#define szOID_ANSI_X942_DH
Definition: wincrypt.h:3059
LPCSTR WINAPI CertAlgIdToOID(DWORD dwAlgId)
Definition: oid.c:1888
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define CALG_MD4
Definition: wincrypt.h:1804
#define CALG_SHA_512
Definition: wincrypt.h:1815
#define ARRAY_SIZE(a)
Definition: main.h:24
BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr, DWORD dwFlags)
Definition: oid.c:468
#define CALG_SHA1
Definition: wincrypt.h:1807
#define szOID_X957_SHA1DSA
Definition: wincrypt.h:3062
static BOOL(WINAPI *pCryptEnumOIDInfo)(DWORD
#define szOID_OIWSEC_dsaSHA1
Definition: wincrypt.h:3101
static BOOL WINAPI noOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
Definition: oid.c:519
#define X509_CERT
Definition: wincrypt.h:3365
#define CALG_SHA
Definition: wincrypt.h:1806
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define CRYPT_OID_INFO_ALGID_KEY
Definition: wincrypt.h:1704
#define skip(...)
#define ALG_TYPE_ANY
Definition: wincrypt.h:1722
#define szOID_RSA_DH
Definition: wincrypt.h:3027
static void test_registerDefaultOIDFunction(void)
Definition: oid.c:376
#define CRYPT_SIGN_ALG_OID_GROUP_ID
Definition: wincrypt.h:1687
BOOL WINAPI CryptGetOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet, DWORD dwEncodingType, LPCSTR pszOID, DWORD dwFlags, void **ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
Definition: oid.c:387
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define GetProcAddress(x, y)
Definition: compat.h:410
#define szOID_INFOSEC_mosaicUpdatedSig
Definition: wincrypt.h:3131
int(* funcY)(int)
Definition: oid.c:225
PCCRYPT_OID_INFO WINAPI CryptFindOIDInfo(DWORD dwKeyType, void *pvKey, DWORD dwGroupId)
Definition: oid.c:1799
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define CRYPT_OID_INFO_NAME_KEY
Definition: wincrypt.h:1703
#define szOID_RSA_RSA
Definition: wincrypt.h:3015
static void test_registerOIDInfo(void)
Definition: oid.c:618
static void test_registerOIDFunction(void)
Definition: oid.c:293
#define CRYPT_DEFAULT_OID
Definition: wincrypt.h:2535
static void PFN_CRYPT_ENUM_OID_INFO
Definition: oid.c:33
Definition: _set.h:46
#define memset(x, y, z)
Definition: compat.h:39
#define REG_DWORD
Definition: sdbapi.c:596
#define szOID_RSA_MD2RSA
Definition: wincrypt.h:3019
#define win_skip
Definition: test.h:141
Definition: dsound.c:943
#define HeapFree(x, y, z)
Definition: compat.h:394
BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, DWORD dwIndex, LPCWSTR pwszDll)
Definition: oid.c:1109
static void testAlgIDToOID(void)
Definition: oid.c:118
static DWORD
Definition: oid.c:33
Definition: path.c:42
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define CALG_DH_EPHEM
Definition: wincrypt.h:1820
#define REG_SZ
Definition: layer.c:22