master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) David Bures
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#ifdef USE_SCHANNEL
27#include "urldata.h"
28#include "cfilters.h"
29#include "curl_sspi.h"
30#include "vtls/schannel.h"
31#include "vtls/schannel_int.h"
32#include "vtls/vtls_int.h"
34static const unsigned char t4782_token[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
36static struct {
37 unsigned int generated;
38 unsigned int freed;
39 unsigned int sends;
40 unsigned int blocks;
41 size_t accepted;
42 size_t first_write;
43 CURLcode send_error;
44 SECURITY_STATUS generate_error;
45} t4782;
47static SECURITY_STATUS SEC_ENTRY t4782_apply(PCtxtHandle context,
48 PSecBufferDesc input_desc)
49{
50 (void)context;
51 fail_unless(input_desc->cBuffers == 1, "one shutdown input buffer");
52 fail_unless(*(DWORD *)input_desc->pBuffers[0].pvBuffer == SCHANNEL_SHUTDOWN,
53 "shutdown token");
54 return SEC_E_OK;
55}
57static SECURITY_STATUS SEC_ENTRY t4782_generate(
58 PCredHandle credential, PCtxtHandle context, TCHAR *target,
59 unsigned long flags, unsigned long reserved, unsigned long representation,
60 PSecBufferDesc input_desc, unsigned long reserved2, PCtxtHandle new_context,
61 PSecBufferDesc output_desc, unsigned long *attributes, PTimeStamp expiry)
62{
63 SecBuffer *token = &output_desc->pBuffers[0];
64 (void)credential;
65 (void)context;
66 (void)target;
67 (void)flags;
68 (void)reserved;
69 (void)representation;
70 (void)input_desc;
71 (void)reserved2;
72 (void)new_context;
73 (void)attributes;
74 (void)expiry;
75 t4782.generated++;
76 token->pvBuffer = curlx_malloc(sizeof(t4782_token));
77 if(!token->pvBuffer)
78 return SEC_E_INSUFFICIENT_MEMORY;
79 memcpy(token->pvBuffer, t4782_token, sizeof(t4782_token));
80 token->cbBuffer = sizeof(t4782_token);
81 token->BufferType = SECBUFFER_TOKEN;
82 return t4782.generate_error;
83}
85static SECURITY_STATUS SEC_ENTRY t4782_free(void *buffer)
86{
87 t4782.freed++;
88 curlx_free(buffer);
89 return SEC_E_OK;
90}
92static SECURITY_STATUS SEC_ENTRY t4782_delete(PCtxtHandle context)
93{
94 (void)context;
95 return SEC_E_OK;
96}
98static SECURITY_STATUS SEC_ENTRY t4782_free_cred(PCredHandle credential)
99{
100 (void)credential;
101 return SEC_E_OK;
102}
104static CURLcode t4782_send(struct Curl_cfilter *cf, struct Curl_easy *data,
105 const uint8_t *buffer, size_t length, bool eos,
106 size_t *written)
107{
108 (void)cf;
109 (void)data;
110 (void)eos;
111 t4782.sends++;
112 *written = 0;
113 fail_unless(length == sizeof(t4782_token) - t4782.accepted,
114 "retry begins at the unsent offset");
115 verify_memory(buffer, t4782_token + t4782.accepted, (int)length);
116 if(t4782.blocks) {
117 t4782.blocks--;
118 return CURLE_AGAIN;
119 }
120 if(t4782.send_error)
121 return t4782.send_error;
122 *written = t4782.first_write ? t4782.first_write : length;
123 t4782.first_write = 0;
124 t4782.accepted += *written;
125 return CURLE_OK;
126}
128static CURLcode t4782_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
129 char *buffer, size_t length, size_t *received)
130{
131 (void)cf;
132 (void)data;
133 (void)buffer;
134 (void)length;
135 *received = 0;
136 return CURLE_AGAIN;
137}
139static void t4782_destroy(struct Curl_cfilter *cf, struct Curl_easy *data)
140{
141 (void)cf;
142 (void)data;
143}
145static const struct Curl_cftype t4782_filter = {
146 "TEST",
147 0,
148 CURL_LOG_LVL_NONE,
149 t4782_destroy,
150 Curl_cf_def_connect,
151 Curl_cf_def_shutdown,
152 Curl_cf_def_adjust_pollset,
153 Curl_cf_def_data_pending,
154 t4782_send,
155 t4782_recv,
156 Curl_cf_def_cntrl,
157 Curl_cf_def_conn_is_alive,
158 Curl_cf_def_conn_keep_alive,
159 Curl_cf_def_query,
160};
162static CURLcode t4782_setup(CURL **easy)
163{
164 CURLcode result = CURLE_OK;
165 global_init(CURL_GLOBAL_ALL);
166 *easy = curl_easy_init();
167 if(!*easy) {
168 curl_global_cleanup();
169 return CURLE_OUT_OF_MEMORY;
170 }
171 return result;
172}
174static void t4782_stop(CURL *easy)
175{
176 curl_easy_cleanup(easy);
177 curl_global_cleanup();
178}
179#endif
181static CURLcode test_unit4782(const char *arg)
182{
183#ifdef USE_SCHANNEL
184 CURL *easy = NULL;
185 PSecurityFunctionTable original;
186 SecurityFunctionTable functions;
187 static char hostname[] = "example.invalid";
188 unsigned int scenario;
189 UNITTEST_BEGIN(t4782_setup(&easy))
191 original = Curl_pSecFn;
192 functions = *original;
193 functions.ApplyControlToken = t4782_apply;
194 functions.InitializeSecurityContext = t4782_generate;
195 functions.FreeContextBuffer = t4782_free;
196 functions.DeleteSecurityContext = t4782_delete;
197 functions.FreeCredentialsHandle = t4782_free_cred;
198 Curl_pSecFn = &functions;
200 for(scenario = 0; scenario < 6; scenario++) {
201 struct schannel_ssl_backend_data backend;
202 struct ssl_connect_data ssl;
203 struct connectdata connection;
204 struct Curl_peer origin;
205 struct Curl_cfilter cf;
206 struct Curl_cfilter lower;
207 CURLcode result;
208 bool done;
209 unsigned int attempts;
211 memset(&t4782, 0, sizeof(t4782));
212 memset(&backend, 0, sizeof(backend));
213 memset(&ssl, 0, sizeof(ssl));
214 memset(&connection, 0, sizeof(connection));
215 memset(&origin, 0, sizeof(origin));
216 memset(&cf, 0, sizeof(cf));
217 memset(&lower, 0, sizeof(lower));
218 backend.cred = curlx_calloc(1, sizeof(*backend.cred));
219 backend.ctxt = curlx_calloc(1, sizeof(*backend.ctxt));
220 if(!backend.cred || !backend.ctxt) {
221 curlx_free(backend.cred);
222 curlx_free(backend.ctxt);
223 fail("allocation failed");
224 break;
225 }
226 backend.cred->refcount = 1;
227 backend.recv_sspi_close_notify = TRUE;
228 ssl.backend = &backend;
229 ssl.peer.origin = &origin;
230 origin.hostname = hostname;
231 origin.port = 443;
232 cf.ctx = &ssl;
233 cf.conn = &connection;
234 cf.next = &lower;
235 lower.cft = &t4782_filter;
237 if(scenario == 0 || scenario == 2)
238 t4782.blocks = 2;
239 if(scenario == 1)
240 t4782.first_write = 1;
241 if(scenario == 3 || scenario == 4)
242 t4782.send_error = CURLE_SEND_ERROR;
243 if(scenario == 4)
244 backend.recv_connection_closed = TRUE;
245 if(scenario == 5)
246 t4782.generate_error = SEC_E_INTERNAL_ERROR;
248 result = Curl_ssl_schannel.shut_down(&cf, easy, TRUE, &done);
249 if(scenario < 3) {
250 fail_unless(result == CURLE_OK && !done && !cf.shutdown,
251 "incomplete send keeps shutdown pending");
252 fail_unless(t4782.generated == 1 && t4782.freed == 0,
253 "pending token remains owned");
254 fail_unless(ssl.io_need == CURL_SSL_IO_NEED_SEND,
255 "pending shutdown waits for writability");
256 if(scenario != 2) {
257 for(attempts = 0; !done && attempts < 3; attempts++)
258 result = Curl_ssl_schannel.shut_down(&cf, easy, TRUE, &done);
259 fail_unless(result == CURLE_OK && done && cf.shutdown,
260 "shutdown completed");
261 fail_unless(t4782.generated == 1 && t4782.freed == 1,
262 "retry reuses and then frees one token");
263 fail_unless(t4782.accepted == sizeof(t4782_token),
264 "complete record delivered once");
265 }
266 }
267 else {
268 fail_unless(result == (scenario == 4 ? CURLE_OK : CURLE_SEND_ERROR),
269 "send/generation failure retains existing error semantics");
270 fail_unless(cf.shutdown, "failed shutdown does not retry");
271 }
272 Curl_ssl_schannel.close(&cf, easy);
273 fail_unless(t4782.generated == 1 && t4782.freed == 1,
274 "close releases the token exactly once");
275 }
277 Curl_pSecFn = original;
278 UNITTEST_END(t4782_stop(easy))
279#else
280 (void)arg;
281 return CURLE_OK;
282#endif
283}
Diagnostics4 git calls · 28 ms
CallStatusSizeTime028 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=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 · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=23 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 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 KiB · hit23 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2773 git.response.cache=HIT git.response.duration_ms=23 git.fetch.wants=fe0afc4fb5d7489e4fd207b7a4be930f89c8f91e 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=2773 git.pkt.payload.max=2752 git.sideband.band1.bytes=2751 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
- a5e2e5fb3b242947
- Request
- 98d98699…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format