ReactOS 0.4.17-dev-470-gf9e3448
str.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "winuser.h"
#include "wincrypt.h"
#include "wine/debug.h"
#include "crypt32_private.h"
Include dependency graph for str.c:

Go to the source code of this file.

Classes

struct  KeynameKeeper
 
struct  X500TokenW
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (crypt)
 
DWORD WINAPI CertRDNValueToStrA (DWORD type, PCERT_RDN_VALUE_BLOB value_blob, LPSTR value, DWORD value_len)
 
static DWORD rdn_value_to_strW (DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, LPWSTR psz, DWORD csz, BOOL partial_copy)
 
DWORD WINAPI CertRDNValueToStrW (DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, LPWSTR psz, DWORD csz)
 
static BOOL is_quotable_char (WCHAR c)
 
static BOOL is_spaceW (WCHAR c)
 
static DWORD quote_rdn_value_to_str_w (DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, DWORD dwStrType, LPWSTR psz, DWORD csz)
 
DWORD WINAPI CertNameToStrA (DWORD encoding_type, PCERT_NAME_BLOB name_blob, DWORD str_type, LPSTR str, DWORD str_len)
 
static DWORD CRYPT_AddPrefixAToW (LPCSTR prefix, LPWSTR psz, DWORD csz)
 
static DWORD CRYPT_AddPrefixW (LPCWSTR prefix, LPWSTR psz, DWORD csz)
 
DWORD cert_name_to_str_with_indent (DWORD dwCertEncodingType, DWORD indentLevel, const CERT_NAME_BLOB *pName, DWORD dwStrType, LPWSTR psz, DWORD csz)
 
DWORD WINAPI CertNameToStrW (DWORD dwCertEncodingType, PCERT_NAME_BLOB pName, DWORD dwStrType, LPWSTR psz, DWORD csz)
 
BOOL WINAPI CertStrToNameA (DWORD dwCertEncodingType, LPCSTR pszX500, DWORD dwStrType, void *pvReserved, BYTE *pbEncoded, DWORD *pcbEncoded, LPCSTR *ppszError)
 
static void CRYPT_InitializeKeynameKeeper (struct KeynameKeeper *keeper)
 
static void CRYPT_FreeKeynameKeeper (struct KeynameKeeper *keeper)
 
static void CRYPT_KeynameKeeperFromTokenW (struct KeynameKeeper *keeper, const struct X500TokenW *key)
 
static BOOL CRYPT_GetNextKeyW (LPCWSTR str, struct X500TokenW *token, LPCWSTR *ppszError)
 
static BOOL CRYPT_GetNextValueW (LPCWSTR str, DWORD dwFlags, LPCWSTR separators, WCHAR *separator_used, struct X500TokenW *token, LPCWSTR *ppszError)
 
static BOOL CRYPT_EncodeValueWithType (DWORD dwCertEncodingType, const struct X500TokenW *value, PCERT_NAME_BLOB output, DWORD type, LPCWSTR *ppszError)
 
static BOOL CRYPT_EncodeValue (DWORD dwCertEncodingType, const struct X500TokenW *value, PCERT_NAME_BLOB output, const DWORD *types, LPCWSTR *ppszError)
 
static BOOL CRYPT_ValueToRDN (DWORD dwCertEncodingType, PCERT_NAME_INFO info, PCCRYPT_OID_INFO keyOID, struct X500TokenW *value, DWORD dwStrType, LPCWSTR *ppszError)
 
BOOL WINAPI CertStrToNameW (DWORD dwCertEncodingType, LPCWSTR pszX500, DWORD dwStrType, void *pvReserved, BYTE *pbEncoded, DWORD *pcbEncoded, LPCWSTR *ppszError)
 
DWORD WINAPI CertGetNameStringA (PCCERT_CONTEXT cert, DWORD type, DWORD flags, void *type_para, LPSTR name, DWORD name_len)
 
static BOOL cert_get_alt_name_info (PCCERT_CONTEXT cert, BOOL alt_name_issuer, PCERT_ALT_NAME_INFO *info)
 
static PCERT_ALT_NAME_ENTRY cert_find_next_alt_name_entry (PCERT_ALT_NAME_INFO info, DWORD entry_type, unsigned int *index)
 
static PCERT_ALT_NAME_ENTRY cert_find_alt_name_entry (PCCERT_CONTEXT cert, BOOL alt_name_issuer, DWORD entry_type, PCERT_ALT_NAME_INFO *info)
 
static DWORD cert_get_name_from_rdn_attr (DWORD encodingType, const CERT_NAME_BLOB *name, LPCSTR oid, LPWSTR pszNameString, DWORD cchNameString)
 
static DWORD copy_output_str (WCHAR *dst, const WCHAR *src, DWORD dst_size)
 
DWORD WINAPI CertGetNameStringW (PCCERT_CONTEXT cert, DWORD type, DWORD flags, void *type_para, LPWSTR name_string, DWORD name_len)
 

Variables

static const WCHAR indent [] = L" "
 

Function Documentation

◆ cert_find_alt_name_entry()

static PCERT_ALT_NAME_ENTRY cert_find_alt_name_entry ( PCCERT_CONTEXT  cert,
BOOL  alt_name_issuer,
DWORD  entry_type,
PCERT_ALT_NAME_INFO info 
)
static

Definition at line 960 of file str.c.

962{
963 unsigned int index = 0;
964
965 if (!cert_get_alt_name_info(cert, alt_name_issuer, info)) return NULL;
966 return cert_find_next_alt_name_entry(*info, entry_type, &index);
967}
#define NULL
Definition: types.h:112
static BOOL cert_get_alt_name_info(PCCERT_CONTEXT cert, BOOL alt_name_issuer, PCERT_ALT_NAME_INFO *info)
Definition: str.c:918
static PCERT_ALT_NAME_ENTRY cert_find_next_alt_name_entry(PCERT_ALT_NAME_INFO info, DWORD entry_type, unsigned int *index)
Definition: str.c:937
GLuint index
Definition: glext.h:6031
static BYTE cert[]
Definition: msg.c:1374

Referenced by CertGetNameStringW().

◆ cert_find_next_alt_name_entry()

static PCERT_ALT_NAME_ENTRY cert_find_next_alt_name_entry ( PCERT_ALT_NAME_INFO  info,
DWORD  entry_type,
unsigned int index 
)
static

Definition at line 937 of file str.c.

939{
940 unsigned int i;
941
942 for (i = *index; i < info->cAltEntry; ++i)
943 if (info->rgAltEntry[i].dwAltNameChoice == entry_type)
944 {
945 *index = i + 1;
946 return &info->rgAltEntry[i];
947 }
948 return NULL;
949}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by cert_find_alt_name_entry(), and CertGetNameStringW().

◆ cert_get_alt_name_info()

static BOOL cert_get_alt_name_info ( PCCERT_CONTEXT  cert,
BOOL  alt_name_issuer,
PCERT_ALT_NAME_INFO info 
)
static

Definition at line 918 of file str.c.

