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 "curl_setup.h"
26#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_DIGEST_AUTH)
28#include "urldata.h"
29#include "curl_trc.h"
30#include "strcase.h"
31#include "vauth/vauth.h"
32#include "http_digest.h"
33#include "curlx/strparse.h"
35/* Flush the Digest state if it was created for a different origin or with
36 different credentials than the ones now in use, then link the current
37 ones. */
38static void digest_flush_stale(struct Curl_easy *data,
39 struct digestdata *digest,
40 struct Curl_peer *peer,
41 struct Curl_creds *creds)
42{
43 bool flush = FALSE;
44 if(!digest->origin || !Curl_peer_equal(peer, digest->origin)) {
45 CURL_TRC_M(data, "http_digest, reset on peer change to %s:%u",
46 peer ? peer->hostname : "-",
47 (unsigned int)(peer ? peer->port : 0));
48 flush = TRUE;
49 }
50 else if(digest->creds && !Curl_creds_same(creds, digest->creds)) {
51 CURL_TRC_M(data, "http_digest, reset on creds change to %s",
52 creds ? creds->user : "-");
53 flush = TRUE;
54 }
56 if(flush) {
57 /* flush Digest state */
58 Curl_auth_digest_cleanup(digest);
59 }
61 Curl_peer_link(&digest->origin, peer);
62 Curl_creds_link(&digest->creds, creds);
63}
65/* Test example headers:
67 WWW-Authenticate: Digest realm="testrealm", nonce="1053604598"
68 Proxy-Authenticate: Digest realm="testrealm", nonce="1053604598"
69 */
70CURLcode Curl_input_digest(struct Curl_easy *data,
71 bool proxy,
72 const char *header) /* rest of the *-authenticate:
73 header */
74{
75 /* Point to the correct struct with this */
76 struct digestdata *digest;
77 struct Curl_peer *origin = NULL;
78 CURLcode result;
80 if(proxy) {
81 digest = &data->state.proxydigest;
82#ifdef CURL_DISABLE_PROXY
83 Curl_auth_digest_cleanup(digest);
84 return CURLE_OK; /* just ignore such a header without proxy support */
85#else
86 origin = data->conn->http_proxy.peer;
87#endif
88 }
89 else {
90 digest = &data->state.digest;
91 origin = data->state.origin;
92 }
94 if(!checkprefix("Digest", header) || !ISBLANK(header[6])) {
95 Curl_auth_digest_cleanup(digest);
96 return CURLE_AUTH_ERROR;
97 }
99 header += CURL_CSTRLEN("Digest");
100 curlx_str_passblanks(&header);
102 /* This resets the digest struct before decoding */
103 result = Curl_auth_decode_digest_http_message(header, digest);
104 /* Remember only the peer, the data we take in has no relation to creds
105 * at this time. We can use it even if creds change. */
106 Curl_peer_link(&digest->origin, origin);
107 return result;
108}
110CURLcode Curl_output_digest(struct Curl_easy *data,
111 bool proxy,
112 const unsigned char *request,
113 const unsigned char *uripath)
114{
115 struct Curl_peer *origin = NULL;
116 CURLcode result;
117 char *response;
118 size_t len;
119 bool have_chlg;
121 /* Point to the address of the pointer that holds the string to send to the
122 server, which is for a plain host or for an HTTP proxy */
123 char **allocuserpwd;
125 /* Point to the name and password for this */
126 struct Curl_creds *creds = NULL;
128 /* Point to the correct struct with this */
129 struct digestdata *digest;
130 struct auth *authp;
132 if(proxy) {
133#ifdef CURL_DISABLE_PROXY
134 return CURLE_NOT_BUILT_IN;
135#else
136 digest = &data->state.proxydigest;
137 origin = data->conn->http_proxy.peer;
138 creds = data->conn->http_proxy.creds;
139 allocuserpwd = &data->req.hd_proxy_auth;
140 authp = &data->state.authproxy;
141#endif
142 }
143 else {
144 DEBUGASSERT(data->state.origin);
145 digest = &data->state.digest;
146 origin = data->state.origin;
147 creds = data->state.creds;
148 allocuserpwd = &data->req.hd_auth;
149 authp = &data->state.authhost;
150 }
152 digest_flush_stale(data, digest, origin, creds);
153 curlx_safefree(*allocuserpwd);
155#ifdef USE_WINDOWS_SSPI
156 have_chlg = !!digest->input_token;
157#else
158 have_chlg = !!digest->nonce;
159#endif
161 if(!have_chlg) {
162 authp->done = FALSE;
163 return CURLE_OK;
164 }
166 result = Curl_auth_create_digest_http_message(data, creds, request,
167 uripath, digest,
168 &response, &len);
169 if(result)
170 return result;
172 *allocuserpwd = curl_maprintf("%sAuthorization: Digest %s\r\n",
173 proxy ? "Proxy-" : "", response);
174 curlx_free(response);
175 if(!*allocuserpwd)
176 return CURLE_OUT_OF_MEMORY;
178 authp->done = TRUE;
180 return CURLE_OK;
181}
183void Curl_http_auth_cleanup_digest(struct Curl_easy *data)
184{
185 Curl_auth_digest_cleanup(&data->state.digest);
186 Curl_auth_digest_cleanup(&data->state.proxydigest);
187}
189#endif
Diagnostics4 git calls · 31 ms
CallStatusSizeTime031 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 · hit4 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=4 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=4 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.1 KiB · hit24 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=24 git.response.bytes=2170 git.response.cache=HIT git.response.duration_ms=24 git.fetch.wants=e739b2be801cd166f4f69622a9f2ffc6d2b0edf2 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=2170 git.pkt.payload.max=2149 git.sideband.band1.bytes=2148 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
- a5e24bae6e650ecd
- Request
- 5ec9592d…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format