master
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 * SPDX-License-Identifier: curl
19 *
20 ***************************************************************************/
21#include "unitcheck.h"
23#if defined(USE_OPENSSL) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
24#include "urldata.h"
25#include "cfilters.h"
26#include "curl_trc.h"
27#include "vtls/openssl.h"
28#include "vtls/vtls.h"
29#include "vtls/vtls_int.h"
30#include <errno.h>
32static bool t2641_send_error;
33static bool t2641_read_after_error;
34static bool t2641_write_failed;
35static bool t2641_fail_writes;
37static bool t2641_contains(const char *buf, size_t size, const char *text)
38{
39 size_t i, len = strlen(text);
40 for(i = 0; i + len <= size; i++) {
41 if(!memcmp(buf + i, text, len))
42 return TRUE;
43 }
44 return FALSE;
45}
47/* The post-send read trace detects SSL_read() even if OpenSSL returns
48 * without calling the BIO. The initial read has a different trace message. */
49static int t2641_debug(CURL *handle, curl_infotype type, char *buf,
50 size_t size, void *userptr)
51{
52 (void)handle;
53 (void)userptr;
54 if(type == CURLINFO_TEXT && size) {
55 if(t2641_contains(buf, size, "SSL shutdown, ignore send error:"))
56 t2641_send_error = TRUE;
57 if(t2641_contains(buf, size, "SSL shutdown read ->"))
58 t2641_read_after_error = TRUE;
59 }
60 return 0;
61}
63/* Forward traffic and retry flags during the handshake, then inject a
64 * non-retryable write failure when shutdown sends close_notify. */
65static int t2641_bio_create(BIO *bio)
66{
67 BIO_set_init(bio, 1);
68 return 1;
69}
71static int t2641_bio_write(BIO *bio, const char *buf, int len)
72{
73 int rc;
74 BIO_clear_retry_flags(bio);
75 if(t2641_fail_writes) {
76 t2641_write_failed = TRUE;
77 errno = EPIPE;
78 return -1;
79 }
80 rc = BIO_write(BIO_next(bio), buf, len);
81 BIO_copy_next_retry(bio);
82 return rc;
83}
85static int t2641_bio_read(BIO *bio, char *buf, int len)
86{
87 int rc;
88 BIO_clear_retry_flags(bio);
89 rc = BIO_read(BIO_next(bio), buf, len);
90 BIO_copy_next_retry(bio);
91 return rc;
92}
94static long t2641_bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
95{
96 return BIO_ctrl(BIO_next(bio), cmd, num, ptr);
97}
99/* Advance one peer of the in-memory handshake, accepting blocked I/O. */
100static bool t2641_handshake_step(SSL *ssl)
101{
102 int rc, error;
103 if(SSL_is_init_finished(ssl))
104 return TRUE;
105 rc = SSL_do_handshake(ssl);
106 if(rc == 1)
107 return TRUE;
108 error = SSL_get_error(ssl, rc);
109 return error == SSL_ERROR_WANT_READ || error == SSL_ERROR_WANT_WRITE;
110}
111#endif
113static CURLcode test_unit2641(const char *arg)
114{
115#if defined(USE_OPENSSL) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
116 CURL *easy = NULL;
117 SSL_CTX *client_ctx = NULL, *server_ctx = NULL;
118 SSL *client = NULL, *server = NULL;
119 BIO *client_bio = NULL, *server_bio = NULL, *filter = NULL;
120 BIO_METHOD *method = NULL;
121 struct ossl_ctx backend;
122 struct ssl_connect_data connssl;
123 struct connectdata connection;
124 struct Curl_cfilter cf;
125 struct Curl_cftype cft;
126 CURLcode result;
127 bool done = FALSE;
128 int i;
130 UNITTEST_BEGIN_SIMPLE
131 global_init(CURL_GLOBAL_ALL);
132 easy = curl_easy_init();
133 abort_unless(easy, "curl_easy_init");
134 curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
135 curl_easy_setopt(easy, CURLOPT_DEBUGFUNCTION, t2641_debug);
136 t2641_send_error = t2641_read_after_error = t2641_write_failed = FALSE;
137 t2641_fail_writes = FALSE;
139 /* Connect real client and server SSL objects over an in-memory BIO pair.
140 * The test harness supplies the server certificate and key. */
141 client_ctx = SSL_CTX_new(TLS_client_method());
142 server_ctx = SSL_CTX_new(TLS_server_method());
143 abort_unless(client_ctx && server_ctx, "SSL contexts");
144 abort_unless(arg && SSL_CTX_use_certificate_file(server_ctx, arg,
145 SSL_FILETYPE_PEM) == 1,
146 "server certificate");
147 abort_unless(SSL_CTX_use_PrivateKey_file(server_ctx, arg,
148 SSL_FILETYPE_PEM) == 1,
149 "server private key");
150 client = SSL_new(client_ctx);
151 server = SSL_new(server_ctx);
152 abort_unless(client && server, "SSL connections");
153 abort_unless(BIO_new_bio_pair(&client_bio, 0, &server_bio, 0) == 1,
154 "BIO pair");
155 /* Place the fault-injection filter on the client side before handshaking. */
156 method = BIO_meth_new(BIO_TYPE_FILTER, "unit2641 failing write");
157 abort_unless(method, "BIO method");
158 abort_unless(BIO_meth_set_write(method, t2641_bio_write) &&
159 BIO_meth_set_read(method, t2641_bio_read) &&
160 BIO_meth_set_create(method, t2641_bio_create) &&
161 BIO_meth_set_ctrl(method, t2641_bio_ctrl), "BIO callbacks");
162 filter = BIO_new(method);
163 abort_unless(filter, "filter BIO");
164 BIO_push(filter, client_bio);
165 client_bio = NULL;
166 SSL_set_bio(client, filter, filter);
167 filter = NULL;
168 SSL_set_bio(server, server_bio, server_bio);
169 server_bio = NULL;
170 SSL_set_connect_state(client);
171 SSL_set_accept_state(server);
172 for(i = 0; i < 100 &&
173 (!SSL_is_init_finished(client) || !SSL_is_init_finished(server)); i++)
174 abort_unless(t2641_handshake_step(client) && t2641_handshake_step(server),
175 "TLS handshake step");
176 abort_unless(SSL_is_init_finished(client) && SSL_is_init_finished(server),
177 "TLS handshake complete");
179 /* Leave the read side connected but fail the close_notify write. */
180 t2641_fail_writes = TRUE;
182 /* Give the backend shutdown entry point a minimal filter context with the
183 * established client SSL object. Enable its trace for the assertions. */
184 memset(&backend, 0, sizeof(backend));
185 memset(&connssl, 0, sizeof(connssl));
186 memset(&connection, 0, sizeof(connection));
187 memset(&cf, 0, sizeof(cf));
188 cft = Curl_cft_ssl;
189 cft.log_level = CURL_LOG_LVL_INFO;
190 backend.ssl = client;
191 connssl.backend = &backend;
192 connssl.ssl_impl = &Curl_ssl_openssl;
193 cf.cft = &cft;
194 cf.ctx = &connssl;
195 cf.conn = &connection;
196 result = Curl_ssl_openssl.shut_down(&cf, easy, TRUE, &done);
197 /* Check that the write failure reached the terminal path and that the
198 * post-send read path was not entered. Shutdown itself is best-effort. */
199 fail_unless(result == CURLE_OK, "best-effort shutdown");
200 fail_unless(t2641_write_failed, "close_notify write failed");
201 fail_unless(t2641_send_error, "shutdown error was terminal");
202 fail_unless(done, "shutdown finished after terminal error");
203 fail_unless(!t2641_read_after_error, "no read after terminal error");
204 /* !checksrc! disable CLOSEBRACE 1 */
205 }
206unit_test_abort:
207 BIO_free_all(filter);
208 BIO_free(client_bio);
209 BIO_free(server_bio);
210 SSL_free(client);
211 SSL_free(server);
212 BIO_meth_free(method);
213 SSL_CTX_free(client_ctx);
214 SSL_CTX_free(server_ctx);
215 curl_easy_cleanup(easy);
216 curl_global_cleanup();
217 return (CURLcode)unitfail;
218#else
219 (void)arg;
220 return CURLE_OK;
221#endif
222}
Diagnostics4 git calls · 333 ms
CallStatusSizeTime0333 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 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 · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 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=3 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=86Open pack map
fetch2002.7 KiB328 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=328 git.response.bytes=2743 git.response.cache=MISS git.response.duration_ms=328 git.fetch.wants=62b518e7c264d6c387f4c26fda530cc508450aa2 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=2743 git.pkt.payload.max=2722 git.sideband.band1.bytes=2721 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
- a5e1ff528f7ea9c0
- Request
- a8b373f1…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format