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 * 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#include "unitcheck.h"
26#include "urldata.h"
27#include "cfilters.h"
28#include "curl_trc.h"
29#include "vtls/vtls_int.h"
30#include "vtls/rustls.h"
32#ifdef USE_RUSTLS
34struct t2640_ctx {
35 size_t calls;
36 size_t written;
37 size_t write_once;
38 bool blocked;
39 bool fatal;
40};
42static void t2640_destroy(struct Curl_cfilter *cf, struct Curl_easy *data)
43{
44 (void)cf;
45 (void)data;
46}
48static CURLcode t2640_send(struct Curl_cfilter *cf,
49 struct Curl_easy *data,
50 const uint8_t *buf, size_t len, bool eos,
51 size_t *pnwritten)
52{
53 struct t2640_ctx *ctx = cf->ctx;
54 (void)data;
55 (void)buf;
56 (void)eos;
58 ++ctx->calls;
59 *pnwritten = 0;
60 if(ctx->fatal)
61 return CURLE_SEND_ERROR;
62 if(ctx->write_once) {
63 len = CURLMIN(len, ctx->write_once);
64 ctx->write_once = 0;
65 }
66 else if(ctx->blocked)
67 return CURLE_AGAIN;
68 ctx->written += len;
69 *pnwritten = len;
70 return CURLE_OK;
71}
73static const struct Curl_cftype t2640_cft = {
74 "TEST",
75 CF_TYPE_IP_CONNECT,
76 CURL_LOG_LVL_NONE,
77 t2640_destroy,
78 Curl_cf_def_connect,
79 Curl_cf_def_shutdown,
80 Curl_cf_def_adjust_pollset,
81 Curl_cf_def_data_pending,
82 t2640_send,
83 Curl_cf_def_recv,
84 Curl_cf_def_cntrl,
85 Curl_cf_def_conn_is_alive,
86 Curl_cf_def_conn_keep_alive,
87 Curl_cf_def_query,
88};
90static void t2640_run(struct Curl_easy *data, const struct Curl_cftype *cft,
91 size_t partial, bool extend, bool flush_only, bool fatal)
92{
93 struct ssl_connect_data connssl;
94 struct t2640_ctx transport_ctx;
95 struct Curl_cfilter transport_cf;
96 struct Curl_cfilter rustls_cf;
97 unsigned char buf[1024], retry[1536];
98 size_t nwritten = 0, retrylen;
99#ifndef DEBUGBUILD
100 size_t calls;
101#endif
102 CURLcode result;
104 memset(&connssl, 0, sizeof(connssl));
105 memset(&transport_ctx, 0, sizeof(transport_ctx));
106 memset(&transport_cf, 0, sizeof(transport_cf));
107 memset(&rustls_cf, 0, sizeof(rustls_cf));
108 memset(buf, 'x', sizeof(buf));
109 memset(retry, 'x', sizeof(retry));
111 connssl.backend = curlx_calloc(1, Curl_ssl_rustls.sizeof_ssl_backend_data);
112 abort_unless(connssl.backend, "Rustls backend allocation failed");
113 connssl.ssl_impl = &Curl_ssl_rustls;
114 transport_ctx.blocked = TRUE;
115 transport_ctx.write_once = partial;
116 transport_cf.cft = &t2640_cft;
117 transport_cf.ctx = &transport_ctx;
118 transport_cf.connected = TRUE;
119 rustls_cf.cft = cft;
120 rustls_cf.next = &transport_cf;
121 rustls_cf.ctx = &connssl;
123 result = rustls_test_init(&connssl, 2 * sizeof(buf));
124 abort_unless(!result, "Rustls test connection initialization failed");
126 /* The ClientHello supplies TLS output to block, while application data
127 * goes into the pre-handshake plaintext buffer. This exercises the real
128 * send bookkeeping without a server, certificates or timing assumptions.
129 * ssl_cf_send allows ssl_connection_none through; only
130 * ssl_connection_deferred triggers a handshake there. */
131 result = Curl_conn_cf_send(&rustls_cf, data, buf, sizeof(buf), FALSE,
132 &nwritten);
133 fail_unless(result == CURLE_AGAIN && !nwritten,
134 "blocked send acknowledged plaintext");
135 fail_unless(transport_ctx.written == partial,
136 "partial TLS write did not precede blocking");
138 /* Moving the buffer is fine, but the unacknowledged prefix must remain. */
139 result = Curl_conn_cf_send(&rustls_cf, data, retry, sizeof(buf), FALSE,
140 &nwritten);
141 fail_unless(result == CURLE_AGAIN && !nwritten,
142 "blocked retry acknowledged plaintext");
144#ifndef DEBUGBUILD
145 /* Short retries assert in debug builds; check the returned error in
146 * non-debug builds. */
147 calls = transport_ctx.calls;
148 nwritten = 99;
149 result = Curl_conn_cf_send(&rustls_cf, data, retry, sizeof(buf) - 1,
150 FALSE, &nwritten);
151 fail_unless(result == CURLE_BAD_FUNCTION_ARGUMENT && !nwritten,
152 "short retry was not rejected while blocked");
153 fail_unless(transport_ctx.calls == calls,
154 "invalid retry attempted a TLS write");
155#endif
157 if(flush_only) {
158 nwritten = 99;
159 result = Curl_ssl_rustls.send_plain(&rustls_cf, data, NULL, 0, &nwritten);
160 fail_unless(result == CURLE_AGAIN && !nwritten,
161 "blocked flush-only send acknowledged plaintext");
162 }
164 if(fatal) {
165 transport_ctx.fatal = TRUE;
166 result = Curl_conn_cf_send(&rustls_cf, data, retry, sizeof(buf), FALSE,
167 &nwritten);
168 fail_unless(result == CURLE_SEND_ERROR && !nwritten,
169 "retry hid a fatal TLS write error");
170 goto unit_test_abort;
171 }
173 transport_ctx.blocked = FALSE;
174 if(flush_only) {
175 nwritten = 99;
176 result = Curl_ssl_rustls.send_plain(&rustls_cf, data, NULL, 0, &nwritten);
177 fail_unless(!result && !nwritten,
178 "flush-only send acknowledged plaintext");
179 fail_unless(transport_ctx.written > partial,
180 "flush-only send did not drain TLS output");
181 }
183#ifndef DEBUGBUILD
184 calls = transport_ctx.calls;
185 nwritten = 99;
186 result = Curl_conn_cf_send(&rustls_cf, data, retry, sizeof(buf) - 1,
187 FALSE, &nwritten);
188 fail_unless(result == CURLE_BAD_FUNCTION_ARGUMENT && !nwritten,
189 "short retry was not rejected after unblocking");
190 fail_unless(transport_ctx.calls == calls,
191 "invalid retry wrote TLS output after unblocking");
192#endif
194 /* Retry both the original length and an extended buffer with the same
195 * prefix. Only bytes beyond the saved count may be added to Rustls. */
196 retrylen = extend ? sizeof(retry) : sizeof(buf);
197 result = Curl_conn_cf_send(&rustls_cf, data, retry, retrylen, FALSE,
198 &nwritten);
199 fail_unless(!result && nwritten == retrylen,
200 "valid retry did not acknowledge the correct byte count");
201 fail_unless(transport_ctx.written > partial,
202 "valid retry did not drain TLS output");
204 /* Exactly this much room remains. Re-enqueuing a retry would fill the
205 * buffer early. */
206 result = Curl_conn_cf_send(&rustls_cf, data, buf, 2 * sizeof(buf) - retrylen,
207 FALSE, &nwritten);
208 fail_unless(!result && nwritten == 2 * sizeof(buf) - retrylen,
209 "retry duplicated plaintext");
211unit_test_abort:
212 if(connssl.backend)
213 Curl_ssl_rustls.close(&rustls_cf, data);
214 curlx_free(connssl.backend);
215}
217#endif /* USE_RUSTLS */
219static void t2640_stop(struct Curl_easy *data)
220{
221 curl_easy_cleanup(data);
222 curl_global_cleanup();
223}
225static CURLcode test_unit2640(const char *arg)
226{
227 struct Curl_easy *data = NULL;
229 UNITTEST_BEGIN_SIMPLE
231#ifdef USE_RUSTLS
232 static const size_t partials[] = { 0, 7 };
233 size_t i;
234 int extend, flush_only, fatal;
236 abort_unless(!curl_global_init(CURL_GLOBAL_ALL), "global init failed");
237 data = curl_easy_init();
238 abort_unless(data, "easy handle allocation failed");
239 for(i = 0; i < CURL_ARRAYSIZE(partials); ++i) {
240 for(extend = 0; extend <= 1; ++extend) {
241 for(flush_only = 0; flush_only <= 1; ++flush_only) {
242 for(fatal = 0; fatal <= 1; ++fatal) {
243 t2640_run(data, &Curl_cft_ssl, partials[i], extend != 0,
244 flush_only != 0, fatal != 0);
245#ifndef CURL_DISABLE_PROXY
246 t2640_run(data, &Curl_cft_ssl_proxy, partials[i], extend != 0,
247 flush_only != 0, fatal != 0);
248#endif
249 }
250 }
251 }
252 }
253#endif /* USE_RUSTLS */
255 UNITTEST_END(t2640_stop(data))
256}
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 · 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.6 KiB · hit39 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=39 git.response.bytes=2671 git.response.cache=HIT git.response.duration_ms=39 git.fetch.wants=f8506a4c24d930bb72769a9361b8bb65059f80c4 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=2671 git.pkt.payload.max=2650 git.sideband.band1.bytes=2649 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
- a5e1ffcf8f85a9c0
- Request
- 3867c4fa…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format