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
21 #define NONAMELESSUNION
27 #include "wine/debug.h"
28 #include "wine/list.h"
29 #include "crypt32_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
34 static const WCHAR DllW[] = { 'D','l','l',0 };
36 static void init_function_sets(void);
37 static void init_oid_info(HINSTANCE hinst);
38 static void free_function_sets(void);
39 static void free_oid_info(void);
41 void crypt_oid_init(HINSTANCE hinst)
47 void crypt_oid_free(void)
53 static CRITICAL_SECTION funcSetCS;
54 static struct list funcSets;
59 CRITICAL_SECTION cs; /* protects functions */
60 struct list functions;
67 CRYPT_OID_FUNC_ENTRY entry;
71 static void init_function_sets(void)
73 InitializeCriticalSection(&funcSetCS);
77 static void free_function_sets(void)
79 struct OIDFunctionSet *setCursor, *setNext;
81 LIST_FOR_EACH_ENTRY_SAFE(setCursor, setNext, &funcSets,
82 struct OIDFunctionSet, next)
84 struct OIDFunction *functionCursor, *funcNext;
86 list_remove(&setCursor->next);
87 CryptMemFree(setCursor->name);
88 LIST_FOR_EACH_ENTRY_SAFE(functionCursor, funcNext,
89 &setCursor->functions, struct OIDFunction, next)
91 list_remove(&functionCursor->next);
92 CryptMemFree(functionCursor);
94 DeleteCriticalSection(&setCursor->cs);
95 CryptMemFree(setCursor);
97 DeleteCriticalSection(&funcSetCS);
100 /* There is no free function associated with this; therefore, the sets are
101 * freed when crypt32.dll is unloaded.
103 HCRYPTOIDFUNCSET WINAPI CryptInitOIDFunctionSet(LPCSTR pszFuncName,
106 struct OIDFunctionSet *cursor, *ret = NULL;
108 TRACE("(%s, %lx)\n", debugstr_a(pszFuncName), dwFlags);
110 EnterCriticalSection(&funcSetCS);
111 LIST_FOR_EACH_ENTRY(cursor, &funcSets, struct OIDFunctionSet, next)
113 if (!strcasecmp(pszFuncName, cursor->name))
115 ret = (HCRYPTOIDFUNCSET)cursor;
121 ret = CryptMemAlloc(sizeof(struct OIDFunctionSet));
124 memset(ret, 0, sizeof(*ret));
125 ret->name = CryptMemAlloc(strlen(pszFuncName) + 1);
128 InitializeCriticalSection(&ret->cs);
129 list_init(&ret->functions);
130 strcpy(ret->name, pszFuncName);
131 list_add_tail(&funcSets, &ret->next);
140 LeaveCriticalSection(&funcSetCS);
142 return (HCRYPTOIDFUNCSET)ret;
145 static char *CRYPT_GetKeyName(DWORD dwEncodingType, LPCSTR pszFuncName,
148 static const char szEncodingTypeFmt[] =
149 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %ld\\%s\\%s";
151 char numericOID[7]; /* enough for "#65535" */
155 /* MSDN says the encoding type is a mask, but it isn't treated that way.
156 * (E.g., if dwEncodingType were 3, the key names "EncodingType 1" and
157 * "EncodingType 2" would be expected if it were a mask. Instead native
158 * stores values in "EncodingType 3".
162 snprintf(numericOID, sizeof(numericOID), "#%d", LOWORD(pszOID));
168 /* This is enough: the lengths of the two string parameters are explicitly
169 * counted, and we need up to five additional characters for the encoding
170 * type. These are covered by the "%d", "%s", and "%s" characters in the
171 * format specifier that are removed by sprintf.
173 len = sizeof(szEncodingTypeFmt) + lstrlenA(pszFuncName) + lstrlenA(oid);
174 szKey = CryptMemAlloc(len);
176 sprintf(szKey, szEncodingTypeFmt, dwEncodingType, pszFuncName, oid);
180 BOOL WINAPI CryptGetDefaultOIDDllList(HCRYPTOIDFUNCSET hFuncSet,
181 DWORD dwEncodingType, LPWSTR pwszDllList, DWORD *pcchDllList)
184 struct OIDFunctionSet *set = (struct OIDFunctionSet *)hFuncSet;
189 TRACE("(%p, %ld, %p, %p)\n", hFuncSet, dwEncodingType, pwszDllList,
192 keyName = CRYPT_GetKeyName(dwEncodingType, set->name, "DEFAULT");
193 rc = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, NULL, 0,
194 KEY_READ, NULL, &key, NULL);
197 DWORD size = *pcchDllList * sizeof(WCHAR);
199 rc = RegQueryValueExW(key, DllW, NULL, NULL, (LPBYTE)pwszDllList,
202 *pcchDllList = size / sizeof(WCHAR);
205 /* No value, return an empty list */
217 CryptMemFree(keyName);
222 BOOL WINAPI CryptInstallOIDFunctionAddress(HMODULE hModule,
223 DWORD dwEncodingType, LPCSTR pszFuncName, DWORD cFuncEntry,
224 const CRYPT_OID_FUNC_ENTRY rgFuncEntry[], DWORD dwFlags)
227 struct OIDFunctionSet *set;
229 TRACE("(%p, %ld, %s, %ld, %p, %08lx)\n", hModule, dwEncodingType,
230 debugstr_a(pszFuncName), cFuncEntry, rgFuncEntry, dwFlags);
232 set = (struct OIDFunctionSet *)CryptInitOIDFunctionSet(pszFuncName, 0);
237 EnterCriticalSection(&set->cs);
238 for (i = 0; ret && i < cFuncEntry; i++)
240 struct OIDFunction *func;
242 if (HIWORD(rgFuncEntry[i].pszOID))
243 func = CryptMemAlloc(sizeof(struct OIDFunction)
244 + strlen(rgFuncEntry[i].pszOID) + 1);
246 func = CryptMemAlloc(sizeof(struct OIDFunction));
249 func->encoding = dwEncodingType;
250 if (HIWORD(rgFuncEntry[i].pszOID))
252 func->entry.pszOID = (LPSTR)((LPBYTE)func + sizeof(*func));
253 strcpy((LPSTR)func->entry.pszOID, rgFuncEntry[i].pszOID);
256 func->entry.pszOID = rgFuncEntry[i].pszOID;
257 func->entry.pvFuncAddr = rgFuncEntry[i].pvFuncAddr;
258 list_add_tail(&set->functions, &func->next);
263 LeaveCriticalSection(&set->cs);
270 static BOOL CRYPT_GetFuncFromReg(DWORD dwEncodingType, LPCSTR pszOID,
271 LPCSTR szFuncName, LPVOID *ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
275 const char *funcName;
279 keyName = CRYPT_GetKeyName(dwEncodingType, szFuncName, pszOID);
280 rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &key);
283 DWORD type, size = 0;
285 rc = RegQueryValueExA(key, "FuncName", NULL, &type, NULL, &size);
286 if (rc == ERROR_MORE_DATA && type == REG_SZ)
288 funcName = CryptMemAlloc(size);
289 rc = RegQueryValueExA(key, "FuncName", NULL, &type,
290 (LPBYTE)funcName, &size);
293 funcName = szFuncName;
294 rc = RegQueryValueExW(key, DllW, NULL, &type, NULL, &size);
295 if (rc == ERROR_MORE_DATA && type == REG_SZ)
297 LPWSTR dllName = CryptMemAlloc(size);
301 rc = RegQueryValueExW(key, DllW, NULL, NULL,
302 (LPBYTE)dllName, &size);
307 /* This is a bit of a hack; MSDN describes a more
308 * complicated unload routine than this will allow.
309 * Still, this seems to suffice for now.
311 lib = LoadLibraryW(dllName);
314 *ppvFuncAddr = GetProcAddress(lib, szFuncName);
317 *phFuncAddr = (HCRYPTOIDFUNCADDR)lib;
322 /* Unload the library, the caller doesn't want
323 * to unload it when the return value is NULL.
331 CryptMemFree(dllName);
336 if (funcName != szFuncName)
337 CryptMemFree((char *)funcName);
342 CryptMemFree(keyName);
346 BOOL WINAPI CryptGetOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet,
347 DWORD dwEncodingType, LPCSTR pszOID, DWORD dwFlags, void **ppvFuncAddr,
348 HCRYPTOIDFUNCADDR *phFuncAddr)
351 struct OIDFunctionSet *set = (struct OIDFunctionSet *)hFuncSet;
353 TRACE("(%p, %ld, %s, %08lx, %p, %p)\n", hFuncSet, dwEncodingType,
354 debugstr_a(pszOID), dwFlags, ppvFuncAddr, phFuncAddr);
357 if (!(dwFlags & CRYPT_GET_INSTALLED_OID_FUNC_FLAG))
359 struct OIDFunction *function;
361 EnterCriticalSection(&set->cs);
362 LIST_FOR_EACH_ENTRY(function, &set->functions, struct OIDFunction, next)
364 if (function->encoding == dwEncodingType)
368 if (HIWORD(function->entry.pszOID) &&
369 !strcasecmp(function->entry.pszOID, pszOID))
371 *ppvFuncAddr = function->entry.pvFuncAddr;
372 *phFuncAddr = NULL; /* FIXME: what should it be? */
377 else if (function->entry.pszOID == pszOID)
379 *ppvFuncAddr = function->entry.pvFuncAddr;
380 *phFuncAddr = NULL; /* FIXME: what should it be? */
386 LeaveCriticalSection(&set->cs);
389 ret = CRYPT_GetFuncFromReg(dwEncodingType, pszOID, set->name,
390 ppvFuncAddr, phFuncAddr);
394 BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr,
397 TRACE("(%p, %08lx)\n", hFuncAddr, dwFlags);
399 /* FIXME: as MSDN states, need to check for DllCanUnloadNow in the DLL,
400 * and only unload it if it can be unloaded. Also need to implement ref
401 * counting on the functions.
403 FreeLibrary((HMODULE)hFuncAddr);
407 BOOL WINAPI CryptGetDefaultOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet,
408 DWORD dwEncodingType, LPCWSTR pwszDll, DWORD dwFlags, void *ppvFuncAddr,
409 HCRYPTOIDFUNCADDR *phFuncAddr)
411 FIXME("(%p, %ld, %s, %08lx, %p, %p): stub\n", hFuncSet, dwEncodingType,
412 debugstr_w(pwszDll), dwFlags, ppvFuncAddr, phFuncAddr);
416 BOOL WINAPI CryptRegisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
417 LPCSTR pszOID, LPCWSTR pwszDll, LPCSTR pszOverrideFuncName)
423 TRACE("(%lx, %s, %s, %s, %s)\n", dwEncodingType, pszFuncName, pszOID,
424 debugstr_w(pwszDll), pszOverrideFuncName);
426 /* This only registers functions for encoding certs, not messages */
427 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
430 /* Native does nothing pwszDll is NULL */
434 /* I'm not matching MS bug for bug here, because I doubt any app depends on
435 * it: native "succeeds" if pszFuncName is NULL, but the nonsensical entry
436 * it creates would never be used.
438 if (!pszFuncName || !pszOID)
440 SetLastError(E_INVALIDARG);
444 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
445 TRACE("Key name is %s\n", debugstr_a(szKey));
450 r = RegCreateKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
452 if(r != ERROR_SUCCESS)
455 /* write the values */
456 if (pszOverrideFuncName)
457 RegSetValueExA(hKey, "FuncName", 0, REG_SZ,
458 (const BYTE*)pszOverrideFuncName, lstrlenA(pszOverrideFuncName) + 1);
459 RegSetValueExW(hKey, DllW, 0, REG_SZ, (const BYTE*) pwszDll,
460 (lstrlenW(pwszDll) + 1) * sizeof (WCHAR));
466 BOOL WINAPI CryptUnregisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
472 TRACE("%lx %s %s\n", dwEncodingType, pszFuncName, pszOID);
474 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
477 if (!pszFuncName || !pszOID)
479 SetLastError(ERROR_INVALID_PARAMETER);
483 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
484 rc = RegDeleteKeyA(HKEY_LOCAL_MACHINE, szKey);
488 return rc ? FALSE : TRUE;
491 BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
492 LPCSTR pszOID, LPCWSTR pwszValueName, DWORD *pdwValueType, BYTE *pbValueData,
499 TRACE("%lx %s %s %s %p %p %p\n", dwEncodingType, debugstr_a(pszFuncName),
500 debugstr_a(pszOID), debugstr_w(pwszValueName), pdwValueType, pbValueData,
503 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
506 if (!pszFuncName || !pszOID || !pwszValueName)
508 SetLastError(ERROR_INVALID_PARAMETER);
512 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
513 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
519 rc = RegQueryValueExW(hKey, pwszValueName, NULL, pdwValueType,
520 pbValueData, pcbValueData);
525 return rc ? FALSE : TRUE;
528 BOOL WINAPI CryptSetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
529 LPCSTR pszOID, LPCWSTR pwszValueName, DWORD dwValueType,
530 const BYTE *pbValueData, DWORD cbValueData)
536 TRACE("%lx %s %s %s %ld %p %ld\n", dwEncodingType, debugstr_a(pszFuncName),
537 debugstr_a(pszOID), debugstr_w(pwszValueName), dwValueType, pbValueData,
540 if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
543 if (!pszFuncName || !pszOID || !pwszValueName)
545 SetLastError(ERROR_INVALID_PARAMETER);
549 szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
550 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
556 rc = RegSetValueExW(hKey, pwszValueName, 0, dwValueType, pbValueData,
562 return rc ? FALSE : TRUE;
565 static LPCWSTR CRYPT_FindStringInMultiString(LPCWSTR multi, LPCWSTR toFind)
567 LPCWSTR ret = NULL, ptr;
569 for (ptr = multi; ptr && *ptr && !ret; ptr += lstrlenW(ptr) + 1)
571 if (!lstrcmpiW(ptr, toFind))
577 static DWORD CRYPT_GetMultiStringCharacterLen(LPCWSTR multi)
585 /* Count terminating empty string */
587 for (ptr = multi; *ptr; ptr += lstrlenW(ptr) + 1)
588 ret += lstrlenW(ptr) + 1;
595 static LPWSTR CRYPT_AddStringToMultiString(LPWSTR multi, LPCWSTR toAdd,
602 /* FIXME: ignoring index, is that okay? */
603 ret = CryptMemAlloc((lstrlenW(toAdd) + 2) * sizeof(WCHAR));
606 /* copy string, including NULL terminator */
607 memcpy(ret, toAdd, (lstrlenW(toAdd) + 1) * sizeof(WCHAR));
608 /* add terminating empty string */
609 *(ret + lstrlenW(toAdd) + 1) = 0;
614 DWORD len = CRYPT_GetMultiStringCharacterLen(multi);
616 ret = CryptMemRealloc(multi, (len + lstrlenW(toAdd) + 1) *
622 if (index == CRYPT_REGISTER_LAST_INDEX)
623 spotToAdd = ret + len - 1;
628 /* FIXME: if index is too large for the string, toAdd is
629 * added to the end. Is that okay?
631 for (i = 0, spotToAdd = ret; i < index && *spotToAdd;
632 spotToAdd += lstrlenW(spotToAdd) + 1)
637 /* Copy existing string "right" */
638 memmove(spotToAdd + lstrlenW(toAdd) + 1, spotToAdd,
639 (len - (spotToAdd - ret)) * sizeof(WCHAR));
640 /* Copy new string */
641 memcpy(spotToAdd, toAdd, (lstrlenW(toAdd) + 1) * sizeof(WCHAR));
653 static BOOL CRYPT_RemoveStringFromMultiString(LPWSTR multi, LPCWSTR toRemove)
655 LPWSTR spotToRemove = (LPWSTR)CRYPT_FindStringInMultiString(multi,
661 DWORD len = CRYPT_GetMultiStringCharacterLen(multi);
663 /* Copy remainder of string "left" */
664 memmove(spotToRemove, spotToRemove + lstrlenW(toRemove) + 1,
665 (len - (spotToRemove - multi)) * sizeof(WCHAR));
670 SetLastError(ERROR_FILE_NOT_FOUND);
676 static BOOL CRYPT_GetDefaultOIDKey(DWORD dwEncodingType, LPCSTR pszFuncName,
682 keyName = CRYPT_GetKeyName(dwEncodingType, pszFuncName, "DEFAULT");
683 TRACE("Key name is %s\n", debugstr_a(keyName));
688 r = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, NULL, 0, KEY_ALL_ACCESS,
690 CryptMemFree(keyName);
691 if (r != ERROR_SUCCESS)
699 static LPWSTR CRYPT_GetDefaultOIDDlls(HKEY key)
705 r = RegQueryValueExW(key, DllW, NULL, &type, NULL, &size);
706 if (r == ERROR_SUCCESS && type == REG_MULTI_SZ)
708 dlls = CryptMemAlloc(size);
709 r = RegQueryValueExW(key, DllW, NULL, &type, (LPBYTE)dlls, &size);
710 if (r != ERROR_SUCCESS)
721 static inline BOOL CRYPT_SetDefaultOIDDlls(HKEY key, LPCWSTR dlls)
723 DWORD len = CRYPT_GetMultiStringCharacterLen(dlls);
726 if ((r = RegSetValueExW(key, DllW, 0, REG_MULTI_SZ, (const BYTE *)dlls,
727 len * sizeof (WCHAR))))
729 return r == ERROR_SUCCESS;
732 BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType,
733 LPCSTR pszFuncName, DWORD dwIndex, LPCWSTR pwszDll)
740 TRACE("(%lx, %s, %lx, %s)\n", dwEncodingType, pszFuncName, dwIndex,
741 debugstr_w(pwszDll));
745 SetLastError(E_INVALIDARG);
749 if (!CRYPT_GetDefaultOIDKey(dwEncodingType, pszFuncName, &key))
752 dlls = CRYPT_GetDefaultOIDDlls(key);
753 if ((existing = CRYPT_FindStringInMultiString(dlls, pwszDll)))
754 SetLastError(ERROR_FILE_EXISTS);
757 dlls = CRYPT_AddStringToMultiString(dlls, pwszDll, dwIndex);
759 ret = CRYPT_SetDefaultOIDDlls(key, dlls);
766 BOOL WINAPI CryptUnregisterDefaultOIDFunction(DWORD dwEncodingType,
767 LPCSTR pszFuncName, LPCWSTR pwszDll)
773 TRACE("(%lx, %s, %s)\n", dwEncodingType, debugstr_a(pszFuncName),
774 debugstr_w(pwszDll));
778 SetLastError(E_INVALIDARG);
782 if (!CRYPT_GetDefaultOIDKey(dwEncodingType, pszFuncName, &key))
785 dlls = CRYPT_GetDefaultOIDDlls(key);
786 if ((ret = CRYPT_RemoveStringFromMultiString(dlls, pwszDll)))
787 ret = CRYPT_SetDefaultOIDDlls(key, dlls);
793 static CRITICAL_SECTION oidInfoCS;
794 static struct list oidInfo;
796 static const WCHAR tripledes[] = { '3','d','e','s',0 };
797 static const WCHAR cms3deswrap[] = { 'C','M','S','3','D','E','S','w','r','a',
799 static const WCHAR cmsrc2wrap[] = { 'C','M','S','R','C','2','w','r','a','p',0 };
800 static const WCHAR des[] = { 'd','e','s',0 };
801 static const WCHAR md2[] = { 'm','d','2',0 };
802 static const WCHAR md4[] = { 'm','d','4',0 };
803 static const WCHAR md5[] = { 'm','d','5',0 };
804 static const WCHAR rc2[] = { 'r','c','2',0 };
805 static const WCHAR rc4[] = { 'r','c','4',0 };
806 static const WCHAR sha[] = { 's','h','a',0 };
807 static const WCHAR sha1[] = { 's','h','a','1',0 };
808 static const WCHAR RSA[] = { 'R','S','A',0 };
809 static const WCHAR RSA_KEYX[] = { 'R','S','A','_','K','E','Y','X',0 };
810 static const WCHAR RSA_SIGN[] = { 'R','S','A','_','S','I','G','N',0 };
811 static const WCHAR DSA[] = { 'D','S','A',0 };
812 static const WCHAR DSA_SIGN[] = { 'D','S','A','_','S','I','G','N',0 };
813 static const WCHAR DH[] = { 'D','H',0 };
814 static const WCHAR DSS[] = { 'D','S','S',0 };
815 static const WCHAR mosaicKMandUpdSig[] =
816 { 'm','o','s','a','i','c','K','M','a','n','d','U','p','d','S','i','g',0 };
817 static const WCHAR ESDH[] = { 'E','S','D','H',0 };
818 static const WCHAR NO_SIGN[] = { 'N','O','S','I','G','N',0 };
819 static const WCHAR dsaSHA1[] = { 'd','s','a','S','H','A','1',0 };
820 static const WCHAR md2RSA[] = { 'm','d','2','R','S','A',0 };
821 static const WCHAR md4RSA[] = { 'm','d','4','R','S','A',0 };
822 static const WCHAR md5RSA[] = { 'm','d','5','R','S','A',0 };
823 static const WCHAR shaDSA[] = { 's','h','a','D','S','A',0 };
824 static const WCHAR sha1DSA[] = { 's','h','a','1','D','S','A',0 };
825 static const WCHAR shaRSA[] = { 's','h','a','R','S','A',0 };
826 static const WCHAR sha1RSA[] = { 's','h','a','1','R','S','A',0 };
827 static const WCHAR mosaicUpdatedSig[] =
828 { 'm','o','s','a','i','c','U','p','d','a','t','e','d','S','i','g',0 };
829 static const WCHAR CN[] = { 'C','N',0 };
830 static const WCHAR L[] = { 'L',0 };
831 static const WCHAR O[] = { 'O',0 };
832 static const WCHAR OU[] = { 'O','U',0 };
833 static const WCHAR E[] = { 'E',0 };
834 static const WCHAR C[] = { 'C',0 };
835 static const WCHAR S[] = { 'S',0 };
836 static const WCHAR ST[] = { 'S','T',0 };
837 static const WCHAR STREET[] = { 'S','T','R','E','E','T',0 };
838 static const WCHAR T[] = { 'T',0 };
839 static const WCHAR Title[] = { 'T','i','t','l','e',0 };
840 static const WCHAR G[] = { 'G',0 };
841 static const WCHAR GivenName[] = { 'G','i','v','e','n','N','a','m','e',0 };
842 static const WCHAR I[] = { 'I',0 };
843 static const WCHAR Initials[] = { 'I','n','i','t','i','a','l','s',0 };
844 static const WCHAR SN[] = { 'S','N',0 };
845 static const WCHAR DC[] = { 'D','C',0 };
846 static const WCHAR Description[] =
847 { 'D','e','s','c','r','i','p','t','i','o','n',0 };
848 static const WCHAR PostalCode[] = { 'P','o','s','t','a','l','C','o','d','e',0 };
849 static const WCHAR POBox[] = { 'P','O','B','o','x',0 };
850 static const WCHAR Phone[] = { 'P','h','o','n','e',0 };
851 static const WCHAR X21Address[] = { 'X','2','1','A','d','d','r','e','s','s',0 };
852 static const WCHAR dnQualifier[] =
853 { 'd','n','Q','u','a','l','i','f','i','e','r',0 };
854 static const WCHAR Email[] = { 'E','m','a','i','l',0 };
855 static const WCHAR GN[] = { 'G','N',0 };
857 static const DWORD noNullFlag = CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG;
858 static const DWORD mosaicFlags = CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG |
859 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG;
860 static const CRYPT_DATA_BLOB noNullBlob = { sizeof(noNullFlag),
861 (LPBYTE)&noNullFlag };
862 static const CRYPT_DATA_BLOB mosaicFlagsBlob = { sizeof(mosaicFlags),
863 (LPBYTE)&mosaicFlags };
865 static const DWORD rsaSign = CALG_RSA_SIGN;
866 static const DWORD dssSign[2] = { CALG_DSS_SIGN,
867 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG };
868 static const DWORD mosaicSign[2] = { CALG_DSS_SIGN,
869 CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG |
870 CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG };
871 static const CRYPT_DATA_BLOB rsaSignBlob = { sizeof(rsaSign),
873 static const CRYPT_DATA_BLOB dssSignBlob = { sizeof(dssSign),
875 static const CRYPT_DATA_BLOB mosaicSignBlob = { sizeof(mosaicSign),
876 (LPBYTE)mosaicSign };
878 static const DWORD ia5String[] = { CERT_RDN_IA5_STRING, 0 };
879 static const DWORD numericString[] = { CERT_RDN_NUMERIC_STRING, 0 };
880 static const DWORD printableString[] = { CERT_RDN_PRINTABLE_STRING, 0 };
881 static const DWORD domainCompTypes[] = { CERT_RDN_IA5_STRING,
882 CERT_RDN_UTF8_STRING, 0 };
883 static const CRYPT_DATA_BLOB ia5StringBlob = { sizeof(ia5String),
885 static const CRYPT_DATA_BLOB numericStringBlob = { sizeof(numericString),
886 (LPBYTE)numericString };
887 static const CRYPT_DATA_BLOB printableStringBlob = { sizeof(printableString),
888 (LPBYTE)printableString };
889 static const CRYPT_DATA_BLOB domainCompTypesBlob = { sizeof(domainCompTypes),
890 (LPBYTE)domainCompTypes };
892 static const struct OIDInfoConstructor {
897 const CRYPT_DATA_BLOB *blob;
898 } oidInfoConstructors[] = {
899 { 1, szOID_OIWSEC_sha1, CALG_SHA1, sha1, NULL },
900 { 1, szOID_OIWSEC_sha1, CALG_SHA1, sha, NULL },
901 { 1, szOID_OIWSEC_sha, CALG_SHA, sha, NULL },
902 { 1, szOID_RSA_MD5, CALG_MD5, md5, NULL },
903 { 1, szOID_RSA_MD4, CALG_MD4, md4, NULL },
904 { 1, szOID_RSA_MD2, CALG_MD2, md2, NULL },
906 { 2, szOID_OIWSEC_desCBC, CALG_DES, des, NULL },
907 { 2, szOID_RSA_DES_EDE3_CBC, CALG_3DES, tripledes, NULL },
908 { 2, szOID_RSA_RC2CBC, CALG_RC2, rc2, NULL },
909 { 2, szOID_RSA_RC4, CALG_RC4, rc4, NULL },
910 { 2, szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES, cms3deswrap, NULL },
911 { 2, szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2, cmsrc2wrap, NULL },
913 { 3, szOID_RSA_RSA, CALG_RSA_KEYX, RSA, NULL },
914 { 3, szOID_X957_DSA, CALG_DSS_SIGN, DSA, &noNullBlob },
915 { 3, szOID_ANSI_X942_DH, CALG_DH_SF, DH, &noNullBlob },
916 { 3, szOID_RSA_RSA, CALG_RSA_KEYX, RSA_KEYX, NULL },
917 { 3, szOID_RSA_RSA, CALG_RSA_SIGN, RSA, NULL },
918 { 3, szOID_RSA_RSA, CALG_RSA_SIGN, RSA_SIGN, NULL },
919 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSA, &noNullBlob },
920 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSS, &noNullBlob },
921 { 3, szOID_OIWSEC_dsa, CALG_DSS_SIGN, DSA_SIGN, &noNullBlob },
922 { 3, szOID_RSA_DH, CALG_DH_SF, DH, &noNullBlob },
923 { 3, szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX, RSA_KEYX, NULL },
924 { 3, szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN, mosaicKMandUpdSig,
926 { 3, szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM, ESDH, &noNullBlob },
927 { 3, szOID_PKIX_NO_SIGNATURE, CALG_NO_SIGN, NO_SIGN, NULL },
929 { 4, szOID_RSA_SHA1RSA, CALG_SHA1, sha1RSA, &rsaSignBlob },
930 { 4, szOID_RSA_MD5RSA, CALG_MD5, md5RSA, &rsaSignBlob },
931 { 4, szOID_X957_SHA1DSA, CALG_SHA1, sha1DSA, &dssSignBlob },
932 { 4, szOID_OIWSEC_sha1RSASign, CALG_SHA1, sha1RSA, &rsaSignBlob },
933 { 4, szOID_OIWSEC_sha1RSASign, CALG_SHA1, shaRSA, &rsaSignBlob },
934 { 4, szOID_OIWSEC_shaRSA, CALG_SHA1, shaRSA, &rsaSignBlob },
935 { 4, szOID_OIWSEC_md5RSA, CALG_MD5, md5RSA, &rsaSignBlob },
936 { 4, szOID_RSA_MD2RSA, CALG_MD2, md2RSA, &rsaSignBlob },
937 { 4, szOID_RSA_MD4RSA, CALG_MD4, md4RSA, &rsaSignBlob },
938 { 4, szOID_OIWSEC_md4RSA, CALG_MD4, md4RSA, &rsaSignBlob },
939 { 4, szOID_OIWSEC_md4RSA2, CALG_MD4, md4RSA, &rsaSignBlob },
940 { 4, szOID_OIWDIR_md2RSA, CALG_MD2, md2RSA, &rsaSignBlob },
941 { 4, szOID_OIWSEC_shaDSA, CALG_SHA1, sha1DSA, &dssSignBlob },
942 { 4, szOID_OIWSEC_shaDSA, CALG_SHA1, shaDSA, &dssSignBlob },
943 { 4, szOID_OIWSEC_dsaSHA1, CALG_SHA1, dsaSHA1, &dssSignBlob },
944 { 4, szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA1, mosaicUpdatedSig,
947 { 5, szOID_COMMON_NAME, 0, CN, NULL },
948 { 5, szOID_LOCALITY_NAME, 0, L, NULL },
949 { 5, szOID_ORGANIZATION_NAME, 0, O, NULL },
950 { 5, szOID_ORGANIZATIONAL_UNIT_NAME, 0, OU, NULL },
951 { 5, szOID_RSA_emailAddr, 0, E, &ia5StringBlob },
952 { 5, szOID_RSA_emailAddr, 0, Email, &ia5StringBlob },
953 { 5, szOID_COUNTRY_NAME, 0, C, &printableStringBlob },
954 { 5, szOID_STATE_OR_PROVINCE_NAME, 0, S, NULL },
955 { 5, szOID_STATE_OR_PROVINCE_NAME, 0, ST, NULL },
956 { 5, szOID_STREET_ADDRESS, 0, STREET, NULL },
957 { 5, szOID_TITLE, 0, T, NULL },
958 { 5, szOID_TITLE, 0, Title, NULL },
959 { 5, szOID_GIVEN_NAME, 0, G, NULL },
960 { 5, szOID_GIVEN_NAME, 0, GN, NULL },
961 { 5, szOID_GIVEN_NAME, 0, GivenName, NULL },
962 { 5, szOID_INITIALS, 0, I, NULL },
963 { 5, szOID_INITIALS, 0, Initials, NULL },
964 { 5, szOID_SUR_NAME, 0, SN, NULL },
965 { 5, szOID_DOMAIN_COMPONENT, 0, DC, &domainCompTypesBlob },
966 { 5, szOID_DESCRIPTION, 0, Description, NULL },
967 { 5, szOID_POSTAL_CODE, 0, PostalCode, NULL },
968 { 5, szOID_POST_OFFICE_BOX, 0, POBox, NULL },
969 { 5, szOID_TELEPHONE_NUMBER, 0, Phone, &printableStringBlob },
970 { 5, szOID_X21_ADDRESS, 0, X21Address, &numericStringBlob },
971 { 5, szOID_DN_QUALIFIER, 0, dnQualifier, NULL },
973 { 6, szOID_AUTHORITY_KEY_IDENTIFIER2, 0, (LPCWSTR)IDS_AUTHORITY_KEY_ID, NULL },
974 { 6, szOID_AUTHORITY_KEY_IDENTIFIER, 0, (LPCWSTR)IDS_AUTHORITY_KEY_ID, NULL },
975 { 6, szOID_KEY_ATTRIBUTES, 0, (LPCWSTR)IDS_KEY_ATTRIBUTES, NULL },
976 { 6, szOID_KEY_USAGE_RESTRICTION, 0, (LPCWSTR)IDS_KEY_USAGE_RESTRICTION, NULL },
977 { 6, szOID_SUBJECT_ALT_NAME2, 0, (LPCWSTR)IDS_SUBJECT_ALT_NAME, NULL },
978 { 6, szOID_SUBJECT_ALT_NAME, 0, (LPCWSTR)IDS_SUBJECT_ALT_NAME, NULL },
979 { 6, szOID_ISSUER_ALT_NAME2, 0, (LPCWSTR)IDS_ISSUER_ALT_NAME, NULL },
980 { 6, szOID_ISSUER_ALT_NAME2, 0, (LPCWSTR)IDS_ISSUER_ALT_NAME, NULL },
981 { 6, szOID_BASIC_CONSTRAINTS2, 0, (LPCWSTR)IDS_BASIC_CONSTRAINTS, NULL },
982 { 6, szOID_BASIC_CONSTRAINTS, 0, (LPCWSTR)IDS_BASIC_CONSTRAINTS, NULL },
983 { 6, szOID_KEY_USAGE, 0, (LPCWSTR)IDS_KEY_USAGE, NULL },
984 { 6, szOID_CERT_POLICIES, 0, (LPCWSTR)IDS_CERT_POLICIES, NULL },
985 { 6, szOID_SUBJECT_KEY_IDENTIFIER, 0, (LPCWSTR)IDS_SUBJECT_KEY_IDENTIFIER, NULL },
986 { 6, szOID_CRL_REASON_CODE, 0, (LPCWSTR)IDS_CRL_REASON_CODE, NULL },
987 { 6, szOID_CRL_DIST_POINTS, 0, (LPCWSTR)IDS_CRL_DIST_POINTS, NULL },
988 { 6, szOID_ENHANCED_KEY_USAGE, 0, (LPCWSTR)IDS_ENHANCED_KEY_USAGE, NULL },
989 { 6, szOID_AUTHORITY_INFO_ACCESS, 0, (LPCWSTR)IDS_AUTHORITY_INFO_ACCESS, NULL },
990 { 6, szOID_CERT_EXTENSIONS, 0, (LPCWSTR)IDS_CERT_EXTENSIONS, NULL },
991 { 6, szOID_RSA_certExtensions, 0, (LPCWSTR)IDS_CERT_EXTENSIONS, NULL },
992 { 6, szOID_NEXT_UPDATE_LOCATION, 0, (LPCWSTR)IDS_NEXT_UPDATE_LOCATION, NULL },
993 { 6, szOID_YESNO_TRUST_ATTR, 0, (LPCWSTR)IDS_YES_OR_NO_TRUST, NULL },
994 { 6, szOID_RSA_emailAddr, 0, (LPCWSTR)IDS_EMAIL_ADDRESS, NULL },
995 { 6, szOID_RSA_unstructName, 0, (LPCWSTR)IDS_UNSTRUCTURED_NAME, NULL },
996 { 6, szOID_RSA_contentType, 0, (LPCWSTR)IDS_CONTENT_TYPE, NULL },
997 { 6, szOID_RSA_messageDigest, 0, (LPCWSTR)IDS_MESSAGE_DIGEST, NULL },
998 { 6, szOID_RSA_signingTime, 0, (LPCWSTR)IDS_SIGNING_TIME, NULL },
999 { 6, szOID_RSA_counterSign, 0, (LPCWSTR)IDS_COUNTER_SIGN, NULL },
1000 { 6, szOID_RSA_challengePwd, 0, (LPCWSTR)IDS_CHALLENGE_PASSWORD, NULL },
1001 { 6, szOID_RSA_unstructAddr, 0, (LPCWSTR)IDS_UNSTRUCTURED_ADDRESS, NULL },
1002 { 6, szOID_RSA_SMIMECapabilities, 0, (LPCWSTR)IDS_SMIME_CAPABILITIES, NULL },
1003 { 6, szOID_RSA_preferSignedData, 0, (LPCWSTR)IDS_PREFER_SIGNED_DATA, NULL },
1004 { 6, szOID_PKIX_POLICY_QUALIFIER_CPS, 0, (LPCWSTR)IDS_CPS, NULL },
1005 { 6, szOID_PKIX_POLICY_QUALIFIER_USERNOTICE, 0, (LPCWSTR)IDS_USER_NOTICE, NULL },
1006 { 6, szOID_PKIX_OCSP, 0, (LPCWSTR)IDS_OCSP, NULL },
1007 { 6, szOID_PKIX_CA_ISSUERS, 0, (LPCWSTR)IDS_CA_ISSUER, NULL },
1008 { 6, szOID_ENROLL_CERTTYPE_EXTENSION, 0, (LPCWSTR)IDS_CERT_TEMPLATE_NAME, NULL },
1009 { 6, szOID_ENROLL_CERTTYPE_EXTENSION, 0, (LPCWSTR)IDS_CERT_TYPE, NULL },
1010 { 6, szOID_CERT_MANIFOLD, 0, (LPCWSTR)IDS_CERT_MANIFOLD, NULL },
1011 { 6, szOID_NETSCAPE_CERT_TYPE, 0, (LPCWSTR)IDS_NETSCAPE_CERT_TYPE, NULL },
1012 { 6, szOID_NETSCAPE_BASE_URL, 0, (LPCWSTR)IDS_NETSCAPE_BASE_URL, NULL },
1013 { 6, szOID_NETSCAPE_REVOCATION_URL, 0, (LPCWSTR)IDS_NETSCAPE_REVOCATION_URL, NULL },
1014 { 6, szOID_NETSCAPE_CA_REVOCATION_URL, 0, (LPCWSTR)IDS_NETSCAPE_CA_REVOCATION_URL, NULL },
1015 { 6, szOID_NETSCAPE_CERT_RENEWAL_URL, 0, (LPCWSTR)IDS_NETSCAPE_CERT_RENEWAL_URL, NULL },
1016 { 6, szOID_NETSCAPE_CA_POLICY_URL, 0, (LPCWSTR)IDS_NETSCAPE_CA_POLICY_URL, NULL },
1017 { 6, szOID_NETSCAPE_SSL_SERVER_NAME, 0, (LPCWSTR)IDS_NETSCAPE_SSL_SERVER_NAME, NULL },
1018 { 6, szOID_NETSCAPE_COMMENT, 0, (LPCWSTR)IDS_NETSCAPE_COMMENT, NULL },
1019 { 6, "1.3.6.1.4.1.311.2.1.10", 0, (LPCWSTR)IDS_SPC_SP_AGENCY_INFO, NULL },
1020 { 6, "1.3.6.1.4.1.311.2.1.27", 0, (LPCWSTR)IDS_SPC_FINANCIAL_CRITERIA, NULL },
1021 { 6, "1.3.6.1.4.1.311.2.1.26", 0, (LPCWSTR)IDS_SPC_MINIMAL_CRITERIA, NULL },
1022 { 6, szOID_COUNTRY_NAME, 0, (LPCWSTR)IDS_COUNTRY, NULL },
1023 { 6, szOID_ORGANIZATION_NAME, 0, (LPCWSTR)IDS_ORGANIZATION, NULL },
1024 { 6, szOID_ORGANIZATIONAL_UNIT_NAME, 0, (LPCWSTR)IDS_ORGANIZATIONAL_UNIT, NULL },
1025 { 6, szOID_COMMON_NAME, 0, (LPCWSTR)IDS_COMMON_NAME, NULL },
1026 { 6, szOID_LOCALITY_NAME, 0, (LPCWSTR)IDS_LOCALITY, NULL },
1027 { 6, szOID_STATE_OR_PROVINCE_NAME, 0, (LPCWSTR)IDS_STATE_OR_PROVINCE, NULL },
1028 { 6, szOID_TITLE, 0, (LPCWSTR)IDS_TITLE, NULL },
1029 { 6, szOID_GIVEN_NAME, 0, (LPCWSTR)IDS_GIVEN_NAME, NULL },
1030 { 6, szOID_INITIALS, 0, (LPCWSTR)IDS_INITIALS, NULL },
1031 { 6, szOID_SUR_NAME, 0, (LPCWSTR)IDS_SUR_NAME, NULL },
1032 { 6, szOID_DOMAIN_COMPONENT, 0, (LPCWSTR)IDS_DOMAIN_COMPONENT, NULL },
1033 { 6, szOID_STREET_ADDRESS, 0, (LPCWSTR)IDS_STREET_ADDRESS, NULL },
1034 { 6, szOID_DEVICE_SERIAL_NUMBER, 0, (LPCWSTR)IDS_SERIAL_NUMBER, NULL },
1035 { 6, szOID_CERTSRV_CA_VERSION, 0, (LPCWSTR)IDS_CA_VERSION, NULL },
1036 { 6, szOID_CERTSRV_CROSSCA_VERSION, 0, (LPCWSTR)IDS_CROSS_CA_VERSION, NULL },
1037 { 6, szOID_SERIALIZED, 0, (LPCWSTR)IDS_SERIALIZED_SIG_SERIAL_NUMBER, NULL },
1038 { 6, szOID_NT_PRINCIPAL_NAME, 0, (LPCWSTR)IDS_PRINCIPAL_NAME, NULL },
1039 { 6, szOID_PRODUCT_UPDATE, 0, (LPCWSTR)IDS_WINDOWS_PRODUCT_UPDATE, NULL },
1040 { 6, szOID_ENROLLMENT_NAME_VALUE_PAIR, 0, (LPCWSTR)IDS_ENROLLMENT_NAME_VALUE_PAIR, NULL },
1041 { 6, szOID_OS_VERSION, 0, (LPCWSTR)IDS_OS_VERSION, NULL },
1042 { 6, szOID_ENROLLMENT_CSP_PROVIDER, 0, (LPCWSTR)IDS_ENROLLMENT_CSP, NULL },
1043 { 6, szOID_CRL_NUMBER, 0, (LPCWSTR)IDS_CRL_NUMBER, NULL },
1044 { 6, szOID_DELTA_CRL_INDICATOR, 0, (LPCWSTR)IDS_DELTA_CRL_INDICATOR, NULL },
1045 { 6, szOID_ISSUING_DIST_POINT, 0, (LPCWSTR)IDS_ISSUING_DIST_POINT, NULL },
1046 { 6, szOID_FRESHEST_CRL, 0, (LPCWSTR)IDS_FRESHEST_CRL, NULL },
1047 { 6, szOID_NAME_CONSTRAINTS, 0, (LPCWSTR)IDS_NAME_CONSTRAINTS, NULL },
1048 { 6, szOID_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_POLICY_MAPPINGS, NULL },
1049 { 6, szOID_LEGACY_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_POLICY_MAPPINGS, NULL },
1050 { 6, szOID_POLICY_CONSTRAINTS, 0, (LPCWSTR)IDS_POLICY_CONSTRAINTS, NULL },
1051 { 6, szOID_CROSS_CERT_DIST_POINTS, 0, (LPCWSTR)IDS_CROSS_CERT_DIST_POINTS, NULL },
1052 { 6, szOID_APPLICATION_CERT_POLICIES, 0, (LPCWSTR)IDS_APPLICATION_POLICIES, NULL },
1053 { 6, szOID_APPLICATION_POLICY_MAPPINGS, 0, (LPCWSTR)IDS_APPLICATION_POLICY_MAPPINGS, NULL },
1054 { 6, szOID_APPLICATION_POLICY_CONSTRAINTS, 0, (LPCWSTR)IDS_APPLICATION_POLICY_CONSTRAINTS, NULL },
1055 { 6, szOID_CT_PKI_DATA, 0, (LPCWSTR)IDS_CMC_DATA, NULL },
1056 { 6, szOID_CT_PKI_RESPONSE, 0, (LPCWSTR)IDS_CMC_RESPONSE, NULL },
1057 { 6, szOID_CMC, 0, (LPCWSTR)IDS_UNSIGNED_CMC_REQUEST, NULL },
1058 { 6, szOID_CMC_STATUS_INFO, 0, (LPCWSTR)IDS_CMC_STATUS_INFO, NULL },
1059 { 6, szOID_CMC_ADD_EXTENSIONS, 0, (LPCWSTR)IDS_CMC_EXTENSIONS, NULL },
1060 { 6, szOID_CTL, 0, (LPCWSTR)IDS_CMC_ATTRIBUTES, NULL },
1061 { 6, szOID_RSA_data, 0, (LPCWSTR)IDS_PKCS_7_DATA, NULL },
1062 { 6, szOID_RSA_signedData, 0, (LPCWSTR)IDS_PKCS_7_SIGNED, NULL },
1063 { 6, szOID_RSA_envelopedData, 0, (LPCWSTR)IDS_PKCS_7_ENVELOPED, NULL },
1064 { 6, szOID_RSA_signEnvData, 0, (LPCWSTR)IDS_PKCS_7_SIGNED_ENVELOPED, NULL },
1065 { 6, szOID_RSA_digestedData, 0, (LPCWSTR)IDS_PKCS_7_DIGESTED, NULL },
1066 { 6, szOID_RSA_encryptedData, 0, (LPCWSTR)IDS_PKCS_7_ENCRYPTED, NULL },
1067 { 6, szOID_CERTSRV_PREVIOUS_CERT_HASH, 0, (LPCWSTR)IDS_PREVIOUS_CA_CERT_HASH, NULL },
1068 { 6, szOID_CRL_VIRTUAL_BASE, 0, (LPCWSTR)IDS_CRL_VIRTUAL_BASE, NULL },
1069 { 6, szOID_CRL_NEXT_PUBLISH, 0, (LPCWSTR)IDS_CRL_NEXT_PUBLISH, NULL },
1070 { 6, szOID_KP_CA_EXCHANGE, 0, (LPCWSTR)IDS_CA_EXCHANGE, NULL },
1071 { 6, szOID_KP_KEY_RECOVERY_AGENT, 0, (LPCWSTR)IDS_KEY_RECOVERY_AGENT, NULL },
1072 { 6, szOID_CERTIFICATE_TEMPLATE, 0, (LPCWSTR)IDS_CERTIFICATE_TEMPLATE, NULL },
1073 { 6, szOID_ENTERPRISE_OID_ROOT, 0, (LPCWSTR)IDS_ENTERPRISE_ROOT_OID, NULL },
1074 { 6, szOID_RDN_DUMMY_SIGNER, 0, (LPCWSTR)IDS_RDN_DUMMY_SIGNER, NULL },
1075 { 6, szOID_ARCHIVED_KEY_ATTR, 0, (LPCWSTR)IDS_ARCHIVED_KEY_ATTR, NULL },
1076 { 6, szOID_CRL_SELF_CDP, 0, (LPCWSTR)IDS_CRL_SELF_CDP, NULL },
1077 { 6, szOID_REQUIRE_CERT_CHAIN_POLICY, 0, (LPCWSTR)IDS_REQUIRE_CERT_CHAIN_POLICY, NULL },
1078 { 6, szOID_CMC_TRANSACTION_ID, 0, (LPCWSTR)IDS_TRANSACTION_ID, NULL },
1079 { 6, szOID_CMC_SENDER_NONCE, 0, (LPCWSTR)IDS_SENDER_NONCE, NULL },
1080 { 6, szOID_CMC_RECIPIENT_NONCE, 0, (LPCWSTR)IDS_RECIPIENT_NONCE, NULL },
1081 { 6, szOID_CMC_REG_INFO, 0, (LPCWSTR)IDS_REG_INFO, NULL },
1082 { 6, szOID_CMC_GET_CERT, 0, (LPCWSTR)IDS_GET_CERTIFICATE, NULL },
1083 { 6, szOID_CMC_GET_CRL, 0, (LPCWSTR)IDS_GET_CRL, NULL },
1084 { 6, szOID_CMC_REVOKE_REQUEST, 0, (LPCWSTR)IDS_REVOKE_REQUEST, NULL },
1085 { 6, szOID_CMC_QUERY_PENDING, 0, (LPCWSTR)IDS_QUERY_PENDING, NULL },
1086 { 6, szOID_SORTED_CTL, 0, (LPCWSTR)IDS_SORTED_CTL, NULL },
1087 { 6, szOID_ARCHIVED_KEY_CERT_HASH, 0, (LPCWSTR)IDS_ARCHIVED_KEY_CERT_HASH, NULL },
1088 { 6, szOID_PRIVATEKEY_USAGE_PERIOD, 0, (LPCWSTR)IDS_PRIVATE_KEY_USAGE_PERIOD, NULL },
1089 { 6, szOID_REQUEST_CLIENT_INFO, 0, (LPCWSTR)IDS_CLIENT_INFORMATION, NULL },
1091 { 7, szOID_PKIX_KP_SERVER_AUTH, 0, (LPCWSTR)IDS_SERVER_AUTHENTICATION, NULL },
1092 { 7, szOID_PKIX_KP_CLIENT_AUTH, 0, (LPCWSTR)IDS_CLIENT_AUTHENTICATION, NULL },
1093 { 7, szOID_PKIX_KP_CODE_SIGNING, 0, (LPCWSTR)IDS_CODE_SIGNING, NULL },
1094 { 7, szOID_PKIX_KP_EMAIL_PROTECTION, 0, (LPCWSTR)IDS_SECURE_EMAIL, NULL },
1095 { 7, szOID_PKIX_KP_TIMESTAMP_SIGNING, 0, (LPCWSTR)IDS_TIME_STAMPING, NULL },
1096 { 7, szOID_KP_CTL_USAGE_SIGNING, 0, (LPCWSTR)IDS_MICROSOFT_TRUST_LIST_SIGNING, NULL },
1097 { 7, szOID_KP_TIME_STAMP_SIGNING, 0, (LPCWSTR)IDS_MICROSOFT_TIME_STAMPING, NULL },
1098 { 7, szOID_PKIX_KP_IPSEC_END_SYSTEM, 0, (LPCWSTR)IDS_IPSEC_END_SYSTEM, NULL },
1099 { 7, szOID_PKIX_KP_IPSEC_TUNNEL, 0, (LPCWSTR)IDS_IPSEC_TUNNEL, NULL },
1100 { 7, szOID_PKIX_KP_IPSEC_USER, 0, (LPCWSTR)IDS_IPSEC_USER, NULL },
1101 { 7, szOID_KP_EFS, 0, (LPCWSTR)IDS_EFS, NULL },
1102 { 7, szOID_WHQL_CRYPTO, 0, (LPCWSTR)IDS_WHQL_CRYPTO, NULL },
1103 { 7, szOID_NT5_CRYPTO, 0, (LPCWSTR)IDS_NT5_CRYPTO, NULL },
1104 { 7, szOID_OEM_WHQL_CRYPTO, 0, (LPCWSTR)IDS_OEM_WHQL_CRYPTO, NULL },
1105 { 7, szOID_EMBEDDED_NT_CRYPTO, 0, (LPCWSTR)IDS_EMBEDDED_NT_CRYPTO, NULL },
1106 { 7, szOID_LICENSES, 0, (LPCWSTR)IDS_KEY_PACK_LICENSES, NULL },
1107 { 7, szOID_LICENSE_SERVER, 0, (LPCWSTR)IDS_LICENSE_SERVER, NULL },
1108 { 7, szOID_KP_SMARTCARD_LOGON, 0, (LPCWSTR)IDS_SMART_CARD_LOGON, NULL },
1109 { 7, szOID_DRM, 0, (LPCWSTR)IDS_DIGITAL_RIGHTS, NULL },
1110 { 7, szOID_KP_QUALIFIED_SUBORDINATION, 0, (LPCWSTR)IDS_QUALIFIED_SUBORDINATION, NULL },
1111 { 7, szOID_KP_KEY_RECOVERY, 0, (LPCWSTR)IDS_KEY_RECOVERY, NULL },
1112 { 7, szOID_KP_DOCUMENT_SIGNING, 0, (LPCWSTR)IDS_DOCUMENT_SIGNING, NULL },
1113 { 7, szOID_IPSEC_KP_IKE_INTERMEDIATE, 0, (LPCWSTR)IDS_IPSEC_IKE_INTERMEDIATE, NULL },
1114 { 7, szOID_EFS_RECOVERY, 0, (LPCWSTR)IDS_FILE_RECOVERY, NULL },
1115 { 7, szOID_ROOT_LIST_SIGNER, 0, (LPCWSTR)IDS_ROOT_LIST_SIGNER, NULL },
1116 { 7, szOID_ANY_APPLICATION_POLICY, 0, (LPCWSTR)IDS_ANY_APPLICATION_POLICIES, NULL },
1117 { 7, szOID_DS_EMAIL_REPLICATION, 0, (LPCWSTR)IDS_DS_EMAIL_REPLICATION, NULL },
1118 { 7, szOID_ENROLLMENT_AGENT, 0, (LPCWSTR)IDS_ENROLLMENT_AGENT, NULL },
1119 { 7, szOID_KP_KEY_RECOVERY_AGENT, 0, (LPCWSTR)IDS_KEY_RECOVERY_AGENT, NULL },
1120 { 7, szOID_KP_CA_EXCHANGE, 0, (LPCWSTR)IDS_CA_EXCHANGE, NULL },
1121 { 7, szOID_KP_LIFETIME_SIGNING, 0, (LPCWSTR)IDS_LIFETIME_SIGNING, NULL },
1123 { 8, szOID_ANY_CERT_POLICY, 0, (LPCWSTR)IDS_ANY_CERT_POLICY, NULL },
1127 CRYPT_OID_INFO info;
1131 static void init_oid_info(HINSTANCE hinst)
1135 InitializeCriticalSection(&oidInfoCS);
1136 list_init(&oidInfo);
1137 for (i = 0; i < sizeof(oidInfoConstructors) /
1138 sizeof(oidInfoConstructors[0]); i++)
1140 if (HIWORD(oidInfoConstructors[i].pwszName))
1142 struct OIDInfo *info;
1144 /* The name is a static string, so just use the same pointer */
1145 info = CryptMemAlloc(sizeof(struct OIDInfo));
1148 memset(info, 0, sizeof(*info));
1149 info->info.cbSize = sizeof(CRYPT_OID_INFO);
1150 info->info.pszOID = oidInfoConstructors[i].pszOID;
1151 info->info.pwszName = oidInfoConstructors[i].pwszName;
1152 info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
1153 info->info.u.Algid = oidInfoConstructors[i].Algid;
1154 if (oidInfoConstructors[i].blob)
1156 info->info.ExtraInfo.cbData =
1157 oidInfoConstructors[i].blob->cbData;
1158 info->info.ExtraInfo.pbData =
1159 oidInfoConstructors[i].blob->pbData;
1161 list_add_tail(&oidInfo, &info->entry);
1166 int len = LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName,
1171 struct OIDInfo *info = CryptMemAlloc(sizeof(struct OIDInfo) +
1172 (len + 1) * sizeof(WCHAR));
1176 memset(info, 0, sizeof(*info));
1177 info->info.cbSize = sizeof(CRYPT_OID_INFO);
1178 info->info.pszOID = oidInfoConstructors[i].pszOID;
1179 info->info.pwszName =
1180 (LPWSTR)((LPBYTE)info + sizeof(struct OIDInfo));
1181 info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
1182 info->info.u.Algid = oidInfoConstructors[i].Algid;
1183 LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName,
1184 (LPWSTR)info->info.pwszName, len + 1);
1185 if (oidInfoConstructors[i].blob)
1187 info->info.ExtraInfo.cbData =
1188 oidInfoConstructors[i].blob->cbData;
1189 info->info.ExtraInfo.pbData =
1190 oidInfoConstructors[i].blob->pbData;
1192 list_add_tail(&oidInfo, &info->entry);
1199 static void free_oid_info(void)
1201 struct OIDInfo *info, *next;
1203 LIST_FOR_EACH_ENTRY_SAFE(info, next, &oidInfo, struct OIDInfo, entry)
1205 list_remove(&info->entry);
1208 DeleteCriticalSection(&oidInfoCS);
1211 BOOL WINAPI CryptEnumOIDInfo(DWORD dwGroupId, DWORD dwFlags, void *pvArg,
1212 PFN_CRYPT_ENUM_OID_INFO pfnEnumOIDInfo)
1215 struct OIDInfo *info;
1217 TRACE("(%ld, %08lx, %p, %p)\n", dwGroupId, dwFlags, pvArg,
1220 EnterCriticalSection(&oidInfoCS);
1221 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1223 if (!dwGroupId || dwGroupId == info->info.dwGroupId)
1225 ret = pfnEnumOIDInfo(&info->info, pvArg);
1230 LeaveCriticalSection(&oidInfoCS);
1234 PCCRYPT_OID_INFO WINAPI CryptFindOIDInfo(DWORD dwKeyType, void *pvKey,
1237 PCCRYPT_OID_INFO ret = NULL;
1239 TRACE("(%ld, %p, %ld)\n", dwKeyType, pvKey, dwGroupId);
1243 case CRYPT_OID_INFO_ALGID_KEY:
1245 struct OIDInfo *info;
1247 TRACE("CRYPT_OID_INFO_ALGID_KEY: %ld\n", *(DWORD *)pvKey);
1248 EnterCriticalSection(&oidInfoCS);
1249 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1251 if (info->info.u.Algid == *(DWORD *)pvKey &&
1252 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1258 LeaveCriticalSection(&oidInfoCS);
1261 case CRYPT_OID_INFO_NAME_KEY:
1263 struct OIDInfo *info;
1265 TRACE("CRYPT_OID_INFO_NAME_KEY: %s\n", debugstr_w((LPWSTR)pvKey));
1266 EnterCriticalSection(&oidInfoCS);
1267 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1269 if (!lstrcmpW(info->info.pwszName, (LPWSTR)pvKey) &&
1270 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1276 LeaveCriticalSection(&oidInfoCS);
1279 case CRYPT_OID_INFO_OID_KEY:
1281 struct OIDInfo *info;
1282 LPSTR oid = (LPSTR)pvKey;
1284 TRACE("CRYPT_OID_INFO_OID_KEY: %s\n", debugstr_a(oid));
1285 EnterCriticalSection(&oidInfoCS);
1286 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1288 if (!lstrcmpA(info->info.pszOID, oid) &&
1289 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1295 LeaveCriticalSection(&oidInfoCS);
1298 case CRYPT_OID_INFO_SIGN_KEY:
1300 struct OIDInfo *info;
1302 TRACE("CRYPT_OID_INFO_SIGN_KEY: %ld\n", *(DWORD *)pvKey);
1303 EnterCriticalSection(&oidInfoCS);
1304 LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
1306 if (info->info.u.Algid == *(DWORD *)pvKey &&
1307 info->info.ExtraInfo.cbData >= sizeof(DWORD) &&
1308 *(DWORD *)info->info.ExtraInfo.pbData ==
1309 *(DWORD *)((LPBYTE)pvKey + sizeof(DWORD)) &&
1310 (!dwGroupId || info->info.dwGroupId == dwGroupId))
1316 LeaveCriticalSection(&oidInfoCS);
1323 LPCSTR WINAPI CertAlgIdToOID(DWORD dwAlgId)
1326 PCCRYPT_OID_INFO info = CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY,
1336 DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId)
1339 PCCRYPT_OID_INFO info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY,
1340 (void *)pszObjId, 0);
1343 ret = info->u.Algid;