919{
920 static const char *oids[][2] =
921 {
924 };
926 DWORD bytes = 0;
927
928 ext = CertFindExtension(oids[!!alt_name_issuer][0], cert->pCertInfo->cExtension, cert->pCertInfo->rgExtension);
929 if (!ext)
930 ext = CertFindExtension(oids[!!alt_name_issuer][1], cert->pCertInfo->cExtension, cert->pCertInfo->rgExtension);
931 if (!ext) return FALSE;
932
933 return CryptDecodeObjectEx(cert->dwCertEncodingType, X509_ALTERNATE_NAME, ext->Value.pbData, ext->Value.cbData,
935}
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
BOOL WINAPI CryptDecodeObjectEx(DWORD dwCertEncodingType, LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
Definition: decode.c:6998
#define FALSE
Definition: types.h:117
PCERT_EXTENSION WINAPI CertFindExtension(LPCSTR pszObjId, DWORD cExtensions, CERT_EXTENSION rgExtensions[])
Definition: cert.c:2099
static const WCHAR *const ext[]
Definition: module.c:53
unsigned long DWORD
Definition: ntddk_ex.h:95
#define szOID_ISSUER_ALT_NAME2
Definition: wincrypt.h:3344
#define CRYPT_DECODE_ALLOC_FLAG
Definition: wincrypt.h:3612
#define szOID_SUBJECT_ALT_NAME
Definition: wincrypt.h:3336
#define szOID_SUBJECT_ALT_NAME2
Definition: wincrypt.h:3343
#define X509_ALTERNATE_NAME
Definition: wincrypt.h:3529
#define szOID_ISSUER_ALT_NAME
Definition: wincrypt.h:3337

Referenced by cert_find_alt_name_entry(), and CertGetNameStringW().

◆ cert_get_name_from_rdn_attr()

static DWORD cert_get_name_from_rdn_attr ( DWORD  encodingType,
const CERT_NAME_BLOB name,
LPCSTR  oid,
LPWSTR  pszNameString,
DWORD  cchNameString 
)
static

Definition at line 969 of file str.c.

971{
972 CERT_NAME_INFO *nameInfo;
973 DWORD bytes = 0, ret = 0;
974
975 if (CryptDecodeObjectEx(encodingType, X509_NAME, name->pbData,
976 name->cbData, CRYPT_DECODE_ALLOC_FLAG, NULL, &nameInfo, &bytes))
977 {
978 PCERT_RDN_ATTR nameAttr = NULL;
979
980 if (oid)
981 nameAttr = CertFindRDNAttr(oid, nameInfo);
982 else
983 {
984 static const LPCSTR attributeOIDs[] =
985 {
988 };
989 DWORD i;
990
991 for (i = 0; !nameAttr && i < ARRAY_SIZE(attributeOIDs); i++)
992 nameAttr = CertFindRDNAttr(attributeOIDs[i], nameInfo);
993 }
994 if (nameAttr)
995 ret = rdn_value_to_strW(nameAttr->dwValueType, &nameAttr->Value,
996 pszNameString, cchNameString, TRUE);
997 LocalFree(nameInfo);
998 }
999 return ret;
1000}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define TRUE
Definition: types.h:120
PCERT_RDN_ATTR WINAPI CertFindRDNAttr(LPCSTR pszObjId, PCERT_NAME_INFO pName)
Definition: cert.c:2122
static DWORD rdn_value_to_strW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, LPWSTR psz, DWORD csz, BOOL partial_copy)
Definition: str.c:65
return ret
Definition: mutex.c:146
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
DWORD dwValueType
Definition: wincrypt.h:266
CERT_RDN_VALUE_BLOB Value
Definition: wincrypt.h:267
Definition: name.c:39
const char * LPCSTR
Definition: typedefs.h:52
#define X509_NAME
Definition: wincrypt.h:3524
#define szOID_ORGANIZATIONAL_UNIT_NAME
Definition: wincrypt.h:3298
#define szOID_RSA_emailAddr
Definition: wincrypt.h:3188
#define szOID_COMMON_NAME
Definition: wincrypt.h:3290
#define szOID_ORGANIZATION_NAME
Definition: wincrypt.h:3297

Referenced by CertGetNameStringW().

◆ cert_name_to_str_with_indent()

DWORD cert_name_to_str_with_indent ( DWORD  dwCertEncodingType,
DWORD  indent,
const CERT_NAME_BLOB pName,
DWORD  dwStrType,
LPWSTR  psz,
DWORD  csz 
)

String functions

Definition at line 336 of file str.c.

338{
339 static const DWORD unsupportedFlags = CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG;
340 DWORD ret = 0, bytes = 0;
341 BOOL bRet;
343 DWORD chars;
344
345 if (dwStrType & unsupportedFlags)
346 FIXME("unsupported flags: %08lx\n", dwStrType & unsupportedFlags);
347
348 bRet = CryptDecodeObjectEx(dwCertEncodingType, X509_NAME, pName->pbData,
350 if (bRet)
351 {
352 DWORD i, j, sepLen, rdnSepLen;
353 LPCWSTR sep, rdnSep;
355 const CERT_RDN *rdn = info->rgRDN;
356
357 if(reverse && info->cRDN > 1) rdn += (info->cRDN - 1);
358
359 if (dwStrType & CERT_NAME_STR_SEMICOLON_FLAG)
360 sep = L"; ";
361 else if (dwStrType & CERT_NAME_STR_CRLF_FLAG)
362 sep = L"\r\n";
363 else
364 sep = L", ";
365 sepLen = lstrlenW(sep);
366 if (dwStrType & CERT_NAME_STR_NO_PLUS_FLAG)
367 rdnSep = L" ";
368 else
369 rdnSep = L" + ";
370 rdnSepLen = lstrlenW(rdnSep);
371 if (!csz) psz = NULL;
372 for (i = 0; i < info->cRDN; i++)
373 {
374 if (psz && ret + 1 == csz) break;
375 for (j = 0; j < rdn->cRDNAttr; j++)
376 {
377 LPCSTR prefixA = NULL;
378 LPCWSTR prefixW = NULL;
379
380 if (psz && ret + 1 == csz) break;
381
382 if ((dwStrType & 0x000000ff) == CERT_OID_NAME_STR)
383 prefixA = rdn->rgRDNAttr[j].pszObjId;
384 else if ((dwStrType & 0x000000ff) == CERT_X500_NAME_STR)
385 {
388 rdn->rgRDNAttr[j].pszObjId,
390
391 if (oidInfo)
392 prefixW = oidInfo->pwszName;
393 else
394 prefixA = rdn->rgRDNAttr[j].pszObjId;
395 }
396 if (dwStrType & CERT_NAME_STR_CRLF_FLAG)
397 {
398 DWORD k;
399
400 for (k = 0; k < indentLevel; k++)
401 {
402 if (psz)
403 {
404 chars = min(lstrlenW(indent), csz - ret - 1);
405 memcpy(psz + ret, indent, chars * sizeof(WCHAR));
406 }
407 else
408 chars = lstrlenW(indent);
409 ret += chars;
410 }
411 if (psz && ret + 1 == csz) break;
412 }
413 if (prefixW)
414 {
415 /* - 1 is needed to account for the NULL terminator. */
416 chars = CRYPT_AddPrefixW(prefixW,
417 psz ? psz + ret : NULL, psz ? csz - ret - 1 : 0);
418 ret += chars;
419 }
420 else if (prefixA)
421 {
422 /* - 1 is needed to account for the NULL terminator. */
423 chars = CRYPT_AddPrefixAToW(prefixA,
424 psz ? psz + ret : NULL, psz ? csz - ret - 1 : 0);
425 ret += chars;
426 }
427 if (psz && ret + 1 == csz) break;
428
429 chars = quote_rdn_value_to_str_w(rdn->rgRDNAttr[j].dwValueType, &rdn->rgRDNAttr[j].Value, dwStrType,
430 psz ? psz + ret : NULL, psz ? csz - ret - 1 : 0);
431 ret += chars;
432 if (j < rdn->cRDNAttr - 1)
433 {
434 if (psz)
435 {
436 chars = min(rdnSepLen, csz - ret - 1);
437 memcpy(psz + ret, rdnSep, chars * sizeof(WCHAR));
438 ret += chars;
439 }
440 else ret += rdnSepLen;
441 }
442 }
443 if (psz && ret + 1 == csz) break;
444 if (i < info->cRDN - 1)
445 {
446 if (psz)
447 {
448 chars = min(sepLen, csz - ret - 1);
449 memcpy(psz + ret, sep, chars * sizeof(WCHAR));
450 ret += chars;
451 }
452 else ret += sepLen;
453 }
454 if(reverse) rdn--;
455 else rdn++;
456 }
458 }
459 if (psz && csz) psz[ret] = 0;
460 return ret + 1;
461}
#define FIXME(fmt,...)
Definition: precomp.h:53
static struct list oidInfo
Definition: oid.c:1194
PCCRYPT_OID_INFO WINAPI CryptFindOIDInfo(DWORD dwKeyType, void *pvKey, DWORD dwGroupId)
Definition: oid.c:1714
static DWORD CRYPT_AddPrefixAToW(LPCSTR prefix, LPWSTR psz, DWORD csz)
Definition: str.c:290
static DWORD quote_rdn_value_to_str_w(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, DWORD dwStrType, LPWSTR psz, DWORD csz)
Definition: str.c:147
static const WCHAR indent[]
Definition: str.c:334
static DWORD CRYPT_AddPrefixW(LPCWSTR prefix, LPWSTR psz, DWORD csz)
Definition: str.c:316
#define lstrlenW
Definition: compat.h:750
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static LPSTR pName
Definition: security.c:86
#define min(a, b)
Definition: monoChain.cc:55
int k
Definition: mpi.c:3369
short WCHAR
Definition: pedump.c:58
LPSTR pszObjId
Definition: wincrypt.h:265
DWORD cRDNAttr
Definition: wincrypt.h:271
PCERT_RDN_ATTR rgRDNAttr
Definition: wincrypt.h:272
const uint16_t * LPCWSTR
Definition: typedefs.h:57
static void reverse(int *pidx, int cch)
Definition: bidi.c:1153
#define CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG
Definition: wincrypt.h:3652
#define CERT_X500_NAME_STR
Definition: wincrypt.h:3644
#define CERT_NAME_STR_NO_PLUS_FLAG
Definition: wincrypt.h:3646
#define CERT_NAME_STR_SEMICOLON_FLAG
Definition: wincrypt.h:3645
#define CRYPT_RDN_ATTR_OID_GROUP_ID
Definition: wincrypt.h:1941
#define CERT_NAME_STR_CRLF_FLAG
Definition: wincrypt.h:3648
#define CRYPT_OID_INFO_OID_KEY
Definition: wincrypt.h:1955
#define CERT_NAME_STR_REVERSE_FLAG
Definition: wincrypt.h:3650
#define CERT_OID_NAME_STR
Definition: wincrypt.h:3643

Referenced by CertGetNameStringW(), CertNameToStrW(), CRYPT_FormatAltNameEntry(), and name_value_to_str().

◆ CertGetNameStringA()

DWORD WINAPI CertGetNameStringA ( PCCERT_CONTEXT  cert,
DWORD  type,
DWORD  flags,
void type_para,
LPSTR  name,
DWORD  name_len 
)

Definition at line 883 of file str.c.

885{
886 DWORD len, len_mb, ret;
888
889 TRACE("(%p, %ld, %08lx, %p, %p, %ld)\n", cert, type, flags, type_para, name, name_len);
890
891 len = CertGetNameStringW(cert, type, flags, type_para, NULL, 0);
892
893 if (!(nameW = CryptMemAlloc(len * sizeof(*nameW))))
894 {
895 ERR("No memory.\n");
896 if (name && name_len) *name = 0;
897 return 1;
898 }
899
900 len = CertGetNameStringW(cert, type, flags, type_para, nameW, len);
901 len_mb = WideCharToMultiByte(CP_ACP, 0, nameW, len, NULL, 0, NULL, NULL);
902 if (!name || !name_len)
903 {
905 return len_mb;
906 }
907
908 ret = WideCharToMultiByte(CP_ACP, 0, nameW, len, name, name_len, NULL, NULL);
909 if (ret < len_mb)
910 {
911 name[0] = 0;
912 ret = 1;
913 }
915 return ret;
916}
static const WCHAR nameW[]
Definition: main.c:49
#define ERR(fmt,...)
Definition: precomp.h:57
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:136
VOID WINAPI CryptMemFree(LPVOID pv)
Definition: main.c:146
DWORD WINAPI CertGetNameStringW(PCCERT_CONTEXT cert, DWORD type, DWORD flags, void *type_para, LPWSTR name_string, DWORD name_len)
Definition: str.c:1013
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
#define TRACE(s)
Definition: solgame.cpp:4
uint16_t * LPWSTR
Definition: typedefs.h:56

Referenced by GetFriendlyNameOfCertA(), test_CertGetNameString(), and test_CertGetNameString_value_().

◆ CertGetNameStringW()

DWORD WINAPI CertGetNameStringW ( PCCERT_CONTEXT  cert,
DWORD  type,
DWORD  flags,
void type_para,
LPWSTR  name_string,
DWORD  name_len 
)

Definition at line 1013 of file str.c.

1015{
1016 static const DWORD supported_flags = CERT_NAME_ISSUER_FLAG | CERT_NAME_SEARCH_ALL_NAMES_FLAG;
1017 BOOL alt_name_issuer, search_all_names;
1021 DWORD ret = 0;
1022
1023 TRACE("(%p, %ld, %08lx, %p, %p, %ld)\n", cert, type, flags, type_para, name_string, name_len);
1024
1025 if (!cert)
1026 goto done;
1027
1028 if (flags & ~supported_flags)
1029 FIXME("Unsupported flags %#lx.\n", flags);
1030
1031 search_all_names = flags & CERT_NAME_SEARCH_ALL_NAMES_FLAG;
1032 if (search_all_names && type != CERT_NAME_DNS_TYPE)
1033 {
1034 WARN("CERT_NAME_SEARCH_ALL_NAMES_FLAG used with type %lu.\n", type);
1035 goto done;
1036 }
1037
1038 alt_name_issuer = flags & CERT_NAME_ISSUER_FLAG;
1039 name = alt_name_issuer ? &cert->pCertInfo->Issuer : &cert->pCertInfo->Subject;
1040
1041 switch (type)
1042 {
1044 {
1046
1047 if (entry)
1048 {
1049 ret = copy_output_str(name_string, entry->pwszRfc822Name, name_len);
1050 break;
1051 }
1053 name_string, name_len);
1054 break;
1055 }
1056 case CERT_NAME_RDN_TYPE:
1057 {
1058 DWORD param = type_para ? *(DWORD *)type_para : 0;
1059
1060 if (name->cbData)
1061 {
1062 ret = CertNameToStrW(cert->dwCertEncodingType, name, param, name_string, name_len);
1063 }
1064 else
1065 {
1067
1068 if (entry)
1069 ret = CertNameToStrW(cert->dwCertEncodingType, &entry->DirectoryName,
1070 param, name_string, name_len);
1071 }
1072 break;
1073 }
1075 ret = cert_get_name_from_rdn_attr(cert->dwCertEncodingType, name, type_para,
1076 name_string, name_len);
1077 if (ret) break;
1078
1080
1081 if (entry)
1083 0, name_string, name_len);
1084 break;
1086 {
1087 static const LPCSTR simpleAttributeOIDs[] =
1088 {
1090 };
1091 CERT_NAME_INFO *nameInfo = NULL;
1092 DWORD bytes = 0, i;
1093
1094 if (CryptDecodeObjectEx(cert->dwCertEncodingType, X509_NAME, name->pbData, name->cbData,
1095 CRYPT_DECODE_ALLOC_FLAG, NULL, &nameInfo, &bytes))
1096 {
1097 PCERT_RDN_ATTR nameAttr = NULL;
1098
1099 for (i = 0; !nameAttr && i < ARRAY_SIZE(simpleAttributeOIDs); i++)
1100 nameAttr = CertFindRDNAttr(simpleAttributeOIDs[i], nameInfo);
1101 if (nameAttr)
1102 ret = rdn_value_to_strW(nameAttr->dwValueType, &nameAttr->Value, name_string, name_len, TRUE);
1103 LocalFree(nameInfo);
1104 }
1105 if (ret) break;
1107 if (!info) break;
1108 if (!entry && info->cAltEntry)
1109 entry = &info->rgAltEntry[0];
1110 if (entry) ret = copy_output_str(name_string, entry->pwszRfc822Name, name_len);
1111 break;
1112 }
1114 {
1115 DWORD len = name_len;
1116
1118 ret = len;
1119 else
1121 type_para, name_string, name_len);
1122 break;
1123 }
1124 case CERT_NAME_DNS_TYPE:
1125 {
1126 unsigned int index = 0, len;
1127
1128 if (cert_get_alt_name_info(cert, alt_name_issuer, &info)
1130 {
1131 if (search_all_names)
1132 {
1133 do
1134 {
1135 if (name_string && name_len == 1) break;
1136 ret += len = copy_output_str(name_string, entry->pwszDNSName, name_len ? name_len - 1 : 0);
1137 if (name_string && name_len)
1138 {
1139 name_string += len;
1140 name_len -= len;
1141 }
1142 }
1144 }
1145 else ret = copy_output_str(name_string, entry->pwszDNSName, name_len);
1146 }
1147 else
1148 {
1149 if (!search_all_names || name_len != 1)
1150 {
1151 len = search_all_names && name_len ? name_len - 1 : name_len;
1153 name_string, len);
1154 if (name_string) name_string += ret;
1155 }
1156 }
1157
1158 if (search_all_names)
1159 {
1160 if (name_string && name_len) *name_string = 0;
1161 ++ret;
1162 }
1163 break;
1164 }
1165 case CERT_NAME_URL_TYPE:
1166 {
1167 if ((entry = cert_find_alt_name_entry(cert, alt_name_issuer, CERT_ALT_NAME_URL, &info)))
1168 ret = copy_output_str(name_string, entry->pwszURL, name_len);
1169 break;
1170 }
1171 default:
1172 FIXME("unimplemented for type %lu.\n", type);
1173 ret = 0;
1174 break;
1175 }
1176done:
1177 if (info)
1178 LocalFree(info);
1179
1180 if (!ret)
1181 {
1182 ret = 1;
1183 if (name_string && name_len) name_string[0] = 0;
1184 }
1185 return ret;
1186}
#define WARN(fmt,...)
Definition: precomp.h:61
BOOL WINAPI CertGetCertificateContextProperty(PCCERT_CONTEXT pCertContext, DWORD dwPropId, void *pvData, DWORD *pcbData)
Definition: cert.c:615
DWORD cert_name_to_str_with_indent(DWORD dwCertEncodingType, DWORD indentLevel, const CERT_NAME_BLOB *pName, DWORD dwStrType, LPWSTR psz, DWORD csz)
Definition: str.c:336
static PCERT_ALT_NAME_ENTRY cert_find_alt_name_entry(PCCERT_CONTEXT cert, BOOL alt_name_issuer, DWORD entry_type, PCERT_ALT_NAME_INFO *info)
Definition: str.c:960
static DWORD copy_output_str(WCHAR *dst, const WCHAR *src, DWORD dst_size)
Definition: str.c:1002
DWORD WINAPI CertNameToStrW(DWORD dwCertEncodingType, PCERT_NAME_BLOB pName, DWORD dwStrType, LPWSTR psz, DWORD csz)
Definition: str.c:463
static DWORD cert_get_name_from_rdn_attr(DWORD encodingType, const CERT_NAME_BLOB *name, LPCSTR oid, LPWSTR pszNameString, DWORD cchNameString)
Definition: str.c:969
GLfloat param
Definition: glext.h:5796
uint32_t entry
Definition: isohybrid.c:63
Definition: wincrypt.h:341
#define CERT_NAME_SIMPLE_DISPLAY_TYPE
Definition: wincrypt.h:3658
#define CERT_ALT_NAME_URL
Definition: wincrypt.h:360
#define CERT_NAME_EMAIL_TYPE
Definition: wincrypt.h:3655
#define CERT_ALT_NAME_DIRECTORY_NAME
Definition: wincrypt.h:358
#define CERT_ALT_NAME_RFC822_NAME
Definition: wincrypt.h:355
#define X509_ASN_ENCODING
Definition: wincrypt.h:2501
#define CERT_NAME_SEARCH_ALL_NAMES_FLAG
Definition: wincrypt.h:3665
#define CERT_FRIENDLY_NAME_PROP_ID
Definition: wincrypt.h:2844
#define CERT_NAME_DNS_TYPE
Definition: wincrypt.h:3660
#define CERT_ALT_NAME_DNS_NAME
Definition: wincrypt.h:356
#define CERT_NAME_RDN_TYPE
Definition: wincrypt.h:3656
#define CERT_NAME_ISSUER_FLAG
Definition: wincrypt.h:3664
#define CERT_NAME_ATTR_TYPE
Definition: wincrypt.h:3657
#define CERT_NAME_URL_TYPE
Definition: wincrypt.h:3661
#define CERT_NAME_FRIENDLY_DISPLAY_TYPE
Definition: wincrypt.h:3659

