cryptnet/tests: Clean up and expand tests for CertDllVerifyRevocation.
[wine.git] / dlls / cryptnet / tests / cryptnet.c
blobb37a5e698f363f6f0a0997780281e8708807f99b
1 /*
2 * Unit test suite for cryptnet.dll
4 * Copyright 2007 Juan Lang
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.
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.
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
20 #include <stdarg.h>
21 #include <stdio.h>
23 #include <windef.h>
24 #include <winbase.h>
25 #include <winerror.h>
26 #include <wincrypt.h>
27 #include "wine/test.h"
29 static const BYTE bigCert[] = {
30 0x30,0x78,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x14,0x31,0x12,0x30,0x10,
31 0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
32 0x67,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,
33 0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,
34 0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
35 0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x30,
36 0x07,0x30,0x02,0x06,0x00,0x03,0x01,0x00,0xa3,0x16,0x30,0x14,0x30,0x12,0x06,
37 0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,0x01,0x01,0xff,0x02,
38 0x01,0x01};
39 static const BYTE certWithIssuingDistPoint[] = {
40 0x30,0x81,0x99,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,0x01,0x30,0x0d,0x06,0x09,
41 0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,0x14,0x31,0x12,
42 0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,
43 0x61,0x6e,0x67,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,
44 0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,
45 0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x14,0x31,0x12,0x30,0x10,
46 0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
47 0x67,0x30,0x07,0x30,0x02,0x06,0x00,0x03,0x01,0x00,0xa3,0x27,0x30,0x25,0x30,
48 0x23,0x06,0x03,0x55,0x1d,0x1c,0x01,0x01,0xff,0x04,0x19,0x30,0x17,0xa0,0x15,
49 0xa0,0x13,0x86,0x11,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x69,0x6e,0x65,
50 0x68,0x71,0x2e,0x6f,0x72,0x67, };
51 static const BYTE certWithCRLDistPoint[] = {
52 0x30,0x81,0x9b,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,0x01,0x30,0x0d,0x06,0x09,
53 0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,0x14,0x31,0x12,
54 0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,
55 0x61,0x6e,0x67,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,
56 0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,
57 0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x14,0x31,0x12,0x30,0x10,
58 0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
59 0x67,0x30,0x07,0x30,0x02,0x06,0x00,0x03,0x01,0x00,0xa3,0x29,0x30,0x27,0x30,
60 0x25,0x06,0x03,0x55,0x1d,0x1f,0x01,0x01,0xff,0x04,0x1b,0x30,0x19,0x30,0x17,
61 0xa0,0x15,0xa0,0x13,0x86,0x11,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x69,
62 0x6e,0x65,0x68,0x71,0x2e,0x6f,0x72,0x67, };
63 static const BYTE certWithAIAWithCAIssuers[] = {
64 0x30,0x82,0x01,0x3c,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,0x01,0x30,0x0b,0x06,
65 0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x30,0x14,0x31,0x12,0x30,
66 0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,
67 0x6e,0x67,0x30,0x1e,0x17,0x0d,0x30,0x39,0x31,0x30,0x32,0x38,0x30,0x30,0x30,
68 0x30,0x30,0x30,0x5a,0x17,0x0d,0x32,0x30,0x31,0x31,0x32,0x37,0x30,0x30,0x30,
69 0x30,0x30,0x30,0x5a,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,
70 0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x30,0x81,0xa5,0x30,
71 0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x03,0x81,0x95,
72 0x00,0x06,0x02,0x00,0x00,0x00,0x24,0x00,0x00,0x52,0x53,0x41,0x31,0x00,0x04,
73 0x00,0x00,0x01,0x00,0x01,0x00,0x2f,0xb2,0x8c,0xff,0x6c,0xf1,0xb1,0x61,0x9c,
74 0x3a,0x8f,0x5e,0x35,0x2f,0x1f,0xd5,0xcf,0x2a,0xf6,0x9e,0x37,0xe8,0x89,0xa2,
75 0xb1,0x1c,0xc0,0x1c,0xb6,0x72,0x45,0x97,0xe5,0x88,0x3d,0xfe,0xa6,0x27,0xea,
76 0xd6,0x07,0x0f,0xcd,0xba,0x49,0x06,0x16,0xdb,0xad,0x06,0x76,0x39,0x4c,0x15,
77 0xdf,0xe2,0x07,0xc5,0x99,0x1b,0x98,0x4b,0xc3,0x8e,0x89,0x12,0x95,0x9e,0x3b,
78 0xb9,0x59,0xfe,0x91,0x33,0xc1,0x1f,0xce,0x8f,0xab,0x93,0x25,0x01,0x3e,0xde,
79 0xf1,0x58,0x3b,0xe7,0x7a,0x03,0x14,0x07,0x09,0x0a,0x21,0x2d,0x12,0x11,0x08,
80 0x78,0x07,0x9e,0x34,0xc3,0xc5,0xde,0xb2,0xd8,0xd7,0x86,0x0d,0x0d,0xcd,0x81,
81 0xa4,0x2d,0x7c,0x82,0x50,0xca,0x2a,0xc2,0x99,0xe5,0xf3,0xca,0x7e,0xad,0xa3,
82 0x31,0x30,0x2f,0x30,0x2d,0x06,0x08,0x2b,0x06,0x01,0x05,0x05,0x07,0x01,0x01,
83 0x04,0x21,0x30,0x1f,0x30,0x1d,0x06,0x08,0x2b,0x06,0x01,0x05,0x05,0x07,0x30,
84 0x02,0x86,0x11,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x69,0x6e,0x65,0x68,
85 0x71,0x2e,0x6f,0x72,0x67 };
87 static void compareUrlArray(const CRYPT_URL_ARRAY *expected,
88 const CRYPT_URL_ARRAY *got)
90 ok(expected->cUrl == got->cUrl, "Expected %d URLs, got %d\n",
91 expected->cUrl, got->cUrl);
92 if (expected->cUrl == got->cUrl)
94 DWORD i;
96 for (i = 0; i < got->cUrl; i++)
97 ok(!lstrcmpiW(expected->rgwszUrl[i], got->rgwszUrl[i]),
98 "%d: unexpected URL\n", i);
103 static void test_getObjectUrl(void)
105 static WCHAR url[] = L"http://winehq.org";
106 BOOL ret;
107 DWORD urlArraySize = 0, infoSize = 0;
108 PCCERT_CONTEXT cert;
110 SetLastError(0xdeadbeef);
111 ret = CryptGetObjectUrl(NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL);
112 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
113 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
114 /* Crash
115 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, NULL, 0, NULL, NULL,
116 NULL, NULL, NULL);
117 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, NULL, 0, NULL, NULL,
118 NULL, &infoSize, NULL);
119 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, NULL, 0, NULL,
120 &urlArraySize, NULL, &infoSize, NULL);
122 /* A cert with no CRL dist point extension fails.. */
123 cert = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert,
124 sizeof(bigCert));
125 SetLastError(0xdeadbeef);
126 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert, 0, NULL,
127 NULL, NULL, NULL, NULL);
128 ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
129 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
130 CertFreeCertificateContext(cert);
132 cert = CertCreateCertificateContext(X509_ASN_ENCODING,
133 certWithIssuingDistPoint, sizeof(certWithIssuingDistPoint));
134 if (cert)
136 /* This cert has no AIA extension, so expect this to fail */
137 SetLastError(0xdeadbeef);
138 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert, 0,
139 NULL, NULL, NULL, NULL, NULL);
140 ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
141 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
142 SetLastError(0xdeadbeef);
143 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert,
144 CRYPT_GET_URL_FROM_PROPERTY, NULL, NULL, NULL, NULL, NULL);
145 ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
146 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
147 SetLastError(0xdeadbeef);
148 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert,
149 CRYPT_GET_URL_FROM_EXTENSION, NULL, NULL, NULL, NULL, NULL);
150 ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
151 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
152 /* It does have an issuing dist point extension, but that's not what
153 * this is looking for (it wants a CRL dist points extension)
155 SetLastError(0xdeadbeef);
156 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
157 (void *)cert, 0, NULL, NULL, NULL, NULL, NULL);
158 ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
159 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
160 SetLastError(0xdeadbeef);
161 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
162 (void *)cert, CRYPT_GET_URL_FROM_PROPERTY, NULL, NULL, NULL, NULL,
163 NULL);
164 ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
165 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
166 SetLastError(0xdeadbeef);
167 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
168 (void *)cert, CRYPT_GET_URL_FROM_EXTENSION, NULL, NULL, NULL, NULL,
169 NULL);
170 ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
171 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
172 CertFreeCertificateContext(cert);
174 cert = CertCreateCertificateContext(X509_ASN_ENCODING,
175 certWithCRLDistPoint, sizeof(certWithCRLDistPoint));
176 if (cert)
178 PCRYPT_URL_ARRAY urlArray;
180 /* This cert has no AIA extension, so expect this to fail */
181 SetLastError(0xdeadbeef);
182 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert, 0,
183 NULL, NULL, NULL, NULL, NULL);
184 ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
185 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
186 SetLastError(0xdeadbeef);
187 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert,
188 CRYPT_GET_URL_FROM_PROPERTY, NULL, NULL, NULL, NULL, NULL);
189 ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
190 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
191 SetLastError(0xdeadbeef);
192 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert,
193 CRYPT_GET_URL_FROM_EXTENSION, NULL, NULL, NULL, NULL, NULL);
194 ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
195 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
196 /* It does have a CRL dist points extension */
197 SetLastError(0xdeadbeef);
198 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
199 (void *)cert, 0, NULL, NULL, NULL, NULL, NULL);
200 ok(!ret && GetLastError() == E_INVALIDARG,
201 "Expected E_INVALIDARG, got %08x\n", GetLastError());
202 SetLastError(0xdeadbeef);
203 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
204 (void *)cert, 0, NULL, NULL, NULL, &infoSize, NULL);
205 ok(!ret && GetLastError() == E_INVALIDARG,
206 "Expected E_INVALIDARG, got %08x\n", GetLastError());
207 /* Can get it without specifying the location: */
208 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
209 (void *)cert, 0, NULL, &urlArraySize, NULL, NULL, NULL);
210 ok(ret, "CryptGetObjectUrl failed: %08x\n", GetLastError());
211 urlArray = HeapAlloc(GetProcessHeap(), 0, urlArraySize);
212 if (urlArray)
214 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
215 (void *)cert, 0, urlArray, &urlArraySize, NULL, NULL, NULL);
216 ok(ret, "CryptGetObjectUrl failed: %08x\n", GetLastError());
217 if (ret)
219 LPWSTR pUrl = url;
220 CRYPT_URL_ARRAY expectedUrl = { 1, &pUrl };
222 compareUrlArray(&expectedUrl, urlArray);
224 HeapFree(GetProcessHeap(), 0, urlArray);
226 /* or by specifying it's an extension: */
227 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
228 (void *)cert, CRYPT_GET_URL_FROM_EXTENSION, NULL, &urlArraySize, NULL,
229 NULL, NULL);
230 ok(ret, "CryptGetObjectUrl failed: %08x\n", GetLastError());
231 urlArray = HeapAlloc(GetProcessHeap(), 0, urlArraySize);
232 if (urlArray)
234 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
235 (void *)cert, CRYPT_GET_URL_FROM_EXTENSION, urlArray,
236 &urlArraySize, NULL, NULL, NULL);
237 ok(ret, "CryptGetObjectUrl failed: %08x\n", GetLastError());
238 if (ret)
240 LPWSTR pUrl = url;
241 CRYPT_URL_ARRAY expectedUrl = { 1, &pUrl };
243 compareUrlArray(&expectedUrl, urlArray);
245 HeapFree(GetProcessHeap(), 0, urlArray);
247 /* but it isn't contained in a property: */
248 SetLastError(0xdeadbeef);
249 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
250 (void *)cert, CRYPT_GET_URL_FROM_PROPERTY, NULL, &urlArraySize, NULL,
251 NULL, NULL);
252 ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
253 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
254 CertFreeCertificateContext(cert);
256 cert = CertCreateCertificateContext(X509_ASN_ENCODING,
257 certWithAIAWithCAIssuers, sizeof(certWithAIAWithCAIssuers));
258 if (cert)
260 PCRYPT_URL_ARRAY urlArray;
262 /* This has an AIA extension with the CA Issuers set, so expect it
263 * to succeed:
265 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER,
266 (void *)cert, 0, NULL, &urlArraySize, NULL, NULL, NULL);
267 ok(ret, "CryptGetObjectUrl failed: %08x\n", GetLastError());
268 if (ret)
270 urlArray = HeapAlloc(GetProcessHeap(), 0, urlArraySize);
271 if (urlArray)
273 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER,
274 (void *)cert, CRYPT_GET_URL_FROM_EXTENSION, urlArray,
275 &urlArraySize, NULL, NULL, NULL);
276 ok(ret, "CryptGetObjectUrl failed: %08x\n", GetLastError());
277 if (ret)
279 LPWSTR pUrl = url;
280 CRYPT_URL_ARRAY expectedUrl = { 1, &pUrl };
282 compareUrlArray(&expectedUrl, urlArray);
284 HeapFree(GetProcessHeap(), 0, urlArray);
287 /* It doesn't have a CRL dist points extension, so this should fail */
288 SetLastError(0xdeadbeef);
289 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
290 (void *)cert, 0, NULL, &urlArraySize, NULL, NULL, NULL);
291 ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
292 "expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
293 CertFreeCertificateContext(cert);
297 static void make_tmp_file(LPSTR path)
299 static char curr[MAX_PATH] = { 0 };
300 char temp[MAX_PATH];
301 DWORD dwNumberOfBytesWritten;
302 HANDLE hf;
304 if (!*curr)
305 GetCurrentDirectoryA(MAX_PATH, curr);
306 GetTempFileNameA(curr, "net", 0, temp);
307 lstrcpyA(path, temp);
308 hf = CreateFileA(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
309 FILE_ATTRIBUTE_NORMAL, NULL);
310 WriteFile(hf, certWithCRLDistPoint, sizeof(certWithCRLDistPoint),
311 &dwNumberOfBytesWritten, NULL);
312 CloseHandle(hf);
315 static void test_retrieveObjectByUrl(void)
317 BOOL ret;
318 char tmpfile[MAX_PATH], url[MAX_PATH + 8];
319 CRYPT_BLOB_ARRAY *pBlobArray;
320 PCCERT_CONTEXT cert;
321 PCCRL_CONTEXT crl;
322 HCERTSTORE store;
323 CRYPT_RETRIEVE_AUX_INFO aux = { 0 };
324 FILETIME ft = { 0 };
326 SetLastError(0xdeadbeef);
327 ret = CryptRetrieveObjectByUrlA(NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL);
328 ok(!ret && (GetLastError() == ERROR_INVALID_PARAMETER ||
329 GetLastError() == E_INVALIDARG),
330 "got 0x%x/%u (expected ERROR_INVALID_PARAMETER or E_INVALIDARG)\n",
331 GetLastError(), GetLastError());
333 make_tmp_file(tmpfile);
334 sprintf(url, "file://%s", tmpfile);
336 pBlobArray = (CRYPT_BLOB_ARRAY *)0xdeadbeef;
337 ret = CryptRetrieveObjectByUrlA(url, NULL, 0, 0, (void **)&pBlobArray,
338 NULL, NULL, NULL, NULL);
339 if (!ret)
341 /* File URL support was apparently removed in Vista/Windows 2008 */
342 win_skip("File URLs not supported\n");
343 return;
345 ok(ret, "CryptRetrieveObjectByUrlA failed: %d\n", GetLastError());
346 ok(pBlobArray && pBlobArray != (CRYPT_BLOB_ARRAY *)0xdeadbeef,
347 "Expected a valid pointer\n");
348 if (pBlobArray && pBlobArray != (CRYPT_BLOB_ARRAY *)0xdeadbeef)
350 ok(pBlobArray->cBlob == 1, "Expected 1 blob, got %d\n",
351 pBlobArray->cBlob);
352 ok(pBlobArray->rgBlob[0].cbData == sizeof(certWithCRLDistPoint),
353 "Unexpected size %d\n", pBlobArray->rgBlob[0].cbData);
354 CryptMemFree(pBlobArray);
356 cert = (PCCERT_CONTEXT)0xdeadbeef;
357 ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, 0, 0,
358 (void **)&cert, NULL, NULL, NULL, NULL);
359 ok(ret, "CryptRetrieveObjectByUrlA failed: %d\n", GetLastError());
360 ok(cert && cert != (PCCERT_CONTEXT)0xdeadbeef, "Expected a cert\n");
361 if (cert && cert != (PCCERT_CONTEXT)0xdeadbeef)
362 CertFreeCertificateContext(cert);
363 crl = (PCCRL_CONTEXT)0xdeadbeef;
364 SetLastError(0xdeadbeef);
365 ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CRL, 0, 0, (void **)&crl,
366 NULL, NULL, NULL, NULL);
367 /* w2k3,XP, newer w2k: CRYPT_E_NO_MATCH, older w2k: CRYPT_E_ASN1_BADTAG
368 * or OSS_DATA_ERROR.
370 ok(!ret && (GetLastError() == CRYPT_E_NO_MATCH ||
371 broken(GetLastError() == CRYPT_E_ASN1_BADTAG ||
372 GetLastError() == OSS_DATA_ERROR)),
373 "got 0x%x/%u (expected CRYPT_E_NO_MATCH)\n", GetLastError(), GetLastError());
375 /* only newer versions of cryptnet do the cleanup */
376 if(!ret && GetLastError() != CRYPT_E_ASN1_BADTAG &&
377 GetLastError() != OSS_DATA_ERROR) {
378 ok(crl == NULL, "Expected CRL to be NULL\n");
381 if (crl && crl != (PCCRL_CONTEXT)0xdeadbeef)
382 CertFreeCRLContext(crl);
383 store = (HCERTSTORE)0xdeadbeef;
384 ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CAPI2_ANY, 0, 0,
385 &store, NULL, NULL, NULL, NULL);
386 ok(ret, "CryptRetrieveObjectByUrlA failed: %d\n", GetLastError());
387 if (store && store != (HCERTSTORE)0xdeadbeef)
389 DWORD certs = 0;
391 cert = NULL;
392 do {
393 cert = CertEnumCertificatesInStore(store, cert);
394 if (cert)
395 certs++;
396 } while (cert);
397 ok(certs == 1, "Expected 1 cert, got %d\n", certs);
398 CertCloseStore(store, 0);
400 /* Are file URLs cached? */
401 cert = (PCCERT_CONTEXT)0xdeadbeef;
402 ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE,
403 CRYPT_CACHE_ONLY_RETRIEVAL, 0, (void **)&cert, NULL, NULL, NULL, NULL);
404 ok(ret, "CryptRetrieveObjectByUrlA failed: %08x\n", GetLastError());
405 if (cert && cert != (PCCERT_CONTEXT)0xdeadbeef)
406 CertFreeCertificateContext(cert);
408 cert = (PCCERT_CONTEXT)0xdeadbeef;
409 ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, 0, 0,
410 (void **)&cert, NULL, NULL, NULL, &aux);
411 /* w2k: failure with E_INVALIDARG */
412 ok(ret || broken(GetLastError() == E_INVALIDARG),
413 "got %u with 0x%x/%u (expected '!=0' or '0' with E_INVALIDARG)\n",
414 ret, GetLastError(), GetLastError());
415 if (cert && cert != (PCCERT_CONTEXT)0xdeadbeef)
416 CertFreeCertificateContext(cert);
418 cert = (PCCERT_CONTEXT)0xdeadbeef;
419 aux.cbSize = sizeof(aux);
420 ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, 0, 0,
421 (void **)&cert, NULL, NULL, NULL, &aux);
422 /* w2k: failure with E_INVALIDARG */
423 ok(ret || broken(GetLastError() == E_INVALIDARG),
424 "got %u with 0x%x/%u (expected '!=0' or '0' with E_INVALIDARG)\n",
425 ret, GetLastError(), GetLastError());
426 if (!ret) {
427 /* no more tests useful */
428 DeleteFileA(tmpfile);
429 skip("no usable CertificateContext\n");
430 return;
432 CertFreeCertificateContext(cert);
434 aux.pLastSyncTime = &ft;
435 ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, 0, 0,
436 (void **)&cert, NULL, NULL, NULL, &aux);
437 ok(ret, "CryptRetrieveObjectByUrlA failed: %08x\n", GetLastError());
438 CertFreeCertificateContext(cert);
439 ok(ft.dwLowDateTime || ft.dwHighDateTime,
440 "Expected last sync time to be set\n");
441 DeleteFileA(tmpfile);
442 /* Okay, after being deleted, are file URLs still cached? */
443 SetLastError(0xdeadbeef);
444 ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE,
445 CRYPT_CACHE_ONLY_RETRIEVAL, 0, (void **)&cert, NULL, NULL, NULL, NULL);
446 ok(!ret && (GetLastError() == ERROR_FILE_NOT_FOUND ||
447 GetLastError() == ERROR_PATH_NOT_FOUND),
448 "Expected ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND, got %d\n",
449 GetLastError());
452 static const BYTE rootWithKeySignAndCRLSign[] = {
453 0x30,0x82,0x01,0xdf,0x30,0x82,0x01,0x4c,0xa0,0x03,0x02,0x01,0x02,0x02,0x10,
454 0x5b,0xc7,0x0b,0x27,0x99,0xbb,0x2e,0x99,0x47,0x9d,0x45,0x4e,0x7c,0x1a,0xca,
455 0xe8,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x30,0x10,0x31,
456 0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x31,
457 0x30,0x1e,0x17,0x0d,0x30,0x37,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,
458 0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x32,0x33,0x31,0x32,0x33,0x35,0x39,0x35,
459 0x39,0x5a,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,
460 0x43,0x65,0x72,0x74,0x31,0x30,0x81,0x9f,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,
461 0x86,0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x81,0x8d,0x00,0x30,0x81,0x89,
462 0x02,0x81,0x81,0x00,0xad,0x7e,0xca,0xf3,0xe5,0x99,0xc2,0x2a,0xca,0x50,0x82,
463 0x7c,0x2d,0xa4,0x81,0xcd,0x0d,0x0d,0x86,0xd7,0xd8,0xb2,0xde,0xc5,0xc3,0x34,
464 0x9e,0x07,0x78,0x08,0x11,0x12,0x2d,0x21,0x0a,0x09,0x07,0x14,0x03,0x7a,0xe7,
465 0x3b,0x58,0xf1,0xde,0x3e,0x01,0x25,0x93,0xab,0x8f,0xce,0x1f,0xc1,0x33,0x91,
466 0xfe,0x59,0xb9,0x3b,0x9e,0x95,0x12,0x89,0x8e,0xc3,0x4b,0x98,0x1b,0x99,0xc5,
467 0x07,0xe2,0xdf,0x15,0x4c,0x39,0x76,0x06,0xad,0xdb,0x16,0x06,0x49,0xba,0xcd,
468 0x0f,0x07,0xd6,0xea,0x27,0xa6,0xfe,0x3d,0x88,0xe5,0x97,0x45,0x72,0xb6,0x1c,
469 0xc0,0x1c,0xb1,0xa2,0x89,0xe8,0x37,0x9e,0xf6,0x2a,0xcf,0xd5,0x1f,0x2f,0x35,
470 0x5e,0x8f,0x3a,0x9c,0x61,0xb1,0xf1,0x6c,0xff,0x8c,0xb2,0x2f,0x02,0x03,0x01,
471 0x00,0x01,0xa3,0x42,0x30,0x40,0x30,0x0e,0x06,0x03,0x55,0x1d,0x0f,0x01,0x01,
472 0xff,0x04,0x04,0x03,0x02,0x00,0x06,0x30,0x0f,0x06,0x03,0x55,0x1d,0x13,0x01,
473 0x01,0xff,0x04,0x05,0x30,0x03,0x01,0x01,0xff,0x30,0x1d,0x06,0x03,0x55,0x1d,
474 0x0e,0x04,0x16,0x04,0x14,0x14,0x8c,0x16,0xbb,0xbe,0x70,0xa2,0x28,0x89,0xa0,
475 0x58,0xff,0x98,0xbd,0xa8,0x24,0x2b,0x8a,0xe9,0x9a,0x30,0x09,0x06,0x05,0x2b,
476 0x0e,0x03,0x02,0x1d,0x05,0x00,0x03,0x81,0x81,0x00,0x74,0xcb,0x21,0xfd,0x2d,
477 0x25,0xdc,0xa5,0xaa,0xa1,0x26,0xdc,0x8b,0x40,0x11,0x64,0xae,0x5c,0x71,0x3c,
478 0x28,0xbc,0xf9,0xb3,0xcb,0xa5,0x94,0xb2,0x8d,0x4c,0x23,0x2b,0x9b,0xde,0x2c,
479 0x4c,0x30,0x04,0xc6,0x88,0x10,0x2f,0x53,0xfd,0x6c,0x82,0xf1,0x13,0xfb,0xda,
480 0x27,0x75,0x25,0x48,0xe4,0x72,0x09,0x2a,0xee,0xb4,0x1e,0xc9,0x55,0xf5,0xf7,
481 0x82,0x91,0xd8,0x4b,0xe4,0x3a,0xfe,0x97,0x87,0xdf,0xfb,0x15,0x5a,0x12,0x3e,
482 0x12,0xe6,0xad,0x40,0x0b,0xcf,0xee,0x1a,0x44,0xe0,0x83,0xb2,0x67,0x94,0xd4,
483 0x2e,0x7c,0xf2,0x06,0x9d,0xb3,0x3b,0x7e,0x2f,0xda,0x25,0x66,0x7e,0xa7,0x1f,
484 0x45,0xd4,0xf5,0xe3,0xdf,0x2a,0xf1,0x18,0x28,0x20,0xb5,0xf8,0xf5,0x8d,0x7a,
485 0x2e,0x84,0xee };
486 static const BYTE revokedCert[] = {
487 0x30,0x82,0x01,0xb9,0x30,0x82,0x01,0x22,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,
488 0x01,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,
489 0x00,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,
490 0x65,0x72,0x74,0x31,0x30,0x1e,0x17,0x0d,0x30,0x37,0x30,0x35,0x30,0x31,0x30,
491 0x30,0x30,0x30,0x30,0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x30,0x30,0x31,0x30,
492 0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,
493 0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x32,0x30,0x81,0x9f,0x30,0x0d,0x06,
494 0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x81,0x8d,
495 0x00,0x30,0x81,0x89,0x02,0x81,0x81,0x00,0xb8,0x52,0xda,0xc5,0x4b,0x3f,0xe5,
496 0x33,0x0e,0x67,0x5f,0x48,0x21,0xdc,0x7e,0xef,0x37,0x33,0xba,0xff,0xb4,0xc6,
497 0xdc,0xb6,0x17,0x8e,0x20,0x55,0x07,0x12,0xd2,0x7b,0x3c,0xce,0x30,0xc5,0xa7,
498 0x48,0x9f,0x6e,0xfe,0xb8,0xbe,0xdb,0x9f,0x9b,0x17,0x60,0x16,0xde,0xc6,0x8b,
499 0x47,0xd1,0x57,0x71,0x3c,0x93,0xfc,0xbd,0xec,0x44,0x32,0x3b,0xb9,0xcf,0x6b,
500 0x05,0x72,0xa7,0x87,0x8e,0x7e,0xd4,0x9a,0x87,0x1c,0x2f,0xb7,0x82,0x40,0xfc,
501 0x6a,0x80,0x83,0x68,0x28,0xce,0x84,0xf4,0x0b,0x2e,0x44,0xcb,0x53,0xac,0x85,
502 0x85,0xb5,0x46,0x36,0x98,0x3c,0x10,0x02,0xaa,0x02,0xbc,0x8b,0xa2,0x23,0xb2,
503 0xd3,0x51,0x9a,0x22,0x4a,0xe3,0xaa,0x4e,0x7c,0xda,0x38,0xcf,0x49,0x98,0x72,
504 0xa3,0x02,0x03,0x01,0x00,0x01,0xa3,0x23,0x30,0x21,0x30,0x1f,0x06,0x03,0x55,
505 0x1d,0x23,0x04,0x18,0x30,0x18,0x80,0x14,0x14,0x8c,0x16,0xbb,0xbe,0x70,0xa2,
506 0x28,0x89,0xa0,0x58,0xff,0x98,0xbd,0xa8,0x24,0x2b,0x8a,0xe9,0x9a,0x30,0x0d,
507 0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x03,0x81,
508 0x81,0x00,0x8a,0x49,0xa9,0x86,0x5e,0xc9,0x33,0x7e,0xfd,0xab,0x64,0x1f,0x6d,
509 0x00,0xd7,0x9b,0xec,0xd1,0x5b,0x38,0xcc,0xd6,0xf3,0xf2,0xb4,0x75,0x70,0x00,
510 0x82,0x9d,0x37,0x58,0xe1,0xcd,0x2c,0x61,0xb3,0x28,0xe7,0x8a,0x00,0xbe,0x6e,
511 0xca,0xe8,0x55,0xd5,0xad,0x3a,0xea,0xaf,0x13,0x20,0x1c,0x44,0xfc,0xb4,0xf9,
512 0x29,0x2b,0xdc,0x8a,0x2d,0x1b,0x27,0x9e,0xb9,0x3b,0x4a,0x71,0x9d,0x47,0x7d,
513 0xf7,0x92,0x6b,0x21,0x7f,0xfa,0x88,0x79,0x94,0x33,0xf6,0xdd,0x92,0x04,0x92,
514 0xd6,0x5e,0x0a,0x74,0xf2,0x85,0xa6,0xd5,0x3c,0x28,0xc0,0x89,0x5d,0xda,0xf3,
515 0xa6,0x01,0xc2,0xe9,0xa3,0xc1,0xb7,0x21,0x08,0xba,0x18,0x07,0x45,0xeb,0x77,
516 0x7d,0xcd,0xc6,0xe7,0x2a,0x7b,0x46,0xd2,0x3d,0xb5 };
517 static const BYTE unRevokedCert[] = {
518 0x30,0x82,0x01,0xa2,0x30,0x82,0x01,0x0d,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,
519 0x02,0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x30,
520 0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,
521 0x74,0x31,0x30,0x1e,0x17,0x0d,0x30,0x37,0x30,0x35,0x30,0x31,0x30,0x30,0x30,
522 0x30,0x30,0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x30,0x30,0x31,0x30,0x30,0x30,
523 0x30,0x30,0x30,0x5a,0x30,0x24,0x31,0x22,0x30,0x0e,0x06,0x03,0x55,0x04,0x03,
524 0x13,0x07,0x66,0x6f,0x6f,0x2e,0x63,0x6f,0x6d,0x30,0x10,0x06,0x03,0x55,0x04,
525 0x03,0x13,0x09,0x2a,0x2e,0x66,0x6f,0x6f,0x2e,0x63,0x6f,0x6d,0x30,0x81,0x9d,
526 0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x03,0x81,
527 0x8d,0x00,0x30,0x81,0x89,0x02,0x81,0x81,0x00,0xb8,0x52,0xda,0xc5,0x4b,0x3f,
528 0xe5,0x33,0x0e,0x67,0x5f,0x48,0x21,0xdc,0x7e,0xef,0x37,0x33,0xba,0xff,0xb4,
529 0xc6,0xdc,0xb6,0x17,0x8e,0x20,0x55,0x07,0x12,0xd2,0x7b,0x3c,0xce,0x30,0xc5,
530 0xa7,0x48,0x9f,0x6e,0xfe,0xb8,0xbe,0xdb,0x9f,0x9b,0x17,0x60,0x16,0xde,0xc6,
531 0x8b,0x47,0xd1,0x57,0x71,0x3c,0x93,0xfc,0xbd,0xec,0x44,0x32,0x3b,0xb9,0xcf,
532 0x6b,0x05,0x72,0xa7,0x87,0x8e,0x7e,0xd4,0x9a,0x87,0x1c,0x2f,0xb7,0x82,0x40,
533 0xfc,0x6a,0x80,0x83,0x68,0x28,0xce,0x84,0xf4,0x0b,0x2e,0x44,0xcb,0x53,0xac,
534 0x85,0x85,0xb5,0x46,0x36,0x98,0x3c,0x10,0x02,0xaa,0x02,0xbc,0x8b,0xa2,0x23,
535 0xb2,0xd3,0x51,0x9a,0x22,0x4a,0xe3,0xaa,0x4e,0x7c,0xda,0x38,0xcf,0x49,0x98,
536 0x72,0xa3,0x02,0x03,0x01,0x00,0x01,0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,
537 0xf7,0x0d,0x01,0x01,0x05,0x03,0x81,0x81,0x00,0x9f,0x11,0x8a,0x0a,0x6e,0xb0,
538 0x73,0xcc,0x48,0xf1,0x92,0xca,0xaf,0x9a,0x3d,0xb9,0xcf,0xbe,0x84,0xd0,0xa8,
539 0x34,0x25,0x27,0x9d,0x28,0x68,0xc5,0x35,0x2b,0x84,0xff,0xdb,0xd0,0x1f,0x0d,
540 0xd7,0xd6,0x8c,0x1b,0x33,0x52,0x7d,0x19,0xd0,0xc2,0xf3,0x63,0xd6,0x55,0x45,
541 0xf9,0x46,0xa0,0xb7,0xb3,0x94,0xbb,0x25,0x9b,0x29,0x76,0x7c,0x11,0xc7,0x7b,
542 0xcc,0xcb,0x99,0x3c,0xae,0xe7,0x16,0xb5,0xa7,0x6a,0x1f,0x75,0x4a,0x58,0x65,
543 0xb1,0x5b,0x91,0x29,0x20,0x81,0x51,0x64,0x05,0x24,0xa5,0x77,0xb7,0x8e,0xc8,
544 0x32,0x0f,0x0d,0x4f,0xf9,0x78,0x0f,0xc4,0xef,0xd6,0x25,0x5a,0xa4,0x9b,0x07,
545 0x17,0xea,0x56,0xe2,0x7b,0x61,0x1c,0x2d,0x40,0x38,0x9a,0x24,0x64,0x4b,0x6d,
546 0x08,0x96 };
547 static const BYTE rootSignedCRLWithBadAKI[] = {
548 0x30,0x82,0x01,0x1f,0x30,0x81,0x89,0x02,0x01,0x01,0x30,0x0d,0x06,0x09,0x2a,
549 0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,0x10,0x31,0x0e,0x30,
550 0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x31,0x17,0x0d,
551 0x30,0x37,0x30,0x39,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x17,0x0d,
552 0x30,0x37,0x31,0x32,0x33,0x31,0x32,0x33,0x35,0x39,0x35,0x39,0x5a,0x30,0x14,
553 0x30,0x12,0x02,0x01,0x01,0x17,0x0d,0x30,0x37,0x30,0x39,0x30,0x31,0x30,0x30,
554 0x30,0x30,0x30,0x30,0x5a,0xa0,0x2f,0x30,0x2d,0x30,0x0a,0x06,0x03,0x55,0x1d,
555 0x14,0x04,0x03,0x02,0x01,0x01,0x30,0x1f,0x06,0x03,0x55,0x1d,0x23,0x04,0x18,
556 0x30,0x18,0x80,0x14,0x14,0x8c,0x16,0xbb,0xbe,0x70,0xa2,0x28,0x89,0xa0,0x58,
557 0xff,0x98,0xbd,0xa8,0x24,0x2b,0x8a,0xe9,0x9a,0x30,0x0d,0x06,0x09,0x2a,0x86,
558 0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x03,0x81,0x81,0x00,0xa3,0xcf,
559 0x17,0x5d,0x7a,0x08,0xab,0x11,0x1a,0xbd,0x5c,0xde,0x9a,0x22,0x92,0x38,0xe6,
560 0x96,0xcc,0xb1,0xc5,0x42,0x86,0xa6,0xae,0xad,0xa3,0x1a,0x2b,0xa0,0xb0,0x65,
561 0xaa,0x9c,0xd7,0x2d,0x44,0x8c,0xae,0x61,0xc7,0x30,0x17,0x89,0x84,0x3b,0x4a,
562 0x8f,0x17,0x08,0x06,0x37,0x1c,0xf7,0x2d,0x4e,0x47,0x07,0x61,0x50,0xd9,0x06,
563 0xd1,0x46,0xed,0x0a,0xbb,0xc3,0x9b,0x36,0x0b,0xa7,0x27,0x2f,0x2b,0x55,0xce,
564 0x2a,0xa5,0x60,0xc6,0x53,0x28,0xe8,0xee,0xad,0x0e,0x2b,0xe8,0xd7,0x5f,0xc9,
565 0xa5,0xed,0xf9,0x77,0xb0,0x3c,0x81,0xcf,0xcc,0x49,0xb2,0x1a,0xc3,0xfd,0x34,
566 0xd5,0xbc,0xb0,0xd5,0xa5,0x9c,0x1b,0x72,0xc3,0x0f,0xa3,0xe3,0x3c,0xf0,0xc3,
567 0x91,0xe8,0x93,0x4f,0xd4,0x2f };
568 static const BYTE rootSignedCRL[] = {
569 0x30,0x81,0xe6,0x30,0x53,0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,
570 0x01,0x01,0x05,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,
571 0x05,0x43,0x65,0x72,0x74,0x31,0x17,0x0d,0x30,0x37,0x30,0x35,0x30,0x31,0x30,
572 0x30,0x30,0x30,0x30,0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x32,0x33,0x31,0x32,
573 0x33,0x35,0x39,0x35,0x39,0x5a,0x30,0x14,0x30,0x12,0x02,0x01,0x01,0x17,0x0d,
574 0x30,0x37,0x31,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x0b,
575 0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x03,0x81,0x81,0x00,
576 0x94,0x84,0x0a,0xad,0x63,0xe3,0x05,0xc1,0xd8,0x94,0x44,0xeb,0x30,0x03,0xa1,
577 0xb4,0x7b,0x09,0x2f,0xf6,0xef,0x0f,0xe5,0x58,0x70,0x67,0xac,0x32,0x91,0xc0,
578 0x9d,0xf1,0x2b,0xf4,0xb3,0xcf,0xdd,0x1d,0x74,0x7b,0x6f,0x59,0x36,0x73,0xca,
579 0xcd,0x9c,0xb6,0xd9,0x35,0x39,0x45,0x8d,0xfd,0xf9,0x65,0xf3,0x42,0x2c,0x2c,
580 0xa6,0xfc,0xd2,0x23,0x6c,0x73,0x28,0x21,0x47,0x22,0x88,0x36,0x7d,0xd8,0xf0,
581 0xd0,0xca,0x11,0x20,0x50,0x6b,0x1e,0xb1,0x16,0x16,0xde,0xa6,0xc1,0x8d,0x18,
582 0xf1,0x42,0x22,0x1d,0x95,0x11,0xd7,0xa9,0x8f,0x90,0xe5,0x2f,0x71,0x52,0x47,
583 0xe0,0x45,0xb1,0x5a,0x2c,0x72,0x8a,0x25,0xca,0xd6,0x96,0xa2,0x7b,0x83,0x4c,
584 0xa3,0x24,0x7e,0xdd,0x45,0xa1,0x38,0xf8 };
586 static BOOL (WINAPI *pCertVerifyRevocation)(DWORD, DWORD, DWORD, void **, DWORD,
587 PCERT_REVOCATION_PARA, PCERT_REVOCATION_STATUS);
589 /* Wednesday, Oct 1, 2007 */
590 static SYSTEMTIME oct2007 = { 2007, 10, 1, 1, 0, 0, 0, 0 };
591 /* Tuesday, May 1, 2007 */
592 static SYSTEMTIME may2007 = { 2007, 5, 2, 1, 0, 0, 0, 0 };
594 static void test_verifyRevocation(void)
596 CERT_REVOCATION_STATUS status = {sizeof(status)};
597 CERT_REVOCATION_PARA params = {sizeof(params)};
598 const CERT_CONTEXT *certs[2];
599 FILETIME time;
600 BOOL ret;
602 pCertVerifyRevocation = (void *)GetProcAddress(GetModuleHandleA("cryptnet.dll"), "CertDllVerifyRevocation");
604 if (0)
606 /* Crash */
607 pCertVerifyRevocation(0, 0, 0, NULL, 0, NULL, NULL);
610 SetLastError(0xdeadbeef);
611 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
612 ret = pCertVerifyRevocation(0, 0, 0, NULL, 0, NULL, &status);
613 ok(!ret, "expected failure\n");
614 ok(GetLastError() == E_INVALIDARG, "got error %#x\n", GetLastError());
615 todo_wine ok(!status.dwIndex, "got index %u\n", status.dwIndex);
616 todo_wine ok(status.dwError == E_INVALIDARG, "got error %#x\n", status.dwError);
617 todo_wine ok(!status.dwReason, "got reason %u\n", status.dwReason);
619 SetLastError(0xdeadbeef);
620 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
621 ret = pCertVerifyRevocation(X509_ASN_ENCODING, 0, 0, NULL, 0, NULL, &status);
622 ok(!ret, "expected failure\n");
623 ok(GetLastError() == E_INVALIDARG, "got error %#x\n", GetLastError());
624 todo_wine ok(!status.dwIndex, "got index %u\n", status.dwIndex);
625 todo_wine ok(status.dwError == E_INVALIDARG, "got error %#x\n", status.dwError);
626 todo_wine ok(!status.dwReason, "got reason %u\n", status.dwReason);
628 SetLastError(0xdeadbeef);
629 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
630 ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 0, NULL, 0, NULL, &status);
631 ok(!ret, "expected failure\n");
632 ok(GetLastError() == E_INVALIDARG, "got error %#x\n", GetLastError());
633 todo_wine ok(!status.dwIndex, "got index %u\n", status.dwIndex);
634 todo_wine ok(status.dwError == E_INVALIDARG, "got error %#x\n", status.dwError);
635 todo_wine ok(!status.dwReason, "got reason %u\n", status.dwReason);
637 certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert, sizeof(bigCert));
639 SetLastError(0xdeadbeef);
640 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
641 ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)certs, 0, NULL, &status);
642 ok(!ret, "expected failure\n");
643 ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", GetLastError());
644 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
645 ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", status.dwError);
646 ok(!status.dwReason, "got reason %u\n", status.dwReason);
648 CertFreeCertificateContext(certs[0]);
650 certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING, rootWithKeySignAndCRLSign, sizeof(rootWithKeySignAndCRLSign));
651 certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING, revokedCert, sizeof(revokedCert));
653 /* The root cert itself can't be checked for revocation */
654 SetLastError(0xdeadbeef);
655 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
656 ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)&certs[0], 0, NULL, &status);
657 ok(!ret, "expected failure\n");
658 ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", GetLastError());
659 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
660 ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", status.dwError);
661 ok(!status.dwReason, "got reason %u\n", status.dwReason);
663 /* Neither can the end cert */
664 SetLastError(0xdeadbeef);
665 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
666 ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)&certs[1], 0, NULL, &status);
667 ok(!ret, "expected failure\n");
668 ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", GetLastError());
669 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
670 ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", status.dwError);
671 ok(!status.dwReason, "got reason %u\n", status.dwReason);
673 /* Both certs together can't, either (they're not CRLs) */
674 SetLastError(0xdeadbeef);
675 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
676 ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 2, (void **)certs, 0, NULL, &status);
677 ok(!ret, "expected failure\n");
678 ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", GetLastError());
679 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
680 ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", status.dwError);
681 ok(!status.dwReason, "got reason %u\n", status.dwReason);
683 /* Test with an invalid CRL */
685 params.hCrlStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL);
686 ret = CertAddEncodedCRLToStore(params.hCrlStore, X509_ASN_ENCODING, rootSignedCRLWithBadAKI,
687 sizeof(rootSignedCRLWithBadAKI), CERT_STORE_ADD_ALWAYS, NULL);
688 ok(ret, "failed to add CRL, error %u\n", GetLastError());
690 SetLastError(0xdeadbeef);
691 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
692 ret = pCertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
693 2, (void **)certs, 0, &params, &status);
694 ok(!ret, "expected failure\n");
695 ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", GetLastError());
696 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
697 ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", status.dwError);
698 ok(!status.dwReason, "got reason %u\n", status.dwReason);
700 /* Specifying CERT_VERIFY_REV_CHAIN_FLAG doesn't change things either */
701 SetLastError(0xdeadbeef);
702 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
703 ret = pCertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
704 2, (void **)certs, CERT_VERIFY_REV_CHAIN_FLAG, &params, &status);
705 ok(!ret, "expected failure\n");
706 ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", GetLastError());
707 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
708 ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", status.dwError);
709 ok(!status.dwReason, "got reason %u\n", status.dwReason);
711 /* Again, specifying the issuer cert: no change */
712 params.pIssuerCert = certs[0];
713 SetLastError(0xdeadbeef);
714 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
715 ret = pCertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
716 1, (void **)&certs[1], 0, &params, &status);
717 ok(!ret, "expected failure\n");
718 ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", GetLastError());
719 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
720 ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", status.dwError);
721 ok(!status.dwReason, "got reason %u\n", status.dwReason);
723 /* Specifying the time to check: still no change */
724 SystemTimeToFileTime(&oct2007, &time);
725 params.pftTimeToUse = &time;
727 SetLastError(0xdeadbeef);
728 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
729 ret = pCertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
730 1, (void **)&certs[1], 0, &params, &status);
731 ok(!ret, "expected failure\n");
732 ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", GetLastError());
733 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
734 ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", status.dwError);
735 ok(!status.dwReason, "got reason %u\n", status.dwReason);
737 CertCloseStore(params.hCrlStore, 0);
739 /* Test again with a valid CRL. This time, the cert should be revoked when
740 * the time is after the validity period of the CRL, or considered
741 * "revocation offline" when the checked time precedes the validity
742 * period of the CRL.
744 params.hCrlStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL);
745 ret = CertAddEncodedCRLToStore(params.hCrlStore, X509_ASN_ENCODING,
746 rootSignedCRL, sizeof(rootSignedCRL), CERT_STORE_ADD_ALWAYS, NULL);
747 ok(ret, "failed to add CRL, error %u\n", GetLastError());
749 params.pftTimeToUse = NULL;
751 SetLastError(0xdeadbeef);
752 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
753 ret = pCertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
754 1, (void **)&certs[1], 0, &params, &status);
755 ok(!ret, "expected failure\n");
756 ok(GetLastError() == CRYPT_E_REVOKED, "got error %#x\n", GetLastError());
757 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
758 ok(status.dwError == CRYPT_E_REVOKED, "got error %#x\n", status.dwError);
759 ok(!status.dwReason, "got reason %u\n", status.dwReason);
761 SystemTimeToFileTime(&oct2007, &time);
762 params.pftTimeToUse = &time;
763 SetLastError(0xdeadbeef);
764 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
765 ret = pCertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
766 1, (void **)&certs[1], 0, &params, &status);
767 ok(!ret, "expected failure\n");
768 ok(GetLastError() == CRYPT_E_REVOKED, "got error %#x\n", GetLastError());
769 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
770 ok(status.dwError == CRYPT_E_REVOKED, "got error %#x\n", status.dwError);
771 ok(!status.dwReason, "got reason %u\n", status.dwReason);
773 SystemTimeToFileTime(&may2007, &time);
774 SetLastError(0xdeadbeef);
775 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
776 ret = pCertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
777 1, (void **)&certs[1], 0, &params, &status);
778 ok(!ret, "expected failure\n");
779 ok(GetLastError() == CRYPT_E_REVOCATION_OFFLINE, "got error %#x\n", GetLastError());
780 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
781 ok(status.dwError == CRYPT_E_REVOCATION_OFFLINE, "got error %#x\n", status.dwError);
782 ok(!status.dwReason, "got reason %u\n", status.dwReason);
784 CertFreeCertificateContext(certs[1]);
786 /* Test again with a valid CRL and an un-revoked cert. No matter the
787 * time checked, it's reported as revocation offline.
789 certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING, unRevokedCert, sizeof(unRevokedCert));
791 params.pftTimeToUse = NULL;
792 SetLastError(0xdeadbeef);
793 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
794 ret = pCertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
795 1, (void **)&certs[1], 0, &params, &status);
796 ok(!ret, "expected failure\n");
797 ok(GetLastError() == CRYPT_E_REVOCATION_OFFLINE, "got error %#x\n", GetLastError());
798 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
799 ok(status.dwError == CRYPT_E_REVOCATION_OFFLINE, "got error %#x\n", status.dwError);
800 ok(!status.dwReason, "got reason %u\n", status.dwReason);
802 SystemTimeToFileTime(&oct2007, &time);
803 params.pftTimeToUse = &time;
804 SetLastError(0xdeadbeef);
805 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
806 ret = pCertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
807 1, (void **)&certs[1], 0, &params, &status);
808 ok(!ret, "expected failure\n");
809 ok(GetLastError() == CRYPT_E_REVOCATION_OFFLINE, "got error %#x\n", GetLastError());
810 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
811 ok(status.dwError == CRYPT_E_REVOCATION_OFFLINE, "got error %#x\n", status.dwError);
812 ok(!status.dwReason, "got reason %u\n", status.dwReason);
814 SystemTimeToFileTime(&may2007, &time);
815 SetLastError(0xdeadbeef);
816 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
817 ret = pCertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
818 1, (void **)&certs[1], 0, &params, &status);
819 ok(!ret, "expected failure\n");
820 ok(GetLastError() == CRYPT_E_REVOCATION_OFFLINE, "got error %#x\n", GetLastError());
821 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
822 ok(status.dwError == CRYPT_E_REVOCATION_OFFLINE, "got error %#x\n", status.dwError);
823 ok(!status.dwReason, "got reason %u\n", status.dwReason);
825 params.pftTimeToUse = NULL;
827 /* Test with the wrong encoding type. */
828 SetLastError(0xdeadbeef);
829 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
830 ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE,
831 1, (void **)&certs[1], 0, &params, &status);
832 ok(!ret, "expected failure\n");
833 todo_wine ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", GetLastError());
834 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
835 todo_wine ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", status.dwError);
836 ok(!status.dwReason, "got reason %u\n", status.dwReason);
838 /* Test with the wrong context type. */
839 SetLastError(0xdeadbeef);
840 memset(&status.dwIndex, 0xcc, sizeof(status) - offsetof(CERT_REVOCATION_STATUS, dwIndex));
841 ret = pCertVerifyRevocation(X509_ASN_ENCODING, 0xdeadbeef,
842 1, (void **)&certs[1], 0, &params, &status);
843 ok(!ret, "expected failure\n");
844 ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", GetLastError());
845 ok(!status.dwIndex, "got index %u\n", status.dwIndex);
846 ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "got error %#x\n", status.dwError);
847 ok(!status.dwReason, "got reason %u\n", status.dwReason);
849 CertCloseStore(params.hCrlStore, 0);
850 CertFreeCertificateContext(certs[1]);
851 CertFreeCertificateContext(certs[0]);
854 START_TEST(cryptnet)
856 test_getObjectUrl();
857 test_retrieveObjectByUrl();
858 test_verifyRevocation();