Artifactspublic-v0

curl

master
ply4 git calls35 ms291 KiB3 cachedprotocol v2
456 lines15 KiBRaw
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Steve Holme, <steve_holme@hotmail.com>.
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 * RFC4752 The Kerberos V5 ("GSSAPI") SASL Mechanism
24 *
25 ***************************************************************************/
26#include "curl_setup.h"
28#if defined(USE_WINDOWS_SSPI) && defined(USE_KERBEROS5)
30#include "vauth/vauth.h"
31#include "curl_trc.h"
33/*
34 * Curl_auth_is_gssapi_supported()
35 *
36 * This is used to evaluate if GSSAPI (Kerberos V5) is supported.
37 *
38 * Parameters: None
39 *
40 * Returns TRUE if Kerberos V5 is supported by Windows SSPI.
41 */
42bool Curl_auth_is_gssapi_supported(void)
44 PSecPkgInfo SecurityPackage;
45 SECURITY_STATUS status;
47 /* Query the security package for Kerberos */
48 status = Curl_pSecFn->QuerySecurityPackageInfo(
49 CURL_UNCONST(TEXT(SP_NAME_KERBEROS)),
50 &SecurityPackage);
52 /* Release the package buffer as it is not required anymore */
53 if(status == SEC_E_OK) {
54 Curl_pSecFn->FreeContextBuffer(SecurityPackage);
55 }
57 return status == SEC_E_OK;
60/*
61 * Curl_auth_create_gssapi_user_message()
62 *
63 * This is used to generate an already encoded GSSAPI (Kerberos V5) user token
64 * message ready for sending to the recipient.
65 *
66 * Parameters:
67 *
68 * data [in] - The session handle.
69 * userp [in] - The username in the format User or Domain\User.
70 * passwdp [in] - The user's password.
71 * service [in] - The service type such as http, smtp, pop or imap.
72 * host [in] - The hostname.
73 * mutual_auth [in] - Flag specifying whether or not mutual authentication
74 * is enabled.
75 * chlg [in] - Optional challenge message.
76 * krb5 [in/out] - The Kerberos 5 data struct being used and modified.
77 * out [out] - The result storage.
78 *
79 * Returns CURLE_OK on success.
80 */
81CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
82 struct Curl_creds *creds,
83 const char *default_service,
84 const char *host,
85 const bool mutual_auth,
86 const struct bufref *chlg,
87 struct kerberos5data *krb5,
88 struct bufref *out)
90 CURLcode result = CURLE_OK;
91 CtxtHandle context;
92 PSecPkgInfo SecurityPackage;
93 SecBuffer chlg_buf;
94 SecBuffer resp_buf;
95 SecBufferDesc chlg_desc;
96 SecBufferDesc resp_desc;
97 SECURITY_STATUS status;
98 unsigned long attrs;
99 const char *service = Curl_creds_has_sasl_service(creds) ?
100 Curl_creds_sasl_service(creds) : default_service;
102 if(!krb5->spn) {
103 /* Generate our SPN */
104 krb5->spn = Curl_auth_build_spn(service, host, NULL);
105 if(!krb5->spn)
106 return CURLE_OUT_OF_MEMORY;
107 }
109 if(!krb5->output_token) {
110 /* Query the security package for Kerberos */
111 status = Curl_pSecFn->QuerySecurityPackageInfo(
112 CURL_UNCONST(TEXT(SP_NAME_KERBEROS)),
113 &SecurityPackage);
114 if(status != SEC_E_OK) {
115 failf(data, "SSPI: could not get auth info");
116 return CURLE_AUTH_ERROR;
117 }
119 krb5->token_max = SecurityPackage->cbMaxToken;
121 /* Release the package buffer as it is not required anymore */
122 Curl_pSecFn->FreeContextBuffer(SecurityPackage);
124 /* Allocate our response buffer */
125 krb5->output_token = curlx_malloc(krb5->token_max);
126 if(!krb5->output_token)
127 return CURLE_OUT_OF_MEMORY;
128 }
130 if(!krb5->credentials) {
131 /* Do we have credentials to use or are we using single sign-on? */
132 if(Curl_creds_has_user(creds)) {
133 /* Populate our identity structure */
134 result = Curl_create_sspi_identity(
135 creds->user, creds->passwd, &krb5->identity);
136 if(result)
137 return result;
139 /* Allow proper cleanup of the identity structure */
140 krb5->p_identity = &krb5->identity;
141 }
142 else
143 /* Use the current Windows user */
144 krb5->p_identity = NULL;
146 /* Allocate our credentials handle */
147 krb5->credentials = curlx_calloc(1, sizeof(CredHandle));
148 if(!krb5->credentials)
149 return CURLE_OUT_OF_MEMORY;
151 /* Acquire our credentials handle */
152 status = Curl_pSecFn->AcquireCredentialsHandle(NULL,
153 CURL_UNCONST(TEXT(SP_NAME_KERBEROS)),
154 SECPKG_CRED_OUTBOUND, NULL,
155 krb5->p_identity, NULL, NULL,
156 krb5->credentials, NULL);
157 if(status != SEC_E_OK) {
158 curlx_safefree(krb5->credentials);
159 return CURLE_LOGIN_DENIED;
160 }
162 /* Allocate our new context handle */
163 krb5->context = curlx_calloc(1, sizeof(CtxtHandle));
164 if(!krb5->context)
165 return CURLE_OUT_OF_MEMORY;
166 }
168 if(chlg) {
169 if(!Curl_bufref_len(chlg)) {
170 infof(data, "GSSAPI handshake failure (empty challenge message)");
171 return CURLE_BAD_CONTENT_ENCODING;
172 }
174 /* Setup the challenge "input" security buffer */
175 chlg_desc.ulVersion = SECBUFFER_VERSION;
176 chlg_desc.cBuffers = 1;
177 chlg_desc.pBuffers = &chlg_buf;
178 chlg_buf.BufferType = SECBUFFER_TOKEN;
179 chlg_buf.pvBuffer = CURL_UNCONST(Curl_bufref_ptr(chlg));
180 chlg_buf.cbBuffer = curlx_uztoul(Curl_bufref_len(chlg));
181 }
183 /* Setup the response "output" security buffer */
184 resp_desc.ulVersion = SECBUFFER_VERSION;
185 resp_desc.cBuffers = 1;
186 resp_desc.pBuffers = &resp_buf;
187 resp_buf.BufferType = SECBUFFER_TOKEN;
188 resp_buf.pvBuffer = krb5->output_token;
189 resp_buf.cbBuffer = curlx_uztoul(krb5->token_max);
191 /* Generate our challenge-response message */
192 status = Curl_pSecFn->InitializeSecurityContext(krb5->credentials,
193 chlg ? krb5->context : NULL,
194 krb5->spn,
195 (mutual_auth ?
196 ISC_REQ_MUTUAL_AUTH : 0),
197 0, SECURITY_NATIVE_DREP,
198 chlg ? &chlg_desc : NULL, 0,
199 &context,
200 &resp_desc, &attrs, NULL);
202 if(status == SEC_E_INSUFFICIENT_MEMORY)
203 return CURLE_OUT_OF_MEMORY;
205 if(status != SEC_E_OK && status != SEC_I_CONTINUE_NEEDED)
206 return CURLE_AUTH_ERROR;
208 if(memcmp(&context, krb5->context, sizeof(context))) {
209 Curl_pSecFn->DeleteSecurityContext(krb5->context);
211 memcpy(krb5->context, &context, sizeof(context));
212 }
214 if(resp_buf.cbBuffer) {
215 result = Curl_bufref_memdup0(out, resp_buf.pvBuffer, resp_buf.cbBuffer);
216 }
217 else if(mutual_auth)
218 Curl_bufref_set(out, "", 0, NULL);
219 else
220 Curl_bufref_set(out, NULL, 0, NULL);
222 return result;
225/*
226 * Curl_auth_create_gssapi_security_message()
227 *
228 * This is used to generate an already encoded GSSAPI (Kerberos V5) security
229 * token message ready for sending to the recipient.
230 *
231 * Parameters:
232 *
233 * data [in] - The session handle.
234 * authzid [in] - The authorization identity if some.
235 * chlg [in] - The challenge message.
236 * krb5 [in/out] - The Kerberos 5 data struct being used and modified.
237 * out [out] - The result storage.
238 *
239 * Returns CURLE_OK on success.
240 */
241CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
242 const char *authzid,
243 const struct bufref *chlg,
244 struct kerberos5data *krb5,
245 struct bufref *out)
247 CURLcode result = CURLE_OK;
248 size_t offset = 0;
249 size_t messagelen = 0;
250 size_t appdatalen = 0;
251 unsigned char *trailer = NULL;
252 unsigned char *message = NULL;
253 unsigned char *padding = NULL;
254 unsigned char *appdata = NULL;
255 SecBuffer input_buf[2];
256 SecBuffer wrap_buf[3];
257 SecBufferDesc input_desc;
258 SecBufferDesc wrap_desc;
259 unsigned char *indata;
260 unsigned long qop = 0;
261 unsigned long sec_layer = 0;
262 unsigned long max_size = 0;
263 SecPkgContext_Sizes sizes;
264 SECURITY_STATUS status;
266 /* Ensure we have a valid challenge message */
267 DEBUGASSERT(chlg);
268 if(!Curl_bufref_len(chlg)) {
269 infof(data, "GSSAPI handshake failure (empty security message)");
270 return CURLE_BAD_CONTENT_ENCODING;
271 }
273 /* Get our response size information */
274 status = Curl_pSecFn->QueryContextAttributes(krb5->context,
275 SECPKG_ATTR_SIZES, &sizes);
277 if(status == SEC_E_INSUFFICIENT_MEMORY)
278 return CURLE_OUT_OF_MEMORY;
280 if(status != SEC_E_OK)
281 return CURLE_AUTH_ERROR;
283 /* Setup the "input" security buffer */
284 input_desc.ulVersion = SECBUFFER_VERSION;
285 input_desc.cBuffers = 2;
286 input_desc.pBuffers = input_buf;
287 input_buf[0].BufferType = SECBUFFER_STREAM;
288 input_buf[0].pvBuffer = CURL_UNCONST(Curl_bufref_ptr(chlg));
289 input_buf[0].cbBuffer = curlx_uztoul(Curl_bufref_len(chlg));
290 input_buf[1].BufferType = SECBUFFER_DATA;
291 input_buf[1].pvBuffer = NULL;
292 input_buf[1].cbBuffer = 0;
294 /* Decrypt the inbound challenge and obtain the qop. The encrypted message
295 is decrypted in place, overwriting the original contents of its buffer.
296 The SECBUFFER_DATA receives a pointer to the message in
297 SECBUFFER_STREAM. */
298 status = Curl_pSecFn->DecryptMessage(krb5->context, &input_desc, 0, &qop);
299 if(status != SEC_E_OK) {
300 infof(data, "GSSAPI handshake failure (decryption failed)");
301 return CURLE_BAD_CONTENT_ENCODING;
302 }
304 /* Not 4 octets long so fail as per RFC4752 Section 3.1 */
305 if(input_buf[1].cbBuffer != 4) {
306 infof(data, "GSSAPI handshake failure (invalid security data)");
307 return CURLE_BAD_CONTENT_ENCODING;
308 }
310 /* Extract the security layer and the maximum message size */
311 indata = input_buf[1].pvBuffer;
312 sec_layer = indata[0];
313 max_size = ((unsigned long)indata[1] << 16) |
314 ((unsigned long)indata[2] << 8) | indata[3];
316 /* Process the security layer */
317 if(!(sec_layer & KERB_WRAP_NO_ENCRYPT)) {
318 infof(data, "GSSAPI handshake failure (invalid security layer)");
319 return CURLE_BAD_CONTENT_ENCODING;
320 }
321 sec_layer &= KERB_WRAP_NO_ENCRYPT; /* We do not support a security layer */
323 /* Process the maximum message size the server can receive */
324 if(max_size > 0) {
325 /* The server has told us it supports a maximum receive buffer, but as we
326 do not require one unless we are encrypting data, we tell the server
327 our receive buffer is zero. */
328 max_size = 0;
329 }
331 /* Allocate the trailer */
332 trailer = curlx_malloc(sizes.cbSecurityTrailer);
333 if(!trailer)
334 return CURLE_OUT_OF_MEMORY;
336 /* Allocate our message */
337 messagelen = 4;
338 if(authzid)
339 messagelen += strlen(authzid);
340 message = curlx_malloc(messagelen);
341 if(!message) {
342 result = CURLE_OUT_OF_MEMORY;
343 goto out;
344 }
346 /* Populate the message with the security layer and client supported receive
347 message size. */
348 message[0] = sec_layer & 0xFF;
349 message[1] = (max_size >> 16) & 0xFF;
350 message[2] = (max_size >> 8) & 0xFF;
351 message[3] = max_size & 0xFF;
353 /* If given, append the authorization identity. */
355 if(authzid && *authzid)
356 memcpy(message + 4, authzid, messagelen - 4);
358 /* Allocate the padding */
359 padding = curlx_malloc(sizes.cbBlockSize);
360 if(!padding) {
361 result = CURLE_OUT_OF_MEMORY;
362 goto out;
363 }
365 /* Setup the "authentication data" security buffer */
366 wrap_desc.ulVersion = SECBUFFER_VERSION;
367 wrap_desc.cBuffers = 3;
368 wrap_desc.pBuffers = wrap_buf;
369 wrap_buf[0].BufferType = SECBUFFER_TOKEN;
370 wrap_buf[0].pvBuffer = trailer;
371 wrap_buf[0].cbBuffer = sizes.cbSecurityTrailer;
372 wrap_buf[1].BufferType = SECBUFFER_DATA;
373 wrap_buf[1].pvBuffer = message;
374 wrap_buf[1].cbBuffer = curlx_uztoul(messagelen);
375 wrap_buf[2].BufferType = SECBUFFER_PADDING;
376 wrap_buf[2].pvBuffer = padding;
377 wrap_buf[2].cbBuffer = sizes.cbBlockSize;
379 /* Encrypt the data */
380 status = Curl_pSecFn->EncryptMessage(krb5->context, KERB_WRAP_NO_ENCRYPT,
381 &wrap_desc, 0);
382 if(status != SEC_E_OK) {
383 if(status == SEC_E_INSUFFICIENT_MEMORY)
384 result = CURLE_OUT_OF_MEMORY;
385 else
386 result = CURLE_AUTH_ERROR;
387 goto out;
388 }
390 /* Allocate the encryption (wrap) buffer */
391 appdatalen = wrap_buf[0].cbBuffer + wrap_buf[1].cbBuffer +
392 wrap_buf[2].cbBuffer;
393 appdata = curlx_malloc(appdatalen);
394 if(!appdata) {
395 result = CURLE_OUT_OF_MEMORY;
396 goto out;
397 }
399 /* Populate the encryption buffer */
400 memcpy(appdata, wrap_buf[0].pvBuffer, wrap_buf[0].cbBuffer);
401 offset += wrap_buf[0].cbBuffer;
402 memcpy(appdata + offset, wrap_buf[1].pvBuffer, wrap_buf[1].cbBuffer);
403 offset += wrap_buf[1].cbBuffer;
404 memcpy(appdata + offset, wrap_buf[2].pvBuffer, wrap_buf[2].cbBuffer);
406out:
407 /* Free all of our local buffers */
408 curlx_free(padding);
409 curlx_free(message);
410 curlx_free(trailer);
412 if(result)
413 return result;
415 /* Return the response. */
416 Curl_bufref_set(out, appdata, appdatalen, curl_free);
417 return CURLE_OK;
420/*
421 * Curl_auth_cleanup_gssapi()
422 *
423 * This is used to clean up the GSSAPI (Kerberos V5) specific data.
424 *
425 * Parameters:
426 *
427 * krb5 [in/out] - The Kerberos 5 data struct being cleaned up.
428 *
429 */
430void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5)
432 /* Free our security context */
433 if(krb5->context) {
434 Curl_pSecFn->DeleteSecurityContext(krb5->context);
435 curlx_safefree(krb5->context);
436 }
438 /* Free our credentials handle */
439 if(krb5->credentials) {
440 Curl_pSecFn->FreeCredentialsHandle(krb5->credentials);
441 curlx_safefree(krb5->credentials);
442 }
444 /* Free our identity */
445 Curl_sspi_free_identity(krb5->p_identity);
446 krb5->p_identity = NULL;
448 /* Free the SPN and output token */
449 curlx_safefree(krb5->spn);
450 curlx_safefree(krb5->output_token);
452 /* Reset any variables */
453 krb5->token_max = 0;
456#endif /* USE_WINDOWS_SSPI && USE_KERBEROS5 */
Diagnostics4 git calls · 35 ms
CallStatusSizeTime035 ms
discover200152 B2 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 · hit1 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=1
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=1
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=31
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=86
Open pack map
fetch2004.4 KiB · hit31 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=4462
git.response.cache=HIT
git.response.duration_ms=31
git.fetch.wants=24d2421be652e6aa0f5856d19cc9670d7699a176
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=4462
git.pkt.payload.max=4441
git.sideband.band1.bytes=4440
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
a5eafa66cb30b1bb
Request
b2e9982a…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format