Referenced by add_cert_to_list(), add_cert_to_view(), CertGetNameStringA(), CertGetNameStringW(), dump_element(), get_cert_name_string(), GetFriendlyNameOfCertW(), CCert::GetNameString(), test_CertGetNameString(), and test_CertGetNameString_value_().

◆ CertNameToStrA()

DWORD WINAPI CertNameToStrA ( DWORD  encoding_type,
PCERT_NAME_BLOB  name_blob,
DWORD  str_type,
LPSTR  str,
DWORD  str_len 
)

Definition at line 250 of file str.c.

251{
252 DWORD len, len_mb, ret;
253 LPWSTR strW;
254
255 TRACE("(%ld, %p, %08lx, %p, %ld)\n", encoding_type, name_blob, str_type, str, str_len);
256
257 len = CertNameToStrW(encoding_type, name_blob, str_type, NULL, 0);
258
259 if (!(strW = CryptMemAlloc(len * sizeof(*strW))))
260 {
261 ERR("No memory.\n");
262 if (str && str_len) *str = 0;
263 return 1;
264 }
265
266 len = CertNameToStrW(encoding_type, name_blob, str_type, strW, len);
267 len_mb = WideCharToMultiByte(CP_ACP, 0, strW, len, NULL, 0, NULL, NULL);
268 if (!str || !str_len)
269 {
271 return len_mb;
272 }
273
275 if (ret < len_mb)
276 {
277 str[0] = 0;
278 ret = 1;
279 }
281 return ret;
282}
WCHAR strW[12]
Definition: clipboard.c:2216
const WCHAR * str
#define str_len
Definition: treelist.c:89

