Artifactspublic-v0

curl

master
ply4 git calls76 ms290 KiB3 cachedprotocol v2
328 lines10 KiBRaw
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
25/* This file is for implementing all "generic" SSL functions that all libcurl
26 internals should use. It is then responsible for calling the proper
27 "backend" function.
29 SSL-functions in libcurl should call functions in this source file, and not
30 to any specific SSL-layer.
32 Curl_ssl_ - prefix for generic ones
34 Note that this source code uses the functions of the configured SSL
35 backend via the global Curl_ssl instance.
37 "SSL/TLS Strong Encryption: An Introduction"
38 https://httpd.apache.org/docs/2.0/ssl/ssl_intro.html
39 */
41#include "curl_setup.h"
43#ifdef USE_APPLE_SECTRUST
45#include "urldata.h"
46#include "cfilters.h"
47#include "curl_trc.h"
48#include "vtls/vtls.h"
49#include "vtls/apple.h"
51#include <Security/Security.h>
53#if (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \
54 __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400) || \
55 (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \
56 __IPHONE_OS_VERSION_MAX_ALLOWED >= 120000) || \
57 (defined(__TV_OS_VERSION_MAX_ALLOWED) && \
58 __TV_OS_VERSION_MAX_ALLOWED >= 120000) || \
59 (defined(__WATCH_OS_VERSION_MAX_ALLOWED) && \
60 __WATCH_OS_VERSION_MAX_ALLOWED >= 50000) || \
61 (defined(__VISION_OS_VERSION_MAX_ALLOWED) && \
62 __VISION_OS_VERSION_MAX_ALLOWED >= 10000)
63#define SUPPORTS_SecTrustEvaluateWithError 1
64#endif
66#if defined(SUPPORTS_SecTrustEvaluateWithError) && \
67 ((defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
68 __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || \
69 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && \
70 __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000) || \
71 (defined(__TV_OS_VERSION_MIN_REQUIRED) && \
72 __TV_OS_VERSION_MIN_REQUIRED >= 120000) || \
73 (defined(__WATCH_OS_VERSION_MIN_REQUIRED) && \
74 __WATCH_OS_VERSION_MIN_REQUIRED >= 50000) || \
75 (defined(__VISION_OS_VERSION_MIN_REQUIRED) && \
76 __VISION_OS_VERSION_MIN_REQUIRED >= 10000))
77#define REQUIRES_SecTrustEvaluateWithError 1
78#endif
80#if defined(SUPPORTS_SecTrustEvaluateWithError) && \
81 !defined(HAVE_BUILTIN_AVAILABLE) && \
82 !defined(REQUIRES_SecTrustEvaluateWithError)
83#undef SUPPORTS_SecTrustEvaluateWithError
84#endif
86#if (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \
87 __MAC_OS_X_VERSION_MAX_ALLOWED >= 100900) || \
88 (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \
89 __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || \
90 (defined(__TV_OS_VERSION_MAX_ALLOWED) && \
91 __TV_OS_VERSION_MAX_ALLOWED >= 90000) || \
92 (defined(__WATCH_OS_VERSION_MAX_ALLOWED) && \
93 __WATCH_OS_VERSION_MAX_ALLOWED >= 20000) || \
94 (defined(__VISION_OS_VERSION_MAX_ALLOWED) && \
95 __VISION_OS_VERSION_MAX_ALLOWED >= 10000)
96#define SUPPORTS_SecOCSP 1
97#endif
99CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf,
100 struct Curl_easy *data,
101 struct ssl_peer *peer,
102 size_t num_certs,
103 Curl_vtls_get_cert_der *der_cb,
104 void *cb_user_data,
105 const unsigned char *ocsp_buf,
106 size_t ocsp_len,
107 bool require_ocsp)
109 struct ssl_filter_config *conn_config = Curl_ssl_cf_get_filter_config(cf);
110 CURLcode result = CURLE_OK;
111 SecTrustRef trust = NULL;
112 SecPolicyRef policy = NULL;
113 CFMutableArrayRef policies = NULL;
114 CFMutableArrayRef cert_array = NULL;
115 CFStringRef host_str = NULL;
116 CFErrorRef error = NULL;
117 OSStatus status = noErr;
118 CFStringRef error_ref = NULL;
119 char *err_desc = NULL;
120 size_t i;
122 if(conn_config->verifyhost) {
123 host_str = CFStringCreateWithCString(NULL,
124 peer->sni ? peer->sni : peer->origin->hostname, kCFStringEncodingUTF8);
125 if(!host_str) {
126 result = CURLE_OUT_OF_MEMORY;
127 goto out;
128 }
129 }
131 policies = CFArrayCreateMutable(NULL, 2, &kCFTypeArrayCallBacks);
132 if(!policies) {
133 result = CURLE_OUT_OF_MEMORY;
134 goto out;
135 }
137 policy = SecPolicyCreateSSL(true, host_str);
138 if(!policy) {
139 result = CURLE_OUT_OF_MEMORY;
140 goto out;
141 }
143 CFArrayAppendValue(policies, policy);
144 CFRelease(policy);
145 policy = NULL;
147#if defined(HAVE_BUILTIN_AVAILABLE) && defined(SUPPORTS_SecOCSP)
148 {
149 if(!conn_config->no_revoke) {
150 if(__builtin_available(macOS 10.9, iOS 7, tvOS 9, watchOS 2, *)) {
151 /* Even without this set, validation seemingly-unavoidably fails
152 * for certificates that trustd already knows to be revoked.
153 * This policy further allows trustd to consult CRLs and OCSP data
154 * to determine revocation status (which it may then cache). */
155 CFOptionFlags revocation_flags = kSecRevocationUseAnyAvailableMethod;
156 if(require_ocsp)
157 revocation_flags |= kSecRevocationRequirePositiveResponse;
158 policy = SecPolicyCreateRevocation(revocation_flags);
159 if(!policy) {
160 result = CURLE_OUT_OF_MEMORY;
161 goto out;
162 }
164 CFArrayAppendValue(policies, policy);
165 }
166 }
167 }
168#else
169 /* OCSP check not available in this Apple OS version. */
170 if(require_ocsp) {
171 failf(data, "Apple SecTrust version does not support OCSP checks");
172 result = CURLE_SSL_INVALIDCERTSTATUS;
173 goto out;
174 }
176#endif
178 cert_array = CFArrayCreateMutable(NULL, num_certs, &kCFTypeArrayCallBacks);
179 if(!cert_array) {
180 result = CURLE_OUT_OF_MEMORY;
181 goto out;
182 }
184 for(i = 0; i < num_certs; i++) {
185 SecCertificateRef cert;
186 CFDataRef certdata;
187 unsigned char *der;
188 size_t der_len;
190 result = der_cb(cf, data, cb_user_data, i, &der, &der_len);
191 if(result)
192 goto out;
194 certdata = CFDataCreate(NULL, der, (CFIndex)der_len);
195 if(!certdata) {
196 result = CURLE_OUT_OF_MEMORY;
197 goto out;
198 }
200 cert = SecCertificateCreateWithData(NULL, certdata);
201 CFRelease(certdata);
202 if(!cert) {
203 result = CURLE_OUT_OF_MEMORY;
204 goto out;
205 }
207 CFArrayAppendValue(cert_array, cert);
208 CFRelease(cert);
209 }
211 status = SecTrustCreateWithCertificates(cert_array, policies, &trust);
212 if(status != noErr || !trust) {
213 failf(data, "Apple SecTrust: failed to create validation trust");
214 result = CURLE_PEER_FAILED_VERIFICATION;
215 goto out;
216 }
218 if(ocsp_len > 0) {
219 bool checked = FALSE;
220#if defined(HAVE_BUILTIN_AVAILABLE) && defined(SUPPORTS_SecOCSP)
221 if(__builtin_available(macOS 10.9, iOS 7, tvOS 9, watchOS 2, *)) {
222 CFDataRef ocspdata = CFDataCreate(NULL, ocsp_buf, (CFIndex)ocsp_len);
223 if(!ocspdata) {
224 result = CURLE_OUT_OF_MEMORY;
225 goto out;
226 }
227 status = SecTrustSetOCSPResponse(trust, ocspdata);
228 CFRelease(ocspdata);
229 if(status != noErr) {
230 failf(data, "Apple SecTrust: failed to set OCSP response: %d",
231 (int)status);
232 result = CURLE_PEER_FAILED_VERIFICATION;
233 goto out;
234 }
235 checked = TRUE;
236 }
237#endif
238 if(!checked) {
239 (void)ocsp_buf;
240 failf(data, "Apple SecTrust: OCSP verification not supported");
241 result = CURLE_NOT_BUILT_IN;
242 goto out;
243 }
244 }
246#ifdef SUPPORTS_SecTrustEvaluateWithError
247#ifdef HAVE_BUILTIN_AVAILABLE
248 if(__builtin_available(macOS 10.14, iOS 12, tvOS 12, watchOS 5, *)) {
249#else
250 if(1) {
251#endif
252 result = SecTrustEvaluateWithError(trust, &error) ?
253 CURLE_OK : CURLE_PEER_FAILED_VERIFICATION;
254 if(error) {
255 CFIndex code = CFErrorGetCode(error);
256 error_ref = CFErrorCopyDescription(error);
258 if(error_ref) {
259 CFIndex size = CFStringGetMaximumSizeForEncoding(
260 CFStringGetLength(error_ref), kCFStringEncodingUTF8);
261 err_desc = curlx_malloc(size + 1);
262 if(err_desc) {
263 if(!CFStringGetCString(error_ref, err_desc, size,
264 kCFStringEncodingUTF8))
265 curlx_safefree(err_desc);
266 }
267 }
268 failf(data, "Apple SecTrust failure %ld%s%s", code,
269 err_desc ? ": " : "", err_desc ? err_desc : "");
270 if(code == errSecIncompleteCertRevocationCheck)
271 result = CURLE_SSL_INVALIDCERTSTATUS;
272 }
273 }
274 else
275#endif /* SUPPORTS_SecTrustEvaluateWithError */
276 {
277#ifndef REQUIRES_SecTrustEvaluateWithError
278 SecTrustResultType sec_result;
279 status = SecTrustEvaluate(trust, &sec_result);
281 if(status != noErr) {
282 failf(data, "Apple SecTrust verification failed: error %d", (int)status);
283 result = CURLE_PEER_FAILED_VERIFICATION;
284 }
285 else if((sec_result == kSecTrustResultUnspecified) ||
286 (sec_result == kSecTrustResultProceed)) {
287 /* "unspecified" means system-trusted with no explicit user setting */
288 result = CURLE_OK;
289 }
290 else {
291 /* Any other trust result is a verification failure in this context */
292 result = CURLE_PEER_FAILED_VERIFICATION;
293 }
294#endif /* REQUIRES_SecTrustEvaluateWithError */
295 }
297out:
298 curlx_free(err_desc);
299 if(error_ref)
300 CFRelease(error_ref);
301 if(error)
302 CFRelease(error);
303 if(host_str)
304 CFRelease(host_str);
305 if(policies)
306 CFRelease(policies);
307 if(policy)
308 CFRelease(policy);
309 if(cert_array)
310 CFRelease(cert_array);
311 if(trust)
312 CFRelease(trust);
313 return result;
316bool Curl_vtls_apple_verifies_ocsp(struct Curl_cfilter *cf,
317 struct Curl_easy *data)
319 (void)cf;
320 (void)data;
321#if defined(HAVE_BUILTIN_AVAILABLE) && defined(SUPPORTS_SecOCSP)
322 return TRUE;
323#else
324 return FALSE;
325#endif
328#endif /* USE_APPLE_SECTRUST */
Diagnostics4 git calls · 76 ms
CallStatusSizeTime076 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 · hit22 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=22
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
fetch2003.3 KiB · hit51 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=51
git.response.bytes=3330
git.response.cache=HIT
git.response.duration_ms=51
git.fetch.wants=1ce52f257ce0e5e08e046f631f039e9a19915401
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=3330
git.pkt.payload.max=3309
git.sideband.band1.bytes=3308
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
a5e310257e64bdc9
Request
d947fe5f…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format