86290c0084d7ec33a1d18e050d018a0d9a411395
[reactos.git] / rostests / winetests / crypt32 / str.c
1 /*
2 * Unit test suite for crypt32.dll's Cert*ToStr and CertStrToName functions.
3 *
4 * Copyright 2006 Juan Lang, Aric Stewart for CodeWeavers
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20 //#include <stdio.h>
21 #include <stdarg.h>
22 #include <windef.h>
23 #include <winbase.h>
24 //#include <winerror.h>
25 #include <wincrypt.h>
26
27 #include <wine/test.h>
28
29 typedef struct _CertRDNAttrEncoding {
30 LPCSTR pszObjId;
31 DWORD dwValueType;
32 CERT_RDN_VALUE_BLOB Value;
33 LPCSTR str;
34 BOOL todo;
35 } CertRDNAttrEncoding, *PCertRDNAttrEncoding;
36
37 typedef struct _CertRDNAttrEncodingW {
38 LPCSTR pszObjId;
39 DWORD dwValueType;
40 CERT_RDN_VALUE_BLOB Value;
41 LPCWSTR str;
42 BOOL todo;
43 } CertRDNAttrEncodingW, *PCertRDNAttrEncodingW;
44
45 static BYTE bin1[] = { 0x55, 0x53 };
46 static BYTE bin2[] = { 0x4d, 0x69, 0x6e, 0x6e, 0x65, 0x73, 0x6f, 0x74,
47 0x61 };
48 static BYTE bin3[] = { 0x4d, 0x69, 0x6e, 0x6e, 0x65, 0x61, 0x70, 0x6f,
49 0x6c, 0x69, 0x73 };
50 static BYTE bin4[] = { 0x43, 0x6f, 0x64, 0x65, 0x57, 0x65, 0x61, 0x76,
51 0x65, 0x72, 0x73 };
52 static BYTE bin5[] = { 0x57, 0x69, 0x6e, 0x65, 0x20, 0x44, 0x65, 0x76,
53 0x65, 0x6c, 0x6f, 0x70, 0x6d, 0x65, 0x6e, 0x74 };
54 static BYTE bin6[] = { 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73,
55 0x74 };
56 static BYTE bin7[] = { 0x61, 0x72, 0x69, 0x63, 0x40, 0x63, 0x6f, 0x64,
57 0x65, 0x77, 0x65, 0x61, 0x76, 0x65, 0x72, 0x73, 0x2e, 0x63, 0x6f, 0x6d };
58 static BYTE bin8[] = {
59 0x65,0x00,0x50,0x00,0x4b,0x00,0x49,0x00,0x20,0x00,0x52,0x00,0x6f,0x00,0x6f,
60 0x00,0x74,0x00,0x20,0x00,0x43,0x00,0x65,0x00,0x72,0x00,0x74,0x00,0x69,0x00,
61 0x66,0x00,0x69,0x00,0x63,0x00,0x61,0x00,0x74,0x00,0x69,0x00,0x6f,0x00,0x6e,
62 0x00,0x20,0x00,0x41,0x00,0x75,0x00,0x74,0x00,0x68,0x00,0x6f,0x00,0x72,0x00,
63 0x69,0x00,0x74,0x00,0x79,0x00 };
64 static BYTE bin9[] = { 0x61, 0x62, 0x63, 0x22, 0x64, 0x65, 0x66 };
65 static BYTE bin10[] = { 0x61, 0x62, 0x63, 0x27, 0x64, 0x65, 0x66 };
66 static BYTE bin11[] = { 0x61, 0x62, 0x63, 0x2c, 0x20, 0x64, 0x65, 0x66 };
67 static BYTE bin12[] = { 0x20, 0x61, 0x62, 0x63, 0x20 };
68 static BYTE bin13[] = { 0x22, 0x64, 0x65, 0x66, 0x22 };
69 static BYTE bin14[] = { 0x31, 0x3b, 0x33 };
70
71 static const BYTE cert[] =
72 {0x30,0x82,0x2,0xbb,0x30,0x82,0x2,0x24,0x2,0x9,0x0,0xe3,0x5a,0x10,0xf1,0xfc,
73 0x4b,0xf3,0xa2,0x30,0xd,0x6,0x9,0x2a,0x86,0x48,0x86,0xf7,0xd,0x1,0x1,0x4,0x5,
74 0x0,0x30,0x81,0xa1,0x31,0xb,0x30,0x9,0x6,0x3,0x55,0x4,0x6,0x13,0x2,0x55,0x53,
75 0x31,0x12,0x30,0x10,0x6,0x3,0x55,0x4,0x8,0x13,0x9,0x4d,0x69,0x6e,0x6e,0x65,
76 0x73,0x6f,0x74,0x61,0x31,0x14,0x30,0x12,0x6,0x3,0x55,0x4,0x7,0x13,0xb,0x4d,
77 0x69,0x6e,0x6e,0x65,0x61,0x70,0x6f,0x6c,0x69,0x73,0x31,0x14,0x30,0x12,0x6,0x3,
78 0x55,0x4,0xa,0x13,0xb,0x43,0x6f,0x64,0x65,0x57,0x65,0x61,0x76,0x65,0x72,0x73,
79 0x31,0x19,0x30,0x17,0x6,0x3,0x55,0x4,0xb,0x13,0x10,0x57,0x69,0x6e,0x65,0x20,
80 0x44,0x65,0x76,0x65,0x6c,0x6f,0x70,0x6d,0x65,0x6e,0x74,0x31,0x12,0x30,0x10,
81 0x6,0x3,0x55,0x4,0x3,0x13,0x9,0x6c,0x6f,0x63,0x61,0x6c,0x68,0x6f,0x73,0x74,
82 0x31,0x23,0x30,0x21,0x6,0x9,0x2a,0x86,0x48,0x86,0xf7,0xd,0x1,0x9,0x1,0x16,
83 0x14,0x61,0x72,0x69,0x63,0x40,0x63,0x6f,0x64,0x65,0x77,0x65,0x61,0x76,0x65,
84 0x72,0x73,0x2e,0x63,0x6f,0x6d,0x30,0x1e,0x17,0xd,0x30,0x36,0x30,0x31,0x32,
85 0x35,0x31,0x33,0x35,0x37,0x32,0x34,0x5a,0x17,0xd,0x30,0x36,0x30,0x32,0x32,
86 0x34,0x31,0x33,0x35,0x37,0x32,0x34,0x5a,0x30,0x81,0xa1,0x31,0xb,0x30,0x9,0x6,
87 0x3,0x55,0x4,0x6,0x13,0x2,0x55,0x53,0x31,0x12,0x30,0x10,0x6,0x3,0x55,0x4,0x8,
88 0x13,0x9,0x4d,0x69,0x6e,0x6e,0x65,0x73,0x6f,0x74,0x61,0x31,0x14,0x30,0x12,0x6,
89 0x3,0x55,0x4,0x7,0x13,0xb,0x4d,0x69,0x6e,0x6e,0x65,0x61,0x70,0x6f,0x6c,0x69,
90 0x73,0x31,0x14,0x30,0x12,0x6,0x3,0x55,0x4,0xa,0x13,0xb,0x43,0x6f,0x64,0x65,
91 0x57,0x65,0x61,0x76,0x65,0x72,0x73,0x31,0x19,0x30,0x17,0x6,0x3,0x55,0x4,0xb,
92 0x13,0x10,0x57,0x69,0x6e,0x65,0x20,0x44,0x65,0x76,0x65,0x6c,0x6f,0x70,0x6d,
93 0x65,0x6e,0x74,0x31,0x12,0x30,0x10,0x6,0x3,0x55,0x4,0x3,0x13,0x9,0x6c,0x6f,
94 0x63,0x61,0x6c,0x68,0x6f,0x73,0x74,0x31,0x23,0x30,0x21,0x6,0x9,0x2a,0x86,0x48,
95 0x86,0xf7,0xd,0x1,0x9,0x1,0x16,0x14,0x61,0x72,0x69,0x63,0x40,0x63,0x6f,0x64,
96 0x65,0x77,0x65,0x61,0x76,0x65,0x72,0x73,0x2e,0x63,0x6f,0x6d,0x30,0x81,0x9f,
97 0x30,0xd,0x6,0x9,0x2a,0x86,0x48,0x86,0xf7,0xd,0x1,0x1,0x1,0x5,0x0,0x3,0x81,
98 0x8d,0x0,0x30,0x81,0x89,0x2,0x81,0x81,0x0,0x9b,0xb5,0x8f,0xaf,0xfb,0x9a,0xaf,
99 0xdc,0xa2,0x4d,0xb1,0xc8,0x72,0x44,0xef,0x79,0x7f,0x28,0xb6,0xfe,0x50,0xdc,
100 0x8a,0xf7,0x11,0x2f,0x90,0x70,0xed,0xa4,0xa9,0xd,0xbf,0x82,0x3e,0x56,0xd8,
101 0x36,0xb6,0x9,0x52,0x83,0xab,0x65,0x95,0x0,0xe2,0xea,0x3c,0x4f,0x85,0xb8,0xc,
102 0x41,0x42,0x77,0x5c,0x9d,0x44,0xeb,0xcf,0x7d,0x60,0x64,0x7a,0x6c,0x4c,0xac,
103 0x4a,0x9a,0x23,0x25,0x15,0xd7,0x92,0xb4,0x10,0xe7,0x95,0xad,0x4b,0x93,0xda,
104 0x6a,0x76,0xe0,0xa5,0xd2,0x13,0x8,0x12,0x30,0x68,0xde,0xb9,0x5b,0x6e,0x2a,
105 0x97,0x43,0xaa,0x7b,0x22,0x33,0x34,0xb1,0xca,0x5d,0x19,0xd8,0x42,0x26,0x45,
106 0xc6,0xe9,0x1d,0xee,0x7,0xc2,0x27,0x95,0x87,0xd8,0x12,0xec,0x4b,0x16,0x9f,0x2,
107 0x3,0x1,0x0,0x1,0x30,0xd,0x6,0x9,0x2a,0x86,0x48,0x86,0xf7,0xd,0x1,0x1,0x4,0x5,
108 0x0,0x3,0x81,0x81,0x0,0x96,0xf9,0xf6,0x6a,0x3d,0xd9,0xca,0x6e,0xd5,0x76,0x73,
109 0xab,0x75,0xc1,0xcc,0x98,0x44,0xc3,0xa9,0x90,0x68,0x88,0x76,0xb9,0xeb,0xb6,
110 0xbe,0x60,0x62,0xb9,0x67,0x1e,0xcc,0xf4,0xe1,0xe7,0x6c,0xc8,0x67,0x3f,0x1d,
111 0xf3,0x68,0x86,0x30,0xee,0xaa,0x92,0x61,0x37,0xd7,0x82,0x90,0x28,0xaa,0x7a,
112 0x18,0x88,0x60,0x14,0x88,0x75,0xc0,0x4a,0x4e,0x7d,0x48,0xe7,0x3,0xa6,0xfd,
113 0xd7,0xce,0x3c,0xe5,0x9b,0xaf,0x2f,0xdc,0xbb,0x7c,0xbd,0x20,0x49,0xd9,0x68,
114 0x37,0xeb,0x5d,0xbb,0xe2,0x6d,0x66,0xe3,0x11,0xc1,0xa7,0x88,0x49,0xc6,0x6f,
115 0x65,0xd3,0xce,0xae,0x26,0x19,0x3,0x2e,0x4f,0x78,0xa5,0xa,0x97,0x7e,0x4f,0xc4,
116 0x91,0x8a,0xf8,0x5,0xef,0x5b,0x3b,0x49,0xbf,0x5f,0x2b};
117
118 static char issuerStr[] =
119 "US, Minnesota, Minneapolis, CodeWeavers, Wine Development, localhost, aric@codeweavers.com";
120 static char issuerStrSemicolon[] =
121 "US; Minnesota; Minneapolis; CodeWeavers; Wine Development; localhost; aric@codeweavers.com";
122 static char issuerStrCRLF[] =
123 "US\r\nMinnesota\r\nMinneapolis\r\nCodeWeavers\r\nWine Development\r\nlocalhost\r\naric@codeweavers.com";
124 static char subjectStr[] =
125 "2.5.4.6=US, 2.5.4.8=Minnesota, 2.5.4.7=Minneapolis, 2.5.4.10=CodeWeavers, 2.5.4.11=Wine Development, 2.5.4.3=localhost, 1.2.840.113549.1.9.1=aric@codeweavers.com";
126 static char subjectStrSemicolon[] =
127 "2.5.4.6=US; 2.5.4.8=Minnesota; 2.5.4.7=Minneapolis; 2.5.4.10=CodeWeavers; 2.5.4.11=Wine Development; 2.5.4.3=localhost; 1.2.840.113549.1.9.1=aric@codeweavers.com";
128 static char subjectStrCRLF[] =
129 "2.5.4.6=US\r\n2.5.4.8=Minnesota\r\n2.5.4.7=Minneapolis\r\n2.5.4.10=CodeWeavers\r\n2.5.4.11=Wine Development\r\n2.5.4.3=localhost\r\n1.2.840.113549.1.9.1=aric@codeweavers.com";
130 static char x500SubjectStr[] = "C=US, S=Minnesota, L=Minneapolis, O=CodeWeavers, OU=Wine Development, CN=localhost, E=aric@codeweavers.com";
131 static char x500SubjectStrSemicolonReverse[] = "E=aric@codeweavers.com; CN=localhost; OU=Wine Development; O=CodeWeavers; L=Minneapolis; S=Minnesota; C=US";
132 static WCHAR issuerStrW[] = {
133 'U','S',',',' ','M','i','n','n','e','s','o','t','a',',',' ','M','i','n','n',
134 'e','a','p','o','l','i','s',',',' ','C','o','d','e','W','e','a','v','e','r',
135 's',',',' ','W','i','n','e',' ','D','e','v','e','l','o','p','m','e','n','t',
136 ',',' ','l','o','c','a','l','h','o','s','t',',',' ','a','r','i','c','@','c',
137 'o','d','e','w','e','a','v','e','r','s','.','c','o','m',0 };
138 static WCHAR issuerStrSemicolonW[] = {
139 'U','S',';',' ','M','i','n','n','e','s','o','t','a',';',' ','M','i','n','n',
140 'e','a','p','o','l','i','s',';',' ','C','o','d','e','W','e','a','v','e','r',
141 's',';',' ','W','i','n','e',' ','D','e','v','e','l','o','p','m','e','n','t',
142 ';',' ','l','o','c','a','l','h','o','s','t',';',' ','a','r','i','c','@','c',
143 'o','d','e','w','e','a','v','e','r','s','.','c','o','m',0 };
144 static WCHAR issuerStrCRLFW[] = {
145 'U','S','\r','\n','M','i','n','n','e','s','o','t','a','\r','\n','M','i','n',
146 'n','e','a','p','o','l','i','s','\r','\n','C','o','d','e','W','e','a','v','e',
147 'r','s','\r','\n','W','i','n','e',' ','D','e','v','e','l','o','p','m','e','n',
148 't','\r','\n','l','o','c','a','l','h','o','s','t','\r','\n','a','r','i','c',
149 '@','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0 };
150 static WCHAR subjectStrW[] = {
151 '2','.','5','.','4','.','6','=','U','S',',',' ','2','.','5','.','4','.','8',
152 '=','M','i','n','n','e','s','o','t','a',',',' ','2','.','5','.','4','.','7',
153 '=','M','i','n','n','e','a','p','o','l','i','s',',',' ','2','.','5','.','4',
154 '.','1','0','=','C','o','d','e','W','e','a','v','e','r','s',',',' ','2','.',
155 '5','.','4','.','1','1','=','W','i','n','e',' ','D','e','v','e','l','o','p',
156 'm','e','n','t',',',' ','2','.','5','.','4','.','3','=','l','o','c','a','l',
157 'h','o','s','t',',',' ','1','.','2','.','8','4','0','.','1','1','3','5','4',
158 '9','.','1','.','9','.','1','=','a','r','i','c','@','c','o','d','e','w','e',
159 'a','v','e','r','s','.','c','o','m',0 };
160 static WCHAR subjectStrSemicolonW[] = {
161 '2','.','5','.','4','.','6','=','U','S',';',' ','2','.','5','.','4','.','8',
162 '=','M','i','n','n','e','s','o','t','a',';',' ','2','.','5','.','4','.','7',
163 '=','M','i','n','n','e','a','p','o','l','i','s',';',' ','2','.','5','.','4',
164 '.','1','0','=','C','o','d','e','W','e','a','v','e','r','s',';',' ','2','.',
165 '5','.','4','.','1','1','=','W','i','n','e',' ','D','e','v','e','l','o','p',
166 'm','e','n','t',';',' ','2','.','5','.','4','.','3','=','l','o','c','a','l',
167 'h','o','s','t',';',' ','1','.','2','.','8','4','0','.','1','1','3','5','4',
168 '9','.','1','.','9','.','1','=','a','r','i','c','@','c','o','d','e','w','e',
169 'a','v','e','r','s','.','c','o','m',0 };
170 static WCHAR subjectStrCRLFW[] = {
171 '2','.','5','.','4','.','6','=','U','S','\r','\n','2','.','5','.','4','.','8',
172 '=','M','i','n','n','e','s','o','t','a','\r','\n','2','.','5','.','4','.','7',
173 '=','M','i','n','n','e','a','p','o','l','i','s','\r','\n','2','.','5','.','4',
174 '.','1','0','=','C','o','d','e','W','e','a','v','e','r','s','\r','\n','2','.',
175 '5','.','4','.','1','1','=','W','i','n','e',' ','D','e','v','e','l','o','p',
176 'm','e','n','t','\r','\n','2','.','5','.','4','.','3','=','l','o','c','a','l',
177 'h','o','s','t','\r','\n','1','.','2','.','8','4','0','.','1','1','3','5','4',
178 '9','.','1','.','9','.','1','=','a','r','i','c','@','c','o','d','e','w','e',
179 'a','v','e','r','s','.','c','o','m',0 };
180 static WCHAR x500SubjectStrSemicolonReverseW[] = {
181 'E','=','a','r','i','c','@','c','o','d','e','w','e','a','v','e','r','s','.','c',
182 'o','m',';',' ','C','N','=','l','o','c','a','l','h','o','s','t',';',' ','O','U',
183 '=','W','i','n','e',' ','D','e','v','e','l','o','p','m','e','n','t',';',' ','O',
184 '=','C','o','d','e','W','e','a','v','e','r','s',';',' ','L','=','M','i','n','n',
185 'e','a','p','o','l','i','s',';',' ','S','=','M','i','n','n','e','s','o','t','a',
186 ';',' ','C','=','U','S',0 };
187
188 static HMODULE dll;
189 static DWORD (WINAPI *pCertNameToStrA)(DWORD,LPVOID,DWORD,LPSTR,DWORD);
190 static DWORD (WINAPI *pCertNameToStrW)(DWORD,LPVOID,DWORD,LPWSTR,DWORD);
191 static DWORD (WINAPI *pCertRDNValueToStrA)(DWORD, PCERT_RDN_VALUE_BLOB,
192 LPSTR, DWORD);
193 static DWORD (WINAPI *pCertRDNValueToStrW)(DWORD, PCERT_RDN_VALUE_BLOB,
194 LPWSTR, DWORD);
195 static BOOL (WINAPI *pCertStrToNameA)(DWORD dwCertEncodingType,
196 LPCSTR pszX500, DWORD dwStrType, void *pvReserved, BYTE *pbEncoded,
197 DWORD *pcbEncoded, LPCSTR *ppszError);
198 static BOOL (WINAPI *pCertStrToNameW)(DWORD dwCertEncodingType,
199 LPCWSTR pszX500, DWORD dwStrType, void *pvReserved, BYTE *pbEncoded,
200 DWORD *pcbEncoded, LPCWSTR *ppszError);
201 static DWORD (WINAPI *pCertGetNameStringA)(PCCERT_CONTEXT cert, DWORD type,
202 DWORD flags, void *typePara, LPSTR str, DWORD cch);
203
204
205 static void test_CertRDNValueToStrA(void)
206 {
207 CertRDNAttrEncoding attrs[] = {
208 { "2.5.4.6", CERT_RDN_PRINTABLE_STRING,
209 { sizeof(bin1), bin1 }, "US", FALSE },
210 { "2.5.4.8", CERT_RDN_PRINTABLE_STRING,
211 { sizeof(bin2), bin2 }, "Minnesota", FALSE },
212 { "2.5.4.7", CERT_RDN_PRINTABLE_STRING,
213 { sizeof(bin3), bin3 }, "Minneapolis", FALSE },
214 { "2.5.4.10", CERT_RDN_PRINTABLE_STRING,
215 { sizeof(bin4), bin4 }, "CodeWeavers", FALSE },
216 { "2.5.4.11", CERT_RDN_PRINTABLE_STRING,
217 { sizeof(bin5), bin5 }, "Wine Development", FALSE },
218 { "2.5.4.3", CERT_RDN_PRINTABLE_STRING,
219 { sizeof(bin6), bin6 }, "localhost", FALSE },
220 { "1.2.840.113549.1.9.1", CERT_RDN_IA5_STRING,
221 { sizeof(bin7), bin7 }, "aric@codeweavers.com", FALSE },
222 { "0", CERT_RDN_PRINTABLE_STRING,
223 { sizeof(bin9), bin9 }, "abc\"def", FALSE },
224 { "0", CERT_RDN_PRINTABLE_STRING,
225 { sizeof(bin10), bin10 }, "abc'def", FALSE },
226 { "0", CERT_RDN_PRINTABLE_STRING,
227 { sizeof(bin11), bin11 }, "abc, def", FALSE },
228 { "0", CERT_RDN_PRINTABLE_STRING,
229 { sizeof(bin12), bin12 }, " abc ", FALSE },
230 { "0", CERT_RDN_PRINTABLE_STRING,
231 { sizeof(bin13), bin13 }, "\"def\"", FALSE },
232 { "0", CERT_RDN_PRINTABLE_STRING,
233 { sizeof(bin14), bin14 }, "1;3", FALSE },
234 };
235 DWORD i, ret;
236 char buffer[2000];
237 CERT_RDN_VALUE_BLOB blob = { 0, NULL };
238 static const char ePKI[] = "ePKI Root Certification Authority";
239
240 if (!pCertRDNValueToStrA) return;
241
242 /* This crashes
243 ret = pCertRDNValueToStrA(0, NULL, NULL, 0);
244 */
245 /* With empty input, it generates the empty string */
246 SetLastError(0xdeadbeef);
247 ret = pCertRDNValueToStrA(0, &blob, NULL, 0);
248 ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
249 ret = pCertRDNValueToStrA(0, &blob, buffer, sizeof(buffer));
250 ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
251 ok(!buffer[0], "Expected empty string\n");
252
253 for (i = 0; i < sizeof(attrs) / sizeof(attrs[0]); i++)
254 {
255 ret = pCertRDNValueToStrA(attrs[i].dwValueType, &attrs[i].Value,
256 buffer, sizeof(buffer));
257 if (attrs[i].todo)
258 {
259 todo_wine
260 ok(ret == strlen(attrs[i].str) + 1, "Expected length %d, got %d\n",
261 lstrlenA(attrs[i].str) + 1, ret);
262 todo_wine
263 ok(!strcmp(buffer, attrs[i].str), "Expected %s, got %s\n",
264 attrs[i].str, buffer);
265 }
266 else
267 {
268 ok(ret == strlen(attrs[i].str) + 1, "Expected length %d, got %d\n",
269 lstrlenA(attrs[i].str) + 1, ret);
270 ok(!strcmp(buffer, attrs[i].str), "Expected %s, got %s\n",
271 attrs[i].str, buffer);
272 }
273 }
274 blob.pbData = bin8;
275 blob.cbData = sizeof(bin8);
276 ret = pCertRDNValueToStrA(CERT_RDN_UTF8_STRING, &blob, buffer,
277 sizeof(buffer));
278 ok(ret == strlen(ePKI) + 1 || broken(ret != strlen(ePKI) + 1),
279 "Expected length %d, got %d\n", lstrlenA(ePKI), ret);
280 if (ret == strlen(ePKI) + 1)
281 ok(!strcmp(buffer, ePKI), "Expected %s, got %s\n", ePKI, buffer);
282 }
283
284 static void test_CertRDNValueToStrW(void)
285 {
286 static const WCHAR usW[] = { 'U','S',0 };
287 static const WCHAR minnesotaW[] = { 'M','i','n','n','e','s','o','t','a',0 };
288 static const WCHAR minneapolisW[] = { 'M','i','n','n','e','a','p','o','l',
289 'i','s',0 };
290 static const WCHAR codeweaversW[] = { 'C','o','d','e','W','e','a','v','e',
291 'r','s',0 };
292 static const WCHAR wineDevW[] = { 'W','i','n','e',' ','D','e','v','e','l',
293 'o','p','m','e','n','t',0 };
294 static const WCHAR localhostW[] = { 'l','o','c','a','l','h','o','s','t',0 };
295 static const WCHAR aricW[] = { 'a','r','i','c','@','c','o','d','e','w','e',
296 'a','v','e','r','s','.','c','o','m',0 };
297 static const WCHAR ePKIW[] = { 'e','P','K','I',' ','R','o','o','t',' ',
298 'C','e','r','t','i','f','i','c','a','t','i','o','n',' ','A','u','t','h',
299 'o','r','i','t','y',0 };
300 static const WCHAR embeddedDoubleQuoteW[] = { 'a','b','c','"','d','e','f',
301 0 };
302 static const WCHAR embeddedSingleQuoteW[] = { 'a','b','c','\'','d','e','f',
303 0 };
304 static const WCHAR embeddedCommaW[] = { 'a','b','c',',',' ','d','e','f',0 };
305 static const WCHAR trailingAndEndingSpaceW[] = { ' ','a','b','c',' ',0 };
306 static const WCHAR enclosingQuotesW[] = { '"','d','e','f','"',0 };
307 static const WCHAR embeddedSemiW[] = { '1',';','3',0 };
308 CertRDNAttrEncodingW attrs[] = {
309 { "2.5.4.6", CERT_RDN_PRINTABLE_STRING,
310 { sizeof(bin1), bin1 }, usW, FALSE },
311 { "2.5.4.8", CERT_RDN_PRINTABLE_STRING,
312 { sizeof(bin2), bin2 }, minnesotaW, FALSE },
313 { "2.5.4.7", CERT_RDN_PRINTABLE_STRING,
314 { sizeof(bin3), bin3 }, minneapolisW, FALSE },
315 { "2.5.4.10", CERT_RDN_PRINTABLE_STRING,
316 { sizeof(bin4), bin4 }, codeweaversW, FALSE },
317 { "2.5.4.11", CERT_RDN_PRINTABLE_STRING,
318 { sizeof(bin5), bin5 }, wineDevW, FALSE },
319 { "2.5.4.3", CERT_RDN_PRINTABLE_STRING,
320 { sizeof(bin6), bin6 }, localhostW, FALSE },
321 { "1.2.840.113549.1.9.1", CERT_RDN_IA5_STRING,
322 { sizeof(bin7), bin7 }, aricW, FALSE },
323 { "0", CERT_RDN_PRINTABLE_STRING,
324 { sizeof(bin9), bin9 }, embeddedDoubleQuoteW, FALSE },
325 { "0", CERT_RDN_PRINTABLE_STRING,
326 { sizeof(bin10), bin10 }, embeddedSingleQuoteW, FALSE },
327 { "0", CERT_RDN_PRINTABLE_STRING,
328 { sizeof(bin11), bin11 }, embeddedCommaW, FALSE },
329 { "0", CERT_RDN_PRINTABLE_STRING,
330 { sizeof(bin12), bin12 }, trailingAndEndingSpaceW, FALSE },
331 { "0", CERT_RDN_PRINTABLE_STRING,
332 { sizeof(bin13), bin13 }, enclosingQuotesW, FALSE },
333 { "0", CERT_RDN_PRINTABLE_STRING,
334 { sizeof(bin14), bin14 }, embeddedSemiW, FALSE },
335 };
336 DWORD i, ret;
337 WCHAR buffer[2000];
338 CERT_RDN_VALUE_BLOB blob = { 0, NULL };
339
340 if (!pCertRDNValueToStrW)
341 {
342 win_skip("CertRDNValueToStrW is not available\n");
343 return;
344 }
345
346 /* This crashes
347 ret = pCertRDNValueToStrW(0, NULL, NULL, 0);
348 */
349 /* With empty input, it generates the empty string */
350 SetLastError(0xdeadbeef);
351 ret = pCertRDNValueToStrW(0, &blob, NULL, 0);
352 ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
353 ret = pCertRDNValueToStrW(0, &blob, buffer,
354 sizeof(buffer) / sizeof(buffer[0]));
355 ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
356 ok(!buffer[0], "Expected empty string\n");
357
358 for (i = 0; i < sizeof(attrs) / sizeof(attrs[0]); i++)
359 {
360 ret = pCertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value,
361 buffer, sizeof(buffer) / sizeof(buffer[0]));
362 if (attrs[i].todo)
363 {
364 todo_wine
365 ok(ret == lstrlenW(attrs[i].str) + 1,
366 "Expected length %d, got %d\n", lstrlenW(attrs[i].str) + 1, ret);
367 todo_wine
368 ok(!lstrcmpW(buffer, attrs[i].str), "Expected %s, got %s\n",
369 wine_dbgstr_w(attrs[i].str), wine_dbgstr_w(buffer));
370 }
371 else
372 {
373 ok(ret == lstrlenW(attrs[i].str) + 1,
374 "Expected length %d, got %d\n", lstrlenW(attrs[i].str) + 1, ret);
375 ok(!lstrcmpW(buffer, attrs[i].str), "Expected %s, got %s\n",
376 wine_dbgstr_w(attrs[i].str), wine_dbgstr_w(buffer));
377 }
378 }
379 blob.pbData = bin8;
380 blob.cbData = sizeof(bin8);
381 ret = pCertRDNValueToStrW(CERT_RDN_UTF8_STRING, &blob, buffer,
382 sizeof(buffer));
383 ok(ret == lstrlenW(ePKIW) + 1 || broken(ret != lstrlenW(ePKIW) + 1),
384 "Expected length %d, got %d\n", lstrlenW(ePKIW), ret);
385 if (ret == lstrlenW(ePKIW) + 1)
386 ok(!lstrcmpW(buffer, ePKIW), "Expected %s, got %s\n",
387 wine_dbgstr_w(ePKIW), wine_dbgstr_w(buffer));
388 }
389
390 static void test_NameToStrConversionA(PCERT_NAME_BLOB pName, DWORD dwStrType,
391 LPCSTR expected, BOOL todo)
392 {
393 char buffer[2000] = { 0 };
394 DWORD i;
395
396 i = pCertNameToStrA(X509_ASN_ENCODING, pName, dwStrType, NULL, 0);
397 if (todo)
398 todo_wine
399 ok(i == strlen(expected) + 1, "Expected %d chars, got %d\n",
400 lstrlenA(expected) + 1, i);
401 else
402 ok(i == strlen(expected) + 1, "Expected %d chars, got %d\n",
403 lstrlenA(expected) + 1, i);
404 i = pCertNameToStrA(X509_ASN_ENCODING,pName, dwStrType, buffer,
405 sizeof(buffer));
406 if (todo)
407 todo_wine
408 ok(i == strlen(expected) + 1, "Expected %d chars, got %d\n",
409 lstrlenA(expected) + 1, i);
410 else
411 ok(i == strlen(expected) + 1, "Expected %d chars, got %d\n",
412 lstrlenA(expected) + 1, i);
413 if (todo)
414 todo_wine
415 ok(!strcmp(buffer, expected), "Expected %s, got %s\n", expected,
416 buffer);
417 else
418 ok(!strcmp(buffer, expected), "Expected %s, got %s\n", expected,
419 buffer);
420 }
421
422 static BYTE encodedSimpleCN[] = {
423 0x30,0x0c,0x31,0x0a,0x30,0x08,0x06,0x03,0x55,0x04,0x03,0x13,0x01,0x31 };
424 static BYTE encodedSingleQuotedCN[] = { 0x30,0x0e,0x31,0x0c,0x30,0x0a,
425 0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x27,0x31,0x27 };
426 static BYTE encodedSpacedCN[] = { 0x30,0x0e,0x31,0x0c,0x30,0x0a,0x06,0x03,
427 0x55,0x04,0x03,0x13,0x03,0x20,0x31,0x20 };
428 static BYTE encodedQuotedCN[] = { 0x30,0x11,0x31,0x0f,0x30,0x0d,0x06,0x03,
429 0x55, 0x04,0x03,0x1e,0x06,0x00,0x22,0x00,0x31,0x00,0x22, };
430 static BYTE encodedMultipleAttrCN[] = { 0x30,0x0e,0x31,0x0c,0x30,0x0a,
431 0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x31,0x2b,0x32 };
432 static BYTE encodedCommaCN[] = {
433 0x30,0x0e,0x31,0x0c,0x30,0x0a,0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x61,0x2c,
434 0x62 };
435 static BYTE encodedEqualCN[] = {
436 0x30,0x0e,0x31,0x0c,0x30,0x0a,0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x61,0x3d,
437 0x62 };
438 static BYTE encodedLessThanCN[] = {
439 0x30,0x0d,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x03,0x1e,0x02,0x00,0x3c
440 };
441 static BYTE encodedGreaterThanCN[] = {
442 0x30,0x0d,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x03,0x1e,0x02,0x00,0x3e
443 };
444 static BYTE encodedHashCN[] = {
445 0x30,0x0d,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x03,0x1e,0x02,0x00,0x23
446 };
447 static BYTE encodedSemiCN[] = {
448 0x30,0x0d,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x03,0x1e,0x02,0x00,0x3b
449 };
450 static BYTE encodedNewlineCN[] = {
451 0x30,0x11,0x31,0x0f,0x30,0x0d,0x06,0x03,0x55,0x04,0x03,0x1e,0x06,0x00,0x61,
452 0x00,0x0a,0x00,0x62 };
453 static BYTE encodedDummyCN[] = {
454 0x30,0x1F,0x31,0x0E,0x30,0x0C,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x64,0x75,
455 0x6D,0x6D,0x79,0x31,0x0D,0x30,0x0B,0x06,0x03,0x55,0x04,0x0C,0x13,0x04,0x74,
456 0x65,0x73,0x74 };
457 static BYTE encodedFields[] = {
458 0x30,0x2F,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x57,0x69,
459 0x6E,0x65,0x20,0x54,0x65,0x73,0x74,0x31,0x0C,0x30,0x0A,0x06,0x03,0x55,0x04,
460 0x0C,0x13,0x03,0x31,0x32,0x33,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,
461 0x13,0x02,0x42,0x52 };
462
463 static void test_CertNameToStrA(void)
464 {
465 PCCERT_CONTEXT context;
466 CERT_NAME_BLOB blob;
467
468 if (!pCertNameToStrA)
469 {
470 win_skip("CertNameToStrA is not available\n");
471 return;
472 }
473
474 context = CertCreateCertificateContext(X509_ASN_ENCODING, cert,
475 sizeof(cert));
476 ok(context != NULL, "CertCreateCertificateContext failed: %08x\n",
477 GetLastError());
478 if (context)
479 {
480 DWORD ret;
481
482 /* This crashes
483 ret = pCertNameToStrA(0, NULL, 0, NULL, 0);
484 */
485 /* Test with a bogus encoding type */
486 SetLastError(0xdeadbeef);
487 ret = pCertNameToStrA(0, &context->pCertInfo->Issuer, 0, NULL, 0);
488 ok(ret == 1 && GetLastError() == ERROR_FILE_NOT_FOUND,
489 "Expected retval 1 and ERROR_FILE_NOT_FOUND, got %d - %08x\n",
490 ret, GetLastError());
491 SetLastError(0xdeadbeef);
492 ret = pCertNameToStrA(X509_ASN_ENCODING, &context->pCertInfo->Issuer,
493 0, NULL, 0);
494 ok(ret && GetLastError() == ERROR_SUCCESS,
495 "Expected positive return and ERROR_SUCCESS, got %d - %08x\n",
496 ret, GetLastError());
497
498 test_NameToStrConversionA(&context->pCertInfo->Issuer,
499 CERT_SIMPLE_NAME_STR, issuerStr, FALSE);
500 test_NameToStrConversionA(&context->pCertInfo->Issuer,
501 CERT_SIMPLE_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG,
502 issuerStrSemicolon, FALSE);
503 test_NameToStrConversionA(&context->pCertInfo->Issuer,
504 CERT_SIMPLE_NAME_STR | CERT_NAME_STR_CRLF_FLAG,
505 issuerStrCRLF, FALSE);
506 test_NameToStrConversionA(&context->pCertInfo->Subject,
507 CERT_OID_NAME_STR, subjectStr, FALSE);
508 test_NameToStrConversionA(&context->pCertInfo->Subject,
509 CERT_OID_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG,
510 subjectStrSemicolon, FALSE);
511 test_NameToStrConversionA(&context->pCertInfo->Subject,
512 CERT_OID_NAME_STR | CERT_NAME_STR_CRLF_FLAG,
513 subjectStrCRLF, FALSE);
514 test_NameToStrConversionA(&context->pCertInfo->Subject,
515 CERT_X500_NAME_STR, x500SubjectStr, FALSE);
516 test_NameToStrConversionA(&context->pCertInfo->Subject,
517 CERT_X500_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG | CERT_NAME_STR_REVERSE_FLAG,
518 x500SubjectStrSemicolonReverse, FALSE);
519
520 CertFreeCertificateContext(context);
521 }
522 blob.pbData = encodedSimpleCN;
523 blob.cbData = sizeof(encodedSimpleCN);
524 test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=1", FALSE);
525 blob.pbData = encodedSingleQuotedCN;
526 blob.cbData = sizeof(encodedSingleQuotedCN);
527 test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN='1'", FALSE);
528 test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "'1'", FALSE);
529 blob.pbData = encodedSpacedCN;
530 blob.cbData = sizeof(encodedSpacedCN);
531 test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\" 1 \"", FALSE);
532 test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "\" 1 \"", FALSE);
533 blob.pbData = encodedQuotedCN;
534 blob.cbData = sizeof(encodedQuotedCN);
535 test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"\"\"1\"\"\"",
536 FALSE);
537 test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "\"\"\"1\"\"\"",
538 FALSE);
539 blob.pbData = encodedMultipleAttrCN;
540 blob.cbData = sizeof(encodedMultipleAttrCN);
541 test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"1+2\"", FALSE);
542 test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "\"1+2\"", FALSE);
543 blob.pbData = encodedCommaCN;
544 blob.cbData = sizeof(encodedCommaCN);
545 test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"a,b\"", FALSE);
546 test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "\"a,b\"", FALSE);
547 blob.pbData = encodedEqualCN;
548 blob.cbData = sizeof(encodedEqualCN);
549 test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"a=b\"", FALSE);
550 test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "\"a=b\"", FALSE);
551 blob.pbData = encodedLessThanCN;
552 blob.cbData = sizeof(encodedLessThanCN);
553 test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"<\"", FALSE);
554 test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "\"<\"", FALSE);
555 blob.pbData = encodedGreaterThanCN;
556 blob.cbData = sizeof(encodedGreaterThanCN);
557 test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\">\"", FALSE);
558 test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "\">\"", FALSE);
559 blob.pbData = encodedHashCN;
560 blob.cbData = sizeof(encodedHashCN);
561 test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"#\"", FALSE);
562 test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "\"#\"", FALSE);
563 blob.pbData = encodedSemiCN;
564 blob.cbData = sizeof(encodedSemiCN);
565 test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\";\"", FALSE);
566 test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "\";\"", FALSE);
567 blob.pbData = encodedNewlineCN;
568 blob.cbData = sizeof(encodedNewlineCN);
569 test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"a\nb\"", FALSE);
570 test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "\"a\nb\"", FALSE);
571 }
572
573 static void test_NameToStrConversionW(PCERT_NAME_BLOB pName, DWORD dwStrType,
574 LPCWSTR expected, BOOL todo)
575 {
576 WCHAR buffer[2000] = { 0 };
577 DWORD i;
578
579 i = pCertNameToStrW(X509_ASN_ENCODING,pName, dwStrType, NULL, 0);
580 if (todo)
581 todo_wine ok(i == lstrlenW(expected) + 1, "Expected %d chars, got %d\n",
582 lstrlenW(expected) + 1, i);
583 else
584 ok(i == lstrlenW(expected) + 1, "Expected %d chars, got %d\n",
585 lstrlenW(expected) + 1, i);
586 i = pCertNameToStrW(X509_ASN_ENCODING,pName, dwStrType, buffer,
587 sizeof(buffer) / sizeof(buffer[0]));
588 if (todo)
589 todo_wine ok(i == lstrlenW(expected) + 1, "Expected %d chars, got %d\n",
590 lstrlenW(expected) + 1, i);
591 else
592 ok(i == lstrlenW(expected) + 1, "Expected %d chars, got %d\n",
593 lstrlenW(expected) + 1, i);
594 if (todo)
595 todo_wine ok(!lstrcmpW(buffer, expected), "Expected %s, got %s\n",
596 wine_dbgstr_w(expected), wine_dbgstr_w(buffer));
597 else
598 ok(!lstrcmpW(buffer, expected), "Expected %s, got %s\n",
599 wine_dbgstr_w(expected), wine_dbgstr_w(buffer));
600 }
601
602 static const WCHAR simpleCN_W[] = { 'C','N','=','1',0 };
603 static const WCHAR singledQuotedCN_W[] = { 'C','N','=','\'','1','\'',0 };
604 static const WCHAR simpleSingleQuotedCN_W[] = { '\'','1','\'',0 };
605 static const WCHAR spacedCN_W[] = { 'C','N','=','"',' ','1',' ','"',0 };
606 static const WCHAR simpleSpacedCN_W[] = { '"',' ','1',' ','"',0 };
607 static const WCHAR quotedCN_W[] = { 'C','N','=','"','"','"','1','"','"','"',0 };
608 static const WCHAR simpleQuotedCN_W[] = { '"','"','"','1','"','"','"',0 };
609 static const WCHAR multipleAttrCN_W[] = { 'C','N','=','"','1','+','2','"',0 };
610 static const WCHAR simpleMultipleAttrCN_W[] = { '"','1','+','2','"',0 };
611 static const WCHAR commaCN_W[] = { 'C','N','=','"','a',',','b','"',0 };
612 static const WCHAR simpleCommaCN_W[] = { '"','a',',','b','"',0 };
613 static const WCHAR equalCN_W[] = { 'C','N','=','"','a','=','b','"',0 };
614 static const WCHAR simpleEqualCN_W[] = { '"','a','=','b','"',0 };
615 static const WCHAR lessThanCN_W[] = { 'C','N','=','"','<','"',0 };
616 static const WCHAR simpleLessThanCN_W[] = { '"','<','"',0 };
617 static const WCHAR greaterThanCN_W[] = { 'C','N','=','"','>','"',0 };
618 static const WCHAR simpleGreaterThanCN_W[] = { '"','>','"',0 };
619 static const WCHAR hashCN_W[] = { 'C','N','=','"','#','"',0 };
620 static const WCHAR simpleHashCN_W[] = { '"','#','"',0 };
621 static const WCHAR semiCN_W[] = { 'C','N','=','"',';','"',0 };
622 static const WCHAR simpleSemiCN_W[] = { '"',';','"',0 };
623 static const WCHAR newlineCN_W[] = { 'C','N','=','"','a','\n','b','"',0 };
624 static const WCHAR simpleNewlineCN_W[] = { '"','a','\n','b','"',0 };
625
626 static void test_CertNameToStrW(void)
627 {
628 PCCERT_CONTEXT context;
629 CERT_NAME_BLOB blob;
630
631 if (!pCertNameToStrW)
632 {
633 win_skip("CertNameToStrW is not available\n");
634 return;
635 }
636
637 context = CertCreateCertificateContext(X509_ASN_ENCODING, cert,
638 sizeof(cert));
639 ok(context != NULL, "CertCreateCertificateContext failed: %08x\n",
640 GetLastError());
641 if (context)
642 {
643 DWORD ret;
644
645 /* This crashes
646 ret = pCertNameToStrW(0, NULL, 0, NULL, 0);
647 */
648 /* Test with a bogus encoding type */
649 SetLastError(0xdeadbeef);
650 ret = pCertNameToStrW(0, &context->pCertInfo->Issuer, 0, NULL, 0);
651 ok(ret == 1 && GetLastError() == ERROR_FILE_NOT_FOUND,
652 "Expected retval 1 and ERROR_FILE_NOT_FOUND, got %d - %08x\n",
653 ret, GetLastError());
654 SetLastError(0xdeadbeef);
655 ret = pCertNameToStrW(X509_ASN_ENCODING, &context->pCertInfo->Issuer,
656 0, NULL, 0);
657 ok(ret && GetLastError() == ERROR_SUCCESS,
658 "Expected positive return and ERROR_SUCCESS, got %d - %08x\n",
659 ret, GetLastError());
660
661 test_NameToStrConversionW(&context->pCertInfo->Issuer,
662 CERT_SIMPLE_NAME_STR, issuerStrW, FALSE);
663 test_NameToStrConversionW(&context->pCertInfo->Issuer,
664 CERT_SIMPLE_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG,
665 issuerStrSemicolonW, FALSE);
666 test_NameToStrConversionW(&context->pCertInfo->Issuer,
667 CERT_SIMPLE_NAME_STR | CERT_NAME_STR_CRLF_FLAG,
668 issuerStrCRLFW, FALSE);
669 test_NameToStrConversionW(&context->pCertInfo->Subject,
670 CERT_OID_NAME_STR, subjectStrW, FALSE);
671 test_NameToStrConversionW(&context->pCertInfo->Subject,
672 CERT_OID_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG,
673 subjectStrSemicolonW, FALSE);
674 test_NameToStrConversionW(&context->pCertInfo->Subject,
675 CERT_OID_NAME_STR | CERT_NAME_STR_CRLF_FLAG,
676 subjectStrCRLFW, FALSE);
677 test_NameToStrConversionW(&context->pCertInfo->Subject,
678 CERT_X500_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG | CERT_NAME_STR_REVERSE_FLAG,
679 x500SubjectStrSemicolonReverseW, FALSE);
680
681 CertFreeCertificateContext(context);
682 }
683 blob.pbData = encodedSimpleCN;
684 blob.cbData = sizeof(encodedSimpleCN);
685 test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, simpleCN_W, FALSE);
686 blob.pbData = encodedSingleQuotedCN;
687 blob.cbData = sizeof(encodedSingleQuotedCN);
688 test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, singledQuotedCN_W,
689 FALSE);
690 test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR,
691 simpleSingleQuotedCN_W, FALSE);
692 blob.pbData = encodedSpacedCN;
693 blob.cbData = sizeof(encodedSpacedCN);
694 test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, spacedCN_W, FALSE);
695 test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, simpleSpacedCN_W,
696 FALSE);
697 blob.pbData = encodedQuotedCN;
698 blob.cbData = sizeof(encodedQuotedCN);
699 test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, quotedCN_W,
700 FALSE);
701 test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, simpleQuotedCN_W,
702 FALSE);
703 blob.pbData = encodedMultipleAttrCN;
704 blob.cbData = sizeof(encodedMultipleAttrCN);
705 test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, multipleAttrCN_W,
706 FALSE);
707 test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR,
708 simpleMultipleAttrCN_W, FALSE);
709 blob.pbData = encodedCommaCN;
710 blob.cbData = sizeof(encodedCommaCN);
711 test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, commaCN_W, FALSE);
712 test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, simpleCommaCN_W,
713 FALSE);
714 blob.pbData = encodedEqualCN;
715 blob.cbData = sizeof(encodedEqualCN);
716 test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, equalCN_W, FALSE);
717 test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, simpleEqualCN_W,
718 FALSE);
719 blob.pbData = encodedLessThanCN;
720 blob.cbData = sizeof(encodedLessThanCN);
721 test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, lessThanCN_W, FALSE);
722 test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, simpleLessThanCN_W,
723 FALSE);
724 blob.pbData = encodedGreaterThanCN;
725 blob.cbData = sizeof(encodedGreaterThanCN);
726 test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, greaterThanCN_W,
727 FALSE);
728 test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR,
729 simpleGreaterThanCN_W, FALSE);
730 blob.pbData = encodedHashCN;
731 blob.cbData = sizeof(encodedHashCN);
732 test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, hashCN_W, FALSE);
733 test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, simpleHashCN_W,
734 FALSE);
735 blob.pbData = encodedSemiCN;
736 blob.cbData = sizeof(encodedSemiCN);
737 test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, semiCN_W, FALSE);
738 test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, simpleSemiCN_W,
739 FALSE);
740 blob.pbData = encodedNewlineCN;
741 blob.cbData = sizeof(encodedNewlineCN);
742 test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, newlineCN_W, FALSE);
743 test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, simpleNewlineCN_W,
744 FALSE);
745 }
746
747 struct StrToNameA
748 {
749 LPCSTR x500;
750 DWORD encodedSize;
751 const BYTE *encoded;
752 };
753
754 static const struct StrToNameA namesA[] = {
755 { "CN=1", sizeof(encodedSimpleCN), encodedSimpleCN },
756 { "CN=\"1\"", sizeof(encodedSimpleCN), encodedSimpleCN },
757 { "CN = \"1\"", sizeof(encodedSimpleCN), encodedSimpleCN },
758 { "CN='1'", sizeof(encodedSingleQuotedCN), encodedSingleQuotedCN },
759 { "CN=\" 1 \"", sizeof(encodedSpacedCN), encodedSpacedCN },
760 { "CN=\"\"\"1\"\"\"", sizeof(encodedQuotedCN), encodedQuotedCN },
761 { "CN=\"1+2\"", sizeof(encodedMultipleAttrCN), encodedMultipleAttrCN },
762 { "CN=\"a,b\"", sizeof(encodedCommaCN), encodedCommaCN },
763 { "CN=\"a=b\"", sizeof(encodedEqualCN), encodedEqualCN },
764 { "CN=\"<\"", sizeof(encodedLessThanCN), encodedLessThanCN },
765 { "CN=\">\"", sizeof(encodedGreaterThanCN), encodedGreaterThanCN },
766 { "CN=\"#\"", sizeof(encodedHashCN), encodedHashCN },
767 { "CN=\";\"", sizeof(encodedSemiCN), encodedSemiCN },
768 { "CN=dummy,T=test", sizeof(encodedDummyCN), encodedDummyCN },
769 { " CN = Wine Test,T = 123, C = BR", sizeof(encodedFields), encodedFields },
770 };
771
772 static void test_CertStrToNameA(void)
773 {
774 BOOL ret;
775 DWORD size, i;
776 BYTE buf[100];
777
778 if (!pCertStrToNameA)
779 {
780 win_skip("CertStrToNameA is not available\n");
781 return;
782 }
783
784 /* Crash
785 ret = pCertStrToNameA(0, NULL, 0, NULL, NULL, NULL, NULL);
786 */
787 ret = pCertStrToNameA(0, NULL, 0, NULL, NULL, &size, NULL);
788 ok(!ret, "Expected failure\n");
789 ret = pCertStrToNameA(0, "bogus", 0, NULL, NULL, &size, NULL);
790 ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
791 "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
792 ret = pCertStrToNameA(0, "foo=1", 0, NULL, NULL, &size, NULL);
793 ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
794 "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
795 ret = pCertStrToNameA(0, "CN=1", 0, NULL, NULL, &size, NULL);
796 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
797 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
798 ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=1", 0, NULL, NULL, &size, NULL);
799 ok(ret, "CertStrToNameA failed: %08x\n", GetLastError());
800 size = sizeof(buf);
801 ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=\"\"1\"\"", 0, NULL, buf, &size,
802 NULL);
803 ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
804 "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
805 ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=1+2", 0, NULL, buf,
806 &size, NULL);
807 ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
808 "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
809 ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=1+2", CERT_NAME_STR_NO_PLUS_FLAG, NULL, buf,
810 &size, NULL);
811 ok(ret && GetLastError() == ERROR_SUCCESS,
812 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
813 ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=1,2", CERT_NAME_STR_NO_QUOTING_FLAG, NULL, buf,
814 &size, NULL);
815 ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
816 "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
817 ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=\"1,2;3,4\"", CERT_NAME_STR_NO_QUOTING_FLAG, NULL, buf,
818 &size, NULL);
819 ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
820 "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
821 ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=abc", 0, NULL, buf,
822 &size, NULL);
823 ok(ret && GetLastError() == ERROR_SUCCESS,
824 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
825 ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=abc", CERT_NAME_STR_NO_QUOTING_FLAG, NULL, buf,
826 &size, NULL);
827 ok(ret && GetLastError() == ERROR_SUCCESS,
828 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
829 ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=\"abc\"", 0, NULL, buf,
830 &size, NULL);
831 ok(ret && GetLastError() == ERROR_SUCCESS,
832 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
833 ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=\"abc\"", CERT_NAME_STR_NO_QUOTING_FLAG, NULL, buf,
834 &size, NULL);
835 ok(!ret && GetLastError() == ERROR_MORE_DATA,
836 "Expected ERROR_MORE_DATA, got %08x\n", GetLastError());
837 for (i = 0; i < sizeof(namesA) / sizeof(namesA[0]); i++)
838 {
839 size = sizeof(buf);
840 ret = pCertStrToNameA(X509_ASN_ENCODING, namesA[i].x500, 0, NULL, buf,
841 &size, NULL);
842 ok(ret, "CertStrToNameA failed on string %s: %08x\n", namesA[i].x500,
843 GetLastError());
844 ok(size == namesA[i].encodedSize,
845 "Expected size %d, got %d\n", namesA[i].encodedSize, size);
846 if (ret)
847 ok(!memcmp(buf, namesA[i].encoded, namesA[i].encodedSize),
848 "Unexpected value for string %s\n", namesA[i].x500);
849 }
850 }
851
852 struct StrToNameW
853 {
854 LPCWSTR x500;
855 DWORD encodedSize;
856 const BYTE *encoded;
857 };
858
859 static const WCHAR badlyQuotedCN_W[] = { 'C','N','=','"','"','1','"','"',0 };
860 static const WCHAR simpleCN2_W[] = { 'C','N','=','"','1','"',0 };
861 static const WCHAR simpleCN3_W[] = { 'C','N',' ','=',' ','"','1','"',0 };
862 static const WCHAR japaneseCN_W[] = { 'C','N','=',0x226f,0x575b,0 };
863 static const WCHAR dummyCN_W[] = { 'C','N','=','d','u','m','m','y',',','T','=','t','e','s','t',0 };
864 static const WCHAR encodedFields_W[] = { ' ','C','N',' ','=',' ',' ',' ','W','i','n','e',' ','T',
865 'e','s','t',',','T',' ','=',' ','1','2','3',',',' ','C',
866 ' ','=',' ','B','R',0 };
867 static const BYTE encodedJapaneseCN[] = { 0x30,0x0f,0x31,0x0d,0x30,0x0b,0x06,
868 0x03,0x55,0x04,0x03,0x1e,0x04,0x22,0x6f,0x57,0x5b };
869
870 static const struct StrToNameW namesW[] = {
871 { simpleCN_W, sizeof(encodedSimpleCN), encodedSimpleCN },
872 { simpleCN2_W, sizeof(encodedSimpleCN), encodedSimpleCN },
873 { simpleCN3_W, sizeof(encodedSimpleCN), encodedSimpleCN },
874 { singledQuotedCN_W, sizeof(encodedSingleQuotedCN), encodedSingleQuotedCN },
875 { spacedCN_W, sizeof(encodedSpacedCN), encodedSpacedCN },
876 { quotedCN_W, sizeof(encodedQuotedCN), encodedQuotedCN },
877 { multipleAttrCN_W, sizeof(encodedMultipleAttrCN), encodedMultipleAttrCN },
878 { japaneseCN_W, sizeof(encodedJapaneseCN), encodedJapaneseCN },
879 { commaCN_W, sizeof(encodedCommaCN), encodedCommaCN },
880 { equalCN_W, sizeof(encodedEqualCN), encodedEqualCN },
881 { lessThanCN_W, sizeof(encodedLessThanCN), encodedLessThanCN },
882 { greaterThanCN_W, sizeof(encodedGreaterThanCN), encodedGreaterThanCN },
883 { hashCN_W, sizeof(encodedHashCN), encodedHashCN },
884 { semiCN_W, sizeof(encodedSemiCN), encodedSemiCN },
885 { dummyCN_W, sizeof(encodedDummyCN), encodedDummyCN },
886 { encodedFields_W, sizeof(encodedFields), encodedFields },
887 };
888
889 static void test_CertStrToNameW(void)
890 {
891 static const WCHAR bogusW[] = { 'b','o','g','u','s',0 };
892 static const WCHAR fooW[] = { 'f','o','o','=','1',0 };
893 BOOL ret;
894 DWORD size, i;
895 LPCWSTR errorPtr;
896 BYTE buf[100];
897
898 if (!pCertStrToNameW)
899 {
900 win_skip("CertStrToNameW is not available\n");
901 return;
902 }
903
904 /* Crash
905 ret = pCertStrToNameW(0, NULL, 0, NULL, NULL, NULL, NULL);
906 */
907 ret = pCertStrToNameW(0, NULL, 0, NULL, NULL, &size, NULL);
908 ok(!ret, "Expected failure\n");
909 ret = pCertStrToNameW(0, bogusW, 0, NULL, NULL, &size, NULL);
910 ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
911 "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
912 ret = pCertStrToNameW(0, fooW, 0, NULL, NULL, &size, NULL);
913 ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
914 "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
915 ret = pCertStrToNameW(0, simpleCN_W, 0, NULL, NULL, &size, NULL);
916 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
917 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
918 ret = pCertStrToNameW(X509_ASN_ENCODING, simpleCN_W, 0, NULL, NULL, &size,
919 NULL);
920 ok(ret, "CertStrToNameW failed: %08x\n", GetLastError());
921 size = sizeof(buf);
922 ret = pCertStrToNameW(X509_ASN_ENCODING, badlyQuotedCN_W, 0, NULL, buf,
923 &size, NULL);
924 ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
925 "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
926 ret = pCertStrToNameW(X509_ASN_ENCODING, badlyQuotedCN_W, 0, NULL, buf,
927 &size, &errorPtr);
928 ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
929 "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
930 ok(errorPtr && *errorPtr == '1', "Expected first error character was 1\n");
931 for (i = 0; i < sizeof(namesW) / sizeof(namesW[0]); i++)
932 {
933 size = sizeof(buf);
934 ret = pCertStrToNameW(X509_ASN_ENCODING, namesW[i].x500, 0, NULL, buf,
935 &size, NULL);
936 ok(ret, "Index %d: CertStrToNameW failed: %08x\n", i, GetLastError());
937 ok(size == namesW[i].encodedSize,
938 "Index %d: expected size %d, got %d\n", i, namesW[i].encodedSize,
939 size);
940 if (ret)
941 ok(!memcmp(buf, namesW[i].encoded, size),
942 "Index %d: unexpected value for string %s\n", i, wine_dbgstr_w(namesW[i].x500));
943 }
944 }
945
946 static void test_CertGetNameStringA(void)
947 {
948 PCCERT_CONTEXT context;
949
950 if (!pCertGetNameStringA)
951 {
952 win_skip("CertGetNameStringA is not available\n");
953 return;
954 }
955
956 context = CertCreateCertificateContext(X509_ASN_ENCODING, cert,
957 sizeof(cert));
958 ok(context != NULL, "CertCreateCertificateContext failed: %08x\n",
959 GetLastError());
960 if (context)
961 {
962 static const char aric[] = "aric@codeweavers.com";
963 static const char localhost[] = "localhost";
964 DWORD len, type;
965 LPSTR str;
966
967 /* Bad string types/types missing from the cert */
968 len = pCertGetNameStringA(NULL, 0, 0, NULL, NULL, 0);
969 ok(len == 1, "expected 1, got %d\n", len);
970 len = pCertGetNameStringA(context, 0, 0, NULL, NULL, 0);
971 ok(len == 1, "expected 1, got %d\n", len);
972 len = pCertGetNameStringA(context, CERT_NAME_URL_TYPE, 0, NULL, NULL,
973 0);
974 ok(len == 1, "expected 1, got %d\n", len);
975
976 len = pCertGetNameStringA(context, CERT_NAME_EMAIL_TYPE, 0, NULL, NULL,
977 0);
978 ok(len == strlen(aric) + 1, "unexpected length %d\n", len);
979 str = HeapAlloc(GetProcessHeap(), 0, len);
980 if (str)
981 {
982 len = pCertGetNameStringA(context, CERT_NAME_EMAIL_TYPE, 0, NULL,
983 str, len);
984 ok(!strcmp(str, aric), "unexpected value %s\n", str);
985 HeapFree(GetProcessHeap(), 0, str);
986 }
987
988 len = pCertGetNameStringA(context, CERT_NAME_RDN_TYPE, 0, NULL, NULL,
989 0);
990 ok(len == strlen(issuerStr) + 1, "unexpected length %d\n", len);
991 str = HeapAlloc(GetProcessHeap(), 0, len);
992 if (str)
993 {
994 len = pCertGetNameStringA(context, CERT_NAME_RDN_TYPE, 0, NULL,
995 str, len);
996 ok(!strcmp(str, issuerStr), "unexpected value %s\n", str);
997 HeapFree(GetProcessHeap(), 0, str);
998 }
999 type = 0;
1000 len = pCertGetNameStringA(context, CERT_NAME_RDN_TYPE, 0, &type, NULL,
1001 0);
1002 ok(len == strlen(issuerStr) + 1, "unexpected length %d\n", len);
1003 str = HeapAlloc(GetProcessHeap(), 0, len);
1004 if (str)
1005 {
1006 len = pCertGetNameStringA(context, CERT_NAME_RDN_TYPE, 0, &type,
1007 str, len);
1008 ok(!strcmp(str, issuerStr), "unexpected value %s\n", str);
1009 HeapFree(GetProcessHeap(), 0, str);
1010 }
1011 type = CERT_OID_NAME_STR;
1012 len = pCertGetNameStringA(context, CERT_NAME_RDN_TYPE, 0, &type, NULL,
1013 0);
1014 ok(len == strlen(subjectStr) + 1, "unexpected length %d\n", len);
1015 str = HeapAlloc(GetProcessHeap(), 0, len);
1016 if (str)
1017 {
1018 len = pCertGetNameStringA(context, CERT_NAME_RDN_TYPE, 0, &type,
1019 str, len);
1020 ok(!strcmp(str, subjectStr), "unexpected value %s\n", str);
1021 HeapFree(GetProcessHeap(), 0, str);
1022 }
1023
1024 len = pCertGetNameStringA(context, CERT_NAME_ATTR_TYPE, 0, NULL, NULL,
1025 0);
1026 ok(len == strlen(aric) + 1, "unexpected length %d\n", len);
1027 str = HeapAlloc(GetProcessHeap(), 0, len);
1028 if (str)
1029 {
1030 len = pCertGetNameStringA(context, CERT_NAME_ATTR_TYPE, 0, NULL,
1031 str, len);
1032 ok(!strcmp(str, aric), "unexpected value %s\n", str);
1033 HeapFree(GetProcessHeap(), 0, str);
1034 }
1035 len = pCertGetNameStringA(context, CERT_NAME_ATTR_TYPE, 0,
1036 (void *)szOID_RSA_emailAddr, NULL, 0);
1037 ok(len == strlen(aric) + 1, "unexpected length %d\n", len);
1038 str = HeapAlloc(GetProcessHeap(), 0, len);
1039 if (str)
1040 {
1041 len = pCertGetNameStringA(context, CERT_NAME_ATTR_TYPE, 0,
1042 (void *)szOID_RSA_emailAddr, str, len);
1043 ok(!strcmp(str, aric), "unexpected value %s\n", str);
1044 HeapFree(GetProcessHeap(), 0, str);
1045 }
1046 len = pCertGetNameStringA(context, CERT_NAME_ATTR_TYPE, 0,
1047 (void *)szOID_COMMON_NAME, NULL, 0);
1048 ok(len == strlen(localhost) + 1, "unexpected length %d\n", len);
1049 str = HeapAlloc(GetProcessHeap(), 0, len);
1050 if (str)
1051 {
1052 len = pCertGetNameStringA(context, CERT_NAME_ATTR_TYPE, 0,
1053 (void *)szOID_COMMON_NAME, str, len);
1054 ok(!strcmp(str, localhost), "unexpected value %s\n", str);
1055 HeapFree(GetProcessHeap(), 0, str);
1056 }
1057
1058 len = pCertGetNameStringA(context, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0,
1059 NULL, NULL, 0);
1060 ok(len == strlen(localhost) + 1, "unexpected length %d\n", len);
1061 str = HeapAlloc(GetProcessHeap(), 0, len);
1062 if (str)
1063 {
1064 len = pCertGetNameStringA(context, CERT_NAME_SIMPLE_DISPLAY_TYPE,
1065 0, NULL, str, len);
1066 ok(!strcmp(str, localhost), "unexpected value %s\n", str);
1067 HeapFree(GetProcessHeap(), 0, str);
1068 }
1069
1070 len = pCertGetNameStringA(context, CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0,
1071 NULL, NULL, 0);
1072 ok(len == strlen(localhost) + 1, "unexpected length %d\n", len);
1073 str = HeapAlloc(GetProcessHeap(), 0, len);
1074 if (str)
1075 {
1076 len = pCertGetNameStringA(context, CERT_NAME_FRIENDLY_DISPLAY_TYPE,
1077 0, NULL, str, len);
1078 ok(!strcmp(str, localhost), "unexpected value %s\n", str);
1079 HeapFree(GetProcessHeap(), 0, str);
1080 }
1081
1082 len = pCertGetNameStringA(context, CERT_NAME_DNS_TYPE, 0, NULL, NULL,
1083 0);
1084 ok(len == strlen(localhost) + 1 || broken(len == 1) /* NT4 */,
1085 "unexpected length %d\n", len);
1086 if (len > 1)
1087 {
1088 str = HeapAlloc(GetProcessHeap(), 0, len);
1089 if (str)
1090 {
1091 len = pCertGetNameStringA(context, CERT_NAME_DNS_TYPE, 0, NULL,
1092 str, len);
1093 ok(!strcmp(str, localhost), "unexpected value %s\n", str);
1094 HeapFree(GetProcessHeap(), 0, str);
1095 }
1096 }
1097
1098 CertFreeCertificateContext(context);
1099 }
1100 }
1101
1102 START_TEST(str)
1103 {
1104 dll = GetModuleHandleA("Crypt32.dll");
1105
1106 pCertNameToStrA = (void*)GetProcAddress(dll,"CertNameToStrA");
1107 pCertNameToStrW = (void*)GetProcAddress(dll,"CertNameToStrW");
1108 pCertRDNValueToStrA = (void*)GetProcAddress(dll, "CertRDNValueToStrA");
1109 pCertRDNValueToStrW = (void*)GetProcAddress(dll, "CertRDNValueToStrW");
1110 pCertStrToNameA = (void*)GetProcAddress(dll,"CertStrToNameA");
1111 pCertStrToNameW = (void*)GetProcAddress(dll,"CertStrToNameW");
1112 pCertGetNameStringA = (void*)GetProcAddress(dll, "CertGetNameStringA");
1113
1114 test_CertRDNValueToStrA();
1115 test_CertRDNValueToStrW();
1116 test_CertNameToStrA();
1117 test_CertNameToStrW();
1118 test_CertStrToNameA();
1119 test_CertStrToNameW();
1120 test_CertGetNameStringA();
1121 }