Referenced by _test_name_blob(), get_security_cert_struct(), test_CertNameToStrA(), and test_NameToStrConversionA_().

◆ CertNameToStrW()

DWORD WINAPI CertNameToStrW ( DWORD  dwCertEncodingType,
PCERT_NAME_BLOB  pName,
DWORD  dwStrType,
LPWSTR  psz,
DWORD  csz 
)

Definition at line 463 of file str.c.

465{
466 BOOL ret;
467
468 TRACE("(%ld, %p, %08lx, %p, %ld)\n", dwCertEncodingType, pName, dwStrType,
469 psz, csz);
470
471 ret = cert_name_to_str_with_indent(dwCertEncodingType, 0, pName, dwStrType,
472 psz, csz);
473 TRACE("Returning %s\n", debugstr_w(psz));
474 return ret;
475}
#define debugstr_w
Definition: kernel32.h:32

Referenced by blob_to_str(), CertGetNameStringW(), CertNameToStrA(), compare_cert_by_name_str(), field_format_detailed_cert_name(), test_CertNameToStrW(), test_NameToStrConversionW_(), and test_quoted_RDN().

◆ CertRDNValueToStrA()

DWORD WINAPI CertRDNValueToStrA ( DWORD  type,
PCERT_RDN_VALUE_BLOB  value_blob,
LPSTR  value,
DWORD  value_len 
)

