Artifactspublic-v0

curl

master
ply4 git calls27 ms289 KiB3 cachedprotocol v2
196 lines6.5 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 ***************************************************************************/
24/* <DESC>
25 * CA cert in memory with OpenSSL to get an HTTPS page.
26 * </DESC>
27 */
29/* This example uses the legacy and discouraged method. Use
30 CURLOPT_CAINFO_BLOB instead, which is TLS backend agnostic. See the
31 cainfo-blob.c example */
33/* Requires: USE_OPENSSL */
35#include <openssl/ssl.h>
37#include <stdio.h>
39#include <curl/curl.h>
41#if defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC)
42typedef size_t ossl_valsize_t;
43#else
44typedef int ossl_valsize_t;
45#endif
47static size_t write_cb(char *ptr, size_t size, size_t nmemb, void *stream)
49 fwrite(ptr, size, nmemb, (FILE *)stream);
50 return nmemb * size;
53static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer)
55 /** This example uses two (fake) certificates **/
56 /* replace the XXX with the actual CA certificates */
57 static const char mypem[] =
58 "-----BEGIN CERTIFICATE-----\n"
59 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
60 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
61 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
62 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
63 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
64 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
65 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
66 "-----END CERTIFICATE-----\n"
67 "-----BEGIN CERTIFICATE-----\n"
68 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
69 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
70 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
71 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
72 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
73 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
74 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
75 "-----END CERTIFICATE-----\n";
77 CURLcode result = CURLE_ABORTED_BY_CALLBACK;
78 BIO *cbio = NULL;
79 X509_STORE *cts;
80 ossl_valsize_t i;
81 STACK_OF(X509_INFO) * inf;
83 (void)curl;
84 (void)pointer;
86 cts = SSL_CTX_get_cert_store((SSL_CTX *)sslctx);
87 if(!cts) {
88 printf("SSL_CTX_get_cert_store() failed\n");
89 goto out;
90 }
92 cbio = BIO_new_mem_buf(mypem, sizeof(mypem) - 1);
93 if(!cbio) {
94 printf("BIO_new_mem_buf() failed\n");
95 goto out;
96 }
98 inf = PEM_X509_INFO_read_bio(cbio, NULL, NULL, NULL);
99 if(!inf) {
100 printf("PEM_X509_INFO_read_bio() failed\n");
101 goto out;
102 }
104 for(i = 0; i < sk_X509_INFO_num(inf); i++) {
105 X509_INFO *itmp = sk_X509_INFO_value(inf, i);
106 if(itmp->x509) {
107 X509_STORE_add_cert(cts, itmp->x509);
108 }
109 if(itmp->crl) {
110 X509_STORE_add_crl(cts, itmp->crl);
111 }
112 }
114#if defined(__clang__) && __clang_major__ >= 16
115#pragma clang diagnostic push
116#pragma clang diagnostic ignored "-Wcast-function-type-strict"
117#endif
118 sk_X509_INFO_pop_free(inf, X509_INFO_free);
119#if defined(__clang__) && __clang_major__ >= 16
120#pragma clang diagnostic pop
121#endif
123 result = CURLE_OK;
125out:
127 if(cbio)
128 BIO_free(cbio);
130 return result;
133int main(void)
135 CURL *curl;
137 CURLcode result = curl_global_init(CURL_GLOBAL_ALL);
138 if(result != CURLE_OK)
139 return (int)result;
141 curl = curl_easy_init();
142 if(curl) {
143 curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
144 curl_easy_setopt(curl, CURLOPT_HEADER, 0L);
145 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
146 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
147 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
148 curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout);
149 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_cb);
150 curl_easy_setopt(curl, CURLOPT_HEADERDATA, stderr);
151 curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
152 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
153 curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
155 /* Turn off the default CA locations, otherwise libcurl loads CA
156 * certificates from the locations that were detected/specified at
157 * build-time
158 */
159 curl_easy_setopt(curl, CURLOPT_CAINFO, NULL);
160 curl_easy_setopt(curl, CURLOPT_CAPATH, NULL);
162 /* first try: retrieve page without CA certificates -> should fail
163 * unless libcurl was built --with-ca-fallback enabled at build-time
164 */
165 result = curl_easy_perform(curl);
166 if(result == CURLE_OK)
167 printf("*** transfer succeeded ***\n");
168 else
169 printf("*** transfer failed ***\n");
171 /* use a fresh connection (optional) this option seriously impacts
172 * performance of multiple transfers but it is necessary order to
173 * demonstrate this example. recall that the SSL ctx callback is only
174 * called _before_ an SSL connection is established, therefore it does not
175 * affect existing verified SSL connections already in the connection
176 * cache associated with this handle. normally you would set the SSL ctx
177 * function before making any transfers, and not use this option.
178 */
179 curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1L);
181 /* second try: retrieve page using cacerts' certificate -> succeeds to
182 * load the certificate by installing a function doing the necessary
183 * "modifications" to the SSL CONTEXT before link init
184 */
185 curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctx_function);
186 result = curl_easy_perform(curl);
187 if(result == CURLE_OK)
188 printf("*** transfer succeeded ***\n");
189 else
190 printf("*** transfer failed ***\n");
192 curl_easy_cleanup(curl);
193 }
194 curl_global_cleanup();
195 return (int)result;
Diagnostics4 git calls · 27 ms
CallStatusSizeTime027 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
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 · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=21
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
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
fetch2002.3 KiB · hit21 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2363
git.response.cache=HIT
git.response.duration_ms=21
git.fetch.wants=841f4447d259bb8e6eaf597c4928646d55740218
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=2363
git.pkt.payload.max=2342
git.sideband.band1.bytes=2341
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
a5e2dd2fbfe7c125
Request
1a4dfa1c…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format