gdiplus: Implemented GdipGetPenDashCount.
[wine.git] / dlls / crypt32 / oid.c
blob5a71c74b0bd224e7e7c5605628332c359059cba3
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 void init_oid_info(HINSTANCE hinst);
41 static void free_function_sets(void);
42 static void free_oid_info(void);
44 void crypt_oid_init(HINSTANCE hinst)
46 init_oid_info(hinst);
49 void crypt_oid_free(void)
51 free_function_sets();
52 free_oid_info();
55 static CRITICAL_SECTION funcSetCS;
56 static CRITICAL_SECTION_DEBUG funcSetCSDebug =
58 0, 0, &funcSetCS,
59 { &funcSetCSDebug.ProcessLocksList, &funcSetCSDebug.ProcessLocksList },
60 0, 0, { (DWORD_PTR)(__FILE__ ": funcSetCS") }
62 static CRITICAL_SECTION funcSetCS = { &funcSetCSDebug, -1, 0, 0, 0, 0 };
63 static struct list funcSets = { &funcSets, &funcSets };
65 struct OIDFunctionSet
67 LPSTR name;
68 CRITICAL_SECTION cs; /* protects functions */
69 struct list functions;
70 struct list next;
73 struct OIDFunction
75 DWORD encoding;
76 CRYPT_OID_FUNC_ENTRY entry;
77 struct list next;
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 LPCWSTR LocalizedKeys[] = {ROOT,MY,CA,ADDRESSBOOK};
85 static WCHAR LocalizedNames[4][256];
87 static void free_function_sets(void)
89 struct OIDFunctionSet *setCursor, *setNext;
91 LIST_FOR_EACH_ENTRY_SAFE(setCursor, setNext, &funcSets,
92 struct OIDFunctionSet, next)
94 struct OIDFunction *functionCursor, *funcNext;
96 list_remove(&setCursor->next);
97 CryptMemFree(setCursor->name);
98 LIST_FOR_EACH_ENTRY_SAFE(functionCursor, funcNext,
99 &setCursor->functions, struct OIDFunction, next)
101 list_remove(&functionCursor->next);
102 CryptMemFree(functionCursor);
104 setCursor->cs.DebugInfo->Spare[0] = 0;
105 DeleteCriticalSection(&setCursor->cs);
106 CryptMemFree(setCursor);
110 /* There is no free function associated with this; therefore, the sets are
111 * freed when crypt32.dll is unloaded.
113 HCRYPTOIDFUNCSET WINAPI CryptInitOIDFunctionSet(LPCSTR pszFuncName,
114 DWORD dwFlags)
116 struct OIDFunctionSet *cursor, *ret = NULL;
118 TRACE("(%s, %x)\n", debugstr_a(pszFuncName), dwFlags);
120 EnterCriticalSection(&funcSetCS);
121 LIST_FOR_EACH_ENTRY(cursor, &funcSets, struct OIDFunctionSet, next)
123 if (!strcasecmp(pszFuncName, cursor->name))
125 ret = (HCRYPTOIDFUNCSET)cursor;
126 break;
129 if (!ret)
131 ret = CryptMemAlloc(sizeof(struct OIDFunctionSet));
132 if (ret)
134 memset(ret, 0, sizeof(*ret));
135 ret->name = CryptMemAlloc(strlen(pszFuncName) + 1);
136 if (ret->name)
138 InitializeCriticalSection(&ret->cs);
139 ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": OIDFunctionSet.cs");
140 list_init(&ret->functions);
141 strcpy(ret->name, pszFuncName);
142 list_add_tail(&funcSets, &ret->next);
144 else
146 CryptMemFree(ret);
147 ret = NULL;
151 LeaveCriticalSection(&funcSetCS);
153 return (HCRYPTOIDFUNCSET)ret;
156 static char *CRYPT_GetKeyName(DWORD dwEncodingType, LPCSTR pszFuncName,
157 LPCSTR pszOID)
159 static const char szEncodingTypeFmt[] =
160 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\%s";
161 UINT len;
162 char numericOID[7]; /* enough for "#65535" */
163 const char *oid;
164 LPSTR szKey;
166 /* MSDN says the encoding type is a mask, but it isn't treated that way.
167 * (E.g., if dwEncodingType were 3, the key names "EncodingType 1" and
168 * "EncodingType 2" would be expected if it were a mask. Instead native
169 * stores values in "EncodingType 3".
171 if (!HIWORD(pszOID))
173 snprintf(numericOID, sizeof(numericOID), "#%d", LOWORD(pszOID));
174 oid = numericOID;
176 else
177 oid = pszOID;
179 /* This is enough: the lengths of the two string parameters are explicitly
180 * counted, and we need up to five additional characters for the encoding
181 * type. These are covered by the "%d", "%s", and "%s" characters in the
182 * format specifier that are removed by sprintf.
184 len = sizeof(szEncodingTypeFmt) + lstrlenA(pszFuncName) + lstrlenA(oid);
185 szKey = CryptMemAlloc(len);
186 if (szKey)
187 sprintf(szKey, szEncodingTypeFmt,
188 GET_CERT_ENCODING_TYPE(dwEncodingType), pszFuncName, oid);
189 return szKey;
192 BOOL WINAPI CryptGetDefaultOIDDllList(HCRYPTOIDFUNCSET hFuncSet,
193 DWORD dwEncodingType, LPWSTR pwszDllList, DWORD *pcchDllList)
195 BOOL ret = TRUE;
196 struct OIDFunctionSet *set = (struct OIDFunctionSet *)hFuncSet;
197 char *keyName;
198 HKEY key;
199 long rc;
201 TRACE("(%p, %d, %p, %p)\n", hFuncSet, dwEncodingType, pwszDllList,
202 pcchDllList);
204 keyName = CRYPT_GetKeyName(dwEncodingType, set->name, "DEFAULT");
205 rc = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, NULL, 0,
206 KEY_READ, NULL, &key, NULL);
207 if (!rc)
209 DWORD size = *pcchDllList * sizeof(WCHAR);
211 rc = RegQueryValueExW(key, DllW, NULL, NULL, (LPBYTE)pwszDllList,
212 &size);
213 if (!rc)
214 *pcchDllList = size / sizeof(WCHAR);
215 else
217 /* No value, return an empty list */
218 if (pwszDllList && *pcchDllList)
219 *pwszDllList = '\0';
220 *pcchDllList = 1;
222 RegCloseKey(key);
224 else
226 /* No value, return an empty list */
227 if (pwszDllList && *pcchDllList)
228 *pwszDllList = '\0';
229 *pcchDllList = 1;
231 CryptMemFree(keyName);
233 return ret;
236 BOOL WINAPI CryptInstallOIDFunctionAddress(HMODULE hModule,
237 DWORD dwEncodingType, LPCSTR pszFuncName, DWORD cFuncEntry,
238 const CRYPT_OID_FUNC_ENTRY rgFuncEntry[], DWORD dwFlags)
240 BOOL ret = TRUE;
241 struct OIDFunctionSet *set;
243 TRACE("(%p, %d, %s, %d, %p, %08x)\n", hModule, dwEncodingType,
244 debugstr_a(pszFuncName), cFuncEntry, rgFuncEntry, dwFlags);
246 set = (struct OIDFunctionSet *)CryptInitOIDFunctionSet(pszFuncName, 0);
247 if (set)
249 DWORD i;
251 EnterCriticalSection(&set->cs);
252 for (i = 0; ret && i < cFuncEntry; i++)
254 struct OIDFunction *func;
256 if (HIWORD(rgFuncEntry[i].pszOID))
257 func = CryptMemAlloc(sizeof(struct OIDFunction)
258 + strlen(rgFuncEntry[i].pszOID) + 1);
259 else
260 func = CryptMemAlloc(sizeof(struct OIDFunction));
261 if (func)
263 func->encoding = GET_CERT_ENCODING_TYPE(dwEncodingType);
264 if (HIWORD(rgFuncEntry[i].pszOID))
266 LPSTR oid;
268 oid = (LPSTR)((LPBYTE)func + sizeof(*func));
269 strcpy(oid, rgFuncEntry[i].pszOID);
270 func->entry.pszOID = oid;
272 else
273 func->entry.pszOID = rgFuncEntry[i].pszOID;
274 func->entry.pvFuncAddr = rgFuncEntry[i].pvFuncAddr;
275 list_add_tail(&set->functions, &func->next);
277 else
278 ret = FALSE;
280 LeaveCriticalSection(&set->cs);
282 else
283 ret = FALSE;
284 return ret;
287 struct FuncAddr
289 HMODULE lib;
290 LPWSTR dllList;
291 LPWSTR currentDll;
294 static BOOL CRYPT_GetFuncFromReg(DWORD dwEncodingType, LPCSTR pszOID,
295 LPCSTR szFuncName, LPVOID *ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
297 BOOL ret = FALSE;
298 char *keyName;
299 const char *funcName;
300 HKEY key;
301 long rc;
303 keyName = CRYPT_GetKeyName(dwEncodingType, szFuncName, pszOID);
304 rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &key);
305 if (!rc)
307 DWORD type, size = 0;
309 rc = RegQueryValueExA(key, "FuncName", NULL, &type, NULL, &size);
310 if ((!rc || rc == ERROR_MORE_DATA) && type == REG_SZ)
312 funcName = CryptMemAlloc(size);
313 rc = RegQueryValueExA(key, "FuncName", NULL, &type,
314 (LPBYTE)funcName, &size);
316 else
317 funcName = szFuncName;
318 rc = RegQueryValueExW(key, DllW, NULL, &type, NULL, &size);
319 if ((!rc || rc == ERROR_MORE_DATA) && type == REG_SZ)
321 LPWSTR dllName = CryptMemAlloc(size);
323 if (dllName)
325 rc = RegQueryValueExW(key, DllW, NULL, NULL,
326 (LPBYTE)dllName, &size);
327 if (!rc)
329 HMODULE lib;
331 /* This is a bit of a hack; MSDN describes a more
332 * complicated unload routine than this will allow.
333 * Still, this seems to suffice for now.
335 lib = LoadLibraryW(dllName);
336 if (lib)
338 *ppvFuncAddr = GetProcAddress(lib, funcName);
339 if (*ppvFuncAddr)
341 struct FuncAddr *addr =
342 CryptMemAlloc(sizeof(struct FuncAddr));
344 if (addr)
346 addr->lib = lib;
347 addr->dllList = addr->currentDll = NULL;
348 *phFuncAddr = addr;
349 ret = TRUE;
351 else
353 *phFuncAddr = NULL;
354 FreeLibrary(lib);
357 else
359 /* Unload the library, the caller doesn't want
360 * to unload it when the return value is NULL.
362 FreeLibrary(lib);
366 else
367 SetLastError(rc);
368 CryptMemFree(dllName);
371 else
372 SetLastError(rc);
373 if (funcName != szFuncName)
374 CryptMemFree((char *)funcName);
375 RegCloseKey(key);
377 else
378 SetLastError(rc);
379 CryptMemFree(keyName);
380 return ret;
383 BOOL WINAPI CryptGetOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet,
384 DWORD dwEncodingType, LPCSTR pszOID, DWORD dwFlags, void **ppvFuncAddr,
385 HCRYPTOIDFUNCADDR *phFuncAddr)
387 BOOL ret = FALSE;
388 struct OIDFunctionSet *set = (struct OIDFunctionSet *)hFuncSet;
390 TRACE("(%p, %d, %s, %08x, %p, %p)\n", hFuncSet, dwEncodingType,
391 debugstr_a(pszOID), dwFlags, ppvFuncAddr, phFuncAddr);
393 *ppvFuncAddr = NULL;
394 if (!(dwFlags & CRYPT_GET_INSTALLED_OID_FUNC_FLAG))
396 struct OIDFunction *function;
398 EnterCriticalSection(&set->cs);
399 LIST_FOR_EACH_ENTRY(function, &set->functions, struct OIDFunction, next)
401 if (function->encoding == GET_CERT_ENCODING_TYPE(dwEncodingType))
403 if (HIWORD(pszOID))
405 if (HIWORD(function->entry.pszOID) &&
406 !strcasecmp(function->entry.pszOID, pszOID))
408 *ppvFuncAddr = function->entry.pvFuncAddr;
409 *phFuncAddr = NULL; /* FIXME: what should it be? */
410 ret = TRUE;
411 break;
414 else if (function->entry.pszOID == pszOID)
416 *ppvFuncAddr = function->entry.pvFuncAddr;
417 *phFuncAddr = NULL; /* FIXME: what should it be? */
418 ret = TRUE;
419 break;
423 LeaveCriticalSection(&set->cs);
425 if (!*ppvFuncAddr)
426 ret = CRYPT_GetFuncFromReg(dwEncodingType, pszOID, set->name,
427 ppvFuncAddr, phFuncAddr);
428 TRACE("returning %d\n", ret);
429 return ret;
432 BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr,
433 DWORD dwFlags)
435 TRACE("(%p, %08x)\n", hFuncAddr, dwFlags);
437 /* FIXME: as MSDN states, need to check for DllCanUnloadNow in the DLL,
438 * and only unload it if it can be unloaded. Also need to implement ref
439 * counting on the functions.
441 if (hFuncAddr)
443 struct FuncAddr *addr = (struct FuncAddr *)hFuncAddr;
445 CryptMemFree(addr->dllList);
446 FreeLibrary(addr->lib);
447 CryptMemFree(addr);
449 return TRUE;
452 static BOOL CRYPT_GetFuncFromDll(LPCWSTR dll, LPCSTR func, HMODULE *lib,
453 void **ppvFuncAddr)
455 BOOL ret = FALSE;
457 *lib = LoadLibraryW(dll);
458 if (*lib)
460 *ppvFuncAddr = GetProcAddress(*lib, func);
461 if (*ppvFuncAddr)
462 ret = TRUE;
463 else
465 FreeLibrary(*lib);
466 *lib = NULL;
469 return ret;
472 BOOL WINAPI CryptGetDefaultOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet,
473 DWORD dwEncodingType, LPCWSTR pwszDll, DWORD dwFlags, void **ppvFuncAddr,
474 HCRYPTOIDFUNCADDR *phFuncAddr)
476 struct OIDFunctionSet *set = (struct OIDFunctionSet *)hFuncSet;
477 BOOL ret = FALSE;
479 TRACE("(%p, %d, %s, %08x, %p, %p)\n", hFuncSet, dwEncodingType,
480 debugstr_w(pwszDll), dwFlags, ppvFuncAddr, phFuncAddr);
482 if (pwszDll)
484 HMODULE lib;
486 *phFuncAddr = NULL;
487 ret = CRYPT_GetFuncFromDll(pwszDll, set->name, &lib, ppvFuncAddr);
488 if (ret)
490 struct FuncAddr *addr = CryptMemAlloc(sizeof(struct FuncAddr));
492 if (addr)
494 addr->lib = lib;
495 addr->dllList = addr->currentDll = NULL;
496 *phFuncAddr = addr;
498 else
500 FreeLibrary(lib);
501 *ppvFuncAddr = NULL;
502 SetLastError(ERROR_OUTOFMEMORY);
503 ret = FALSE;
506 else
507 SetLastError(ERROR_FILE_NOT_FOUND);
509 else
511 struct FuncAddr *addr = (struct FuncAddr *)*phFuncAddr;
513 if (!addr)
515 DWORD size;
517 ret = CryptGetDefaultOIDDllList(hFuncSet, dwEncodingType, NULL,
518 &size);
519 if (ret)
521 LPWSTR dllList = CryptMemAlloc(size * sizeof(WCHAR));
523 if (dllList)
525 ret = CryptGetDefaultOIDDllList(hFuncSet, dwEncodingType,
526 dllList, &size);
527 if (ret)
529 addr = CryptMemAlloc(sizeof(struct FuncAddr));
530 if (addr)
532 addr->dllList = dllList;
533 addr->currentDll = dllList;
534 addr->lib = NULL;
535 *phFuncAddr = addr;
537 else
539 CryptMemFree(dllList);
540 SetLastError(ERROR_OUTOFMEMORY);
541 ret = FALSE;
545 else
547 SetLastError(ERROR_OUTOFMEMORY);
548 ret = FALSE;
552 if (addr)
554 if (!*addr->currentDll)
556 CryptFreeOIDFunctionAddress(*phFuncAddr, 0);
557 SetLastError(ERROR_FILE_NOT_FOUND);
558 *phFuncAddr = NULL;
559 ret = FALSE;
561 else
563 /* FIXME: as elsewhere, can't free until DllCanUnloadNow says
564 * it's possible, and should defer unloading for some time to
565 * avoid repeated LoadLibrary/FreeLibrary on the same dll.
567 FreeLibrary(addr->lib);
568 ret = CRYPT_GetFuncFromDll(addr->currentDll, set->name,
569 &addr->lib, ppvFuncAddr);
570 if (ret)
572 /* Move past the current DLL */
573 addr->currentDll += lstrlenW(addr->currentDll) + 1;
574 *phFuncAddr = addr;
576 else
578 CryptFreeOIDFunctionAddress(*phFuncAddr, 0);
579 SetLastError(ERROR_FILE_NOT_FOUND);
580 *phFuncAddr = NULL;
585 return ret;
588 /***********************************************************************
589 * CryptRegisterOIDFunction (CRYPT32.@)
591 * Register the DLL and the functions it uses to cover the combination
592 * of encoding type, functionname and OID.
594 * PARAMS
595 * dwEncodingType [I] Encoding type to be used.
596 * pszFuncName [I] Name of the function to be registered.
597 * pszOID [I] OID of the function (numeric or string).
598 * pwszDll [I] The DLL that is to be registered.
599 * pszOverrideFuncName [I] Name of the function in the DLL.
601 * RETURNS
602 * Success: TRUE.
603 * Failure: FALSE. (Look at GetLastError()).
605 * NOTES
606 * Registry errors are always reported via SetLastError().
608 BOOL WINAPI CryptRegisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
609 LPCSTR pszOID, LPCWSTR pwszDll, LPCSTR pszOverrideFuncName)
611 LONG r;
612 HKEY hKey;
613 LPSTR szKey;
615 TRACE("(%x, %s, %s, %s, %s)\n", dwEncodingType, pszFuncName,
616 debugstr_a(pszOID), debugstr_w(pwszDll), pszOverrideFuncName);
618 /* Native does nothing pwszDll is NULL */
619 if (!pwszDll)
620 return TRUE;
622 /* I'm not matching MS bug for bug here, because I doubt any app depends on
623 * it: native "succeeds" if pszFuncName is NULL, but the nonsensical entry
624 * it creates would never be used.
626 if (!pszFuncName || !pszOID)
628 SetLastError(E_INVALIDARG);
629 return FALSE;
632 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
633 TRACE("Key name is %s\n", debugstr_a(szKey));
635 if (!szKey)
636 return FALSE;
638 r = RegCreateKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
639 CryptMemFree(szKey);
641 if (r != ERROR_SUCCESS) goto error_close_key;
643 /* write the values */
644 if (pszOverrideFuncName)
646 r = RegSetValueExA(hKey, "FuncName", 0, REG_SZ,
647 (const BYTE*)pszOverrideFuncName, lstrlenA(pszOverrideFuncName) + 1);
648 if (r != ERROR_SUCCESS) goto error_close_key;
650 r = RegSetValueExW(hKey, DllW, 0, REG_SZ, (const BYTE*) pwszDll,
651 (lstrlenW(pwszDll) + 1) * sizeof (WCHAR));
653 error_close_key:
655 RegCloseKey(hKey);
657 if (r != ERROR_SUCCESS)
659 SetLastError(r);
660 return FALSE;
663 return TRUE;
666 /***********************************************************************
667 * CryptUnregisterOIDFunction (CRYPT32.@)
669 BOOL WINAPI CryptUnregisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
670 LPCSTR pszOID)
672 LPSTR szKey;
673 LONG rc;
675 TRACE("%x %s %s\n", dwEncodingType, debugstr_a(pszFuncName),
676 debugstr_a(pszOID));
678 if (!pszFuncName || !pszOID)
680 SetLastError(ERROR_INVALID_PARAMETER);
681 return FALSE;
684 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
685 rc = RegDeleteKeyA(HKEY_LOCAL_MACHINE, szKey);
686 CryptMemFree(szKey);
687 if (rc)
688 SetLastError(rc);
689 return rc ? FALSE : TRUE;
692 BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
693 LPCSTR pszOID, LPCWSTR pwszValueName, DWORD *pdwValueType, BYTE *pbValueData,
694 DWORD *pcbValueData)
696 LPSTR szKey;
697 LONG rc;
698 HKEY hKey;
700 TRACE("%x %s %s %s %p %p %p\n", dwEncodingType, debugstr_a(pszFuncName),
701 debugstr_a(pszOID), debugstr_w(pwszValueName), pdwValueType, pbValueData,
702 pcbValueData);
704 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
705 return TRUE;
707 if (!pszFuncName || !pszOID || !pwszValueName)
709 SetLastError(ERROR_INVALID_PARAMETER);
710 return FALSE;
713 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
714 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
715 CryptMemFree(szKey);
716 if (rc)
717 SetLastError(rc);
718 else
720 rc = RegQueryValueExW(hKey, pwszValueName, NULL, pdwValueType,
721 pbValueData, pcbValueData);
722 if (rc)
723 SetLastError(rc);
724 RegCloseKey(hKey);
726 return rc ? FALSE : TRUE;
729 BOOL WINAPI CryptSetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
730 LPCSTR pszOID, LPCWSTR pwszValueName, DWORD dwValueType,
731 const BYTE *pbValueData, DWORD cbValueData)
733 LPSTR szKey;
734 LONG rc;
735 HKEY hKey;
737 TRACE("%x %s %s %s %d %p %d\n", dwEncodingType, debugstr_a(pszFuncName),
738 debugstr_a(pszOID), debugstr_w(pwszValueName), dwValueType, pbValueData,
739 cbValueData);
741 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
742 return TRUE;
744 if (!pszFuncName || !pszOID || !pwszValueName)
746 SetLastError(ERROR_INVALID_PARAMETER);
747 return FALSE;
750 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
751 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
752 CryptMemFree(szKey);
753 if (rc)
754 SetLastError(rc);
755 else
757 rc = RegSetValueExW(hKey, pwszValueName, 0, dwValueType, pbValueData,
758 cbValueData);
759 if (rc)
760 SetLastError(rc);
761 RegCloseKey(hKey);
763 return rc ? FALSE : TRUE;
766 static LPCWSTR CRYPT_FindStringInMultiString(LPCWSTR multi, LPCWSTR toFind)
768 LPCWSTR ret = NULL, ptr;
770 for (ptr = multi; ptr && *ptr && !ret; ptr += lstrlenW(ptr) + 1)
772 if (!lstrcmpiW(ptr, toFind))
773 ret = ptr;
775 return ret;
778 static DWORD CRYPT_GetMultiStringCharacterLen(LPCWSTR multi)
780 DWORD ret;
782 if (multi)
784 LPCWSTR ptr;
786 /* Count terminating empty string */
787 ret = 1;
788 for (ptr = multi; *ptr; ptr += lstrlenW(ptr) + 1)
789 ret += lstrlenW(ptr) + 1;
791 else
792 ret = 0;
793 return ret;
796 static LPWSTR CRYPT_AddStringToMultiString(LPWSTR multi, LPCWSTR toAdd,
797 DWORD index)
799 LPWSTR ret;
801 if (!multi)
803 /* FIXME: ignoring index, is that okay? */
804 ret = CryptMemAlloc((lstrlenW(toAdd) + 2) * sizeof(WCHAR));
805 if (ret)
807 /* copy string, including NULL terminator */
808 memcpy(ret, toAdd, (lstrlenW(toAdd) + 1) * sizeof(WCHAR));
809 /* add terminating empty string */
810 *(ret + lstrlenW(toAdd) + 1) = 0;
813 else
815 DWORD len = CRYPT_GetMultiStringCharacterLen(multi);
817 ret = CryptMemRealloc(multi, (len + lstrlenW(toAdd) + 1) *
818 sizeof(WCHAR));
819 if (ret)
821 LPWSTR spotToAdd;
823 if (index == CRYPT_REGISTER_LAST_INDEX)
824 spotToAdd = ret + len - 1;
825 else
827 DWORD i;
829 /* FIXME: if index is too large for the string, toAdd is
830 * added to the end. Is that okay?
832 for (i = 0, spotToAdd = ret; i < index && *spotToAdd;
833 spotToAdd += lstrlenW(spotToAdd) + 1)
836 if (spotToAdd)
838 /* Copy existing string "right" */
839 memmove(spotToAdd + lstrlenW(toAdd) + 1, spotToAdd,
840 (len - (spotToAdd - ret)) * sizeof(WCHAR));
841 /* Copy new string */
842 memcpy(spotToAdd, toAdd, (lstrlenW(toAdd) + 1) * sizeof(WCHAR));
844 else
846 CryptMemFree(ret);
847 ret = NULL;
851 return ret;
854 static BOOL CRYPT_RemoveStringFromMultiString(LPWSTR multi, LPCWSTR toRemove)
856 LPWSTR spotToRemove = (LPWSTR)CRYPT_FindStringInMultiString(multi,
857 toRemove);
858 BOOL ret;
860 if (spotToRemove)
862 DWORD len = CRYPT_GetMultiStringCharacterLen(multi);
864 /* Copy remainder of string "left" */
865 memmove(spotToRemove, spotToRemove + lstrlenW(toRemove) + 1,
866 (len - (spotToRemove - multi)) * sizeof(WCHAR));
867 ret = TRUE;
869 else
871 SetLastError(ERROR_FILE_NOT_FOUND);
872 ret = FALSE;
874 return ret;
877 static BOOL CRYPT_GetDefaultOIDKey(DWORD dwEncodingType, LPCSTR pszFuncName,
878 PHKEY key)
880 LPSTR keyName;
881 LONG r;
883 keyName = CRYPT_GetKeyName(dwEncodingType, pszFuncName, "DEFAULT");
884 TRACE("Key name is %s\n", debugstr_a(keyName));
886 if (!keyName)
887 return FALSE;
889 r = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, NULL, 0, KEY_ALL_ACCESS,
890 NULL, key, NULL);
891 CryptMemFree(keyName);
892 if (r != ERROR_SUCCESS)
894 SetLastError(r);
895 return FALSE;
897 return TRUE;
900 static LPWSTR CRYPT_GetDefaultOIDDlls(HKEY key)
902 LONG r;
903 DWORD type, size;
904 LPWSTR dlls;
906 r = RegQueryValueExW(key, DllW, NULL, &type, NULL, &size);
907 if (r == ERROR_SUCCESS && type == REG_MULTI_SZ)
909 dlls = CryptMemAlloc(size);
910 r = RegQueryValueExW(key, DllW, NULL, &type, (LPBYTE)dlls, &size);
911 if (r != ERROR_SUCCESS)
913 CryptMemFree(dlls);
914 dlls = NULL;
917 else
918 dlls = NULL;
919 return dlls;
922 static inline BOOL CRYPT_SetDefaultOIDDlls(HKEY key, LPCWSTR dlls)
924 DWORD len = CRYPT_GetMultiStringCharacterLen(dlls);
925 LONG r;
927 if ((r = RegSetValueExW(key, DllW, 0, REG_MULTI_SZ, (const BYTE *)dlls,
928 len * sizeof (WCHAR))))
929 SetLastError(r);
930 return r == ERROR_SUCCESS;
933 /***********************************************************************
934 * CryptRegisterDefaultOIDFunction (CRYPT32.@)
936 BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType,
937 LPCSTR pszFuncName, DWORD dwIndex, LPCWSTR pwszDll)
939 HKEY key;
940 LPWSTR dlls;
941 BOOL ret = FALSE;
943 TRACE("(%x, %s, %d, %s)\n", dwEncodingType, debugstr_a(pszFuncName),
944 dwIndex, debugstr_w(pwszDll));
946 if (!pwszDll)
948 SetLastError(E_INVALIDARG);
949 return FALSE;
952 if (!CRYPT_GetDefaultOIDKey(dwEncodingType, pszFuncName, &key))
953 return FALSE;
955 dlls = CRYPT_GetDefaultOIDDlls(key);
956 if (CRYPT_FindStringInMultiString(dlls, pwszDll))
957 SetLastError(ERROR_FILE_EXISTS);
958 else
960 dlls = CRYPT_AddStringToMultiString(dlls, pwszDll, dwIndex);
961 if (dlls)
962 ret = CRYPT_SetDefaultOIDDlls(key, dlls);
964 CryptMemFree(dlls);
965 RegCloseKey(key);
966 return ret;
969 BOOL WINAPI CryptUnregisterDefaultOIDFunction(DWORD dwEncodingType,
970 LPCSTR pszFuncName, LPCWSTR pwszDll)
972 HKEY key;
973 LPWSTR dlls;
974 BOOL ret;
976 TRACE("(%x, %s, %s)\n", dwEncodingType, debugstr_a(pszFuncName),
977 debugstr_w(pwszDll));
979 if (!pwszDll)
981 SetLastError(E_INVALIDARG);
982 return FALSE;
985 if (!CRYPT_GetDefaultOIDKey(dwEncodingType, pszFuncName, &key))
986 return FALSE;
988 dlls = CRYPT_GetDefaultOIDDlls(key);
989 if ((ret = CRYPT_RemoveStringFromMultiString(dlls, pwszDll)))
990 ret = CRYPT_SetDefaultOIDDlls(key, dlls);
991 CryptMemFree(dlls);
992 RegCloseKey(key);
993 return ret;
996 static void oid_init_localizednames(HINSTANCE hInstance)
998 int i;
1000 for(i = 0; i < sizeof(LocalizedKeys)/sizeof(LPCWSTR); i++)
1002 LoadStringW(hInstance, IDS_LOCALIZEDNAME_ROOT+i, LocalizedNames[i], 256);
1006 /********************************************************************
1007 * CryptFindLocalizedName (CRYPT32.@)
1009 LPCWSTR WINAPI CryptFindLocalizedName(LPCWSTR pwszCryptName)
1011 int i;
1013 for(i = 0; i < sizeof(LocalizedKeys)/sizeof(LPCWSTR); i++)
1015 if(!lstrcmpiW(LocalizedKeys[i], pwszCryptName))
1017 return LocalizedNames[i];
1021 FIXME("No name for: %s - stub\n",debugstr_w(pwszCryptName));
1022 return NULL;
1025 static CRITICAL_SECTION oidInfoCS;
1026 static CRITICAL_SECTION_DEBUG oidInfoCSDebug =
1028 0, 0, &oidInfoCS,
1029 { &oidInfoCSDebug.ProcessLocksList, &oidInfoCSDebug.ProcessLocksList },
1030 0, 0, { (DWORD_PTR)(__FILE__ ": oidInfoCS") }
1032 static CRITICAL_SECTION oidInfoCS = { &oidInfoCSDebug, -1, 0, 0, 0, 0 };
1033 static struct list oidInfo = { &oidInfo, &oidInfo };
1035 static const WCHAR tripledes[] = { '3','d','e','s',0 };
1036 static const WCHAR cms3deswrap[] = { 'C','M','S','3','D','E','S','w','r','a',
1037 'p',0 };
1038 static const WCHAR cmsrc2wrap[] = { 'C','M','S','R','C','2','w','r','a','p',0 };
1039 static const WCHAR des[] = { 'd','e','s',0 };
1040 static const WCHAR md2[] = { 'm','d','2',0 };
1041 static const WCHAR md4[] = { 'm','d','4',0 };
1042 static const WCHAR md5[] = { 'm','d','5',0 };
1043 static const WCHAR rc2[] = { 'r','c','2',0 };
1044 static const WCHAR rc4[] = { 'r','c','4',0 };
1045 static const WCHAR sha[] = { 's','h','a',0 };
1046 static const WCHAR sha1[] = { 's','h','a','1',0 };
1047 static const WCHAR RSA[] = { 'R','S','A',0 };
1048 static const WCHAR RSA_KEYX[] = { 'R','S','A','_','K','E','Y','X',0 };
1049 static const WCHAR RSA_SIGN[] = { 'R','S','A','_','S','I','G','N',0 };
1050 static const WCHAR DSA[] = { 'D','S','A',0 };
1051 static const WCHAR DSA_SIGN[] = { 'D','S','A','_','S','I','G','N',0 };
1052 static const WCHAR DH[] = { 'D','H',0 };
1053 static const WCHAR DSS[] = { 'D','S','S',0 };
1054 static const WCHAR mosaicKMandUpdSig[] =
1055 { 'm','o','s','a','i','c','K','M','a','n','d','U','p','d','S','i','g',0 };
1056 static const WCHAR ESDH[] = { 'E','S','D','H',0 };
1057 static const WCHAR NO_SIGN[] = { 'N','O','S','I','G','N',0 };
1058 static const WCHAR dsaSHA1[] = { 'd','s','a','S','H','A','1',0 };
1059 static const WCHAR md2RSA[] = { 'm','d','2','R','S','A',0 };
1060 static const WCHAR md4RSA[] = { 'm','d','4','R','S','A',0 };
1061 static const WCHAR md5RSA[] = { 'm','d','5','R','S','A',0 };
1062 static const WCHAR shaDSA[] = { 's','h','a','D','S','A',0 };
1063 static const WCHAR sha1DSA[] = { 's','h','a','1','D','S','A',0 };
1064 static const WCHAR shaRSA[] = { 's','h','a','R','S','A',0 };
1065 static const WCHAR sha1RSA[] = { 's','h','a','1','R','S','A',0 };
1066 static const WCHAR mosaicUpdatedSig[] =
1067 { 'm','o','s','a','i','c','U','p','d','a','t','e','d','S','i','g',0 };
1068 static const WCHAR CN[] = { 'C','N',0 };
1069 static const WCHAR L[] = { 'L',0 };
1070 static const WCHAR O[] = { 'O',0 };
1071 static const WCHAR OU[] = { 'O','U',0 };
1072 static const WCHAR E[] = { 'E',0 };
1073 static const WCHAR C[] = { 'C',0 };
1074 static const WCHAR S[] = { 'S',0 };
1075 static const WCHAR ST[] = { 'S','T',0 };
1076 static const WCHAR STREET[] = { 'S','T','R','E','E','T',0 };
1077 static const WCHAR T[] = { 'T',0 };
1078 static const WCHAR Title[] = { 'T','i','t','l','e',0 };
1079 static const WCHAR G[] = { 'G',0 };
1080 static const WCHAR GivenName[] = { 'G','i','v','e','n','N','a','m','e',0 };
1081 static const WCHAR I[] = { 'I',0 };
1082 static const WCHAR Initials[] = { 'I','n','i','t','i','a','l','s',0 };
1083 static const WCHAR SN[] = { 'S','N',0 };
1084 static const WCHAR DC[] = { 'D','C',0 };
1085 static const WCHAR Description[] =
1086 { 'D','e','s','c','r','i','p','t','i','o','n',0 };
1087 static const WCHAR PostalCode[] = { 'P','o','s','t','a','l','C','o','d','e',0 };
1088 static const WCHAR POBox[] = { 'P','O','B','o','x',0 };
1089 static const WCHAR Phone[] = { 'P','h','o','n','e',0 };
1090 static const WCHAR X21Address[] = { 'X','2','1','A','d','d','r','e','s','s',0 };
1091 static const WCHAR dnQualifier[] =
1092 { 'd','n','Q','u','a','l','i','f','i','e','r',0 };
1093 static const WCHAR Email[] = { 'E','m','a','i','l',0 };
1094 static const WCHAR GN[] = { 'G','N',0 };
1096 static const DWORD noNullFlag = CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG;
1097 static const DWORD mosaicFlags = CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG |
1098 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG;
1099 static const CRYPT_DATA_BLOB noNullBlob = { sizeof(noNullFlag),
1100 (LPBYTE)&noNullFlag };
1101 static const CRYPT_DATA_BLOB mosaicFlagsBlob = { sizeof(mosaicFlags),
1102 (LPBYTE)&mosaicFlags };
1104 static const DWORD rsaSign = CALG_RSA_SIGN;
1105 static const DWORD dssSign[2] = { CALG_DSS_SIGN,
1106 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG };
1107 static const DWORD mosaicSign[2] = { CALG_DSS_SIGN,
1108 CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG |
1109 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG };
1110 static const CRYPT_DATA_BLOB rsaSignBlob = { sizeof(rsaSign),
1111 (LPBYTE)&rsaSign };
1112 static const CRYPT_DATA_BLOB dssSignBlob = { sizeof(dssSign),
1113 (LPBYTE)dssSign };
1114 static const CRYPT_DATA_BLOB mosaicSignBlob = { sizeof(mosaicSign),
1115 (LPBYTE)mosaicSign };
1117 static const DWORD ia5String[] = { CERT_RDN_IA5_STRING, 0 };
1118 static const DWORD numericString[] = { CERT_RDN_NUMERIC_STRING, 0 };
1119 static const DWORD printableString[] = { CERT_RDN_PRINTABLE_STRING, 0 };
1120 static const DWORD domainCompTypes[] = { CERT_RDN_IA5_STRING,
1121 CERT_RDN_UTF8_STRING, 0 };
1122 static const CRYPT_DATA_BLOB ia5StringBlob = { sizeof(ia5String),
1123 (LPBYTE)ia5String };
1124 static const CRYPT_DATA_BLOB numericStringBlob = { sizeof(numericString),
1125 (LPBYTE)numericString };
1126 static const CRYPT_DATA_BLOB printableStringBlob = { sizeof(printableString),
1127 (LPBYTE)printableString };
1128 static const CRYPT_DATA_BLOB domainCompTypesBlob = { sizeof(domainCompTypes),
1129 (LPBYTE)domainCompTypes };
1131 static const struct OIDInfoConstructor {
1132 DWORD dwGroupId;
1133 LPCSTR pszOID;
1134 UINT Algid;
1135 LPCWSTR pwszName;
1136 const CRYPT_DATA_BLOB *blob;
1137 } oidInfoConstructors[] = {
1138 { 1, szOID_OIWSEC_sha1, CALG_SHA1, sha1, NULL },
1139 { 1, szOID_OIWSEC_sha1, CALG_SHA1, sha, NULL },
1140 { 1, szOID_OIWSEC_sha, CALG_SHA, sha, NULL },
1141 { 1, szOID_RSA_MD5, CALG_MD5, md5, NULL },
1142 { 1, szOID_RSA_MD4, CALG_MD4, md4, NULL },
1143 { 1, szOID_RSA_MD2, CALG_MD2, md2, NULL },
1145 { 2, szOID_OIWSEC_desCBC, CALG_DES, des, NULL },
1146 { 2, szOID_RSA_DES_EDE3_CBC, CALG_3DES, tripledes, NULL },
1147 { 2, szOID_RSA_RC2CBC, CALG_RC2, rc2, NULL },
1148 { 2, szOID_RSA_RC4, CALG_RC4, rc4, NULL },
1149 { 2, szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES, cms3deswrap, NULL },
1150 { 2, szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2, cmsrc2wrap, NULL },
1152 { 3, szOID_RSA_RSA, CALG_RSA_KEYX, RSA, NULL },
1153 { 3, szOID_X957_DSA, CALG_DSS_SIGN, DSA, &noNullBlob },
1154 { 3, szOID_ANSI_X942_DH, CALG_DH_SF, DH, &noNullBlob },
1155 { 3, szOID_RSA_RSA, CALG_RSA_KEYX, RSA_KEYX, NULL },
1156 { 3, szOID_RSA_RSA, CALG_RSA_SIGN, RSA, NULL },
1157 { 3, szOID_RSA_RSA, CALG_RSA_SIGN, RSA_SIGN, NULL },
1158 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSA, &noNullBlob },
1159 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSS, &noNullBlob },
1160 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSA_SIGN, &noNullBlob },
1161 { 3, szOID_RSA_DH, CALG_DH_SF, DH, &noNullBlob },
1162 { 3, szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX, RSA_KEYX, NULL },
1163 { 3, szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN, mosaicKMandUpdSig,
1164 &mosaicFlagsBlob },
1165 { 3, szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM, ESDH, &noNullBlob },
1166 { 3, szOID_PKIX_NO_SIGNATURE, CALG_NO_SIGN, NO_SIGN, NULL },
1168 { 4, szOID_RSA_SHA1RSA, CALG_SHA1, sha1RSA, &rsaSignBlob },
1169 { 4, szOID_RSA_MD5RSA, CALG_MD5, md5RSA, &rsaSignBlob },
1170 { 4, szOID_X957_SHA1DSA, CALG_SHA1, sha1DSA, &dssSignBlob },
1171 { 4, szOID_OIWSEC_sha1RSASign, CALG_SHA1, sha1RSA, &rsaSignBlob },
1172 { 4, szOID_OIWSEC_sha1RSASign, CALG_SHA1, shaRSA, &rsaSignBlob },
1173 { 4, szOID_OIWSEC_shaRSA, CALG_SHA1, shaRSA, &rsaSignBlob },
1174 { 4, szOID_OIWSEC_md5RSA, CALG_MD5, md5RSA, &rsaSignBlob },
1175 { 4, szOID_RSA_MD2RSA, CALG_MD2, md2RSA, &rsaSignBlob },
1176 { 4, szOID_RSA_MD4RSA, CALG_MD4, md4RSA, &rsaSignBlob },
1177 { 4, szOID_OIWSEC_md4RSA, CALG_MD4, md4RSA, &rsaSignBlob },
1178 { 4, szOID_OIWSEC_md4RSA2, CALG_MD4, md4RSA, &rsaSignBlob },
1179 { 4, szOID_OIWDIR_md2RSA, CALG_MD2, md2RSA, &rsaSignBlob },
1180 { 4, szOID_OIWSEC_shaDSA, CALG_SHA1, sha1DSA, &dssSignBlob },
1181 { 4, szOID_OIWSEC_shaDSA, CALG_SHA1, shaDSA, &dssSignBlob },
1182 { 4, szOID_OIWSEC_dsaSHA1, CALG_SHA1, dsaSHA1, &dssSignBlob },
1183 { 4, szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA1, mosaicUpdatedSig,
1184 &mosaicSignBlob },
1186 { 5, szOID_COMMON_NAME, 0, CN, NULL },
1187 { 5, szOID_LOCALITY_NAME, 0, L, NULL },
1188 { 5, szOID_ORGANIZATION_NAME, 0, O, NULL },
1189 { 5, szOID_ORGANIZATIONAL_UNIT_NAME, 0, OU, NULL },
1190 { 5, szOID_RSA_emailAddr, 0, E, &ia5StringBlob },
1191 { 5, szOID_RSA_emailAddr, 0, Email, &ia5StringBlob },
1192 { 5, szOID_COUNTRY_NAME, 0, C, &printableStringBlob },
1193 { 5, szOID_STATE_OR_PROVINCE_NAME, 0, S, NULL },
1194 { 5, szOID_STATE_OR_PROVINCE_NAME, 0, ST, NULL },
1195 { 5, szOID_STREET_ADDRESS, 0, STREET, NULL },
1196 { 5, szOID_TITLE, 0, T, NULL },
1197 { 5, szOID_TITLE, 0, Title, NULL },
1198 { 5, szOID_GIVEN_NAME, 0, G, NULL },
1199 { 5, szOID_GIVEN_NAME, 0, GN, NULL },
1200 { 5, szOID_GIVEN_NAME, 0, GivenName, NULL },
1201 { 5, szOID_INITIALS, 0, I, NULL },
1202 { 5, szOID_INITIALS, 0, Initials, NULL },
1203 { 5, szOID_SUR_NAME, 0, SN, NULL },
1204 { 5, szOID_DOMAIN_COMPONENT, 0, DC, &domainCompTypesBlob },
1205 { 5, szOID_DESCRIPTION, 0, Description, NULL },
1206 { 5, szOID_POSTAL_CODE, 0, PostalCode, NULL },
1207 { 5, szOID_POST_OFFICE_BOX, 0, POBox, NULL },
1208 { 5, szOID_TELEPHONE_NUMBER, 0, Phone, &printableStringBlob },
1209 { 5, szOID_X21_ADDRESS, 0, X21Address, &numericStringBlob },
1210 { 5, szOID_DN_QUALIFIER, 0, dnQualifier, NULL },
1212 { 6, szOID_AUTHORITY_KEY_IDENTIFIER2, 0, (LPCWSTR)IDS_AUTHORITY_KEY_ID, NULL },
1213 { 6, szOID_AUTHORITY_KEY_IDENTIFIER, 0, (LPCWSTR)IDS_AUTHORITY_KEY_ID, NULL },
1214 { 6, szOID_KEY_ATTRIBUTES, 0, (LPCWSTR)IDS_KEY_ATTRIBUTES, NULL },
1215 { 6, szOID_KEY_USAGE_RESTRICTION, 0, (LPCWSTR)IDS_KEY_USAGE_RESTRICTION, NULL },
1216 { 6, szOID_SUBJECT_ALT_NAME2, 0, (LPCWSTR)IDS_SUBJECT_ALT_NAME, NULL },
1217 { 6, szOID_SUBJECT_ALT_NAME, 0, (LPCWSTR)IDS_SUBJECT_ALT_NAME, NULL },
1218 { 6, szOID_ISSUER_ALT_NAME2, 0, (LPCWSTR)IDS_ISSUER_ALT_NAME, NULL },
1219 { 6, szOID_ISSUER_ALT_NAME2, 0, (LPCWSTR)IDS_ISSUER_ALT_NAME, NULL },
1220 { 6, szOID_BASIC_CONSTRAINTS2, 0, (LPCWSTR)IDS_BASIC_CONSTRAINTS, NULL },
1221 { 6, szOID_BASIC_CONSTRAINTS, 0, (LPCWSTR)IDS_BASIC_CONSTRAINTS, NULL },
1222 { 6, szOID_KEY_USAGE, 0, (LPCWSTR)IDS_KEY_USAGE, NULL },
1223 { 6, szOID_CERT_POLICIES, 0, (LPCWSTR)IDS_CERT_POLICIES, NULL },
1224 { 6, szOID_SUBJECT_KEY_IDENTIFIER, 0, (LPCWSTR)IDS_SUBJECT_KEY_IDENTIFIER, NULL },
1225 { 6, szOID_CRL_REASON_CODE, 0, (LPCWSTR)IDS_CRL_REASON_CODE, NULL },
1226 { 6, szOID_CRL_DIST_POINTS, 0, (LPCWSTR)IDS_CRL_DIST_POINTS, NULL },
1227 { 6, szOID_ENHANCED_KEY_USAGE, 0, (LPCWSTR)IDS_ENHANCED_KEY_USAGE, NULL },
1228 { 6, szOID_AUTHORITY_INFO_ACCESS, 0, (LPCWSTR)IDS_AUTHORITY_INFO_ACCESS, NULL },
1229 { 6, szOID_CERT_EXTENSIONS, 0, (LPCWSTR)IDS_CERT_EXTENSIONS, NULL },
1230 { 6, szOID_RSA_certExtensions, 0, (LPCWSTR)IDS_CERT_EXTENSIONS, NULL },
1231 { 6, szOID_NEXT_UPDATE_LOCATION, 0, (LPCWSTR)IDS_NEXT_UPDATE_LOCATION, NULL },
1232 { 6, szOID_YESNO_TRUST_ATTR, 0, (LPCWSTR)IDS_YES_OR_NO_TRUST, NULL },
1233 { 6, szOID_RSA_emailAddr, 0, (LPCWSTR)IDS_EMAIL_ADDRESS, NULL },
1234 { 6, szOID_RSA_unstructName, 0, (LPCWSTR)IDS_UNSTRUCTURED_NAME, NULL },
1235 { 6, szOID_RSA_contentType, 0, (LPCWSTR)IDS_CONTENT_TYPE, NULL },
1236 { 6, szOID_RSA_messageDigest, 0, (LPCWSTR)IDS_MESSAGE_DIGEST, NULL },
1237 { 6, szOID_RSA_signingTime, 0, (LPCWSTR)IDS_SIGNING_TIME, NULL },
1238 { 6, szOID_RSA_counterSign, 0, (LPCWSTR)IDS_COUNTER_SIGN, NULL },
1239 { 6, szOID_RSA_challengePwd, 0, (LPCWSTR)IDS_CHALLENGE_PASSWORD, NULL },
1240 { 6, szOID_RSA_unstructAddr, 0, (LPCWSTR)IDS_UNSTRUCTURED_ADDRESS, NULL },
1241 { 6, szOID_RSA_SMIMECapabilities, 0, (LPCWSTR)IDS_SMIME_CAPABILITIES, NULL },
1242 { 6, szOID_RSA_preferSignedData, 0, (LPCWSTR)IDS_PREFER_SIGNED_DATA, NULL },
1243 { 6, szOID_PKIX_POLICY_QUALIFIER_CPS, 0, (LPCWSTR)IDS_CPS, NULL },
1244 { 6, szOID_PKIX_POLICY_QUALIFIER_USERNOTICE, 0, (LPCWSTR)IDS_USER_NOTICE, NULL },
1245 { 6, szOID_PKIX_OCSP, 0, (LPCWSTR)IDS_OCSP, NULL },
1246 { 6, szOID_PKIX_CA_ISSUERS, 0, (LPCWSTR)IDS_CA_ISSUER, NULL },
1247 { 6, szOID_ENROLL_CERTTYPE_EXTENSION, 0, (LPCWSTR)IDS_CERT_TEMPLATE_NAME, NULL },
1248 { 6, szOID_ENROLL_CERTTYPE_EXTENSION, 0, (LPCWSTR)IDS_CERT_TYPE, NULL },
1249 { 6, szOID_CERT_MANIFOLD, 0, (LPCWSTR)IDS_CERT_MANIFOLD, NULL },
1250 { 6, szOID_NETSCAPE_CERT_TYPE, 0, (LPCWSTR)IDS_NETSCAPE_CERT_TYPE, NULL },
1251 { 6, szOID_NETSCAPE_BASE_URL, 0, (LPCWSTR)IDS_NETSCAPE_BASE_URL, NULL },
1252 { 6, szOID_NETSCAPE_REVOCATION_URL, 0, (LPCWSTR)IDS_NETSCAPE_REVOCATION_URL, NULL },
1253 { 6, szOID_NETSCAPE_CA_REVOCATION_URL, 0, (LPCWSTR)IDS_NETSCAPE_CA_REVOCATION_URL, NULL },
1254 { 6, szOID_NETSCAPE_CERT_RENEWAL_URL, 0, (LPCWSTR)IDS_NETSCAPE_CERT_RENEWAL_URL, NULL },
1255 { 6, szOID_NETSCAPE_CA_POLICY_URL, 0, (LPCWSTR)IDS_NETSCAPE_CA_POLICY_URL, NULL },
1256 { 6, szOID_NETSCAPE_SSL_SERVER_NAME, 0, (LPCWSTR)IDS_NETSCAPE_SSL_SERVER_NAME, NULL },
1257 { 6, szOID_NETSCAPE_COMMENT, 0, (LPCWSTR)IDS_NETSCAPE_COMMENT, NULL },
1258 { 6, "1.3.6.1.4.1.311.2.1.10", 0, (LPCWSTR)IDS_SPC_SP_AGENCY_INFO, NULL },
1259 { 6, "1.3.6.1.4.1.311.2.1.27", 0, (LPCWSTR)IDS_SPC_FINANCIAL_CRITERIA, NULL },
1260 { 6, "1.3.6.1.4.1.311.2.1.26", 0, (LPCWSTR)IDS_SPC_MINIMAL_CRITERIA, NULL },
1261 { 6, szOID_COUNTRY_NAME, 0, (LPCWSTR)IDS_COUNTRY, NULL },
1262 { 6, szOID_ORGANIZATION_NAME, 0, (LPCWSTR)IDS_ORGANIZATION, NULL },
1263 { 6, szOID_ORGANIZATIONAL_UNIT_NAME, 0, (LPCWSTR)IDS_ORGANIZATIONAL_UNIT, NULL },
1264 { 6, szOID_COMMON_NAME, 0, (LPCWSTR)IDS_COMMON_NAME, NULL },
1265 { 6, szOID_LOCALITY_NAME, 0, (LPCWSTR)IDS_LOCALITY, NULL },
1266 { 6, szOID_STATE_OR_PROVINCE_NAME, 0, (LPCWSTR)IDS_STATE_OR_PROVINCE, NULL },
1267 { 6, szOID_TITLE, 0, (LPCWSTR)IDS_TITLE, NULL },
1268 { 6, szOID_GIVEN_NAME, 0, (LPCWSTR)IDS_GIVEN_NAME, NULL },
1269 { 6, szOID_INITIALS, 0, (LPCWSTR)IDS_INITIALS, NULL },
1270 { 6, szOID_SUR_NAME, 0, (LPCWSTR)IDS_SUR_NAME, NULL },
1271 { 6, szOID_DOMAIN_COMPONENT, 0, (LPCWSTR)IDS_DOMAIN_COMPONENT, NULL },
1272 { 6, szOID_STREET_ADDRESS, 0, (LPCWSTR)IDS_STREET_ADDRESS, NULL },
1273 { 6, szOID_DEVICE_SERIAL_NUMBER, 0, (LPCWSTR)IDS_SERIAL_NUMBER, NULL },
1274 { 6, szOID_CERTSRV_CA_VERSION, 0, (LPCWSTR)IDS_CA_VERSION, NULL },
1275 { 6, szOID_CERTSRV_CROSSCA_VERSION, 0, (LPCWSTR)IDS_CROSS_CA_VERSION, NULL },
1276 { 6, szOID_SERIALIZED, 0, (LPCWSTR)IDS_SERIALIZED_SIG_SERIAL_NUMBER, NULL },
1277 { 6, szOID_NT_PRINCIPAL_NAME, 0, (LPCWSTR)IDS_PRINCIPAL_NAME, NULL },
1278 { 6, szOID_PRODUCT_UPDATE, 0, (LPCWSTR)IDS_WINDOWS_PRODUCT_UPDATE, NULL },
1279 { 6, szOID_ENROLLMENT_NAME_VALUE_PAIR, 0, (LPCWSTR)IDS_ENROLLMENT_NAME_VALUE_PAIR, NULL },
1280 { 6, szOID_OS_VERSION, 0, (LPCWSTR)IDS_OS_VERSION, NULL },
1281 { 6, szOID_ENROLLMENT_CSP_PROVIDER, 0, (LPCWSTR)IDS_ENROLLMENT_CSP, NULL },
1282 { 6, szOID_CRL_NUMBER, 0, (LPCWSTR)IDS_CRL_NUMBER, NULL },
1283 { 6, szOID_DELTA_CRL_INDICATOR, 0, (LPCWSTR)IDS_DELTA_CRL_INDICATOR, NULL },
1284 { 6, szOID_ISSUING_DIST_POINT, 0, (LPCWSTR)IDS_ISSUING_DIST_POINT, NULL },
1285 { 6, szOID_FRESHEST_CRL, 0, (LPCWSTR)IDS_FRESHEST_CRL, NULL },
1286 { 6, szOID_NAME_CONSTRAINTS, 0, (LPCWSTR)IDS_NAME_CONSTRAINTS, NULL },
1287 { 6, szOID_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_POLICY_MAPPINGS, NULL },
1288 { 6, szOID_LEGACY_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_POLICY_MAPPINGS, NULL },
1289 { 6, szOID_POLICY_CONSTRAINTS, 0, (LPCWSTR)IDS_POLICY_CONSTRAINTS, NULL },
1290 { 6, szOID_CROSS_CERT_DIST_POINTS, 0, (LPCWSTR)IDS_CROSS_CERT_DIST_POINTS, NULL },
1291 { 6, szOID_APPLICATION_CERT_POLICIES, 0, (LPCWSTR)IDS_APPLICATION_POLICIES, NULL },
1292 { 6, szOID_APPLICATION_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_APPLICATION_POLICY_MAPPINGS, NULL },
1293 { 6, szOID_APPLICATION_POLICY_CONSTRAINTS, 0, (LPCWSTR)IDS_APPLICATION_POLICY_CONSTRAINTS, NULL },
1294 { 6, szOID_CT_PKI_DATA, 0, (LPCWSTR)IDS_CMC_DATA, NULL },
1295 { 6, szOID_CT_PKI_RESPONSE, 0, (LPCWSTR)IDS_CMC_RESPONSE, NULL },
1296 { 6, szOID_CMC, 0, (LPCWSTR)IDS_UNSIGNED_CMC_REQUEST, NULL },
1297 { 6, szOID_CMC_STATUS_INFO, 0, (LPCWSTR)IDS_CMC_STATUS_INFO, NULL },
1298 { 6, szOID_CMC_ADD_EXTENSIONS, 0, (LPCWSTR)IDS_CMC_EXTENSIONS, NULL },
1299 { 6, szOID_CTL, 0, (LPCWSTR)IDS_CMC_ATTRIBUTES, NULL },
1300 { 6, szOID_RSA_data, 0, (LPCWSTR)IDS_PKCS_7_DATA, NULL },
1301 { 6, szOID_RSA_signedData, 0, (LPCWSTR)IDS_PKCS_7_SIGNED, NULL },
1302 { 6, szOID_RSA_envelopedData, 0, (LPCWSTR)IDS_PKCS_7_ENVELOPED, NULL },
1303 { 6, szOID_RSA_signEnvData, 0, (LPCWSTR)IDS_PKCS_7_SIGNED_ENVELOPED, NULL },
1304 { 6, szOID_RSA_digestedData, 0, (LPCWSTR)IDS_PKCS_7_DIGESTED, NULL },
1305 { 6, szOID_RSA_encryptedData, 0, (LPCWSTR)IDS_PKCS_7_ENCRYPTED, NULL },
1306 { 6, szOID_CERTSRV_PREVIOUS_CERT_HASH, 0, (LPCWSTR)IDS_PREVIOUS_CA_CERT_HASH, NULL },
1307 { 6, szOID_CRL_VIRTUAL_BASE, 0, (LPCWSTR)IDS_CRL_VIRTUAL_BASE, NULL },
1308 { 6, szOID_CRL_NEXT_PUBLISH, 0, (LPCWSTR)IDS_CRL_NEXT_PUBLISH, NULL },
1309 { 6, szOID_KP_CA_EXCHANGE, 0, (LPCWSTR)IDS_CA_EXCHANGE, NULL },
1310 { 6, szOID_KP_KEY_RECOVERY_AGENT, 0, (LPCWSTR)IDS_KEY_RECOVERY_AGENT, NULL },
1311 { 6, szOID_CERTIFICATE_TEMPLATE, 0, (LPCWSTR)IDS_CERTIFICATE_TEMPLATE, NULL },
1312 { 6, szOID_ENTERPRISE_OID_ROOT, 0, (LPCWSTR)IDS_ENTERPRISE_ROOT_OID, NULL },
1313 { 6, szOID_RDN_DUMMY_SIGNER, 0, (LPCWSTR)IDS_RDN_DUMMY_SIGNER, NULL },
1314 { 6, szOID_ARCHIVED_KEY_ATTR, 0, (LPCWSTR)IDS_ARCHIVED_KEY_ATTR, NULL },
1315 { 6, szOID_CRL_SELF_CDP, 0, (LPCWSTR)IDS_CRL_SELF_CDP, NULL },
1316 { 6, szOID_REQUIRE_CERT_CHAIN_POLICY, 0, (LPCWSTR)IDS_REQUIRE_CERT_CHAIN_POLICY, NULL },
1317 { 6, szOID_CMC_TRANSACTION_ID, 0, (LPCWSTR)IDS_TRANSACTION_ID, NULL },
1318 { 6, szOID_CMC_SENDER_NONCE, 0, (LPCWSTR)IDS_SENDER_NONCE, NULL },
1319 { 6, szOID_CMC_RECIPIENT_NONCE, 0, (LPCWSTR)IDS_RECIPIENT_NONCE, NULL },
1320 { 6, szOID_CMC_REG_INFO, 0, (LPCWSTR)IDS_REG_INFO, NULL },
1321 { 6, szOID_CMC_GET_CERT, 0, (LPCWSTR)IDS_GET_CERTIFICATE, NULL },
1322 { 6, szOID_CMC_GET_CRL, 0, (LPCWSTR)IDS_GET_CRL, NULL },
1323 { 6, szOID_CMC_REVOKE_REQUEST, 0, (LPCWSTR)IDS_REVOKE_REQUEST, NULL },
1324 { 6, szOID_CMC_QUERY_PENDING, 0, (LPCWSTR)IDS_QUERY_PENDING, NULL },
1325 { 6, szOID_SORTED_CTL, 0, (LPCWSTR)IDS_SORTED_CTL, NULL },
1326 { 6, szOID_ARCHIVED_KEY_CERT_HASH, 0, (LPCWSTR)IDS_ARCHIVED_KEY_CERT_HASH, NULL },
1327 { 6, szOID_PRIVATEKEY_USAGE_PERIOD, 0, (LPCWSTR)IDS_PRIVATE_KEY_USAGE_PERIOD, NULL },
1328 { 6, szOID_REQUEST_CLIENT_INFO, 0, (LPCWSTR)IDS_CLIENT_INFORMATION, NULL },
1330 { 7, szOID_PKIX_KP_SERVER_AUTH, 0, (LPCWSTR)IDS_SERVER_AUTHENTICATION, NULL },
1331 { 7, szOID_PKIX_KP_CLIENT_AUTH, 0, (LPCWSTR)IDS_CLIENT_AUTHENTICATION, NULL },
1332 { 7, szOID_PKIX_KP_CODE_SIGNING, 0, (LPCWSTR)IDS_CODE_SIGNING, NULL },
1333 { 7, szOID_PKIX_KP_EMAIL_PROTECTION, 0, (LPCWSTR)IDS_SECURE_EMAIL, NULL },
1334 { 7, szOID_PKIX_KP_TIMESTAMP_SIGNING, 0, (LPCWSTR)IDS_TIME_STAMPING, NULL },
1335 { 7, szOID_KP_CTL_USAGE_SIGNING, 0, (LPCWSTR)IDS_MICROSOFT_TRUST_LIST_SIGNING, NULL },
1336 { 7, szOID_KP_TIME_STAMP_SIGNING, 0, (LPCWSTR)IDS_MICROSOFT_TIME_STAMPING, NULL },
1337 { 7, szOID_PKIX_KP_IPSEC_END_SYSTEM, 0, (LPCWSTR)IDS_IPSEC_END_SYSTEM, NULL },
1338 { 7, szOID_PKIX_KP_IPSEC_TUNNEL, 0, (LPCWSTR)IDS_IPSEC_TUNNEL, NULL },
1339 { 7, szOID_PKIX_KP_IPSEC_USER, 0, (LPCWSTR)IDS_IPSEC_USER, NULL },
1340 { 7, szOID_KP_EFS, 0, (LPCWSTR)IDS_EFS, NULL },
1341 { 7, szOID_WHQL_CRYPTO, 0, (LPCWSTR)IDS_WHQL_CRYPTO, NULL },
1342 { 7, szOID_NT5_CRYPTO, 0, (LPCWSTR)IDS_NT5_CRYPTO, NULL },
1343 { 7, szOID_OEM_WHQL_CRYPTO, 0, (LPCWSTR)IDS_OEM_WHQL_CRYPTO, NULL },
1344 { 7, szOID_EMBEDDED_NT_CRYPTO, 0, (LPCWSTR)IDS_EMBEDDED_NT_CRYPTO, NULL },
1345 { 7, szOID_LICENSES, 0, (LPCWSTR)IDS_KEY_PACK_LICENSES, NULL },
1346 { 7, szOID_LICENSE_SERVER, 0, (LPCWSTR)IDS_LICENSE_SERVER, NULL },
1347 { 7, szOID_KP_SMARTCARD_LOGON, 0, (LPCWSTR)IDS_SMART_CARD_LOGON, NULL },
1348 { 7, szOID_DRM, 0, (LPCWSTR)IDS_DIGITAL_RIGHTS, NULL },
1349 { 7, szOID_KP_QUALIFIED_SUBORDINATION, 0, (LPCWSTR)IDS_QUALIFIED_SUBORDINATION, NULL },
1350 { 7, szOID_KP_KEY_RECOVERY, 0, (LPCWSTR)IDS_KEY_RECOVERY, NULL },
1351 { 7, szOID_KP_DOCUMENT_SIGNING, 0, (LPCWSTR)IDS_DOCUMENT_SIGNING, NULL },
1352 { 7, szOID_IPSEC_KP_IKE_INTERMEDIATE, 0, (LPCWSTR)IDS_IPSEC_IKE_INTERMEDIATE, NULL },
1353 { 7, szOID_EFS_RECOVERY, 0, (LPCWSTR)IDS_FILE_RECOVERY, NULL },
1354 { 7, szOID_ROOT_LIST_SIGNER, 0, (LPCWSTR)IDS_ROOT_LIST_SIGNER, NULL },
1355 { 7, szOID_ANY_APPLICATION_POLICY, 0, (LPCWSTR)IDS_ANY_APPLICATION_POLICIES, NULL },
1356 { 7, szOID_DS_EMAIL_REPLICATION, 0, (LPCWSTR)IDS_DS_EMAIL_REPLICATION, NULL },
1357 { 7, szOID_ENROLLMENT_AGENT, 0, (LPCWSTR)IDS_ENROLLMENT_AGENT, NULL },
1358 { 7, szOID_KP_KEY_RECOVERY_AGENT, 0, (LPCWSTR)IDS_KEY_RECOVERY_AGENT, NULL },
1359 { 7, szOID_KP_CA_EXCHANGE, 0, (LPCWSTR)IDS_CA_EXCHANGE, NULL },
1360 { 7, szOID_KP_LIFETIME_SIGNING, 0, (LPCWSTR)IDS_LIFETIME_SIGNING, NULL },
1362 { 8, szOID_ANY_CERT_POLICY, 0, (LPCWSTR)IDS_ANY_CERT_POLICY, NULL },
1365 struct OIDInfo {
1366 CRYPT_OID_INFO info;
1367 struct list entry;
1370 static void init_oid_info(HINSTANCE hinst)
1372 DWORD i;
1374 oid_init_localizednames(hinst);
1375 for (i = 0; i < sizeof(oidInfoConstructors) /
1376 sizeof(oidInfoConstructors[0]); i++)
1378 if (HIWORD(oidInfoConstructors[i].pwszName))
1380 struct OIDInfo *info;
1382 /* The name is a static string, so just use the same pointer */
1383 info = CryptMemAlloc(sizeof(struct OIDInfo));
1384 if (info)
1386 memset(info, 0, sizeof(*info));
1387 info->info.cbSize = sizeof(CRYPT_OID_INFO);
1388 info->info.pszOID = oidInfoConstructors[i].pszOID;
1389 info->info.pwszName = oidInfoConstructors[i].pwszName;
1390 info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
1391 info->info.u.Algid = oidInfoConstructors[i].Algid;
1392 if (oidInfoConstructors[i].blob)
1394 info->info.ExtraInfo.cbData =
1395 oidInfoConstructors[i].blob->cbData;
1396 info->info.ExtraInfo.pbData =
1397 oidInfoConstructors[i].blob->pbData;
1399 list_add_tail(&oidInfo, &info->entry);
1402 else
1404 LPCWSTR stringresource;
1405 int len = LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName,
1406 (LPWSTR)&stringresource, 0);
1408 if (len)
1410 struct OIDInfo *info = CryptMemAlloc(sizeof(struct OIDInfo) +
1411 (len + 1) * sizeof(WCHAR));
1413 if (info)
1415 memset(info, 0, sizeof(*info));
1416 info->info.cbSize = sizeof(CRYPT_OID_INFO);
1417 info->info.pszOID = oidInfoConstructors[i].pszOID;
1418 info->info.pwszName = (LPWSTR)(info + 1);
1419 info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
1420 info->info.u.Algid = oidInfoConstructors[i].Algid;
1421 memcpy(info + 1, stringresource, len*sizeof(WCHAR));
1422 ((LPWSTR)(info + 1))[len] = 0;
1423 if (oidInfoConstructors[i].blob)
1425 info->info.ExtraInfo.cbData =
1426 oidInfoConstructors[i].blob->cbData;
1427 info->info.ExtraInfo.pbData =
1428 oidInfoConstructors[i].blob->pbData;
1430 list_add_tail(&oidInfo, &info->entry);
1437 static void free_oid_info(void)
1439 struct OIDInfo *info, *next;
1441 LIST_FOR_EACH_ENTRY_SAFE(info, next, &oidInfo, struct OIDInfo, entry)
1443 list_remove(&info->entry);
1444 CryptMemFree(info);
1448 /***********************************************************************
1449 * CryptEnumOIDInfo (CRYPT32.@)
1451 BOOL WINAPI CryptEnumOIDInfo(DWORD dwGroupId, DWORD dwFlags, void *pvArg,
1452 PFN_CRYPT_ENUM_OID_INFO pfnEnumOIDInfo)
1454 BOOL ret = TRUE;
1455 struct OIDInfo *info;
1457 TRACE("(%d, %08x, %p, %p)\n", dwGroupId, dwFlags, pvArg,
1458 pfnEnumOIDInfo);
1460 EnterCriticalSection(&oidInfoCS);
1461 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1463 if (!dwGroupId || dwGroupId == info->info.dwGroupId)
1465 ret = pfnEnumOIDInfo(&info->info, pvArg);
1466 if (!ret)
1467 break;
1470 LeaveCriticalSection(&oidInfoCS);
1471 return ret;
1474 PCCRYPT_OID_INFO WINAPI CryptFindOIDInfo(DWORD dwKeyType, void *pvKey,
1475 DWORD dwGroupId)
1477 PCCRYPT_OID_INFO ret = NULL;
1479 TRACE("(%d, %p, %d)\n", dwKeyType, pvKey, dwGroupId);
1481 switch(dwKeyType)
1483 case CRYPT_OID_INFO_ALGID_KEY:
1485 struct OIDInfo *info;
1487 TRACE("CRYPT_OID_INFO_ALGID_KEY: %d\n", *(DWORD *)pvKey);
1488 EnterCriticalSection(&oidInfoCS);
1489 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1491 if (info->info.u.Algid == *(DWORD *)pvKey &&
1492 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1494 ret = &info->info;
1495 break;
1498 LeaveCriticalSection(&oidInfoCS);
1499 break;
1501 case CRYPT_OID_INFO_NAME_KEY:
1503 struct OIDInfo *info;
1505 TRACE("CRYPT_OID_INFO_NAME_KEY: %s\n", debugstr_w((LPWSTR)pvKey));
1506 EnterCriticalSection(&oidInfoCS);
1507 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1509 if (!lstrcmpW(info->info.pwszName, (LPWSTR)pvKey) &&
1510 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1512 ret = &info->info;
1513 break;
1516 LeaveCriticalSection(&oidInfoCS);
1517 break;
1519 case CRYPT_OID_INFO_OID_KEY:
1521 struct OIDInfo *info;
1522 LPSTR oid = (LPSTR)pvKey;
1524 TRACE("CRYPT_OID_INFO_OID_KEY: %s\n", debugstr_a(oid));
1525 EnterCriticalSection(&oidInfoCS);
1526 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1528 if (!lstrcmpA(info->info.pszOID, oid) &&
1529 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1531 ret = &info->info;
1532 break;
1535 LeaveCriticalSection(&oidInfoCS);
1536 break;
1538 case CRYPT_OID_INFO_SIGN_KEY:
1540 struct OIDInfo *info;
1542 TRACE("CRYPT_OID_INFO_SIGN_KEY: %d\n", *(DWORD *)pvKey);
1543 EnterCriticalSection(&oidInfoCS);
1544 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1546 if (info->info.u.Algid == *(DWORD *)pvKey &&
1547 info->info.ExtraInfo.cbData >= sizeof(DWORD) &&
1548 *(DWORD *)info->info.ExtraInfo.pbData ==
1549 *(DWORD *)((LPBYTE)pvKey + sizeof(DWORD)) &&
1550 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1552 ret = &info->info;
1553 break;
1556 LeaveCriticalSection(&oidInfoCS);
1557 break;
1560 return ret;
1563 LPCSTR WINAPI CertAlgIdToOID(DWORD dwAlgId)
1565 LPCSTR ret;
1566 PCCRYPT_OID_INFO info = CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY,
1567 &dwAlgId, 0);
1569 if (info)
1570 ret = info->pszOID;
1571 else
1572 ret = NULL;
1573 return ret;
1576 DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId)
1578 DWORD ret;
1579 PCCRYPT_OID_INFO info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY,
1580 (void *)pszObjId, 0);
1582 if (info)
1583 ret = info->u.Algid;
1584 else
1585 ret = 0;
1586 return ret;