wined3d: IWineD3DBuffer_Unmap() can't fail.
[wine] / dlls / cryptnet / tests / cryptnet.c
1 /*
2  * Unit test suite for cryptnet.dll
3  *
4  * Copyright 2007 Juan Lang
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 <stdarg.h>
21 #include <stdio.h>
22 #define NONAMELESSUNION
23 #include <windef.h>
24 #include <winbase.h>
25 #include <winerror.h>
26 #include <wincrypt.h>
27 #include <shlwapi.h>
28 #include "wine/test.h"
29
30 static const BYTE bigCert[] = {
31 0x30,0x78,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x14,0x31,0x12,0x30,0x10,
32 0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
33 0x67,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,
34 0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,
35 0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
36 0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x30,
37 0x07,0x30,0x02,0x06,0x00,0x03,0x01,0x00,0xa3,0x16,0x30,0x14,0x30,0x12,0x06,
38 0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,0x01,0x01,0xff,0x02,
39 0x01,0x01};
40 static const BYTE certWithIssuingDistPoint[] = {
41 0x30,0x81,0x99,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,0x01,0x30,0x0d,0x06,0x09,
42 0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,0x14,0x31,0x12,
43 0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,
44 0x61,0x6e,0x67,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,
45 0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,
46 0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x14,0x31,0x12,0x30,0x10,
47 0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
48 0x67,0x30,0x07,0x30,0x02,0x06,0x00,0x03,0x01,0x00,0xa3,0x27,0x30,0x25,0x30,
49 0x23,0x06,0x03,0x55,0x1d,0x1c,0x01,0x01,0xff,0x04,0x19,0x30,0x17,0xa0,0x15,
50 0xa0,0x13,0x86,0x11,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x69,0x6e,0x65,
51 0x68,0x71,0x2e,0x6f,0x72,0x67, };
52 static const BYTE certWithCRLDistPoint[] = {
53 0x30,0x81,0x9b,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,0x01,0x30,0x0d,0x06,0x09,
54 0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,0x14,0x31,0x12,
55 0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,
56 0x61,0x6e,0x67,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,
57 0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,
58 0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x14,0x31,0x12,0x30,0x10,
59 0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
60 0x67,0x30,0x07,0x30,0x02,0x06,0x00,0x03,0x01,0x00,0xa3,0x29,0x30,0x27,0x30,
61 0x25,0x06,0x03,0x55,0x1d,0x1f,0x01,0x01,0xff,0x04,0x1b,0x30,0x19,0x30,0x17,
62 0xa0,0x15,0xa0,0x13,0x86,0x11,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x69,
63 0x6e,0x65,0x68,0x71,0x2e,0x6f,0x72,0x67, };
64 static const BYTE certWithAIAWithCAIssuers[] = {
65 0x30,0x82,0x01,0x3c,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,0x01,0x30,0x0b,0x06,
66 0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x30,0x14,0x31,0x12,0x30,
67 0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,
68 0x6e,0x67,0x30,0x1e,0x17,0x0d,0x30,0x39,0x31,0x30,0x32,0x38,0x30,0x30,0x30,
69 0x30,0x30,0x30,0x5a,0x17,0x0d,0x32,0x30,0x31,0x31,0x32,0x37,0x30,0x30,0x30,
70 0x30,0x30,0x30,0x5a,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,
71 0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x30,0x81,0xa5,0x30,
72 0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x03,0x81,0x95,
73 0x00,0x06,0x02,0x00,0x00,0x00,0x24,0x00,0x00,0x52,0x53,0x41,0x31,0x00,0x04,
74 0x00,0x00,0x01,0x00,0x01,0x00,0x2f,0xb2,0x8c,0xff,0x6c,0xf1,0xb1,0x61,0x9c,
75 0x3a,0x8f,0x5e,0x35,0x2f,0x1f,0xd5,0xcf,0x2a,0xf6,0x9e,0x37,0xe8,0x89,0xa2,
76 0xb1,0x1c,0xc0,0x1c,0xb6,0x72,0x45,0x97,0xe5,0x88,0x3d,0xfe,0xa6,0x27,0xea,
77 0xd6,0x07,0x0f,0xcd,0xba,0x49,0x06,0x16,0xdb,0xad,0x06,0x76,0x39,0x4c,0x15,
78 0xdf,0xe2,0x07,0xc5,0x99,0x1b,0x98,0x4b,0xc3,0x8e,0x89,0x12,0x95,0x9e,0x3b,
79 0xb9,0x59,0xfe,0x91,0x33,0xc1,0x1f,0xce,0x8f,0xab,0x93,0x25,0x01,0x3e,0xde,
80 0xf1,0x58,0x3b,0xe7,0x7a,0x03,0x14,0x07,0x09,0x0a,0x21,0x2d,0x12,0x11,0x08,
81 0x78,0x07,0x9e,0x34,0xc3,0xc5,0xde,0xb2,0xd8,0xd7,0x86,0x0d,0x0d,0xcd,0x81,
82 0xa4,0x2d,0x7c,0x82,0x50,0xca,0x2a,0xc2,0x99,0xe5,0xf3,0xca,0x7e,0xad,0xa3,
83 0x31,0x30,0x2f,0x30,0x2d,0x06,0x08,0x2b,0x06,0x01,0x05,0x05,0x07,0x01,0x01,
84 0x04,0x21,0x30,0x1f,0x30,0x1d,0x06,0x08,0x2b,0x06,0x01,0x05,0x05,0x07,0x30,
85 0x02,0x86,0x11,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x69,0x6e,0x65,0x68,
86 0x71,0x2e,0x6f,0x72,0x67 };
87
88 static void compareUrlArray(const CRYPT_URL_ARRAY *expected,
89  const CRYPT_URL_ARRAY *got)
90 {
91     ok(expected->cUrl == got->cUrl, "Expected %d URLs, got %d\n",
92      expected->cUrl, got->cUrl);
93     if (expected->cUrl == got->cUrl)
94     {
95         DWORD i;
96
97         for (i = 0; i < got->cUrl; i++)
98             ok(!lstrcmpiW(expected->rgwszUrl[i], got->rgwszUrl[i]),
99              "%d: unexpected URL\n", i);
100     }
101 }
102
103 static WCHAR url[] =
104  { 'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',0 };
105
106 static void test_getObjectUrl(void)
107 {
108     BOOL ret;
109     DWORD urlArraySize = 0, infoSize = 0;
110     PCCERT_CONTEXT cert;
111
112     SetLastError(0xdeadbeef);
113     ret = CryptGetObjectUrl(NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL);
114     ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
115      "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
116     /* Crash
117     ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, NULL, 0, NULL, NULL,
118      NULL, NULL, NULL);
119     ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, NULL, 0, NULL, NULL,
120      NULL, &infoSize, NULL);
121     ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, NULL, 0, NULL,
122      &urlArraySize, NULL, &infoSize, NULL);
123      */
124     /* A cert with no CRL dist point extension fails.. */
125     cert = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert,
126      sizeof(bigCert));
127     SetLastError(0xdeadbeef);
128     ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert, 0, NULL,
129      NULL, NULL, NULL, NULL);
130     ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
131      "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
132     CertFreeCertificateContext(cert);
133
134     cert = CertCreateCertificateContext(X509_ASN_ENCODING,
135      certWithIssuingDistPoint, sizeof(certWithIssuingDistPoint));
136     if (cert)
137     {
138         /* This cert has no AIA extension, so expect this to fail */
139         SetLastError(0xdeadbeef);
140         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert, 0,
141          NULL, NULL, NULL, NULL, NULL);
142         ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
143          "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
144         SetLastError(0xdeadbeef);
145         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert,
146          CRYPT_GET_URL_FROM_PROPERTY, NULL, NULL, NULL, NULL, NULL);
147         ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
148          "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
149         SetLastError(0xdeadbeef);
150         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert,
151          CRYPT_GET_URL_FROM_EXTENSION, NULL, NULL, NULL, NULL, NULL);
152         ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
153          "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
154         /* It does have an issuing dist point extension, but that's not what
155          * this is looking for (it wants a CRL dist points extension)
156          */
157         SetLastError(0xdeadbeef);
158         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
159          (void *)cert, 0, NULL, NULL, NULL, NULL, NULL);
160         ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
161          "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
162         SetLastError(0xdeadbeef);
163         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
164          (void *)cert, CRYPT_GET_URL_FROM_PROPERTY, NULL, NULL, NULL, NULL,
165          NULL);
166         ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
167          "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
168         SetLastError(0xdeadbeef);
169         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
170          (void *)cert, CRYPT_GET_URL_FROM_EXTENSION, NULL, NULL, NULL, NULL,
171          NULL);
172         ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
173          "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
174         CertFreeCertificateContext(cert);
175     }
176     cert = CertCreateCertificateContext(X509_ASN_ENCODING,
177      certWithCRLDistPoint, sizeof(certWithCRLDistPoint));
178     if (cert)
179     {
180         PCRYPT_URL_ARRAY urlArray;
181
182         /* This cert has no AIA extension, so expect this to fail */
183         SetLastError(0xdeadbeef);
184         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert, 0,
185          NULL, NULL, NULL, NULL, NULL);
186         ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
187          "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
188         SetLastError(0xdeadbeef);
189         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert,
190          CRYPT_GET_URL_FROM_PROPERTY, NULL, NULL, NULL, NULL, NULL);
191         ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
192          "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
193         SetLastError(0xdeadbeef);
194         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, (void *)cert,
195          CRYPT_GET_URL_FROM_EXTENSION, NULL, NULL, NULL, NULL, NULL);
196         ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
197          "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
198         /* It does have a CRL dist points extension */
199         SetLastError(0xdeadbeef);
200         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
201          (void *)cert, 0, NULL, NULL, NULL, NULL, NULL);
202         ok(!ret && GetLastError() == E_INVALIDARG,
203          "Expected E_INVALIDARG, got %08x\n", GetLastError());
204         SetLastError(0xdeadbeef);
205         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
206          (void *)cert, 0, NULL, NULL, NULL, &infoSize, NULL);
207         ok(!ret && GetLastError() == E_INVALIDARG,
208          "Expected E_INVALIDARG, got %08x\n", GetLastError());
209         /* Can get it without specifying the location: */
210         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
211          (void *)cert, 0, NULL, &urlArraySize, NULL, NULL, NULL);
212         ok(ret, "CryptGetObjectUrl failed: %08x\n", GetLastError());
213         urlArray = HeapAlloc(GetProcessHeap(), 0, urlArraySize);
214         if (urlArray)
215         {
216             ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
217              (void *)cert, 0, urlArray, &urlArraySize, NULL, NULL, NULL);
218             ok(ret, "CryptGetObjectUrl failed: %08x\n", GetLastError());
219             if (ret)
220             {
221                 LPWSTR pUrl = url;
222                 CRYPT_URL_ARRAY expectedUrl = { 1, &pUrl };
223
224                 compareUrlArray(&expectedUrl, urlArray);
225             }
226             HeapFree(GetProcessHeap(), 0, urlArray);
227         }
228         /* or by specifying it's an extension: */
229         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
230          (void *)cert, CRYPT_GET_URL_FROM_EXTENSION, NULL, &urlArraySize, NULL,
231          NULL, NULL);
232         ok(ret, "CryptGetObjectUrl failed: %08x\n", GetLastError());
233         urlArray = HeapAlloc(GetProcessHeap(), 0, urlArraySize);
234         if (urlArray)
235         {
236             ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
237              (void *)cert, CRYPT_GET_URL_FROM_EXTENSION, urlArray,
238              &urlArraySize, NULL, NULL, NULL);
239             ok(ret, "CryptGetObjectUrl failed: %08x\n", GetLastError());
240             if (ret)
241             {
242                 LPWSTR pUrl = url;
243                 CRYPT_URL_ARRAY expectedUrl = { 1, &pUrl };
244
245                 compareUrlArray(&expectedUrl, urlArray);
246             }
247             HeapFree(GetProcessHeap(), 0, urlArray);
248         }
249         /* but it isn't contained in a property: */
250         SetLastError(0xdeadbeef);
251         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
252          (void *)cert, CRYPT_GET_URL_FROM_PROPERTY, NULL, &urlArraySize, NULL,
253          NULL, NULL);
254         ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
255          "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
256         CertFreeCertificateContext(cert);
257     }
258     cert = CertCreateCertificateContext(X509_ASN_ENCODING,
259      certWithAIAWithCAIssuers, sizeof(certWithAIAWithCAIssuers));
260     if (cert)
261     {
262         PCRYPT_URL_ARRAY urlArray;
263
264         /* This has an AIA extension with the CA Issuers set, so expect it
265          * to succeed:
266          */
267         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER,
268          (void *)cert, 0, NULL, &urlArraySize, NULL, NULL, NULL);
269         ok(ret, "CryptGetObjectUrl failed: %08x\n", GetLastError());
270         if (ret)
271         {
272             urlArray = HeapAlloc(GetProcessHeap(), 0, urlArraySize);
273             if (urlArray)
274             {
275                 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER,
276                  (void *)cert, CRYPT_GET_URL_FROM_EXTENSION, urlArray,
277                  &urlArraySize, NULL, NULL, NULL);
278                 ok(ret, "CryptGetObjectUrl failed: %08x\n", GetLastError());
279                 if (ret)
280                 {
281                     LPWSTR pUrl = url;
282                     CRYPT_URL_ARRAY expectedUrl = { 1, &pUrl };
283
284                     compareUrlArray(&expectedUrl, urlArray);
285                 }
286                 HeapFree(GetProcessHeap(), 0, urlArray);
287             }
288         }
289         /* It doesn't have a CRL dist points extension, so this should fail */
290         SetLastError(0xdeadbeef);
291         ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT,
292          (void *)cert, 0, NULL, &urlArraySize, NULL, NULL, NULL);
293         ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
294          "expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
295         CertFreeCertificateContext(cert);
296     }
297 }
298
299 static void make_tmp_file(LPSTR path)
300 {
301     static char curr[MAX_PATH] = { 0 };
302     char temp[MAX_PATH];
303     DWORD dwNumberOfBytesWritten;
304     HANDLE hf;
305
306     if (!*curr)
307         GetCurrentDirectoryA(MAX_PATH, curr);
308     GetTempFileNameA(curr, "net", 0, temp);
309     lstrcpyA(path, temp);
310     hf = CreateFileA(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
311      FILE_ATTRIBUTE_NORMAL, NULL);
312     WriteFile(hf, certWithCRLDistPoint, sizeof(certWithCRLDistPoint),
313      &dwNumberOfBytesWritten, NULL);
314     CloseHandle(hf);
315 }
316
317 static void test_retrieveObjectByUrl(void)
318 {
319     BOOL ret;
320     char tmpfile[MAX_PATH * 2], url[MAX_PATH + 8];
321     CRYPT_BLOB_ARRAY *pBlobArray;
322     PCCERT_CONTEXT cert;
323     PCCRL_CONTEXT crl;
324     HCERTSTORE store;
325     CRYPT_RETRIEVE_AUX_INFO aux = { 0 };
326     FILETIME ft = { 0 };
327     DWORD urllen;
328
329     SetLastError(0xdeadbeef);
330     ret = CryptRetrieveObjectByUrlA(NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL);
331     ok(!ret && (GetLastError() == ERROR_INVALID_PARAMETER ||
332                 GetLastError() == E_INVALIDARG),
333        "got 0x%x/%u (expected ERROR_INVALID_PARAMETER or E_INVALIDARG)\n",
334        GetLastError(), GetLastError());
335
336     make_tmp_file(tmpfile);
337     urllen = sizeof(url);
338     UrlCanonicalizeA(tmpfile, url, &urllen, URL_WININET_COMPATIBILITY);
339
340     pBlobArray = (CRYPT_BLOB_ARRAY *)0xdeadbeef;
341     ret = CryptRetrieveObjectByUrlA(url, NULL, 0, 0, (void **)&pBlobArray,
342      NULL, NULL, NULL, NULL);
343     if (!ret)
344     {
345         /* File URL support was apparently removed in Vista/Windows 2008 */
346         win_skip("File URLs not supported\n");
347         return;
348     }
349     ok(ret, "CryptRetrieveObjectByUrlA failed: %d\n", GetLastError());
350     ok(pBlobArray && pBlobArray != (CRYPT_BLOB_ARRAY *)0xdeadbeef,
351      "Expected a valid pointer\n");
352     if (pBlobArray && pBlobArray != (CRYPT_BLOB_ARRAY *)0xdeadbeef)
353     {
354         ok(pBlobArray->cBlob == 1, "Expected 1 blob, got %d\n",
355          pBlobArray->cBlob);
356         ok(pBlobArray->rgBlob[0].cbData == sizeof(certWithCRLDistPoint),
357          "Unexpected size %d\n", pBlobArray->rgBlob[0].cbData);
358         CryptMemFree(pBlobArray);
359     }
360     cert = (PCCERT_CONTEXT)0xdeadbeef;
361     ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, 0, 0,
362      (void **)&cert, NULL, NULL, NULL, NULL);
363     ok(cert && cert != (PCCERT_CONTEXT)0xdeadbeef, "Expected a cert\n");
364     if (cert && cert != (PCCERT_CONTEXT)0xdeadbeef)
365         CertFreeCertificateContext(cert);
366     crl = (PCCRL_CONTEXT)0xdeadbeef;
367     SetLastError(0xdeadbeef);
368     ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CRL, 0, 0, (void **)&crl,
369      NULL, NULL, NULL, NULL);
370     /* w2k3,XP, newer w2k: CRYPT_E_NO_MATCH, 95: OSS_DATA_ERROR */
371     ok(!ret && (GetLastError() == CRYPT_E_NO_MATCH ||
372                 GetLastError() == CRYPT_E_ASN1_BADTAG ||
373                 GetLastError() == OSS_DATA_ERROR),
374        "got 0x%x/%u (expected CRYPT_E_NO_MATCH or CRYPT_E_ASN1_BADTAG or "
375        "OSS_DATA_ERROR)\n", GetLastError(), GetLastError());
376
377     /* only newer versions of cryptnet do the cleanup */
378     if(!ret && GetLastError() != CRYPT_E_ASN1_BADTAG &&
379                GetLastError() != OSS_DATA_ERROR) {
380         ok(crl == NULL, "Expected CRL to be NULL\n");
381     }
382
383     if (crl && crl != (PCCRL_CONTEXT)0xdeadbeef)
384         CertFreeCRLContext(crl);
385     store = (HCERTSTORE)0xdeadbeef;
386     ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CAPI2_ANY, 0, 0,
387      &store, NULL, NULL, NULL, NULL);
388     ok(ret, "CryptRetrieveObjectByUrlA failed: %d\n", GetLastError());
389     if (store && store != (HCERTSTORE)0xdeadbeef)
390     {
391         DWORD certs = 0;
392
393         cert = NULL;
394         do {
395             cert = CertEnumCertificatesInStore(store, cert);
396             if (cert)
397                 certs++;
398         } while (cert);
399         ok(certs == 1, "Expected 1 cert, got %d\n", certs);
400         CertCloseStore(store, 0);
401     }
402     /* Are file URLs cached? */
403     cert = (PCCERT_CONTEXT)0xdeadbeef;
404     ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE,
405      CRYPT_CACHE_ONLY_RETRIEVAL, 0, (void **)&cert, NULL, NULL, NULL, NULL);
406     ok(ret, "CryptRetrieveObjectByUrlA failed: %08x\n", GetLastError());
407     if (cert && cert != (PCCERT_CONTEXT)0xdeadbeef)
408         CertFreeCertificateContext(cert);
409
410     cert = (PCCERT_CONTEXT)0xdeadbeef;
411     ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, 0, 0,
412      (void **)&cert, NULL, NULL, NULL, &aux);
413     /* w2k: success, 9x: fail with E_INVALIDARG */
414     ok(ret || (GetLastError() == E_INVALIDARG),
415        "got %u with 0x%x/%u (expected '!=0' or '0' with E_INVALIDARG)\n",
416        ret, GetLastError(), GetLastError());
417     if (cert && cert != (PCCERT_CONTEXT)0xdeadbeef)
418         CertFreeCertificateContext(cert);
419
420     cert = (PCCERT_CONTEXT)0xdeadbeef;
421     aux.cbSize = sizeof(aux);
422     ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, 0, 0,
423      (void **)&cert, NULL, NULL, NULL, &aux);
424     /* w2k: success, 9x: fail with E_INVALIDARG */
425     ok(ret || (GetLastError() == E_INVALIDARG),
426        "got %u with 0x%x/%u (expected '!=0' or '0' with E_INVALIDARG)\n",
427        ret, GetLastError(), GetLastError());
428     if (!ret) {
429         /* no more tests useful */
430         DeleteFileA(tmpfile);
431         skip("no usable CertificateContext\n");
432         return;
433     }
434     CertFreeCertificateContext(cert);
435
436     aux.pLastSyncTime = &ft;
437     ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, 0, 0,
438      (void **)&cert, NULL, NULL, NULL, &aux);
439     ok(ret, "CryptRetrieveObjectByUrlA failed: %08x\n", GetLastError());
440     CertFreeCertificateContext(cert);
441     ok(ft.dwLowDateTime || ft.dwHighDateTime,
442      "Expected last sync time to be set\n");
443     DeleteFileA(tmpfile);
444     /* Okay, after being deleted, are file URLs still cached? */
445     SetLastError(0xdeadbeef);
446     ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE,
447      CRYPT_CACHE_ONLY_RETRIEVAL, 0, (void **)&cert, NULL, NULL, NULL, NULL);
448     ok(!ret && (GetLastError() == ERROR_FILE_NOT_FOUND ||
449      GetLastError() == ERROR_PATH_NOT_FOUND),
450      "Expected ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND, got %d\n",
451      GetLastError());
452 }
453
454 static const BYTE rootWithKeySignAndCRLSign[] = {
455 0x30,0x82,0x01,0xdf,0x30,0x82,0x01,0x4c,0xa0,0x03,0x02,0x01,0x02,0x02,0x10,
456 0x5b,0xc7,0x0b,0x27,0x99,0xbb,0x2e,0x99,0x47,0x9d,0x45,0x4e,0x7c,0x1a,0xca,
457 0xe8,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x30,0x10,0x31,
458 0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x31,
459 0x30,0x1e,0x17,0x0d,0x30,0x37,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,
460 0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x32,0x33,0x31,0x32,0x33,0x35,0x39,0x35,
461 0x39,0x5a,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,
462 0x43,0x65,0x72,0x74,0x31,0x30,0x81,0x9f,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,
463 0x86,0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x81,0x8d,0x00,0x30,0x81,0x89,
464 0x02,0x81,0x81,0x00,0xad,0x7e,0xca,0xf3,0xe5,0x99,0xc2,0x2a,0xca,0x50,0x82,
465 0x7c,0x2d,0xa4,0x81,0xcd,0x0d,0x0d,0x86,0xd7,0xd8,0xb2,0xde,0xc5,0xc3,0x34,
466 0x9e,0x07,0x78,0x08,0x11,0x12,0x2d,0x21,0x0a,0x09,0x07,0x14,0x03,0x7a,0xe7,
467 0x3b,0x58,0xf1,0xde,0x3e,0x01,0x25,0x93,0xab,0x8f,0xce,0x1f,0xc1,0x33,0x91,
468 0xfe,0x59,0xb9,0x3b,0x9e,0x95,0x12,0x89,0x8e,0xc3,0x4b,0x98,0x1b,0x99,0xc5,
469 0x07,0xe2,0xdf,0x15,0x4c,0x39,0x76,0x06,0xad,0xdb,0x16,0x06,0x49,0xba,0xcd,
470 0x0f,0x07,0xd6,0xea,0x27,0xa6,0xfe,0x3d,0x88,0xe5,0x97,0x45,0x72,0xb6,0x1c,
471 0xc0,0x1c,0xb1,0xa2,0x89,0xe8,0x37,0x9e,0xf6,0x2a,0xcf,0xd5,0x1f,0x2f,0x35,
472 0x5e,0x8f,0x3a,0x9c,0x61,0xb1,0xf1,0x6c,0xff,0x8c,0xb2,0x2f,0x02,0x03,0x01,
473 0x00,0x01,0xa3,0x42,0x30,0x40,0x30,0x0e,0x06,0x03,0x55,0x1d,0x0f,0x01,0x01,
474 0xff,0x04,0x04,0x03,0x02,0x00,0x06,0x30,0x0f,0x06,0x03,0x55,0x1d,0x13,0x01,
475 0x01,0xff,0x04,0x05,0x30,0x03,0x01,0x01,0xff,0x30,0x1d,0x06,0x03,0x55,0x1d,
476 0x0e,0x04,0x16,0x04,0x14,0x14,0x8c,0x16,0xbb,0xbe,0x70,0xa2,0x28,0x89,0xa0,
477 0x58,0xff,0x98,0xbd,0xa8,0x24,0x2b,0x8a,0xe9,0x9a,0x30,0x09,0x06,0x05,0x2b,
478 0x0e,0x03,0x02,0x1d,0x05,0x00,0x03,0x81,0x81,0x00,0x74,0xcb,0x21,0xfd,0x2d,
479 0x25,0xdc,0xa5,0xaa,0xa1,0x26,0xdc,0x8b,0x40,0x11,0x64,0xae,0x5c,0x71,0x3c,
480 0x28,0xbc,0xf9,0xb3,0xcb,0xa5,0x94,0xb2,0x8d,0x4c,0x23,0x2b,0x9b,0xde,0x2c,
481 0x4c,0x30,0x04,0xc6,0x88,0x10,0x2f,0x53,0xfd,0x6c,0x82,0xf1,0x13,0xfb,0xda,
482 0x27,0x75,0x25,0x48,0xe4,0x72,0x09,0x2a,0xee,0xb4,0x1e,0xc9,0x55,0xf5,0xf7,
483 0x82,0x91,0xd8,0x4b,0xe4,0x3a,0xfe,0x97,0x87,0xdf,0xfb,0x15,0x5a,0x12,0x3e,
484 0x12,0xe6,0xad,0x40,0x0b,0xcf,0xee,0x1a,0x44,0xe0,0x83,0xb2,0x67,0x94,0xd4,
485 0x2e,0x7c,0xf2,0x06,0x9d,0xb3,0x3b,0x7e,0x2f,0xda,0x25,0x66,0x7e,0xa7,0x1f,
486 0x45,0xd4,0xf5,0xe3,0xdf,0x2a,0xf1,0x18,0x28,0x20,0xb5,0xf8,0xf5,0x8d,0x7a,
487 0x2e,0x84,0xee };
488 static const BYTE eeCert[] = {
489 0x30,0x82,0x01,0xb9,0x30,0x82,0x01,0x22,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,
490 0x01,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,
491 0x00,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,
492 0x65,0x72,0x74,0x31,0x30,0x1e,0x17,0x0d,0x30,0x37,0x30,0x35,0x30,0x31,0x30,
493 0x30,0x30,0x30,0x30,0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x30,0x30,0x31,0x30,
494 0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,
495 0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x32,0x30,0x81,0x9f,0x30,0x0d,0x06,
496 0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x81,0x8d,
497 0x00,0x30,0x81,0x89,0x02,0x81,0x81,0x00,0xb8,0x52,0xda,0xc5,0x4b,0x3f,0xe5,
498 0x33,0x0e,0x67,0x5f,0x48,0x21,0xdc,0x7e,0xef,0x37,0x33,0xba,0xff,0xb4,0xc6,
499 0xdc,0xb6,0x17,0x8e,0x20,0x55,0x07,0x12,0xd2,0x7b,0x3c,0xce,0x30,0xc5,0xa7,
500 0x48,0x9f,0x6e,0xfe,0xb8,0xbe,0xdb,0x9f,0x9b,0x17,0x60,0x16,0xde,0xc6,0x8b,
501 0x47,0xd1,0x57,0x71,0x3c,0x93,0xfc,0xbd,0xec,0x44,0x32,0x3b,0xb9,0xcf,0x6b,
502 0x05,0x72,0xa7,0x87,0x8e,0x7e,0xd4,0x9a,0x87,0x1c,0x2f,0xb7,0x82,0x40,0xfc,
503 0x6a,0x80,0x83,0x68,0x28,0xce,0x84,0xf4,0x0b,0x2e,0x44,0xcb,0x53,0xac,0x85,
504 0x85,0xb5,0x46,0x36,0x98,0x3c,0x10,0x02,0xaa,0x02,0xbc,0x8b,0xa2,0x23,0xb2,
505 0xd3,0x51,0x9a,0x22,0x4a,0xe3,0xaa,0x4e,0x7c,0xda,0x38,0xcf,0x49,0x98,0x72,
506 0xa3,0x02,0x03,0x01,0x00,0x01,0xa3,0x23,0x30,0x21,0x30,0x1f,0x06,0x03,0x55,
507 0x1d,0x23,0x04,0x18,0x30,0x18,0x80,0x14,0x14,0x8c,0x16,0xbb,0xbe,0x70,0xa2,
508 0x28,0x89,0xa0,0x58,0xff,0x98,0xbd,0xa8,0x24,0x2b,0x8a,0xe9,0x9a,0x30,0x0d,
509 0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x03,0x81,
510 0x81,0x00,0x8a,0x49,0xa9,0x86,0x5e,0xc9,0x33,0x7e,0xfd,0xab,0x64,0x1f,0x6d,
511 0x00,0xd7,0x9b,0xec,0xd1,0x5b,0x38,0xcc,0xd6,0xf3,0xf2,0xb4,0x75,0x70,0x00,
512 0x82,0x9d,0x37,0x58,0xe1,0xcd,0x2c,0x61,0xb3,0x28,0xe7,0x8a,0x00,0xbe,0x6e,
513 0xca,0xe8,0x55,0xd5,0xad,0x3a,0xea,0xaf,0x13,0x20,0x1c,0x44,0xfc,0xb4,0xf9,
514 0x29,0x2b,0xdc,0x8a,0x2d,0x1b,0x27,0x9e,0xb9,0x3b,0x4a,0x71,0x9d,0x47,0x7d,
515 0xf7,0x92,0x6b,0x21,0x7f,0xfa,0x88,0x79,0x94,0x33,0xf6,0xdd,0x92,0x04,0x92,
516 0xd6,0x5e,0x0a,0x74,0xf2,0x85,0xa6,0xd5,0x3c,0x28,0xc0,0x89,0x5d,0xda,0xf3,
517 0xa6,0x01,0xc2,0xe9,0xa3,0xc1,0xb7,0x21,0x08,0xba,0x18,0x07,0x45,0xeb,0x77,
518 0x7d,0xcd,0xc6,0xe7,0x2a,0x7b,0x46,0xd2,0x3d,0xb5 };
519 static const BYTE rootSignedCRL[] = {
520 0x30,0x82,0x01,0x1f,0x30,0x81,0x89,0x02,0x01,0x01,0x30,0x0d,0x06,0x09,0x2a,
521 0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,0x10,0x31,0x0e,0x30,
522 0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x31,0x17,0x0d,
523 0x30,0x37,0x30,0x39,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x17,0x0d,
524 0x30,0x37,0x31,0x32,0x33,0x31,0x32,0x33,0x35,0x39,0x35,0x39,0x5a,0x30,0x14,
525 0x30,0x12,0x02,0x01,0x01,0x17,0x0d,0x30,0x37,0x30,0x39,0x30,0x31,0x30,0x30,
526 0x30,0x30,0x30,0x30,0x5a,0xa0,0x2f,0x30,0x2d,0x30,0x0a,0x06,0x03,0x55,0x1d,
527 0x14,0x04,0x03,0x02,0x01,0x01,0x30,0x1f,0x06,0x03,0x55,0x1d,0x23,0x04,0x18,
528 0x30,0x18,0x80,0x14,0x14,0x8c,0x16,0xbb,0xbe,0x70,0xa2,0x28,0x89,0xa0,0x58,
529 0xff,0x98,0xbd,0xa8,0x24,0x2b,0x8a,0xe9,0x9a,0x30,0x0d,0x06,0x09,0x2a,0x86,
530 0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x03,0x81,0x81,0x00,0xa3,0xcf,
531 0x17,0x5d,0x7a,0x08,0xab,0x11,0x1a,0xbd,0x5c,0xde,0x9a,0x22,0x92,0x38,0xe6,
532 0x96,0xcc,0xb1,0xc5,0x42,0x86,0xa6,0xae,0xad,0xa3,0x1a,0x2b,0xa0,0xb0,0x65,
533 0xaa,0x9c,0xd7,0x2d,0x44,0x8c,0xae,0x61,0xc7,0x30,0x17,0x89,0x84,0x3b,0x4a,
534 0x8f,0x17,0x08,0x06,0x37,0x1c,0xf7,0x2d,0x4e,0x47,0x07,0x61,0x50,0xd9,0x06,
535 0xd1,0x46,0xed,0x0a,0xbb,0xc3,0x9b,0x36,0x0b,0xa7,0x27,0x2f,0x2b,0x55,0xce,
536 0x2a,0xa5,0x60,0xc6,0x53,0x28,0xe8,0xee,0xad,0x0e,0x2b,0xe8,0xd7,0x5f,0xc9,
537 0xa5,0xed,0xf9,0x77,0xb0,0x3c,0x81,0xcf,0xcc,0x49,0xb2,0x1a,0xc3,0xfd,0x34,
538 0xd5,0xbc,0xb0,0xd5,0xa5,0x9c,0x1b,0x72,0xc3,0x0f,0xa3,0xe3,0x3c,0xf0,0xc3,
539 0x91,0xe8,0x93,0x4f,0xd4,0x2f };
540
541 static BOOL (WINAPI *pCertVerifyRevocation)(DWORD, DWORD, DWORD, void **, DWORD,
542  PCERT_REVOCATION_PARA, PCERT_REVOCATION_STATUS);
543
544 /* Wednesday, Oct 1, 2007 */
545 static SYSTEMTIME oct2007 = { 2007, 10, 1, 1, 0, 0, 0, 0 };
546
547 static void test_verifyRevocation(void)
548 {
549     HMODULE hCryptNet = GetModuleHandleA("cryptnet.dll");
550     BOOL ret;
551     CERT_REVOCATION_STATUS status = { sizeof(status), 0 };
552     PCCERT_CONTEXT certs[2];
553     CERT_REVOCATION_PARA revPara = { sizeof(revPara), 0 };
554     FILETIME time;
555
556     pCertVerifyRevocation = (void *)GetProcAddress(hCryptNet,
557      "CertDllVerifyRevocation");
558     if (!pCertVerifyRevocation)
559     {
560         win_skip("no CertDllVerifyRevocation\n");
561         return;
562     }
563     if (0)
564     {
565         /* Crash */
566         ret = pCertVerifyRevocation(0, 0, 0, NULL, 0, NULL, NULL);
567     }
568     SetLastError(0xdeadbeef);
569     ret = pCertVerifyRevocation(0, 0, 0, NULL, 0, NULL, &status);
570     ok(!ret && GetLastError() == E_INVALIDARG,
571      "expected E_INVALIDARG, got %08x\n", GetLastError());
572     SetLastError(0xdeadbeef);
573     ret = pCertVerifyRevocation(X509_ASN_ENCODING, 0, 0, NULL, 0, NULL,
574      &status);
575     ok(!ret && GetLastError() == E_INVALIDARG,
576      "expected E_INVALIDARG, got %08x\n", GetLastError());
577     SetLastError(0xdeadbeef);
578     ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 0, NULL, 0,
579      NULL, &status);
580     ok(!ret && GetLastError() == E_INVALIDARG,
581      "expected E_INVALIDARG, got %08x\n", GetLastError());
582     certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert,
583      sizeof(bigCert));
584     SetLastError(0xdeadbeef);
585     ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE,
586      1, (void **)certs, 0, NULL, &status);
587     ok(!ret && GetLastError() == CRYPT_E_NO_REVOCATION_CHECK,
588      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
589     ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK,
590      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError);
591     ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex);
592     CertFreeCertificateContext(certs[0]);
593     certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING,
594      rootWithKeySignAndCRLSign, sizeof(rootWithKeySignAndCRLSign));
595     certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING,
596      eeCert, sizeof(eeCert));
597     /* The root cert itself can't be checked for revocation */
598     SetLastError(0xdeadbeef);
599     ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE,
600      1, (void **)certs, 0, NULL, &status);
601     ok(!ret && GetLastError() == CRYPT_E_NO_REVOCATION_CHECK,
602      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
603     ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK,
604      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError);
605     ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex);
606     /* Neither can the end cert */
607     SetLastError(0xdeadbeef);
608     ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE,
609      1, (void **)&certs[1], 0, NULL, &status);
610     ok(!ret && GetLastError() == CRYPT_E_NO_REVOCATION_CHECK,
611      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
612     ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK,
613      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError);
614     ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex);
615     /* Both certs together can't, either (they're not CRLs) */
616     SetLastError(0xdeadbeef);
617     ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE,
618      2, (void **)certs, 0, NULL, &status);
619     ok(!ret && GetLastError() == CRYPT_E_NO_REVOCATION_CHECK,
620      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
621     ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK,
622      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError);
623     ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex);
624     /* Now add a CRL to the hCrlStore */
625     revPara.hCrlStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
626      CERT_STORE_CREATE_NEW_FLAG, NULL);
627     CertAddEncodedCRLToStore(revPara.hCrlStore, X509_ASN_ENCODING,
628      rootSignedCRL, sizeof(rootSignedCRL), CERT_STORE_ADD_ALWAYS, NULL);
629     SetLastError(0xdeadbeef);
630     ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE,
631      2, (void **)certs, 0, &revPara, &status);
632     ok(!ret && GetLastError() == CRYPT_E_NO_REVOCATION_CHECK,
633      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
634     ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK,
635      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError);
636     ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex);
637     /* Specifying CERT_VERIFY_REV_CHAIN_FLAG doesn't change things either */
638     SetLastError(0xdeadbeef);
639     ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE,
640      2, (void **)certs, CERT_VERIFY_REV_CHAIN_FLAG, &revPara, &status);
641     ok(!ret && GetLastError() == CRYPT_E_NO_REVOCATION_CHECK,
642      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
643     ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK,
644      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError);
645     ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex);
646     /* Again, specifying the issuer cert: no change */
647     revPara.pIssuerCert = certs[0];
648     SetLastError(0xdeadbeef);
649     ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
650      1, (void **)&certs[1], 0, &revPara, &status);
651     /* Win2k thinks the cert is revoked, and it is, except the CRL is out of
652      * date, hence the revocation status should be unknown.
653      */
654     ok(!ret && (GetLastError() == CRYPT_E_NO_REVOCATION_CHECK ||
655      broken(GetLastError() == CRYPT_E_REVOKED /* Win2k */)),
656      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
657     ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK ||
658      broken(status.dwError == CRYPT_E_REVOKED /* Win2k */),
659      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError);
660     ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex);
661     /* Specifying the time to check: still no change */
662     SystemTimeToFileTime(&oct2007, &time);
663     revPara.pftTimeToUse = &time;
664     ret = pCertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
665      1, (void **)&certs[1], 0, &revPara, &status);
666     ok(!ret, "Expected failure\n");
667     ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK ||
668      broken(GetLastError() == CRYPT_E_REVOKED), /* W2K SP3/SP4 */
669      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
670     ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK ||
671      broken(GetLastError() == CRYPT_E_REVOKED), /* W2K SP3/SP4 */
672      "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError);
673     ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex);
674     CertCloseStore(revPara.hCrlStore, 0);
675     CertFreeCertificateContext(certs[1]);
676     CertFreeCertificateContext(certs[0]);
677 }
678
679 START_TEST(cryptnet)
680 {
681     test_getObjectUrl();
682     test_retrieveObjectByUrl();
683     test_verifyRevocation();
684 }