Definition at line 30 of file str.c.

32{
33 DWORD len, len_mb, ret;
35
36 TRACE("(%ld, %p, %p, %ld)\n", type, value_blob, value, value_len);
37
38 len = CertRDNValueToStrW(type, value_blob, NULL, 0);
39
40 if (!(valueW = CryptMemAlloc(len * sizeof(*valueW))))
41 {
42 ERR("No memory.\n");
43 if (value && value_len) *value = 0;
44 return 1;
45 }
46
47 len = CertRDNValueToStrW(type, value_blob, valueW, len);
48 len_mb = WideCharToMultiByte(CP_ACP, 0, valueW, len, NULL, 0, NULL, NULL);
49 if (!value || !value_len)
50 {
52 return len_mb;
53 }
54
55 ret = WideCharToMultiByte(CP_ACP, 0, valueW, len, value, value_len, NULL, NULL);
56 if (ret < len_mb)
57 {
58 value[0] = 0;
59 ret = 1;
60 }
62 return ret;
63}
DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, LPWSTR psz, DWORD csz)
Definition: str.c:117
static WCHAR valueW[]
Definition: reg.c:1394
Definition: pdh_main.c:96

Referenced by get_cert_common_name(), and test_CertRDNValueToStrA().

◆ CertRDNValueToStrW()

DWORD WINAPI CertRDNValueToStrW ( DWORD  dwValueType,
PCERT_RDN_VALUE_BLOB  pValue,
LPWSTR  psz,
DWORD  csz 
)

Definition at line 117 of file str.c.

119{
120 return rdn_value_to_strW(dwValueType, pValue, psz, csz, FALSE);
121}
PWCHAR pValue

Referenced by CertRDNValueToStrA(), get_cps_str_from_qualifier(), and test_CertRDNValueToStrW().

◆ CertStrToNameA()

BOOL WINAPI CertStrToNameA ( DWORD  dwCertEncodingType,
LPCSTR  pszX500,
DWORD  dwStrType,
void pvReserved,
BYTE pbEncoded,
DWORD pcbEncoded,
LPCSTR ppszError 
)

Definition at line 477 of file str.c.

480{
481 BOOL ret;
482 int len;
483
484 TRACE("(%08lx, %s, %08lx, %p, %p, %p, %p)\n", dwCertEncodingType,
485 debugstr_a(pszX500), dwStrType, pvReserved, pbEncoded, pcbEncoded,
486 ppszError);
487
488 len = MultiByteToWideChar(CP_ACP, 0, pszX500, -1, NULL, 0);
489 if (len)
490 {
491 LPWSTR x500, errorStr;
492
493 if ((x500 = CryptMemAlloc(len * sizeof(WCHAR))))
494 {
495 MultiByteToWideChar(CP_ACP, 0, pszX500, -1, x500, len);
496 ret = CertStrToNameW(dwCertEncodingType, x500, dwStrType,
497 pvReserved, pbEncoded, pcbEncoded,
498 ppszError ? (LPCWSTR *)&errorStr : NULL);
499 if (ppszError)
500 {
501 if (!ret)
502 {
503 LONG i;
504
505 *ppszError = pszX500;
506 for (i = 0; i < errorStr - x500; i++)
507 *ppszError = CharNextA(*ppszError);
508 }
509 else
510 *ppszError = NULL;
511 }
512 CryptMemFree(x500);
513 }
514 else
515 {
517 ret = FALSE;
518 }
519 }
520 else
521 {
523 if (ppszError)
524 *ppszError = pszX500;
525 ret = FALSE;
526 }
527 return ret;
528}
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500, DWORD dwStrType, void *pvReserved, BYTE *pbEncoded, DWORD *pcbEncoded, LPCWSTR *ppszError)
Definition: str.c:785
#define SetLastError(x)
Definition: compat.h:752
#define MultiByteToWideChar
Definition: compat.h:110
LPSTR WINAPI CharNextA(const char *ptr)
Definition: string.c:1151
#define debugstr_a
Definition: kernel32.h:31
static LPCWSTR LPVOID pvReserved
Definition: asmcache.c:749
long LONG
Definition: pedump.c:60
#define CRYPT_E_INVALID_X500_STRING
Definition: winerror.h:4441

Referenced by test_CertStrToNameA().

◆ CertStrToNameW()

BOOL WINAPI CertStrToNameW ( DWORD  dwCertEncodingType,
LPCWSTR  pszX500,
DWORD  dwStrType,
void pvReserved,
BYTE pbEncoded,
DWORD pcbEncoded,
LPCWSTR ppszError 
)

Definition at line 785 of file str.c.

