Artifactspublic-v0

curl

master
ply4 git calls45 ms295 KiB3 cachedprotocol v2
834 lines28 KiBRaw
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Marc Hoersken, <info@marc-hoersken.de>
9 * Copyright (C) Mark Salisbury, <mark.salisbury@hp.com>
10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11 *
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at https://curl.se/docs/copyright.html.
15 *
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 * SPDX-License-Identifier: curl
24 *
25 ***************************************************************************/
26/*
27 * Source file for Schannel-specific certificate verification. This code should
28 * only be invoked by code in schannel.c.
29 */
30#include "curl_setup.h"
32#ifdef USE_SCHANNEL
34#ifndef USE_WINDOWS_SSPI
35#error "cannot compile Schannel support without SSPI."
36#endif
38#include "vtls/schannel.h"
39#include "vtls/schannel_int.h"
41#include "vtls/hostcheck.h"
42#include "vtls/vtls.h"
43#include "vtls/vtls_int.h"
44#include "curl_trc.h"
45#include "strerror.h"
46#include "curlx/win32-fopen.h"
47#include "curlx/inet_pton.h"
48#include "curlx/multibyte.h"
49#include "curlx/version_win32.h"
50#include "curlx/winapi.h"
52#define BACKEND ((struct schannel_ssl_backend_data *)connssl->backend)
54#define MAX_CAFILE_SIZE (1024 * 1024) /* 1 MiB */
55#define BEGIN_CERT "-----BEGIN CERTIFICATE-----"
56#define END_CERT "\n-----END CERTIFICATE-----"
58struct cert_chain_engine_config_win8 {
59 DWORD cbSize;
60 HCERTSTORE hRestrictedRoot;
61 HCERTSTORE hRestrictedTrust;
62 HCERTSTORE hRestrictedOther;
63 DWORD cAdditionalStore;
64 HCERTSTORE *rghAdditionalStore;
65 DWORD dwFlags;
66 DWORD dwUrlRetrievalTimeout;
67 DWORD MaximumCachedCertificates;
68 DWORD CycleDetectionModulus;
69 HCERTSTORE hExclusiveRoot;
70 HCERTSTORE hExclusiveTrustedPeople;
71 DWORD dwExclusiveFlags;
72};
74/* Offered by mingw-w64 v4+, MS SDK 8.0/~VS2012+ */
75#ifndef CERT_CHAIN_EXCLUSIVE_ENABLE_CA_FLAG
76#define CERT_CHAIN_EXCLUSIVE_ENABLE_CA_FLAG 0x00000001
77#endif
79/* Legacy structure to supply size to Win7 clients */
80struct cert_chain_engine_config_win7 {
81 DWORD cbSize;
82 HCERTSTORE hRestrictedRoot;
83 HCERTSTORE hRestrictedTrust;
84 HCERTSTORE hRestrictedOther;
85 DWORD cAdditionalStore;
86 HCERTSTORE *rghAdditionalStore;
87 DWORD dwFlags;
88 DWORD dwUrlRetrievalTimeout;
89 DWORD MaximumCachedCertificates;
90 DWORD CycleDetectionModulus;
91 HCERTSTORE hExclusiveRoot;
92 HCERTSTORE hExclusiveTrustedPeople;
93};
95/* Search the substring needle,needlelen into string haystack,haystacklen
96 * Strings do not need to be terminated by a '\0'.
97 * Similar of macOS/Linux memmem (not available on Visual Studio).
98 * Return position of beginning of first occurrence or NULL if not found
99 */
100static const char *c_memmem(const void *haystack, size_t haystacklen,
101 const void *needle, size_t needlelen)
103 const char *p;
104 char first;
105 const char *str_limit = (const char *)haystack + haystacklen;
106 if(!needlelen || needlelen > haystacklen)
107 return NULL;
108 first = *(const char *)needle;
109 for(p = (const char *)haystack; p <= (str_limit - needlelen); p++)
110 if((*p == first) && !memcmp(p, needle, needlelen))
111 return p;
113 return NULL;
116static CURLcode add_certs_data_to_store(HCERTSTORE trust_store,
117 const char *ca_buffer,
118 size_t ca_buffer_size,
119 const char *ca_file_text,
120 struct Curl_easy *data)
122 const size_t begin_cert_len = CURL_CSTRLEN(BEGIN_CERT);
123 const size_t end_cert_len = CURL_CSTRLEN(END_CERT);
124 CURLcode result = CURLE_OK;
125 int num_certs = 0;
126 bool more_certs = 1;
127 const char *current_ca_file_ptr = ca_buffer;
128 const char *ca_buffer_limit = ca_buffer + ca_buffer_size;
130 while(more_certs && (current_ca_file_ptr < ca_buffer_limit)) {
131 const char *begin_cert_ptr = c_memmem(current_ca_file_ptr,
132 ca_buffer_limit -
133 current_ca_file_ptr - 1,
134 BEGIN_CERT,
135 begin_cert_len);
136 if(!begin_cert_ptr || !ISNEWLINE(begin_cert_ptr[begin_cert_len])) {
137 more_certs = 0;
138 }
139 else {
140 const char *end_cert_ptr = c_memmem(begin_cert_ptr,
141 ca_buffer_limit-begin_cert_ptr,
142 END_CERT,
143 end_cert_len);
144 if(!end_cert_ptr) {
145 failf(data,
146 "schannel: CA file '%s' is not correctly formatted",
147 ca_file_text);
148 result = CURLE_SSL_CACERT_BADFILE;
149 more_certs = 0;
150 }
151 else {
152 CERT_BLOB cert_blob;
153 const CERT_CONTEXT *cert_context = NULL;
154 BOOL add_cert_result = FALSE;
155 DWORD cert_size =
156 (DWORD)((end_cert_ptr + end_cert_len) - begin_cert_ptr);
158 cert_blob.pbData = (BYTE *)CURL_UNCONST(begin_cert_ptr);
159 cert_blob.cbData = cert_size;
160 /* Caution: CryptQueryObject() is deprecated */
161 if(!CryptQueryObject(CERT_QUERY_OBJECT_BLOB,
162 &cert_blob,
163 CERT_QUERY_CONTENT_FLAG_CERT,
164 CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED,
165 0,
166 NULL,
167 NULL,
168 NULL,
169 NULL,
170 NULL,
171 (const void **)&cert_context)) {
172 char buffer[WINAPI_ERROR_LEN];
173 failf(data,
174 "schannel: failed to extract certificate from CA file "
175 "'%s': %s",
176 ca_file_text,
177 curlx_winapi_strerror(GetLastError(), buffer, sizeof(buffer)));
178 result = CURLE_SSL_CACERT_BADFILE;
179 more_certs = 0;
180 }
181 else {
182 current_ca_file_ptr = begin_cert_ptr + cert_size;
184 add_cert_result =
185 CertAddCertificateContextToStore(trust_store,
186 cert_context,
187 CERT_STORE_ADD_ALWAYS,
188 NULL);
189 if(!add_cert_result) {
190 char buffer[WINAPI_ERROR_LEN];
191 failf(data,
192 "schannel: failed to add certificate from CA file '%s' "
193 "to certificate store: %s",
194 ca_file_text,
195 curlx_winapi_strerror(GetLastError(), buffer,
196 sizeof(buffer)));
197 result = CURLE_SSL_CACERT_BADFILE;
198 more_certs = 0;
199 }
200 else {
201 num_certs++;
202 }
204 CertFreeCertificateContext(cert_context);
205 }
206 }
207 }
208 }
210 if(result == CURLE_OK) {
211 if(!num_certs) {
212 infof(data, "schannel: did not add any certificates from CA file '%s'",
213 ca_file_text);
214 }
215 else {
216 infof(data, "schannel: added %d certificate(s) from CA file '%s'",
217 num_certs, ca_file_text);
218 }
219 }
220 return result;
223static CURLcode add_certs_file_to_store(HCERTSTORE trust_store,
224 const char *ca_file,
225 struct Curl_easy *data)
227 CURLcode result;
228 FILE *ca_file_handle;
229 char *ca_file_buffer = NULL;
230 long ca_file_bufsize = 0;
231 long total_bytes_read = 0;
233 /*
234 * Read the CA file completely into memory before parsing it. This
235 * optimizes for the common case where the CA file is relatively
236 * small ( < 1 MiB ).
237 */
238 ca_file_handle = curlx_fopen(ca_file, "rb");
239 if(!ca_file_handle) {
240 failf(data, "schannel: failed to open CA file '%s'", ca_file);
241 result = CURLE_SSL_CACERT_BADFILE;
242 goto cleanup;
243 }
245 if(curlx_fseek(ca_file_handle, 0, SEEK_END)) {
246 failf(data, "schannel: failed seeking to end of CA file '%s'", ca_file);
247 result = CURLE_SSL_CACERT_BADFILE;
248 goto cleanup;
249 }
251 ca_file_bufsize = ftell(ca_file_handle);
253 if(curlx_fseek(ca_file_handle, 0, SEEK_SET)) {
254 failf(data, "schannel: failed seeking to beginning of CA file '%s'",
255 ca_file);
256 result = CURLE_SSL_CACERT_BADFILE;
257 goto cleanup;
258 }
260 if(ca_file_bufsize < 0) {
261 failf(data, "schannel: failed to get length of CA file '%s'", ca_file);
262 result = CURLE_SSL_CACERT_BADFILE;
263 goto cleanup;
264 }
266 if(ca_file_bufsize > MAX_CAFILE_SIZE) {
267 failf(data, "schannel: CA file exceeds max size of %d bytes",
268 MAX_CAFILE_SIZE);
269 result = CURLE_SSL_CACERT_BADFILE;
270 goto cleanup;
271 }
273 ca_file_buffer = curlx_malloc(ca_file_bufsize + 1);
274 if(!ca_file_buffer) {
275 result = CURLE_OUT_OF_MEMORY;
276 goto cleanup;
277 }
279 while(total_bytes_read < ca_file_bufsize) {
280 size_t nread = fread(ca_file_buffer + total_bytes_read, 1,
281 ca_file_bufsize - total_bytes_read, ca_file_handle);
283 if(ferror(ca_file_handle)) {
284 failf(data, "schannel: failed to read from CA file '%s'", ca_file);
285 result = CURLE_SSL_CACERT_BADFILE;
286 goto cleanup;
287 }
289 if(nread == 0) {
290 /* Premature EOF -- adjust the bufsize to the new value */
291 ca_file_bufsize = total_bytes_read;
292 }
293 else {
294 total_bytes_read += (long)nread;
295 }
296 }
298 /* null-terminate the buffer */
299 ca_file_buffer[ca_file_bufsize] = '\0';
301 result = add_certs_data_to_store(trust_store,
302 ca_file_buffer, ca_file_bufsize,
303 ca_file,
304 data);
306cleanup:
307 if(ca_file_handle) {
308 curlx_fclose(ca_file_handle);
309 }
310 curlx_safefree(ca_file_buffer);
312 return result;
315/*
316 * Returns the number of characters necessary to populate all the host_names.
317 * If host_names is not NULL, populate it with all the hostnames. Each string
318 * in the host_names is null-terminated and the last string is double
319 * null-terminated. If no DNS names are found, a single null-terminated empty
320 * string is returned.
321 */
322static DWORD cert_get_name_string(struct Curl_easy *data,
323 CERT_CONTEXT *cert_context,
324 LPTSTR host_names,
325 DWORD length,
326 PCERT_ALT_NAME_INFO alt_name_info,
327 BOOL Win8_compat)
329 DWORD actual_length = 0;
330 BOOL compute_content = FALSE;
331 LPTSTR current_pos = NULL;
332 DWORD i;
334 /* CERT_NAME_SEARCH_ALL_NAMES_FLAG is available from Windows 8 onwards. */
335 if(Win8_compat) {
336/* Offered by mingw-w64 v4+, MS SDK 8.0/~VS2012+ */
337#ifndef CERT_NAME_SEARCH_ALL_NAMES_FLAG
338#define CERT_NAME_SEARCH_ALL_NAMES_FLAG 0x2
339#endif
340 /* CertGetNameString provides the 8-bit character string without
341 * any decoding */
342 DWORD name_flags =
343 CERT_NAME_DISABLE_IE4_UTF8_FLAG | CERT_NAME_SEARCH_ALL_NAMES_FLAG;
344 actual_length = CertGetNameString(cert_context,
345 CERT_NAME_DNS_TYPE,
346 name_flags,
347 NULL,
348 host_names,
349 length);
350 return actual_length;
351 }
353 if(!alt_name_info)
354 return 0;
356 compute_content = host_names && length != 0;
358 /* Initialize default return values. */
359 actual_length = 1;
360 if(compute_content) {
361 *host_names = '\0';
362 }
364 current_pos = host_names;
366 /* Iterate over the alternate names and populate host_names. */
367 for(i = 0; i < alt_name_info->cAltEntry; i++) {
368 const CERT_ALT_NAME_ENTRY *entry = &alt_name_info->rgAltEntry[i];
369 wchar_t *dns_w = NULL;
370 size_t current_length = 0;
372 if(entry->dwAltNameChoice != CERT_ALT_NAME_DNS_NAME) {
373 continue;
374 }
375 if(!entry->pwszDNSName) {
376 infof(data, "schannel: Empty DNS name.");
377 continue;
378 }
379 current_length = wcslen(entry->pwszDNSName) + 1;
380 if(!compute_content) {
381 actual_length += (DWORD)current_length;
382 continue;
383 }
384 /* Sanity check to prevent buffer overrun. */
385 if((actual_length + current_length) > length) {
386 failf(data, "schannel: Not enough memory to list all hostnames.");
387 break;
388 }
389 dns_w = entry->pwszDNSName;
390 /* pwszDNSName is in ia5 string format and hence does not contain any
391 * non-ASCII characters. */
392 while(*dns_w != '\0') {
393 *current_pos++ = (TCHAR)(*dns_w++);
394 }
395 *current_pos++ = '\0';
396 actual_length += (DWORD)current_length;
397 }
398 if(compute_content) {
399 /* Last string has double null-terminator. */
400 *current_pos = '\0';
401 }
402 return actual_length;
405/*
406 * Returns TRUE if the hostname is a numeric IPv4/IPv6 Address,
407 * and populates the buffer with IPv4/IPv6 info.
408 */
410static bool get_num_host_info(struct num_ip_data *ip_blob, LPCSTR hostname)
412 struct in_addr ia;
413 int res = curlx_inet_pton(AF_INET, hostname, &ia);
414 if(res) {
415 ip_blob->size = sizeof(struct in_addr);
416 memcpy(&ip_blob->bData.ia, &ia, sizeof(struct in_addr));
417 return TRUE;
418 }
419 else {
420 struct in6_addr ia6;
421 res = curlx_inet_pton(AF_INET6, hostname, &ia6);
422 if(res) {
423 ip_blob->size = sizeof(struct in6_addr);
424 memcpy(&ip_blob->bData.ia6, &ia6, sizeof(struct in6_addr));
425 return TRUE;
426 }
427 }
428 return FALSE;
431static bool get_alt_name_info(struct Curl_easy *data,
432 PCCERT_CONTEXT ctx,
433 PCERT_ALT_NAME_INFO *alt_name_info,
434 LPDWORD alt_name_info_size)
436 PCERT_INFO cert_info = NULL;
437 PCERT_EXTENSION extension = NULL;
438 CRYPT_DECODE_PARA decode_para = { sizeof(CRYPT_DECODE_PARA), NULL, NULL };
440 if(!ctx) {
441 failf(data, "schannel: Null certificate context.");
442 return FALSE;
443 }
445 cert_info = ctx->pCertInfo;
446 if(!cert_info) {
447 failf(data, "schannel: Null certificate info.");
448 return FALSE;
449 }
451 extension = CertFindExtension(szOID_SUBJECT_ALT_NAME2,
452 cert_info->cExtension,
453 cert_info->rgExtension);
454 if(!extension) {
455 failf(data, "schannel: CertFindExtension() returned no extension.");
456 return FALSE;
457 }
459 if(!CryptDecodeObjectEx(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
460 szOID_SUBJECT_ALT_NAME2,
461 extension->Value.pbData,
462 extension->Value.cbData,
463 CRYPT_DECODE_ALLOC_FLAG | CRYPT_DECODE_NOCOPY_FLAG,
464 &decode_para,
465 alt_name_info,
466 alt_name_info_size)) {
467 failf(data, "schannel: CryptDecodeObjectEx() returned no alternate name "
468 "information.");
469 return FALSE;
470 }
471 return TRUE;
474/* Verify the server's hostname */
475CURLcode Curl_verify_host(struct Curl_cfilter *cf, struct Curl_easy *data)
477 CURLcode result = CURLE_PEER_FAILED_VERIFICATION;
478 struct ssl_connect_data *connssl = cf->ctx;
479 CERT_CONTEXT *pCertContextServer = NULL;
480 SECURITY_STATUS sspi_status;
481 TCHAR *cert_hostname_buff = NULL;
482 size_t cert_hostname_buff_index = 0;
483 const char *conn_hostname = connssl->peer.origin->hostname;
484 size_t hostlen = strlen(conn_hostname);
485 DWORD len = 0;
486 DWORD actual_len = 0;
487 PCERT_ALT_NAME_INFO alt_name_info = NULL;
488 DWORD alt_name_info_size = 0;
489 struct num_ip_data ip_blob = { 0 };
490 bool Win8_compat;
491 struct num_ip_data *p = &ip_blob;
492 DWORD i;
494 sspi_status =
495 Curl_pSecFn->QueryContextAttributes(&BACKEND->ctxt->ctxt_handle,
496 SECPKG_ATTR_REMOTE_CERT_CONTEXT,
497 &pCertContextServer);
499 if((sspi_status != SEC_E_OK) || !pCertContextServer) {
500 char buffer[WINAPI_ERROR_LEN];
501 failf(data, "schannel: Failed to read remote certificate context: %s",
502 Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
503 goto cleanup;
504 }
506 Win8_compat = curlx_verify_windows_version(6, 2, 0, PLATFORM_WINNT,
507 VERSION_GREATER_THAN_EQUAL);
508 if(get_num_host_info(p, conn_hostname) || !Win8_compat) {
509 if(!get_alt_name_info(data, pCertContextServer,
510 &alt_name_info, &alt_name_info_size)) {
511 goto cleanup;
512 }
513 }
515 if(p->size && alt_name_info) {
516 for(i = 0; i < alt_name_info->cAltEntry; ++i) {
517 PCERT_ALT_NAME_ENTRY entry = &alt_name_info->rgAltEntry[i];
518 if(entry->dwAltNameChoice == CERT_ALT_NAME_IP_ADDRESS) {
519 if(entry->IPAddress.cbData == p->size) {
520 if(!memcmp(entry->IPAddress.pbData, &p->bData,
521 entry->IPAddress.cbData)) {
522 result = CURLE_OK;
523 infof(data,
524 "schannel: connection hostname (%s) matched cert's IP address!",
525 conn_hostname);
526 break;
527 }
528 }
529 }
530 }
531 }
532 else {
533 /* Determine the size of the string needed for the cert hostname */
534 len = cert_get_name_string(data, pCertContextServer,
535 NULL, 0, alt_name_info, Win8_compat);
536 if(len == 0) {
537 failf(data,
538 "schannel: CertGetNameString() returned no "
539 "certificate name information");
540 goto cleanup;
541 }
543 /* CertGetNameString guarantees that the returned name does not contain
544 * embedded NUL bytes. This appears to be undocumented behavior.
545 */
546 cert_hostname_buff = curlx_malloc(len * sizeof(TCHAR));
547 if(!cert_hostname_buff) {
548 result = CURLE_OUT_OF_MEMORY;
549 goto cleanup;
550 }
551 actual_len = cert_get_name_string(data, pCertContextServer,
552 (LPTSTR)cert_hostname_buff, len,
553 alt_name_info, Win8_compat);
555 /* Sanity check */
556 if(actual_len != len) {
557 failf(data,
558 "schannel: CertGetNameString() returned certificate "
559 "name information of unexpected size");
560 goto cleanup;
561 }
563 /* cert_hostname_buff contains all DNS names, where each name is
564 * null-terminated and the last DNS name is double null-terminated. Due to
565 * this encoding, use the length of the buffer to iterate over all names.
566 */
567 while(cert_hostname_buff_index < len &&
568 cert_hostname_buff[cert_hostname_buff_index] != TEXT('\0') &&
569 result == CURLE_PEER_FAILED_VERIFICATION) {
570 char *cert_hostname;
572 /* Comparing the cert name and the connection hostname encoded as UTF-8
573 * is acceptable since both values are assumed to use ASCII
574 * (or some equivalent) encoding
575 */
576 cert_hostname = curlx_convert_tchar_to_UTF8(
577 &cert_hostname_buff[cert_hostname_buff_index]);
578 if(!cert_hostname) {
579 result = CURLE_OUT_OF_MEMORY;
580 }
581 else {
582 if(Curl_cert_hostcheck(cert_hostname, strlen(cert_hostname),
583 conn_hostname, hostlen)) {
584 infof(data, "schannel: connection hostname (%s) validated "
585 "against certificate name (%s)",
586 conn_hostname, cert_hostname);
587 result = CURLE_OK;
588 }
589 else {
590 size_t cert_hostname_len;
592 infof(data,
593 "schannel: connection hostname (%s) did not match "
594 "against certificate name (%s)",
595 conn_hostname, cert_hostname);
597 cert_hostname_len =
598 _tcslen(&cert_hostname_buff[cert_hostname_buff_index]);
600 /* Move on to next cert name */
601 cert_hostname_buff_index += cert_hostname_len + 1;
603 result = CURLE_PEER_FAILED_VERIFICATION;
604 }
605 curlx_free(cert_hostname);
606 }
607 }
609 if(result == CURLE_PEER_FAILED_VERIFICATION) {
610 failf(data,
611 "schannel: CertGetNameString() failed to match "
612 "connection hostname (%s) against server certificate names",
613 conn_hostname);
614 }
615 else if(result != CURLE_OK)
616 failf(data, "schannel: server certificate name verification failed");
617 }
619cleanup:
620 LocalFree(alt_name_info);
621 curlx_safefree(cert_hostname_buff);
623 if(pCertContextServer)
624 CertFreeCertificateContext(pCertContextServer);
626 return result;
629/* Verify the server's certificate and hostname */
630CURLcode Curl_verify_certificate(struct Curl_cfilter *cf,
631 struct Curl_easy *data)
633 struct ssl_connect_data *connssl = cf->ctx;
634 struct ssl_filter_config *conn_config = Curl_ssl_cf_get_filter_config(cf);
635 SECURITY_STATUS sspi_status;
636 CURLcode result = CURLE_OK;
637 CERT_CONTEXT *pCertContextServer = NULL;
638 const CERT_CHAIN_CONTEXT *pChainContext = NULL;
639 HCERTCHAINENGINE cert_chain_engine = NULL;
640 HCERTSTORE trust_store = NULL;
641 HCERTSTORE own_trust_store = NULL;
643 DEBUGASSERT(BACKEND);
645 sspi_status =
646 Curl_pSecFn->QueryContextAttributes(&BACKEND->ctxt->ctxt_handle,
647 SECPKG_ATTR_REMOTE_CERT_CONTEXT,
648 &pCertContextServer);
650 if((sspi_status != SEC_E_OK) || !pCertContextServer) {
651 char buffer[WINAPI_ERROR_LEN];
652 failf(data, "schannel: Failed to read remote certificate context: %s",
653 Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
654 result = CURLE_PEER_FAILED_VERIFICATION;
655 }
657 if(result == CURLE_OK &&
658 (conn_config->CAfile || conn_config->ca_info_blob) &&
659 BACKEND->use_manual_cred_validation) {
660 /*
661 * Create a chain engine that uses the certificates in the CA file as
662 * trusted certificates. This is only supported on Windows 7+.
663 */
665 if(curlx_verify_windows_version(6, 1, 0, PLATFORM_WINNT,
666 VERSION_LESS_THAN)) {
667 failf(data, "schannel: this version of Windows is too old to support "
668 "certificate verification via CA bundle file.");
669 result = CURLE_SSL_CACERT_BADFILE;
670 }
671 else {
672 /* try cache */
673 trust_store = Curl_schannel_get_cached_cert_store(cf, data);
675 if(trust_store) {
676 infof(data, "schannel: reusing certificate store from cache");
677 }
678 else {
679 /* Open the certificate store */
680 trust_store = CertOpenStore(CERT_STORE_PROV_MEMORY,
681 0,
682 (HCRYPTPROV)NULL,
683 CERT_STORE_CREATE_NEW_FLAG,
684 NULL);
685 if(!trust_store) {
686 char buffer[WINAPI_ERROR_LEN];
687 failf(data, "schannel: failed to create certificate store: %s",
688 curlx_winapi_strerror(GetLastError(), buffer, sizeof(buffer)));
689 result = CURLE_SSL_CACERT_BADFILE;
690 }
691 else {
692 const struct curl_blob *ca_info_blob = conn_config->ca_info_blob;
693 own_trust_store = trust_store;
695 if(ca_info_blob) {
696 result = add_certs_data_to_store(trust_store,
697 (const char *)ca_info_blob->data,
698 ca_info_blob->len,
699 "(memory blob)",
700 data);
701 }
702 else {
703 result = add_certs_file_to_store(trust_store,
704 conn_config->CAfile,
705 data);
706 }
707 if(result == CURLE_OK) {
708 if(Curl_schannel_set_cached_cert_store(cf, data, trust_store)) {
709 own_trust_store = NULL;
710 }
711 }
712 }
713 }
714 }
716 if(result == CURLE_OK) {
717 struct cert_chain_engine_config_win8 engine_config;
718 BOOL create_engine_result;
720 memset(&engine_config, 0, sizeof(engine_config));
721 engine_config.hExclusiveRoot = trust_store;
723 /* Win8/Server2012 allows us to match partial chains */
724 if(curlx_verify_windows_version(6, 2, 0, PLATFORM_WINNT,
725 VERSION_GREATER_THAN_EQUAL) &&
726 !conn_config->no_partialchain) {
727 engine_config.cbSize = sizeof(engine_config);
728 engine_config.dwExclusiveFlags = CERT_CHAIN_EXCLUSIVE_ENABLE_CA_FLAG;
729 }
730 else
731 engine_config.cbSize = sizeof(struct cert_chain_engine_config_win7);
733 /* CertCreateCertificateChainEngine checks the expected size of the
734 * CERT_CHAIN_ENGINE_CONFIG structure and fail if the specified size
735 * does not match the expected size. When this occurs, it indicates that
736 * CAINFO is not supported on the version of Windows in use.
737 */
738 create_engine_result =
739 CertCreateCertificateChainEngine(
740 (CERT_CHAIN_ENGINE_CONFIG *)&engine_config, &cert_chain_engine);
741 if(!create_engine_result) {
742 char buffer[WINAPI_ERROR_LEN];
743 failf(data,
744 "schannel: failed to create certificate chain engine: %s",
745 curlx_winapi_strerror(GetLastError(), buffer, sizeof(buffer)));
746 result = CURLE_SSL_CACERT_BADFILE;
747 }
748 }
749 }
751 if(result == CURLE_OK) {
752 CERT_CHAIN_PARA ChainPara;
753 LPSTR serverAuthOID = CURL_UNCONST(szOID_PKIX_KP_SERVER_AUTH);
755 memset(&ChainPara, 0, sizeof(ChainPara));
756 ChainPara.cbSize = sizeof(ChainPara);
757 ChainPara.RequestedUsage.dwType = USAGE_MATCH_TYPE_AND;
758 ChainPara.RequestedUsage.Usage.cUsageIdentifier = 1;
759 ChainPara.RequestedUsage.Usage.rgpszUsageIdentifier = &serverAuthOID;
761 if(!CertGetCertificateChain(cert_chain_engine,
762 pCertContextServer,
763 NULL,
764 pCertContextServer->hCertStore,
765 &ChainPara,
766 (conn_config->no_revoke ? 0 :
767 CERT_CHAIN_REVOCATION_CHECK_CHAIN),
768 NULL,
769 &pChainContext)) {
770 char buffer[WINAPI_ERROR_LEN];
771 failf(data, "schannel: failed to get the certificate chain: %s",
772 curlx_winapi_strerror(GetLastError(), buffer, sizeof(buffer)));
773 pChainContext = NULL;
774 result = CURLE_PEER_FAILED_VERIFICATION;
775 }
777 if(result == CURLE_OK) {
778 CERT_SIMPLE_CHAIN *pSimpleChain = pChainContext->rgpChain[0];
779 DWORD dwTrustErrorMask = ~(DWORD)(CERT_TRUST_IS_NOT_TIME_NESTED);
780 dwTrustErrorMask &= pSimpleChain->TrustStatus.dwErrorStatus;
782 if(conn_config->revoke_best_effort) {
783 /* Ignore errors when root certificates are missing the revocation
784 * list URL, or when the list could not be downloaded because the
785 * server is currently unreachable. */
786 dwTrustErrorMask &= ~(DWORD)(CERT_TRUST_REVOCATION_STATUS_UNKNOWN |
787 CERT_TRUST_IS_OFFLINE_REVOCATION);
788 }
790 if(dwTrustErrorMask) {
791 if(dwTrustErrorMask & CERT_TRUST_IS_REVOKED)
792 failf(data, "schannel: trust for this certificate or one of "
793 "the certificates in the certificate chain has been revoked");
794 else if(dwTrustErrorMask & CERT_TRUST_IS_PARTIAL_CHAIN)
795 failf(data, "schannel: the certificate chain is incomplete");
796 else if(dwTrustErrorMask & CERT_TRUST_IS_UNTRUSTED_ROOT)
797 failf(data, "schannel: the certificate or certificate chain is "
798 "based on an untrusted root");
799 else if(dwTrustErrorMask & CERT_TRUST_IS_NOT_TIME_VALID)
800 failf(data, "schannel: this certificate or one of the certificates "
801 "in the certificate chain is not time valid");
802 else if(dwTrustErrorMask & CERT_TRUST_REVOCATION_STATUS_UNKNOWN)
803 failf(data, "schannel: the revocation status is unknown");
804 else
805 failf(data, "schannel: error 0x%08lx", dwTrustErrorMask);
806 result = CURLE_PEER_FAILED_VERIFICATION;
807 }
808 }
809 }
811 if(result == CURLE_OK) {
812 if(conn_config->verifyhost) {
813 result = Curl_verify_host(cf, data);
814 }
815 }
817 if(cert_chain_engine) {
818 CertFreeCertificateChainEngine(cert_chain_engine);
819 }
821 if(own_trust_store) {
822 CertCloseStore(own_trust_store, 0);
823 }
825 if(pChainContext)
826 CertFreeCertificateChain(pChainContext);
828 if(pCertContextServer)
829 CertFreeCertificateContext(pCertContextServer);
831 return result;
834#endif /* USE_SCHANNEL */
Diagnostics4 git calls · 45 ms
CallStatusSizeTime045 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit13 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=13
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2008.0 KiB · hit29 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=29
git.response.bytes=8235
git.response.cache=HIT
git.response.duration_ms=29
git.fetch.wants=3e4470cca80b3f9377714eee596ecc8de968cca7
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=8235
git.pkt.payload.max=8214
git.sideband.band1.bytes=8213
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e357c89c572c38
Request
4a88a7ac…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format