ReactOS 0.4.16-dev-1946-g52006dd
str.c
Go to the documentation of this file.
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#include <winnls.h>
27
28#include "wine/test.h"
29
30typedef struct _CertRDNAttrEncoding {
36
37typedef struct _CertRDNAttrEncodingW {
43
44static BYTE bin1[] = { 0x55, 0x53 };
45static BYTE bin2[] = { 0x4d, 0x69, 0x6e, 0x6e, 0x65, 0x73, 0x6f, 0x74,
46 0x61 };
47static BYTE bin3[] = { 0x4d, 0x69, 0x6e, 0x6e, 0x65, 0x61, 0x70, 0x6f,
48 0x6c, 0x69, 0x73 };
49static BYTE bin4[] = { 0x43, 0x6f, 0x64, 0x65, 0x57, 0x65, 0x61, 0x76,
50 0x65, 0x72, 0x73 };
51static BYTE bin5[] = { 0x57, 0x69, 0x6e, 0x65, 0x20, 0x44, 0x65, 0x76,
52 0x65, 0x6c, 0x6f, 0x70, 0x6d, 0x65, 0x6e, 0x74 };
53static BYTE bin6[] = { 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73,
54 0x74 };
55static BYTE bin7[] = { 0x61, 0x72, 0x69, 0x63, 0x40, 0x63, 0x6f, 0x64,
56 0x65, 0x77, 0x65, 0x61, 0x76, 0x65, 0x72, 0x73, 0x2e, 0x63, 0x6f, 0x6d };
57static BYTE bin8[] = {
580x65,0x00,0x50,0x00,0x4b,0x00,0x49,0x00,0x20,0x00,0x52,0x00,0x6f,0x00,0x6f,
590x00,0x74,0x00,0x20,0x00,0x43,0x00,0x65,0x00,0x72,0x00,0x74,0x00,0x69,0x00,
600x66,0x00,0x69,0x00,0x63,0x00,0x61,0x00,0x74,0x00,0x69,0x00,0x6f,0x00,0x6e,
610x00,0x20,0x00,0x41,0x00,0x75,0x00,0x74,0x00,0x68,0x00,0x6f,0x00,0x72,0x00,
620x69,0x00,0x74,0x00,0x79,0x00 };
63static BYTE bin9[] = { 0x61, 0x62, 0x63, 0x22, 0x64, 0x65, 0x66 };
64static BYTE bin10[] = { 0x61, 0x62, 0x63, 0x27, 0x64, 0x65, 0x66 };
65static BYTE bin11[] = { 0x61, 0x62, 0x63, 0x2c, 0x20, 0x64, 0x65, 0x66 };
66static BYTE bin12[] = { 0x20, 0x61, 0x62, 0x63, 0x20 };
67static BYTE bin13[] = { 0x22, 0x64, 0x65, 0x66, 0x22 };
68static BYTE bin14[] = { 0x31, 0x3b, 0x33 };
69
70/*
71Certificate:
72 Data:
73 Version: 1 (0x0)
74 Serial Number:
75 e3:5a:10:f1:fc:4b:f3:a2
76 Signature Algorithm: md5WithRSAEncryption
77 Issuer: C = US, ST = Minnesota, L = Minneapolis, O = CodeWeavers, OU = Wine Development, CN = localhost, emailAddress = aric@codeweavers.com
78 Validity
79 Not Before: Jan 25 13:57:24 2006 GMT
80 Not After : Feb 24 13:57:24 2006 GMT
81 Subject: C = US, ST = Minnesota, L = Minneapolis, O = CodeWeavers, OU = Wine Development, CN = localhost, emailAddress = aric@codeweavers.com
82 Subject Public Key Info:
83 Public Key Algorithm: rsaEncryption
84 Public-Key: (1024 bit)
85 Modulus:
86...
87 Exponent: 65537 (0x10001)
88 Signature Algorithm: md5WithRSAEncryption
89...
90*/
91static const BYTE cert[] =
92{0x30,0x82,0x2,0xbb,0x30,0x82,0x2,0x24,0x2,0x9,0x0,0xe3,0x5a,0x10,0xf1,0xfc,
93 0x4b,0xf3,0xa2,0x30,0xd,0x6,0x9,0x2a,0x86,0x48,0x86,0xf7,0xd,0x1,0x1,0x4,0x5,
94 0x0,0x30,0x81,0xa1,0x31,0xb,0x30,0x9,0x6,0x3,0x55,0x4,0x6,0x13,0x2,0x55,0x53,
95 0x31,0x12,0x30,0x10,0x6,0x3,0x55,0x4,0x8,0x13,0x9,0x4d,0x69,0x6e,0x6e,0x65,
96 0x73,0x6f,0x74,0x61,0x31,0x14,0x30,0x12,0x6,0x3,0x55,0x4,0x7,0x13,0xb,0x4d,
97 0x69,0x6e,0x6e,0x65,0x61,0x70,0x6f,0x6c,0x69,0x73,0x31,0x14,0x30,0x12,0x6,0x3,
98 0x55,0x4,0xa,0x13,0xb,0x43,0x6f,0x64,0x65,0x57,0x65,0x61,0x76,0x65,0x72,0x73,
99 0x31,0x19,0x30,0x17,0x6,0x3,0x55,0x4,0xb,0x13,0x10,0x57,0x69,0x6e,0x65,0x20,
100 0x44,0x65,0x76,0x65,0x6c,0x6f,0x70,0x6d,0x65,0x6e,0x74,0x31,0x12,0x30,0x10,
101 0x6,0x3,0x55,0x4,0x3,0x13,0x9,0x6c,0x6f,0x63,0x61,0x6c,0x68,0x6f,0x73,0x74,
102 0x31,0x23,0x30,0x21,0x6,0x9,0x2a,0x86,0x48,0x86,0xf7,0xd,0x1,0x9,0x1,0x16,
103 0x14,0x61,0x72,0x69,0x63,0x40,0x63,0x6f,0x64,0x65,0x77,0x65,0x61,0x76,0x65,
104 0x72,0x73,0x2e,0x63,0x6f,0x6d,0x30,0x1e,0x17,0xd,0x30,0x36,0x30,0x31,0x32,
105 0x35,0x31,0x33,0x35,0x37,0x32,0x34,0x5a,0x17,0xd,0x30,0x36,0x30,0x32,0x32,
106 0x34,0x31,0x33,0x35,0x37,0x32,0x34,0x5a,0x30,0x81,0xa1,0x31,0xb,0x30,0x9,0x6,
107 0x3,0x55,0x4,0x6,0x13,0x2,0x55,0x53,0x31,0x12,0x30,0x10,0x6,0x3,0x55,0x4,0x8,
108 0x13,0x9,0x4d,0x69,0x6e,0x6e,0x65,0x73,0x6f,0x74,0x61,0x31,0x14,0x30,0x12,0x6,
109 0x3,0x55,0x4,0x7,0x13,0xb,0x4d,0x69,0x6e,0x6e,0x65,0x61,0x70,0x6f,0x6c,0x69,
110 0x73,0x31,0x14,0x30,0x12,0x6,0x3,0x55,0x4,0xa,0x13,0xb,0x43,0x6f,0x64,0x65,
111 0x57,0x65,0x61,0x76,0x65,0x72,0x73,0x31,0x19,0x30,0x17,0x6,0x3,0x55,0x4,0xb,
112 0x13,0x10,0x57,0x69,0x6e,0x65,0x20,0x44,0x65,0x76,0x65,0x6c,0x6f,0x70,0x6d,
113 0x65,0x6e,0x74,0x31,0x12,0x30,0x10,0x6,0x3,0x55,0x4,0x3,0x13,0x9,0x6c,0x6f,
114 0x63,0x61,0x6c,0x68,0x6f,0x73,0x74,0x31,0x23,0x30,0x21,0x6,0x9,0x2a,0x86,0x48,
115 0x86,0xf7,0xd,0x1,0x9,0x1,0x16,0x14,0x61,0x72,0x69,0x63,0x40,0x63,0x6f,0x64,
116 0x65,0x77,0x65,0x61,0x76,0x65,0x72,0x73,0x2e,0x63,0x6f,0x6d,0x30,0x81,0x9f,
117 0x30,0xd,0x6,0x9,0x2a,0x86,0x48,0x86,0xf7,0xd,0x1,0x1,0x1,0x5,0x0,0x3,0x81,
118 0x8d,0x0,0x30,0x81,0x89,0x2,0x81,0x81,0x0,0x9b,0xb5,0x8f,0xaf,0xfb,0x9a,0xaf,
119 0xdc,0xa2,0x4d,0xb1,0xc8,0x72,0x44,0xef,0x79,0x7f,0x28,0xb6,0xfe,0x50,0xdc,
120 0x8a,0xf7,0x11,0x2f,0x90,0x70,0xed,0xa4,0xa9,0xd,0xbf,0x82,0x3e,0x56,0xd8,
121 0x36,0xb6,0x9,0x52,0x83,0xab,0x65,0x95,0x0,0xe2,0xea,0x3c,0x4f,0x85,0xb8,0xc,
122 0x41,0x42,0x77,0x5c,0x9d,0x44,0xeb,0xcf,0x7d,0x60,0x64,0x7a,0x6c,0x4c,0xac,
123 0x4a,0x9a,0x23,0x25,0x15,0xd7,0x92,0xb4,0x10,0xe7,0x95,0xad,0x4b,0x93,0xda,
124 0x6a,0x76,0xe0,0xa5,0xd2,0x13,0x8,0x12,0x30,0x68,0xde,0xb9,0x5b,0x6e,0x2a,
125 0x97,0x43,0xaa,0x7b,0x22,0x33,0x34,0xb1,0xca,0x5d,0x19,0xd8,0x42,0x26,0x45,
126 0xc6,0xe9,0x1d,0xee,0x7,0xc2,0x27,0x95,0x87,0xd8,0x12,0xec,0x4b,0x16,0x9f,0x2,
127 0x3,0x1,0x0,0x1,0x30,0xd,0x6,0x9,0x2a,0x86,0x48,0x86,0xf7,0xd,0x1,0x1,0x4,0x5,
128 0x0,0x3,0x81,0x81,0x0,0x96,0xf9,0xf6,0x6a,0x3d,0xd9,0xca,0x6e,0xd5,0x76,0x73,
129 0xab,0x75,0xc1,0xcc,0x98,0x44,0xc3,0xa9,0x90,0x68,0x88,0x76,0xb9,0xeb,0xb6,
130 0xbe,0x60,0x62,0xb9,0x67,0x1e,0xcc,0xf4,0xe1,0xe7,0x6c,0xc8,0x67,0x3f,0x1d,
131 0xf3,0x68,0x86,0x30,0xee,0xaa,0x92,0x61,0x37,0xd7,0x82,0x90,0x28,0xaa,0x7a,
132 0x18,0x88,0x60,0x14,0x88,0x75,0xc0,0x4a,0x4e,0x7d,0x48,0xe7,0x3,0xa6,0xfd,
133 0xd7,0xce,0x3c,0xe5,0x9b,0xaf,0x2f,0xdc,0xbb,0x7c,0xbd,0x20,0x49,0xd9,0x68,
134 0x37,0xeb,0x5d,0xbb,0xe2,0x6d,0x66,0xe3,0x11,0xc1,0xa7,0x88,0x49,0xc6,0x6f,
135 0x65,0xd3,0xce,0xae,0x26,0x19,0x3,0x2e,0x4f,0x78,0xa5,0xa,0x97,0x7e,0x4f,0xc4,
136 0x91,0x8a,0xf8,0x5,0xef,0x5b,0x3b,0x49,0xbf,0x5f,0x2b};
137
138/*
139Certificate:
140 Data:
141 Version: 1 (0x0)
142 Serial Number:
143 59:9e:db:44:80:da:6c:92:f9:38:be:d8:fe:7a:20:77:57:c7:71:5b
144 Signature Algorithm: md5WithRSAEncryption
145 Issuer: C = US, ST = Minnesota, L = Minneapolis, O = CodeWeavers, OU = Wine Development, CN = localhost
146 Validity
147 Not Before: Mar 17 22:20:44 2023 GMT
148 Not After : Apr 16 22:20:44 2023 GMT
149 Subject: C = US, ST = Minnesota, L = Minneapolis, O = CodeWeavers, OU = Wine Development, CN = localhost
150 Subject Public Key Info:
151 Public Key Algorithm: rsaEncryption
152 Public-Key: (1024 bit)
153 Modulus:
154...
155 Exponent: 65537 (0x10001)
156 Signature Algorithm: md5WithRSAEncryption
157...
158*/
159static const BYTE cert_no_email[] = {
160 0x30,0x82,0x02,0x7a,0x30,0x82,0x01,0xe3,0x02,0x14,0x59,0x9e,0xdb,0x44,0x80,0xda,
161 0x6c,0x92,0xf9,0x38,0xbe,0xd8,0xfe,0x7a,0x20,0x77,0x57,0xc7,0x71,0x5b,0x30,0x0d,
162 0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x04,0x05,0x00,0x30,0x7c,0x31,
163 0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x12,0x30,0x10,
164 0x06,0x03,0x55,0x04,0x08,0x0c,0x09,0x4d,0x69,0x6e,0x6e,0x65,0x73,0x6f,0x74,0x61,
165 0x31,0x14,0x30,0x12,0x06,0x03,0x55,0x04,0x07,0x0c,0x0b,0x4d,0x69,0x6e,0x6e,0x65,
166 0x61,0x70,0x6f,0x6c,0x69,0x73,0x31,0x14,0x30,0x12,0x06,0x03,0x55,0x04,0x0a,0x0c,
167 0x0b,0x43,0x6f,0x64,0x65,0x57,0x65,0x61,0x76,0x65,0x72,0x73,0x31,0x19,0x30,0x17,
168 0x06,0x03,0x55,0x04,0x0b,0x0c,0x10,0x57,0x69,0x6e,0x65,0x20,0x44,0x65,0x76,0x65,
169 0x6c,0x6f,0x70,0x6d,0x65,0x6e,0x74,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,
170 0x0c,0x09,0x6c,0x6f,0x63,0x61,0x6c,0x68,0x6f,0x73,0x74,0x30,0x1e,0x17,0x0d,0x32,
171 0x33,0x30,0x33,0x31,0x37,0x32,0x32,0x32,0x30,0x34,0x34,0x5a,0x17,0x0d,0x32,0x33,
172 0x30,0x34,0x31,0x36,0x32,0x32,0x32,0x30,0x34,0x34,0x5a,0x30,0x7c,0x31,0x0b,0x30,
173 0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x12,0x30,0x10,0x06,0x03,
174 0x55,0x04,0x08,0x0c,0x09,0x4d,0x69,0x6e,0x6e,0x65,0x73,0x6f,0x74,0x61,0x31,0x14,
175 0x30,0x12,0x06,0x03,0x55,0x04,0x07,0x0c,0x0b,0x4d,0x69,0x6e,0x6e,0x65,0x61,0x70,
176 0x6f,0x6c,0x69,0x73,0x31,0x14,0x30,0x12,0x06,0x03,0x55,0x04,0x0a,0x0c,0x0b,0x43,
177 0x6f,0x64,0x65,0x57,0x65,0x61,0x76,0x65,0x72,0x73,0x31,0x19,0x30,0x17,0x06,0x03,
178 0x55,0x04,0x0b,0x0c,0x10,0x57,0x69,0x6e,0x65,0x20,0x44,0x65,0x76,0x65,0x6c,0x6f,
179 0x70,0x6d,0x65,0x6e,0x74,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x0c,0x09,
180 0x6c,0x6f,0x63,0x61,0x6c,0x68,0x6f,0x73,0x74,0x30,0x81,0x9f,0x30,0x0d,0x06,0x09,
181 0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x81,0x8d,0x00,0x30,
182 0x81,0x89,0x02,0x81,0x81,0x00,0xc4,0xdd,0x00,0xa7,0xdb,0xec,0x95,0x68,0xee,0xf0,
183 0x3f,0xed,0xb2,0xcb,0x6f,0xf4,0x34,0x2f,0xbe,0x13,0xa9,0x24,0x95,0xf3,0xca,0x3c,
184 0x2b,0xd3,0x41,0x7c,0x32,0xe7,0x95,0x4e,0xdd,0xef,0xcc,0x45,0x0d,0xf2,0x71,0x42,
185 0x12,0x78,0xb1,0x17,0x88,0xf4,0x12,0xba,0x92,0x2d,0x5c,0xfc,0x2c,0x8a,0x53,0xbf,
186 0xee,0x23,0x3f,0x7b,0x11,0x46,0x5e,0x1d,0xb8,0xff,0xa3,0x70,0x5c,0x5f,0x6b,0xa8,
187 0x3c,0x47,0x75,0xa5,0x3a,0x80,0x61,0x15,0x10,0x56,0x57,0x1f,0x82,0x6a,0xb2,0xb8,
188 0xdc,0x3a,0xe0,0x1c,0x9c,0x83,0xd9,0x11,0x26,0xa6,0xb6,0x85,0x0a,0x27,0x45,0xb7,
189 0xff,0xfa,0x26,0xbd,0x11,0x29,0x23,0x59,0xaa,0x19,0x77,0x3f,0x86,0x32,0x9f,0x48,
190 0x43,0x4f,0xd0,0x03,0x7a,0x09,0x02,0x03,0x01,0x00,0x01,0x30,0x0d,0x06,0x09,0x2a,
191 0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x04,0x05,0x00,0x03,0x81,0x81,0x00,0xa3,0xf0,
192 0x23,0xfc,0x80,0x05,0xac,0x76,0x26,0xbb,0xfc,0x79,0x03,0x10,0xa0,0xfb,0x7a,0x3e,
193 0xf9,0xa7,0xdd,0xb1,0x9e,0x7c,0x22,0x83,0xa6,0xee,0x77,0x88,0xa2,0x74,0x64,0x35,
194 0x4f,0x66,0x82,0x88,0x4a,0x83,0xc9,0xda,0x7e,0xc4,0xa0,0xd1,0xfb,0xe1,0x3e,0x22,
195 0x1e,0xa8,0xdc,0x1b,0xd4,0xda,0x64,0x63,0xfc,0x1b,0x61,0x4f,0x52,0x1b,0xab,0x61,
196 0x05,0xcd,0xb8,0x2d,0xb0,0x73,0xa7,0x5d,0x78,0xff,0x3f,0x4d,0x12,0x3a,0x38,0x69,
197 0xc4,0x9f,0x77,0x35,0xce,0xe2,0xf9,0xd6,0x23,0x47,0xc2,0x15,0xff,0xbf,0x3e,0x65,
198 0xf3,0xc0,0x0a,0x58,0x76,0x10,0x8e,0xd5,0xa9,0x30,0x3e,0x25,0x4b,0x6d,0xb7,0xb2,
199 0x64,0x96,0x0e,0x27,0x88,0x55,0xfc,0xaa,0x18,0x65,0x2a,0xe9,0xf4,0x23
200};
201
202/*
203Certificate:
204 Data:
205 Version: 3 (0x2)
206 Serial Number:
207 5d:79:35:fd:d3:8f:6b:e2:28:3e:94:f4:14:bf:d4:b5:c2:3a:ac:38
208 Signature Algorithm: md5WithRSAEncryption
209 Issuer: C = US, ST = Minnesota, L = Minneapolis, O = CodeWeavers, CN = server_cn.org, emailAddress = test@codeweavers.com
210 Validity
211 Not Before: Apr 14 18:56:22 2022 GMT
212 Not After : Apr 11 18:56:22 2032 GMT
213 Subject: C = US, ST = Minnesota, L = Minneapolis, O = CodeWeavers, CN = server_cn.org, emailAddress = test@codeweavers.com
214 Subject Public Key Info:
215 Public Key Algorithm: rsaEncryption
216 RSA Public-Key: (1024 bit)
217 Modulus:
218...
219 Exponent: 65537 (0x10001)
220 X509v3 extensions:
221 X509v3 Subject Alternative Name:
222 DNS:ex1.org, DNS:*.ex2.org
223 X509v3 Issuer Alternative Name:
224 DNS:ex3.org, DNS:*.ex4.org
225 Signature Algorithm: md5WithRSAEncryption
226...
227*/
228static BYTE cert_v3[] = {
229 0x30, 0x82, 0x02, 0xdf, 0x30, 0x82, 0x02, 0x48, 0xa0, 0x03, 0x02, 0x01,
230 0x02, 0x02, 0x14, 0x5d, 0x79, 0x35, 0xfd, 0xd3, 0x8f, 0x6b, 0xe2, 0x28,
231 0x3e, 0x94, 0xf4, 0x14, 0xbf, 0xd4, 0xb5, 0xc2, 0x3a, 0xac, 0x38, 0x30,
232 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x04,
233 0x05, 0x00, 0x30, 0x81, 0x8a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
234 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03,
235 0x55, 0x04, 0x08, 0x0c, 0x09, 0x4d, 0x69, 0x6e, 0x6e, 0x65, 0x73, 0x6f,
236 0x74, 0x61, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c,
237 0x0b, 0x4d, 0x69, 0x6e, 0x6e, 0x65, 0x61, 0x70, 0x6f, 0x6c, 0x69, 0x73,
238 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x0b, 0x43,
239 0x6f, 0x64, 0x65, 0x57, 0x65, 0x61, 0x76, 0x65, 0x72, 0x73, 0x31, 0x16,
240 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0d, 0x73, 0x65, 0x72,
241 0x76, 0x65, 0x72, 0x5f, 0x63, 0x6e, 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x23,
242 0x30, 0x21, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
243 0x01, 0x16, 0x14, 0x74, 0x65, 0x73, 0x74, 0x40, 0x63, 0x6f, 0x64, 0x65,
244 0x77, 0x65, 0x61, 0x76, 0x65, 0x72, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x30,
245 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x34, 0x31, 0x34, 0x31, 0x38, 0x35,
246 0x36, 0x32, 0x32, 0x5a, 0x17, 0x0d, 0x33, 0x32, 0x30, 0x34, 0x31, 0x31,
247 0x31, 0x38, 0x35, 0x36, 0x32, 0x32, 0x5a, 0x30, 0x81, 0x8a, 0x31, 0x0b,
248 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,
249 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x09, 0x4d, 0x69,
250 0x6e, 0x6e, 0x65, 0x73, 0x6f, 0x74, 0x61, 0x31, 0x14, 0x30, 0x12, 0x06,
251 0x03, 0x55, 0x04, 0x07, 0x0c, 0x0b, 0x4d, 0x69, 0x6e, 0x6e, 0x65, 0x61,
252 0x70, 0x6f, 0x6c, 0x69, 0x73, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
253 0x04, 0x0a, 0x0c, 0x0b, 0x43, 0x6f, 0x64, 0x65, 0x57, 0x65, 0x61, 0x76,
254 0x65, 0x72, 0x73, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x03,
255 0x0c, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x63, 0x6e, 0x2e,
256 0x6f, 0x72, 0x67, 0x31, 0x23, 0x30, 0x21, 0x06, 0x09, 0x2a, 0x86, 0x48,
257 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x14, 0x74, 0x65, 0x73, 0x74,
258 0x40, 0x63, 0x6f, 0x64, 0x65, 0x77, 0x65, 0x61, 0x76, 0x65, 0x72, 0x73,
259 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a,
260 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81,
261 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xcd, 0x7c, 0x05,
262 0xba, 0xad, 0xd0, 0xb0, 0x43, 0xcc, 0x47, 0x7d, 0x87, 0xaa, 0xb5, 0x89,
263 0x9f, 0x43, 0x94, 0xa0, 0x84, 0xc0, 0xc0, 0x5e, 0x05, 0x6d, 0x2f, 0x05,
264 0x21, 0x6b, 0x20, 0x39, 0x88, 0x06, 0x4e, 0xce, 0x76, 0xa7, 0x24, 0x77,
265 0x13, 0x71, 0x9b, 0x2a, 0x53, 0x04, 0x4f, 0x0f, 0xfc, 0x3f, 0x4f, 0xb1,
266 0x4e, 0xdc, 0xed, 0x96, 0xd4, 0x55, 0xbd, 0xcf, 0x25, 0xa6, 0x7c, 0xe3,
267 0x35, 0xbf, 0xeb, 0x30, 0xec, 0xef, 0x7f, 0x8e, 0xa1, 0xc6, 0xd3, 0xb2,
268 0x03, 0x62, 0x0a, 0x92, 0x87, 0x17, 0x52, 0x2d, 0x45, 0x2a, 0xdc, 0xdb,
269 0x87, 0xa5, 0x32, 0x4a, 0x78, 0x28, 0x4a, 0x51, 0xff, 0xdb, 0xd5, 0x20,
270 0x47, 0x7e, 0xc5, 0xbe, 0x1d, 0x01, 0x55, 0x13, 0x9f, 0xfb, 0x8e, 0x39,
271 0xd9, 0x1b, 0xe0, 0x34, 0x93, 0x43, 0x9c, 0x02, 0xa3, 0x0f, 0xb5, 0xdc,
272 0x9d, 0x86, 0x45, 0xc5, 0x4d, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x40,
273 0x30, 0x3e, 0x30, 0x1d, 0x06, 0x03,
274 0x55, 0x1d, 0x11, /* Subject Alternative Name OID */
275 0x04, 0x16, 0x30, 0x14, 0x82, 0x07, 0x65, 0x78, 0x31, 0x2e, 0x6f, 0x72,
276 0x67, 0x82, 0x09, 0x2a, 0x2e, 0x65, 0x78, 0x32, 0x2e, 0x6f, 0x72, 0x67,
277 0x30, 0x1d, 0x06, 0x03,
278 0x55, 0x1d, 0x12, /* Issuer Alternative Name OID */
279 0x04, 0x16, 0x30, 0x14, 0x82, 0x07, 0x65, 0x78, 0x33, 0x2e, 0x6f, 0x72,
280 0x67, 0x82, 0x09, 0x2a, 0x2e, 0x65, 0x78, 0x34, 0x2e, 0x6f, 0x72, 0x67,
281 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
282 0x04, 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, 0xcc, 0xa3, 0x75, 0x67, 0x61,
283 0x63, 0x1d, 0x99, 0x16, 0xc6, 0x93, 0x35, 0xa4, 0x31, 0xb6, 0x05, 0x05,
284 0x77, 0x12, 0x15, 0x16, 0x78, 0xb3, 0xba, 0x6e, 0xde, 0xfc, 0x73, 0x7c,
285 0x5c, 0xdd, 0xdf, 0x92, 0xde, 0xa0, 0x86, 0xff, 0x77, 0x60, 0x99, 0x8f,
286 0x4a, 0x40, 0xa8, 0x6a, 0xdb, 0x6f, 0x30, 0xe5, 0xce, 0x82, 0x2f, 0xf7,
287 0x09, 0x17, 0xb2, 0xd3, 0x3a, 0x29, 0x9a, 0xd0, 0x73, 0x9c, 0x44, 0xa2,
288 0x19, 0xf3, 0x1d, 0x16, 0x1a, 0x45, 0x2c, 0x4b, 0x94, 0xf1, 0xb8, 0xb6,
289 0xc9, 0x82, 0x6c, 0x1f, 0xae, 0xbc, 0xd1, 0xbe, 0x78, 0xc9, 0x23, 0xf5,
290 0x51, 0x6c, 0x90, 0xbf, 0xa3, 0x5c, 0xa1, 0x3a, 0xd8, 0xe3, 0xcf, 0x82,
291 0x31, 0x78, 0x2b, 0xda, 0x99, 0xff, 0x23, 0x5b, 0xea, 0x59, 0xe0, 0x6d,
292 0xd1, 0x30, 0xfd, 0x96, 0x6a, 0x4d, 0x36, 0x72, 0x96, 0xd7, 0x4f, 0x01,
293 0xa9, 0x4d, 0x8f
294};
295
296#define CERT_V3_SAN_OID_OFFSET 534
297#define CERT_V3_IAN_OID_OFFSET 565
298
299static char issuerStr[] =
300 "US, Minnesota, Minneapolis, CodeWeavers, Wine Development, localhost, aric@codeweavers.com";
301static char issuerStrSemicolon[] =
302 "US; Minnesota; Minneapolis; CodeWeavers; Wine Development; localhost; aric@codeweavers.com";
303static char issuerStrCRLF[] =
304 "US\r\nMinnesota\r\nMinneapolis\r\nCodeWeavers\r\nWine Development\r\nlocalhost\r\naric@codeweavers.com";
305static char subjectStr[] =
306 "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";
307static char subjectStrSemicolon[] =
308 "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";
309static char subjectStrCRLF[] =
310 "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";
311static char x500SubjectStr[] = "C=US, S=Minnesota, L=Minneapolis, O=CodeWeavers, OU=Wine Development, CN=localhost, E=aric@codeweavers.com";
312static char x500SubjectStrSemicolonReverse[] = "E=aric@codeweavers.com; CN=localhost; OU=Wine Development; O=CodeWeavers; L=Minneapolis; S=Minnesota; C=US";
313
314static void test_CertRDNValueToStrA(void)
315{
316 CertRDNAttrEncoding attrs[] = {
317 { "2.5.4.6", CERT_RDN_PRINTABLE_STRING,
318 { sizeof(bin1), bin1 }, "US" },
319 { "2.5.4.8", CERT_RDN_PRINTABLE_STRING,
320 { sizeof(bin2), bin2 }, "Minnesota" },
321 { "2.5.4.7", CERT_RDN_PRINTABLE_STRING,
322 { sizeof(bin3), bin3 }, "Minneapolis" },
323 { "2.5.4.10", CERT_RDN_PRINTABLE_STRING,
324 { sizeof(bin4), bin4 }, "CodeWeavers" },
325 { "2.5.4.11", CERT_RDN_PRINTABLE_STRING,
326 { sizeof(bin5), bin5 }, "Wine Development" },
327 { "2.5.4.3", CERT_RDN_PRINTABLE_STRING,
328 { sizeof(bin6), bin6 }, "localhost" },
329 { "1.2.840.113549.1.9.1", CERT_RDN_IA5_STRING,
330 { sizeof(bin7), bin7 }, "aric@codeweavers.com" },
332 { sizeof(bin9), bin9 }, "abc\"def" },
334 { sizeof(bin10), bin10 }, "abc'def" },
336 { sizeof(bin11), bin11 }, "abc, def" },
338 { sizeof(bin12), bin12 }, " abc " },
340 { sizeof(bin13), bin13 }, "\"def\"" },
342 { sizeof(bin14), bin14 }, "1;3" },
343 };
344 unsigned int i;
345 DWORD ret, len;
346 char buffer[2000];
348 static const char ePKI[] = "ePKI Root Certification Authority";
349
350 /* This crashes
351 ret = CertRDNValueToStrA(0, NULL, NULL, 0);
352 */
353 /* With empty input, it generates the empty string */
354 SetLastError(0xdeadbeef);
355 ret = CertRDNValueToStrA(0, &blob, NULL, 0);
356 ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
357 ret = CertRDNValueToStrA(0, &blob, buffer, sizeof(buffer));
358 ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
359 ok(!buffer[0], "Expected empty string\n");
360
361 for (i = 0; i < ARRAY_SIZE(attrs); i++)
362 {
363 len = CertRDNValueToStrA(attrs[i].dwValueType, &attrs[i].Value,
364 buffer, sizeof(buffer));
365 ok(len == strlen(attrs[i].str) + 1, "Expected length %d, got %ld\n",
366 lstrlenA(attrs[i].str) + 1, ret);
367 ok(!strcmp(buffer, attrs[i].str), "Expected %s, got %s\n",
368 attrs[i].str, buffer);
369 memset(buffer, 0xcc, sizeof(buffer));
370 ret = CertRDNValueToStrA(attrs[i].dwValueType, &attrs[i].Value, buffer, len - 1);
371 ok(ret == 1, "Unexpected ret %lu, expected 1, test %u.\n", ret, i);
372 ok(!buffer[0], "Unexpected value %#x, test %u.\n", buffer[0], i);
373 ok(!strncmp(buffer + 1, attrs[i].str + 1, len - 2), "Strings do not match, test %u.\n", i);
374 memset(buffer, 0xcc, sizeof(buffer));
375 ret = CertRDNValueToStrA(attrs[i].dwValueType, &attrs[i].Value, buffer, 0);
376 ok(ret == len, "Unexpected ret %lu, expected %lu, test %u.\n", ret, len, i);
377 ok((unsigned char)buffer[0] == 0xcc, "Unexpected value %#x, test %u.\n", buffer[0], i);
378 }
379 blob.pbData = bin8;
380 blob.cbData = sizeof(bin8);
382 sizeof(buffer));
383 ok(ret == strlen(ePKI) + 1, "Expected length %d, got %ld\n", lstrlenA(ePKI), ret);
384 if (ret == strlen(ePKI) + 1)
385 ok(!strcmp(buffer, ePKI), "Expected %s, got %s\n", ePKI, buffer);
386}
387
388static void test_CertRDNValueToStrW(void)
389{
390 static const WCHAR ePKIW[] = L"ePKI Root Certification Authority";
391 CertRDNAttrEncodingW attrs[] = {
392 { "2.5.4.6", CERT_RDN_PRINTABLE_STRING,
393 { sizeof(bin1), bin1 }, L"US" },
394 { "2.5.4.8", CERT_RDN_PRINTABLE_STRING,
395 { sizeof(bin2), bin2 }, L"Minnesota" },
396 { "2.5.4.7", CERT_RDN_PRINTABLE_STRING,
397 { sizeof(bin3), bin3 }, L"Minneapolis" },
398 { "2.5.4.10", CERT_RDN_PRINTABLE_STRING,
399 { sizeof(bin4), bin4 }, L"CodeWeavers" },
400 { "2.5.4.11", CERT_RDN_PRINTABLE_STRING,
401 { sizeof(bin5), bin5 }, L"Wine Development" },
402 { "2.5.4.3", CERT_RDN_PRINTABLE_STRING,
403 { sizeof(bin6), bin6 }, L"localhost" },
404 { "1.2.840.113549.1.9.1", CERT_RDN_IA5_STRING,
405 { sizeof(bin7), bin7 }, L"aric@codeweavers.com" },
407 { sizeof(bin9), bin9 }, L"abc\"def" },
409 { sizeof(bin10), bin10 }, L"abc'def" },
411 { sizeof(bin11), bin11 }, L"abc, def" },
413 { sizeof(bin12), bin12 }, L" abc " },
415 { sizeof(bin13), bin13 }, L"\"def\"" },
417 { sizeof(bin14), bin14 }, L"1;3" },
418 };
419 unsigned int i;
420 DWORD ret, len;
421 WCHAR buffer[2000];
423
424 /* This crashes
425 ret = CertRDNValueToStrW(0, NULL, NULL, 0);
426 */
427 /* With empty input, it generates the empty string */
428 SetLastError(0xdeadbeef);
429 ret = CertRDNValueToStrW(0, &blob, NULL, 0);
430 ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
432 ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
433 ok(!buffer[0], "Expected empty string\n");
434
435 for (i = 0; i < ARRAY_SIZE(attrs); i++)
436 {
437 len = CertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value, buffer, ARRAY_SIZE(buffer));
438 ok(len == lstrlenW(attrs[i].str) + 1,
439 "Expected length %d, got %ld\n", lstrlenW(attrs[i].str) + 1, ret);
440 ok(!lstrcmpW(buffer, attrs[i].str), "Expected %s, got %s\n",
442 memset(buffer, 0xcc, sizeof(buffer));
443 ret = CertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value, buffer, len - 1);
444 ok(ret == 1, "Unexpected ret %lu, expected 1, test %u.\n", ret, i);
445 ok(!buffer[0], "Unexpected value %#x, test %u.\n", buffer[0], i);
446 ok(buffer[1] == 0xcccc, "Unexpected value %#x, test %u.\n", buffer[1], i);
447 memset(buffer, 0xcc, sizeof(buffer));
448 ret = CertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value, buffer, 0);
449 ok(ret == len, "Unexpected ret %lu, expected %lu, test %u.\n", ret, len, i);
450 ok(buffer[0] == 0xcccc, "Unexpected value %#x, test %u.\n", buffer[0], i);
451 }
452 blob.pbData = bin8;
453 blob.cbData = sizeof(bin8);
455 sizeof(buffer));
456 ok(ret == lstrlenW(ePKIW) + 1, "Expected length %d, got %ld\n", lstrlenW(ePKIW), ret);
457 if (ret == lstrlenW(ePKIW) + 1)
458 ok(!lstrcmpW(buffer, ePKIW), "Expected %s, got %s\n",
460}
461
462#define test_NameToStrConversionA(a, b, c) test_NameToStrConversionA_(__LINE__, a, b, c)
464{
465 char buffer[2000];
466 DWORD len, retlen;
467
468 len = CertNameToStrA(X509_ASN_ENCODING, pName, dwStrType, NULL, 0);
469 ok(len == strlen(expected) + 1, "line %u: Expected %d chars, got %ld.\n", line, lstrlenA(expected) + 1, len);
470 len = CertNameToStrA(X509_ASN_ENCODING,pName, dwStrType, buffer, sizeof(buffer));
471 ok(len == strlen(expected) + 1, "line %u: Expected %d chars, got %ld.\n", line, lstrlenA(expected) + 1, len);
472 ok(!strcmp(buffer, expected), "line %u: Expected %s, got %s.\n", line, expected, buffer);
473
474 memset(buffer, 0xcc, sizeof(buffer));
475 retlen = CertNameToStrA(X509_ASN_ENCODING, pName, dwStrType, buffer, len - 1);
476 ok(retlen == 1, "line %u: expected 1, got %lu\n", line, retlen);
477 ok(!buffer[0], "line %u: string is not zero terminated.\n", line);
478
479 memset(buffer, 0xcc, sizeof(buffer));
480 retlen = CertNameToStrA(X509_ASN_ENCODING, pName, dwStrType, buffer, 0);
481 ok(retlen == len, "line %u: expected %lu chars, got %lu\n", line, len - 1, retlen);
482 ok((unsigned char)buffer[0] == 0xcc, "line %u: got %s\n", line, wine_dbgstr_a(buffer));
483}
484
4860x30,0x0c,0x31,0x0a,0x30,0x08,0x06,0x03,0x55,0x04,0x03,0x13,0x01,0x31 };
487static BYTE encodedSingleQuotedCN[] = { 0x30,0x0e,0x31,0x0c,0x30,0x0a,
488 0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x27,0x31,0x27 };
489static BYTE encodedSpacedCN[] = { 0x30,0x0e,0x31,0x0c,0x30,0x0a,0x06,0x03,
490 0x55,0x04,0x03,0x13,0x03,0x20,0x31,0x20 };
491static BYTE encodedQuotedCN[] = { 0x30,0x11,0x31,0x0f,0x30,0x0d,0x06,0x03,
492 0x55, 0x04,0x03,0x1e,0x06,0x00,0x22,0x00,0x31,0x00,0x22, };
493static BYTE encodedMultipleAttrCN[] = { 0x30,0x0e,0x31,0x0c,0x30,0x0a,
494 0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x31,0x2b,0x32 };
4960x30,0x0e,0x31,0x0c,0x30,0x0a,0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x61,0x2c,
4970x62 };
4990x30,0x0e,0x31,0x0c,0x30,0x0a,0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x61,0x3d,
5000x62 };
5020x30,0x0d,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x03,0x1e,0x02,0x00,0x3c
503};
5050x30,0x0d,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x03,0x1e,0x02,0x00,0x3e
506};
507static BYTE encodedHashCN[] = {
5080x30,0x0d,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x03,0x1e,0x02,0x00,0x23
509};
510static BYTE encodedSemiCN[] = {
5110x30,0x0d,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x03,0x1e,0x02,0x00,0x3b
512};
5140x30,0x11,0x31,0x0f,0x30,0x0d,0x06,0x03,0x55,0x04,0x03,0x1e,0x06,0x00,0x61,
5150x00,0x0a,0x00,0x62 };
5170x30,0x1F,0x31,0x0E,0x30,0x0C,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x64,0x75,
5180x6D,0x6D,0x79,0x31,0x0D,0x30,0x0B,0x06,0x03,0x55,0x04,0x0C,0x13,0x04,0x74,
5190x65,0x73,0x74 };
520static BYTE encodedFields[] = {
5210x30,0x2F,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x57,0x69,
5220x6E,0x65,0x20,0x54,0x65,0x73,0x74,0x31,0x0C,0x30,0x0A,0x06,0x03,0x55,0x04,
5230x0C,0x13,0x03,0x31,0x32,0x33,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,
5240x13,0x02,0x42,0x52 };
525
526static void test_CertNameToStrA(void)
527{
530
532 sizeof(cert));
533 ok(context != NULL, "CertCreateCertificateContext failed: %08lx\n",
534 GetLastError());
535 if (context)
536 {
537 DWORD ret;
538
539 /* This crashes
540 ret = CertNameToStrA(0, NULL, 0, NULL, 0);
541 */
542 /* Test with a bogus encoding type */
543 SetLastError(0xdeadbeef);
544 ret = CertNameToStrA(0, &context->pCertInfo->Issuer, 0, NULL, 0);
546 "Expected retval 1 and ERROR_FILE_NOT_FOUND, got %ld - %08lx\n",
547 ret, GetLastError());
548 SetLastError(0xdeadbeef);
549 ret = CertNameToStrA(X509_ASN_ENCODING, &context->pCertInfo->Issuer,
550 0, NULL, 0);
552 "Expected positive return and ERROR_SUCCESS, got %ld - %08lx\n",
553 ret, GetLastError());
554
556 test_NameToStrConversionA(&context->pCertInfo->Issuer,
558 test_NameToStrConversionA(&context->pCertInfo->Issuer,
561 test_NameToStrConversionA(&context->pCertInfo->Subject,
563 test_NameToStrConversionA(&context->pCertInfo->Subject,
565 test_NameToStrConversionA(&context->pCertInfo->Subject,
567 test_NameToStrConversionA(&context->pCertInfo->Subject,
570
572 }
573 blob.pbData = encodedSimpleCN;
574 blob.cbData = sizeof(encodedSimpleCN);
577 blob.cbData = sizeof(encodedSingleQuotedCN);
580 blob.pbData = encodedSpacedCN;
581 blob.cbData = sizeof(encodedSpacedCN);
584 blob.pbData = encodedQuotedCN;
585 blob.cbData = sizeof(encodedQuotedCN);
589 blob.cbData = sizeof(encodedMultipleAttrCN);
592 blob.pbData = encodedCommaCN;
593 blob.cbData = sizeof(encodedCommaCN);
596 blob.pbData = encodedEqualCN;
597 blob.cbData = sizeof(encodedEqualCN);
600 blob.pbData = encodedLessThanCN;
601 blob.cbData = sizeof(encodedLessThanCN);
604 blob.pbData = encodedGreaterThanCN;
605 blob.cbData = sizeof(encodedGreaterThanCN);
608 blob.pbData = encodedHashCN;
609 blob.cbData = sizeof(encodedHashCN);
612 blob.pbData = encodedSemiCN;
613 blob.cbData = sizeof(encodedSemiCN);
616 blob.pbData = encodedNewlineCN;
617 blob.cbData = sizeof(encodedNewlineCN);
620}
621
622#define test_NameToStrConversionW(a, b, c) test_NameToStrConversionW_(__LINE__, a, b, c)
624{
625 DWORD len, retlen, expected_len;
626 WCHAR buffer[2000];
627
628 expected_len = wcslen(expected) + 1;
629 memset(buffer, 0xcc, sizeof(buffer));
630 len = CertNameToStrW(X509_ASN_ENCODING, pName, dwStrType, NULL, 0);
631 ok(len == expected_len, "line %u: expected %lu chars, got %lu\n", line, expected_len, len);
633 ok(retlen == len, "line %u: expected %lu chars, got %lu.\n", line, len, retlen);
634 ok(!wcscmp(buffer, expected), "Expected %s, got %s\n", wine_dbgstr_w(expected), wine_dbgstr_w(buffer));
635
636 memset(buffer, 0xcc, sizeof(buffer));
637 retlen = CertNameToStrW(X509_ASN_ENCODING, pName, dwStrType, buffer, len - 1);
638 ok(retlen == len - 1, "line %u: expected %lu chars, got %lu\n", line, len - 1, retlen);
639 ok(!wcsncmp(buffer, expected, retlen - 1), "line %u: expected %s, got %s\n",
641 ok(!buffer[retlen - 1], "line %u: string is not zero terminated.\n", line);
642
643 memset(buffer, 0xcc, sizeof(buffer));
644 retlen = CertNameToStrW(X509_ASN_ENCODING, pName, dwStrType, buffer, 0);
645 ok(retlen == len, "line %u: expected %lu chars, got %lu\n", line, len - 1, retlen);
646 ok(buffer[0] == 0xcccc, "line %u: got %s\n", line, wine_dbgstr_w(buffer));
647}
648
649static void test_CertNameToStrW(void)
650{
653
655 sizeof(cert));
656 ok(context != NULL, "CertCreateCertificateContext failed: %08lx\n",
657 GetLastError());
658 if (context)
659 {
660 DWORD ret;
661
662 /* This crashes
663 ret = CertNameToStrW(0, NULL, 0, NULL, 0);
664 */
665 /* Test with a bogus encoding type */
666 SetLastError(0xdeadbeef);
667 ret = CertNameToStrW(0, &context->pCertInfo->Issuer, 0, NULL, 0);
669 "Expected retval 1 and ERROR_FILE_NOT_FOUND, got %ld - %08lx\n",
670 ret, GetLastError());
671 SetLastError(0xdeadbeef);
672 ret = CertNameToStrW(X509_ASN_ENCODING, &context->pCertInfo->Issuer,
673 0, NULL, 0);
675 "Expected positive return and ERROR_SUCCESS, got %ld - %08lx\n",
676 ret, GetLastError());
677
678 test_NameToStrConversionW(&context->pCertInfo->Issuer,
680 L"US, Minnesota, Minneapolis, CodeWeavers, Wine Development, localhost, aric@codeweavers.com");
681 test_NameToStrConversionW(&context->pCertInfo->Issuer,
683 L"US; Minnesota; Minneapolis; CodeWeavers; Wine Development; localhost; aric@codeweavers.com");
684 test_NameToStrConversionW(&context->pCertInfo->Issuer,
686 L"US\r\nMinnesota\r\nMinneapolis\r\nCodeWeavers\r\nWine Development\r\nlocalhost\r\naric@codeweavers.com");
687 test_NameToStrConversionW(&context->pCertInfo->Subject,
689 L"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,"
690 " 2.5.4.3=localhost, 1.2.840.113549.1.9.1=aric@codeweavers.com");
691 test_NameToStrConversionW(&context->pCertInfo->Subject,
693 L"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;"
694 " 2.5.4.3=localhost; 1.2.840.113549.1.9.1=aric@codeweavers.com");
695 test_NameToStrConversionW(&context->pCertInfo->Subject,
697 L"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 "
698 "Development\r\n2.5.4.3=localhost\r\n1.2.840.113549.1.9.1=aric@codeweavers.com");
699 test_NameToStrConversionW(&context->pCertInfo->Subject,
701 L"E=aric@codeweavers.com; CN=localhost; OU=Wine Development; O=CodeWeavers; L=Minneapolis; S=Minnesota; "
702 "C=US");
703
705 }
706 blob.pbData = encodedSimpleCN;
707 blob.cbData = sizeof(encodedSimpleCN);
710 blob.cbData = sizeof(encodedSingleQuotedCN);
713 blob.pbData = encodedSpacedCN;
714 blob.cbData = sizeof(encodedSpacedCN);
717 blob.pbData = encodedQuotedCN;
718 blob.cbData = sizeof(encodedQuotedCN);
722 blob.cbData = sizeof(encodedMultipleAttrCN);
725 blob.pbData = encodedCommaCN;
726 blob.cbData = sizeof(encodedCommaCN);
729 blob.pbData = encodedEqualCN;
730 blob.cbData = sizeof(encodedEqualCN);
733 blob.pbData = encodedLessThanCN;
734 blob.cbData = sizeof(encodedLessThanCN);
737 blob.pbData = encodedGreaterThanCN;
738 blob.cbData = sizeof(encodedGreaterThanCN);
741 blob.pbData = encodedHashCN;
742 blob.cbData = sizeof(encodedHashCN);
745 blob.pbData = encodedSemiCN;
746 blob.cbData = sizeof(encodedSemiCN);
749 blob.pbData = encodedNewlineCN;
750 blob.cbData = sizeof(encodedNewlineCN);
753}
754
756{
759 const BYTE *encoded;
760};
761
762static const struct StrToNameA namesA[] = {
763 { "CN=1", sizeof(encodedSimpleCN), encodedSimpleCN },
764 { "CN=\"1\"", sizeof(encodedSimpleCN), encodedSimpleCN },
765 { "CN = \"1\"", sizeof(encodedSimpleCN), encodedSimpleCN },
766 { "CN='1'", sizeof(encodedSingleQuotedCN), encodedSingleQuotedCN },
767 { "CN=\" 1 \"", sizeof(encodedSpacedCN), encodedSpacedCN },
768 { "CN=\"\"\"1\"\"\"", sizeof(encodedQuotedCN), encodedQuotedCN },
769 { "CN=\"1+2\"", sizeof(encodedMultipleAttrCN), encodedMultipleAttrCN },
770 { "CN=\"a,b\"", sizeof(encodedCommaCN), encodedCommaCN },
771 { "CN=\"a=b\"", sizeof(encodedEqualCN), encodedEqualCN },
772 { "CN=\"<\"", sizeof(encodedLessThanCN), encodedLessThanCN },
773 { "CN=\">\"", sizeof(encodedGreaterThanCN), encodedGreaterThanCN },
774 { "CN=\"#\"", sizeof(encodedHashCN), encodedHashCN },
775 { "CN=\";\"", sizeof(encodedSemiCN), encodedSemiCN },
776 { "CN=dummy,T=test", sizeof(encodedDummyCN), encodedDummyCN },
777 { " CN = Wine Test,T = 123, C = BR", sizeof(encodedFields), encodedFields },
778};
779
780static void test_CertStrToNameA(void)
781{
782 BOOL ret;
783 DWORD size, i;
784 BYTE buf[100];
785
786 /* Crash
787 ret = CertStrToNameA(0, NULL, 0, NULL, NULL, NULL, NULL);
788 */
789 ret = CertStrToNameA(0, NULL, 0, NULL, NULL, &size, NULL);
790 ok(!ret, "Expected failure\n");
791 ret = CertStrToNameA(0, "bogus", 0, NULL, NULL, &size, NULL);
793 "Expected CRYPT_E_INVALID_X500_STRING, got %08lx\n", GetLastError());
794 ret = CertStrToNameA(0, "foo=1", 0, NULL, NULL, &size, NULL);
796 "Expected CRYPT_E_INVALID_X500_STRING, got %08lx\n", GetLastError());
797 ret = CertStrToNameA(0, "CN=1", 0, NULL, NULL, &size, NULL);
799 "Expected ERROR_FILE_NOT_FOUND, got %08lx\n", GetLastError());
801 ok(ret, "CertStrToNameA failed: %08lx\n", GetLastError());
802 size = sizeof(buf);
803 ret = CertStrToNameA(X509_ASN_ENCODING, "CN=\"\"1\"\"", 0, NULL, buf, &size,
804 NULL);
806 "Expected CRYPT_E_INVALID_X500_STRING, got %08lx\n", GetLastError());
808 &size, NULL);
810 "Expected CRYPT_E_INVALID_X500_STRING, got %08lx\n", GetLastError());
812 &size, NULL);
814 "Expected ERROR_SUCCESS, got %08lx\n", GetLastError());
816 &size, NULL);
818 "Expected CRYPT_E_INVALID_X500_STRING, got %08lx\n", GetLastError());
820 &size, NULL);
822 "Expected CRYPT_E_INVALID_X500_STRING, got %08lx\n", GetLastError());
824 &size, NULL);
826 "Expected ERROR_SUCCESS, got %08lx\n", GetLastError());
828 &size, NULL);
830 "Expected ERROR_SUCCESS, got %08lx\n", GetLastError());
831 ret = CertStrToNameA(X509_ASN_ENCODING, "CN=\"abc\"", 0, NULL, buf,
832 &size, NULL);
834 "Expected ERROR_SUCCESS, got %08lx\n", GetLastError());
836 &size, NULL);
838 "Expected ERROR_MORE_DATA, got %08lx\n", GetLastError());
839 for (i = 0; i < ARRAY_SIZE(namesA); i++)
840 {
841 size = sizeof(buf);
843 &size, NULL);
844 ok(ret, "CertStrToNameA failed on string %s: %08lx\n", namesA[i].x500,
845 GetLastError());
847 "Expected size %ld, got %ld\n", namesA[i].encodedSize, size);
848 if (ret)
850 "Unexpected value for string %s\n", namesA[i].x500);
851 }
852}
853
855{
858 const BYTE *encoded;
859};
860
861static const BYTE encodedJapaneseCN[] = { 0x30,0x0f,0x31,0x0d,0x30,0x0b,0x06,
862 0x03,0x55,0x04,0x03,0x1e,0x04,0x22,0x6f,0x57,0x5b };
863
864static const struct StrToNameW namesW[] = {
865 { L"CN=1", sizeof(encodedSimpleCN), encodedSimpleCN },
866 { L"CN=\"1\"", sizeof(encodedSimpleCN), encodedSimpleCN },
867 { L"CN = \"1\"", sizeof(encodedSimpleCN), encodedSimpleCN },
868 { L"CN='1'", sizeof(encodedSingleQuotedCN), encodedSingleQuotedCN },
869 { L"CN=\" 1 \"", sizeof(encodedSpacedCN), encodedSpacedCN },
870 { L"CN=\"\"\"1\"\"\"", sizeof(encodedQuotedCN), encodedQuotedCN },
871 { L"CN=\"1+2\"", sizeof(encodedMultipleAttrCN), encodedMultipleAttrCN },
872 { L"CN=\x226f\x575b", sizeof(encodedJapaneseCN), encodedJapaneseCN },
873 { L"CN=\"a,b\"", sizeof(encodedCommaCN), encodedCommaCN },
874 { L"CN=\"a=b\"", sizeof(encodedEqualCN), encodedEqualCN },
875 { L"CN=\"<\"", sizeof(encodedLessThanCN), encodedLessThanCN },
876 { L"CN=\">\"", sizeof(encodedGreaterThanCN), encodedGreaterThanCN },
877 { L"CN=\"#\"", sizeof(encodedHashCN), encodedHashCN },
878 { L"CN=\";\"", sizeof(encodedSemiCN), encodedSemiCN },
879 { L"CN=dummy,T=test", sizeof(encodedDummyCN), encodedDummyCN },
880 { L" CN = Wine Test,T = 123, C = BR", sizeof(encodedFields), encodedFields },
881};
882
883static void test_CertStrToNameW(void)
884{
885 BOOL ret;
886 DWORD size, i;
887 LPCWSTR errorPtr;
888 BYTE buf[100];
889
890 /* Crash
891 ret = CertStrToNameW(0, NULL, 0, NULL, NULL, NULL, NULL);
892 */
893 ret = CertStrToNameW(0, NULL, 0, NULL, NULL, &size, NULL);
894 ok(!ret, "Expected failure\n");
895 ret = CertStrToNameW(0, L"bogus", 0, NULL, NULL, &size, NULL);
897 "Expected CRYPT_E_INVALID_X500_STRING, got %08lx\n", GetLastError());
898 ret = CertStrToNameW(0, L"foo=1", 0, NULL, NULL, &size, NULL);
900 "Expected CRYPT_E_INVALID_X500_STRING, got %08lx\n", GetLastError());
901 ret = CertStrToNameW(0, L"CN=1", 0, NULL, NULL, &size, NULL);
903 "Expected ERROR_FILE_NOT_FOUND, got %08lx\n", GetLastError());
905 NULL);
906 ok(ret, "CertStrToNameW failed: %08lx\n", GetLastError());
907 size = sizeof(buf);
908 ret = CertStrToNameW(X509_ASN_ENCODING, L"CN=\"\"1\"\"", 0, NULL, buf,
909 &size, NULL);
911 "Expected CRYPT_E_INVALID_X500_STRING, got %08lx\n", GetLastError());
912 ret = CertStrToNameW(X509_ASN_ENCODING, L"CN=\"\"1\"\"", 0, NULL, buf,
913 &size, &errorPtr);
915 "Expected CRYPT_E_INVALID_X500_STRING, got %08lx\n", GetLastError());
916 ok(errorPtr && *errorPtr == '1', "Expected first error character was 1\n");
917 for (i = 0; i < ARRAY_SIZE(namesW); i++)
918 {
919 size = sizeof(buf);
921 &size, NULL);
922 ok(ret, "Index %ld: CertStrToNameW failed: %08lx\n", i, GetLastError());
924 "Index %ld: expected size %ld, got %ld\n", i, namesW[i].encodedSize,
925 size);
926 if (ret)
928 "Index %ld: unexpected value for string %s\n", i, wine_dbgstr_w(namesW[i].x500));
929 }
930}
931
932#define test_CertGetNameString_value(a, b, c, d, e) test_CertGetNameString_value_(__LINE__, a, b, c, d, e)
934 void *type_para, const char *expected)
935{
936 DWORD len, retlen, expected_len;
937 WCHAR expectedW[512];
938 WCHAR strW[512];
939 char str[512];
940
941 expected_len = 0;
942 while(expected[expected_len])
943 {
944 while((expectedW[expected_len] = expected[expected_len]))
945 ++expected_len;
947 break;
948 expectedW[expected_len++] = 0;
949 }
950 expectedW[expected_len++] = 0;
951
952 len = CertGetNameStringA(context, type, flags, type_para, NULL, 0);
953 if (flags & CERT_NAME_SEARCH_ALL_NAMES_FLAG && ((type == CERT_NAME_DNS_TYPE && len < expected_len)
954 || (type != CERT_NAME_DNS_TYPE && len > expected_len)))
955 {
956 /* Supported since Win8. */
957 win_skip("line %u: CERT_NAME_SEARCH_ALL_NAMES_FLAG is not supported.\n", line);
958 return;
959 }
960 ok(len == expected_len, "line %u: unexpected length %ld, expected %ld.\n", line, len, expected_len);
961 memset(str, 0xcc, len);
962 retlen = CertGetNameStringA(context, type, flags, type_para, str, len);
963 ok(retlen == len, "line %u: unexpected len %lu, expected %lu.\n", line, retlen, len);
964 ok(!memcmp(str, expected, expected_len), "line %u: unexpected value %s.\n", line, debugstr_an(str, expected_len));
965 str[0] = str[1] = 0xcc;
966 retlen = CertGetNameStringA(context, type, flags, type_para, str, len - 1);
967 ok(retlen == 1, "line %u: Unexpected len %lu, expected 1.\n", line, retlen);
968 if (len == 1) return;
969 ok(!str[0], "line %u: unexpected str[0] %#x.\n", line, str[0]);
970 ok(str[1] == expected[1], "line %u: unexpected str[1] %#x.\n", line, str[1]);
971 ok(!memcmp(str + 1, expected + 1, len - 2),
972 "line %u: str %s, string data mismatch.\n", line, debugstr_a(str + 1));
973 retlen = CertGetNameStringA(context, type, flags, type_para, str, 0);
974 ok(retlen == len, "line %u: Unexpected len %lu, expected 1.\n", line, retlen);
975
976 memset(strW, 0xcc, len * sizeof(*strW));
977 retlen = CertGetNameStringW(context, type, flags, type_para, strW, len);
978 ok(retlen == expected_len, "line %u: unexpected len %lu, expected %lu.\n", line, retlen, expected_len);
979 ok(!memcmp(strW, expectedW, len * sizeof(*strW)), "line %u: unexpected value %s.\n", line, debugstr_wn(strW, len));
980 strW[0] = strW[1] = 0xcccc;
981 retlen = CertGetNameStringW(context, type, flags, type_para, strW, len - 1);
982 ok(retlen == len - 1, "line %u: unexpected len %lu, expected %lu.\n", line, retlen, len - 1);
984 {
985 ok(!memcmp(strW, expectedW, (retlen - 2) * sizeof(*strW)),
986 "line %u: str %s, string data mismatch.\n", line, debugstr_wn(strW, retlen - 2));
987 ok(!strW[retlen - 2], "line %u: string is not zero terminated.\n", line);
988 ok(!strW[retlen - 1], "line %u: string sequence is not zero terminated.\n", line);
989
990 retlen = CertGetNameStringW(context, type, flags, type_para, strW, 1);
991 ok(retlen == 1, "line %u: unexpected len %lu, expected %lu.\n", line, retlen, len - 1);
992 ok(!strW[retlen - 1], "line %u: string sequence is not zero terminated.\n", line);
993 }
994 else
995 {
996 ok(!memcmp(strW, expectedW, (retlen - 1) * sizeof(*strW)),
997 "line %u: str %s, string data mismatch.\n", line, debugstr_wn(strW, retlen - 1));
998 ok(!strW[retlen - 1], "line %u: string is not zero terminated.\n", line);
999 }
1000 retlen = CertGetNameStringA(context, type, flags, type_para, NULL, len - 1);
1001 ok(retlen == len, "line %u: unexpected len %lu, expected %lu\n", line, retlen, len);
1002 retlen = CertGetNameStringW(context, type, flags, type_para, NULL, len - 1);
1003 ok(retlen == len, "line %u: unexpected len %lu, expected %lu\n", line, retlen, len);
1004}
1005
1006static void test_CertGetNameString(void)
1007{
1008 static const char aric[] = "aric@codeweavers.com";
1009 static const char localhost[] = "localhost";
1011 DWORD len, type;
1012
1014 sizeof(cert));
1015 ok(!!context, "CertCreateCertificateContext failed, err %lu\n", GetLastError());
1016
1017 /* Bad string types/types missing from the cert */
1018 len = CertGetNameStringA(NULL, 0, 0, NULL, NULL, 0);
1019 ok(len == 1, "expected 1, got %lu\n", len);
1020 len = CertGetNameStringA(context, 0, 0, NULL, NULL, 0);
1021 ok(len == 1, "expected 1, got %lu\n", len);
1023 ok(len == 1, "expected 1, got %lu\n", len);
1024
1025 len = CertGetNameStringW(NULL, 0, 0, NULL, NULL, 0);
1026 ok(len == 1, "expected 1, got %lu\n", len);
1027 len = CertGetNameStringW(context, 0, 0, NULL, NULL, 0);
1028 ok(len == 1, "expected 1, got %lu\n", len);
1030 ok(len == 1, "expected 1, got %lu\n", len);
1031
1034 type = 0;
1047
1049
1051 sizeof(cert_no_email));
1052 ok(!!context, "CertCreateCertificateContext failed, err %lu\n", GetLastError());
1053
1055
1057
1058 ok(cert_v3[CERT_V3_SAN_OID_OFFSET] == 0x55, "Incorrect CERT_V3_SAN_OID_OFFSET.\n");
1059 ok(cert_v3[CERT_V3_IAN_OID_OFFSET] == 0x55, "Incorrect CERT_V3_IAN_OID_OFFSET.\n");
1060 cert_v3[CERT_V3_SAN_OID_OFFSET + 2] = 7; /* legacy OID_SUBJECT_ALT_NAME */
1061 cert_v3[CERT_V3_IAN_OID_OFFSET + 2] = 8; /* legacy OID_ISSUER_ALT_NAME */
1063 ok(!!context, "CertCreateCertificateContext failed, err %lu\n", GetLastError());
1067
1068 cert_v3[CERT_V3_SAN_OID_OFFSET + 2] = 17; /* OID_SUBJECT_ALT_NAME2 */
1069 cert_v3[CERT_V3_IAN_OID_OFFSET + 2] = 18; /* OID_ISSUER_ALT_NAME2 */
1071 ok(!!context, "CertCreateCertificateContext failed, err %lu\n", GetLastError());
1077 NULL, "ex1.org\0*.ex2.org\0");
1079 NULL, "ex3.org\0*.ex4.org\0");
1081}
1082
1083static void test_quoted_RDN(void)
1084{
1085 static const WCHAR str1[] = { '1',0x00a0,0 };
1086 static const WCHAR str2[] = { '1',0x3000,0 };
1087 static const struct
1088 {
1089 const WCHAR *CN;
1090 const WCHAR *X500_CN;
1091 } test[] =
1092 {
1093 { L"1", L"1" },
1094 { L" 1", L"\" 1\"" },
1095 { L"1 ", L"\"1 \"" },
1096 { L"\"1\"", L"\"\"\"1\"\"\"" },
1097 { L"\" 1 \"", L"\"\"\" 1 \"\"\"" },
1098 { L"\"\"\"1\"\"\"", L"\"\"\"\"\"\"\"1\"\"\"\"\"\"\"" },
1099 { L"1+", L"\"1+\"" },
1100 { L"1=", L"\"1=\"" },
1101 { L"1\"", L"\"1\"\"\"" },
1102 { L"1<", L"\"1<\"" },
1103 { L"1>", L"\"1>\"" },
1104 { L"1#", L"\"1#\"" },
1105 { L"1+", L"\"1+\"" },
1106 { L"1\t", L"\"1\t\"" },
1107 { L"1\r", L"\"1\r\"" },
1108 { L"1\n", L"\"1\n\"" },
1109 { str1, str1 },
1110 { str2, str2 },
1111 };
1113 CERT_RDN rdn;
1116 BYTE *buf;
1117 WCHAR str[256];
1118 DWORD size, ret, i;
1119
1120 for (i = 0; i < ARRAY_SIZE(test); i++)
1121 {
1122 winetest_push_context("%lu", i);
1123
1124 attr.pszObjId = (LPSTR)szOID_COMMON_NAME;
1125 attr.dwValueType = CERT_RDN_UNICODE_STRING;
1126 attr.Value.cbData = wcslen(test[i].CN) * sizeof(WCHAR);
1127 attr.Value.pbData = (BYTE *)test[i].CN;
1128 rdn.cRDNAttr = 1;
1129 rdn.rgRDNAttr = &attr;
1130 info.cRDN = 1;
1131 info.rgRDN = &rdn;
1132 buf = NULL;
1133 size = 0;
1135 ok(ret, "CryptEncodeObjectEx error %08lx\n", GetLastError());
1136
1137 blob.pbData = buf;
1138 blob.cbData = size;
1139
1140 str[0] = 0;
1142 ok(ret, "CertNameToStr error %08lx\n", GetLastError());
1143 ok(!wcscmp(str, test[i].X500_CN), "got %s, expected %s\n", debugstr_w(str), debugstr_w(test[i].X500_CN));
1144
1145 str[0] = 0;
1147 ok(ret, "CertNameToStr error %08lx\n", GetLastError());
1148 ok(!wcscmp(str, test[i].X500_CN), "got %s, expected %s\n", debugstr_w(str), debugstr_w(test[i].X500_CN));
1149
1150 str[0] = 0;
1152 ok(ret, "CertNameToStr error %08lx\n", GetLastError());
1153 ok(!wcsncmp(str, L"2.5.4.3=", 8), "got %s\n", debugstr_w(str));
1154 ok(!wcscmp(&str[8], test[i].X500_CN), "got %s, expected %s\n", debugstr_w(&str[8]), debugstr_w(test[i].X500_CN));
1155
1156 str[0] = 0;
1158 ok(ret, "CertNameToStr error %08lx\n", GetLastError());
1159 ok(!wcsncmp(str, L"CN=", 3), "got %s\n", debugstr_w(str));
1160 ok(!wcscmp(&str[3], test[i].X500_CN), "got %s, expected %s\n", debugstr_w(&str[3]), debugstr_w(test[i].X500_CN));
1161
1162 str[0] = 0;
1164 ok(ret, "CertNameToStr error %08lx\n", GetLastError());
1165 ok(!wcsncmp(str, L"CN=", 3), "got %s\n", debugstr_w(str));
1166 ok(!wcscmp(&str[3], test[i].CN), "got %s, expected %s\n", debugstr_w(&str[3]), debugstr_w(test[i].CN));
1167
1168 LocalFree(buf);
1169
1171 }
1172
1173 for (i = 0; i < ARRAY_SIZE(test); i++)
1174 {
1175 winetest_push_context("%lu", i);
1176
1177 attr.pszObjId = (LPSTR)szOID_COMMON_NAME;
1178 attr.dwValueType = CERT_RDN_UTF8_STRING;
1179 attr.Value.cbData = wcslen(test[i].CN) * sizeof(WCHAR);
1180 attr.Value.pbData = (BYTE *)test[i].CN;
1181 rdn.cRDNAttr = 1;
1182 rdn.rgRDNAttr = &attr;
1183 info.cRDN = 1;
1184 info.rgRDN = &rdn;
1185 buf = NULL;
1186 size = 0;
1188 ok(ret, "CryptEncodeObjectEx error %08lx\n", GetLastError());
1189
1190 blob.pbData = buf;
1191 blob.cbData = size;
1192
1193 str[0] = 0;
1195 ok(ret, "CertNameToStr error %08lx\n", GetLastError());
1196 ok(!wcscmp(str, test[i].X500_CN), "got %s, expected %s\n", debugstr_w(str), debugstr_w(test[i].X500_CN));
1197
1198 str[0] = 0;
1200 ok(ret, "CertNameToStr error %08lx\n", GetLastError());
1201 ok(!wcscmp(str, test[i].X500_CN), "got %s, expected %s\n", debugstr_w(str), debugstr_w(test[i].X500_CN));
1202
1203 str[0] = 0;
1205 ok(ret, "CertNameToStr error %08lx\n", GetLastError());
1206 ok(!wcsncmp(str, L"2.5.4.3=", 8), "got %s\n", debugstr_w(str));
1207 ok(!wcscmp(&str[8], test[i].X500_CN), "got %s, expected %s\n", debugstr_w(&str[8]), debugstr_w(test[i].X500_CN));
1208
1209 str[0] = 0;
1211 ok(ret, "CertNameToStr error %08lx\n", GetLastError());
1212 ok(!wcsncmp(str, L"CN=", 3), "got %s\n", debugstr_w(str));
1213 ok(!wcscmp(&str[3], test[i].X500_CN), "got %s, expected %s\n", debugstr_w(&str[3]), debugstr_w(test[i].X500_CN));
1214
1215 str[0] = 0;
1217 ok(ret, "CertNameToStr error %08lx\n", GetLastError());
1218 ok(!wcsncmp(str, L"CN=", 3), "got %s\n", debugstr_w(str));
1219 ok(!wcscmp(&str[3], test[i].CN), "got %s, expected %s\n", debugstr_w(&str[3]), debugstr_w(test[i].CN));
1220
1221 LocalFree(buf);
1222
1224 }
1225}
1226
1228{
1237}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ARRAY_SIZE(A)
Definition: main.h:20
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define CN(I, J, K)
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
PCCERT_CONTEXT WINAPI CertCreateCertificateContext(DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded)
Definition: cert.c:316
BOOL WINAPI CryptEncodeObjectEx(DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, void *pvEncoded, DWORD *pcbEncoded)
Definition: encode.c:4696
BOOL WINAPI CertStrToNameA(DWORD dwCertEncodingType, LPCSTR pszX500, DWORD dwStrType, void *pvReserved, BYTE *pbEncoded, DWORD *pcbEncoded, LPCSTR *ppszError)
Definition: str.c:716
DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, LPSTR psz, DWORD csz)
Definition: str.c:33
DWORD WINAPI CertNameToStrA(DWORD dwCertEncodingType, PCERT_NAME_BLOB pName, DWORD dwStrType, LPSTR psz, DWORD csz)
Definition: str.c:414
DWORD WINAPI CertGetNameStringA(PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags, void *pvTypePara, LPSTR pszNameString, DWORD cchNameString)
Definition: str.c:1127
DWORD WINAPI CertNameToStrW(DWORD dwCertEncodingType, PCERT_NAME_BLOB pName, DWORD dwStrType, LPWSTR psz, DWORD csz)
Definition: str.c:702
DWORD WINAPI CertGetNameStringW(PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags, void *pvTypePara, LPWSTR pszNameString, DWORD cchNameString)
Definition: str.c:1228
BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500, DWORD dwStrType, void *pvReserved, BYTE *pbEncoded, DWORD *pcbEncoded, LPCWSTR *ppszError)
Definition: str.c:1024
DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, LPWSTR psz, DWORD csz)
Definition: str.c:100
#define SetLastError(x)
Definition: compat.h:752
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
#define lstrlenW
Definition: compat.h:750
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4246
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
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
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_wn
Definition: kernel32.h:33
#define debugstr_w
Definition: kernel32.h:32
#define wine_dbgstr_w
Definition: kernel32.h:34
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl winetest_push_context(const char *fmt,...) __WINE_PRINTF_ATTR(1
#define win_skip
Definition: minitest.h:67
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl void winetest_pop_context(void)
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static LPSTR pName
Definition: security.c:75
static const BYTE aric[]
Definition: encode.c:682
static const BYTE localhost[]
Definition: encode.c:1391
static BYTE cert[]
Definition: msg.c:1374
BOOL expected
Definition: store.c:2000
static BYTE encodedQuotedCN[]
Definition: str.c:491
static BYTE encodedLessThanCN[]
Definition: str.c:501
static BYTE encodedSpacedCN[]
Definition: str.c:489
struct _CertRDNAttrEncodingW * PCertRDNAttrEncodingW
static BYTE cert_v3[]
Definition: str.c:228
static BYTE bin7[]
Definition: str.c:55
#define CERT_V3_SAN_OID_OFFSET
Definition: str.c:296
static const BYTE encodedJapaneseCN[]
Definition: str.c:861
static BYTE bin5[]
Definition: str.c:51
static BYTE bin11[]
Definition: str.c:65
static char x500SubjectStr[]
Definition: str.c:311
static void test_quoted_RDN(void)
Definition: str.c:1083
static char issuerStrSemicolon[]
Definition: str.c:301
static char subjectStr[]
Definition: str.c:305
static BYTE bin2[]
Definition: str.c:45
static BYTE encodedEqualCN[]
Definition: str.c:498
static void test_CertGetNameString_value_(unsigned int line, PCCERT_CONTEXT context, DWORD type, DWORD flags, void *type_para, const char *expected)
Definition: str.c:933
static BYTE encodedSimpleCN[]
Definition: str.c:485
static BYTE bin13[]
Definition: str.c:67
struct _CertRDNAttrEncodingW CertRDNAttrEncodingW
static BYTE encodedGreaterThanCN[]
Definition: str.c:504
static char issuerStr[]
Definition: str.c:299
struct _CertRDNAttrEncoding CertRDNAttrEncoding
static BYTE bin10[]
Definition: str.c:64
static BYTE encodedNewlineCN[]
Definition: str.c:513
static void test_NameToStrConversionA_(unsigned int line, PCERT_NAME_BLOB pName, DWORD dwStrType, LPCSTR expected)
Definition: str.c:463
#define CERT_V3_IAN_OID_OFFSET
Definition: str.c:297
static BYTE encodedSemiCN[]
Definition: str.c:510
static char x500SubjectStrSemicolonReverse[]
Definition: str.c:312
static BYTE encodedCommaCN[]
Definition: str.c:495
static const BYTE cert_no_email[]
Definition: str.c:159
static BYTE bin3[]
Definition: str.c:47
static BYTE encodedMultipleAttrCN[]
Definition: str.c:493
struct _CertRDNAttrEncoding * PCertRDNAttrEncoding
static char subjectStrCRLF[]
Definition: str.c:309
static void test_CertRDNValueToStrW(void)
Definition: str.c:388
static void test_CertNameToStrW(void)
Definition: str.c:649
static BYTE encodedSingleQuotedCN[]
Definition: str.c:487
static BYTE bin12[]
Definition: str.c:66
#define test_NameToStrConversionA(a, b, c)
Definition: str.c:462
#define test_CertGetNameString_value(a, b, c, d, e)
Definition: str.c:932
static BYTE bin14[]
Definition: str.c:68
static char subjectStrSemicolon[]
Definition: str.c:307
static BYTE bin1[]
Definition: str.c:44
static const struct StrToNameW namesW[]
Definition: str.c:864
static void test_CertStrToNameA(void)
Definition: str.c:780
static BYTE bin4[]
Definition: str.c:49
static void test_CertRDNValueToStrA(void)
Definition: str.c:314
static BYTE encodedHashCN[]
Definition: str.c:507
static void test_CertStrToNameW(void)
Definition: str.c:883
static BYTE bin6[]
Definition: str.c:53
static void test_NameToStrConversionW_(unsigned int line, PCERT_NAME_BLOB pName, DWORD dwStrType, LPCWSTR expected)
Definition: str.c:623
static char issuerStrCRLF[]
Definition: str.c:303
#define test_NameToStrConversionW(a, b, c)
Definition: str.c:622
static BYTE encodedDummyCN[]
Definition: str.c:516
static BYTE encodedFields[]
Definition: str.c:520
static const struct StrToNameA namesA[]
Definition: str.c:762
static BYTE bin8[]
Definition: str.c:57
static void test_CertNameToStrA(void)
Definition: str.c:526
static BYTE bin9[]
Definition: str.c:63
static void test_CertGetNameString(void)
Definition: str.c:1006
WCHAR strW[12]
Definition: clipboard.c:2025
#define test
Definition: rosglue.h:37
const WCHAR * str
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
const char int int int static __inline const char * wine_dbgstr_a(const char *s)
Definition: debug.h:187
#define memset(x, y, z)
Definition: compat.h:39
const BYTE * encoded
Definition: str.c:759
DWORD encodedSize
Definition: str.c:758
LPCSTR x500
Definition: str.c:757
const BYTE * encoded
Definition: str.c:858
LPCWSTR x500
Definition: str.c:856
DWORD encodedSize
Definition: str.c:857
DWORD cRDNAttr
Definition: wincrypt.h:271
PCERT_RDN_ATTR rgRDNAttr
Definition: wincrypt.h:272
CERT_RDN_VALUE_BLOB Value
Definition: str.c:40
LPCWSTR str
Definition: str.c:41
DWORD dwValueType
Definition: str.c:39
LPCSTR pszObjId
Definition: str.c:38
LPCSTR pszObjId
Definition: str.c:31
CERT_RDN_VALUE_BLOB Value
Definition: str.c:33
DWORD dwValueType
Definition: str.c:32
LPCSTR str
Definition: str.c:34
Definition: cookie.c:202
Definition: image.c:134
Definition: http.c:7252
Definition: parser.c:49
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CERT_NAME_STR_NO_QUOTING_FLAG
Definition: wincrypt.h:3647
#define CERT_RDN_UTF8_STRING
Definition: wincrypt.h:2940
#define CERT_RDN_IA5_STRING
Definition: wincrypt.h:2931
#define X509_UNICODE_NAME
Definition: wincrypt.h:3537
#define CERT_NAME_SIMPLE_DISPLAY_TYPE
Definition: wincrypt.h:3658
#define CERT_RDN_PRINTABLE_STRING
Definition: wincrypt.h:2927
#define CERT_X500_NAME_STR
Definition: wincrypt.h:3644
#define CERT_NAME_EMAIL_TYPE
Definition: wincrypt.h:3655
#define CERT_NAME_STR_NO_PLUS_FLAG
Definition: wincrypt.h:3646
#define X509_ASN_ENCODING
Definition: wincrypt.h:2501
#define CERT_NAME_STR_SEMICOLON_FLAG
Definition: wincrypt.h:3645
#define CERT_NAME_SEARCH_ALL_NAMES_FLAG
Definition: wincrypt.h:3665
#define CERT_SIMPLE_NAME_STR
Definition: wincrypt.h:3642
#define CERT_NAME_STR_CRLF_FLAG
Definition: wincrypt.h:3648
#define szOID_RSA_emailAddr
Definition: wincrypt.h:3188
#define CERT_NAME_DNS_TYPE
Definition: wincrypt.h:3660
#define szOID_SUR_NAME
Definition: wincrypt.h:3291
#define CERT_NAME_RDN_TYPE
Definition: wincrypt.h:3656
#define CERT_NAME_ISSUER_FLAG
Definition: wincrypt.h:3664
#define CRYPT_ENCODE_ALLOC_FLAG
Definition: wincrypt.h:3599
#define CERT_NAME_ATTR_TYPE
Definition: wincrypt.h:3657
#define CERT_NAME_URL_TYPE
Definition: wincrypt.h:3661
#define szOID_COMMON_NAME
Definition: wincrypt.h:3290
#define CERT_NAME_STR_REVERSE_FLAG
Definition: wincrypt.h:3650
#define CERT_OID_NAME_STR
Definition: wincrypt.h:3643
#define CERT_RDN_UNICODE_STRING
Definition: wincrypt.h:2939
#define CERT_NAME_FRIENDLY_DISPLAY_TYPE
Definition: wincrypt.h:3659
#define CRYPT_E_INVALID_X500_STRING
Definition: winerror.h:4441
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
__wchar_t WCHAR
Definition: xmlstorage.h:180
char * LPSTR
Definition: xmlstorage.h:182
unsigned char BYTE
Definition: xxhash.c:193