788{
789 CERT_NAME_INFO info = { 0, NULL };
790 LPCWSTR str;
791 struct KeynameKeeper keeper;
792 DWORD i;
793 BOOL ret = TRUE;
794
795 TRACE("(%08lx, %s, %08lx, %p, %p, %p, %p)\n", dwCertEncodingType,
796 debugstr_w(pszX500), dwStrType, pvReserved, pbEncoded, pcbEncoded,
797 ppszError);
798
800 str = pszX500;
801 while (str && *str && ret)
802 {
803 struct X500TokenW token;
804
805 ret = CRYPT_GetNextKeyW(str, &token, ppszError);
806 if (ret && token.start)
807 {
808 PCCRYPT_OID_INFO keyOID;
809
811 keyOID = CryptFindOIDInfo(CRYPT_OID_INFO_NAME_KEY, keeper.keyName,
813 if (!keyOID)
814 {
815 if (ppszError)
816 *ppszError = token.start;
818 ret = FALSE;
819 }
820 else
821 {
822 str = token.end;
823 while (iswspace(*str))
824 str++;
825 if (*str != '=')
826 {
827 if (ppszError)
828 *ppszError = str;
830 ret = FALSE;
831 }
832 else
833 {
834 LPCWSTR sep;
835 WCHAR sep_used;
836
837 str++;
838 if (dwStrType & CERT_NAME_STR_COMMA_FLAG)
839 sep = L",";
840 else if (dwStrType & CERT_NAME_STR_SEMICOLON_FLAG)
841 sep = L";";
842 else if (dwStrType & CERT_NAME_STR_CRLF_FLAG)
843 sep = L"\r\n";
844 else if (dwStrType & CERT_NAME_STR_NO_PLUS_FLAG)
845 sep = L",;\r\n";
846 else
847 sep = L"+,;\r\n";
848 ret = CRYPT_GetNextValueW(str, dwStrType, sep, &sep_used, &token,
849 ppszError);
850 if (ret)
851 {
852 str = token.end;
853 /* if token.end points to the separator, skip it */
854 if (str && sep_used && *str == sep_used) str++;
855
856 ret = CRYPT_ValueToRDN(dwCertEncodingType, &info,
857 keyOID, &token, dwStrType, ppszError);
858 }
859 }
860 }
861 }
862 }
864 if (ret)
865 {
866 if (ppszError)
867 *ppszError = NULL;
868 ret = CryptEncodeObjectEx(dwCertEncodingType, X509_NAME, &info,
869 0, NULL, pbEncoded, pcbEncoded);
870 }
871 for (i = 0; i < info.cRDN; i++)
872 {
873 DWORD j;
874
875 for (j = 0; j < info.rgRDN[i].cRDNAttr; j++)
876 LocalFree(info.rgRDN[i].rgRDNAttr[j].Value.pbData);
877 CryptMemFree(info.rgRDN[i].rgRDNAttr);
878 }
879 CryptMemFree(info.rgRDN);
880 return ret;
881}
BOOL WINAPI CryptEncodeObjectEx(DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, void *pvEncoded, DWORD *pcbEncoded)
Definition: encode.c:4950
static void CRYPT_FreeKeynameKeeper(struct KeynameKeeper *keeper)
Definition: str.c:543
static BOOL CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators, WCHAR *separator_used, struct X500TokenW *token, LPCWSTR *ppszError)
Definition: str.c:600
static void CRYPT_InitializeKeynameKeeper(struct KeynameKeeper *keeper)
Definition: str.c:537
static void CRYPT_KeynameKeeperFromTokenW(struct KeynameKeeper *keeper, const struct X500TokenW *key)
Definition: str.c:555
static BOOL CRYPT_ValueToRDN(DWORD dwCertEncodingType, PCERT_NAME_INFO info, PCCRYPT_OID_INFO keyOID, struct X500TokenW *value, DWORD dwStrType, LPCWSTR *ppszError)
Definition: str.c:733
static BOOL CRYPT_GetNextKeyW(LPCWSTR str, struct X500TokenW *token, LPCWSTR *ppszError)
Definition: str.c:571
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
#define iswspace(_c)
Definition: ctype.h:669
#define CRYPT_OID_INFO_NAME_KEY
Definition: wincrypt.h:1956
#define CERT_NAME_STR_COMMA_FLAG
Definition: wincrypt.h:3649

Referenced by CertStrToNameA(), test_CertStrToNameW(), and testGetIssuerCert().

◆ copy_output_str()

static DWORD copy_output_str ( WCHAR dst,
const WCHAR src,
DWORD  dst_size 
)
static

Definition at line 1002 of file str.c.

1003{
1004 DWORD len = wcslen(src);
1005
1006 if (!dst || !dst_size) return len + 1;
1007 len = min(len, dst_size - 1);
1008 memcpy(dst, src, len * sizeof(*dst));
1009 dst[len] = 0;
1010 return len + 1;
1011}
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by CertGetNameStringW().

◆ CRYPT_AddPrefixAToW()

static DWORD CRYPT_AddPrefixAToW ( LPCSTR  prefix,
LPWSTR  psz,
DWORD  csz 
)
static

Definition at line 290 of file str.c.

291{
292 DWORD chars;
293
294 TRACE("(%s, %p, %ld)\n", debugstr_a(prefix), psz, csz);
295
296 if (psz)
297 {
298 DWORD i;
299
300 chars = min(strlen(prefix), csz);
301 for (i = 0; i < chars; i++)
302 *(psz + i) = prefix[i];
303 *(psz + chars) = '=';
304 chars++;
305 }
306 else
307 chars = lstrlenA(prefix) + 1;
308 return chars;
309}
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
Character const *const prefix
Definition: tempnam.cpp:195

Referenced by cert_name_to_str_with_indent().

◆ CRYPT_AddPrefixW()

static DWORD CRYPT_AddPrefixW ( LPCWSTR  prefix,
LPWSTR  psz,
DWORD  csz 
)
static

Definition at line 316 of file str.c.

317{
318 DWORD chars;
319
320 TRACE("(%s, %p, %ld)\n", debugstr_w(prefix), psz, csz);
321
322 if (psz)
323 {
324 chars = min(lstrlenW(prefix), csz);
325 memcpy(psz, prefix, chars * sizeof(WCHAR));
326 *(psz + chars) = '=';
327 chars++;
328 }
329 else
330 chars = lstrlenW(prefix) + 1;
331 return chars;
332}

Referenced by cert_name_to_str_with_indent().

◆ CRYPT_EncodeValue()

static BOOL CRYPT_EncodeValue ( DWORD  dwCertEncodingType,
const struct X500TokenW value,
PCERT_NAME_BLOB  output,
const DWORD types,
LPCWSTR ppszError 
)
static

Definition at line 719 of file str.c.

722{
723 DWORD i;
724 BOOL ret;
725
726 ret = FALSE;
727 for (i = 0; !ret && types[i]; i++)
728 ret = CRYPT_EncodeValueWithType(dwCertEncodingType, value, output,
729 types[i], ppszError);
730 return ret;
731}
static BOOL CRYPT_EncodeValueWithType(DWORD dwCertEncodingType, const struct X500TokenW *value, PCERT_NAME_BLOB output, DWORD type, LPCWSTR *ppszError)
Definition: str.c:667
Definition: cmds.c:130

Referenced by CRYPT_ValueToRDN().

◆ CRYPT_EncodeValueWithType()

static BOOL CRYPT_EncodeValueWithType ( DWORD  dwCertEncodingType,
const struct X500TokenW value,
PCERT_NAME_BLOB  output,
DWORD  type,
LPCWSTR ppszError 
)
static

Definition at line 667 of file str.c.

