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
22 #define NONAMELESSUNION
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,
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
)
96 for (i
= 0; i
< got
->cUrl
; i
++)
97 ok(!lstrcmpiW(expected
->rgwszUrl
[i
], got
->rgwszUrl
[i
]),
98 "%d: unexpected URL\n", i
);
103 { 'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',0 };
105 static void test_getObjectUrl(void)
108 DWORD urlArraySize
= 0, infoSize
= 0;
111 SetLastError(0xdeadbeef);
112 ret
= CryptGetObjectUrl(NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
, NULL
);
113 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
114 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
116 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, NULL, 0, NULL, NULL,
118 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, NULL, 0, NULL, NULL,
119 NULL, &infoSize, NULL);
120 ret = CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER, NULL, 0, NULL,
121 &urlArraySize, NULL, &infoSize, NULL);
123 /* A cert with no CRL dist point extension fails.. */
124 cert
= CertCreateCertificateContext(X509_ASN_ENCODING
, bigCert
,
126 SetLastError(0xdeadbeef);
127 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER
, (void *)cert
, 0, NULL
,
128 NULL
, NULL
, NULL
, NULL
);
129 ok(!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
,
130 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
131 CertFreeCertificateContext(cert
);
133 cert
= CertCreateCertificateContext(X509_ASN_ENCODING
,
134 certWithIssuingDistPoint
, sizeof(certWithIssuingDistPoint
));
137 /* This cert has no AIA extension, so expect this to fail */
138 SetLastError(0xdeadbeef);
139 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER
, (void *)cert
, 0,
140 NULL
, NULL
, NULL
, NULL
, NULL
);
141 ok(!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
,
142 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
143 SetLastError(0xdeadbeef);
144 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER
, (void *)cert
,
145 CRYPT_GET_URL_FROM_PROPERTY
, NULL
, NULL
, NULL
, NULL
, NULL
);
146 ok(!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
,
147 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
148 SetLastError(0xdeadbeef);
149 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER
, (void *)cert
,
150 CRYPT_GET_URL_FROM_EXTENSION
, NULL
, NULL
, NULL
, NULL
, NULL
);
151 ok(!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
,
152 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
153 /* It does have an issuing dist point extension, but that's not what
154 * this is looking for (it wants a CRL dist points extension)
156 SetLastError(0xdeadbeef);
157 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
158 (void *)cert
, 0, NULL
, NULL
, NULL
, NULL
, NULL
);
159 ok(!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
,
160 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
161 SetLastError(0xdeadbeef);
162 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
163 (void *)cert
, CRYPT_GET_URL_FROM_PROPERTY
, NULL
, NULL
, NULL
, NULL
,
165 ok(!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
,
166 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
167 SetLastError(0xdeadbeef);
168 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
169 (void *)cert
, CRYPT_GET_URL_FROM_EXTENSION
, NULL
, NULL
, NULL
, NULL
,
171 ok(!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
,
172 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
173 CertFreeCertificateContext(cert
);
175 cert
= CertCreateCertificateContext(X509_ASN_ENCODING
,
176 certWithCRLDistPoint
, sizeof(certWithCRLDistPoint
));
179 PCRYPT_URL_ARRAY urlArray
;
181 /* This cert has no AIA extension, so expect this to fail */
182 SetLastError(0xdeadbeef);
183 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER
, (void *)cert
, 0,
184 NULL
, NULL
, NULL
, NULL
, NULL
);
185 ok(!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
,
186 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
187 SetLastError(0xdeadbeef);
188 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER
, (void *)cert
,
189 CRYPT_GET_URL_FROM_PROPERTY
, NULL
, NULL
, NULL
, NULL
, NULL
);
190 ok(!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
,
191 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
192 SetLastError(0xdeadbeef);
193 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER
, (void *)cert
,
194 CRYPT_GET_URL_FROM_EXTENSION
, NULL
, NULL
, NULL
, NULL
, NULL
);
195 ok(!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
,
196 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
197 /* It does have a CRL dist points extension */
198 SetLastError(0xdeadbeef);
199 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
200 (void *)cert
, 0, NULL
, NULL
, NULL
, NULL
, NULL
);
201 ok(!ret
&& GetLastError() == E_INVALIDARG
,
202 "Expected E_INVALIDARG, got %08x\n", GetLastError());
203 SetLastError(0xdeadbeef);
204 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
205 (void *)cert
, 0, NULL
, NULL
, NULL
, &infoSize
, NULL
);
206 ok(!ret
&& GetLastError() == E_INVALIDARG
,
207 "Expected E_INVALIDARG, got %08x\n", GetLastError());
208 /* Can get it without specifying the location: */
209 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
210 (void *)cert
, 0, NULL
, &urlArraySize
, NULL
, NULL
, NULL
);
211 ok(ret
, "CryptGetObjectUrl failed: %08x\n", GetLastError());
212 urlArray
= HeapAlloc(GetProcessHeap(), 0, urlArraySize
);
215 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
216 (void *)cert
, 0, urlArray
, &urlArraySize
, NULL
, NULL
, NULL
);
217 ok(ret
, "CryptGetObjectUrl failed: %08x\n", GetLastError());
221 CRYPT_URL_ARRAY expectedUrl
= { 1, &pUrl
};
223 compareUrlArray(&expectedUrl
, urlArray
);
225 HeapFree(GetProcessHeap(), 0, urlArray
);
227 /* or by specifying it's an extension: */
228 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
229 (void *)cert
, CRYPT_GET_URL_FROM_EXTENSION
, NULL
, &urlArraySize
, NULL
,
231 ok(ret
, "CryptGetObjectUrl failed: %08x\n", GetLastError());
232 urlArray
= HeapAlloc(GetProcessHeap(), 0, urlArraySize
);
235 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
236 (void *)cert
, CRYPT_GET_URL_FROM_EXTENSION
, urlArray
,
237 &urlArraySize
, NULL
, NULL
, NULL
);
238 ok(ret
, "CryptGetObjectUrl failed: %08x\n", GetLastError());
242 CRYPT_URL_ARRAY expectedUrl
= { 1, &pUrl
};
244 compareUrlArray(&expectedUrl
, urlArray
);
246 HeapFree(GetProcessHeap(), 0, urlArray
);
248 /* but it isn't contained in a property: */
249 SetLastError(0xdeadbeef);
250 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
251 (void *)cert
, CRYPT_GET_URL_FROM_PROPERTY
, NULL
, &urlArraySize
, NULL
,
253 ok(!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
,
254 "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
255 CertFreeCertificateContext(cert
);
257 cert
= CertCreateCertificateContext(X509_ASN_ENCODING
,
258 certWithAIAWithCAIssuers
, sizeof(certWithAIAWithCAIssuers
));
261 PCRYPT_URL_ARRAY urlArray
;
263 /* This has an AIA extension with the CA Issuers set, so expect it
266 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER
,
267 (void *)cert
, 0, NULL
, &urlArraySize
, NULL
, NULL
, NULL
);
268 ok(ret
, "CryptGetObjectUrl failed: %08x\n", GetLastError());
271 urlArray
= HeapAlloc(GetProcessHeap(), 0, urlArraySize
);
274 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_ISSUER
,
275 (void *)cert
, CRYPT_GET_URL_FROM_EXTENSION
, urlArray
,
276 &urlArraySize
, NULL
, NULL
, NULL
);
277 ok(ret
, "CryptGetObjectUrl failed: %08x\n", GetLastError());
281 CRYPT_URL_ARRAY expectedUrl
= { 1, &pUrl
};
283 compareUrlArray(&expectedUrl
, urlArray
);
285 HeapFree(GetProcessHeap(), 0, urlArray
);
288 /* It doesn't have a CRL dist points extension, so this should fail */
289 SetLastError(0xdeadbeef);
290 ret
= CryptGetObjectUrl(URL_OID_CERTIFICATE_CRL_DIST_POINT
,
291 (void *)cert
, 0, NULL
, &urlArraySize
, NULL
, NULL
, NULL
);
292 ok(!ret
&& GetLastError() == CRYPT_E_NOT_FOUND
,
293 "expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
294 CertFreeCertificateContext(cert
);
298 static void make_tmp_file(LPSTR path
)
300 static char curr
[MAX_PATH
] = { 0 };
302 DWORD dwNumberOfBytesWritten
;
306 GetCurrentDirectoryA(MAX_PATH
, curr
);
307 GetTempFileNameA(curr
, "net", 0, temp
);
308 lstrcpyA(path
, temp
);
309 hf
= CreateFileA(path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
310 FILE_ATTRIBUTE_NORMAL
, NULL
);
311 WriteFile(hf
, certWithCRLDistPoint
, sizeof(certWithCRLDistPoint
),
312 &dwNumberOfBytesWritten
, NULL
);
316 static void test_retrieveObjectByUrl(void)
319 char tmpfile
[MAX_PATH
* 2], url
[MAX_PATH
+ 8];
320 CRYPT_BLOB_ARRAY
*pBlobArray
;
324 CRYPT_RETRIEVE_AUX_INFO aux
= { 0 };
327 SetLastError(0xdeadbeef);
328 ret
= CryptRetrieveObjectByUrlA(NULL
, NULL
, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
);
329 ok(!ret
&& (GetLastError() == ERROR_INVALID_PARAMETER
||
330 GetLastError() == E_INVALIDARG
),
331 "got 0x%x/%u (expected ERROR_INVALID_PARAMETER or E_INVALIDARG)\n",
332 GetLastError(), GetLastError());
334 make_tmp_file(tmpfile
);
335 snprintf(url
, sizeof(url
), "file://%s", tmpfile
);
337 pBlobArray
= (CRYPT_BLOB_ARRAY
*)0xdeadbeef;
338 ret
= CryptRetrieveObjectByUrlA(url
, NULL
, 0, 0, (void **)&pBlobArray
,
339 NULL
, NULL
, NULL
, NULL
);
342 /* File URL support was apparently removed in Vista/Windows 2008 */
343 win_skip("File URLs not supported\n");
346 ok(ret
, "CryptRetrieveObjectByUrlA failed: %d\n", GetLastError());
347 ok(pBlobArray
&& pBlobArray
!= (CRYPT_BLOB_ARRAY
*)0xdeadbeef,
348 "Expected a valid pointer\n");
349 if (pBlobArray
&& pBlobArray
!= (CRYPT_BLOB_ARRAY
*)0xdeadbeef)
351 ok(pBlobArray
->cBlob
== 1, "Expected 1 blob, got %d\n",
353 ok(pBlobArray
->rgBlob
[0].cbData
== sizeof(certWithCRLDistPoint
),
354 "Unexpected size %d\n", pBlobArray
->rgBlob
[0].cbData
);
355 CryptMemFree(pBlobArray
);
357 cert
= (PCCERT_CONTEXT
)0xdeadbeef;
358 ret
= CryptRetrieveObjectByUrlA(url
, CONTEXT_OID_CERTIFICATE
, 0, 0,
359 (void **)&cert
, NULL
, NULL
, NULL
, NULL
);
360 ok(ret
, "CryptRetrieveObjectByUrlA failed: %d\n", GetLastError());
361 ok(cert
&& cert
!= (PCCERT_CONTEXT
)0xdeadbeef, "Expected a cert\n");
362 if (cert
&& cert
!= (PCCERT_CONTEXT
)0xdeadbeef)
363 CertFreeCertificateContext(cert
);
364 crl
= (PCCRL_CONTEXT
)0xdeadbeef;
365 SetLastError(0xdeadbeef);
366 ret
= CryptRetrieveObjectByUrlA(url
, CONTEXT_OID_CRL
, 0, 0, (void **)&crl
,
367 NULL
, NULL
, NULL
, NULL
);
368 /* w2k3,XP, newer w2k: CRYPT_E_NO_MATCH, older w2k: CRYPT_E_ASN1_BADTAG */
369 ok(!ret
&& (GetLastError() == CRYPT_E_NO_MATCH
||
370 broken(GetLastError() == CRYPT_E_ASN1_BADTAG
)),
371 "got 0x%x/%u (expected CRYPT_E_NO_MATCH)\n", GetLastError(), GetLastError());
373 /* only newer versions of cryptnet do the cleanup */
374 if(!ret
&& GetLastError() != CRYPT_E_ASN1_BADTAG
&&
375 GetLastError() != OSS_DATA_ERROR
) {
376 ok(crl
== NULL
, "Expected CRL to be NULL\n");
379 if (crl
&& crl
!= (PCCRL_CONTEXT
)0xdeadbeef)
380 CertFreeCRLContext(crl
);
381 store
= (HCERTSTORE
)0xdeadbeef;
382 ret
= CryptRetrieveObjectByUrlA(url
, CONTEXT_OID_CAPI2_ANY
, 0, 0,
383 &store
, NULL
, NULL
, NULL
, NULL
);
384 ok(ret
, "CryptRetrieveObjectByUrlA failed: %d\n", GetLastError());
385 if (store
&& store
!= (HCERTSTORE
)0xdeadbeef)
391 cert
= CertEnumCertificatesInStore(store
, cert
);
395 ok(certs
== 1, "Expected 1 cert, got %d\n", certs
);
396 CertCloseStore(store
, 0);
398 /* Are file URLs cached? */
399 cert
= (PCCERT_CONTEXT
)0xdeadbeef;
400 ret
= CryptRetrieveObjectByUrlA(url
, CONTEXT_OID_CERTIFICATE
,
401 CRYPT_CACHE_ONLY_RETRIEVAL
, 0, (void **)&cert
, NULL
, NULL
, NULL
, NULL
);
402 ok(ret
, "CryptRetrieveObjectByUrlA failed: %08x\n", GetLastError());
403 if (cert
&& cert
!= (PCCERT_CONTEXT
)0xdeadbeef)
404 CertFreeCertificateContext(cert
);
406 cert
= (PCCERT_CONTEXT
)0xdeadbeef;
407 ret
= CryptRetrieveObjectByUrlA(url
, CONTEXT_OID_CERTIFICATE
, 0, 0,
408 (void **)&cert
, NULL
, NULL
, NULL
, &aux
);
409 /* w2k: failure with E_INVALIDARG */
410 ok(ret
|| broken(GetLastError() == E_INVALIDARG
),
411 "got %u with 0x%x/%u (expected '!=0' or '0' with E_INVALIDARG)\n",
412 ret
, GetLastError(), GetLastError());
413 if (cert
&& cert
!= (PCCERT_CONTEXT
)0xdeadbeef)
414 CertFreeCertificateContext(cert
);
416 cert
= (PCCERT_CONTEXT
)0xdeadbeef;
417 aux
.cbSize
= sizeof(aux
);
418 ret
= CryptRetrieveObjectByUrlA(url
, CONTEXT_OID_CERTIFICATE
, 0, 0,
419 (void **)&cert
, NULL
, NULL
, NULL
, &aux
);
420 /* w2k: failure with E_INVALIDARG */
421 ok(ret
|| broken(GetLastError() == E_INVALIDARG
),
422 "got %u with 0x%x/%u (expected '!=0' or '0' with E_INVALIDARG)\n",
423 ret
, GetLastError(), GetLastError());
425 /* no more tests useful */
426 DeleteFileA(tmpfile
);
427 skip("no usable CertificateContext\n");
430 CertFreeCertificateContext(cert
);
432 aux
.pLastSyncTime
= &ft
;
433 ret
= CryptRetrieveObjectByUrlA(url
, CONTEXT_OID_CERTIFICATE
, 0, 0,
434 (void **)&cert
, NULL
, NULL
, NULL
, &aux
);
435 ok(ret
, "CryptRetrieveObjectByUrlA failed: %08x\n", GetLastError());
436 CertFreeCertificateContext(cert
);
437 ok(ft
.dwLowDateTime
|| ft
.dwHighDateTime
,
438 "Expected last sync time to be set\n");
439 DeleteFileA(tmpfile
);
440 /* Okay, after being deleted, are file URLs still cached? */
441 SetLastError(0xdeadbeef);
442 ret
= CryptRetrieveObjectByUrlA(url
, CONTEXT_OID_CERTIFICATE
,
443 CRYPT_CACHE_ONLY_RETRIEVAL
, 0, (void **)&cert
, NULL
, NULL
, NULL
, NULL
);
444 ok(!ret
&& (GetLastError() == ERROR_FILE_NOT_FOUND
||
445 GetLastError() == ERROR_PATH_NOT_FOUND
),
446 "Expected ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND, got %d\n",
450 static const BYTE rootWithKeySignAndCRLSign
[] = {
451 0x30,0x82,0x01,0xdf,0x30,0x82,0x01,0x4c,0xa0,0x03,0x02,0x01,0x02,0x02,0x10,
452 0x5b,0xc7,0x0b,0x27,0x99,0xbb,0x2e,0x99,0x47,0x9d,0x45,0x4e,0x7c,0x1a,0xca,
453 0xe8,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x30,0x10,0x31,
454 0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x31,
455 0x30,0x1e,0x17,0x0d,0x30,0x37,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,
456 0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x32,0x33,0x31,0x32,0x33,0x35,0x39,0x35,
457 0x39,0x5a,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,
458 0x43,0x65,0x72,0x74,0x31,0x30,0x81,0x9f,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,
459 0x86,0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x81,0x8d,0x00,0x30,0x81,0x89,
460 0x02,0x81,0x81,0x00,0xad,0x7e,0xca,0xf3,0xe5,0x99,0xc2,0x2a,0xca,0x50,0x82,
461 0x7c,0x2d,0xa4,0x81,0xcd,0x0d,0x0d,0x86,0xd7,0xd8,0xb2,0xde,0xc5,0xc3,0x34,
462 0x9e,0x07,0x78,0x08,0x11,0x12,0x2d,0x21,0x0a,0x09,0x07,0x14,0x03,0x7a,0xe7,
463 0x3b,0x58,0xf1,0xde,0x3e,0x01,0x25,0x93,0xab,0x8f,0xce,0x1f,0xc1,0x33,0x91,
464 0xfe,0x59,0xb9,0x3b,0x9e,0x95,0x12,0x89,0x8e,0xc3,0x4b,0x98,0x1b,0x99,0xc5,
465 0x07,0xe2,0xdf,0x15,0x4c,0x39,0x76,0x06,0xad,0xdb,0x16,0x06,0x49,0xba,0xcd,
466 0x0f,0x07,0xd6,0xea,0x27,0xa6,0xfe,0x3d,0x88,0xe5,0x97,0x45,0x72,0xb6,0x1c,
467 0xc0,0x1c,0xb1,0xa2,0x89,0xe8,0x37,0x9e,0xf6,0x2a,0xcf,0xd5,0x1f,0x2f,0x35,
468 0x5e,0x8f,0x3a,0x9c,0x61,0xb1,0xf1,0x6c,0xff,0x8c,0xb2,0x2f,0x02,0x03,0x01,
469 0x00,0x01,0xa3,0x42,0x30,0x40,0x30,0x0e,0x06,0x03,0x55,0x1d,0x0f,0x01,0x01,
470 0xff,0x04,0x04,0x03,0x02,0x00,0x06,0x30,0x0f,0x06,0x03,0x55,0x1d,0x13,0x01,
471 0x01,0xff,0x04,0x05,0x30,0x03,0x01,0x01,0xff,0x30,0x1d,0x06,0x03,0x55,0x1d,
472 0x0e,0x04,0x16,0x04,0x14,0x14,0x8c,0x16,0xbb,0xbe,0x70,0xa2,0x28,0x89,0xa0,
473 0x58,0xff,0x98,0xbd,0xa8,0x24,0x2b,0x8a,0xe9,0x9a,0x30,0x09,0x06,0x05,0x2b,
474 0x0e,0x03,0x02,0x1d,0x05,0x00,0x03,0x81,0x81,0x00,0x74,0xcb,0x21,0xfd,0x2d,
475 0x25,0xdc,0xa5,0xaa,0xa1,0x26,0xdc,0x8b,0x40,0x11,0x64,0xae,0x5c,0x71,0x3c,
476 0x28,0xbc,0xf9,0xb3,0xcb,0xa5,0x94,0xb2,0x8d,0x4c,0x23,0x2b,0x9b,0xde,0x2c,
477 0x4c,0x30,0x04,0xc6,0x88,0x10,0x2f,0x53,0xfd,0x6c,0x82,0xf1,0x13,0xfb,0xda,
478 0x27,0x75,0x25,0x48,0xe4,0x72,0x09,0x2a,0xee,0xb4,0x1e,0xc9,0x55,0xf5,0xf7,
479 0x82,0x91,0xd8,0x4b,0xe4,0x3a,0xfe,0x97,0x87,0xdf,0xfb,0x15,0x5a,0x12,0x3e,
480 0x12,0xe6,0xad,0x40,0x0b,0xcf,0xee,0x1a,0x44,0xe0,0x83,0xb2,0x67,0x94,0xd4,
481 0x2e,0x7c,0xf2,0x06,0x9d,0xb3,0x3b,0x7e,0x2f,0xda,0x25,0x66,0x7e,0xa7,0x1f,
482 0x45,0xd4,0xf5,0xe3,0xdf,0x2a,0xf1,0x18,0x28,0x20,0xb5,0xf8,0xf5,0x8d,0x7a,
484 static const BYTE revokedCert
[] = {
485 0x30,0x82,0x01,0xb9,0x30,0x82,0x01,0x22,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,
486 0x01,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,
487 0x00,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,
488 0x65,0x72,0x74,0x31,0x30,0x1e,0x17,0x0d,0x30,0x37,0x30,0x35,0x30,0x31,0x30,
489 0x30,0x30,0x30,0x30,0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x30,0x30,0x31,0x30,
490 0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,
491 0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x32,0x30,0x81,0x9f,0x30,0x0d,0x06,
492 0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x81,0x8d,
493 0x00,0x30,0x81,0x89,0x02,0x81,0x81,0x00,0xb8,0x52,0xda,0xc5,0x4b,0x3f,0xe5,
494 0x33,0x0e,0x67,0x5f,0x48,0x21,0xdc,0x7e,0xef,0x37,0x33,0xba,0xff,0xb4,0xc6,
495 0xdc,0xb6,0x17,0x8e,0x20,0x55,0x07,0x12,0xd2,0x7b,0x3c,0xce,0x30,0xc5,0xa7,
496 0x48,0x9f,0x6e,0xfe,0xb8,0xbe,0xdb,0x9f,0x9b,0x17,0x60,0x16,0xde,0xc6,0x8b,
497 0x47,0xd1,0x57,0x71,0x3c,0x93,0xfc,0xbd,0xec,0x44,0x32,0x3b,0xb9,0xcf,0x6b,
498 0x05,0x72,0xa7,0x87,0x8e,0x7e,0xd4,0x9a,0x87,0x1c,0x2f,0xb7,0x82,0x40,0xfc,
499 0x6a,0x80,0x83,0x68,0x28,0xce,0x84,0xf4,0x0b,0x2e,0x44,0xcb,0x53,0xac,0x85,
500 0x85,0xb5,0x46,0x36,0x98,0x3c,0x10,0x02,0xaa,0x02,0xbc,0x8b,0xa2,0x23,0xb2,
501 0xd3,0x51,0x9a,0x22,0x4a,0xe3,0xaa,0x4e,0x7c,0xda,0x38,0xcf,0x49,0x98,0x72,
502 0xa3,0x02,0x03,0x01,0x00,0x01,0xa3,0x23,0x30,0x21,0x30,0x1f,0x06,0x03,0x55,
503 0x1d,0x23,0x04,0x18,0x30,0x18,0x80,0x14,0x14,0x8c,0x16,0xbb,0xbe,0x70,0xa2,
504 0x28,0x89,0xa0,0x58,0xff,0x98,0xbd,0xa8,0x24,0x2b,0x8a,0xe9,0x9a,0x30,0x0d,
505 0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x03,0x81,
506 0x81,0x00,0x8a,0x49,0xa9,0x86,0x5e,0xc9,0x33,0x7e,0xfd,0xab,0x64,0x1f,0x6d,
507 0x00,0xd7,0x9b,0xec,0xd1,0x5b,0x38,0xcc,0xd6,0xf3,0xf2,0xb4,0x75,0x70,0x00,
508 0x82,0x9d,0x37,0x58,0xe1,0xcd,0x2c,0x61,0xb3,0x28,0xe7,0x8a,0x00,0xbe,0x6e,
509 0xca,0xe8,0x55,0xd5,0xad,0x3a,0xea,0xaf,0x13,0x20,0x1c,0x44,0xfc,0xb4,0xf9,
510 0x29,0x2b,0xdc,0x8a,0x2d,0x1b,0x27,0x9e,0xb9,0x3b,0x4a,0x71,0x9d,0x47,0x7d,
511 0xf7,0x92,0x6b,0x21,0x7f,0xfa,0x88,0x79,0x94,0x33,0xf6,0xdd,0x92,0x04,0x92,
512 0xd6,0x5e,0x0a,0x74,0xf2,0x85,0xa6,0xd5,0x3c,0x28,0xc0,0x89,0x5d,0xda,0xf3,
513 0xa6,0x01,0xc2,0xe9,0xa3,0xc1,0xb7,0x21,0x08,0xba,0x18,0x07,0x45,0xeb,0x77,
514 0x7d,0xcd,0xc6,0xe7,0x2a,0x7b,0x46,0xd2,0x3d,0xb5 };
515 static const BYTE unRevokedCert
[] = {
516 0x30,0x82,0x01,0xa2,0x30,0x82,0x01,0x0d,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,
517 0x02,0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x30,
518 0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,
519 0x74,0x31,0x30,0x1e,0x17,0x0d,0x30,0x37,0x30,0x35,0x30,0x31,0x30,0x30,0x30,
520 0x30,0x30,0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x30,0x30,0x31,0x30,0x30,0x30,
521 0x30,0x30,0x30,0x5a,0x30,0x24,0x31,0x22,0x30,0x0e,0x06,0x03,0x55,0x04,0x03,
522 0x13,0x07,0x66,0x6f,0x6f,0x2e,0x63,0x6f,0x6d,0x30,0x10,0x06,0x03,0x55,0x04,
523 0x03,0x13,0x09,0x2a,0x2e,0x66,0x6f,0x6f,0x2e,0x63,0x6f,0x6d,0x30,0x81,0x9d,
524 0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x03,0x81,
525 0x8d,0x00,0x30,0x81,0x89,0x02,0x81,0x81,0x00,0xb8,0x52,0xda,0xc5,0x4b,0x3f,
526 0xe5,0x33,0x0e,0x67,0x5f,0x48,0x21,0xdc,0x7e,0xef,0x37,0x33,0xba,0xff,0xb4,
527 0xc6,0xdc,0xb6,0x17,0x8e,0x20,0x55,0x07,0x12,0xd2,0x7b,0x3c,0xce,0x30,0xc5,
528 0xa7,0x48,0x9f,0x6e,0xfe,0xb8,0xbe,0xdb,0x9f,0x9b,0x17,0x60,0x16,0xde,0xc6,
529 0x8b,0x47,0xd1,0x57,0x71,0x3c,0x93,0xfc,0xbd,0xec,0x44,0x32,0x3b,0xb9,0xcf,
530 0x6b,0x05,0x72,0xa7,0x87,0x8e,0x7e,0xd4,0x9a,0x87,0x1c,0x2f,0xb7,0x82,0x40,
531 0xfc,0x6a,0x80,0x83,0x68,0x28,0xce,0x84,0xf4,0x0b,0x2e,0x44,0xcb,0x53,0xac,
532 0x85,0x85,0xb5,0x46,0x36,0x98,0x3c,0x10,0x02,0xaa,0x02,0xbc,0x8b,0xa2,0x23,
533 0xb2,0xd3,0x51,0x9a,0x22,0x4a,0xe3,0xaa,0x4e,0x7c,0xda,0x38,0xcf,0x49,0x98,
534 0x72,0xa3,0x02,0x03,0x01,0x00,0x01,0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,
535 0xf7,0x0d,0x01,0x01,0x05,0x03,0x81,0x81,0x00,0x9f,0x11,0x8a,0x0a,0x6e,0xb0,
536 0x73,0xcc,0x48,0xf1,0x92,0xca,0xaf,0x9a,0x3d,0xb9,0xcf,0xbe,0x84,0xd0,0xa8,
537 0x34,0x25,0x27,0x9d,0x28,0x68,0xc5,0x35,0x2b,0x84,0xff,0xdb,0xd0,0x1f,0x0d,
538 0xd7,0xd6,0x8c,0x1b,0x33,0x52,0x7d,0x19,0xd0,0xc2,0xf3,0x63,0xd6,0x55,0x45,
539 0xf9,0x46,0xa0,0xb7,0xb3,0x94,0xbb,0x25,0x9b,0x29,0x76,0x7c,0x11,0xc7,0x7b,
540 0xcc,0xcb,0x99,0x3c,0xae,0xe7,0x16,0xb5,0xa7,0x6a,0x1f,0x75,0x4a,0x58,0x65,
541 0xb1,0x5b,0x91,0x29,0x20,0x81,0x51,0x64,0x05,0x24,0xa5,0x77,0xb7,0x8e,0xc8,
542 0x32,0x0f,0x0d,0x4f,0xf9,0x78,0x0f,0xc4,0xef,0xd6,0x25,0x5a,0xa4,0x9b,0x07,
543 0x17,0xea,0x56,0xe2,0x7b,0x61,0x1c,0x2d,0x40,0x38,0x9a,0x24,0x64,0x4b,0x6d,
545 static const BYTE rootSignedCRLWithBadAKI
[] = {
546 0x30,0x82,0x01,0x1f,0x30,0x81,0x89,0x02,0x01,0x01,0x30,0x0d,0x06,0x09,0x2a,
547 0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,0x10,0x31,0x0e,0x30,
548 0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x31,0x17,0x0d,
549 0x30,0x37,0x30,0x39,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x17,0x0d,
550 0x30,0x37,0x31,0x32,0x33,0x31,0x32,0x33,0x35,0x39,0x35,0x39,0x5a,0x30,0x14,
551 0x30,0x12,0x02,0x01,0x01,0x17,0x0d,0x30,0x37,0x30,0x39,0x30,0x31,0x30,0x30,
552 0x30,0x30,0x30,0x30,0x5a,0xa0,0x2f,0x30,0x2d,0x30,0x0a,0x06,0x03,0x55,0x1d,
553 0x14,0x04,0x03,0x02,0x01,0x01,0x30,0x1f,0x06,0x03,0x55,0x1d,0x23,0x04,0x18,
554 0x30,0x18,0x80,0x14,0x14,0x8c,0x16,0xbb,0xbe,0x70,0xa2,0x28,0x89,0xa0,0x58,
555 0xff,0x98,0xbd,0xa8,0x24,0x2b,0x8a,0xe9,0x9a,0x30,0x0d,0x06,0x09,0x2a,0x86,
556 0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x03,0x81,0x81,0x00,0xa3,0xcf,
557 0x17,0x5d,0x7a,0x08,0xab,0x11,0x1a,0xbd,0x5c,0xde,0x9a,0x22,0x92,0x38,0xe6,
558 0x96,0xcc,0xb1,0xc5,0x42,0x86,0xa6,0xae,0xad,0xa3,0x1a,0x2b,0xa0,0xb0,0x65,
559 0xaa,0x9c,0xd7,0x2d,0x44,0x8c,0xae,0x61,0xc7,0x30,0x17,0x89,0x84,0x3b,0x4a,
560 0x8f,0x17,0x08,0x06,0x37,0x1c,0xf7,0x2d,0x4e,0x47,0x07,0x61,0x50,0xd9,0x06,
561 0xd1,0x46,0xed,0x0a,0xbb,0xc3,0x9b,0x36,0x0b,0xa7,0x27,0x2f,0x2b,0x55,0xce,
562 0x2a,0xa5,0x60,0xc6,0x53,0x28,0xe8,0xee,0xad,0x0e,0x2b,0xe8,0xd7,0x5f,0xc9,
563 0xa5,0xed,0xf9,0x77,0xb0,0x3c,0x81,0xcf,0xcc,0x49,0xb2,0x1a,0xc3,0xfd,0x34,
564 0xd5,0xbc,0xb0,0xd5,0xa5,0x9c,0x1b,0x72,0xc3,0x0f,0xa3,0xe3,0x3c,0xf0,0xc3,
565 0x91,0xe8,0x93,0x4f,0xd4,0x2f };
566 static const BYTE rootSignedCRL
[] = {
567 0x30,0x81,0xe6,0x30,0x53,0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,
568 0x01,0x01,0x05,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,
569 0x05,0x43,0x65,0x72,0x74,0x31,0x17,0x0d,0x30,0x37,0x30,0x35,0x30,0x31,0x30,
570 0x30,0x30,0x30,0x30,0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x32,0x33,0x31,0x32,
571 0x33,0x35,0x39,0x35,0x39,0x5a,0x30,0x14,0x30,0x12,0x02,0x01,0x01,0x17,0x0d,
572 0x30,0x37,0x31,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x0b,
573 0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x03,0x81,0x81,0x00,
574 0x94,0x84,0x0a,0xad,0x63,0xe3,0x05,0xc1,0xd8,0x94,0x44,0xeb,0x30,0x03,0xa1,
575 0xb4,0x7b,0x09,0x2f,0xf6,0xef,0x0f,0xe5,0x58,0x70,0x67,0xac,0x32,0x91,0xc0,
576 0x9d,0xf1,0x2b,0xf4,0xb3,0xcf,0xdd,0x1d,0x74,0x7b,0x6f,0x59,0x36,0x73,0xca,
577 0xcd,0x9c,0xb6,0xd9,0x35,0x39,0x45,0x8d,0xfd,0xf9,0x65,0xf3,0x42,0x2c,0x2c,
578 0xa6,0xfc,0xd2,0x23,0x6c,0x73,0x28,0x21,0x47,0x22,0x88,0x36,0x7d,0xd8,0xf0,
579 0xd0,0xca,0x11,0x20,0x50,0x6b,0x1e,0xb1,0x16,0x16,0xde,0xa6,0xc1,0x8d,0x18,
580 0xf1,0x42,0x22,0x1d,0x95,0x11,0xd7,0xa9,0x8f,0x90,0xe5,0x2f,0x71,0x52,0x47,
581 0xe0,0x45,0xb1,0x5a,0x2c,0x72,0x8a,0x25,0xca,0xd6,0x96,0xa2,0x7b,0x83,0x4c,
582 0xa3,0x24,0x7e,0xdd,0x45,0xa1,0x38,0xf8 };
584 static BOOL (WINAPI
*pCertVerifyRevocation
)(DWORD
, DWORD
, DWORD
, void **, DWORD
,
585 PCERT_REVOCATION_PARA
, PCERT_REVOCATION_STATUS
);
587 /* Wednesday, Oct 1, 2007 */
588 static SYSTEMTIME oct2007
= { 2007, 10, 1, 1, 0, 0, 0, 0 };
589 /* Tuesday, May 1, 2007 */
590 static SYSTEMTIME may2007
= { 2007, 5, 2, 1, 0, 0, 0, 0 };
592 static void test_verifyRevocation(void)
594 HMODULE hCryptNet
= GetModuleHandleA("cryptnet.dll");
596 CERT_REVOCATION_STATUS status
= { sizeof(status
), 0 };
597 PCCERT_CONTEXT certs
[2];
598 CERT_REVOCATION_PARA revPara
= { sizeof(revPara
), 0 };
601 pCertVerifyRevocation
= (void *)GetProcAddress(hCryptNet
,
602 "CertDllVerifyRevocation");
603 if (!pCertVerifyRevocation
)
605 win_skip("no CertDllVerifyRevocation\n");
611 pCertVerifyRevocation(0, 0, 0, NULL
, 0, NULL
, NULL
);
613 SetLastError(0xdeadbeef);
614 ret
= pCertVerifyRevocation(0, 0, 0, NULL
, 0, NULL
, &status
);
615 ok(!ret
&& GetLastError() == E_INVALIDARG
,
616 "expected E_INVALIDARG, got %08x\n", GetLastError());
617 SetLastError(0xdeadbeef);
618 ret
= pCertVerifyRevocation(X509_ASN_ENCODING
, 0, 0, NULL
, 0, NULL
,
620 ok(!ret
&& GetLastError() == E_INVALIDARG
,
621 "expected E_INVALIDARG, got %08x\n", GetLastError());
622 SetLastError(0xdeadbeef);
623 ret
= pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE
, 0, NULL
, 0,
625 ok(!ret
&& GetLastError() == E_INVALIDARG
,
626 "expected E_INVALIDARG, got %08x\n", GetLastError());
627 certs
[0] = CertCreateCertificateContext(X509_ASN_ENCODING
, bigCert
,
629 SetLastError(0xdeadbeef);
630 ret
= pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE
,
631 1, (void **)certs
, 0, NULL
, &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 CertFreeCertificateContext(certs
[0]);
638 certs
[0] = CertCreateCertificateContext(X509_ASN_ENCODING
,
639 rootWithKeySignAndCRLSign
, sizeof(rootWithKeySignAndCRLSign
));
640 certs
[1] = CertCreateCertificateContext(X509_ASN_ENCODING
,
641 revokedCert
, sizeof(revokedCert
));
642 /* The root cert itself can't be checked for revocation */
643 SetLastError(0xdeadbeef);
644 ret
= pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE
,
645 1, (void **)certs
, 0, NULL
, &status
);
646 ok(!ret
&& GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
,
647 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
648 ok(status
.dwError
== CRYPT_E_NO_REVOCATION_CHECK
,
649 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status
.dwError
);
650 ok(status
.dwIndex
== 0, "expected index 0, got %d\n", status
.dwIndex
);
651 /* Neither can the end cert */
652 SetLastError(0xdeadbeef);
653 ret
= pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE
,
654 1, (void **)&certs
[1], 0, NULL
, &status
);
655 ok(!ret
&& GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
,
656 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
657 ok(status
.dwError
== CRYPT_E_NO_REVOCATION_CHECK
,
658 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status
.dwError
);
659 ok(status
.dwIndex
== 0, "expected index 0, got %d\n", status
.dwIndex
);
660 /* Both certs together can't, either (they're not CRLs) */
661 SetLastError(0xdeadbeef);
662 ret
= pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE
,
663 2, (void **)certs
, 0, NULL
, &status
);
664 ok(!ret
&& GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
,
665 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
666 ok(status
.dwError
== CRYPT_E_NO_REVOCATION_CHECK
,
667 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status
.dwError
);
668 ok(status
.dwIndex
== 0, "expected index 0, got %d\n", status
.dwIndex
);
669 /* Now add a CRL to the hCrlStore */
670 revPara
.hCrlStore
= CertOpenStore(CERT_STORE_PROV_MEMORY
, 0, 0,
671 CERT_STORE_CREATE_NEW_FLAG
, NULL
);
672 CertAddEncodedCRLToStore(revPara
.hCrlStore
, X509_ASN_ENCODING
,
673 rootSignedCRLWithBadAKI
, sizeof(rootSignedCRLWithBadAKI
),
674 CERT_STORE_ADD_ALWAYS
, NULL
);
675 SetLastError(0xdeadbeef);
676 ret
= pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE
,
677 2, (void **)certs
, 0, &revPara
, &status
);
678 ok(!ret
&& GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
,
679 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
680 ok(status
.dwError
== CRYPT_E_NO_REVOCATION_CHECK
,
681 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status
.dwError
);
682 ok(status
.dwIndex
== 0, "expected index 0, got %d\n", status
.dwIndex
);
683 /* Specifying CERT_VERIFY_REV_CHAIN_FLAG doesn't change things either */
684 SetLastError(0xdeadbeef);
685 ret
= pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE
,
686 2, (void **)certs
, CERT_VERIFY_REV_CHAIN_FLAG
, &revPara
, &status
);
687 ok(!ret
&& GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
,
688 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
689 ok(status
.dwError
== CRYPT_E_NO_REVOCATION_CHECK
,
690 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status
.dwError
);
691 ok(status
.dwIndex
== 0, "expected index 0, got %d\n", status
.dwIndex
);
692 /* Again, specifying the issuer cert: no change */
693 revPara
.pIssuerCert
= certs
[0];
694 SetLastError(0xdeadbeef);
695 ret
= CertVerifyRevocation(X509_ASN_ENCODING
, CERT_CONTEXT_REVOCATION_TYPE
,
696 1, (void **)&certs
[1], 0, &revPara
, &status
);
697 /* Win2k thinks the cert is revoked, and it is, except the CRL contains a
698 * bad authority key ID extension and can't be matched with the issuer
699 * cert, hence the revocation status should be unknown.
701 ok(!ret
&& (GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
||
702 broken(GetLastError() == CRYPT_E_REVOKED
/* Win2k */)),
703 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
704 ok(status
.dwError
== CRYPT_E_NO_REVOCATION_CHECK
||
705 broken(status
.dwError
== CRYPT_E_REVOKED
/* Win2k */),
706 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status
.dwError
);
707 ok(status
.dwIndex
== 0, "expected index 0, got %d\n", status
.dwIndex
);
708 /* Specifying the time to check: still no change */
709 SystemTimeToFileTime(&oct2007
, &time
);
710 revPara
.pftTimeToUse
= &time
;
711 ret
= pCertVerifyRevocation(X509_ASN_ENCODING
, CERT_CONTEXT_REVOCATION_TYPE
,
712 1, (void **)&certs
[1], 0, &revPara
, &status
);
713 ok(!ret
, "Expected failure\n");
714 ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
||
715 broken(GetLastError() == CRYPT_E_REVOKED
), /* W2K SP3/SP4 */
716 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError());
717 ok(status
.dwError
== CRYPT_E_NO_REVOCATION_CHECK
||
718 broken(GetLastError() == CRYPT_E_REVOKED
), /* W2K SP3/SP4 */
719 "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status
.dwError
);
720 ok(status
.dwIndex
== 0, "expected index 0, got %d\n", status
.dwIndex
);
721 CertCloseStore(revPara
.hCrlStore
, 0);
722 /* Test again with a valid CRL. This time, the cert should be revoked when
723 * the time is after the validity period of the CRL, or considered
724 * "revocation offline" when the checked time precedes the validity
727 revPara
.hCrlStore
= CertOpenStore(CERT_STORE_PROV_MEMORY
, 0, 0,
728 CERT_STORE_CREATE_NEW_FLAG
, NULL
);
729 ret
= CertAddEncodedCRLToStore(revPara
.hCrlStore
, X509_ASN_ENCODING
,
730 rootSignedCRL
, sizeof(rootSignedCRL
), CERT_STORE_ADD_ALWAYS
, NULL
);
731 ok(ret
, "CertAddEncodedCRLToStore failed: %08x\n", GetLastError());
732 revPara
.pftTimeToUse
= NULL
;
733 SetLastError(0xdeadbeef);
734 ret
= CertVerifyRevocation(X509_ASN_ENCODING
, CERT_CONTEXT_REVOCATION_TYPE
,
735 1, (void **)&certs
[1], 0, &revPara
, &status
);
736 ok(!ret
&& (GetLastError() == CRYPT_E_REVOKED
||
737 broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
/* NT4 */)),
738 "expected CRYPT_E_REVOKED, got %08x\n", GetLastError());
739 revPara
.pftTimeToUse
= &time
;
740 SetLastError(0xdeadbeef);
741 ret
= CertVerifyRevocation(X509_ASN_ENCODING
, CERT_CONTEXT_REVOCATION_TYPE
,
742 1, (void **)&certs
[1], 0, &revPara
, &status
);
743 ok(!ret
&& (GetLastError() == CRYPT_E_REVOKED
||
744 broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
/* NT4 */)),
745 "expected CRYPT_E_REVOKED, got %08x\n", GetLastError());
746 SystemTimeToFileTime(&may2007
, &time
);
747 SetLastError(0xdeadbeef);
748 ret
= CertVerifyRevocation(X509_ASN_ENCODING
, CERT_CONTEXT_REVOCATION_TYPE
,
749 1, (void **)&certs
[1], 0, &revPara
, &status
);
750 ok(!ret
&& (GetLastError() == CRYPT_E_REVOCATION_OFFLINE
||
751 broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
/* NT4 */)),
752 "expected CRYPT_E_REVOCATION_OFFLINE, got %08x\n", GetLastError());
753 CertFreeCertificateContext(certs
[1]);
754 /* Test again with a valid CRL and an un-revoked cert. No matter the
755 * time checked, it's reported as revocation offline.
757 certs
[1] = CertCreateCertificateContext(X509_ASN_ENCODING
,
758 unRevokedCert
, sizeof(unRevokedCert
));
759 ok(certs
[1] != NULL
, "CertCreateCertificateContext failed: %08x\n",
761 revPara
.pftTimeToUse
= NULL
;
762 SetLastError(0xdeadbeef);
763 ret
= CertVerifyRevocation(X509_ASN_ENCODING
, CERT_CONTEXT_REVOCATION_TYPE
,
764 1, (void **)&certs
[1], 0, &revPara
, &status
);
765 ok(!ret
&& (GetLastError() == CRYPT_E_REVOCATION_OFFLINE
||
766 broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
/* NT4 */)),
767 "expected CRYPT_E_REVOCATION_OFFLINE, got %08x\n", GetLastError());
768 revPara
.pftTimeToUse
= &time
;
769 SetLastError(0xdeadbeef);
770 ret
= CertVerifyRevocation(X509_ASN_ENCODING
, CERT_CONTEXT_REVOCATION_TYPE
,
771 1, (void **)&certs
[1], 0, &revPara
, &status
);
772 ok(!ret
&& (GetLastError() == CRYPT_E_REVOCATION_OFFLINE
||
773 broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
/* NT4 */)),
774 "expected CRYPT_E_REVOCATION_OFFLINE, got %08x\n", GetLastError());
775 SystemTimeToFileTime(&may2007
, &time
);
776 SetLastError(0xdeadbeef);
777 ret
= CertVerifyRevocation(X509_ASN_ENCODING
, CERT_CONTEXT_REVOCATION_TYPE
,
778 1, (void **)&certs
[1], 0, &revPara
, &status
);
779 ok(!ret
&& (GetLastError() == CRYPT_E_REVOCATION_OFFLINE
||
780 broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK
/* NT4 */)),
781 "expected CRYPT_E_REVOCATION_OFFLINE, got %08x\n", GetLastError());
782 CertCloseStore(revPara
.hCrlStore
, 0);
783 CertFreeCertificateContext(certs
[1]);
784 CertFreeCertificateContext(certs
[0]);
790 test_retrieveObjectByUrl();
791 test_verifyRevocation();