jscript: Add missing port.h include for isnan.
[wine/multimedia.git] / dlls / crypt32 / oid.c
blobd56fe83bd2bd01c529dd63273ef4d1be4c2711b8
1 /*
2 * Copyright 2002 Mike McCormack for CodeWeavers
3 * Copyright 2005-2006 Juan Lang
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.
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.
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
20 #include "config.h"
21 #include "wine/port.h"
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"
36 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
38 static const WCHAR DllW[] = { 'D','l','l',0 };
40 static CRITICAL_SECTION funcSetCS;
41 static CRITICAL_SECTION_DEBUG funcSetCSDebug =
43 0, 0, &funcSetCS,
44 { &funcSetCSDebug.ProcessLocksList, &funcSetCSDebug.ProcessLocksList },
45 0, 0, { (DWORD_PTR)(__FILE__ ": funcSetCS") }
47 static CRITICAL_SECTION funcSetCS = { &funcSetCSDebug, -1, 0, 0, 0, 0 };
48 static struct list funcSets = { &funcSets, &funcSets };
50 struct OIDFunctionSet
52 LPSTR name;
53 CRITICAL_SECTION cs; /* protects functions */
54 struct list functions;
55 struct list next;
58 struct OIDFunction
60 DWORD encoding;
61 CRYPT_OID_FUNC_ENTRY entry;
62 struct list next;
65 static const WCHAR ROOT[] = {'R','O','O','T',0};
66 static const WCHAR MY[] = {'M','Y',0};
67 static const WCHAR CA[] = {'C','A',0};
68 static const WCHAR ADDRESSBOOK[] = {'A','D','D','R','E','S','S','B','O','O','K',0};
69 static const WCHAR TRUSTEDPUBLISHER[] = {'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r',0};
70 static const WCHAR DISALLOWED[] = {'D','i','s','a','l','l','o','w','e','d',0};
71 static const LPCWSTR LocalizedKeys[] = {ROOT,MY,CA,ADDRESSBOOK,TRUSTEDPUBLISHER,DISALLOWED};
72 static WCHAR LocalizedNames[sizeof(LocalizedKeys)/sizeof(LocalizedKeys[0])][256];
74 static void free_function_sets(void)
76 struct OIDFunctionSet *setCursor, *setNext;
78 LIST_FOR_EACH_ENTRY_SAFE(setCursor, setNext, &funcSets,
79 struct OIDFunctionSet, next)
81 struct OIDFunction *functionCursor, *funcNext;
83 list_remove(&setCursor->next);
84 CryptMemFree(setCursor->name);
85 LIST_FOR_EACH_ENTRY_SAFE(functionCursor, funcNext,
86 &setCursor->functions, struct OIDFunction, next)
88 list_remove(&functionCursor->next);
89 CryptMemFree(functionCursor);
91 setCursor->cs.DebugInfo->Spare[0] = 0;
92 DeleteCriticalSection(&setCursor->cs);
93 CryptMemFree(setCursor);
95 DeleteCriticalSection(&funcSetCS);
98 /* There is no free function associated with this; therefore, the sets are
99 * freed when crypt32.dll is unloaded.
101 HCRYPTOIDFUNCSET WINAPI CryptInitOIDFunctionSet(LPCSTR pszFuncName,
102 DWORD dwFlags)
104 struct OIDFunctionSet *cursor, *ret = NULL;
106 TRACE("(%s, %x)\n", debugstr_a(pszFuncName), dwFlags);
108 EnterCriticalSection(&funcSetCS);
109 LIST_FOR_EACH_ENTRY(cursor, &funcSets, struct OIDFunctionSet, next)
111 if (!strcasecmp(pszFuncName, cursor->name))
113 ret = cursor;
114 break;
117 if (!ret)
119 ret = CryptMemAlloc(sizeof(struct OIDFunctionSet));
120 if (ret)
122 memset(ret, 0, sizeof(*ret));
123 ret->name = CryptMemAlloc(strlen(pszFuncName) + 1);
124 if (ret->name)
126 InitializeCriticalSection(&ret->cs);
127 ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": OIDFunctionSet.cs");
128 list_init(&ret->functions);
129 strcpy(ret->name, pszFuncName);
130 list_add_tail(&funcSets, &ret->next);
132 else
134 CryptMemFree(ret);
135 ret = NULL;
139 LeaveCriticalSection(&funcSetCS);
141 return ret;
144 static char *CRYPT_GetKeyName(DWORD dwEncodingType, LPCSTR pszFuncName,
145 LPCSTR pszOID)
147 static const char szEncodingTypeFmt[] =
148 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\%s";
149 UINT len;
150 char numericOID[7]; /* enough for "#65535" */
151 const char *oid;
152 LPSTR szKey;
154 /* MSDN says the encoding type is a mask, but it isn't treated that way.
155 * (E.g., if dwEncodingType were 3, the key names "EncodingType 1" and
156 * "EncodingType 2" would be expected if it were a mask. Instead native
157 * stores values in "EncodingType 3".
159 if (IS_INTOID(pszOID))
161 snprintf(numericOID, sizeof(numericOID), "#%d", LOWORD(pszOID));
162 oid = numericOID;
164 else
165 oid = pszOID;
167 /* This is enough: the lengths of the two string parameters are explicitly
168 * counted, and we need up to five additional characters for the encoding
169 * type. These are covered by the "%d", "%s", and "%s" characters in the
170 * format specifier that are removed by sprintf.
172 len = sizeof(szEncodingTypeFmt) + lstrlenA(pszFuncName) + lstrlenA(oid);
173 szKey = CryptMemAlloc(len);
174 if (szKey)
175 sprintf(szKey, szEncodingTypeFmt,
176 GET_CERT_ENCODING_TYPE(dwEncodingType), pszFuncName, oid);
177 return szKey;
180 BOOL WINAPI CryptGetDefaultOIDDllList(HCRYPTOIDFUNCSET hFuncSet,
181 DWORD dwEncodingType, LPWSTR pwszDllList, DWORD *pcchDllList)
183 BOOL ret = TRUE;
184 struct OIDFunctionSet *set = hFuncSet;
185 char *keyName;
186 HKEY key;
187 LSTATUS rc;
189 TRACE("(%p, %d, %p, %p)\n", hFuncSet, dwEncodingType, pwszDllList,
190 pcchDllList);
192 keyName = CRYPT_GetKeyName(dwEncodingType, set->name, "DEFAULT");
193 rc = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, NULL, 0,
194 KEY_READ, NULL, &key, NULL);
195 if (!rc)
197 DWORD size = *pcchDllList * sizeof(WCHAR);
199 rc = RegQueryValueExW(key, DllW, NULL, NULL, (LPBYTE)pwszDllList,
200 &size);
201 if (!rc)
202 *pcchDllList = size / sizeof(WCHAR);
203 else
205 /* No value, return an empty list */
206 if (pwszDllList && *pcchDllList)
207 *pwszDllList = '\0';
208 *pcchDllList = 1;
210 RegCloseKey(key);
212 else
214 /* No value, return an empty list */
215 if (pwszDllList && *pcchDllList)
216 *pwszDllList = '\0';
217 *pcchDllList = 1;
219 CryptMemFree(keyName);
221 return ret;
224 BOOL WINAPI CryptInstallOIDFunctionAddress(HMODULE hModule,
225 DWORD dwEncodingType, LPCSTR pszFuncName, DWORD cFuncEntry,
226 const CRYPT_OID_FUNC_ENTRY rgFuncEntry[], DWORD dwFlags)
228 BOOL ret = TRUE;
229 struct OIDFunctionSet *set;
231 TRACE("(%p, %d, %s, %d, %p, %08x)\n", hModule, dwEncodingType,
232 debugstr_a(pszFuncName), cFuncEntry, rgFuncEntry, dwFlags);
234 set = CryptInitOIDFunctionSet(pszFuncName, 0);
235 if (set)
237 DWORD i;
239 EnterCriticalSection(&set->cs);
240 for (i = 0; ret && i < cFuncEntry; i++)
242 struct OIDFunction *func;
244 if (!IS_INTOID(rgFuncEntry[i].pszOID))
245 func = CryptMemAlloc(sizeof(struct OIDFunction)
246 + strlen(rgFuncEntry[i].pszOID) + 1);
247 else
248 func = CryptMemAlloc(sizeof(struct OIDFunction));
249 if (func)
251 func->encoding = GET_CERT_ENCODING_TYPE(dwEncodingType);
252 if (!IS_INTOID(rgFuncEntry[i].pszOID))
254 LPSTR oid;
256 oid = (LPSTR)((LPBYTE)func + sizeof(*func));
257 strcpy(oid, rgFuncEntry[i].pszOID);
258 func->entry.pszOID = oid;
260 else
261 func->entry.pszOID = rgFuncEntry[i].pszOID;
262 func->entry.pvFuncAddr = rgFuncEntry[i].pvFuncAddr;
263 list_add_tail(&set->functions, &func->next);
265 else
266 ret = FALSE;
268 LeaveCriticalSection(&set->cs);
270 else
271 ret = FALSE;
272 return ret;
275 struct FuncAddr
277 HMODULE lib;
278 LPWSTR dllList;
279 LPWSTR currentDll;
282 static BOOL CRYPT_GetFuncFromReg(DWORD dwEncodingType, LPCSTR pszOID,
283 LPCSTR szFuncName, LPVOID *ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
285 BOOL ret = FALSE;
286 char *keyName;
287 const char *funcName;
288 HKEY key;
289 LSTATUS rc;
291 keyName = CRYPT_GetKeyName(dwEncodingType, szFuncName, pszOID);
292 rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &key);
293 if (!rc)
295 DWORD type, size = 0;
297 rc = RegQueryValueExA(key, "FuncName", NULL, &type, NULL, &size);
298 if ((!rc || rc == ERROR_MORE_DATA) && type == REG_SZ)
300 funcName = CryptMemAlloc(size);
301 rc = RegQueryValueExA(key, "FuncName", NULL, &type,
302 (LPBYTE)funcName, &size);
304 else
305 funcName = szFuncName;
306 rc = RegQueryValueExW(key, DllW, NULL, &type, NULL, &size);
307 if ((!rc || rc == ERROR_MORE_DATA) && type == REG_SZ)
309 LPWSTR dllName = CryptMemAlloc(size);
311 if (dllName)
313 rc = RegQueryValueExW(key, DllW, NULL, NULL,
314 (LPBYTE)dllName, &size);
315 if (!rc)
317 HMODULE lib;
319 /* This is a bit of a hack; MSDN describes a more
320 * complicated unload routine than this will allow.
321 * Still, this seems to suffice for now.
323 lib = LoadLibraryW(dllName);
324 if (lib)
326 *ppvFuncAddr = GetProcAddress(lib, funcName);
327 if (*ppvFuncAddr)
329 struct FuncAddr *addr =
330 CryptMemAlloc(sizeof(struct FuncAddr));
332 if (addr)
334 addr->lib = lib;
335 addr->dllList = addr->currentDll = NULL;
336 *phFuncAddr = addr;
337 ret = TRUE;
339 else
341 *phFuncAddr = NULL;
342 FreeLibrary(lib);
345 else
347 /* Unload the library, the caller doesn't want
348 * to unload it when the return value is NULL.
350 FreeLibrary(lib);
354 else
355 SetLastError(rc);
356 CryptMemFree(dllName);
359 else
360 SetLastError(rc);
361 if (funcName != szFuncName)
362 CryptMemFree((char *)funcName);
363 RegCloseKey(key);
365 else
366 SetLastError(rc);
367 CryptMemFree(keyName);
368 return ret;
371 BOOL WINAPI CryptGetOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet,
372 DWORD dwEncodingType, LPCSTR pszOID, DWORD dwFlags, void **ppvFuncAddr,
373 HCRYPTOIDFUNCADDR *phFuncAddr)
375 BOOL ret = FALSE;
376 struct OIDFunctionSet *set = hFuncSet;
378 TRACE("(%p, %d, %s, %08x, %p, %p)\n", hFuncSet, dwEncodingType,
379 debugstr_a(pszOID), dwFlags, ppvFuncAddr, phFuncAddr);
381 *ppvFuncAddr = NULL;
382 if (!(dwFlags & CRYPT_GET_INSTALLED_OID_FUNC_FLAG))
384 struct OIDFunction *function;
386 EnterCriticalSection(&set->cs);
387 LIST_FOR_EACH_ENTRY(function, &set->functions, struct OIDFunction, next)
389 if (function->encoding == GET_CERT_ENCODING_TYPE(dwEncodingType))
391 if (!IS_INTOID(pszOID))
393 if (!IS_INTOID(function->entry.pszOID) &&
394 !strcasecmp(function->entry.pszOID, pszOID))
396 *ppvFuncAddr = function->entry.pvFuncAddr;
397 *phFuncAddr = NULL; /* FIXME: what should it be? */
398 ret = TRUE;
399 break;
402 else if (function->entry.pszOID == pszOID)
404 *ppvFuncAddr = function->entry.pvFuncAddr;
405 *phFuncAddr = NULL; /* FIXME: what should it be? */
406 ret = TRUE;
407 break;
411 LeaveCriticalSection(&set->cs);
413 if (!*ppvFuncAddr)
414 ret = CRYPT_GetFuncFromReg(dwEncodingType, pszOID, set->name,
415 ppvFuncAddr, phFuncAddr);
416 TRACE("returning %d\n", ret);
417 return ret;
420 BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr,
421 DWORD dwFlags)
423 TRACE("(%p, %08x)\n", hFuncAddr, dwFlags);
425 /* FIXME: as MSDN states, need to check for DllCanUnloadNow in the DLL,
426 * and only unload it if it can be unloaded. Also need to implement ref
427 * counting on the functions.
429 if (hFuncAddr)
431 struct FuncAddr *addr = hFuncAddr;
433 CryptMemFree(addr->dllList);
434 FreeLibrary(addr->lib);
435 CryptMemFree(addr);
437 return TRUE;
440 static BOOL CRYPT_GetFuncFromDll(LPCWSTR dll, LPCSTR func, HMODULE *lib,
441 void **ppvFuncAddr)
443 BOOL ret = FALSE;
445 *lib = LoadLibraryW(dll);
446 if (*lib)
448 *ppvFuncAddr = GetProcAddress(*lib, func);
449 if (*ppvFuncAddr)
450 ret = TRUE;
451 else
453 FreeLibrary(*lib);
454 *lib = NULL;
457 return ret;
460 BOOL WINAPI CryptGetDefaultOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet,
461 DWORD dwEncodingType, LPCWSTR pwszDll, DWORD dwFlags, void **ppvFuncAddr,
462 HCRYPTOIDFUNCADDR *phFuncAddr)
464 struct OIDFunctionSet *set = hFuncSet;
465 BOOL ret = FALSE;
467 TRACE("(%p, %d, %s, %08x, %p, %p)\n", hFuncSet, dwEncodingType,
468 debugstr_w(pwszDll), dwFlags, ppvFuncAddr, phFuncAddr);
470 if (pwszDll)
472 HMODULE lib;
474 *phFuncAddr = NULL;
475 ret = CRYPT_GetFuncFromDll(pwszDll, set->name, &lib, ppvFuncAddr);
476 if (ret)
478 struct FuncAddr *addr = CryptMemAlloc(sizeof(struct FuncAddr));
480 if (addr)
482 addr->lib = lib;
483 addr->dllList = addr->currentDll = NULL;
484 *phFuncAddr = addr;
486 else
488 FreeLibrary(lib);
489 *ppvFuncAddr = NULL;
490 SetLastError(ERROR_OUTOFMEMORY);
491 ret = FALSE;
494 else
495 SetLastError(ERROR_FILE_NOT_FOUND);
497 else
499 struct FuncAddr *addr = *phFuncAddr;
501 if (!addr)
503 DWORD size;
505 ret = CryptGetDefaultOIDDllList(hFuncSet, dwEncodingType, NULL,
506 &size);
507 if (ret)
509 LPWSTR dllList = CryptMemAlloc(size * sizeof(WCHAR));
511 if (dllList)
513 ret = CryptGetDefaultOIDDllList(hFuncSet, dwEncodingType,
514 dllList, &size);
515 if (ret)
517 addr = CryptMemAlloc(sizeof(struct FuncAddr));
518 if (addr)
520 addr->dllList = dllList;
521 addr->currentDll = dllList;
522 addr->lib = NULL;
523 *phFuncAddr = addr;
525 else
527 CryptMemFree(dllList);
528 SetLastError(ERROR_OUTOFMEMORY);
529 ret = FALSE;
533 else
535 SetLastError(ERROR_OUTOFMEMORY);
536 ret = FALSE;
540 if (addr)
542 if (!*addr->currentDll)
544 CryptFreeOIDFunctionAddress(*phFuncAddr, 0);
545 SetLastError(ERROR_FILE_NOT_FOUND);
546 *phFuncAddr = NULL;
547 ret = FALSE;
549 else
551 /* FIXME: as elsewhere, can't free until DllCanUnloadNow says
552 * it's possible, and should defer unloading for some time to
553 * avoid repeated LoadLibrary/FreeLibrary on the same dll.
555 FreeLibrary(addr->lib);
556 ret = CRYPT_GetFuncFromDll(addr->currentDll, set->name,
557 &addr->lib, ppvFuncAddr);
558 if (ret)
560 /* Move past the current DLL */
561 addr->currentDll += lstrlenW(addr->currentDll) + 1;
562 *phFuncAddr = addr;
564 else
566 CryptFreeOIDFunctionAddress(*phFuncAddr, 0);
567 SetLastError(ERROR_FILE_NOT_FOUND);
568 *phFuncAddr = NULL;
573 return ret;
576 /***********************************************************************
577 * CryptRegisterOIDFunction (CRYPT32.@)
579 * Register the DLL and the functions it uses to cover the combination
580 * of encoding type, function name and OID.
582 * PARAMS
583 * dwEncodingType [I] Encoding type to be used.
584 * pszFuncName [I] Name of the function to be registered.
585 * pszOID [I] OID of the function (numeric or string).
586 * pwszDll [I] The DLL that is to be registered.
587 * pszOverrideFuncName [I] Name of the function in the DLL.
589 * RETURNS
590 * Success: TRUE.
591 * Failure: FALSE. (Look at GetLastError()).
593 * NOTES
594 * Registry errors are always reported via SetLastError().
596 BOOL WINAPI CryptRegisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
597 LPCSTR pszOID, LPCWSTR pwszDll, LPCSTR pszOverrideFuncName)
599 LONG r;
600 HKEY hKey;
601 LPSTR szKey;
603 TRACE("(%x, %s, %s, %s, %s)\n", dwEncodingType, debugstr_a(pszFuncName),
604 debugstr_a(pszOID), debugstr_w(pwszDll), debugstr_a(pszOverrideFuncName));
606 /* Native does nothing pwszDll is NULL */
607 if (!pwszDll)
608 return TRUE;
610 /* I'm not matching MS bug for bug here, because I doubt any app depends on
611 * it: native "succeeds" if pszFuncName is NULL, but the nonsensical entry
612 * it creates would never be used.
614 if (!pszFuncName || !pszOID)
616 SetLastError(E_INVALIDARG);
617 return FALSE;
620 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
621 TRACE("Key name is %s\n", debugstr_a(szKey));
623 if (!szKey)
624 return FALSE;
626 r = RegCreateKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
627 CryptMemFree(szKey);
629 if (r != ERROR_SUCCESS) goto error_close_key;
631 /* write the values */
632 if (pszOverrideFuncName)
634 r = RegSetValueExA(hKey, "FuncName", 0, REG_SZ,
635 (const BYTE*)pszOverrideFuncName, lstrlenA(pszOverrideFuncName) + 1);
636 if (r != ERROR_SUCCESS) goto error_close_key;
638 r = RegSetValueExW(hKey, DllW, 0, REG_SZ, (const BYTE*) pwszDll,
639 (lstrlenW(pwszDll) + 1) * sizeof (WCHAR));
641 error_close_key:
643 RegCloseKey(hKey);
645 if (r != ERROR_SUCCESS)
647 SetLastError(r);
648 return FALSE;
651 return TRUE;
654 /***********************************************************************
655 * CryptRegisterOIDInfo (CRYPT32.@)
657 BOOL WINAPI CryptRegisterOIDInfo(PCCRYPT_OID_INFO pInfo, DWORD dwFlags)
659 FIXME("(%p, %x): stub\n", pInfo, dwFlags );
660 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
661 return FALSE;
664 /***********************************************************************
665 * CryptUnregisterOIDFunction (CRYPT32.@)
667 BOOL WINAPI CryptUnregisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
668 LPCSTR pszOID)
670 LPSTR szKey;
671 LONG rc;
673 TRACE("%x %s %s\n", dwEncodingType, debugstr_a(pszFuncName),
674 debugstr_a(pszOID));
676 if (!pszFuncName || !pszOID)
678 SetLastError(ERROR_INVALID_PARAMETER);
679 return FALSE;
682 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
683 rc = RegDeleteKeyA(HKEY_LOCAL_MACHINE, szKey);
684 CryptMemFree(szKey);
685 if (rc)
686 SetLastError(rc);
687 return rc ? FALSE : TRUE;
690 BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
691 LPCSTR pszOID, LPCWSTR pwszValueName, DWORD *pdwValueType, BYTE *pbValueData,
692 DWORD *pcbValueData)
694 LPSTR szKey;
695 LONG rc;
696 HKEY hKey;
698 TRACE("%x %s %s %s %p %p %p\n", dwEncodingType, debugstr_a(pszFuncName),
699 debugstr_a(pszOID), debugstr_w(pwszValueName), pdwValueType, pbValueData,
700 pcbValueData);
702 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
703 return TRUE;
705 if (!pszFuncName || !pszOID || !pwszValueName)
707 SetLastError(ERROR_INVALID_PARAMETER);
708 return FALSE;
711 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
712 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
713 CryptMemFree(szKey);
714 if (rc)
715 SetLastError(rc);
716 else
718 rc = RegQueryValueExW(hKey, pwszValueName, NULL, pdwValueType,
719 pbValueData, pcbValueData);
720 if (rc)
721 SetLastError(rc);
722 RegCloseKey(hKey);
724 return rc ? FALSE : TRUE;
727 BOOL WINAPI CryptSetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
728 LPCSTR pszOID, LPCWSTR pwszValueName, DWORD dwValueType,
729 const BYTE *pbValueData, DWORD cbValueData)
731 LPSTR szKey;
732 LONG rc;
733 HKEY hKey;
735 TRACE("%x %s %s %s %d %p %d\n", dwEncodingType, debugstr_a(pszFuncName),
736 debugstr_a(pszOID), debugstr_w(pwszValueName), dwValueType, pbValueData,
737 cbValueData);
739 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
740 return TRUE;
742 if (!pszFuncName || !pszOID || !pwszValueName)
744 SetLastError(ERROR_INVALID_PARAMETER);
745 return FALSE;
748 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
749 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
750 CryptMemFree(szKey);
751 if (rc)
752 SetLastError(rc);
753 else
755 rc = RegSetValueExW(hKey, pwszValueName, 0, dwValueType, pbValueData,
756 cbValueData);
757 if (rc)
758 SetLastError(rc);
759 RegCloseKey(hKey);
761 return rc ? FALSE : TRUE;
764 static LPCWSTR CRYPT_FindStringInMultiString(LPCWSTR multi, LPCWSTR toFind)
766 LPCWSTR ret = NULL, ptr;
768 for (ptr = multi; ptr && *ptr && !ret; ptr += lstrlenW(ptr) + 1)
770 if (!lstrcmpiW(ptr, toFind))
771 ret = ptr;
773 return ret;
776 static DWORD CRYPT_GetMultiStringCharacterLen(LPCWSTR multi)
778 DWORD ret;
780 if (multi)
782 LPCWSTR ptr;
784 /* Count terminating empty string */
785 ret = 1;
786 for (ptr = multi; *ptr; ptr += lstrlenW(ptr) + 1)
787 ret += lstrlenW(ptr) + 1;
789 else
790 ret = 0;
791 return ret;
794 static LPWSTR CRYPT_AddStringToMultiString(LPWSTR multi, LPCWSTR toAdd,
795 DWORD index)
797 LPWSTR ret;
799 if (!multi)
801 /* FIXME: ignoring index, is that okay? */
802 ret = CryptMemAlloc((lstrlenW(toAdd) + 2) * sizeof(WCHAR));
803 if (ret)
805 /* copy string, including NULL terminator */
806 memcpy(ret, toAdd, (lstrlenW(toAdd) + 1) * sizeof(WCHAR));
807 /* add terminating empty string */
808 *(ret + lstrlenW(toAdd) + 1) = 0;
811 else
813 DWORD len = CRYPT_GetMultiStringCharacterLen(multi);
815 ret = CryptMemRealloc(multi, (len + lstrlenW(toAdd) + 1) *
816 sizeof(WCHAR));
817 if (ret)
819 LPWSTR spotToAdd;
821 if (index == CRYPT_REGISTER_LAST_INDEX)
822 spotToAdd = ret + len - 1;
823 else
825 DWORD i;
827 /* FIXME: if index is too large for the string, toAdd is
828 * added to the end. Is that okay?
830 for (i = 0, spotToAdd = ret; i < index && *spotToAdd;
831 spotToAdd += lstrlenW(spotToAdd) + 1)
834 if (spotToAdd)
836 /* Copy existing string "right" */
837 memmove(spotToAdd + lstrlenW(toAdd) + 1, spotToAdd,
838 (len - (spotToAdd - ret)) * sizeof(WCHAR));
839 /* Copy new string */
840 memcpy(spotToAdd, toAdd, (lstrlenW(toAdd) + 1) * sizeof(WCHAR));
842 else
844 CryptMemFree(ret);
845 ret = NULL;
849 return ret;
852 static BOOL CRYPT_RemoveStringFromMultiString(LPWSTR multi, LPCWSTR toRemove)
854 LPWSTR spotToRemove = (LPWSTR)CRYPT_FindStringInMultiString(multi,
855 toRemove);
856 BOOL ret;
858 if (spotToRemove)
860 DWORD len = CRYPT_GetMultiStringCharacterLen(multi);
862 if (spotToRemove + lstrlenW(toRemove) + 2 >= multi + len)
864 /* Removing last string in list, terminate multi string directly */
865 *spotToRemove = 0;
866 *(spotToRemove + 1) = 0;
868 else
870 LPCWSTR nextStr = spotToRemove + lstrlenW(toRemove) + 1;
872 /* Copy remainder of string "left" */
873 memmove(spotToRemove, nextStr,
874 (len - (nextStr - multi)) * sizeof(WCHAR));
876 ret = TRUE;
878 else
880 SetLastError(ERROR_FILE_NOT_FOUND);
881 ret = FALSE;
883 return ret;
886 static BOOL CRYPT_GetDefaultOIDKey(DWORD dwEncodingType, LPCSTR pszFuncName,
887 PHKEY key)
889 LPSTR keyName;
890 LONG r;
892 keyName = CRYPT_GetKeyName(dwEncodingType, pszFuncName, "DEFAULT");
893 TRACE("Key name is %s\n", debugstr_a(keyName));
895 if (!keyName)
896 return FALSE;
898 r = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, NULL, 0, KEY_ALL_ACCESS,
899 NULL, key, NULL);
900 CryptMemFree(keyName);
901 if (r != ERROR_SUCCESS)
903 SetLastError(r);
904 return FALSE;
906 return TRUE;
909 static LPWSTR CRYPT_GetDefaultOIDDlls(HKEY key)
911 LONG r;
912 DWORD type, size;
913 LPWSTR dlls;
915 r = RegQueryValueExW(key, DllW, NULL, &type, NULL, &size);
916 if (r == ERROR_SUCCESS && type == REG_MULTI_SZ)
918 dlls = CryptMemAlloc(size);
919 r = RegQueryValueExW(key, DllW, NULL, &type, (LPBYTE)dlls, &size);
920 if (r != ERROR_SUCCESS)
922 CryptMemFree(dlls);
923 dlls = NULL;
926 else
927 dlls = NULL;
928 return dlls;
931 static inline BOOL CRYPT_SetDefaultOIDDlls(HKEY key, LPCWSTR dlls)
933 DWORD len = CRYPT_GetMultiStringCharacterLen(dlls);
934 LONG r;
936 if ((r = RegSetValueExW(key, DllW, 0, REG_MULTI_SZ, (const BYTE *)dlls,
937 len * sizeof (WCHAR))))
938 SetLastError(r);
939 return r == ERROR_SUCCESS;
942 /***********************************************************************
943 * CryptRegisterDefaultOIDFunction (CRYPT32.@)
945 BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType,
946 LPCSTR pszFuncName, DWORD dwIndex, LPCWSTR pwszDll)
948 HKEY key;
949 LPWSTR dlls;
950 BOOL ret = FALSE;
952 TRACE("(%x, %s, %d, %s)\n", dwEncodingType, debugstr_a(pszFuncName),
953 dwIndex, debugstr_w(pwszDll));
955 if (!pwszDll)
957 SetLastError(E_INVALIDARG);
958 return FALSE;
961 if (!CRYPT_GetDefaultOIDKey(dwEncodingType, pszFuncName, &key))
962 return FALSE;
964 dlls = CRYPT_GetDefaultOIDDlls(key);
965 if (CRYPT_FindStringInMultiString(dlls, pwszDll))
966 SetLastError(ERROR_FILE_EXISTS);
967 else
969 dlls = CRYPT_AddStringToMultiString(dlls, pwszDll, dwIndex);
970 if (dlls)
971 ret = CRYPT_SetDefaultOIDDlls(key, dlls);
973 CryptMemFree(dlls);
974 RegCloseKey(key);
975 return ret;
978 BOOL WINAPI CryptUnregisterDefaultOIDFunction(DWORD dwEncodingType,
979 LPCSTR pszFuncName, LPCWSTR pwszDll)
981 HKEY key;
982 LPWSTR dlls;
983 BOOL ret;
985 TRACE("(%x, %s, %s)\n", dwEncodingType, debugstr_a(pszFuncName),
986 debugstr_w(pwszDll));
988 if (!pwszDll)
990 SetLastError(E_INVALIDARG);
991 return FALSE;
994 if (!CRYPT_GetDefaultOIDKey(dwEncodingType, pszFuncName, &key))
995 return FALSE;
997 dlls = CRYPT_GetDefaultOIDDlls(key);
998 if ((ret = CRYPT_RemoveStringFromMultiString(dlls, pwszDll)))
999 ret = CRYPT_SetDefaultOIDDlls(key, dlls);
1000 CryptMemFree(dlls);
1001 RegCloseKey(key);
1002 return ret;
1005 static void oid_init_localizednames(void)
1007 unsigned int i;
1009 for(i = 0; i < sizeof(LocalizedKeys)/sizeof(LPCWSTR); i++)
1011 LoadStringW(hInstance, IDS_LOCALIZEDNAME_ROOT+i, LocalizedNames[i], 256);
1015 /********************************************************************
1016 * CryptFindLocalizedName (CRYPT32.@)
1018 LPCWSTR WINAPI CryptFindLocalizedName(LPCWSTR pwszCryptName)
1020 unsigned int i;
1022 for(i = 0; i < sizeof(LocalizedKeys)/sizeof(LPCWSTR); i++)
1024 if(!lstrcmpiW(LocalizedKeys[i], pwszCryptName))
1026 return LocalizedNames[i];
1030 FIXME("No name for: %s - stub\n",debugstr_w(pwszCryptName));
1031 return NULL;
1034 static CRITICAL_SECTION oidInfoCS;
1035 static CRITICAL_SECTION_DEBUG oidInfoCSDebug =
1037 0, 0, &oidInfoCS,
1038 { &oidInfoCSDebug.ProcessLocksList, &oidInfoCSDebug.ProcessLocksList },
1039 0, 0, { (DWORD_PTR)(__FILE__ ": oidInfoCS") }
1041 static CRITICAL_SECTION oidInfoCS = { &oidInfoCSDebug, -1, 0, 0, 0, 0 };
1042 static struct list oidInfo = { &oidInfo, &oidInfo };
1044 static const WCHAR tripledes[] = { '3','d','e','s',0 };
1045 static const WCHAR cms3deswrap[] = { 'C','M','S','3','D','E','S','w','r','a',
1046 'p',0 };
1047 static const WCHAR cmsrc2wrap[] = { 'C','M','S','R','C','2','w','r','a','p',0 };
1048 static const WCHAR des[] = { 'd','e','s',0 };
1049 static const WCHAR md2[] = { 'm','d','2',0 };
1050 static const WCHAR md4[] = { 'm','d','4',0 };
1051 static const WCHAR md5[] = { 'm','d','5',0 };
1052 static const WCHAR rc2[] = { 'r','c','2',0 };
1053 static const WCHAR rc4[] = { 'r','c','4',0 };
1054 static const WCHAR sha[] = { 's','h','a',0 };
1055 static const WCHAR sha1[] = { 's','h','a','1',0 };
1056 static const WCHAR sha256[] = { 's','h','a','2','5','6',0 };
1057 static const WCHAR sha384[] = { 's','h','a','3','8','4',0 };
1058 static const WCHAR sha512[] = { 's','h','a','5','1','2',0 };
1059 static const WCHAR RSA[] = { 'R','S','A',0 };
1060 static const WCHAR RSA_KEYX[] = { 'R','S','A','_','K','E','Y','X',0 };
1061 static const WCHAR RSA_SIGN[] = { 'R','S','A','_','S','I','G','N',0 };
1062 static const WCHAR DSA[] = { 'D','S','A',0 };
1063 static const WCHAR DSA_SIGN[] = { 'D','S','A','_','S','I','G','N',0 };
1064 static const WCHAR DH[] = { 'D','H',0 };
1065 static const WCHAR DSS[] = { 'D','S','S',0 };
1066 static const WCHAR mosaicKMandUpdSig[] =
1067 { 'm','o','s','a','i','c','K','M','a','n','d','U','p','d','S','i','g',0 };
1068 static const WCHAR ESDH[] = { 'E','S','D','H',0 };
1069 static const WCHAR NO_SIGN[] = { 'N','O','S','I','G','N',0 };
1070 static const WCHAR dsaSHA1[] = { 'd','s','a','S','H','A','1',0 };
1071 static const WCHAR md2RSA[] = { 'm','d','2','R','S','A',0 };
1072 static const WCHAR md4RSA[] = { 'm','d','4','R','S','A',0 };
1073 static const WCHAR md5RSA[] = { 'm','d','5','R','S','A',0 };
1074 static const WCHAR shaDSA[] = { 's','h','a','D','S','A',0 };
1075 static const WCHAR sha1DSA[] = { 's','h','a','1','D','S','A',0 };
1076 static const WCHAR shaRSA[] = { 's','h','a','R','S','A',0 };
1077 static const WCHAR sha1RSA[] = { 's','h','a','1','R','S','A',0 };
1078 static const WCHAR sha256RSA[] = { 's','h','a','2','5','6','R','S','A',0 };
1079 static const WCHAR sha384RSA[] = { 's','h','a','3','8','4','R','S','A',0 };
1080 static const WCHAR sha512RSA[] = { 's','h','a','5','1','2','R','S','A',0 };
1081 static const WCHAR mosaicUpdatedSig[] =
1082 { 'm','o','s','a','i','c','U','p','d','a','t','e','d','S','i','g',0 };
1083 static const WCHAR CN[] = { 'C','N',0 };
1084 static const WCHAR L[] = { 'L',0 };
1085 static const WCHAR O[] = { 'O',0 };
1086 static const WCHAR OU[] = { 'O','U',0 };
1087 static const WCHAR E[] = { 'E',0 };
1088 static const WCHAR C[] = { 'C',0 };
1089 static const WCHAR S[] = { 'S',0 };
1090 static const WCHAR ST[] = { 'S','T',0 };
1091 static const WCHAR STREET[] = { 'S','T','R','E','E','T',0 };
1092 static const WCHAR T[] = { 'T',0 };
1093 static const WCHAR Title[] = { 'T','i','t','l','e',0 };
1094 static const WCHAR G[] = { 'G',0 };
1095 static const WCHAR GivenName[] = { 'G','i','v','e','n','N','a','m','e',0 };
1096 static const WCHAR I[] = { 'I',0 };
1097 static const WCHAR Initials[] = { 'I','n','i','t','i','a','l','s',0 };
1098 static const WCHAR SN[] = { 'S','N',0 };
1099 static const WCHAR DC[] = { 'D','C',0 };
1100 static const WCHAR Description[] =
1101 { 'D','e','s','c','r','i','p','t','i','o','n',0 };
1102 static const WCHAR PostalCode[] = { 'P','o','s','t','a','l','C','o','d','e',0 };
1103 static const WCHAR POBox[] = { 'P','O','B','o','x',0 };
1104 static const WCHAR Phone[] = { 'P','h','o','n','e',0 };
1105 static const WCHAR X21Address[] = { 'X','2','1','A','d','d','r','e','s','s',0 };
1106 static const WCHAR dnQualifier[] =
1107 { 'd','n','Q','u','a','l','i','f','i','e','r',0 };
1108 static const WCHAR SpcSpAgencyInfo[] = { 'S','p','c','S','p','A','g','e','n','c','y','I','n','f','o',0 };
1109 static const WCHAR SpcFinancialCriteria[] = { 'S','p','c','F','i','n','a','n','c','i','a','l','C','r','i','t','e','r','i','a',0 };
1110 static const WCHAR SpcMinimalCriteria[] = { 'S','p','c','M','i','n','i','m','a','l','C','r','i','t','e','r','i','a',0 };
1111 static const WCHAR Email[] = { 'E','m','a','i','l',0 };
1112 static const WCHAR GN[] = { 'G','N',0 };
1114 static const DWORD noNullFlag = CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG;
1115 static const DWORD mosaicFlags = CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG |
1116 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG;
1117 static const CRYPT_DATA_BLOB noNullBlob = { sizeof(noNullFlag),
1118 (LPBYTE)&noNullFlag };
1119 static const CRYPT_DATA_BLOB mosaicFlagsBlob = { sizeof(mosaicFlags),
1120 (LPBYTE)&mosaicFlags };
1122 static const DWORD rsaSign = CALG_RSA_SIGN;
1123 static const DWORD dssSign[2] = { CALG_DSS_SIGN,
1124 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG };
1125 static const DWORD mosaicSign[2] = { CALG_DSS_SIGN,
1126 CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG |
1127 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG };
1128 static const CRYPT_DATA_BLOB rsaSignBlob = { sizeof(rsaSign),
1129 (LPBYTE)&rsaSign };
1130 static const CRYPT_DATA_BLOB dssSignBlob = { sizeof(dssSign),
1131 (LPBYTE)dssSign };
1132 static const CRYPT_DATA_BLOB mosaicSignBlob = { sizeof(mosaicSign),
1133 (LPBYTE)mosaicSign };
1135 static const DWORD ia5String[] = { CERT_RDN_IA5_STRING, 0 };
1136 static const DWORD numericString[] = { CERT_RDN_NUMERIC_STRING, 0 };
1137 static const DWORD printableString[] = { CERT_RDN_PRINTABLE_STRING, 0 };
1138 static const DWORD domainCompTypes[] = { CERT_RDN_IA5_STRING,
1139 CERT_RDN_UTF8_STRING, 0 };
1140 static const CRYPT_DATA_BLOB ia5StringBlob = { sizeof(ia5String),
1141 (LPBYTE)ia5String };
1142 static const CRYPT_DATA_BLOB numericStringBlob = { sizeof(numericString),
1143 (LPBYTE)numericString };
1144 static const CRYPT_DATA_BLOB printableStringBlob = { sizeof(printableString),
1145 (LPBYTE)printableString };
1146 static const CRYPT_DATA_BLOB domainCompTypesBlob = { sizeof(domainCompTypes),
1147 (LPBYTE)domainCompTypes };
1149 static const struct OIDInfoConstructor {
1150 DWORD dwGroupId;
1151 LPCSTR pszOID;
1152 UINT Algid;
1153 LPCWSTR pwszName;
1154 const CRYPT_DATA_BLOB *blob;
1155 } oidInfoConstructors[] = {
1156 { 1, szOID_OIWSEC_sha1, CALG_SHA1, sha1, NULL },
1157 { 1, szOID_OIWSEC_sha1, CALG_SHA1, sha, NULL },
1158 { 1, szOID_OIWSEC_sha, CALG_SHA, sha, NULL },
1159 { 1, szOID_RSA_MD5, CALG_MD5, md5, NULL },
1160 { 1, szOID_RSA_MD4, CALG_MD4, md4, NULL },
1161 { 1, szOID_RSA_MD2, CALG_MD2, md2, NULL },
1163 { 2, szOID_OIWSEC_desCBC, CALG_DES, des, NULL },
1164 { 2, szOID_RSA_DES_EDE3_CBC, CALG_3DES, tripledes, NULL },
1165 { 2, szOID_RSA_RC2CBC, CALG_RC2, rc2, NULL },
1166 { 2, szOID_RSA_RC4, CALG_RC4, rc4, NULL },
1167 { 2, szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES, cms3deswrap, NULL },
1168 { 2, szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2, cmsrc2wrap, NULL },
1170 { 3, szOID_RSA_RSA, CALG_RSA_KEYX, RSA, NULL },
1171 { 3, szOID_X957_DSA, CALG_DSS_SIGN, DSA, &noNullBlob },
1172 { 3, szOID_ANSI_X942_DH, CALG_DH_SF, DH, &noNullBlob },
1173 { 3, szOID_RSA_RSA, CALG_RSA_KEYX, RSA_KEYX, NULL },
1174 { 3, szOID_RSA_RSA, CALG_RSA_SIGN, RSA, NULL },
1175 { 3, szOID_RSA_RSA, CALG_RSA_SIGN, RSA_SIGN, NULL },
1176 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSA, &noNullBlob },
1177 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSS, &noNullBlob },
1178 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSA_SIGN, &noNullBlob },
1179 { 3, szOID_RSA_DH, CALG_DH_SF, DH, &noNullBlob },
1180 { 3, szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX, RSA_KEYX, NULL },
1181 { 3, szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN, mosaicKMandUpdSig,
1182 &mosaicFlagsBlob },
1183 { 3, szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM, ESDH, &noNullBlob },
1184 { 3, szOID_PKIX_NO_SIGNATURE, CALG_NO_SIGN, NO_SIGN, NULL },
1186 { 4, szOID_RSA_SHA1RSA, CALG_SHA1, sha1RSA, &rsaSignBlob },
1187 { 4, szOID_RSA_SHA256RSA, CALG_SHA_256, sha256RSA, &rsaSignBlob },
1188 { 4, szOID_RSA_SHA384RSA, CALG_SHA_384, sha384RSA, &rsaSignBlob },
1189 { 4, szOID_RSA_SHA512RSA, CALG_SHA_512, sha512RSA, &rsaSignBlob },
1190 { 4, szOID_RSA_MD5RSA, CALG_MD5, md5RSA, &rsaSignBlob },
1191 { 4, szOID_X957_SHA1DSA, CALG_SHA1, sha1DSA, &dssSignBlob },
1192 { 4, szOID_OIWSEC_sha1RSASign, CALG_SHA1, sha1RSA, &rsaSignBlob },
1193 { 4, szOID_OIWSEC_sha1RSASign, CALG_SHA1, shaRSA, &rsaSignBlob },
1194 { 4, szOID_OIWSEC_shaRSA, CALG_SHA1, shaRSA, &rsaSignBlob },
1195 { 4, szOID_OIWSEC_md5RSA, CALG_MD5, md5RSA, &rsaSignBlob },
1196 { 4, szOID_RSA_MD2RSA, CALG_MD2, md2RSA, &rsaSignBlob },
1197 { 4, szOID_RSA_MD4RSA, CALG_MD4, md4RSA, &rsaSignBlob },
1198 { 4, szOID_OIWSEC_md4RSA, CALG_MD4, md4RSA, &rsaSignBlob },
1199 { 4, szOID_OIWSEC_md4RSA2, CALG_MD4, md4RSA, &rsaSignBlob },
1200 { 4, szOID_OIWDIR_md2RSA, CALG_MD2, md2RSA, &rsaSignBlob },
1201 { 4, szOID_OIWSEC_shaDSA, CALG_SHA1, sha1DSA, &dssSignBlob },
1202 { 4, szOID_OIWSEC_shaDSA, CALG_SHA1, shaDSA, &dssSignBlob },
1203 { 4, szOID_OIWSEC_dsaSHA1, CALG_SHA1, dsaSHA1, &dssSignBlob },
1204 { 4, szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA1, mosaicUpdatedSig,
1205 &mosaicSignBlob },
1207 { 5, szOID_COMMON_NAME, 0, CN, NULL },
1208 { 5, szOID_LOCALITY_NAME, 0, L, NULL },
1209 { 5, szOID_ORGANIZATION_NAME, 0, O, NULL },
1210 { 5, szOID_ORGANIZATIONAL_UNIT_NAME, 0, OU, NULL },
1211 { 5, szOID_RSA_emailAddr, 0, E, &ia5StringBlob },
1212 { 5, szOID_RSA_emailAddr, 0, Email, &ia5StringBlob },
1213 { 5, szOID_COUNTRY_NAME, 0, C, &printableStringBlob },
1214 { 5, szOID_STATE_OR_PROVINCE_NAME, 0, S, NULL },
1215 { 5, szOID_STATE_OR_PROVINCE_NAME, 0, ST, NULL },
1216 { 5, szOID_STREET_ADDRESS, 0, STREET, NULL },
1217 { 5, szOID_TITLE, 0, T, NULL },
1218 { 5, szOID_TITLE, 0, Title, NULL },
1219 { 5, szOID_GIVEN_NAME, 0, G, NULL },
1220 { 5, szOID_GIVEN_NAME, 0, GN, NULL },
1221 { 5, szOID_GIVEN_NAME, 0, GivenName, NULL },
1222 { 5, szOID_INITIALS, 0, I, NULL },
1223 { 5, szOID_INITIALS, 0, Initials, NULL },
1224 { 5, szOID_SUR_NAME, 0, SN, NULL },
1225 { 5, szOID_DOMAIN_COMPONENT, 0, DC, &domainCompTypesBlob },
1226 { 5, szOID_DESCRIPTION, 0, Description, NULL },
1227 { 5, szOID_POSTAL_CODE, 0, PostalCode, NULL },
1228 { 5, szOID_POST_OFFICE_BOX, 0, POBox, NULL },
1229 { 5, szOID_TELEPHONE_NUMBER, 0, Phone, &printableStringBlob },
1230 { 5, szOID_X21_ADDRESS, 0, X21Address, &numericStringBlob },
1231 { 5, szOID_DN_QUALIFIER, 0, dnQualifier, NULL },
1233 { 6, szOID_AUTHORITY_KEY_IDENTIFIER2, 0, (LPCWSTR)IDS_AUTHORITY_KEY_ID, NULL },
1234 { 6, szOID_AUTHORITY_KEY_IDENTIFIER, 0, (LPCWSTR)IDS_AUTHORITY_KEY_ID, NULL },
1235 { 6, szOID_KEY_ATTRIBUTES, 0, (LPCWSTR)IDS_KEY_ATTRIBUTES, NULL },
1236 { 6, szOID_KEY_USAGE_RESTRICTION, 0, (LPCWSTR)IDS_KEY_USAGE_RESTRICTION, NULL },
1237 { 6, szOID_SUBJECT_ALT_NAME2, 0, (LPCWSTR)IDS_SUBJECT_ALT_NAME, NULL },
1238 { 6, szOID_SUBJECT_ALT_NAME, 0, (LPCWSTR)IDS_SUBJECT_ALT_NAME, NULL },
1239 { 6, szOID_ISSUER_ALT_NAME2, 0, (LPCWSTR)IDS_ISSUER_ALT_NAME, NULL },
1240 { 6, szOID_ISSUER_ALT_NAME2, 0, (LPCWSTR)IDS_ISSUER_ALT_NAME, NULL },
1241 { 6, szOID_BASIC_CONSTRAINTS2, 0, (LPCWSTR)IDS_BASIC_CONSTRAINTS, NULL },
1242 { 6, szOID_BASIC_CONSTRAINTS, 0, (LPCWSTR)IDS_BASIC_CONSTRAINTS, NULL },
1243 { 6, szOID_KEY_USAGE, 0, (LPCWSTR)IDS_KEY_USAGE, NULL },
1244 { 6, szOID_CERT_POLICIES, 0, (LPCWSTR)IDS_CERT_POLICIES, NULL },
1245 { 6, szOID_SUBJECT_KEY_IDENTIFIER, 0, (LPCWSTR)IDS_SUBJECT_KEY_IDENTIFIER, NULL },
1246 { 6, szOID_CRL_REASON_CODE, 0, (LPCWSTR)IDS_CRL_REASON_CODE, NULL },
1247 { 6, szOID_CRL_DIST_POINTS, 0, (LPCWSTR)IDS_CRL_DIST_POINTS, NULL },
1248 { 6, szOID_ENHANCED_KEY_USAGE, 0, (LPCWSTR)IDS_ENHANCED_KEY_USAGE, NULL },
1249 { 6, szOID_AUTHORITY_INFO_ACCESS, 0, (LPCWSTR)IDS_AUTHORITY_INFO_ACCESS, NULL },
1250 { 6, szOID_CERT_EXTENSIONS, 0, (LPCWSTR)IDS_CERT_EXTENSIONS, NULL },
1251 { 6, szOID_RSA_certExtensions, 0, (LPCWSTR)IDS_CERT_EXTENSIONS, NULL },
1252 { 6, szOID_NEXT_UPDATE_LOCATION, 0, (LPCWSTR)IDS_NEXT_UPDATE_LOCATION, NULL },
1253 { 6, szOID_YESNO_TRUST_ATTR, 0, (LPCWSTR)IDS_YES_OR_NO_TRUST, NULL },
1254 { 6, szOID_RSA_emailAddr, 0, (LPCWSTR)IDS_EMAIL_ADDRESS, NULL },
1255 { 6, szOID_RSA_unstructName, 0, (LPCWSTR)IDS_UNSTRUCTURED_NAME, NULL },
1256 { 6, szOID_RSA_contentType, 0, (LPCWSTR)IDS_CONTENT_TYPE, NULL },
1257 { 6, szOID_RSA_messageDigest, 0, (LPCWSTR)IDS_MESSAGE_DIGEST, NULL },
1258 { 6, szOID_RSA_signingTime, 0, (LPCWSTR)IDS_SIGNING_TIME, NULL },
1259 { 6, szOID_RSA_counterSign, 0, (LPCWSTR)IDS_COUNTER_SIGN, NULL },
1260 { 6, szOID_RSA_challengePwd, 0, (LPCWSTR)IDS_CHALLENGE_PASSWORD, NULL },
1261 { 6, szOID_RSA_unstructAddr, 0, (LPCWSTR)IDS_UNSTRUCTURED_ADDRESS, NULL },
1262 { 6, szOID_RSA_SMIMECapabilities, 0, (LPCWSTR)IDS_SMIME_CAPABILITIES, NULL },
1263 { 6, szOID_RSA_preferSignedData, 0, (LPCWSTR)IDS_PREFER_SIGNED_DATA, NULL },
1264 { 6, szOID_PKIX_POLICY_QUALIFIER_CPS, 0, (LPCWSTR)IDS_CPS, NULL },
1265 { 6, szOID_PKIX_POLICY_QUALIFIER_USERNOTICE, 0, (LPCWSTR)IDS_USER_NOTICE, NULL },
1266 { 6, szOID_PKIX_OCSP, 0, (LPCWSTR)IDS_OCSP, NULL },
1267 { 6, szOID_PKIX_CA_ISSUERS, 0, (LPCWSTR)IDS_CA_ISSUER, NULL },
1268 { 6, szOID_ENROLL_CERTTYPE_EXTENSION, 0, (LPCWSTR)IDS_CERT_TEMPLATE_NAME, NULL },
1269 { 6, szOID_ENROLL_CERTTYPE_EXTENSION, 0, (LPCWSTR)IDS_CERT_TYPE, NULL },
1270 { 6, szOID_CERT_MANIFOLD, 0, (LPCWSTR)IDS_CERT_MANIFOLD, NULL },
1271 { 6, szOID_NETSCAPE_CERT_TYPE, 0, (LPCWSTR)IDS_NETSCAPE_CERT_TYPE, NULL },
1272 { 6, szOID_NETSCAPE_BASE_URL, 0, (LPCWSTR)IDS_NETSCAPE_BASE_URL, NULL },
1273 { 6, szOID_NETSCAPE_REVOCATION_URL, 0, (LPCWSTR)IDS_NETSCAPE_REVOCATION_URL, NULL },
1274 { 6, szOID_NETSCAPE_CA_REVOCATION_URL, 0, (LPCWSTR)IDS_NETSCAPE_CA_REVOCATION_URL, NULL },
1275 { 6, szOID_NETSCAPE_CERT_RENEWAL_URL, 0, (LPCWSTR)IDS_NETSCAPE_CERT_RENEWAL_URL, NULL },
1276 { 6, szOID_NETSCAPE_CA_POLICY_URL, 0, (LPCWSTR)IDS_NETSCAPE_CA_POLICY_URL, NULL },
1277 { 6, szOID_NETSCAPE_SSL_SERVER_NAME, 0, (LPCWSTR)IDS_NETSCAPE_SSL_SERVER_NAME, NULL },
1278 { 6, szOID_NETSCAPE_COMMENT, 0, (LPCWSTR)IDS_NETSCAPE_COMMENT, NULL },
1279 { 6, "1.3.6.1.4.1.311.2.1.10", 0, SpcSpAgencyInfo, NULL },
1280 { 6, "1.3.6.1.4.1.311.2.1.27", 0, SpcFinancialCriteria, NULL },
1281 { 6, "1.3.6.1.4.1.311.2.1.26", 0, SpcMinimalCriteria, NULL },
1282 { 6, szOID_COUNTRY_NAME, 0, (LPCWSTR)IDS_COUNTRY, NULL },
1283 { 6, szOID_ORGANIZATION_NAME, 0, (LPCWSTR)IDS_ORGANIZATION, NULL },
1284 { 6, szOID_ORGANIZATIONAL_UNIT_NAME, 0, (LPCWSTR)IDS_ORGANIZATIONAL_UNIT, NULL },
1285 { 6, szOID_COMMON_NAME, 0, (LPCWSTR)IDS_COMMON_NAME, NULL },
1286 { 6, szOID_LOCALITY_NAME, 0, (LPCWSTR)IDS_LOCALITY, NULL },
1287 { 6, szOID_STATE_OR_PROVINCE_NAME, 0, (LPCWSTR)IDS_STATE_OR_PROVINCE, NULL },
1288 { 6, szOID_TITLE, 0, (LPCWSTR)IDS_TITLE, NULL },
1289 { 6, szOID_GIVEN_NAME, 0, (LPCWSTR)IDS_GIVEN_NAME, NULL },
1290 { 6, szOID_INITIALS, 0, (LPCWSTR)IDS_INITIALS, NULL },
1291 { 6, szOID_SUR_NAME, 0, (LPCWSTR)IDS_SUR_NAME, NULL },
1292 { 6, szOID_DOMAIN_COMPONENT, 0, (LPCWSTR)IDS_DOMAIN_COMPONENT, NULL },
1293 { 6, szOID_STREET_ADDRESS, 0, (LPCWSTR)IDS_STREET_ADDRESS, NULL },
1294 { 6, szOID_DEVICE_SERIAL_NUMBER, 0, (LPCWSTR)IDS_SERIAL_NUMBER, NULL },
1295 { 6, szOID_CERTSRV_CA_VERSION, 0, (LPCWSTR)IDS_CA_VERSION, NULL },
1296 { 6, szOID_CERTSRV_CROSSCA_VERSION, 0, (LPCWSTR)IDS_CROSS_CA_VERSION, NULL },
1297 { 6, szOID_SERIALIZED, 0, (LPCWSTR)IDS_SERIALIZED_SIG_SERIAL_NUMBER, NULL },
1298 { 6, szOID_NT_PRINCIPAL_NAME, 0, (LPCWSTR)IDS_PRINCIPAL_NAME, NULL },
1299 { 6, szOID_PRODUCT_UPDATE, 0, (LPCWSTR)IDS_WINDOWS_PRODUCT_UPDATE, NULL },
1300 { 6, szOID_ENROLLMENT_NAME_VALUE_PAIR, 0, (LPCWSTR)IDS_ENROLLMENT_NAME_VALUE_PAIR, NULL },
1301 { 6, szOID_OS_VERSION, 0, (LPCWSTR)IDS_OS_VERSION, NULL },
1302 { 6, szOID_ENROLLMENT_CSP_PROVIDER, 0, (LPCWSTR)IDS_ENROLLMENT_CSP, NULL },
1303 { 6, szOID_CRL_NUMBER, 0, (LPCWSTR)IDS_CRL_NUMBER, NULL },
1304 { 6, szOID_DELTA_CRL_INDICATOR, 0, (LPCWSTR)IDS_DELTA_CRL_INDICATOR, NULL },
1305 { 6, szOID_ISSUING_DIST_POINT, 0, (LPCWSTR)IDS_ISSUING_DIST_POINT, NULL },
1306 { 6, szOID_FRESHEST_CRL, 0, (LPCWSTR)IDS_FRESHEST_CRL, NULL },
1307 { 6, szOID_NAME_CONSTRAINTS, 0, (LPCWSTR)IDS_NAME_CONSTRAINTS, NULL },
1308 { 6, szOID_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_POLICY_MAPPINGS, NULL },
1309 { 6, szOID_LEGACY_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_POLICY_MAPPINGS, NULL },
1310 { 6, szOID_POLICY_CONSTRAINTS, 0, (LPCWSTR)IDS_POLICY_CONSTRAINTS, NULL },
1311 { 6, szOID_CROSS_CERT_DIST_POINTS, 0, (LPCWSTR)IDS_CROSS_CERT_DIST_POINTS, NULL },
1312 { 6, szOID_APPLICATION_CERT_POLICIES, 0, (LPCWSTR)IDS_APPLICATION_POLICIES, NULL },
1313 { 6, szOID_APPLICATION_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_APPLICATION_POLICY_MAPPINGS, NULL },
1314 { 6, szOID_APPLICATION_POLICY_CONSTRAINTS, 0, (LPCWSTR)IDS_APPLICATION_POLICY_CONSTRAINTS, NULL },
1315 { 6, szOID_CT_PKI_DATA, 0, (LPCWSTR)IDS_CMC_DATA, NULL },
1316 { 6, szOID_CT_PKI_RESPONSE, 0, (LPCWSTR)IDS_CMC_RESPONSE, NULL },
1317 { 6, szOID_CMC, 0, (LPCWSTR)IDS_UNSIGNED_CMC_REQUEST, NULL },
1318 { 6, szOID_CMC_STATUS_INFO, 0, (LPCWSTR)IDS_CMC_STATUS_INFO, NULL },
1319 { 6, szOID_CMC_ADD_EXTENSIONS, 0, (LPCWSTR)IDS_CMC_EXTENSIONS, NULL },
1320 { 6, szOID_CTL, 0, (LPCWSTR)IDS_CMC_ATTRIBUTES, NULL },
1321 { 6, szOID_RSA_data, 0, (LPCWSTR)IDS_PKCS_7_DATA, NULL },
1322 { 6, szOID_RSA_signedData, 0, (LPCWSTR)IDS_PKCS_7_SIGNED, NULL },
1323 { 6, szOID_RSA_envelopedData, 0, (LPCWSTR)IDS_PKCS_7_ENVELOPED, NULL },
1324 { 6, szOID_RSA_signEnvData, 0, (LPCWSTR)IDS_PKCS_7_SIGNED_ENVELOPED, NULL },
1325 { 6, szOID_RSA_digestedData, 0, (LPCWSTR)IDS_PKCS_7_DIGESTED, NULL },
1326 { 6, szOID_RSA_encryptedData, 0, (LPCWSTR)IDS_PKCS_7_ENCRYPTED, NULL },
1327 { 6, szOID_CERTSRV_PREVIOUS_CERT_HASH, 0, (LPCWSTR)IDS_PREVIOUS_CA_CERT_HASH, NULL },
1328 { 6, szOID_CRL_VIRTUAL_BASE, 0, (LPCWSTR)IDS_CRL_VIRTUAL_BASE, NULL },
1329 { 6, szOID_CRL_NEXT_PUBLISH, 0, (LPCWSTR)IDS_CRL_NEXT_PUBLISH, NULL },
1330 { 6, szOID_KP_CA_EXCHANGE, 0, (LPCWSTR)IDS_CA_EXCHANGE, NULL },
1331 { 6, szOID_KP_KEY_RECOVERY_AGENT, 0, (LPCWSTR)IDS_KEY_RECOVERY_AGENT, NULL },
1332 { 6, szOID_CERTIFICATE_TEMPLATE, 0, (LPCWSTR)IDS_CERTIFICATE_TEMPLATE, NULL },
1333 { 6, szOID_ENTERPRISE_OID_ROOT, 0, (LPCWSTR)IDS_ENTERPRISE_ROOT_OID, NULL },
1334 { 6, szOID_RDN_DUMMY_SIGNER, 0, (LPCWSTR)IDS_RDN_DUMMY_SIGNER, NULL },
1335 { 6, szOID_ARCHIVED_KEY_ATTR, 0, (LPCWSTR)IDS_ARCHIVED_KEY_ATTR, NULL },
1336 { 6, szOID_CRL_SELF_CDP, 0, (LPCWSTR)IDS_CRL_SELF_CDP, NULL },
1337 { 6, szOID_REQUIRE_CERT_CHAIN_POLICY, 0, (LPCWSTR)IDS_REQUIRE_CERT_CHAIN_POLICY, NULL },
1338 { 6, szOID_CMC_TRANSACTION_ID, 0, (LPCWSTR)IDS_TRANSACTION_ID, NULL },
1339 { 6, szOID_CMC_SENDER_NONCE, 0, (LPCWSTR)IDS_SENDER_NONCE, NULL },
1340 { 6, szOID_CMC_RECIPIENT_NONCE, 0, (LPCWSTR)IDS_RECIPIENT_NONCE, NULL },
1341 { 6, szOID_CMC_REG_INFO, 0, (LPCWSTR)IDS_REG_INFO, NULL },
1342 { 6, szOID_CMC_GET_CERT, 0, (LPCWSTR)IDS_GET_CERTIFICATE, NULL },
1343 { 6, szOID_CMC_GET_CRL, 0, (LPCWSTR)IDS_GET_CRL, NULL },
1344 { 6, szOID_CMC_REVOKE_REQUEST, 0, (LPCWSTR)IDS_REVOKE_REQUEST, NULL },
1345 { 6, szOID_CMC_QUERY_PENDING, 0, (LPCWSTR)IDS_QUERY_PENDING, NULL },
1346 { 6, szOID_SORTED_CTL, 0, (LPCWSTR)IDS_SORTED_CTL, NULL },
1347 { 6, szOID_ARCHIVED_KEY_CERT_HASH, 0, (LPCWSTR)IDS_ARCHIVED_KEY_CERT_HASH, NULL },
1348 { 6, szOID_PRIVATEKEY_USAGE_PERIOD, 0, (LPCWSTR)IDS_PRIVATE_KEY_USAGE_PERIOD, NULL },
1349 { 6, szOID_REQUEST_CLIENT_INFO, 0, (LPCWSTR)IDS_CLIENT_INFORMATION, NULL },
1351 { 7, szOID_PKIX_KP_SERVER_AUTH, 0, (LPCWSTR)IDS_SERVER_AUTHENTICATION, NULL },
1352 { 7, szOID_PKIX_KP_CLIENT_AUTH, 0, (LPCWSTR)IDS_CLIENT_AUTHENTICATION, NULL },
1353 { 7, szOID_PKIX_KP_CODE_SIGNING, 0, (LPCWSTR)IDS_CODE_SIGNING, NULL },
1354 { 7, szOID_PKIX_KP_EMAIL_PROTECTION, 0, (LPCWSTR)IDS_SECURE_EMAIL, NULL },
1355 { 7, szOID_PKIX_KP_TIMESTAMP_SIGNING, 0, (LPCWSTR)IDS_TIME_STAMPING, NULL },
1356 { 7, szOID_KP_CTL_USAGE_SIGNING, 0, (LPCWSTR)IDS_MICROSOFT_TRUST_LIST_SIGNING, NULL },
1357 { 7, szOID_KP_TIME_STAMP_SIGNING, 0, (LPCWSTR)IDS_MICROSOFT_TIME_STAMPING, NULL },
1358 { 7, szOID_PKIX_KP_IPSEC_END_SYSTEM, 0, (LPCWSTR)IDS_IPSEC_END_SYSTEM, NULL },
1359 { 7, szOID_PKIX_KP_IPSEC_TUNNEL, 0, (LPCWSTR)IDS_IPSEC_TUNNEL, NULL },
1360 { 7, szOID_PKIX_KP_IPSEC_USER, 0, (LPCWSTR)IDS_IPSEC_USER, NULL },
1361 { 7, szOID_KP_EFS, 0, (LPCWSTR)IDS_EFS, NULL },
1362 { 7, szOID_WHQL_CRYPTO, 0, (LPCWSTR)IDS_WHQL_CRYPTO, NULL },
1363 { 7, szOID_NT5_CRYPTO, 0, (LPCWSTR)IDS_NT5_CRYPTO, NULL },
1364 { 7, szOID_OEM_WHQL_CRYPTO, 0, (LPCWSTR)IDS_OEM_WHQL_CRYPTO, NULL },
1365 { 7, szOID_EMBEDDED_NT_CRYPTO, 0, (LPCWSTR)IDS_EMBEDDED_NT_CRYPTO, NULL },
1366 { 7, szOID_LICENSES, 0, (LPCWSTR)IDS_KEY_PACK_LICENSES, NULL },
1367 { 7, szOID_LICENSE_SERVER, 0, (LPCWSTR)IDS_LICENSE_SERVER, NULL },
1368 { 7, szOID_KP_SMARTCARD_LOGON, 0, (LPCWSTR)IDS_SMART_CARD_LOGON, NULL },
1369 { 7, szOID_DRM, 0, (LPCWSTR)IDS_DIGITAL_RIGHTS, NULL },
1370 { 7, szOID_KP_QUALIFIED_SUBORDINATION, 0, (LPCWSTR)IDS_QUALIFIED_SUBORDINATION, NULL },
1371 { 7, szOID_KP_KEY_RECOVERY, 0, (LPCWSTR)IDS_KEY_RECOVERY, NULL },
1372 { 7, szOID_KP_DOCUMENT_SIGNING, 0, (LPCWSTR)IDS_DOCUMENT_SIGNING, NULL },
1373 { 7, szOID_IPSEC_KP_IKE_INTERMEDIATE, 0, (LPCWSTR)IDS_IPSEC_IKE_INTERMEDIATE, NULL },
1374 { 7, szOID_EFS_RECOVERY, 0, (LPCWSTR)IDS_FILE_RECOVERY, NULL },
1375 { 7, szOID_ROOT_LIST_SIGNER, 0, (LPCWSTR)IDS_ROOT_LIST_SIGNER, NULL },
1376 { 7, szOID_ANY_APPLICATION_POLICY, 0, (LPCWSTR)IDS_ANY_APPLICATION_POLICIES, NULL },
1377 { 7, szOID_DS_EMAIL_REPLICATION, 0, (LPCWSTR)IDS_DS_EMAIL_REPLICATION, NULL },
1378 { 7, szOID_ENROLLMENT_AGENT, 0, (LPCWSTR)IDS_ENROLLMENT_AGENT, NULL },
1379 { 7, szOID_KP_KEY_RECOVERY_AGENT, 0, (LPCWSTR)IDS_KEY_RECOVERY_AGENT, NULL },
1380 { 7, szOID_KP_CA_EXCHANGE, 0, (LPCWSTR)IDS_CA_EXCHANGE, NULL },
1381 { 7, szOID_KP_LIFETIME_SIGNING, 0, (LPCWSTR)IDS_LIFETIME_SIGNING, NULL },
1383 { 8, szOID_ANY_CERT_POLICY, 0, (LPCWSTR)IDS_ANY_CERT_POLICY, NULL },
1386 struct OIDInfo {
1387 CRYPT_OID_INFO info;
1388 struct list entry;
1391 static void init_oid_info(void)
1393 DWORD i;
1395 oid_init_localizednames();
1396 for (i = 0; i < sizeof(oidInfoConstructors) /
1397 sizeof(oidInfoConstructors[0]); i++)
1399 if (!IS_INTRESOURCE(oidInfoConstructors[i].pwszName))
1401 struct OIDInfo *info;
1403 /* The name is a static string, so just use the same pointer */
1404 info = CryptMemAlloc(sizeof(struct OIDInfo));
1405 if (info)
1407 memset(info, 0, sizeof(*info));
1408 info->info.cbSize = sizeof(CRYPT_OID_INFO);
1409 info->info.pszOID = oidInfoConstructors[i].pszOID;
1410 info->info.pwszName = oidInfoConstructors[i].pwszName;
1411 info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
1412 info->info.u.Algid = oidInfoConstructors[i].Algid;
1413 if (oidInfoConstructors[i].blob)
1415 info->info.ExtraInfo.cbData =
1416 oidInfoConstructors[i].blob->cbData;
1417 info->info.ExtraInfo.pbData =
1418 oidInfoConstructors[i].blob->pbData;
1420 list_add_tail(&oidInfo, &info->entry);
1423 else
1425 LPCWSTR stringresource;
1426 int len = LoadStringW(hInstance,
1427 (UINT_PTR)oidInfoConstructors[i].pwszName,
1428 (LPWSTR)&stringresource, 0);
1430 if (len)
1432 struct OIDInfo *info = CryptMemAlloc(sizeof(struct OIDInfo) +
1433 (len + 1) * sizeof(WCHAR));
1435 if (info)
1437 memset(info, 0, sizeof(*info));
1438 info->info.cbSize = sizeof(CRYPT_OID_INFO);
1439 info->info.pszOID = oidInfoConstructors[i].pszOID;
1440 info->info.pwszName = (LPWSTR)(info + 1);
1441 info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
1442 info->info.u.Algid = oidInfoConstructors[i].Algid;
1443 memcpy(info + 1, stringresource, len*sizeof(WCHAR));
1444 ((LPWSTR)(info + 1))[len] = 0;
1445 if (oidInfoConstructors[i].blob)
1447 info->info.ExtraInfo.cbData =
1448 oidInfoConstructors[i].blob->cbData;
1449 info->info.ExtraInfo.pbData =
1450 oidInfoConstructors[i].blob->pbData;
1452 list_add_tail(&oidInfo, &info->entry);
1459 static void free_oid_info(void)
1461 struct OIDInfo *info, *next;
1463 LIST_FOR_EACH_ENTRY_SAFE(info, next, &oidInfo, struct OIDInfo, entry)
1465 list_remove(&info->entry);
1466 CryptMemFree(info);
1468 DeleteCriticalSection(&oidInfoCS);
1471 /***********************************************************************
1472 * CryptEnumOIDInfo (CRYPT32.@)
1474 BOOL WINAPI CryptEnumOIDInfo(DWORD dwGroupId, DWORD dwFlags, void *pvArg,
1475 PFN_CRYPT_ENUM_OID_INFO pfnEnumOIDInfo)
1477 BOOL ret = TRUE;
1478 struct OIDInfo *info;
1480 TRACE("(%d, %08x, %p, %p)\n", dwGroupId, dwFlags, pvArg,
1481 pfnEnumOIDInfo);
1483 EnterCriticalSection(&oidInfoCS);
1484 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1486 if (!dwGroupId || dwGroupId == info->info.dwGroupId)
1488 ret = pfnEnumOIDInfo(&info->info, pvArg);
1489 if (!ret)
1490 break;
1493 LeaveCriticalSection(&oidInfoCS);
1494 return ret;
1497 PCCRYPT_OID_INFO WINAPI CryptFindOIDInfo(DWORD dwKeyType, void *pvKey,
1498 DWORD dwGroupId)
1500 PCCRYPT_OID_INFO ret = NULL;
1502 TRACE("(%d, %p, %d)\n", dwKeyType, pvKey, dwGroupId);
1504 switch(dwKeyType)
1506 case CRYPT_OID_INFO_ALGID_KEY:
1508 struct OIDInfo *info;
1510 TRACE("CRYPT_OID_INFO_ALGID_KEY: %d\n", *(DWORD *)pvKey);
1511 EnterCriticalSection(&oidInfoCS);
1512 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1514 if (info->info.u.Algid == *(DWORD *)pvKey &&
1515 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1517 ret = &info->info;
1518 break;
1521 LeaveCriticalSection(&oidInfoCS);
1522 break;
1524 case CRYPT_OID_INFO_NAME_KEY:
1526 struct OIDInfo *info;
1528 TRACE("CRYPT_OID_INFO_NAME_KEY: %s\n", debugstr_w(pvKey));
1529 EnterCriticalSection(&oidInfoCS);
1530 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1532 if (!lstrcmpW(info->info.pwszName, pvKey) &&
1533 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1535 ret = &info->info;
1536 break;
1539 LeaveCriticalSection(&oidInfoCS);
1540 break;
1542 case CRYPT_OID_INFO_OID_KEY:
1544 struct OIDInfo *info;
1545 LPSTR oid = pvKey;
1547 TRACE("CRYPT_OID_INFO_OID_KEY: %s\n", debugstr_a(oid));
1548 EnterCriticalSection(&oidInfoCS);
1549 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1551 if (!lstrcmpA(info->info.pszOID, oid) &&
1552 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1554 ret = &info->info;
1555 break;
1558 LeaveCriticalSection(&oidInfoCS);
1559 break;
1561 case CRYPT_OID_INFO_SIGN_KEY:
1563 struct OIDInfo *info;
1565 TRACE("CRYPT_OID_INFO_SIGN_KEY: %d\n", *(DWORD *)pvKey);
1566 EnterCriticalSection(&oidInfoCS);
1567 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1569 if (info->info.u.Algid == *(DWORD *)pvKey &&
1570 info->info.ExtraInfo.cbData >= sizeof(DWORD) &&
1571 *(DWORD *)info->info.ExtraInfo.pbData ==
1572 *(DWORD *)((LPBYTE)pvKey + sizeof(DWORD)) &&
1573 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1575 ret = &info->info;
1576 break;
1579 LeaveCriticalSection(&oidInfoCS);
1580 break;
1583 return ret;
1586 LPCSTR WINAPI CertAlgIdToOID(DWORD dwAlgId)
1588 LPCSTR ret;
1589 PCCRYPT_OID_INFO info = CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY,
1590 &dwAlgId, 0);
1592 if (info)
1593 ret = info->pszOID;
1594 else
1595 ret = NULL;
1596 return ret;
1599 DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId)
1601 DWORD ret;
1602 PCCRYPT_OID_INFO info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY,
1603 (void *)pszObjId, 0);
1605 if (info)
1606 ret = info->u.Algid;
1607 else
1608 ret = 0;
1609 return ret;
1612 void crypt_oid_init(void)
1614 init_oid_info();
1617 void crypt_oid_free(void)
1619 free_function_sets();
1620 free_oid_info();