670{
671 CERT_NAME_VALUE nameValue = { type, { 0, NULL } };
672 BOOL ret = TRUE;
673
674 if (value->end > value->start)
675 {
676 LONG i;
677 LPWSTR ptr;
678
679 nameValue.Value.pbData = CryptMemAlloc((value->end - value->start + 1) *
680 sizeof(WCHAR));
681 if (!nameValue.Value.pbData)
682 {
684 return FALSE;
685 }
686 ptr = (LPWSTR)nameValue.Value.pbData;
687 for (i = 0; i < value->end - value->start; i++)
688 {
689 *ptr++ = value->start[i];
690 if (value->start[i] == '"')
691 i++;
692 }
693 /* The string is NULL terminated because of a quirk in encoding
694 * unicode names values: if the length is given as 0, the value is
695 * assumed to be a NULL-terminated string.
696 */
697 *ptr = 0;
698 nameValue.Value.cbData = (LPBYTE)ptr - nameValue.Value.pbData;
699 }
700 ret = CryptEncodeObjectEx(dwCertEncodingType, X509_UNICODE_NAME_VALUE,
701 &nameValue, CRYPT_ENCODE_ALLOC_FLAG, NULL, &output->pbData,
702 &output->cbData);
703 if (!ret && ppszError)
704 {
707 *ppszError = value->start + output->cbData;
708 else if (type == CERT_RDN_PRINTABLE_STRING &&
710 *ppszError = value->start + output->cbData;
711 else if (type == CERT_RDN_IA5_STRING &&
713 *ppszError = value->start + output->cbData;
714 }
715 CryptMemFree(nameValue.Value.pbData);
716 return ret;
717}
static PVOID ptr
Definition: dispmode.c:27
for(i=0;i< sizeof(testsuite)/sizeof(testsuite[0]);++i) ok(call_test(testsuite[i].func)
CERT_RDN_VALUE_BLOB Value
Definition: wincrypt.h:282
BYTE * pbData
Definition: wincrypt.h:112
unsigned char * LPBYTE
Definition: typedefs.h:53
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CERT_RDN_IA5_STRING
Definition: wincrypt.h:2931
#define CERT_RDN_PRINTABLE_STRING
Definition: wincrypt.h:2927
#define CRYPT_ENCODE_ALLOC_FLAG
Definition: wincrypt.h:3599
#define CERT_RDN_NUMERIC_STRING
Definition: wincrypt.h:2926
#define X509_UNICODE_NAME_VALUE
Definition: wincrypt.h:3541
#define CRYPT_E_INVALID_PRINTABLE_STRING
Definition: winerror.h:4439
#define CRYPT_E_INVALID_IA5_STRING
Definition: winerror.h:4440
#define CRYPT_E_INVALID_NUMERIC_STRING
Definition: winerror.h:4438

Referenced by CRYPT_EncodeValue().

◆ CRYPT_FreeKeynameKeeper()

static void CRYPT_FreeKeynameKeeper ( struct KeynameKeeper keeper)
static

Definition at line 543 of file str.c.

544{
545 if (keeper->keyName != keeper->buf)
546 CryptMemFree(keeper->keyName);
547}
LPWSTR keyName
Definition: str.c:533
WCHAR buf[10]
Definition: str.c:532

Referenced by CertStrToNameW(), and CRYPT_KeynameKeeperFromTokenW().

◆ CRYPT_GetNextKeyW()

static BOOL CRYPT_GetNextKeyW ( LPCWSTR  str,
struct X500TokenW token,
LPCWSTR ppszError 
)
static

Definition at line 571 of file str.c.

573{
574 BOOL ret = TRUE;
575
576 while (*str && iswspace(*str))
577 str++;
578 if (*str)
579 {
580 token->start = str;
581 while (*str && *str != '=' && !iswspace(*str))
582 str++;
583 if (*str && (*str == '=' || iswspace(*str)))
584 token->end = str;
585 else
586 {
587 TRACE("missing equals char at %s\n", debugstr_w(token->start));
588 if (ppszError)
589 *ppszError = token->start;
591 ret = FALSE;
592 }
593 }
594 else
595 token->start = NULL;
596 return ret;
597}

Referenced by CertStrToNameW().

◆ CRYPT_GetNextValueW()

static BOOL CRYPT_GetNextValueW ( LPCWSTR  str,
DWORD  dwFlags,
LPCWSTR  separators,
WCHAR separator_used,
struct X500TokenW token,
LPCWSTR ppszError 
)
static

Definition at line 600 of file str.c.

602{
603 BOOL ret = TRUE;
604
605 TRACE("(%s, %s, %p, %p)\n", debugstr_w(str), debugstr_w(separators), token,
606 ppszError);
607
608 *separator_used = 0;
609 while (*str && iswspace(*str))
610 str++;
611 if (*str)
612 {
613 token->start = str;
614 if (!(dwFlags & CERT_NAME_STR_NO_QUOTING_FLAG) && *str == '"')
615 {
616 token->end = NULL;
617 str++;
618 while (!token->end && ret)
619 {
620 while (*str && *str != '"')
621 str++;
622 if (*str == '"')
623 {
624 if (*(str + 1) != '"')
625 token->end = str + 1;
626 else
627 str += 2;
628 }
629 else
630 {
631 TRACE("unterminated quote at %s\n", debugstr_w(str));
632 if (ppszError)
633 *ppszError = str;
635 ret = FALSE;
636 }
637 }
638 }
639 else
640 {
641 WCHAR map[256] = { 0 };
642
643 while (*separators)
644 map[*separators++] = 1;
645 while (*str && (*str >= 0xff || !map[*str]))
646 str++;
647 token->end = str;
648 if (map[*str]) *separator_used = *str;
649 }
650 }
651 else
652 {
653 TRACE("missing value at %s\n", debugstr_w(str));
654 if (ppszError)
655 *ppszError = str;
657 ret = FALSE;
658 }
659 return ret;
660}
Definition: _map.h:48
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
#define CERT_NAME_STR_NO_QUOTING_FLAG
Definition: wincrypt.h:3647

Referenced by CertStrToNameW().

◆ CRYPT_InitializeKeynameKeeper()

static void CRYPT_InitializeKeynameKeeper ( struct KeynameKeeper keeper)
static

Definition at line 537 of file str.c.

538{
539 keeper->keyName = keeper->buf;
540 keeper->keyLen = ARRAY_SIZE(keeper->buf);
541}
DWORD keyLen
Definition: str.c:534

Referenced by CertStrToNameW().

◆ CRYPT_KeynameKeeperFromTokenW()

static void CRYPT_KeynameKeeperFromTokenW ( struct KeynameKeeper keeper,
const struct X500TokenW key 
)
static

Definition at line 555 of file str.c.

557{
558 DWORD len = key->end - key->start;
559
560 if (len >= keeper->keyLen)
561 {
562 CRYPT_FreeKeynameKeeper( keeper );
563 keeper->keyLen = len + 1;
564 keeper->keyName = CryptMemAlloc(keeper->keyLen * sizeof(WCHAR));
565 }
566 memcpy(keeper->keyName, key->start, len * sizeof(WCHAR));
567 keeper->keyName[len] = '\0';
568 TRACE("Keyname is %s\n", debugstr_w(keeper->keyName));
569}
Definition: copy.c:22

Referenced by CertStrToNameW().

◆ CRYPT_ValueToRDN()

static BOOL CRYPT_ValueToRDN ( DWORD  dwCertEncodingType,
PCERT_NAME_INFO  info,
PCCRYPT_OID_INFO  keyOID,
struct X500TokenW value,
DWORD  dwStrType,
LPCWSTR ppszError 
)
static

Definition at line 733 of file str.c.

735{
736 BOOL ret = FALSE;
737
738 TRACE("OID %s, value %s\n", debugstr_a(keyOID->pszOID),
739 debugstr_wn(value->start, value->end - value->start));
740
741 if (!info->rgRDN)
742 info->rgRDN = CryptMemAlloc(sizeof(CERT_RDN));
743 else
744 info->rgRDN = CryptMemRealloc(info->rgRDN,
745 (info->cRDN + 1) * sizeof(CERT_RDN));
746 if (info->rgRDN)
747 {
748 /* FIXME: support multiple RDN attrs */
749 info->rgRDN[info->cRDN].rgRDNAttr =
751 if (info->rgRDN[info->cRDN].rgRDNAttr)
752 {
753 static const DWORD defaultTypes[] = { CERT_RDN_PRINTABLE_STRING,
755 const DWORD *types;
756
757 info->rgRDN[info->cRDN].cRDNAttr = 1;
758 info->rgRDN[info->cRDN].rgRDNAttr[0].pszObjId =
759 (LPSTR)keyOID->pszOID;
760 info->rgRDN[info->cRDN].rgRDNAttr[0].dwValueType =
762 if (keyOID->ExtraInfo.cbData)
763 types = (const DWORD *)keyOID->ExtraInfo.pbData;
764 else
765 types = defaultTypes;
766
767 /* Remove surrounding quotes */
768 if (value->start[0] == '"' && !(dwStrType & CERT_NAME_STR_NO_QUOTING_FLAG))
769 {
770 value->start++;
771 value->end--;
772 }
773 ret = CRYPT_EncodeValue(dwCertEncodingType, value,
774 &info->rgRDN[info->cRDN].rgRDNAttr[0].Value, types, ppszError);
775 }
776 else
778 info->cRDN++;
779 }
780 else
782 return ret;
783}
LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
Definition: main.c:141
static BOOL CRYPT_EncodeValue(DWORD dwCertEncodingType, const struct X500TokenW *value, PCERT_NAME_BLOB output, const DWORD *types, LPCWSTR *ppszError)
Definition: str.c:719
#define debugstr_wn
Definition: kernel32.h:33
if(dx< 0)
Definition: linetemp.h:194
CRYPT_DATA_BLOB ExtraInfo
Definition: wincrypt.h:1626
char * LPSTR
Definition: typedefs.h:51
#define CERT_RDN_ENCODED_BLOB
Definition: wincrypt.h:2924
#define CERT_RDN_BMP_STRING
Definition: wincrypt.h:2938

Referenced by CertStrToNameW().

◆ is_quotable_char()

static BOOL is_quotable_char ( WCHAR  c)
inlinestatic

Definition at line 123 of file str.c.

124{
125 switch(c)
126 {
127 case '+':
128 case ',':
129 case '"':
130 case '=':
131 case '<':
132 case '>':
133 case ';':
134 case '#':
135 case '\n':
136 return TRUE;
137 default:
138 return FALSE;
139 }
140}
const GLubyte * c
Definition: glext.h:8905

Referenced by quote_rdn_value_to_str_w().

◆ is_spaceW()

static BOOL is_spaceW ( WCHAR  c)
inlinestatic

Definition at line 142 of file str.c.

143{
144 return c <= 0x7f && isspace((char)c);
145}
#define isspace(c)
Definition: acclib.h:69

Referenced by quote_rdn_value_to_str_w().

◆ quote_rdn_value_to_str_w()

static DWORD quote_rdn_value_to_str_w ( DWORD  dwValueType,
PCERT_RDN_VALUE_BLOB  pValue,
DWORD  dwStrType,
LPWSTR  psz,
DWORD  csz 
)
static

Definition at line 147 of file str.c.

149{
150 DWORD ret = 0, len, i, strLen;
151 BOOL needsQuotes = FALSE;
152
153 TRACE("(%ld, %p, %p, %ld)\n", dwValueType, pValue, psz, csz);
154
155 switch (dwValueType)
156 {
158 break;
167 len = pValue->cbData;
168 if (!(dwStrType & CERT_NAME_STR_NO_QUOTING_FLAG))
169 {
170 if (pValue->cbData && isspace(pValue->pbData[0]))
171 needsQuotes = TRUE;
172 if (pValue->cbData && isspace(pValue->pbData[pValue->cbData - 1]))
173 needsQuotes = TRUE;
174 for (i = 0; i < pValue->cbData; i++)
175 {
176 if (is_quotable_char(pValue->pbData[i]))
177 needsQuotes = TRUE;
178 if (pValue->pbData[i] == '"')
179 len += 1;
180 }
181 if (needsQuotes)
182 len += 2;
183 }
184 if (!psz || !csz)
185 ret = len;
186 else
187 {
188 WCHAR *ptr = psz;
189
190 if (needsQuotes)
191 *ptr++ = '"';
192 for (i = 0; i < pValue->cbData && ptr - psz < csz; ptr++, i++)
193 {
194 *ptr = pValue->pbData[i];
195 if (!(dwStrType & CERT_NAME_STR_NO_QUOTING_FLAG) &&
196 pValue->pbData[i] == '"' && ptr - psz < csz - 1)
197 *(++ptr) = '"';
198 }
199 if (needsQuotes && ptr - psz < csz)
200 *ptr++ = '"';
201 ret = ptr - psz;
202 }
203 break;
206 strLen = len = pValue->cbData / sizeof(WCHAR);
207 if (!(dwStrType & CERT_NAME_STR_NO_QUOTING_FLAG))
208 {
209 if (strLen && is_spaceW(((LPCWSTR)pValue->pbData)[0]))
210 needsQuotes = TRUE;
211 if (strLen && is_spaceW(((LPCWSTR)pValue->pbData)[strLen - 1]))
212 needsQuotes = TRUE;
213 for (i = 0; i < strLen; i++)
214 {
215 if (is_quotable_char(((LPCWSTR)pValue->pbData)[i]))
216 needsQuotes = TRUE;
217 if (((LPCWSTR)pValue->pbData)[i] == '"')
218 len += 1;
219 }
220 if (needsQuotes)
221 len += 2;
222 }
223 if (!psz || !csz)
224 ret = len;
225 else
226 {
227 WCHAR *ptr = psz;
228
229 if (needsQuotes)
230 *ptr++ = '"';
231 for (i = 0; i < strLen && ptr - psz < csz; ptr++, i++)
232 {
233 *ptr = ((LPCWSTR)pValue->pbData)[i];
234 if (!(dwStrType & CERT_NAME_STR_NO_QUOTING_FLAG) &&
235 ((LPCWSTR)pValue->pbData)[i] == '"' && ptr - psz < csz - 1)
236 *(++ptr) = '"';
237 }
238 if (needsQuotes && ptr - psz < csz)
239 *ptr++ = '"';
240 ret = ptr - psz;
241 }
242 break;
243 default:
244 FIXME("string type %ld unimplemented\n", dwValueType);
245 }
246 TRACE("returning %ld (%s)\n", ret, debugstr_w(psz));
247 return ret;
248}
static BOOL is_quotable_char(WCHAR c)
Definition: str.c:123
static BOOL is_spaceW(WCHAR c)
Definition: str.c:142
#define CERT_RDN_UTF8_STRING
Definition: wincrypt.h:2940
#define CERT_RDN_GENERAL_STRING
Definition: wincrypt.h:2935
#define CERT_RDN_VISIBLE_STRING
Definition: wincrypt.h:2933
#define CERT_RDN_VIDEOTEX_STRING
Definition: wincrypt.h:2930
#define CERT_RDN_TELETEX_STRING
Definition: wincrypt.h:2928
#define CERT_RDN_ANY_TYPE
Definition: wincrypt.h:2923
#define CERT_RDN_GRAPHIC_STRING
Definition: wincrypt.h:2932

Referenced by cert_name_to_str_with_indent().

◆ rdn_value_to_strW()

static DWORD rdn_value_to_strW ( DWORD  dwValueType,
PCERT_RDN_VALUE_BLOB  pValue,
LPWSTR  psz,
DWORD  csz,
BOOL  partial_copy 
)
static

Definition at line 65 of file str.c.

67{
68 DWORD ret = 0, len, i;
69
70 TRACE("(%ld, %p, %p, %ld)\n", dwValueType, pValue, psz, csz);
71
72 switch (dwValueType)
73 {
75 break;
84 len = pValue->cbData;
85 if (!psz || !csz) ret = len;
86 else if (len < csz || partial_copy)
87 {
88 len = min(len, csz - 1);
89 for (i = 0; i < len; ++i)
90 psz[i] = pValue->pbData[i];
91 ret = len;
92 }
93 break;
96 len = pValue->cbData / sizeof(WCHAR);
97 if (!psz || !csz)
98 ret = len;
99 else if (len < csz || partial_copy)
100 {
101 WCHAR *ptr = psz;
102
103 len = min(len, csz - 1);
104 for (i = 0; i < len; ++i)
105 ptr[i] = ((LPCWSTR)pValue->pbData)[i];
106 ret = len;
107 }
108 break;
109 default:
110 FIXME("string type %ld unimplemented\n", dwValueType);
111 }
112 if (psz && csz) psz[ret] = 0;
113 TRACE("returning %ld (%s)\n", ret + 1, debugstr_w(psz));
114 return ret + 1;
115}

Referenced by cert_get_name_from_rdn_attr(), CertGetNameStringW(), and CertRDNValueToStrW().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( crypt  )

Variable Documentation

◆ indent

const WCHAR indent[] = L" "
static

Definition at line 334 of file str.c.

Referenced by cert_name_to_str_with_indent().