2 * Copyright 2006 Juan Lang for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/debug.h"
25 #include "wine/unicode.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
29 DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
34 TRACE("(%d, %p, %p, %d)\n", dwValueType, pValue, psz, csz);
38 case CERT_RDN_ANY_TYPE:
40 case CERT_RDN_NUMERIC_STRING:
41 case CERT_RDN_PRINTABLE_STRING:
42 case CERT_RDN_TELETEX_STRING:
43 case CERT_RDN_VIDEOTEX_STRING:
44 case CERT_RDN_IA5_STRING:
45 case CERT_RDN_GRAPHIC_STRING:
46 case CERT_RDN_VISIBLE_STRING:
47 case CERT_RDN_GENERAL_STRING:
52 DWORD chars = min(pValue->cbData, csz - 1);
56 memcpy(psz, pValue->pbData, chars);
62 case CERT_RDN_UTF8_STRING:
64 ret = WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)pValue->pbData,
65 pValue->cbData / sizeof(WCHAR) + 1, NULL, 0, NULL, NULL);
68 ret = WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)pValue->pbData,
69 pValue->cbData / sizeof(WCHAR) + 1, psz, csz - 1, NULL, NULL);
74 FIXME("string type %d unimplemented\n", dwValueType);
84 TRACE("returning %d (%s)\n", ret, debugstr_a(psz));
88 DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
89 LPWSTR psz, DWORD csz)
93 TRACE("(%d, %p, %p, %d)\n", dwValueType, pValue, psz, csz);
97 case CERT_RDN_ANY_TYPE:
99 case CERT_RDN_NUMERIC_STRING:
100 case CERT_RDN_PRINTABLE_STRING:
101 case CERT_RDN_TELETEX_STRING:
102 case CERT_RDN_VIDEOTEX_STRING:
103 case CERT_RDN_IA5_STRING:
104 case CERT_RDN_GRAPHIC_STRING:
105 case CERT_RDN_VISIBLE_STRING:
106 case CERT_RDN_GENERAL_STRING:
108 ret = pValue->cbData;
111 DWORD chars = min(pValue->cbData, csz - 1);
117 for (i = 0; i < chars; i++)
118 psz[i] = pValue->pbData[i];
124 case CERT_RDN_UTF8_STRING:
126 ret = pValue->cbData / sizeof(WCHAR);
129 DWORD chars = min(pValue->cbData / sizeof(WCHAR), csz - 1);
135 for (i = 0; i < chars; i++)
136 psz[i] = *((LPWSTR)pValue->pbData + i);
143 FIXME("string type %d unimplemented\n", dwValueType);
153 TRACE("returning %d (%s)\n", ret, debugstr_w(psz));
157 /* Adds the prefix prefix to the string pointed to by psz, followed by the
158 * character '='. Copies no more than csz characters. Returns the number of
159 * characters copied. If psz is NULL, returns the number of characters that
162 static DWORD CRYPT_AddPrefixA(LPCSTR prefix, LPSTR psz, DWORD csz)
166 TRACE("(%s, %p, %d)\n", debugstr_a(prefix), psz, csz);
170 chars = min(lstrlenA(prefix), csz);
171 memcpy(psz, prefix, chars);
173 *(psz + chars) = '=';
178 chars = lstrlenA(prefix) + 1;
182 DWORD WINAPI CertNameToStrA(DWORD dwCertEncodingType, PCERT_NAME_BLOB pName,
183 DWORD dwStrType, LPSTR psz, DWORD csz)
185 static const DWORD unsupportedFlags = CERT_NAME_STR_NO_QUOTING_FLAG |
186 CERT_NAME_STR_REVERSE_FLAG | CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG;
187 static const char commaSep[] = ", ";
188 static const char semiSep[] = "; ";
189 static const char crlfSep[] = "\r\n";
190 static const char plusSep[] = " + ";
191 static const char spaceSep[] = " ";
192 DWORD ret = 0, bytes = 0;
194 CERT_NAME_INFO *info;
196 TRACE("(%d, %p, %08x, %p, %d)\n", dwCertEncodingType, pName, dwStrType,
198 if (dwStrType & unsupportedFlags)
199 FIXME("unsupported flags: %08x\n", dwStrType & unsupportedFlags);
201 bRet = CryptDecodeObjectEx(dwCertEncodingType, X509_NAME, pName->pbData,
202 pName->cbData, CRYPT_DECODE_ALLOC_FLAG, NULL, &info, &bytes);
205 DWORD i, j, sepLen, rdnSepLen;
208 if (dwStrType & CERT_NAME_STR_SEMICOLON_FLAG)
210 else if (dwStrType & CERT_NAME_STR_CRLF_FLAG)
214 sepLen = strlen(sep);
215 if (dwStrType & CERT_NAME_STR_NO_PLUS_FLAG)
219 rdnSepLen = strlen(rdnSep);
220 for (i = 0; (!psz || ret < csz) && i < info->cRDN; i++)
222 for (j = 0; (!psz || ret < csz) && j < info->rgRDN[i].cRDNAttr; j++)
225 char prefixBuf[10]; /* big enough for GivenName */
226 LPCSTR prefix = NULL;
228 if ((dwStrType & 0x000000ff) == CERT_OID_NAME_STR)
229 prefix = info->rgRDN[i].rgRDNAttr[j].pszObjId;
230 else if ((dwStrType & 0x000000ff) == CERT_X500_NAME_STR)
232 PCCRYPT_OID_INFO oidInfo = CryptFindOIDInfo(
233 CRYPT_OID_INFO_OID_KEY,
234 info->rgRDN[i].rgRDNAttr[j].pszObjId,
235 CRYPT_RDN_ATTR_OID_GROUP_ID);
239 WideCharToMultiByte(CP_ACP, 0, oidInfo->pwszName, -1,
240 prefixBuf, sizeof(prefixBuf), NULL, NULL);
244 prefix = info->rgRDN[i].rgRDNAttr[j].pszObjId;
248 /* - 1 is needed to account for the NULL terminator. */
249 chars = CRYPT_AddPrefixA(prefix,
250 psz ? psz + ret : NULL, psz ? csz - ret - 1 : 0);
254 /* FIXME: handle quoting */
255 chars = CertRDNValueToStrA(
256 info->rgRDN[i].rgRDNAttr[j].dwValueType,
257 &info->rgRDN[i].rgRDNAttr[j].Value, psz ? psz + ret : NULL,
258 psz ? csz - ret : 0);
261 if (j < info->rgRDN[i].cRDNAttr - 1)
263 if (psz && ret < csz - rdnSepLen - 1)
264 memcpy(psz + ret, rdnSep, rdnSepLen);
268 if (i < info->cRDN - 1)
270 if (psz && ret < csz - sepLen - 1)
271 memcpy(psz + ret, sep, sepLen);
285 TRACE("Returning %s\n", debugstr_a(psz));
289 /* Adds the prefix prefix to the wide-character string pointed to by psz,
290 * followed by the character '='. Copies no more than csz characters. Returns
291 * the number of characters copied. If psz is NULL, returns the number of
292 * characters that would be copied.
293 * Assumes the characters in prefix are ASCII (not multibyte characters.)
295 static DWORD CRYPT_AddPrefixAToW(LPCSTR prefix, LPWSTR psz, DWORD csz)
299 TRACE("(%s, %p, %d)\n", debugstr_a(prefix), psz, csz);
305 chars = min(lstrlenA(prefix), csz);
306 for (i = 0; i < chars; i++)
307 *(psz + i) = prefix[i];
309 *(psz + chars) = '=';
314 chars = lstrlenA(prefix) + 1;
318 /* Adds the prefix prefix to the string pointed to by psz, followed by the
319 * character '='. Copies no more than csz characters. Returns the number of
320 * characters copied. If psz is NULL, returns the number of characters that
323 static DWORD CRYPT_AddPrefixW(LPCWSTR prefix, LPWSTR psz, DWORD csz)
327 TRACE("(%s, %p, %d)\n", debugstr_w(prefix), psz, csz);
331 chars = min(lstrlenW(prefix), csz);
332 memcpy(psz, prefix, chars * sizeof(WCHAR));
334 *(psz + chars) = '=';
339 chars = lstrlenW(prefix) + 1;
343 DWORD WINAPI CertNameToStrW(DWORD dwCertEncodingType, PCERT_NAME_BLOB pName,
344 DWORD dwStrType, LPWSTR psz, DWORD csz)
346 static const DWORD unsupportedFlags = CERT_NAME_STR_NO_QUOTING_FLAG |
347 CERT_NAME_STR_REVERSE_FLAG | CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG;
348 static const WCHAR commaSep[] = { ',',' ',0 };
349 static const WCHAR semiSep[] = { ';',' ',0 };
350 static const WCHAR crlfSep[] = { '\r','\n',0 };
351 static const WCHAR plusSep[] = { ' ','+',' ',0 };
352 static const WCHAR spaceSep[] = { ' ',0 };
353 DWORD ret = 0, bytes = 0;
355 CERT_NAME_INFO *info;
357 TRACE("(%d, %p, %08x, %p, %d)\n", dwCertEncodingType, pName, dwStrType,
359 if (dwStrType & unsupportedFlags)
360 FIXME("unsupported flags: %08x\n", dwStrType & unsupportedFlags);
362 bRet = CryptDecodeObjectEx(dwCertEncodingType, X509_NAME, pName->pbData,
363 pName->cbData, CRYPT_DECODE_ALLOC_FLAG, NULL, &info, &bytes);
366 DWORD i, j, sepLen, rdnSepLen;
369 if (dwStrType & CERT_NAME_STR_SEMICOLON_FLAG)
371 else if (dwStrType & CERT_NAME_STR_CRLF_FLAG)
375 sepLen = lstrlenW(sep);
376 if (dwStrType & CERT_NAME_STR_NO_PLUS_FLAG)
380 rdnSepLen = lstrlenW(rdnSep);
381 for (i = 0; (!psz || ret < csz) && i < info->cRDN; i++)
383 for (j = 0; (!psz || ret < csz) && j < info->rgRDN[i].cRDNAttr; j++)
386 LPCSTR prefixA = NULL;
387 LPCWSTR prefixW = NULL;
389 if ((dwStrType & 0x000000ff) == CERT_OID_NAME_STR)
390 prefixA = info->rgRDN[i].rgRDNAttr[j].pszObjId;
391 else if ((dwStrType & 0x000000ff) == CERT_X500_NAME_STR)
393 PCCRYPT_OID_INFO oidInfo = CryptFindOIDInfo(
394 CRYPT_OID_INFO_OID_KEY,
395 info->rgRDN[i].rgRDNAttr[j].pszObjId,
396 CRYPT_RDN_ATTR_OID_GROUP_ID);
399 prefixW = oidInfo->pwszName;
401 prefixA = info->rgRDN[i].rgRDNAttr[j].pszObjId;
405 /* - 1 is needed to account for the NULL terminator. */
406 chars = CRYPT_AddPrefixW(prefixW,
407 psz ? psz + ret : NULL, psz ? csz - ret - 1 : 0);
413 /* - 1 is needed to account for the NULL terminator. */
414 chars = CRYPT_AddPrefixAToW(prefixA,
415 psz ? psz + ret : NULL, psz ? csz - ret - 1 : 0);
419 /* FIXME: handle quoting */
420 chars = CertRDNValueToStrW(
421 info->rgRDN[i].rgRDNAttr[j].dwValueType,
422 &info->rgRDN[i].rgRDNAttr[j].Value, psz ? psz + ret : NULL,
423 psz ? csz - ret : 0);
426 if (j < info->rgRDN[i].cRDNAttr - 1)
428 if (psz && ret < csz - rdnSepLen - 1)
429 memcpy(psz + ret, rdnSep, rdnSepLen * sizeof(WCHAR));
433 if (i < info->cRDN - 1)
435 if (psz && ret < csz - sepLen - 1)
436 memcpy(psz + ret, sep, sepLen * sizeof(WCHAR));
450 TRACE("Returning %s\n", debugstr_w(psz));
454 BOOL WINAPI CertStrToNameA(DWORD dwCertEncodingType, LPCSTR pszX500,
455 DWORD dwStrType, void *pvReserved, BYTE *pbEncoded, DWORD *pcbEncoded,
458 LPWSTR x500, errorStr;
462 TRACE("(%08x, %s, %08x, %p, %p, %p, %p)\n", dwCertEncodingType,
463 debugstr_a(pszX500), dwStrType, pvReserved, pbEncoded, pcbEncoded,
466 len = MultiByteToWideChar(CP_ACP, 0, pszX500, -1, NULL, 0);
467 x500 = CryptMemAlloc(len * sizeof(WCHAR));
470 MultiByteToWideChar(CP_ACP, 0, pszX500, -1, x500, len);
471 ret = CertStrToNameW(dwCertEncodingType, x500, dwStrType, pvReserved,
472 pbEncoded, pcbEncoded, ppszError ? (LPCWSTR *)&errorStr : NULL);
477 *ppszError = pszX500;
478 for (i = 0; i < errorStr - x500; i++)
479 *ppszError = CharNextA(*ppszError);
490 WCHAR buf[10]; /* big enough for L"GivenName" */
491 LPWSTR keyName; /* usually = buf, but may be allocated */
495 static void CRYPT_InitializeKeynameKeeper(struct KeynameKeeper *keeper)
497 keeper->keyName = keeper->buf;
498 keeper->keyLen = sizeof(keeper->buf) / sizeof(keeper->buf[0]);
501 static void CRYPT_FreeKeynameKeeper(struct KeynameKeeper *keeper)
503 if (keeper->keyName != keeper->buf)
504 CryptMemFree(keeper->keyName);
513 static void CRYPT_KeynameKeeperFromTokenW(struct KeynameKeeper *keeper,
514 const struct X500TokenW *key)
516 DWORD len = key->end - key->start;
518 if (len > keeper->keyLen)
520 if (keeper->keyName == keeper->buf)
521 keeper->keyName = CryptMemAlloc(len * sizeof(WCHAR));
523 keeper->keyName = CryptMemRealloc(keeper->keyName,
524 len * sizeof(WCHAR));
525 keeper->keyLen = len;
527 memcpy(keeper->keyName, key->start, (key->end - key->start) *
529 keeper->keyName[len] = '\0';
530 TRACE("Keyname is %s\n", debugstr_w(keeper->keyName));
533 static DWORD CRYPT_GetNextKeyW(LPCWSTR str, struct X500TokenW *token,
536 DWORD ret = ERROR_SUCCESS;
538 while (*str && isspaceW(*str))
543 while (*str && *str != '=' && !isspaceW(*str))
545 if (*str && (*str == '=' || isspaceW(*str)))
549 TRACE("missing equals char at %s\n", debugstr_w(token->start));
551 *ppszError = token->start;
552 ret = CRYPT_E_INVALID_X500_STRING;
560 /* Assumes separators are characters in the 0-255 range */
561 static DWORD CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators,
562 struct X500TokenW *token, LPCWSTR *ppszError)
564 DWORD ret = ERROR_SUCCESS;
566 TRACE("(%s, %s, %p, %p)\n", debugstr_w(str), debugstr_w(separators), token,
569 while (*str && isspaceW(*str))
574 if (!(dwFlags & CERT_NAME_STR_NO_QUOTING_FLAG) && *str == '"')
578 while (!token->end && !ret)
580 while (*str && *str != '"')
584 if (*(str + 1) != '"')
585 token->end = str + 1;
591 TRACE("unterminated quote at %s\n", debugstr_w(str));
594 ret = CRYPT_E_INVALID_X500_STRING;
600 WCHAR map[256] = { 0 };
603 map[*separators++] = 1;
604 while (*str && (*str >= 0xff || !map[*(const unsigned short *)str]))
611 TRACE("missing value at %s\n", debugstr_w(str));
614 ret = CRYPT_E_INVALID_X500_STRING;
619 /* Encodes the string represented by value as the string type type into the
620 * CERT_NAME_BLOB output. If there is an error and ppszError is not NULL,
621 * *ppszError is set to the first failing character. If there is no error,
622 * output's pbData must be freed with LocalFree.
624 static BOOL CRYPT_EncodeValueWithType(DWORD dwCertEncodingType,
625 const struct X500TokenW *value, PCERT_NAME_BLOB output, DWORD type,
628 CERT_NAME_VALUE nameValue = { type, { 0, NULL } };
631 nameValue.Value.pbData = CryptMemAlloc((value->end - value->start) *
633 if (nameValue.Value.pbData)
636 LPWSTR ptr = (LPWSTR)nameValue.Value.pbData;
638 for (i = 0; i < value->end - value->start; i++)
640 *ptr++ = value->start[i];
641 if (value->start[i] == '"')
644 nameValue.Value.cbData = (LPBYTE)ptr - nameValue.Value.pbData;
645 ret = CryptEncodeObjectEx(dwCertEncodingType, X509_UNICODE_NAME_VALUE,
646 &nameValue, CRYPT_ENCODE_ALLOC_FLAG, NULL, &output->pbData,
648 if (!ret && ppszError)
650 if (type == CERT_RDN_NUMERIC_STRING &&
651 GetLastError() == CRYPT_E_INVALID_NUMERIC_STRING)
652 *ppszError = value->start + output->cbData;
653 else if (type == CERT_RDN_PRINTABLE_STRING &&
654 GetLastError() == CRYPT_E_INVALID_PRINTABLE_STRING)
655 *ppszError = value->start + output->cbData;
656 else if (type == CERT_RDN_IA5_STRING &&
657 GetLastError() == CRYPT_E_INVALID_IA5_STRING)
658 *ppszError = value->start + output->cbData;
660 CryptMemFree(nameValue.Value.pbData);
665 static BOOL CRYPT_EncodeValue(DWORD dwCertEncodingType,
666 const struct X500TokenW *value, PCERT_NAME_BLOB output, const DWORD *types,
673 for (i = 0; !ret && types[i]; i++)
674 ret = CRYPT_EncodeValueWithType(dwCertEncodingType, value, output,
675 types[i], ppszError);
679 static BOOL CRYPT_ValueToRDN(DWORD dwCertEncodingType, PCERT_NAME_INFO info,
680 PCCRYPT_OID_INFO keyOID, struct X500TokenW *value, LPCWSTR *ppszError)
684 TRACE("OID %s, value %s\n", debugstr_a(keyOID->pszOID),
685 debugstr_wn(value->start, value->end - value->start));
688 info->rgRDN = CryptMemAlloc(sizeof(CERT_RDN));
690 info->rgRDN = CryptMemRealloc(info->rgRDN,
691 (info->cRDN + 1) * sizeof(CERT_RDN));
694 /* FIXME: support multiple RDN attrs */
695 info->rgRDN[info->cRDN].rgRDNAttr =
696 CryptMemAlloc(sizeof(CERT_RDN_ATTR));
697 if (info->rgRDN[info->cRDN].rgRDNAttr)
699 static const DWORD defaultTypes[] = { CERT_RDN_PRINTABLE_STRING,
700 CERT_RDN_BMP_STRING, 0 };
703 info->rgRDN[info->cRDN].cRDNAttr = 1;
704 info->rgRDN[info->cRDN].rgRDNAttr[0].pszObjId =
705 (LPSTR)keyOID->pszOID;
706 info->rgRDN[info->cRDN].rgRDNAttr[0].dwValueType =
707 CERT_RDN_ENCODED_BLOB;
708 if (keyOID->ExtraInfo.cbData)
709 types = (const DWORD *)keyOID->ExtraInfo.pbData;
711 types = defaultTypes;
713 /* Remove surrounding quotes */
714 if (value->start[0] == '"')
719 ret = CRYPT_EncodeValue(dwCertEncodingType, value,
720 &info->rgRDN[info->cRDN].rgRDNAttr[0].Value, types, ppszError);
728 BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500,
729 DWORD dwStrType, void *pvReserved, BYTE *pbEncoded, DWORD *pcbEncoded,
732 CERT_NAME_INFO info = { 0, NULL };
734 struct KeynameKeeper keeper;
735 DWORD i, error = ERROR_SUCCESS;
738 TRACE("(%08x, %s, %08x, %p, %p, %p, %p)\n", dwCertEncodingType,
739 debugstr_w(pszX500), dwStrType, pvReserved, pbEncoded, pcbEncoded,
742 CRYPT_InitializeKeynameKeeper(&keeper);
744 while (str && *str && !error && ret)
746 struct X500TokenW token;
748 error = CRYPT_GetNextKeyW(str, &token, ppszError);
749 if (!error && token.start)
751 PCCRYPT_OID_INFO keyOID;
753 CRYPT_KeynameKeeperFromTokenW(&keeper, &token);
754 keyOID = CryptFindOIDInfo(CRYPT_OID_INFO_NAME_KEY, keeper.keyName,
755 CRYPT_RDN_ATTR_OID_GROUP_ID);
759 *ppszError = token.start;
760 error = CRYPT_E_INVALID_X500_STRING;
765 while (isspace(*str))
771 error = CRYPT_E_INVALID_X500_STRING;
775 static const WCHAR commaSep[] = { ',',0 };
776 static const WCHAR semiSep[] = { ';',0 };
777 static const WCHAR crlfSep[] = { '\r','\n',0 };
778 static const WCHAR allSeps[] = { ',',';','\r','\n',0 };
782 if (dwStrType & CERT_NAME_STR_COMMA_FLAG)
784 else if (dwStrType & CERT_NAME_STR_SEMICOLON_FLAG)
786 else if (dwStrType & CERT_NAME_STR_CRLF_FLAG)
790 error = CRYPT_GetNextValueW(str, dwStrType, sep, &token,
795 ret = CRYPT_ValueToRDN(dwCertEncodingType, &info,
796 keyOID, &token, ppszError);
802 CRYPT_FreeKeynameKeeper(&keeper);
805 ret = CryptEncodeObjectEx(dwCertEncodingType, X509_NAME, &info,
806 0, NULL, pbEncoded, pcbEncoded);
807 for (i = 0; i < info.cRDN; i++)
811 for (j = 0; j < info.rgRDN[i].cRDNAttr; j++)
812 LocalFree(info.rgRDN[i].rgRDNAttr[j].Value.pbData);
813 CryptMemFree(info.rgRDN[i].rgRDNAttr);
815 CryptMemFree(info.rgRDN);
825 DWORD WINAPI CertGetNameStringA(PCCERT_CONTEXT pCertContext, DWORD dwType,
826 DWORD dwFlags, void *pvTypePara, LPSTR pszNameString, DWORD cchNameString)
830 TRACE("(%p, %d, %08x, %p, %p, %d)\n", pCertContext, dwType, dwFlags,
831 pvTypePara, pszNameString, cchNameString);
838 nameLen = CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara,
840 wideName = CryptMemAlloc(nameLen * sizeof(WCHAR));
843 CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara,
845 nameLen = WideCharToMultiByte(CP_ACP, 0, wideName, nameLen,
846 pszNameString, cchNameString, NULL, NULL);
847 if (nameLen <= cchNameString)
851 pszNameString[cchNameString - 1] = '\0';
854 CryptMemFree(wideName);
858 *pszNameString = '\0';
863 ret = CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara,
868 DWORD WINAPI CertGetNameStringW(PCCERT_CONTEXT pCertContext, DWORD dwType,
869 DWORD dwFlags, void *pvTypePara, LPWSTR pszNameString, DWORD cchNameString)
872 PCERT_NAME_BLOB name;
875 TRACE("(%p, %d, %08x, %p, %p, %d)\n", pCertContext, dwType,
876 dwFlags, pvTypePara, pszNameString, cchNameString);
878 if (dwFlags & CERT_NAME_ISSUER_FLAG)
880 name = &pCertContext->pCertInfo->Issuer;
881 altNameOID = szOID_ISSUER_ALT_NAME;
885 name = &pCertContext->pCertInfo->Subject;
886 altNameOID = szOID_SUBJECT_ALT_NAME;
891 case CERT_NAME_SIMPLE_DISPLAY_TYPE:
893 static const LPCSTR simpleAttributeOIDs[] = { szOID_COMMON_NAME,
894 szOID_ORGANIZATIONAL_UNIT_NAME, szOID_ORGANIZATION_NAME,
895 szOID_RSA_emailAddr };
896 CERT_NAME_INFO *info = NULL;
897 PCERT_RDN_ATTR nameAttr = NULL;
900 if (CryptDecodeObjectEx(pCertContext->dwCertEncodingType, X509_NAME,
901 name->pbData, name->cbData, CRYPT_DECODE_ALLOC_FLAG, NULL, &info,
904 for (i = 0; !nameAttr && i < sizeof(simpleAttributeOIDs) /
905 sizeof(simpleAttributeOIDs[0]); i++)
906 nameAttr = CertFindRDNAttr(simpleAttributeOIDs[i], info);
910 PCERT_EXTENSION ext = CertFindExtension(altNameOID,
911 pCertContext->pCertInfo->cExtension,
912 pCertContext->pCertInfo->rgExtension);
916 for (i = 0; !nameAttr && i < sizeof(simpleAttributeOIDs) /
917 sizeof(simpleAttributeOIDs[0]); i++)
918 nameAttr = CertFindRDNAttr(simpleAttributeOIDs[i], info);
921 /* FIXME: gotta then look for a rfc822Name choice in ext.
922 * Failing that, look for the first attribute.
924 FIXME("CERT_NAME_SIMPLE_DISPLAY_TYPE: stub\n");
929 ret = CertRDNValueToStrW(nameAttr->dwValueType, &nameAttr->Value,
930 pszNameString, cchNameString);
937 case CERT_NAME_FRIENDLY_DISPLAY_TYPE:
939 DWORD cch = cchNameString;
941 if (CertGetCertificateContextProperty(pCertContext,
942 CERT_FRIENDLY_NAME_PROP_ID, pszNameString, &cch))
945 ret = CertGetNameStringW(pCertContext,
946 CERT_NAME_SIMPLE_DISPLAY_TYPE, dwFlags, pvTypePara, pszNameString,
951 FIXME("unimplemented for type %d\n", dwType);