ea30d9ccd45eddfbe578c0af94771d265ae89741
[reactos.git] / dll / win32 / crypt32 / oid.c
1 /*
2 * Copyright 2002 Mike McCormack for CodeWeavers
3 * Copyright 2005-2006 Juan Lang
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #include <stdio.h>
24 #include <stdarg.h>
25 #define NONAMELESSUNION
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wincrypt.h"
29 #include "winreg.h"
30 #include "winuser.h"
31 #include "wine/debug.h"
32 #include "wine/list.h"
33 #include "crypt32_private.h"
34 #include "cryptres.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
37
38 static const WCHAR DllW[] = { 'D','l','l',0 };
39
40 static void init_oid_info(void);
41 static void free_function_sets(void);
42 static void free_oid_info(void);
43
44 void crypt_oid_init(void)
45 {
46 init_oid_info();
47 }
48
49 void crypt_oid_free(void)
50 {
51 free_function_sets();
52 free_oid_info();
53 }
54
55 static CRITICAL_SECTION funcSetCS;
56 static CRITICAL_SECTION_DEBUG funcSetCSDebug =
57 {
58 0, 0, &funcSetCS,
59 { &funcSetCSDebug.ProcessLocksList, &funcSetCSDebug.ProcessLocksList },
60 0, 0, { (DWORD_PTR)(__FILE__ ": funcSetCS") }
61 };
62 static CRITICAL_SECTION funcSetCS = { &funcSetCSDebug, -1, 0, 0, 0, 0 };
63 static struct list funcSets = { &funcSets, &funcSets };
64
65 struct OIDFunctionSet
66 {
67 LPSTR name;
68 CRITICAL_SECTION cs; /* protects functions */
69 struct list functions;
70 struct list next;
71 };
72
73 struct OIDFunction
74 {
75 DWORD encoding;
76 CRYPT_OID_FUNC_ENTRY entry;
77 struct list next;
78 };
79
80 static const WCHAR ROOT[] = {'R','O','O','T',0};
81 static const WCHAR MY[] = {'M','Y',0};
82 static const WCHAR CA[] = {'C','A',0};
83 static const WCHAR ADDRESSBOOK[] = {'A','D','D','R','E','S','S','B','O','O','K',0};
84 static const WCHAR TRUSTEDPUBLISHER[] = {'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r',0};
85 static const WCHAR DISALLOWED[] = {'D','i','s','a','l','l','o','w','e','d',0};
86 static const LPCWSTR LocalizedKeys[] = {ROOT,MY,CA,ADDRESSBOOK,TRUSTEDPUBLISHER,DISALLOWED};
87 static WCHAR LocalizedNames[sizeof(LocalizedKeys)/sizeof(LocalizedKeys[0])][256];
88
89 static void free_function_sets(void)
90 {
91 struct OIDFunctionSet *setCursor, *setNext;
92
93 LIST_FOR_EACH_ENTRY_SAFE(setCursor, setNext, &funcSets,
94 struct OIDFunctionSet, next)
95 {
96 struct OIDFunction *functionCursor, *funcNext;
97
98 list_remove(&setCursor->next);
99 CryptMemFree(setCursor->name);
100 LIST_FOR_EACH_ENTRY_SAFE(functionCursor, funcNext,
101 &setCursor->functions, struct OIDFunction, next)
102 {
103 list_remove(&functionCursor->next);
104 CryptMemFree(functionCursor);
105 }
106 setCursor->cs.DebugInfo->Spare[0] = 0;
107 DeleteCriticalSection(&setCursor->cs);
108 CryptMemFree(setCursor);
109 }
110 }
111
112 /* There is no free function associated with this; therefore, the sets are
113 * freed when crypt32.dll is unloaded.
114 */
115 HCRYPTOIDFUNCSET WINAPI CryptInitOIDFunctionSet(LPCSTR pszFuncName,
116 DWORD dwFlags)
117 {
118 struct OIDFunctionSet *cursor, *ret = NULL;
119
120 TRACE("(%s, %x)\n", debugstr_a(pszFuncName), dwFlags);
121
122 EnterCriticalSection(&funcSetCS);
123 LIST_FOR_EACH_ENTRY(cursor, &funcSets, struct OIDFunctionSet, next)
124 {
125 if (!strcasecmp(pszFuncName, cursor->name))
126 {
127 ret = cursor;
128 break;
129 }
130 }
131 if (!ret)
132 {
133 ret = CryptMemAlloc(sizeof(struct OIDFunctionSet));
134 if (ret)
135 {
136 memset(ret, 0, sizeof(*ret));
137 ret->name = CryptMemAlloc(strlen(pszFuncName) + 1);
138 if (ret->name)
139 {
140 InitializeCriticalSection(&ret->cs);
141 ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": OIDFunctionSet.cs");
142 list_init(&ret->functions);
143 strcpy(ret->name, pszFuncName);
144 list_add_tail(&funcSets, &ret->next);
145 }
146 else
147 {
148 CryptMemFree(ret);
149 ret = NULL;
150 }
151 }
152 }
153 LeaveCriticalSection(&funcSetCS);
154
155 return ret;
156 }
157
158 static char *CRYPT_GetKeyName(DWORD dwEncodingType, LPCSTR pszFuncName,
159 LPCSTR pszOID)
160 {
161 static const char szEncodingTypeFmt[] =
162 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\%s";
163 UINT len;
164 char numericOID[7]; /* enough for "#65535" */
165 const char *oid;
166 LPSTR szKey;
167
168 /* MSDN says the encoding type is a mask, but it isn't treated that way.
169 * (E.g., if dwEncodingType were 3, the key names "EncodingType 1" and
170 * "EncodingType 2" would be expected if it were a mask. Instead native
171 * stores values in "EncodingType 3".
172 */
173 if (IS_INTOID(pszOID))
174 {
175 snprintf(numericOID, sizeof(numericOID), "#%d", LOWORD(pszOID));
176 oid = numericOID;
177 }
178 else
179 oid = pszOID;
180
181 /* This is enough: the lengths of the two string parameters are explicitly
182 * counted, and we need up to five additional characters for the encoding
183 * type. These are covered by the "%d", "%s", and "%s" characters in the
184 * format specifier that are removed by sprintf.
185 */
186 len = sizeof(szEncodingTypeFmt) + lstrlenA(pszFuncName) + lstrlenA(oid);
187 szKey = CryptMemAlloc(len);
188 if (szKey)
189 sprintf(szKey, szEncodingTypeFmt,
190 GET_CERT_ENCODING_TYPE(dwEncodingType), pszFuncName, oid);
191 return szKey;
192 }
193
194 BOOL WINAPI CryptGetDefaultOIDDllList(HCRYPTOIDFUNCSET hFuncSet,
195 DWORD dwEncodingType, LPWSTR pwszDllList, DWORD *pcchDllList)
196 {
197 BOOL ret = TRUE;
198 struct OIDFunctionSet *set = hFuncSet;
199 char *keyName;
200 HKEY key;
201 LSTATUS rc;
202
203 TRACE("(%p, %d, %p, %p)\n", hFuncSet, dwEncodingType, pwszDllList,
204 pcchDllList);
205
206 keyName = CRYPT_GetKeyName(dwEncodingType, set->name, "DEFAULT");
207 rc = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, NULL, 0,
208 KEY_READ, NULL, &key, NULL);
209 if (!rc)
210 {
211 DWORD size = *pcchDllList * sizeof(WCHAR);
212
213 rc = RegQueryValueExW(key, DllW, NULL, NULL, (LPBYTE)pwszDllList,
214 &size);
215 if (!rc)
216 *pcchDllList = size / sizeof(WCHAR);
217 else
218 {
219 /* No value, return an empty list */
220 if (pwszDllList && *pcchDllList)
221 *pwszDllList = '\0';
222 *pcchDllList = 1;
223 }
224 RegCloseKey(key);
225 }
226 else
227 {
228 /* No value, return an empty list */
229 if (pwszDllList && *pcchDllList)
230 *pwszDllList = '\0';
231 *pcchDllList = 1;
232 }
233 CryptMemFree(keyName);
234
235 return ret;
236 }
237
238 BOOL WINAPI CryptInstallOIDFunctionAddress(HMODULE hModule,
239 DWORD dwEncodingType, LPCSTR pszFuncName, DWORD cFuncEntry,
240 const CRYPT_OID_FUNC_ENTRY rgFuncEntry[], DWORD dwFlags)
241 {
242 BOOL ret = TRUE;
243 struct OIDFunctionSet *set;
244
245 TRACE("(%p, %d, %s, %d, %p, %08x)\n", hModule, dwEncodingType,
246 debugstr_a(pszFuncName), cFuncEntry, rgFuncEntry, dwFlags);
247
248 set = CryptInitOIDFunctionSet(pszFuncName, 0);
249 if (set)
250 {
251 DWORD i;
252
253 EnterCriticalSection(&set->cs);
254 for (i = 0; ret && i < cFuncEntry; i++)
255 {
256 struct OIDFunction *func;
257
258 if (!IS_INTOID(rgFuncEntry[i].pszOID))
259 func = CryptMemAlloc(sizeof(struct OIDFunction)
260 + strlen(rgFuncEntry[i].pszOID) + 1);
261 else
262 func = CryptMemAlloc(sizeof(struct OIDFunction));
263 if (func)
264 {
265 func->encoding = GET_CERT_ENCODING_TYPE(dwEncodingType);
266 if (!IS_INTOID(rgFuncEntry[i].pszOID))
267 {
268 LPSTR oid;
269
270 oid = (LPSTR)((LPBYTE)func + sizeof(*func));
271 strcpy(oid, rgFuncEntry[i].pszOID);
272 func->entry.pszOID = oid;
273 }
274 else
275 func->entry.pszOID = rgFuncEntry[i].pszOID;
276 func->entry.pvFuncAddr = rgFuncEntry[i].pvFuncAddr;
277 list_add_tail(&set->functions, &func->next);
278 }
279 else
280 ret = FALSE;
281 }
282 LeaveCriticalSection(&set->cs);
283 }
284 else
285 ret = FALSE;
286 return ret;
287 }
288
289 struct FuncAddr
290 {
291 HMODULE lib;
292 LPWSTR dllList;
293 LPWSTR currentDll;
294 };
295
296 static BOOL CRYPT_GetFuncFromReg(DWORD dwEncodingType, LPCSTR pszOID,
297 LPCSTR szFuncName, LPVOID *ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
298 {
299 BOOL ret = FALSE;
300 char *keyName;
301 const char *funcName;
302 HKEY key;
303 LSTATUS rc;
304
305 keyName = CRYPT_GetKeyName(dwEncodingType, szFuncName, pszOID);
306 rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &key);
307 if (!rc)
308 {
309 DWORD type, size = 0;
310
311 rc = RegQueryValueExA(key, "FuncName", NULL, &type, NULL, &size);
312 if ((!rc || rc == ERROR_MORE_DATA) && type == REG_SZ)
313 {
314 funcName = CryptMemAlloc(size);
315 rc = RegQueryValueExA(key, "FuncName", NULL, &type,
316 (LPBYTE)funcName, &size);
317 }
318 else
319 funcName = szFuncName;
320 rc = RegQueryValueExW(key, DllW, NULL, &type, NULL, &size);
321 if ((!rc || rc == ERROR_MORE_DATA) && type == REG_SZ)
322 {
323 LPWSTR dllName = CryptMemAlloc(size);
324
325 if (dllName)
326 {
327 rc = RegQueryValueExW(key, DllW, NULL, NULL,
328 (LPBYTE)dllName, &size);
329 if (!rc)
330 {
331 HMODULE lib;
332
333 /* This is a bit of a hack; MSDN describes a more
334 * complicated unload routine than this will allow.
335 * Still, this seems to suffice for now.
336 */
337 lib = LoadLibraryW(dllName);
338 if (lib)
339 {
340 *ppvFuncAddr = GetProcAddress(lib, funcName);
341 if (*ppvFuncAddr)
342 {
343 struct FuncAddr *addr =
344 CryptMemAlloc(sizeof(struct FuncAddr));
345
346 if (addr)
347 {
348 addr->lib = lib;
349 addr->dllList = addr->currentDll = NULL;
350 *phFuncAddr = addr;
351 ret = TRUE;
352 }
353 else
354 {
355 *phFuncAddr = NULL;
356 FreeLibrary(lib);
357 }
358 }
359 else
360 {
361 /* Unload the library, the caller doesn't want
362 * to unload it when the return value is NULL.
363 */
364 FreeLibrary(lib);
365 }
366 }
367 }
368 else
369 SetLastError(rc);
370 CryptMemFree(dllName);
371 }
372 }
373 else
374 SetLastError(rc);
375 if (funcName != szFuncName)
376 CryptMemFree((char *)funcName);
377 RegCloseKey(key);
378 }
379 else
380 SetLastError(rc);
381 CryptMemFree(keyName);
382 return ret;
383 }
384
385 BOOL WINAPI CryptGetOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet,
386 DWORD dwEncodingType, LPCSTR pszOID, DWORD dwFlags, void **ppvFuncAddr,
387 HCRYPTOIDFUNCADDR *phFuncAddr)
388 {
389 BOOL ret = FALSE;
390 struct OIDFunctionSet *set = hFuncSet;
391
392 TRACE("(%p, %d, %s, %08x, %p, %p)\n", hFuncSet, dwEncodingType,
393 debugstr_a(pszOID), dwFlags, ppvFuncAddr, phFuncAddr);
394
395 *ppvFuncAddr = NULL;
396 if (!(dwFlags & CRYPT_GET_INSTALLED_OID_FUNC_FLAG))
397 {
398 struct OIDFunction *function;
399
400 EnterCriticalSection(&set->cs);
401 LIST_FOR_EACH_ENTRY(function, &set->functions, struct OIDFunction, next)
402 {
403 if (function->encoding == GET_CERT_ENCODING_TYPE(dwEncodingType))
404 {
405 if (!IS_INTOID(pszOID))
406 {
407 if (!IS_INTOID(function->entry.pszOID) &&
408 !strcasecmp(function->entry.pszOID, pszOID))
409 {
410 *ppvFuncAddr = function->entry.pvFuncAddr;
411 *phFuncAddr = NULL; /* FIXME: what should it be? */
412 ret = TRUE;
413 break;
414 }
415 }
416 else if (function->entry.pszOID == pszOID)
417 {
418 *ppvFuncAddr = function->entry.pvFuncAddr;
419 *phFuncAddr = NULL; /* FIXME: what should it be? */
420 ret = TRUE;
421 break;
422 }
423 }
424 }
425 LeaveCriticalSection(&set->cs);
426 }
427 if (!*ppvFuncAddr)
428 ret = CRYPT_GetFuncFromReg(dwEncodingType, pszOID, set->name,
429 ppvFuncAddr, phFuncAddr);
430 TRACE("returning %d\n", ret);
431 return ret;
432 }
433
434 BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr,
435 DWORD dwFlags)
436 {
437 TRACE("(%p, %08x)\n", hFuncAddr, dwFlags);
438
439 /* FIXME: as MSDN states, need to check for DllCanUnloadNow in the DLL,
440 * and only unload it if it can be unloaded. Also need to implement ref
441 * counting on the functions.
442 */
443 if (hFuncAddr)
444 {
445 struct FuncAddr *addr = hFuncAddr;
446
447 CryptMemFree(addr->dllList);
448 FreeLibrary(addr->lib);
449 CryptMemFree(addr);
450 }
451 return TRUE;
452 }
453
454 static BOOL CRYPT_GetFuncFromDll(LPCWSTR dll, LPCSTR func, HMODULE *lib,
455 void **ppvFuncAddr)
456 {
457 BOOL ret = FALSE;
458
459 *lib = LoadLibraryW(dll);
460 if (*lib)
461 {
462 *ppvFuncAddr = GetProcAddress(*lib, func);
463 if (*ppvFuncAddr)
464 ret = TRUE;
465 else
466 {
467 FreeLibrary(*lib);
468 *lib = NULL;
469 }
470 }
471 return ret;
472 }
473
474 BOOL WINAPI CryptGetDefaultOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet,
475 DWORD dwEncodingType, LPCWSTR pwszDll, DWORD dwFlags, void **ppvFuncAddr,
476 HCRYPTOIDFUNCADDR *phFuncAddr)
477 {
478 struct OIDFunctionSet *set = hFuncSet;
479 BOOL ret = FALSE;
480
481 TRACE("(%p, %d, %s, %08x, %p, %p)\n", hFuncSet, dwEncodingType,
482 debugstr_w(pwszDll), dwFlags, ppvFuncAddr, phFuncAddr);
483
484 if (pwszDll)
485 {
486 HMODULE lib;
487
488 *phFuncAddr = NULL;
489 ret = CRYPT_GetFuncFromDll(pwszDll, set->name, &lib, ppvFuncAddr);
490 if (ret)
491 {
492 struct FuncAddr *addr = CryptMemAlloc(sizeof(struct FuncAddr));
493
494 if (addr)
495 {
496 addr->lib = lib;
497 addr->dllList = addr->currentDll = NULL;
498 *phFuncAddr = addr;
499 }
500 else
501 {
502 FreeLibrary(lib);
503 *ppvFuncAddr = NULL;
504 SetLastError(ERROR_OUTOFMEMORY);
505 ret = FALSE;
506 }
507 }
508 else
509 SetLastError(ERROR_FILE_NOT_FOUND);
510 }
511 else
512 {
513 struct FuncAddr *addr = *phFuncAddr;
514
515 if (!addr)
516 {
517 DWORD size;
518
519 ret = CryptGetDefaultOIDDllList(hFuncSet, dwEncodingType, NULL,
520 &size);
521 if (ret)
522 {
523 LPWSTR dllList = CryptMemAlloc(size * sizeof(WCHAR));
524
525 if (dllList)
526 {
527 ret = CryptGetDefaultOIDDllList(hFuncSet, dwEncodingType,
528 dllList, &size);
529 if (ret)
530 {
531 addr = CryptMemAlloc(sizeof(struct FuncAddr));
532 if (addr)
533 {
534 addr->dllList = dllList;
535 addr->currentDll = dllList;
536 addr->lib = NULL;
537 *phFuncAddr = addr;
538 }
539 else
540 {
541 CryptMemFree(dllList);
542 SetLastError(ERROR_OUTOFMEMORY);
543 ret = FALSE;
544 }
545 }
546 }
547 else
548 {
549 SetLastError(ERROR_OUTOFMEMORY);
550 ret = FALSE;
551 }
552 }
553 }
554 if (addr)
555 {
556 if (!*addr->currentDll)
557 {
558 CryptFreeOIDFunctionAddress(*phFuncAddr, 0);
559 SetLastError(ERROR_FILE_NOT_FOUND);
560 *phFuncAddr = NULL;
561 ret = FALSE;
562 }
563 else
564 {
565 /* FIXME: as elsewhere, can't free until DllCanUnloadNow says
566 * it's possible, and should defer unloading for some time to
567 * avoid repeated LoadLibrary/FreeLibrary on the same dll.
568 */
569 FreeLibrary(addr->lib);
570 ret = CRYPT_GetFuncFromDll(addr->currentDll, set->name,
571 &addr->lib, ppvFuncAddr);
572 if (ret)
573 {
574 /* Move past the current DLL */
575 addr->currentDll += lstrlenW(addr->currentDll) + 1;
576 *phFuncAddr = addr;
577 }
578 else
579 {
580 CryptFreeOIDFunctionAddress(*phFuncAddr, 0);
581 SetLastError(ERROR_FILE_NOT_FOUND);
582 *phFuncAddr = NULL;
583 }
584 }
585 }
586 }
587 return ret;
588 }
589
590 /***********************************************************************
591 * CryptRegisterOIDFunction (CRYPT32.@)
592 *
593 * Register the DLL and the functions it uses to cover the combination
594 * of encoding type, functionname and OID.
595 *
596 * PARAMS
597 * dwEncodingType [I] Encoding type to be used.
598 * pszFuncName [I] Name of the function to be registered.
599 * pszOID [I] OID of the function (numeric or string).
600 * pwszDll [I] The DLL that is to be registered.
601 * pszOverrideFuncName [I] Name of the function in the DLL.
602 *
603 * RETURNS
604 * Success: TRUE.
605 * Failure: FALSE. (Look at GetLastError()).
606 *
607 * NOTES
608 * Registry errors are always reported via SetLastError().
609 */
610 BOOL WINAPI CryptRegisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
611 LPCSTR pszOID, LPCWSTR pwszDll, LPCSTR pszOverrideFuncName)
612 {
613 LONG r;
614 HKEY hKey;
615 LPSTR szKey;
616
617 TRACE("(%x, %s, %s, %s, %s)\n", dwEncodingType, pszFuncName,
618 debugstr_a(pszOID), debugstr_w(pwszDll), pszOverrideFuncName);
619
620 /* Native does nothing pwszDll is NULL */
621 if (!pwszDll)
622 return TRUE;
623
624 /* I'm not matching MS bug for bug here, because I doubt any app depends on
625 * it: native "succeeds" if pszFuncName is NULL, but the nonsensical entry
626 * it creates would never be used.
627 */
628 if (!pszFuncName || !pszOID)
629 {
630 SetLastError(E_INVALIDARG);
631 return FALSE;
632 }
633
634 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
635 TRACE("Key name is %s\n", debugstr_a(szKey));
636
637 if (!szKey)
638 return FALSE;
639
640 r = RegCreateKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
641 CryptMemFree(szKey);
642
643 if (r != ERROR_SUCCESS) goto error_close_key;
644
645 /* write the values */
646 if (pszOverrideFuncName)
647 {
648 r = RegSetValueExA(hKey, "FuncName", 0, REG_SZ,
649 (const BYTE*)pszOverrideFuncName, lstrlenA(pszOverrideFuncName) + 1);
650 if (r != ERROR_SUCCESS) goto error_close_key;
651 }
652 r = RegSetValueExW(hKey, DllW, 0, REG_SZ, (const BYTE*) pwszDll,
653 (lstrlenW(pwszDll) + 1) * sizeof (WCHAR));
654
655 error_close_key:
656
657 RegCloseKey(hKey);
658
659 if (r != ERROR_SUCCESS)
660 {
661 SetLastError(r);
662 return FALSE;
663 }
664
665 return TRUE;
666 }
667
668 /***********************************************************************
669 * CryptRegisterOIDInfo (CRYPT32.@)
670 */
671 BOOL WINAPI CryptRegisterOIDInfo(PCCRYPT_OID_INFO pInfo, DWORD dwFlags)
672 {
673 FIXME("(%p, %x): stub\n", pInfo, dwFlags );
674 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
675 return FALSE;
676 }
677
678 /***********************************************************************
679 * CryptUnregisterOIDFunction (CRYPT32.@)
680 */
681 BOOL WINAPI CryptUnregisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
682 LPCSTR pszOID)
683 {
684 LPSTR szKey;
685 LONG rc;
686
687 TRACE("%x %s %s\n", dwEncodingType, debugstr_a(pszFuncName),
688 debugstr_a(pszOID));
689
690 if (!pszFuncName || !pszOID)
691 {
692 SetLastError(ERROR_INVALID_PARAMETER);
693 return FALSE;
694 }
695
696 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
697 rc = RegDeleteKeyA(HKEY_LOCAL_MACHINE, szKey);
698 CryptMemFree(szKey);
699 if (rc)
700 SetLastError(rc);
701 return rc ? FALSE : TRUE;
702 }
703
704 BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
705 LPCSTR pszOID, LPCWSTR pwszValueName, DWORD *pdwValueType, BYTE *pbValueData,
706 DWORD *pcbValueData)
707 {
708 LPSTR szKey;
709 LONG rc;
710 HKEY hKey;
711
712 TRACE("%x %s %s %s %p %p %p\n", dwEncodingType, debugstr_a(pszFuncName),
713 debugstr_a(pszOID), debugstr_w(pwszValueName), pdwValueType, pbValueData,
714 pcbValueData);
715
716 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
717 return TRUE;
718
719 if (!pszFuncName || !pszOID || !pwszValueName)
720 {
721 SetLastError(ERROR_INVALID_PARAMETER);
722 return FALSE;
723 }
724
725 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
726 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
727 CryptMemFree(szKey);
728 if (rc)
729 SetLastError(rc);
730 else
731 {
732 rc = RegQueryValueExW(hKey, pwszValueName, NULL, pdwValueType,
733 pbValueData, pcbValueData);
734 if (rc)
735 SetLastError(rc);
736 RegCloseKey(hKey);
737 }
738 return rc ? FALSE : TRUE;
739 }
740
741 BOOL WINAPI CryptSetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
742 LPCSTR pszOID, LPCWSTR pwszValueName, DWORD dwValueType,
743 const BYTE *pbValueData, DWORD cbValueData)
744 {
745 LPSTR szKey;
746 LONG rc;
747 HKEY hKey;
748
749 TRACE("%x %s %s %s %d %p %d\n", dwEncodingType, debugstr_a(pszFuncName),
750 debugstr_a(pszOID), debugstr_w(pwszValueName), dwValueType, pbValueData,
751 cbValueData);
752
753 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
754 return TRUE;
755
756 if (!pszFuncName || !pszOID || !pwszValueName)
757 {
758 SetLastError(ERROR_INVALID_PARAMETER);
759 return FALSE;
760 }
761
762 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
763 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
764 CryptMemFree(szKey);
765 if (rc)
766 SetLastError(rc);
767 else
768 {
769 rc = RegSetValueExW(hKey, pwszValueName, 0, dwValueType, pbValueData,
770 cbValueData);
771 if (rc)
772 SetLastError(rc);
773 RegCloseKey(hKey);
774 }
775 return rc ? FALSE : TRUE;
776 }
777
778 static LPCWSTR CRYPT_FindStringInMultiString(LPCWSTR multi, LPCWSTR toFind)
779 {
780 LPCWSTR ret = NULL, ptr;
781
782 for (ptr = multi; ptr && *ptr && !ret; ptr += lstrlenW(ptr) + 1)
783 {
784 if (!lstrcmpiW(ptr, toFind))
785 ret = ptr;
786 }
787 return ret;
788 }
789
790 static DWORD CRYPT_GetMultiStringCharacterLen(LPCWSTR multi)
791 {
792 DWORD ret;
793
794 if (multi)
795 {
796 LPCWSTR ptr;
797
798 /* Count terminating empty string */
799 ret = 1;
800 for (ptr = multi; *ptr; ptr += lstrlenW(ptr) + 1)
801 ret += lstrlenW(ptr) + 1;
802 }
803 else
804 ret = 0;
805 return ret;
806 }
807
808 static LPWSTR CRYPT_AddStringToMultiString(LPWSTR multi, LPCWSTR toAdd,
809 DWORD index)
810 {
811 LPWSTR ret;
812
813 if (!multi)
814 {
815 /* FIXME: ignoring index, is that okay? */
816 ret = CryptMemAlloc((lstrlenW(toAdd) + 2) * sizeof(WCHAR));
817 if (ret)
818 {
819 /* copy string, including NULL terminator */
820 memcpy(ret, toAdd, (lstrlenW(toAdd) + 1) * sizeof(WCHAR));
821 /* add terminating empty string */
822 *(ret + lstrlenW(toAdd) + 1) = 0;
823 }
824 }
825 else
826 {
827 DWORD len = CRYPT_GetMultiStringCharacterLen(multi);
828
829 ret = CryptMemRealloc(multi, (len + lstrlenW(toAdd) + 1) *
830 sizeof(WCHAR));
831 if (ret)
832 {
833 LPWSTR spotToAdd;
834
835 if (index == CRYPT_REGISTER_LAST_INDEX)
836 spotToAdd = ret + len - 1;
837 else
838 {
839 DWORD i;
840
841 /* FIXME: if index is too large for the string, toAdd is
842 * added to the end. Is that okay?
843 */
844 for (i = 0, spotToAdd = ret; i < index && *spotToAdd;
845 spotToAdd += lstrlenW(spotToAdd) + 1)
846 ;
847 }
848 if (spotToAdd)
849 {
850 /* Copy existing string "right" */
851 memmove(spotToAdd + lstrlenW(toAdd) + 1, spotToAdd,
852 (len - (spotToAdd - ret)) * sizeof(WCHAR));
853 /* Copy new string */
854 memcpy(spotToAdd, toAdd, (lstrlenW(toAdd) + 1) * sizeof(WCHAR));
855 }
856 else
857 {
858 CryptMemFree(ret);
859 ret = NULL;
860 }
861 }
862 }
863 return ret;
864 }
865
866 static BOOL CRYPT_RemoveStringFromMultiString(LPWSTR multi, LPCWSTR toRemove)
867 {
868 LPWSTR spotToRemove = (LPWSTR)CRYPT_FindStringInMultiString(multi,
869 toRemove);
870 BOOL ret;
871
872 if (spotToRemove)
873 {
874 DWORD len = CRYPT_GetMultiStringCharacterLen(multi);
875
876 if (spotToRemove + lstrlenW(toRemove) + 2 >= multi + len)
877 {
878 /* Removing last string in list, terminate multi string directly */
879 *spotToRemove = 0;
880 *(spotToRemove + 1) = 0;
881 }
882 else
883 {
884 LPCWSTR nextStr = spotToRemove + lstrlenW(toRemove) + 1;
885
886 /* Copy remainder of string "left" */
887 memmove(spotToRemove, nextStr,
888 (len - (nextStr - multi)) * sizeof(WCHAR));
889 }
890 ret = TRUE;
891 }
892 else
893 {
894 SetLastError(ERROR_FILE_NOT_FOUND);
895 ret = FALSE;
896 }
897 return ret;
898 }
899
900 static BOOL CRYPT_GetDefaultOIDKey(DWORD dwEncodingType, LPCSTR pszFuncName,
901 PHKEY key)
902 {
903 LPSTR keyName;
904 LONG r;
905
906 keyName = CRYPT_GetKeyName(dwEncodingType, pszFuncName, "DEFAULT");
907 TRACE("Key name is %s\n", debugstr_a(keyName));
908
909 if (!keyName)
910 return FALSE;
911
912 r = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, NULL, 0, KEY_ALL_ACCESS,
913 NULL, key, NULL);
914 CryptMemFree(keyName);
915 if (r != ERROR_SUCCESS)
916 {
917 SetLastError(r);
918 return FALSE;
919 }
920 return TRUE;
921 }
922
923 static LPWSTR CRYPT_GetDefaultOIDDlls(HKEY key)
924 {
925 LONG r;
926 DWORD type, size;
927 LPWSTR dlls;
928
929 r = RegQueryValueExW(key, DllW, NULL, &type, NULL, &size);
930 if (r == ERROR_SUCCESS && type == REG_MULTI_SZ)
931 {
932 dlls = CryptMemAlloc(size);
933 r = RegQueryValueExW(key, DllW, NULL, &type, (LPBYTE)dlls, &size);
934 if (r != ERROR_SUCCESS)
935 {
936 CryptMemFree(dlls);
937 dlls = NULL;
938 }
939 }
940 else
941 dlls = NULL;
942 return dlls;
943 }
944
945 static inline BOOL CRYPT_SetDefaultOIDDlls(HKEY key, LPCWSTR dlls)
946 {
947 DWORD len = CRYPT_GetMultiStringCharacterLen(dlls);
948 LONG r;
949
950 if ((r = RegSetValueExW(key, DllW, 0, REG_MULTI_SZ, (const BYTE *)dlls,
951 len * sizeof (WCHAR))))
952 SetLastError(r);
953 return r == ERROR_SUCCESS;
954 }
955
956 /***********************************************************************
957 * CryptRegisterDefaultOIDFunction (CRYPT32.@)
958 */
959 BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType,
960 LPCSTR pszFuncName, DWORD dwIndex, LPCWSTR pwszDll)
961 {
962 HKEY key;
963 LPWSTR dlls;
964 BOOL ret = FALSE;
965
966 TRACE("(%x, %s, %d, %s)\n", dwEncodingType, debugstr_a(pszFuncName),
967 dwIndex, debugstr_w(pwszDll));
968
969 if (!pwszDll)
970 {
971 SetLastError(E_INVALIDARG);
972 return FALSE;
973 }
974
975 if (!CRYPT_GetDefaultOIDKey(dwEncodingType, pszFuncName, &key))
976 return FALSE;
977
978 dlls = CRYPT_GetDefaultOIDDlls(key);
979 if (CRYPT_FindStringInMultiString(dlls, pwszDll))
980 SetLastError(ERROR_FILE_EXISTS);
981 else
982 {
983 dlls = CRYPT_AddStringToMultiString(dlls, pwszDll, dwIndex);
984 if (dlls)
985 ret = CRYPT_SetDefaultOIDDlls(key, dlls);
986 }
987 CryptMemFree(dlls);
988 RegCloseKey(key);
989 return ret;
990 }
991
992 BOOL WINAPI CryptUnregisterDefaultOIDFunction(DWORD dwEncodingType,
993 LPCSTR pszFuncName, LPCWSTR pwszDll)
994 {
995 HKEY key;
996 LPWSTR dlls;
997 BOOL ret;
998
999 TRACE("(%x, %s, %s)\n", dwEncodingType, debugstr_a(pszFuncName),
1000 debugstr_w(pwszDll));
1001
1002 if (!pwszDll)
1003 {
1004 SetLastError(E_INVALIDARG);
1005 return FALSE;
1006 }
1007
1008 if (!CRYPT_GetDefaultOIDKey(dwEncodingType, pszFuncName, &key))
1009 return FALSE;
1010
1011 dlls = CRYPT_GetDefaultOIDDlls(key);
1012 if ((ret = CRYPT_RemoveStringFromMultiString(dlls, pwszDll)))
1013 ret = CRYPT_SetDefaultOIDDlls(key, dlls);
1014 CryptMemFree(dlls);
1015 RegCloseKey(key);
1016 return ret;
1017 }
1018
1019 static void oid_init_localizednames(void)
1020 {
1021 unsigned int i;
1022
1023 for(i = 0; i < sizeof(LocalizedKeys)/sizeof(LPCWSTR); i++)
1024 {
1025 LoadStringW(hInstance, IDS_LOCALIZEDNAME_ROOT+i, LocalizedNames[i], 256);
1026 }
1027 }
1028
1029 /********************************************************************
1030 * CryptFindLocalizedName (CRYPT32.@)
1031 */
1032 LPCWSTR WINAPI CryptFindLocalizedName(LPCWSTR pwszCryptName)
1033 {
1034 unsigned int i;
1035
1036 for(i = 0; i < sizeof(LocalizedKeys)/sizeof(LPCWSTR); i++)
1037 {
1038 if(!lstrcmpiW(LocalizedKeys[i], pwszCryptName))
1039 {
1040 return LocalizedNames[i];
1041 }
1042 }
1043
1044 FIXME("No name for: %s - stub\n",debugstr_w(pwszCryptName));
1045 return NULL;
1046 }
1047
1048 static CRITICAL_SECTION oidInfoCS;
1049 static CRITICAL_SECTION_DEBUG oidInfoCSDebug =
1050 {
1051 0, 0, &oidInfoCS,
1052 { &oidInfoCSDebug.ProcessLocksList, &oidInfoCSDebug.ProcessLocksList },
1053 0, 0, { (DWORD_PTR)(__FILE__ ": oidInfoCS") }
1054 };
1055 static CRITICAL_SECTION oidInfoCS = { &oidInfoCSDebug, -1, 0, 0, 0, 0 };
1056 static struct list oidInfo = { &oidInfo, &oidInfo };
1057
1058 static const WCHAR tripledes[] = { '3','d','e','s',0 };
1059 static const WCHAR cms3deswrap[] = { 'C','M','S','3','D','E','S','w','r','a',
1060 'p',0 };
1061 static const WCHAR cmsrc2wrap[] = { 'C','M','S','R','C','2','w','r','a','p',0 };
1062 static const WCHAR des[] = { 'd','e','s',0 };
1063 static const WCHAR md2[] = { 'm','d','2',0 };
1064 static const WCHAR md4[] = { 'm','d','4',0 };
1065 static const WCHAR md5[] = { 'm','d','5',0 };
1066 static const WCHAR rc2[] = { 'r','c','2',0 };
1067 static const WCHAR rc4[] = { 'r','c','4',0 };
1068 static const WCHAR sha[] = { 's','h','a',0 };
1069 static const WCHAR sha1[] = { 's','h','a','1',0 };
1070 static const WCHAR RSA[] = { 'R','S','A',0 };
1071 static const WCHAR RSA_KEYX[] = { 'R','S','A','_','K','E','Y','X',0 };
1072 static const WCHAR RSA_SIGN[] = { 'R','S','A','_','S','I','G','N',0 };
1073 static const WCHAR DSA[] = { 'D','S','A',0 };
1074 static const WCHAR DSA_SIGN[] = { 'D','S','A','_','S','I','G','N',0 };
1075 static const WCHAR DH[] = { 'D','H',0 };
1076 static const WCHAR DSS[] = { 'D','S','S',0 };
1077 static const WCHAR mosaicKMandUpdSig[] =
1078 { 'm','o','s','a','i','c','K','M','a','n','d','U','p','d','S','i','g',0 };
1079 static const WCHAR ESDH[] = { 'E','S','D','H',0 };
1080 static const WCHAR NO_SIGN[] = { 'N','O','S','I','G','N',0 };
1081 static const WCHAR dsaSHA1[] = { 'd','s','a','S','H','A','1',0 };
1082 static const WCHAR md2RSA[] = { 'm','d','2','R','S','A',0 };
1083 static const WCHAR md4RSA[] = { 'm','d','4','R','S','A',0 };
1084 static const WCHAR md5RSA[] = { 'm','d','5','R','S','A',0 };
1085 static const WCHAR shaDSA[] = { 's','h','a','D','S','A',0 };
1086 static const WCHAR sha1DSA[] = { 's','h','a','1','D','S','A',0 };
1087 static const WCHAR shaRSA[] = { 's','h','a','R','S','A',0 };
1088 static const WCHAR sha1RSA[] = { 's','h','a','1','R','S','A',0 };
1089 static const WCHAR mosaicUpdatedSig[] =
1090 { 'm','o','s','a','i','c','U','p','d','a','t','e','d','S','i','g',0 };
1091 static const WCHAR CN[] = { 'C','N',0 };
1092 static const WCHAR L[] = { 'L',0 };
1093 static const WCHAR O[] = { 'O',0 };
1094 static const WCHAR OU[] = { 'O','U',0 };
1095 static const WCHAR E[] = { 'E',0 };
1096 static const WCHAR C[] = { 'C',0 };
1097 static const WCHAR S[] = { 'S',0 };
1098 static const WCHAR ST[] = { 'S','T',0 };
1099 static const WCHAR STREET[] = { 'S','T','R','E','E','T',0 };
1100 static const WCHAR T[] = { 'T',0 };
1101 static const WCHAR Title[] = { 'T','i','t','l','e',0 };
1102 static const WCHAR G[] = { 'G',0 };
1103 static const WCHAR GivenName[] = { 'G','i','v','e','n','N','a','m','e',0 };
1104 static const WCHAR I[] = { 'I',0 };
1105 static const WCHAR Initials[] = { 'I','n','i','t','i','a','l','s',0 };
1106 static const WCHAR SN[] = { 'S','N',0 };
1107 static const WCHAR DC[] = { 'D','C',0 };
1108 static const WCHAR Description[] =
1109 { 'D','e','s','c','r','i','p','t','i','o','n',0 };
1110 static const WCHAR PostalCode[] = { 'P','o','s','t','a','l','C','o','d','e',0 };
1111 static const WCHAR POBox[] = { 'P','O','B','o','x',0 };
1112 static const WCHAR Phone[] = { 'P','h','o','n','e',0 };
1113 static const WCHAR X21Address[] = { 'X','2','1','A','d','d','r','e','s','s',0 };
1114 static const WCHAR dnQualifier[] =
1115 { 'd','n','Q','u','a','l','i','f','i','e','r',0 };
1116 static const WCHAR Email[] = { 'E','m','a','i','l',0 };
1117 static const WCHAR GN[] = { 'G','N',0 };
1118
1119 static const DWORD noNullFlag = CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG;
1120 static const DWORD mosaicFlags = CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG |
1121 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG;
1122 static const CRYPT_DATA_BLOB noNullBlob = { sizeof(noNullFlag),
1123 (LPBYTE)&noNullFlag };
1124 static const CRYPT_DATA_BLOB mosaicFlagsBlob = { sizeof(mosaicFlags),
1125 (LPBYTE)&mosaicFlags };
1126
1127 static const DWORD rsaSign = CALG_RSA_SIGN;
1128 static const DWORD dssSign[2] = { CALG_DSS_SIGN,
1129 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG };
1130 static const DWORD mosaicSign[2] = { CALG_DSS_SIGN,
1131 CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG |
1132 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG };
1133 static const CRYPT_DATA_BLOB rsaSignBlob = { sizeof(rsaSign),
1134 (LPBYTE)&rsaSign };
1135 static const CRYPT_DATA_BLOB dssSignBlob = { sizeof(dssSign),
1136 (LPBYTE)dssSign };
1137 static const CRYPT_DATA_BLOB mosaicSignBlob = { sizeof(mosaicSign),
1138 (LPBYTE)mosaicSign };
1139
1140 static const DWORD ia5String[] = { CERT_RDN_IA5_STRING, 0 };
1141 static const DWORD numericString[] = { CERT_RDN_NUMERIC_STRING, 0 };
1142 static const DWORD printableString[] = { CERT_RDN_PRINTABLE_STRING, 0 };
1143 static const DWORD domainCompTypes[] = { CERT_RDN_IA5_STRING,
1144 CERT_RDN_UTF8_STRING, 0 };
1145 static const CRYPT_DATA_BLOB ia5StringBlob = { sizeof(ia5String),
1146 (LPBYTE)ia5String };
1147 static const CRYPT_DATA_BLOB numericStringBlob = { sizeof(numericString),
1148 (LPBYTE)numericString };
1149 static const CRYPT_DATA_BLOB printableStringBlob = { sizeof(printableString),
1150 (LPBYTE)printableString };
1151 static const CRYPT_DATA_BLOB domainCompTypesBlob = { sizeof(domainCompTypes),
1152 (LPBYTE)domainCompTypes };
1153
1154 static const struct OIDInfoConstructor {
1155 DWORD dwGroupId;
1156 LPCSTR pszOID;
1157 UINT Algid;
1158 LPCWSTR pwszName;
1159 const CRYPT_DATA_BLOB *blob;
1160 } oidInfoConstructors[] = {
1161 { 1, szOID_OIWSEC_sha1, CALG_SHA1, sha1, NULL },
1162 { 1, szOID_OIWSEC_sha1, CALG_SHA1, sha, NULL },
1163 { 1, szOID_OIWSEC_sha, CALG_SHA, sha, NULL },
1164 { 1, szOID_RSA_MD5, CALG_MD5, md5, NULL },
1165 { 1, szOID_RSA_MD4, CALG_MD4, md4, NULL },
1166 { 1, szOID_RSA_MD2, CALG_MD2, md2, NULL },
1167
1168 { 2, szOID_OIWSEC_desCBC, CALG_DES, des, NULL },
1169 { 2, szOID_RSA_DES_EDE3_CBC, CALG_3DES, tripledes, NULL },
1170 { 2, szOID_RSA_RC2CBC, CALG_RC2, rc2, NULL },
1171 { 2, szOID_RSA_RC4, CALG_RC4, rc4, NULL },
1172 { 2, szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES, cms3deswrap, NULL },
1173 { 2, szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2, cmsrc2wrap, NULL },
1174
1175 { 3, szOID_RSA_RSA, CALG_RSA_KEYX, RSA, NULL },
1176 { 3, szOID_X957_DSA, CALG_DSS_SIGN, DSA, &noNullBlob },
1177 { 3, szOID_ANSI_X942_DH, CALG_DH_SF, DH, &noNullBlob },
1178 { 3, szOID_RSA_RSA, CALG_RSA_KEYX, RSA_KEYX, NULL },
1179 { 3, szOID_RSA_RSA, CALG_RSA_SIGN, RSA, NULL },
1180 { 3, szOID_RSA_RSA, CALG_RSA_SIGN, RSA_SIGN, NULL },
1181 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSA, &noNullBlob },
1182 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSS, &noNullBlob },
1183 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSA_SIGN, &noNullBlob },
1184 { 3, szOID_RSA_DH, CALG_DH_SF, DH, &noNullBlob },
1185 { 3, szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX, RSA_KEYX, NULL },
1186 { 3, szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN, mosaicKMandUpdSig,
1187 &mosaicFlagsBlob },
1188 { 3, szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM, ESDH, &noNullBlob },
1189 { 3, szOID_PKIX_NO_SIGNATURE, CALG_NO_SIGN, NO_SIGN, NULL },
1190
1191 { 4, szOID_RSA_SHA1RSA, CALG_SHA1, sha1RSA, &rsaSignBlob },
1192 { 4, szOID_RSA_MD5RSA, CALG_MD5, md5RSA, &rsaSignBlob },
1193 { 4, szOID_X957_SHA1DSA, CALG_SHA1, sha1DSA, &dssSignBlob },
1194 { 4, szOID_OIWSEC_sha1RSASign, CALG_SHA1, sha1RSA, &rsaSignBlob },
1195 { 4, szOID_OIWSEC_sha1RSASign, CALG_SHA1, shaRSA, &rsaSignBlob },
1196 { 4, szOID_OIWSEC_shaRSA, CALG_SHA1, shaRSA, &rsaSignBlob },
1197 { 4, szOID_OIWSEC_md5RSA, CALG_MD5, md5RSA, &rsaSignBlob },
1198 { 4, szOID_RSA_MD2RSA, CALG_MD2, md2RSA, &rsaSignBlob },
1199 { 4, szOID_RSA_MD4RSA, CALG_MD4, md4RSA, &rsaSignBlob },
1200 { 4, szOID_OIWSEC_md4RSA, CALG_MD4, md4RSA, &rsaSignBlob },
1201 { 4, szOID_OIWSEC_md4RSA2, CALG_MD4, md4RSA, &rsaSignBlob },
1202 { 4, szOID_OIWDIR_md2RSA, CALG_MD2, md2RSA, &rsaSignBlob },
1203 { 4, szOID_OIWSEC_shaDSA, CALG_SHA1, sha1DSA, &dssSignBlob },
1204 { 4, szOID_OIWSEC_shaDSA, CALG_SHA1, shaDSA, &dssSignBlob },
1205 { 4, szOID_OIWSEC_dsaSHA1, CALG_SHA1, dsaSHA1, &dssSignBlob },
1206 { 4, szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA1, mosaicUpdatedSig,
1207 &mosaicSignBlob },
1208
1209 { 5, szOID_COMMON_NAME, 0, CN, NULL },
1210 { 5, szOID_LOCALITY_NAME, 0, L, NULL },
1211 { 5, szOID_ORGANIZATION_NAME, 0, O, NULL },
1212 { 5, szOID_ORGANIZATIONAL_UNIT_NAME, 0, OU, NULL },
1213 { 5, szOID_RSA_emailAddr, 0, E, &ia5StringBlob },
1214 { 5, szOID_RSA_emailAddr, 0, Email, &ia5StringBlob },
1215 { 5, szOID_COUNTRY_NAME, 0, C, &printableStringBlob },
1216 { 5, szOID_STATE_OR_PROVINCE_NAME, 0, S, NULL },
1217 { 5, szOID_STATE_OR_PROVINCE_NAME, 0, ST, NULL },
1218 { 5, szOID_STREET_ADDRESS, 0, STREET, NULL },
1219 { 5, szOID_TITLE, 0, T, NULL },
1220 { 5, szOID_TITLE, 0, Title, NULL },
1221 { 5, szOID_GIVEN_NAME, 0, G, NULL },
1222 { 5, szOID_GIVEN_NAME, 0, GN, NULL },
1223 { 5, szOID_GIVEN_NAME, 0, GivenName, NULL },
1224 { 5, szOID_INITIALS, 0, I, NULL },
1225 { 5, szOID_INITIALS, 0, Initials, NULL },
1226 { 5, szOID_SUR_NAME, 0, SN, NULL },
1227 { 5, szOID_DOMAIN_COMPONENT, 0, DC, &domainCompTypesBlob },
1228 { 5, szOID_DESCRIPTION, 0, Description, NULL },
1229 { 5, szOID_POSTAL_CODE, 0, PostalCode, NULL },
1230 { 5, szOID_POST_OFFICE_BOX, 0, POBox, NULL },
1231 { 5, szOID_TELEPHONE_NUMBER, 0, Phone, &printableStringBlob },
1232 { 5, szOID_X21_ADDRESS, 0, X21Address, &numericStringBlob },
1233 { 5, szOID_DN_QUALIFIER, 0, dnQualifier, NULL },
1234
1235 { 6, szOID_AUTHORITY_KEY_IDENTIFIER2, 0, (LPCWSTR)IDS_AUTHORITY_KEY_ID, NULL },
1236 { 6, szOID_AUTHORITY_KEY_IDENTIFIER, 0, (LPCWSTR)IDS_AUTHORITY_KEY_ID, NULL },
1237 { 6, szOID_KEY_ATTRIBUTES, 0, (LPCWSTR)IDS_KEY_ATTRIBUTES, NULL },
1238 { 6, szOID_KEY_USAGE_RESTRICTION, 0, (LPCWSTR)IDS_KEY_USAGE_RESTRICTION, NULL },
1239 { 6, szOID_SUBJECT_ALT_NAME2, 0, (LPCWSTR)IDS_SUBJECT_ALT_NAME, NULL },
1240 { 6, szOID_SUBJECT_ALT_NAME, 0, (LPCWSTR)IDS_SUBJECT_ALT_NAME, NULL },
1241 { 6, szOID_ISSUER_ALT_NAME2, 0, (LPCWSTR)IDS_ISSUER_ALT_NAME, NULL },
1242 { 6, szOID_ISSUER_ALT_NAME2, 0, (LPCWSTR)IDS_ISSUER_ALT_NAME, NULL },
1243 { 6, szOID_BASIC_CONSTRAINTS2, 0, (LPCWSTR)IDS_BASIC_CONSTRAINTS, NULL },
1244 { 6, szOID_BASIC_CONSTRAINTS, 0, (LPCWSTR)IDS_BASIC_CONSTRAINTS, NULL },
1245 { 6, szOID_KEY_USAGE, 0, (LPCWSTR)IDS_KEY_USAGE, NULL },
1246 { 6, szOID_CERT_POLICIES, 0, (LPCWSTR)IDS_CERT_POLICIES, NULL },
1247 { 6, szOID_SUBJECT_KEY_IDENTIFIER, 0, (LPCWSTR)IDS_SUBJECT_KEY_IDENTIFIER, NULL },
1248 { 6, szOID_CRL_REASON_CODE, 0, (LPCWSTR)IDS_CRL_REASON_CODE, NULL },
1249 { 6, szOID_CRL_DIST_POINTS, 0, (LPCWSTR)IDS_CRL_DIST_POINTS, NULL },
1250 { 6, szOID_ENHANCED_KEY_USAGE, 0, (LPCWSTR)IDS_ENHANCED_KEY_USAGE, NULL },
1251 { 6, szOID_AUTHORITY_INFO_ACCESS, 0, (LPCWSTR)IDS_AUTHORITY_INFO_ACCESS, NULL },
1252 { 6, szOID_CERT_EXTENSIONS, 0, (LPCWSTR)IDS_CERT_EXTENSIONS, NULL },
1253 { 6, szOID_RSA_certExtensions, 0, (LPCWSTR)IDS_CERT_EXTENSIONS, NULL },
1254 { 6, szOID_NEXT_UPDATE_LOCATION, 0, (LPCWSTR)IDS_NEXT_UPDATE_LOCATION, NULL },
1255 { 6, szOID_YESNO_TRUST_ATTR, 0, (LPCWSTR)IDS_YES_OR_NO_TRUST, NULL },
1256 { 6, szOID_RSA_emailAddr, 0, (LPCWSTR)IDS_EMAIL_ADDRESS, NULL },
1257 { 6, szOID_RSA_unstructName, 0, (LPCWSTR)IDS_UNSTRUCTURED_NAME, NULL },
1258 { 6, szOID_RSA_contentType, 0, (LPCWSTR)IDS_CONTENT_TYPE, NULL },
1259 { 6, szOID_RSA_messageDigest, 0, (LPCWSTR)IDS_MESSAGE_DIGEST, NULL },
1260 { 6, szOID_RSA_signingTime, 0, (LPCWSTR)IDS_SIGNING_TIME, NULL },
1261 { 6, szOID_RSA_counterSign, 0, (LPCWSTR)IDS_COUNTER_SIGN, NULL },
1262 { 6, szOID_RSA_challengePwd, 0, (LPCWSTR)IDS_CHALLENGE_PASSWORD, NULL },
1263 { 6, szOID_RSA_unstructAddr, 0, (LPCWSTR)IDS_UNSTRUCTURED_ADDRESS, NULL },
1264 { 6, szOID_RSA_SMIMECapabilities, 0, (LPCWSTR)IDS_SMIME_CAPABILITIES, NULL },
1265 { 6, szOID_RSA_preferSignedData, 0, (LPCWSTR)IDS_PREFER_SIGNED_DATA, NULL },
1266 { 6, szOID_PKIX_POLICY_QUALIFIER_CPS, 0, (LPCWSTR)IDS_CPS, NULL },
1267 { 6, szOID_PKIX_POLICY_QUALIFIER_USERNOTICE, 0, (LPCWSTR)IDS_USER_NOTICE, NULL },
1268 { 6, szOID_PKIX_OCSP, 0, (LPCWSTR)IDS_OCSP, NULL },
1269 { 6, szOID_PKIX_CA_ISSUERS, 0, (LPCWSTR)IDS_CA_ISSUER, NULL },
1270 { 6, szOID_ENROLL_CERTTYPE_EXTENSION, 0, (LPCWSTR)IDS_CERT_TEMPLATE_NAME, NULL },
1271 { 6, szOID_ENROLL_CERTTYPE_EXTENSION, 0, (LPCWSTR)IDS_CERT_TYPE, NULL },
1272 { 6, szOID_CERT_MANIFOLD, 0, (LPCWSTR)IDS_CERT_MANIFOLD, NULL },
1273 { 6, szOID_NETSCAPE_CERT_TYPE, 0, (LPCWSTR)IDS_NETSCAPE_CERT_TYPE, NULL },
1274 { 6, szOID_NETSCAPE_BASE_URL, 0, (LPCWSTR)IDS_NETSCAPE_BASE_URL, NULL },
1275 { 6, szOID_NETSCAPE_REVOCATION_URL, 0, (LPCWSTR)IDS_NETSCAPE_REVOCATION_URL, NULL },
1276 { 6, szOID_NETSCAPE_CA_REVOCATION_URL, 0, (LPCWSTR)IDS_NETSCAPE_CA_REVOCATION_URL, NULL },
1277 { 6, szOID_NETSCAPE_CERT_RENEWAL_URL, 0, (LPCWSTR)IDS_NETSCAPE_CERT_RENEWAL_URL, NULL },
1278 { 6, szOID_NETSCAPE_CA_POLICY_URL, 0, (LPCWSTR)IDS_NETSCAPE_CA_POLICY_URL, NULL },
1279 { 6, szOID_NETSCAPE_SSL_SERVER_NAME, 0, (LPCWSTR)IDS_NETSCAPE_SSL_SERVER_NAME, NULL },
1280 { 6, szOID_NETSCAPE_COMMENT, 0, (LPCWSTR)IDS_NETSCAPE_COMMENT, NULL },
1281 { 6, "1.3.6.1.4.1.311.2.1.10", 0, (LPCWSTR)IDS_SPC_SP_AGENCY_INFO, NULL },
1282 { 6, "1.3.6.1.4.1.311.2.1.27", 0, (LPCWSTR)IDS_SPC_FINANCIAL_CRITERIA, NULL },
1283 { 6, "1.3.6.1.4.1.311.2.1.26", 0, (LPCWSTR)IDS_SPC_MINIMAL_CRITERIA, NULL },
1284 { 6, szOID_COUNTRY_NAME, 0, (LPCWSTR)IDS_COUNTRY, NULL },
1285 { 6, szOID_ORGANIZATION_NAME, 0, (LPCWSTR)IDS_ORGANIZATION, NULL },
1286 { 6, szOID_ORGANIZATIONAL_UNIT_NAME, 0, (LPCWSTR)IDS_ORGANIZATIONAL_UNIT, NULL },
1287 { 6, szOID_COMMON_NAME, 0, (LPCWSTR)IDS_COMMON_NAME, NULL },
1288 { 6, szOID_LOCALITY_NAME, 0, (LPCWSTR)IDS_LOCALITY, NULL },
1289 { 6, szOID_STATE_OR_PROVINCE_NAME, 0, (LPCWSTR)IDS_STATE_OR_PROVINCE, NULL },
1290 { 6, szOID_TITLE, 0, (LPCWSTR)IDS_TITLE, NULL },
1291 { 6, szOID_GIVEN_NAME, 0, (LPCWSTR)IDS_GIVEN_NAME, NULL },
1292 { 6, szOID_INITIALS, 0, (LPCWSTR)IDS_INITIALS, NULL },
1293 { 6, szOID_SUR_NAME, 0, (LPCWSTR)IDS_SUR_NAME, NULL },
1294 { 6, szOID_DOMAIN_COMPONENT, 0, (LPCWSTR)IDS_DOMAIN_COMPONENT, NULL },
1295 { 6, szOID_STREET_ADDRESS, 0, (LPCWSTR)IDS_STREET_ADDRESS, NULL },
1296 { 6, szOID_DEVICE_SERIAL_NUMBER, 0, (LPCWSTR)IDS_SERIAL_NUMBER, NULL },
1297 { 6, szOID_CERTSRV_CA_VERSION, 0, (LPCWSTR)IDS_CA_VERSION, NULL },
1298 { 6, szOID_CERTSRV_CROSSCA_VERSION, 0, (LPCWSTR)IDS_CROSS_CA_VERSION, NULL },
1299 { 6, szOID_SERIALIZED, 0, (LPCWSTR)IDS_SERIALIZED_SIG_SERIAL_NUMBER, NULL },
1300 { 6, szOID_NT_PRINCIPAL_NAME, 0, (LPCWSTR)IDS_PRINCIPAL_NAME, NULL },
1301 { 6, szOID_PRODUCT_UPDATE, 0, (LPCWSTR)IDS_WINDOWS_PRODUCT_UPDATE, NULL },
1302 { 6, szOID_ENROLLMENT_NAME_VALUE_PAIR, 0, (LPCWSTR)IDS_ENROLLMENT_NAME_VALUE_PAIR, NULL },
1303 { 6, szOID_OS_VERSION, 0, (LPCWSTR)IDS_OS_VERSION, NULL },
1304 { 6, szOID_ENROLLMENT_CSP_PROVIDER, 0, (LPCWSTR)IDS_ENROLLMENT_CSP, NULL },
1305 { 6, szOID_CRL_NUMBER, 0, (LPCWSTR)IDS_CRL_NUMBER, NULL },
1306 { 6, szOID_DELTA_CRL_INDICATOR, 0, (LPCWSTR)IDS_DELTA_CRL_INDICATOR, NULL },
1307 { 6, szOID_ISSUING_DIST_POINT, 0, (LPCWSTR)IDS_ISSUING_DIST_POINT, NULL },
1308 { 6, szOID_FRESHEST_CRL, 0, (LPCWSTR)IDS_FRESHEST_CRL, NULL },
1309 { 6, szOID_NAME_CONSTRAINTS, 0, (LPCWSTR)IDS_NAME_CONSTRAINTS, NULL },
1310 { 6, szOID_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_POLICY_MAPPINGS, NULL },
1311 { 6, szOID_LEGACY_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_POLICY_MAPPINGS, NULL },
1312 { 6, szOID_POLICY_CONSTRAINTS, 0, (LPCWSTR)IDS_POLICY_CONSTRAINTS, NULL },
1313 { 6, szOID_CROSS_CERT_DIST_POINTS, 0, (LPCWSTR)IDS_CROSS_CERT_DIST_POINTS, NULL },
1314 { 6, szOID_APPLICATION_CERT_POLICIES, 0, (LPCWSTR)IDS_APPLICATION_POLICIES, NULL },
1315 { 6, szOID_APPLICATION_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_APPLICATION_POLICY_MAPPINGS, NULL },
1316 { 6, szOID_APPLICATION_POLICY_CONSTRAINTS, 0, (LPCWSTR)IDS_APPLICATION_POLICY_CONSTRAINTS, NULL },
1317 { 6, szOID_CT_PKI_DATA, 0, (LPCWSTR)IDS_CMC_DATA, NULL },
1318 { 6, szOID_CT_PKI_RESPONSE, 0, (LPCWSTR)IDS_CMC_RESPONSE, NULL },
1319 { 6, szOID_CMC, 0, (LPCWSTR)IDS_UNSIGNED_CMC_REQUEST, NULL },
1320 { 6, szOID_CMC_STATUS_INFO, 0, (LPCWSTR)IDS_CMC_STATUS_INFO, NULL },
1321 { 6, szOID_CMC_ADD_EXTENSIONS, 0, (LPCWSTR)IDS_CMC_EXTENSIONS, NULL },
1322 { 6, szOID_CTL, 0, (LPCWSTR)IDS_CMC_ATTRIBUTES, NULL },
1323 { 6, szOID_RSA_data, 0, (LPCWSTR)IDS_PKCS_7_DATA, NULL },
1324 { 6, szOID_RSA_signedData, 0, (LPCWSTR)IDS_PKCS_7_SIGNED, NULL },
1325 { 6, szOID_RSA_envelopedData, 0, (LPCWSTR)IDS_PKCS_7_ENVELOPED, NULL },
1326 { 6, szOID_RSA_signEnvData, 0, (LPCWSTR)IDS_PKCS_7_SIGNED_ENVELOPED, NULL },
1327 { 6, szOID_RSA_digestedData, 0, (LPCWSTR)IDS_PKCS_7_DIGESTED, NULL },
1328 { 6, szOID_RSA_encryptedData, 0, (LPCWSTR)IDS_PKCS_7_ENCRYPTED, NULL },
1329 { 6, szOID_CERTSRV_PREVIOUS_CERT_HASH, 0, (LPCWSTR)IDS_PREVIOUS_CA_CERT_HASH, NULL },
1330 { 6, szOID_CRL_VIRTUAL_BASE, 0, (LPCWSTR)IDS_CRL_VIRTUAL_BASE, NULL },
1331 { 6, szOID_CRL_NEXT_PUBLISH, 0, (LPCWSTR)IDS_CRL_NEXT_PUBLISH, NULL },
1332 { 6, szOID_KP_CA_EXCHANGE, 0, (LPCWSTR)IDS_CA_EXCHANGE, NULL },
1333 { 6, szOID_KP_KEY_RECOVERY_AGENT, 0, (LPCWSTR)IDS_KEY_RECOVERY_AGENT, NULL },
1334 { 6, szOID_CERTIFICATE_TEMPLATE, 0, (LPCWSTR)IDS_CERTIFICATE_TEMPLATE, NULL },
1335 { 6, szOID_ENTERPRISE_OID_ROOT, 0, (LPCWSTR)IDS_ENTERPRISE_ROOT_OID, NULL },
1336 { 6, szOID_RDN_DUMMY_SIGNER, 0, (LPCWSTR)IDS_RDN_DUMMY_SIGNER, NULL },
1337 { 6, szOID_ARCHIVED_KEY_ATTR, 0, (LPCWSTR)IDS_ARCHIVED_KEY_ATTR, NULL },
1338 { 6, szOID_CRL_SELF_CDP, 0, (LPCWSTR)IDS_CRL_SELF_CDP, NULL },
1339 { 6, szOID_REQUIRE_CERT_CHAIN_POLICY, 0, (LPCWSTR)IDS_REQUIRE_CERT_CHAIN_POLICY, NULL },
1340 { 6, szOID_CMC_TRANSACTION_ID, 0, (LPCWSTR)IDS_TRANSACTION_ID, NULL },
1341 { 6, szOID_CMC_SENDER_NONCE, 0, (LPCWSTR)IDS_SENDER_NONCE, NULL },
1342 { 6, szOID_CMC_RECIPIENT_NONCE, 0, (LPCWSTR)IDS_RECIPIENT_NONCE, NULL },
1343 { 6, szOID_CMC_REG_INFO, 0, (LPCWSTR)IDS_REG_INFO, NULL },
1344 { 6, szOID_CMC_GET_CERT, 0, (LPCWSTR)IDS_GET_CERTIFICATE, NULL },
1345 { 6, szOID_CMC_GET_CRL, 0, (LPCWSTR)IDS_GET_CRL, NULL },
1346 { 6, szOID_CMC_REVOKE_REQUEST, 0, (LPCWSTR)IDS_REVOKE_REQUEST, NULL },
1347 { 6, szOID_CMC_QUERY_PENDING, 0, (LPCWSTR)IDS_QUERY_PENDING, NULL },
1348 { 6, szOID_SORTED_CTL, 0, (LPCWSTR)IDS_SORTED_CTL, NULL },
1349 { 6, szOID_ARCHIVED_KEY_CERT_HASH, 0, (LPCWSTR)IDS_ARCHIVED_KEY_CERT_HASH, NULL },
1350 { 6, szOID_PRIVATEKEY_USAGE_PERIOD, 0, (LPCWSTR)IDS_PRIVATE_KEY_USAGE_PERIOD, NULL },
1351 { 6, szOID_REQUEST_CLIENT_INFO, 0, (LPCWSTR)IDS_CLIENT_INFORMATION, NULL },
1352
1353 { 7, szOID_PKIX_KP_SERVER_AUTH, 0, (LPCWSTR)IDS_SERVER_AUTHENTICATION, NULL },
1354 { 7, szOID_PKIX_KP_CLIENT_AUTH, 0, (LPCWSTR)IDS_CLIENT_AUTHENTICATION, NULL },
1355 { 7, szOID_PKIX_KP_CODE_SIGNING, 0, (LPCWSTR)IDS_CODE_SIGNING, NULL },
1356 { 7, szOID_PKIX_KP_EMAIL_PROTECTION, 0, (LPCWSTR)IDS_SECURE_EMAIL, NULL },
1357 { 7, szOID_PKIX_KP_TIMESTAMP_SIGNING, 0, (LPCWSTR)IDS_TIME_STAMPING, NULL },
1358 { 7, szOID_KP_CTL_USAGE_SIGNING, 0, (LPCWSTR)IDS_MICROSOFT_TRUST_LIST_SIGNING, NULL },
1359 { 7, szOID_KP_TIME_STAMP_SIGNING, 0, (LPCWSTR)IDS_MICROSOFT_TIME_STAMPING, NULL },
1360 { 7, szOID_PKIX_KP_IPSEC_END_SYSTEM, 0, (LPCWSTR)IDS_IPSEC_END_SYSTEM, NULL },
1361 { 7, szOID_PKIX_KP_IPSEC_TUNNEL, 0, (LPCWSTR)IDS_IPSEC_TUNNEL, NULL },
1362 { 7, szOID_PKIX_KP_IPSEC_USER, 0, (LPCWSTR)IDS_IPSEC_USER, NULL },
1363 { 7, szOID_KP_EFS, 0, (LPCWSTR)IDS_EFS, NULL },
1364 { 7, szOID_WHQL_CRYPTO, 0, (LPCWSTR)IDS_WHQL_CRYPTO, NULL },
1365 { 7, szOID_NT5_CRYPTO, 0, (LPCWSTR)IDS_NT5_CRYPTO, NULL },
1366 { 7, szOID_OEM_WHQL_CRYPTO, 0, (LPCWSTR)IDS_OEM_WHQL_CRYPTO, NULL },
1367 { 7, szOID_EMBEDDED_NT_CRYPTO, 0, (LPCWSTR)IDS_EMBEDDED_NT_CRYPTO, NULL },
1368 { 7, szOID_LICENSES, 0, (LPCWSTR)IDS_KEY_PACK_LICENSES, NULL },
1369 { 7, szOID_LICENSE_SERVER, 0, (LPCWSTR)IDS_LICENSE_SERVER, NULL },
1370 { 7, szOID_KP_SMARTCARD_LOGON, 0, (LPCWSTR)IDS_SMART_CARD_LOGON, NULL },
1371 { 7, szOID_DRM, 0, (LPCWSTR)IDS_DIGITAL_RIGHTS, NULL },
1372 { 7, szOID_KP_QUALIFIED_SUBORDINATION, 0, (LPCWSTR)IDS_QUALIFIED_SUBORDINATION, NULL },
1373 { 7, szOID_KP_KEY_RECOVERY, 0, (LPCWSTR)IDS_KEY_RECOVERY, NULL },
1374 { 7, szOID_KP_DOCUMENT_SIGNING, 0, (LPCWSTR)IDS_DOCUMENT_SIGNING, NULL },
1375 { 7, szOID_IPSEC_KP_IKE_INTERMEDIATE, 0, (LPCWSTR)IDS_IPSEC_IKE_INTERMEDIATE, NULL },
1376 { 7, szOID_EFS_RECOVERY, 0, (LPCWSTR)IDS_FILE_RECOVERY, NULL },
1377 { 7, szOID_ROOT_LIST_SIGNER, 0, (LPCWSTR)IDS_ROOT_LIST_SIGNER, NULL },
1378 { 7, szOID_ANY_APPLICATION_POLICY, 0, (LPCWSTR)IDS_ANY_APPLICATION_POLICIES, NULL },
1379 { 7, szOID_DS_EMAIL_REPLICATION, 0, (LPCWSTR)IDS_DS_EMAIL_REPLICATION, NULL },
1380 { 7, szOID_ENROLLMENT_AGENT, 0, (LPCWSTR)IDS_ENROLLMENT_AGENT, NULL },
1381 { 7, szOID_KP_KEY_RECOVERY_AGENT, 0, (LPCWSTR)IDS_KEY_RECOVERY_AGENT, NULL },
1382 { 7, szOID_KP_CA_EXCHANGE, 0, (LPCWSTR)IDS_CA_EXCHANGE, NULL },
1383 { 7, szOID_KP_LIFETIME_SIGNING, 0, (LPCWSTR)IDS_LIFETIME_SIGNING, NULL },
1384
1385 { 8, szOID_ANY_CERT_POLICY, 0, (LPCWSTR)IDS_ANY_CERT_POLICY, NULL },
1386 };
1387
1388 struct OIDInfo {
1389 CRYPT_OID_INFO info;
1390 struct list entry;
1391 };
1392
1393 static void init_oid_info(void)
1394 {
1395 DWORD i;
1396
1397 oid_init_localizednames();
1398 for (i = 0; i < sizeof(oidInfoConstructors) /
1399 sizeof(oidInfoConstructors[0]); i++)
1400 {
1401 if (!IS_INTRESOURCE(oidInfoConstructors[i].pwszName))
1402 {
1403 struct OIDInfo *info;
1404
1405 /* The name is a static string, so just use the same pointer */
1406 info = CryptMemAlloc(sizeof(struct OIDInfo));
1407 if (info)
1408 {
1409 memset(info, 0, sizeof(*info));
1410 info->info.cbSize = sizeof(CRYPT_OID_INFO);
1411 info->info.pszOID = oidInfoConstructors[i].pszOID;
1412 info->info.pwszName = oidInfoConstructors[i].pwszName;
1413 info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
1414 info->info.u.Algid = oidInfoConstructors[i].Algid;
1415 if (oidInfoConstructors[i].blob)
1416 {
1417 info->info.ExtraInfo.cbData =
1418 oidInfoConstructors[i].blob->cbData;
1419 info->info.ExtraInfo.pbData =
1420 oidInfoConstructors[i].blob->pbData;
1421 }
1422 list_add_tail(&oidInfo, &info->entry);
1423 }
1424 }
1425 else
1426 {
1427 LPCWSTR stringresource;
1428 int len = LoadStringW(hInstance,
1429 (UINT_PTR)oidInfoConstructors[i].pwszName,
1430 (LPWSTR)&stringresource, 0);
1431
1432 if (len)
1433 {
1434 struct OIDInfo *info = CryptMemAlloc(sizeof(struct OIDInfo) +
1435 (len + 1) * sizeof(WCHAR));
1436
1437 if (info)
1438 {
1439 memset(info, 0, sizeof(*info));
1440 info->info.cbSize = sizeof(CRYPT_OID_INFO);
1441 info->info.pszOID = oidInfoConstructors[i].pszOID;
1442 info->info.pwszName = (LPWSTR)(info + 1);
1443 info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
1444 info->info.u.Algid = oidInfoConstructors[i].Algid;
1445 memcpy(info + 1, stringresource, len*sizeof(WCHAR));
1446 ((LPWSTR)(info + 1))[len] = 0;
1447 if (oidInfoConstructors[i].blob)
1448 {
1449 info->info.ExtraInfo.cbData =
1450 oidInfoConstructors[i].blob->cbData;
1451 info->info.ExtraInfo.pbData =
1452 oidInfoConstructors[i].blob->pbData;
1453 }
1454 list_add_tail(&oidInfo, &info->entry);
1455 }
1456 }
1457 }
1458 }
1459 }
1460
1461 static void free_oid_info(void)
1462 {
1463 struct OIDInfo *info, *next;
1464
1465 LIST_FOR_EACH_ENTRY_SAFE(info, next, &oidInfo, struct OIDInfo, entry)
1466 {
1467 list_remove(&info->entry);
1468 CryptMemFree(info);
1469 }
1470 }
1471
1472 /***********************************************************************
1473 * CryptEnumOIDInfo (CRYPT32.@)
1474 */
1475 BOOL WINAPI CryptEnumOIDInfo(DWORD dwGroupId, DWORD dwFlags, void *pvArg,
1476 PFN_CRYPT_ENUM_OID_INFO pfnEnumOIDInfo)
1477 {
1478 BOOL ret = TRUE;
1479 struct OIDInfo *info;
1480
1481 TRACE("(%d, %08x, %p, %p)\n", dwGroupId, dwFlags, pvArg,
1482 pfnEnumOIDInfo);
1483
1484 EnterCriticalSection(&oidInfoCS);
1485 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1486 {
1487 if (!dwGroupId || dwGroupId == info->info.dwGroupId)
1488 {
1489 ret = pfnEnumOIDInfo(&info->info, pvArg);
1490 if (!ret)
1491 break;
1492 }
1493 }
1494 LeaveCriticalSection(&oidInfoCS);
1495 return ret;
1496 }
1497
1498 PCCRYPT_OID_INFO WINAPI CryptFindOIDInfo(DWORD dwKeyType, void *pvKey,
1499 DWORD dwGroupId)
1500 {
1501 PCCRYPT_OID_INFO ret = NULL;
1502
1503 TRACE("(%d, %p, %d)\n", dwKeyType, pvKey, dwGroupId);
1504
1505 switch(dwKeyType)
1506 {
1507 case CRYPT_OID_INFO_ALGID_KEY:
1508 {
1509 struct OIDInfo *info;
1510
1511 TRACE("CRYPT_OID_INFO_ALGID_KEY: %d\n", *(DWORD *)pvKey);
1512 EnterCriticalSection(&oidInfoCS);
1513 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1514 {
1515 if (info->info.u.Algid == *(DWORD *)pvKey &&
1516 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1517 {
1518 ret = &info->info;
1519 break;
1520 }
1521 }
1522 LeaveCriticalSection(&oidInfoCS);
1523 break;
1524 }
1525 case CRYPT_OID_INFO_NAME_KEY:
1526 {
1527 struct OIDInfo *info;
1528
1529 TRACE("CRYPT_OID_INFO_NAME_KEY: %s\n", debugstr_w(pvKey));
1530 EnterCriticalSection(&oidInfoCS);
1531 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1532 {
1533 if (!lstrcmpW(info->info.pwszName, pvKey) &&
1534 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1535 {
1536 ret = &info->info;
1537 break;
1538 }
1539 }
1540 LeaveCriticalSection(&oidInfoCS);
1541 break;
1542 }
1543 case CRYPT_OID_INFO_OID_KEY:
1544 {
1545 struct OIDInfo *info;
1546 LPSTR oid = pvKey;
1547
1548 TRACE("CRYPT_OID_INFO_OID_KEY: %s\n", debugstr_a(oid));
1549 EnterCriticalSection(&oidInfoCS);
1550 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1551 {
1552 if (!lstrcmpA(info->info.pszOID, oid) &&
1553 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1554 {
1555 ret = &info->info;
1556 break;
1557 }
1558 }
1559 LeaveCriticalSection(&oidInfoCS);
1560 break;
1561 }
1562 case CRYPT_OID_INFO_SIGN_KEY:
1563 {
1564 struct OIDInfo *info;
1565
1566 TRACE("CRYPT_OID_INFO_SIGN_KEY: %d\n", *(DWORD *)pvKey);
1567 EnterCriticalSection(&oidInfoCS);
1568 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1569 {
1570 if (info->info.u.Algid == *(DWORD *)pvKey &&
1571 info->info.ExtraInfo.cbData >= sizeof(DWORD) &&
1572 *(DWORD *)info->info.ExtraInfo.pbData ==
1573 *(DWORD *)((LPBYTE)pvKey + sizeof(DWORD)) &&
1574 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1575 {
1576 ret = &info->info;
1577 break;
1578 }
1579 }
1580 LeaveCriticalSection(&oidInfoCS);
1581 break;
1582 }
1583 }
1584 return ret;
1585 }
1586
1587 LPCSTR WINAPI CertAlgIdToOID(DWORD dwAlgId)
1588 {
1589 LPCSTR ret;
1590 PCCRYPT_OID_INFO info = CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY,
1591 &dwAlgId, 0);
1592
1593 if (info)
1594 ret = info->pszOID;
1595 else
1596 ret = NULL;
1597 return ret;
1598 }
1599
1600 DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId)
1601 {
1602 DWORD ret;
1603 PCCRYPT_OID_INFO info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY,
1604 (void *)pszObjId, 0);
1605
1606 if (info)
1607 ret = info->u.Algid;
1608 else
1609 ret = 0;
1610 return ret;
1611 }