msvcrt: New implementation of fcvt.
[wine/multimedia.git] / dlls / crypt32 / oid.c
blob98ced9e842d0b405d3f2043b5847f73a65a781ac
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 void free_function_sets(void)
82 struct OIDFunctionSet *setCursor, *setNext;
84 LIST_FOR_EACH_ENTRY_SAFE(setCursor, setNext, &funcSets,
85 struct OIDFunctionSet, next)
87 struct OIDFunction *functionCursor, *funcNext;
89 list_remove(&setCursor->next);
90 CryptMemFree(setCursor->name);
91 LIST_FOR_EACH_ENTRY_SAFE(functionCursor, funcNext,
92 &setCursor->functions, struct OIDFunction, next)
94 list_remove(&functionCursor->next);
95 CryptMemFree(functionCursor);
97 setCursor->cs.DebugInfo->Spare[0] = 0;
98 DeleteCriticalSection(&setCursor->cs);
99 CryptMemFree(setCursor);
103 /* There is no free function associated with this; therefore, the sets are
104 * freed when crypt32.dll is unloaded.
106 HCRYPTOIDFUNCSET WINAPI CryptInitOIDFunctionSet(LPCSTR pszFuncName,
107 DWORD dwFlags)
109 struct OIDFunctionSet *cursor, *ret = NULL;
111 TRACE("(%s, %x)\n", debugstr_a(pszFuncName), dwFlags);
113 EnterCriticalSection(&funcSetCS);
114 LIST_FOR_EACH_ENTRY(cursor, &funcSets, struct OIDFunctionSet, next)
116 if (!strcasecmp(pszFuncName, cursor->name))
118 ret = (HCRYPTOIDFUNCSET)cursor;
119 break;
122 if (!ret)
124 ret = CryptMemAlloc(sizeof(struct OIDFunctionSet));
125 if (ret)
127 memset(ret, 0, sizeof(*ret));
128 ret->name = CryptMemAlloc(strlen(pszFuncName) + 1);
129 if (ret->name)
131 InitializeCriticalSection(&ret->cs);
132 ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": OIDFunctionSet.cs");
133 list_init(&ret->functions);
134 strcpy(ret->name, pszFuncName);
135 list_add_tail(&funcSets, &ret->next);
137 else
139 CryptMemFree(ret);
140 ret = NULL;
144 LeaveCriticalSection(&funcSetCS);
146 return (HCRYPTOIDFUNCSET)ret;
149 static char *CRYPT_GetKeyName(DWORD dwEncodingType, LPCSTR pszFuncName,
150 LPCSTR pszOID)
152 static const char szEncodingTypeFmt[] =
153 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\%s";
154 UINT len;
155 char numericOID[7]; /* enough for "#65535" */
156 const char *oid;
157 LPSTR szKey;
159 /* MSDN says the encoding type is a mask, but it isn't treated that way.
160 * (E.g., if dwEncodingType were 3, the key names "EncodingType 1" and
161 * "EncodingType 2" would be expected if it were a mask. Instead native
162 * stores values in "EncodingType 3".
164 if (!HIWORD(pszOID))
166 snprintf(numericOID, sizeof(numericOID), "#%d", LOWORD(pszOID));
167 oid = numericOID;
169 else
170 oid = pszOID;
172 /* This is enough: the lengths of the two string parameters are explicitly
173 * counted, and we need up to five additional characters for the encoding
174 * type. These are covered by the "%d", "%s", and "%s" characters in the
175 * format specifier that are removed by sprintf.
177 len = sizeof(szEncodingTypeFmt) + lstrlenA(pszFuncName) + lstrlenA(oid);
178 szKey = CryptMemAlloc(len);
179 if (szKey)
180 sprintf(szKey, szEncodingTypeFmt,
181 GET_CERT_ENCODING_TYPE(dwEncodingType), pszFuncName, oid);
182 return szKey;
185 BOOL WINAPI CryptGetDefaultOIDDllList(HCRYPTOIDFUNCSET hFuncSet,
186 DWORD dwEncodingType, LPWSTR pwszDllList, DWORD *pcchDllList)
188 BOOL ret = TRUE;
189 struct OIDFunctionSet *set = (struct OIDFunctionSet *)hFuncSet;
190 char *keyName;
191 HKEY key;
192 long rc;
194 TRACE("(%p, %d, %p, %p)\n", hFuncSet, dwEncodingType, pwszDllList,
195 pcchDllList);
197 keyName = CRYPT_GetKeyName(dwEncodingType, set->name, "DEFAULT");
198 rc = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, NULL, 0,
199 KEY_READ, NULL, &key, NULL);
200 if (!rc)
202 DWORD size = *pcchDllList * sizeof(WCHAR);
204 rc = RegQueryValueExW(key, DllW, NULL, NULL, (LPBYTE)pwszDllList,
205 &size);
206 if (!rc)
207 *pcchDllList = size / sizeof(WCHAR);
208 else
210 /* No value, return an empty list */
211 if (*pcchDllList)
212 *pwszDllList = '\0';
213 *pcchDllList = 1;
215 RegCloseKey(key);
217 else
219 SetLastError(rc);
220 ret = FALSE;
222 CryptMemFree(keyName);
224 return ret;
227 BOOL WINAPI CryptInstallOIDFunctionAddress(HMODULE hModule,
228 DWORD dwEncodingType, LPCSTR pszFuncName, DWORD cFuncEntry,
229 const CRYPT_OID_FUNC_ENTRY rgFuncEntry[], DWORD dwFlags)
231 BOOL ret = TRUE;
232 struct OIDFunctionSet *set;
234 TRACE("(%p, %d, %s, %d, %p, %08x)\n", hModule, dwEncodingType,
235 debugstr_a(pszFuncName), cFuncEntry, rgFuncEntry, dwFlags);
237 set = (struct OIDFunctionSet *)CryptInitOIDFunctionSet(pszFuncName, 0);
238 if (set)
240 DWORD i;
242 EnterCriticalSection(&set->cs);
243 for (i = 0; ret && i < cFuncEntry; i++)
245 struct OIDFunction *func;
247 if (HIWORD(rgFuncEntry[i].pszOID))
248 func = CryptMemAlloc(sizeof(struct OIDFunction)
249 + strlen(rgFuncEntry[i].pszOID) + 1);
250 else
251 func = CryptMemAlloc(sizeof(struct OIDFunction));
252 if (func)
254 func->encoding = GET_CERT_ENCODING_TYPE(dwEncodingType);
255 if (HIWORD(rgFuncEntry[i].pszOID))
257 LPSTR oid;
259 oid = (LPSTR)((LPBYTE)func + sizeof(*func));
260 strcpy(oid, rgFuncEntry[i].pszOID);
261 func->entry.pszOID = oid;
263 else
264 func->entry.pszOID = rgFuncEntry[i].pszOID;
265 func->entry.pvFuncAddr = rgFuncEntry[i].pvFuncAddr;
266 list_add_tail(&set->functions, &func->next);
268 else
269 ret = FALSE;
271 LeaveCriticalSection(&set->cs);
273 else
274 ret = FALSE;
275 return ret;
278 static BOOL CRYPT_GetFuncFromReg(DWORD dwEncodingType, LPCSTR pszOID,
279 LPCSTR szFuncName, LPVOID *ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
281 BOOL ret = FALSE;
282 char *keyName;
283 const char *funcName;
284 HKEY key;
285 long rc;
287 keyName = CRYPT_GetKeyName(dwEncodingType, szFuncName, pszOID);
288 rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &key);
289 if (!rc)
291 DWORD type, size = 0;
293 rc = RegQueryValueExA(key, "FuncName", NULL, &type, NULL, &size);
294 if ((!rc || rc == ERROR_MORE_DATA) && type == REG_SZ)
296 funcName = CryptMemAlloc(size);
297 rc = RegQueryValueExA(key, "FuncName", NULL, &type,
298 (LPBYTE)funcName, &size);
300 else
301 funcName = szFuncName;
302 rc = RegQueryValueExW(key, DllW, NULL, &type, NULL, &size);
303 if ((!rc || rc == ERROR_MORE_DATA) && type == REG_SZ)
305 LPWSTR dllName = CryptMemAlloc(size);
307 if (dllName)
309 rc = RegQueryValueExW(key, DllW, NULL, NULL,
310 (LPBYTE)dllName, &size);
311 if (!rc)
313 HMODULE lib;
315 /* This is a bit of a hack; MSDN describes a more
316 * complicated unload routine than this will allow.
317 * Still, this seems to suffice for now.
319 lib = LoadLibraryW(dllName);
320 if (lib)
322 *ppvFuncAddr = GetProcAddress(lib, funcName);
323 if (*ppvFuncAddr)
325 *phFuncAddr = (HCRYPTOIDFUNCADDR)lib;
326 ret = TRUE;
328 else
330 /* Unload the library, the caller doesn't want
331 * to unload it when the return value is NULL.
333 FreeLibrary(lib);
337 else
338 SetLastError(rc);
339 CryptMemFree(dllName);
342 else
343 SetLastError(rc);
344 if (funcName != szFuncName)
345 CryptMemFree((char *)funcName);
346 RegCloseKey(key);
348 else
349 SetLastError(rc);
350 CryptMemFree(keyName);
351 return ret;
354 BOOL WINAPI CryptGetOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet,
355 DWORD dwEncodingType, LPCSTR pszOID, DWORD dwFlags, void **ppvFuncAddr,
356 HCRYPTOIDFUNCADDR *phFuncAddr)
358 BOOL ret = FALSE;
359 struct OIDFunctionSet *set = (struct OIDFunctionSet *)hFuncSet;
361 TRACE("(%p, %d, %s, %08x, %p, %p)\n", hFuncSet, dwEncodingType,
362 debugstr_a(pszOID), dwFlags, ppvFuncAddr, phFuncAddr);
364 *ppvFuncAddr = NULL;
365 if (!(dwFlags & CRYPT_GET_INSTALLED_OID_FUNC_FLAG))
367 struct OIDFunction *function;
369 EnterCriticalSection(&set->cs);
370 LIST_FOR_EACH_ENTRY(function, &set->functions, struct OIDFunction, next)
372 if (function->encoding == GET_CERT_ENCODING_TYPE(dwEncodingType))
374 if (HIWORD(pszOID))
376 if (HIWORD(function->entry.pszOID) &&
377 !strcasecmp(function->entry.pszOID, pszOID))
379 *ppvFuncAddr = function->entry.pvFuncAddr;
380 *phFuncAddr = NULL; /* FIXME: what should it be? */
381 ret = TRUE;
382 break;
385 else if (function->entry.pszOID == pszOID)
387 *ppvFuncAddr = function->entry.pvFuncAddr;
388 *phFuncAddr = NULL; /* FIXME: what should it be? */
389 ret = TRUE;
390 break;
394 LeaveCriticalSection(&set->cs);
396 if (!*ppvFuncAddr)
397 ret = CRYPT_GetFuncFromReg(dwEncodingType, pszOID, set->name,
398 ppvFuncAddr, phFuncAddr);
399 TRACE("returning %d\n", ret);
400 return ret;
403 BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr,
404 DWORD dwFlags)
406 TRACE("(%p, %08x)\n", hFuncAddr, dwFlags);
408 /* FIXME: as MSDN states, need to check for DllCanUnloadNow in the DLL,
409 * and only unload it if it can be unloaded. Also need to implement ref
410 * counting on the functions.
412 FreeLibrary((HMODULE)hFuncAddr);
413 return TRUE;
416 BOOL WINAPI CryptGetDefaultOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet,
417 DWORD dwEncodingType, LPCWSTR pwszDll, DWORD dwFlags, void *ppvFuncAddr,
418 HCRYPTOIDFUNCADDR *phFuncAddr)
420 FIXME("(%p, %d, %s, %08x, %p, %p): stub\n", hFuncSet, dwEncodingType,
421 debugstr_w(pwszDll), dwFlags, ppvFuncAddr, phFuncAddr);
422 return FALSE;
425 /***********************************************************************
426 * CryptRegisterOIDFunction (CRYPT32.@)
428 * Register the DLL and the functions it uses to cover the combination
429 * of encoding type, functionname and OID.
431 * PARAMS
432 * dwEncodingType [I] Encoding type to be used.
433 * pszFuncName [I] Name of the function to be registered.
434 * pszOID [I] OID of the function (numeric or string).
435 * pwszDll [I] The DLL that is to be registered.
436 * pszOverrideFuncName [I] Name of the function in the DLL.
438 * RETURNS
439 * Success: TRUE.
440 * Failure: FALSE. (Look at GetLastError()).
442 * NOTES
443 * Registry errors are always reported via SetLastError().
445 BOOL WINAPI CryptRegisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
446 LPCSTR pszOID, LPCWSTR pwszDll, LPCSTR pszOverrideFuncName)
448 LONG r;
449 HKEY hKey;
450 LPSTR szKey;
452 TRACE("(%x, %s, %s, %s, %s)\n", dwEncodingType, pszFuncName,
453 debugstr_a(pszOID), debugstr_w(pwszDll), pszOverrideFuncName);
455 /* This only registers functions for encoding certs, not messages */
456 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
457 return TRUE;
459 /* Native does nothing pwszDll is NULL */
460 if (!pwszDll)
461 return TRUE;
463 /* I'm not matching MS bug for bug here, because I doubt any app depends on
464 * it: native "succeeds" if pszFuncName is NULL, but the nonsensical entry
465 * it creates would never be used.
467 if (!pszFuncName || !pszOID)
469 SetLastError(E_INVALIDARG);
470 return FALSE;
473 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
474 TRACE("Key name is %s\n", debugstr_a(szKey));
476 if (!szKey)
477 return FALSE;
479 r = RegCreateKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
480 CryptMemFree(szKey);
482 if (r != ERROR_SUCCESS) goto error_close_key;
484 /* write the values */
485 if (pszOverrideFuncName)
487 r = RegSetValueExA(hKey, "FuncName", 0, REG_SZ,
488 (const BYTE*)pszOverrideFuncName, lstrlenA(pszOverrideFuncName) + 1);
489 if (r != ERROR_SUCCESS) goto error_close_key;
491 r = RegSetValueExW(hKey, DllW, 0, REG_SZ, (const BYTE*) pwszDll,
492 (lstrlenW(pwszDll) + 1) * sizeof (WCHAR));
494 error_close_key:
496 RegCloseKey(hKey);
498 if (r != ERROR_SUCCESS)
500 SetLastError(r);
501 return FALSE;
504 return TRUE;
507 /***********************************************************************
508 * CryptUnregisterOIDFunction (CRYPT32.@)
510 BOOL WINAPI CryptUnregisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
511 LPCSTR pszOID)
513 LPSTR szKey;
514 LONG rc;
516 TRACE("%x %s %s\n", dwEncodingType, pszFuncName, pszOID);
518 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
519 return TRUE;
521 if (!pszFuncName || !pszOID)
523 SetLastError(ERROR_INVALID_PARAMETER);
524 return FALSE;
527 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
528 rc = RegDeleteKeyA(HKEY_LOCAL_MACHINE, szKey);
529 CryptMemFree(szKey);
530 if (rc)
531 SetLastError(rc);
532 return rc ? FALSE : TRUE;
535 BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
536 LPCSTR pszOID, LPCWSTR pwszValueName, DWORD *pdwValueType, BYTE *pbValueData,
537 DWORD *pcbValueData)
539 LPSTR szKey;
540 LONG rc;
541 HKEY hKey;
543 TRACE("%x %s %s %s %p %p %p\n", dwEncodingType, debugstr_a(pszFuncName),
544 debugstr_a(pszOID), debugstr_w(pwszValueName), pdwValueType, pbValueData,
545 pcbValueData);
547 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
548 return TRUE;
550 if (!pszFuncName || !pszOID || !pwszValueName)
552 SetLastError(ERROR_INVALID_PARAMETER);
553 return FALSE;
556 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
557 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
558 CryptMemFree(szKey);
559 if (rc)
560 SetLastError(rc);
561 else
563 rc = RegQueryValueExW(hKey, pwszValueName, NULL, pdwValueType,
564 pbValueData, pcbValueData);
565 if (rc)
566 SetLastError(rc);
567 RegCloseKey(hKey);
569 return rc ? FALSE : TRUE;
572 BOOL WINAPI CryptSetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
573 LPCSTR pszOID, LPCWSTR pwszValueName, DWORD dwValueType,
574 const BYTE *pbValueData, DWORD cbValueData)
576 LPSTR szKey;
577 LONG rc;
578 HKEY hKey;
580 TRACE("%x %s %s %s %d %p %d\n", dwEncodingType, debugstr_a(pszFuncName),
581 debugstr_a(pszOID), debugstr_w(pwszValueName), dwValueType, pbValueData,
582 cbValueData);
584 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
585 return TRUE;
587 if (!pszFuncName || !pszOID || !pwszValueName)
589 SetLastError(ERROR_INVALID_PARAMETER);
590 return FALSE;
593 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
594 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
595 CryptMemFree(szKey);
596 if (rc)
597 SetLastError(rc);
598 else
600 rc = RegSetValueExW(hKey, pwszValueName, 0, dwValueType, pbValueData,
601 cbValueData);
602 if (rc)
603 SetLastError(rc);
604 RegCloseKey(hKey);
606 return rc ? FALSE : TRUE;
609 static LPCWSTR CRYPT_FindStringInMultiString(LPCWSTR multi, LPCWSTR toFind)
611 LPCWSTR ret = NULL, ptr;
613 for (ptr = multi; ptr && *ptr && !ret; ptr += lstrlenW(ptr) + 1)
615 if (!lstrcmpiW(ptr, toFind))
616 ret = ptr;
618 return ret;
621 static DWORD CRYPT_GetMultiStringCharacterLen(LPCWSTR multi)
623 DWORD ret;
625 if (multi)
627 LPCWSTR ptr;
629 /* Count terminating empty string */
630 ret = 1;
631 for (ptr = multi; *ptr; ptr += lstrlenW(ptr) + 1)
632 ret += lstrlenW(ptr) + 1;
634 else
635 ret = 0;
636 return ret;
639 static LPWSTR CRYPT_AddStringToMultiString(LPWSTR multi, LPCWSTR toAdd,
640 DWORD index)
642 LPWSTR ret;
644 if (!multi)
646 /* FIXME: ignoring index, is that okay? */
647 ret = CryptMemAlloc((lstrlenW(toAdd) + 2) * sizeof(WCHAR));
648 if (ret)
650 /* copy string, including NULL terminator */
651 memcpy(ret, toAdd, (lstrlenW(toAdd) + 1) * sizeof(WCHAR));
652 /* add terminating empty string */
653 *(ret + lstrlenW(toAdd) + 1) = 0;
656 else
658 DWORD len = CRYPT_GetMultiStringCharacterLen(multi);
660 ret = CryptMemRealloc(multi, (len + lstrlenW(toAdd) + 1) *
661 sizeof(WCHAR));
662 if (ret)
664 LPWSTR spotToAdd;
666 if (index == CRYPT_REGISTER_LAST_INDEX)
667 spotToAdd = ret + len - 1;
668 else
670 DWORD i;
672 /* FIXME: if index is too large for the string, toAdd is
673 * added to the end. Is that okay?
675 for (i = 0, spotToAdd = ret; i < index && *spotToAdd;
676 spotToAdd += lstrlenW(spotToAdd) + 1)
679 if (spotToAdd)
681 /* Copy existing string "right" */
682 memmove(spotToAdd + lstrlenW(toAdd) + 1, spotToAdd,
683 (len - (spotToAdd - ret)) * sizeof(WCHAR));
684 /* Copy new string */
685 memcpy(spotToAdd, toAdd, (lstrlenW(toAdd) + 1) * sizeof(WCHAR));
687 else
689 CryptMemFree(ret);
690 ret = NULL;
694 return ret;
697 static BOOL CRYPT_RemoveStringFromMultiString(LPWSTR multi, LPCWSTR toRemove)
699 LPWSTR spotToRemove = (LPWSTR)CRYPT_FindStringInMultiString(multi,
700 toRemove);
701 BOOL ret;
703 if (spotToRemove)
705 DWORD len = CRYPT_GetMultiStringCharacterLen(multi);
707 /* Copy remainder of string "left" */
708 memmove(spotToRemove, spotToRemove + lstrlenW(toRemove) + 1,
709 (len - (spotToRemove - multi)) * sizeof(WCHAR));
710 ret = TRUE;
712 else
714 SetLastError(ERROR_FILE_NOT_FOUND);
715 ret = FALSE;
717 return ret;
720 static BOOL CRYPT_GetDefaultOIDKey(DWORD dwEncodingType, LPCSTR pszFuncName,
721 PHKEY key)
723 LPSTR keyName;
724 LONG r;
726 keyName = CRYPT_GetKeyName(dwEncodingType, pszFuncName, "DEFAULT");
727 TRACE("Key name is %s\n", debugstr_a(keyName));
729 if (!keyName)
730 return FALSE;
732 r = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, NULL, 0, KEY_ALL_ACCESS,
733 NULL, key, NULL);
734 CryptMemFree(keyName);
735 if (r != ERROR_SUCCESS)
737 SetLastError(r);
738 return FALSE;
740 return TRUE;
743 static LPWSTR CRYPT_GetDefaultOIDDlls(HKEY key)
745 LONG r;
746 DWORD type, size;
747 LPWSTR dlls;
749 r = RegQueryValueExW(key, DllW, NULL, &type, NULL, &size);
750 if (r == ERROR_SUCCESS && type == REG_MULTI_SZ)
752 dlls = CryptMemAlloc(size);
753 r = RegQueryValueExW(key, DllW, NULL, &type, (LPBYTE)dlls, &size);
754 if (r != ERROR_SUCCESS)
756 CryptMemFree(dlls);
757 dlls = NULL;
760 else
761 dlls = NULL;
762 return dlls;
765 static inline BOOL CRYPT_SetDefaultOIDDlls(HKEY key, LPCWSTR dlls)
767 DWORD len = CRYPT_GetMultiStringCharacterLen(dlls);
768 LONG r;
770 if ((r = RegSetValueExW(key, DllW, 0, REG_MULTI_SZ, (const BYTE *)dlls,
771 len * sizeof (WCHAR))))
772 SetLastError(r);
773 return r == ERROR_SUCCESS;
776 /***********************************************************************
777 * CryptRegisterDefaultOIDFunction (CRYPT32.@)
779 BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType,
780 LPCSTR pszFuncName, DWORD dwIndex, LPCWSTR pwszDll)
782 HKEY key;
783 LPWSTR dlls;
784 LPCWSTR existing;
785 BOOL ret = FALSE;
787 TRACE("(%x, %s, %x, %s)\n", dwEncodingType, pszFuncName, dwIndex,
788 debugstr_w(pwszDll));
790 if (!pwszDll)
792 SetLastError(E_INVALIDARG);
793 return FALSE;
796 if (!CRYPT_GetDefaultOIDKey(dwEncodingType, pszFuncName, &key))
797 return FALSE;
799 dlls = CRYPT_GetDefaultOIDDlls(key);
800 if ((existing = CRYPT_FindStringInMultiString(dlls, pwszDll)))
801 SetLastError(ERROR_FILE_EXISTS);
802 else
804 dlls = CRYPT_AddStringToMultiString(dlls, pwszDll, dwIndex);
805 if (dlls)
806 ret = CRYPT_SetDefaultOIDDlls(key, dlls);
808 CryptMemFree(dlls);
809 RegCloseKey(key);
810 return ret;
813 BOOL WINAPI CryptUnregisterDefaultOIDFunction(DWORD dwEncodingType,
814 LPCSTR pszFuncName, LPCWSTR pwszDll)
816 HKEY key;
817 LPWSTR dlls;
818 BOOL ret;
820 TRACE("(%x, %s, %s)\n", dwEncodingType, debugstr_a(pszFuncName),
821 debugstr_w(pwszDll));
823 if (!pwszDll)
825 SetLastError(E_INVALIDARG);
826 return FALSE;
829 if (!CRYPT_GetDefaultOIDKey(dwEncodingType, pszFuncName, &key))
830 return FALSE;
832 dlls = CRYPT_GetDefaultOIDDlls(key);
833 if ((ret = CRYPT_RemoveStringFromMultiString(dlls, pwszDll)))
834 ret = CRYPT_SetDefaultOIDDlls(key, dlls);
835 CryptMemFree(dlls);
836 RegCloseKey(key);
837 return ret;
840 /********************************************************************
841 * CryptFindLocalizedName (CRYPT32.@)
843 LPCWSTR WINAPI CryptFindLocalizedName(LPCWSTR pwszCryptName)
845 FIXME(" %s - stub\n",debugstr_w(pwszCryptName));
846 return NULL;
849 static CRITICAL_SECTION oidInfoCS;
850 static CRITICAL_SECTION_DEBUG oidInfoCSDebug =
852 0, 0, &oidInfoCS,
853 { &oidInfoCSDebug.ProcessLocksList, &oidInfoCSDebug.ProcessLocksList },
854 0, 0, { (DWORD_PTR)(__FILE__ ": oidInfoCS") }
856 static CRITICAL_SECTION oidInfoCS = { &oidInfoCSDebug, -1, 0, 0, 0, 0 };
857 static struct list oidInfo = { &oidInfo, &oidInfo };
859 static const WCHAR tripledes[] = { '3','d','e','s',0 };
860 static const WCHAR cms3deswrap[] = { 'C','M','S','3','D','E','S','w','r','a',
861 'p',0 };
862 static const WCHAR cmsrc2wrap[] = { 'C','M','S','R','C','2','w','r','a','p',0 };
863 static const WCHAR des[] = { 'd','e','s',0 };
864 static const WCHAR md2[] = { 'm','d','2',0 };
865 static const WCHAR md4[] = { 'm','d','4',0 };
866 static const WCHAR md5[] = { 'm','d','5',0 };
867 static const WCHAR rc2[] = { 'r','c','2',0 };
868 static const WCHAR rc4[] = { 'r','c','4',0 };
869 static const WCHAR sha[] = { 's','h','a',0 };
870 static const WCHAR sha1[] = { 's','h','a','1',0 };
871 static const WCHAR RSA[] = { 'R','S','A',0 };
872 static const WCHAR RSA_KEYX[] = { 'R','S','A','_','K','E','Y','X',0 };
873 static const WCHAR RSA_SIGN[] = { 'R','S','A','_','S','I','G','N',0 };
874 static const WCHAR DSA[] = { 'D','S','A',0 };
875 static const WCHAR DSA_SIGN[] = { 'D','S','A','_','S','I','G','N',0 };
876 static const WCHAR DH[] = { 'D','H',0 };
877 static const WCHAR DSS[] = { 'D','S','S',0 };
878 static const WCHAR mosaicKMandUpdSig[] =
879 { 'm','o','s','a','i','c','K','M','a','n','d','U','p','d','S','i','g',0 };
880 static const WCHAR ESDH[] = { 'E','S','D','H',0 };
881 static const WCHAR NO_SIGN[] = { 'N','O','S','I','G','N',0 };
882 static const WCHAR dsaSHA1[] = { 'd','s','a','S','H','A','1',0 };
883 static const WCHAR md2RSA[] = { 'm','d','2','R','S','A',0 };
884 static const WCHAR md4RSA[] = { 'm','d','4','R','S','A',0 };
885 static const WCHAR md5RSA[] = { 'm','d','5','R','S','A',0 };
886 static const WCHAR shaDSA[] = { 's','h','a','D','S','A',0 };
887 static const WCHAR sha1DSA[] = { 's','h','a','1','D','S','A',0 };
888 static const WCHAR shaRSA[] = { 's','h','a','R','S','A',0 };
889 static const WCHAR sha1RSA[] = { 's','h','a','1','R','S','A',0 };
890 static const WCHAR mosaicUpdatedSig[] =
891 { 'm','o','s','a','i','c','U','p','d','a','t','e','d','S','i','g',0 };
892 static const WCHAR CN[] = { 'C','N',0 };
893 static const WCHAR L[] = { 'L',0 };
894 static const WCHAR O[] = { 'O',0 };
895 static const WCHAR OU[] = { 'O','U',0 };
896 static const WCHAR E[] = { 'E',0 };
897 static const WCHAR C[] = { 'C',0 };
898 static const WCHAR S[] = { 'S',0 };
899 static const WCHAR ST[] = { 'S','T',0 };
900 static const WCHAR STREET[] = { 'S','T','R','E','E','T',0 };
901 static const WCHAR T[] = { 'T',0 };
902 static const WCHAR Title[] = { 'T','i','t','l','e',0 };
903 static const WCHAR G[] = { 'G',0 };
904 static const WCHAR GivenName[] = { 'G','i','v','e','n','N','a','m','e',0 };
905 static const WCHAR I[] = { 'I',0 };
906 static const WCHAR Initials[] = { 'I','n','i','t','i','a','l','s',0 };
907 static const WCHAR SN[] = { 'S','N',0 };
908 static const WCHAR DC[] = { 'D','C',0 };
909 static const WCHAR Description[] =
910 { 'D','e','s','c','r','i','p','t','i','o','n',0 };
911 static const WCHAR PostalCode[] = { 'P','o','s','t','a','l','C','o','d','e',0 };
912 static const WCHAR POBox[] = { 'P','O','B','o','x',0 };
913 static const WCHAR Phone[] = { 'P','h','o','n','e',0 };
914 static const WCHAR X21Address[] = { 'X','2','1','A','d','d','r','e','s','s',0 };
915 static const WCHAR dnQualifier[] =
916 { 'd','n','Q','u','a','l','i','f','i','e','r',0 };
917 static const WCHAR Email[] = { 'E','m','a','i','l',0 };
918 static const WCHAR GN[] = { 'G','N',0 };
920 static const DWORD noNullFlag = CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG;
921 static const DWORD mosaicFlags = CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG |
922 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG;
923 static const CRYPT_DATA_BLOB noNullBlob = { sizeof(noNullFlag),
924 (LPBYTE)&noNullFlag };
925 static const CRYPT_DATA_BLOB mosaicFlagsBlob = { sizeof(mosaicFlags),
926 (LPBYTE)&mosaicFlags };
928 static const DWORD rsaSign = CALG_RSA_SIGN;
929 static const DWORD dssSign[2] = { CALG_DSS_SIGN,
930 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG };
931 static const DWORD mosaicSign[2] = { CALG_DSS_SIGN,
932 CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG |
933 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG };
934 static const CRYPT_DATA_BLOB rsaSignBlob = { sizeof(rsaSign),
935 (LPBYTE)&rsaSign };
936 static const CRYPT_DATA_BLOB dssSignBlob = { sizeof(dssSign),
937 (LPBYTE)dssSign };
938 static const CRYPT_DATA_BLOB mosaicSignBlob = { sizeof(mosaicSign),
939 (LPBYTE)mosaicSign };
941 static const DWORD ia5String[] = { CERT_RDN_IA5_STRING, 0 };
942 static const DWORD numericString[] = { CERT_RDN_NUMERIC_STRING, 0 };
943 static const DWORD printableString[] = { CERT_RDN_PRINTABLE_STRING, 0 };
944 static const DWORD domainCompTypes[] = { CERT_RDN_IA5_STRING,
945 CERT_RDN_UTF8_STRING, 0 };
946 static const CRYPT_DATA_BLOB ia5StringBlob = { sizeof(ia5String),
947 (LPBYTE)ia5String };
948 static const CRYPT_DATA_BLOB numericStringBlob = { sizeof(numericString),
949 (LPBYTE)numericString };
950 static const CRYPT_DATA_BLOB printableStringBlob = { sizeof(printableString),
951 (LPBYTE)printableString };
952 static const CRYPT_DATA_BLOB domainCompTypesBlob = { sizeof(domainCompTypes),
953 (LPBYTE)domainCompTypes };
955 static const struct OIDInfoConstructor {
956 DWORD dwGroupId;
957 LPCSTR pszOID;
958 UINT Algid;
959 LPCWSTR pwszName;
960 const CRYPT_DATA_BLOB *blob;
961 } oidInfoConstructors[] = {
962 { 1, szOID_OIWSEC_sha1, CALG_SHA1, sha1, NULL },
963 { 1, szOID_OIWSEC_sha1, CALG_SHA1, sha, NULL },
964 { 1, szOID_OIWSEC_sha, CALG_SHA, sha, NULL },
965 { 1, szOID_RSA_MD5, CALG_MD5, md5, NULL },
966 { 1, szOID_RSA_MD4, CALG_MD4, md4, NULL },
967 { 1, szOID_RSA_MD2, CALG_MD2, md2, NULL },
969 { 2, szOID_OIWSEC_desCBC, CALG_DES, des, NULL },
970 { 2, szOID_RSA_DES_EDE3_CBC, CALG_3DES, tripledes, NULL },
971 { 2, szOID_RSA_RC2CBC, CALG_RC2, rc2, NULL },
972 { 2, szOID_RSA_RC4, CALG_RC4, rc4, NULL },
973 { 2, szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES, cms3deswrap, NULL },
974 { 2, szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2, cmsrc2wrap, NULL },
976 { 3, szOID_RSA_RSA, CALG_RSA_KEYX, RSA, NULL },
977 { 3, szOID_X957_DSA, CALG_DSS_SIGN, DSA, &noNullBlob },
978 { 3, szOID_ANSI_X942_DH, CALG_DH_SF, DH, &noNullBlob },
979 { 3, szOID_RSA_RSA, CALG_RSA_KEYX, RSA_KEYX, NULL },
980 { 3, szOID_RSA_RSA, CALG_RSA_SIGN, RSA, NULL },
981 { 3, szOID_RSA_RSA, CALG_RSA_SIGN, RSA_SIGN, NULL },
982 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSA, &noNullBlob },
983 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSS, &noNullBlob },
984 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSA_SIGN, &noNullBlob },
985 { 3, szOID_RSA_DH, CALG_DH_SF, DH, &noNullBlob },
986 { 3, szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX, RSA_KEYX, NULL },
987 { 3, szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN, mosaicKMandUpdSig,
988 &mosaicFlagsBlob },
989 { 3, szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM, ESDH, &noNullBlob },
990 { 3, szOID_PKIX_NO_SIGNATURE, CALG_NO_SIGN, NO_SIGN, NULL },
992 { 4, szOID_RSA_SHA1RSA, CALG_SHA1, sha1RSA, &rsaSignBlob },
993 { 4, szOID_RSA_MD5RSA, CALG_MD5, md5RSA, &rsaSignBlob },
994 { 4, szOID_X957_SHA1DSA, CALG_SHA1, sha1DSA, &dssSignBlob },
995 { 4, szOID_OIWSEC_sha1RSASign, CALG_SHA1, sha1RSA, &rsaSignBlob },
996 { 4, szOID_OIWSEC_sha1RSASign, CALG_SHA1, shaRSA, &rsaSignBlob },
997 { 4, szOID_OIWSEC_shaRSA, CALG_SHA1, shaRSA, &rsaSignBlob },
998 { 4, szOID_OIWSEC_md5RSA, CALG_MD5, md5RSA, &rsaSignBlob },
999 { 4, szOID_RSA_MD2RSA, CALG_MD2, md2RSA, &rsaSignBlob },
1000 { 4, szOID_RSA_MD4RSA, CALG_MD4, md4RSA, &rsaSignBlob },
1001 { 4, szOID_OIWSEC_md4RSA, CALG_MD4, md4RSA, &rsaSignBlob },
1002 { 4, szOID_OIWSEC_md4RSA2, CALG_MD4, md4RSA, &rsaSignBlob },
1003 { 4, szOID_OIWDIR_md2RSA, CALG_MD2, md2RSA, &rsaSignBlob },
1004 { 4, szOID_OIWSEC_shaDSA, CALG_SHA1, sha1DSA, &dssSignBlob },
1005 { 4, szOID_OIWSEC_shaDSA, CALG_SHA1, shaDSA, &dssSignBlob },
1006 { 4, szOID_OIWSEC_dsaSHA1, CALG_SHA1, dsaSHA1, &dssSignBlob },
1007 { 4, szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA1, mosaicUpdatedSig,
1008 &mosaicSignBlob },
1010 { 5, szOID_COMMON_NAME, 0, CN, NULL },
1011 { 5, szOID_LOCALITY_NAME, 0, L, NULL },
1012 { 5, szOID_ORGANIZATION_NAME, 0, O, NULL },
1013 { 5, szOID_ORGANIZATIONAL_UNIT_NAME, 0, OU, NULL },
1014 { 5, szOID_RSA_emailAddr, 0, E, &ia5StringBlob },
1015 { 5, szOID_RSA_emailAddr, 0, Email, &ia5StringBlob },
1016 { 5, szOID_COUNTRY_NAME, 0, C, &printableStringBlob },
1017 { 5, szOID_STATE_OR_PROVINCE_NAME, 0, S, NULL },
1018 { 5, szOID_STATE_OR_PROVINCE_NAME, 0, ST, NULL },
1019 { 5, szOID_STREET_ADDRESS, 0, STREET, NULL },
1020 { 5, szOID_TITLE, 0, T, NULL },
1021 { 5, szOID_TITLE, 0, Title, NULL },
1022 { 5, szOID_GIVEN_NAME, 0, G, NULL },
1023 { 5, szOID_GIVEN_NAME, 0, GN, NULL },
1024 { 5, szOID_GIVEN_NAME, 0, GivenName, NULL },
1025 { 5, szOID_INITIALS, 0, I, NULL },
1026 { 5, szOID_INITIALS, 0, Initials, NULL },
1027 { 5, szOID_SUR_NAME, 0, SN, NULL },
1028 { 5, szOID_DOMAIN_COMPONENT, 0, DC, &domainCompTypesBlob },
1029 { 5, szOID_DESCRIPTION, 0, Description, NULL },
1030 { 5, szOID_POSTAL_CODE, 0, PostalCode, NULL },
1031 { 5, szOID_POST_OFFICE_BOX, 0, POBox, NULL },
1032 { 5, szOID_TELEPHONE_NUMBER, 0, Phone, &printableStringBlob },
1033 { 5, szOID_X21_ADDRESS, 0, X21Address, &numericStringBlob },
1034 { 5, szOID_DN_QUALIFIER, 0, dnQualifier, NULL },
1036 { 6, szOID_AUTHORITY_KEY_IDENTIFIER2, 0, (LPCWSTR)IDS_AUTHORITY_KEY_ID, NULL },
1037 { 6, szOID_AUTHORITY_KEY_IDENTIFIER, 0, (LPCWSTR)IDS_AUTHORITY_KEY_ID, NULL },
1038 { 6, szOID_KEY_ATTRIBUTES, 0, (LPCWSTR)IDS_KEY_ATTRIBUTES, NULL },
1039 { 6, szOID_KEY_USAGE_RESTRICTION, 0, (LPCWSTR)IDS_KEY_USAGE_RESTRICTION, NULL },
1040 { 6, szOID_SUBJECT_ALT_NAME2, 0, (LPCWSTR)IDS_SUBJECT_ALT_NAME, NULL },
1041 { 6, szOID_SUBJECT_ALT_NAME, 0, (LPCWSTR)IDS_SUBJECT_ALT_NAME, NULL },
1042 { 6, szOID_ISSUER_ALT_NAME2, 0, (LPCWSTR)IDS_ISSUER_ALT_NAME, NULL },
1043 { 6, szOID_ISSUER_ALT_NAME2, 0, (LPCWSTR)IDS_ISSUER_ALT_NAME, NULL },
1044 { 6, szOID_BASIC_CONSTRAINTS2, 0, (LPCWSTR)IDS_BASIC_CONSTRAINTS, NULL },
1045 { 6, szOID_BASIC_CONSTRAINTS, 0, (LPCWSTR)IDS_BASIC_CONSTRAINTS, NULL },
1046 { 6, szOID_KEY_USAGE, 0, (LPCWSTR)IDS_KEY_USAGE, NULL },
1047 { 6, szOID_CERT_POLICIES, 0, (LPCWSTR)IDS_CERT_POLICIES, NULL },
1048 { 6, szOID_SUBJECT_KEY_IDENTIFIER, 0, (LPCWSTR)IDS_SUBJECT_KEY_IDENTIFIER, NULL },
1049 { 6, szOID_CRL_REASON_CODE, 0, (LPCWSTR)IDS_CRL_REASON_CODE, NULL },
1050 { 6, szOID_CRL_DIST_POINTS, 0, (LPCWSTR)IDS_CRL_DIST_POINTS, NULL },
1051 { 6, szOID_ENHANCED_KEY_USAGE, 0, (LPCWSTR)IDS_ENHANCED_KEY_USAGE, NULL },
1052 { 6, szOID_AUTHORITY_INFO_ACCESS, 0, (LPCWSTR)IDS_AUTHORITY_INFO_ACCESS, NULL },
1053 { 6, szOID_CERT_EXTENSIONS, 0, (LPCWSTR)IDS_CERT_EXTENSIONS, NULL },
1054 { 6, szOID_RSA_certExtensions, 0, (LPCWSTR)IDS_CERT_EXTENSIONS, NULL },
1055 { 6, szOID_NEXT_UPDATE_LOCATION, 0, (LPCWSTR)IDS_NEXT_UPDATE_LOCATION, NULL },
1056 { 6, szOID_YESNO_TRUST_ATTR, 0, (LPCWSTR)IDS_YES_OR_NO_TRUST, NULL },
1057 { 6, szOID_RSA_emailAddr, 0, (LPCWSTR)IDS_EMAIL_ADDRESS, NULL },
1058 { 6, szOID_RSA_unstructName, 0, (LPCWSTR)IDS_UNSTRUCTURED_NAME, NULL },
1059 { 6, szOID_RSA_contentType, 0, (LPCWSTR)IDS_CONTENT_TYPE, NULL },
1060 { 6, szOID_RSA_messageDigest, 0, (LPCWSTR)IDS_MESSAGE_DIGEST, NULL },
1061 { 6, szOID_RSA_signingTime, 0, (LPCWSTR)IDS_SIGNING_TIME, NULL },
1062 { 6, szOID_RSA_counterSign, 0, (LPCWSTR)IDS_COUNTER_SIGN, NULL },
1063 { 6, szOID_RSA_challengePwd, 0, (LPCWSTR)IDS_CHALLENGE_PASSWORD, NULL },
1064 { 6, szOID_RSA_unstructAddr, 0, (LPCWSTR)IDS_UNSTRUCTURED_ADDRESS, NULL },
1065 { 6, szOID_RSA_SMIMECapabilities, 0, (LPCWSTR)IDS_SMIME_CAPABILITIES, NULL },
1066 { 6, szOID_RSA_preferSignedData, 0, (LPCWSTR)IDS_PREFER_SIGNED_DATA, NULL },
1067 { 6, szOID_PKIX_POLICY_QUALIFIER_CPS, 0, (LPCWSTR)IDS_CPS, NULL },
1068 { 6, szOID_PKIX_POLICY_QUALIFIER_USERNOTICE, 0, (LPCWSTR)IDS_USER_NOTICE, NULL },
1069 { 6, szOID_PKIX_OCSP, 0, (LPCWSTR)IDS_OCSP, NULL },
1070 { 6, szOID_PKIX_CA_ISSUERS, 0, (LPCWSTR)IDS_CA_ISSUER, NULL },
1071 { 6, szOID_ENROLL_CERTTYPE_EXTENSION, 0, (LPCWSTR)IDS_CERT_TEMPLATE_NAME, NULL },
1072 { 6, szOID_ENROLL_CERTTYPE_EXTENSION, 0, (LPCWSTR)IDS_CERT_TYPE, NULL },
1073 { 6, szOID_CERT_MANIFOLD, 0, (LPCWSTR)IDS_CERT_MANIFOLD, NULL },
1074 { 6, szOID_NETSCAPE_CERT_TYPE, 0, (LPCWSTR)IDS_NETSCAPE_CERT_TYPE, NULL },
1075 { 6, szOID_NETSCAPE_BASE_URL, 0, (LPCWSTR)IDS_NETSCAPE_BASE_URL, NULL },
1076 { 6, szOID_NETSCAPE_REVOCATION_URL, 0, (LPCWSTR)IDS_NETSCAPE_REVOCATION_URL, NULL },
1077 { 6, szOID_NETSCAPE_CA_REVOCATION_URL, 0, (LPCWSTR)IDS_NETSCAPE_CA_REVOCATION_URL, NULL },
1078 { 6, szOID_NETSCAPE_CERT_RENEWAL_URL, 0, (LPCWSTR)IDS_NETSCAPE_CERT_RENEWAL_URL, NULL },
1079 { 6, szOID_NETSCAPE_CA_POLICY_URL, 0, (LPCWSTR)IDS_NETSCAPE_CA_POLICY_URL, NULL },
1080 { 6, szOID_NETSCAPE_SSL_SERVER_NAME, 0, (LPCWSTR)IDS_NETSCAPE_SSL_SERVER_NAME, NULL },
1081 { 6, szOID_NETSCAPE_COMMENT, 0, (LPCWSTR)IDS_NETSCAPE_COMMENT, NULL },
1082 { 6, "1.3.6.1.4.1.311.2.1.10", 0, (LPCWSTR)IDS_SPC_SP_AGENCY_INFO, NULL },
1083 { 6, "1.3.6.1.4.1.311.2.1.27", 0, (LPCWSTR)IDS_SPC_FINANCIAL_CRITERIA, NULL },
1084 { 6, "1.3.6.1.4.1.311.2.1.26", 0, (LPCWSTR)IDS_SPC_MINIMAL_CRITERIA, NULL },
1085 { 6, szOID_COUNTRY_NAME, 0, (LPCWSTR)IDS_COUNTRY, NULL },
1086 { 6, szOID_ORGANIZATION_NAME, 0, (LPCWSTR)IDS_ORGANIZATION, NULL },
1087 { 6, szOID_ORGANIZATIONAL_UNIT_NAME, 0, (LPCWSTR)IDS_ORGANIZATIONAL_UNIT, NULL },
1088 { 6, szOID_COMMON_NAME, 0, (LPCWSTR)IDS_COMMON_NAME, NULL },
1089 { 6, szOID_LOCALITY_NAME, 0, (LPCWSTR)IDS_LOCALITY, NULL },
1090 { 6, szOID_STATE_OR_PROVINCE_NAME, 0, (LPCWSTR)IDS_STATE_OR_PROVINCE, NULL },
1091 { 6, szOID_TITLE, 0, (LPCWSTR)IDS_TITLE, NULL },
1092 { 6, szOID_GIVEN_NAME, 0, (LPCWSTR)IDS_GIVEN_NAME, NULL },
1093 { 6, szOID_INITIALS, 0, (LPCWSTR)IDS_INITIALS, NULL },
1094 { 6, szOID_SUR_NAME, 0, (LPCWSTR)IDS_SUR_NAME, NULL },
1095 { 6, szOID_DOMAIN_COMPONENT, 0, (LPCWSTR)IDS_DOMAIN_COMPONENT, NULL },
1096 { 6, szOID_STREET_ADDRESS, 0, (LPCWSTR)IDS_STREET_ADDRESS, NULL },
1097 { 6, szOID_DEVICE_SERIAL_NUMBER, 0, (LPCWSTR)IDS_SERIAL_NUMBER, NULL },
1098 { 6, szOID_CERTSRV_CA_VERSION, 0, (LPCWSTR)IDS_CA_VERSION, NULL },
1099 { 6, szOID_CERTSRV_CROSSCA_VERSION, 0, (LPCWSTR)IDS_CROSS_CA_VERSION, NULL },
1100 { 6, szOID_SERIALIZED, 0, (LPCWSTR)IDS_SERIALIZED_SIG_SERIAL_NUMBER, NULL },
1101 { 6, szOID_NT_PRINCIPAL_NAME, 0, (LPCWSTR)IDS_PRINCIPAL_NAME, NULL },
1102 { 6, szOID_PRODUCT_UPDATE, 0, (LPCWSTR)IDS_WINDOWS_PRODUCT_UPDATE, NULL },
1103 { 6, szOID_ENROLLMENT_NAME_VALUE_PAIR, 0, (LPCWSTR)IDS_ENROLLMENT_NAME_VALUE_PAIR, NULL },
1104 { 6, szOID_OS_VERSION, 0, (LPCWSTR)IDS_OS_VERSION, NULL },
1105 { 6, szOID_ENROLLMENT_CSP_PROVIDER, 0, (LPCWSTR)IDS_ENROLLMENT_CSP, NULL },
1106 { 6, szOID_CRL_NUMBER, 0, (LPCWSTR)IDS_CRL_NUMBER, NULL },
1107 { 6, szOID_DELTA_CRL_INDICATOR, 0, (LPCWSTR)IDS_DELTA_CRL_INDICATOR, NULL },
1108 { 6, szOID_ISSUING_DIST_POINT, 0, (LPCWSTR)IDS_ISSUING_DIST_POINT, NULL },
1109 { 6, szOID_FRESHEST_CRL, 0, (LPCWSTR)IDS_FRESHEST_CRL, NULL },
1110 { 6, szOID_NAME_CONSTRAINTS, 0, (LPCWSTR)IDS_NAME_CONSTRAINTS, NULL },
1111 { 6, szOID_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_POLICY_MAPPINGS, NULL },
1112 { 6, szOID_LEGACY_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_POLICY_MAPPINGS, NULL },
1113 { 6, szOID_POLICY_CONSTRAINTS, 0, (LPCWSTR)IDS_POLICY_CONSTRAINTS, NULL },
1114 { 6, szOID_CROSS_CERT_DIST_POINTS, 0, (LPCWSTR)IDS_CROSS_CERT_DIST_POINTS, NULL },
1115 { 6, szOID_APPLICATION_CERT_POLICIES, 0, (LPCWSTR)IDS_APPLICATION_POLICIES, NULL },
1116 { 6, szOID_APPLICATION_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_APPLICATION_POLICY_MAPPINGS, NULL },
1117 { 6, szOID_APPLICATION_POLICY_CONSTRAINTS, 0, (LPCWSTR)IDS_APPLICATION_POLICY_CONSTRAINTS, NULL },
1118 { 6, szOID_CT_PKI_DATA, 0, (LPCWSTR)IDS_CMC_DATA, NULL },
1119 { 6, szOID_CT_PKI_RESPONSE, 0, (LPCWSTR)IDS_CMC_RESPONSE, NULL },
1120 { 6, szOID_CMC, 0, (LPCWSTR)IDS_UNSIGNED_CMC_REQUEST, NULL },
1121 { 6, szOID_CMC_STATUS_INFO, 0, (LPCWSTR)IDS_CMC_STATUS_INFO, NULL },
1122 { 6, szOID_CMC_ADD_EXTENSIONS, 0, (LPCWSTR)IDS_CMC_EXTENSIONS, NULL },
1123 { 6, szOID_CTL, 0, (LPCWSTR)IDS_CMC_ATTRIBUTES, NULL },
1124 { 6, szOID_RSA_data, 0, (LPCWSTR)IDS_PKCS_7_DATA, NULL },
1125 { 6, szOID_RSA_signedData, 0, (LPCWSTR)IDS_PKCS_7_SIGNED, NULL },
1126 { 6, szOID_RSA_envelopedData, 0, (LPCWSTR)IDS_PKCS_7_ENVELOPED, NULL },
1127 { 6, szOID_RSA_signEnvData, 0, (LPCWSTR)IDS_PKCS_7_SIGNED_ENVELOPED, NULL },
1128 { 6, szOID_RSA_digestedData, 0, (LPCWSTR)IDS_PKCS_7_DIGESTED, NULL },
1129 { 6, szOID_RSA_encryptedData, 0, (LPCWSTR)IDS_PKCS_7_ENCRYPTED, NULL },
1130 { 6, szOID_CERTSRV_PREVIOUS_CERT_HASH, 0, (LPCWSTR)IDS_PREVIOUS_CA_CERT_HASH, NULL },
1131 { 6, szOID_CRL_VIRTUAL_BASE, 0, (LPCWSTR)IDS_CRL_VIRTUAL_BASE, NULL },
1132 { 6, szOID_CRL_NEXT_PUBLISH, 0, (LPCWSTR)IDS_CRL_NEXT_PUBLISH, NULL },
1133 { 6, szOID_KP_CA_EXCHANGE, 0, (LPCWSTR)IDS_CA_EXCHANGE, NULL },
1134 { 6, szOID_KP_KEY_RECOVERY_AGENT, 0, (LPCWSTR)IDS_KEY_RECOVERY_AGENT, NULL },
1135 { 6, szOID_CERTIFICATE_TEMPLATE, 0, (LPCWSTR)IDS_CERTIFICATE_TEMPLATE, NULL },
1136 { 6, szOID_ENTERPRISE_OID_ROOT, 0, (LPCWSTR)IDS_ENTERPRISE_ROOT_OID, NULL },
1137 { 6, szOID_RDN_DUMMY_SIGNER, 0, (LPCWSTR)IDS_RDN_DUMMY_SIGNER, NULL },
1138 { 6, szOID_ARCHIVED_KEY_ATTR, 0, (LPCWSTR)IDS_ARCHIVED_KEY_ATTR, NULL },
1139 { 6, szOID_CRL_SELF_CDP, 0, (LPCWSTR)IDS_CRL_SELF_CDP, NULL },
1140 { 6, szOID_REQUIRE_CERT_CHAIN_POLICY, 0, (LPCWSTR)IDS_REQUIRE_CERT_CHAIN_POLICY, NULL },
1141 { 6, szOID_CMC_TRANSACTION_ID, 0, (LPCWSTR)IDS_TRANSACTION_ID, NULL },
1142 { 6, szOID_CMC_SENDER_NONCE, 0, (LPCWSTR)IDS_SENDER_NONCE, NULL },
1143 { 6, szOID_CMC_RECIPIENT_NONCE, 0, (LPCWSTR)IDS_RECIPIENT_NONCE, NULL },
1144 { 6, szOID_CMC_REG_INFO, 0, (LPCWSTR)IDS_REG_INFO, NULL },
1145 { 6, szOID_CMC_GET_CERT, 0, (LPCWSTR)IDS_GET_CERTIFICATE, NULL },
1146 { 6, szOID_CMC_GET_CRL, 0, (LPCWSTR)IDS_GET_CRL, NULL },
1147 { 6, szOID_CMC_REVOKE_REQUEST, 0, (LPCWSTR)IDS_REVOKE_REQUEST, NULL },
1148 { 6, szOID_CMC_QUERY_PENDING, 0, (LPCWSTR)IDS_QUERY_PENDING, NULL },
1149 { 6, szOID_SORTED_CTL, 0, (LPCWSTR)IDS_SORTED_CTL, NULL },
1150 { 6, szOID_ARCHIVED_KEY_CERT_HASH, 0, (LPCWSTR)IDS_ARCHIVED_KEY_CERT_HASH, NULL },
1151 { 6, szOID_PRIVATEKEY_USAGE_PERIOD, 0, (LPCWSTR)IDS_PRIVATE_KEY_USAGE_PERIOD, NULL },
1152 { 6, szOID_REQUEST_CLIENT_INFO, 0, (LPCWSTR)IDS_CLIENT_INFORMATION, NULL },
1154 { 7, szOID_PKIX_KP_SERVER_AUTH, 0, (LPCWSTR)IDS_SERVER_AUTHENTICATION, NULL },
1155 { 7, szOID_PKIX_KP_CLIENT_AUTH, 0, (LPCWSTR)IDS_CLIENT_AUTHENTICATION, NULL },
1156 { 7, szOID_PKIX_KP_CODE_SIGNING, 0, (LPCWSTR)IDS_CODE_SIGNING, NULL },
1157 { 7, szOID_PKIX_KP_EMAIL_PROTECTION, 0, (LPCWSTR)IDS_SECURE_EMAIL, NULL },
1158 { 7, szOID_PKIX_KP_TIMESTAMP_SIGNING, 0, (LPCWSTR)IDS_TIME_STAMPING, NULL },
1159 { 7, szOID_KP_CTL_USAGE_SIGNING, 0, (LPCWSTR)IDS_MICROSOFT_TRUST_LIST_SIGNING, NULL },
1160 { 7, szOID_KP_TIME_STAMP_SIGNING, 0, (LPCWSTR)IDS_MICROSOFT_TIME_STAMPING, NULL },
1161 { 7, szOID_PKIX_KP_IPSEC_END_SYSTEM, 0, (LPCWSTR)IDS_IPSEC_END_SYSTEM, NULL },
1162 { 7, szOID_PKIX_KP_IPSEC_TUNNEL, 0, (LPCWSTR)IDS_IPSEC_TUNNEL, NULL },
1163 { 7, szOID_PKIX_KP_IPSEC_USER, 0, (LPCWSTR)IDS_IPSEC_USER, NULL },
1164 { 7, szOID_KP_EFS, 0, (LPCWSTR)IDS_EFS, NULL },
1165 { 7, szOID_WHQL_CRYPTO, 0, (LPCWSTR)IDS_WHQL_CRYPTO, NULL },
1166 { 7, szOID_NT5_CRYPTO, 0, (LPCWSTR)IDS_NT5_CRYPTO, NULL },
1167 { 7, szOID_OEM_WHQL_CRYPTO, 0, (LPCWSTR)IDS_OEM_WHQL_CRYPTO, NULL },
1168 { 7, szOID_EMBEDDED_NT_CRYPTO, 0, (LPCWSTR)IDS_EMBEDDED_NT_CRYPTO, NULL },
1169 { 7, szOID_LICENSES, 0, (LPCWSTR)IDS_KEY_PACK_LICENSES, NULL },
1170 { 7, szOID_LICENSE_SERVER, 0, (LPCWSTR)IDS_LICENSE_SERVER, NULL },
1171 { 7, szOID_KP_SMARTCARD_LOGON, 0, (LPCWSTR)IDS_SMART_CARD_LOGON, NULL },
1172 { 7, szOID_DRM, 0, (LPCWSTR)IDS_DIGITAL_RIGHTS, NULL },
1173 { 7, szOID_KP_QUALIFIED_SUBORDINATION, 0, (LPCWSTR)IDS_QUALIFIED_SUBORDINATION, NULL },
1174 { 7, szOID_KP_KEY_RECOVERY, 0, (LPCWSTR)IDS_KEY_RECOVERY, NULL },
1175 { 7, szOID_KP_DOCUMENT_SIGNING, 0, (LPCWSTR)IDS_DOCUMENT_SIGNING, NULL },
1176 { 7, szOID_IPSEC_KP_IKE_INTERMEDIATE, 0, (LPCWSTR)IDS_IPSEC_IKE_INTERMEDIATE, NULL },
1177 { 7, szOID_EFS_RECOVERY, 0, (LPCWSTR)IDS_FILE_RECOVERY, NULL },
1178 { 7, szOID_ROOT_LIST_SIGNER, 0, (LPCWSTR)IDS_ROOT_LIST_SIGNER, NULL },
1179 { 7, szOID_ANY_APPLICATION_POLICY, 0, (LPCWSTR)IDS_ANY_APPLICATION_POLICIES, NULL },
1180 { 7, szOID_DS_EMAIL_REPLICATION, 0, (LPCWSTR)IDS_DS_EMAIL_REPLICATION, NULL },
1181 { 7, szOID_ENROLLMENT_AGENT, 0, (LPCWSTR)IDS_ENROLLMENT_AGENT, NULL },
1182 { 7, szOID_KP_KEY_RECOVERY_AGENT, 0, (LPCWSTR)IDS_KEY_RECOVERY_AGENT, NULL },
1183 { 7, szOID_KP_CA_EXCHANGE, 0, (LPCWSTR)IDS_CA_EXCHANGE, NULL },
1184 { 7, szOID_KP_LIFETIME_SIGNING, 0, (LPCWSTR)IDS_LIFETIME_SIGNING, NULL },
1186 { 8, szOID_ANY_CERT_POLICY, 0, (LPCWSTR)IDS_ANY_CERT_POLICY, NULL },
1189 struct OIDInfo {
1190 CRYPT_OID_INFO info;
1191 struct list entry;
1194 static void init_oid_info(HINSTANCE hinst)
1196 DWORD i;
1198 for (i = 0; i < sizeof(oidInfoConstructors) /
1199 sizeof(oidInfoConstructors[0]); i++)
1201 if (HIWORD(oidInfoConstructors[i].pwszName))
1203 struct OIDInfo *info;
1205 /* The name is a static string, so just use the same pointer */
1206 info = CryptMemAlloc(sizeof(struct OIDInfo));
1207 if (info)
1209 memset(info, 0, sizeof(*info));
1210 info->info.cbSize = sizeof(CRYPT_OID_INFO);
1211 info->info.pszOID = oidInfoConstructors[i].pszOID;
1212 info->info.pwszName = oidInfoConstructors[i].pwszName;
1213 info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
1214 info->info.u.Algid = oidInfoConstructors[i].Algid;
1215 if (oidInfoConstructors[i].blob)
1217 info->info.ExtraInfo.cbData =
1218 oidInfoConstructors[i].blob->cbData;
1219 info->info.ExtraInfo.pbData =
1220 oidInfoConstructors[i].blob->pbData;
1222 list_add_tail(&oidInfo, &info->entry);
1225 else
1227 int len = LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName,
1228 NULL, 0);
1230 if (len)
1232 struct OIDInfo *info = CryptMemAlloc(sizeof(struct OIDInfo) +
1233 (len + 1) * sizeof(WCHAR));
1235 if (info)
1237 memset(info, 0, sizeof(*info));
1238 info->info.cbSize = sizeof(CRYPT_OID_INFO);
1239 info->info.pszOID = oidInfoConstructors[i].pszOID;
1240 info->info.pwszName =
1241 (LPWSTR)((LPBYTE)info + sizeof(struct OIDInfo));
1242 info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
1243 info->info.u.Algid = oidInfoConstructors[i].Algid;
1244 LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName,
1245 (LPWSTR)info->info.pwszName, len + 1);
1246 if (oidInfoConstructors[i].blob)
1248 info->info.ExtraInfo.cbData =
1249 oidInfoConstructors[i].blob->cbData;
1250 info->info.ExtraInfo.pbData =
1251 oidInfoConstructors[i].blob->pbData;
1253 list_add_tail(&oidInfo, &info->entry);
1260 static void free_oid_info(void)
1262 struct OIDInfo *info, *next;
1264 LIST_FOR_EACH_ENTRY_SAFE(info, next, &oidInfo, struct OIDInfo, entry)
1266 list_remove(&info->entry);
1267 CryptMemFree(info);
1271 /***********************************************************************
1272 * CryptEnumOIDInfo (CRYPT32.@)
1274 BOOL WINAPI CryptEnumOIDInfo(DWORD dwGroupId, DWORD dwFlags, void *pvArg,
1275 PFN_CRYPT_ENUM_OID_INFO pfnEnumOIDInfo)
1277 BOOL ret = TRUE;
1278 struct OIDInfo *info;
1280 TRACE("(%d, %08x, %p, %p)\n", dwGroupId, dwFlags, pvArg,
1281 pfnEnumOIDInfo);
1283 EnterCriticalSection(&oidInfoCS);
1284 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1286 if (!dwGroupId || dwGroupId == info->info.dwGroupId)
1288 ret = pfnEnumOIDInfo(&info->info, pvArg);
1289 if (!ret)
1290 break;
1293 LeaveCriticalSection(&oidInfoCS);
1294 return ret;
1297 PCCRYPT_OID_INFO WINAPI CryptFindOIDInfo(DWORD dwKeyType, void *pvKey,
1298 DWORD dwGroupId)
1300 PCCRYPT_OID_INFO ret = NULL;
1302 TRACE("(%d, %p, %d)\n", dwKeyType, pvKey, dwGroupId);
1304 switch(dwKeyType)
1306 case CRYPT_OID_INFO_ALGID_KEY:
1308 struct OIDInfo *info;
1310 TRACE("CRYPT_OID_INFO_ALGID_KEY: %d\n", *(DWORD *)pvKey);
1311 EnterCriticalSection(&oidInfoCS);
1312 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1314 if (info->info.u.Algid == *(DWORD *)pvKey &&
1315 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1317 ret = &info->info;
1318 break;
1321 LeaveCriticalSection(&oidInfoCS);
1322 break;
1324 case CRYPT_OID_INFO_NAME_KEY:
1326 struct OIDInfo *info;
1328 TRACE("CRYPT_OID_INFO_NAME_KEY: %s\n", debugstr_w((LPWSTR)pvKey));
1329 EnterCriticalSection(&oidInfoCS);
1330 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1332 if (!lstrcmpW(info->info.pwszName, (LPWSTR)pvKey) &&
1333 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1335 ret = &info->info;
1336 break;
1339 LeaveCriticalSection(&oidInfoCS);
1340 break;
1342 case CRYPT_OID_INFO_OID_KEY:
1344 struct OIDInfo *info;
1345 LPSTR oid = (LPSTR)pvKey;
1347 TRACE("CRYPT_OID_INFO_OID_KEY: %s\n", debugstr_a(oid));
1348 EnterCriticalSection(&oidInfoCS);
1349 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1351 if (!lstrcmpA(info->info.pszOID, oid) &&
1352 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1354 ret = &info->info;
1355 break;
1358 LeaveCriticalSection(&oidInfoCS);
1359 break;
1361 case CRYPT_OID_INFO_SIGN_KEY:
1363 struct OIDInfo *info;
1365 TRACE("CRYPT_OID_INFO_SIGN_KEY: %d\n", *(DWORD *)pvKey);
1366 EnterCriticalSection(&oidInfoCS);
1367 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1369 if (info->info.u.Algid == *(DWORD *)pvKey &&
1370 info->info.ExtraInfo.cbData >= sizeof(DWORD) &&
1371 *(DWORD *)info->info.ExtraInfo.pbData ==
1372 *(DWORD *)((LPBYTE)pvKey + sizeof(DWORD)) &&
1373 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1375 ret = &info->info;
1376 break;
1379 LeaveCriticalSection(&oidInfoCS);
1380 break;
1383 return ret;
1386 LPCSTR WINAPI CertAlgIdToOID(DWORD dwAlgId)
1388 LPCSTR ret;
1389 PCCRYPT_OID_INFO info = CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY,
1390 &dwAlgId, 0);
1392 if (info)
1393 ret = info->pszOID;
1394 else
1395 ret = NULL;
1396 return ret;
1399 DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId)
1401 DWORD ret;
1402 PCCRYPT_OID_INFO info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY,
1403 (void *)pszObjId, 0);
1405 if (info)
1406 ret = info->u.Algid;
1407 else
1408 ret = 0;
1409 return ret;