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(USE_SPNEGO)
28#include "urldata.h"
29#include "cfilters.h"
30#include "curl_trc.h"
31#include "http_negotiate.h"
32#include "vauth/vauth.h"
33#include "vtls/vtls.h"
34#include "curlx/strparse.h"
37static void http_auth_nego_reset(struct connectdata *conn,
38 struct negotiatedata *neg_ctx,
39 bool proxy)
40{
41 if(proxy)
42 conn->proxy_negotiate_state = CURL_NEGO_AUTH_NONE;
43 else {
44 conn->http_negotiate_state = CURL_NEGO_AUTH_NONE;
45 Curl_peer_unlink(&conn->creds_origin);
46 Curl_creds_unlink(&conn->creds);
47 }
48 if(neg_ctx)
49 Curl_auth_cleanup_spnego(neg_ctx);
50}
52CURLcode Curl_input_negotiate(struct Curl_easy *data, struct connectdata *conn,
53 bool proxy, const char *header)
54{
55 CURLcode result;
56 size_t len;
58 /* Point to credentials and host */
59 struct Curl_creds *creds = NULL;
60 const char *host;
62 /* Point to the correct struct with this */
63 struct negotiatedata *neg_ctx;
64 uint8_t state;
66 if(proxy) {
67#ifndef CURL_DISABLE_PROXY
68 creds = conn->http_proxy.creds;
69 host = conn->http_proxy.peer->hostname;
70 state = conn->proxy_negotiate_state;
71#else
72 return CURLE_NOT_BUILT_IN;
73#endif
74 }
75 else {
76 creds = data->state.creds;
77 host = data->state.origin->hostname;
78 state = conn->http_negotiate_state;
79 }
81 neg_ctx = Curl_auth_nego_get(conn, proxy);
82 if(!neg_ctx)
83 return CURLE_OUT_OF_MEMORY;
85 /* Obtain the input token, if any */
86 header += CURL_CSTRLEN("Negotiate");
87 curlx_str_passblanks(&header);
89 len = strlen(header);
90 neg_ctx->havenegdata = len != 0;
91 if(!len) {
92 if(state == CURL_NEGO_AUTH_SUCC) {
93 infof(data, "Negotiate auth restarted");
94 http_auth_nego_reset(conn, neg_ctx, proxy);
95 }
96 else if(state != CURL_NEGO_AUTH_NONE) {
97 /* The server rejected our authentication and has not supplied any more
98 negotiation mechanisms */
99 http_auth_nego_reset(conn, neg_ctx, proxy);
100 return CURLE_LOGIN_DENIED;
101 }
102 }
104 /* Supports SSL channel binding for Windows ISS extended protection */
105#ifdef USE_WINDOWS_SSPI
106 neg_ctx->sslContext = conn->sslContext;
107#endif
108 /* Check if the connection is using SSL and get the channel binding data */
109#ifdef GSS_C_CHANNEL_BOUND_FLAG
110#ifdef USE_SSL
111 curlx_dyn_init(&neg_ctx->channel_binding_data, SSL_CB_MAX_SIZE + 1);
112 if(Curl_conn_is_ssl(conn, FIRSTSOCKET)) {
113 result = Curl_ssl_get_channel_binding(data, FIRSTSOCKET,
114 &neg_ctx->channel_binding_data);
115 if(result) {
116 http_auth_nego_reset(conn, neg_ctx, proxy);
117 return result;
118 }
119 }
120#else
121 curlx_dyn_init(&neg_ctx->channel_binding_data, 1);
122#endif /* USE_SSL */
123#endif /* GSS_C_CHANNEL_BOUND_FLAG */
125 /* Initialize the security context and decode our challenge */
126 result = Curl_auth_decode_spnego_message(data, creds, "HTTP",
127 host, header, neg_ctx);
129#ifdef GSS_C_CHANNEL_BOUND_FLAG
130 curlx_dyn_free(&neg_ctx->channel_binding_data);
131#endif
133 if(result)
134 http_auth_nego_reset(conn, neg_ctx, proxy);
136 if(!result && !proxy) {
137 /* Start it up. From this time onwards, the connection is tied
138 * tp the credentials used. */
139 if(conn->creds_origin &&
140 !Curl_peer_equal(conn->creds_origin, data->state.origin)) {
141 DEBUGASSERT(0); /* should not happen. */
142 return CURLE_FAILED_INIT;
143 }
144 if(conn->creds && !Curl_creds_same(creds, conn->creds)) {
145 DEBUGASSERT(0); /* should not happen. */
146 return CURLE_FAILED_INIT;
147 }
148 Curl_peer_link(&conn->creds_origin, data->state.origin);
149 Curl_creds_link(&conn->creds, creds);
150 }
152 return result;
153}
155CURLcode Curl_output_negotiate(struct Curl_easy *data,
156 struct connectdata *conn, bool proxy)
157{
158 struct negotiatedata *neg_ctx;
159 struct auth *authp;
160 uint8_t *state;
161 char *base64 = NULL;
162 size_t len = 0;
163 char *userp;
164 CURLcode result;
166 if(proxy) {
167#ifndef CURL_DISABLE_PROXY
168 authp = &data->state.authproxy;
169 state = &conn->proxy_negotiate_state;
170#else
171 return CURLE_NOT_BUILT_IN;
172#endif
173 }
174 else {
175 authp = &data->state.authhost;
176 state = &conn->http_negotiate_state;
177 }
178 neg_ctx = Curl_auth_nego_get(conn, proxy);
179 if(!neg_ctx)
180 return CURLE_OUT_OF_MEMORY;
182 authp->done = FALSE;
184 if(*state == CURL_NEGO_AUTH_RECV) {
185 if(neg_ctx->havenegdata) {
186 neg_ctx->havemultiplerequests = TRUE;
187 }
188 }
189 else if(*state == CURL_NEGO_AUTH_SUCC) {
190 if(!neg_ctx->havenoauthpersist) {
191 neg_ctx->noauthpersist = !neg_ctx->havemultiplerequests;
192 }
193 }
195 if(neg_ctx->noauthpersist ||
196 (*state != CURL_NEGO_AUTH_DONE && *state != CURL_NEGO_AUTH_SUCC)) {
198 if(neg_ctx->noauthpersist && *state == CURL_NEGO_AUTH_SUCC) {
199 infof(data, "Curl_output_negotiate, "
200 "no persistent authentication: cleanup existing context");
201 http_auth_nego_reset(conn, neg_ctx, proxy);
202 }
203 if(!neg_ctx->context) {
204 result = Curl_input_negotiate(data, conn, proxy, "Negotiate");
205 if(result == CURLE_AUTH_ERROR) {
206 /* negotiate auth failed, let's continue unauthenticated to stay
207 * compatible with the behavior before curl-7_64_0-158-g6c6035532 */
208 authp->done = TRUE;
209 return CURLE_OK;
210 }
211 else if(result)
212 return result;
213 }
215 result = Curl_auth_create_spnego_message(neg_ctx, &base64, &len);
216 if(result)
217 return result;
219 userp = curl_maprintf("%sAuthorization: Negotiate %s\r\n",
220 proxy ? "Proxy-" : "", base64);
222 if(proxy) {
223#ifndef CURL_DISABLE_PROXY
224 curlx_free(data->req.hd_proxy_auth);
225 data->req.hd_proxy_auth = userp;
226#endif
227 }
228 else {
229 curlx_free(data->req.hd_auth);
230 data->req.hd_auth = userp;
231 }
233 curlx_free(base64);
235 if(!userp) {
236 return CURLE_OUT_OF_MEMORY;
237 }
239 *state = CURL_NEGO_AUTH_SENT;
240#ifdef HAVE_GSSAPI
241 if(neg_ctx->status == GSS_S_COMPLETE ||
242 neg_ctx->status == GSS_S_CONTINUE_NEEDED) {
243 *state = CURL_NEGO_AUTH_DONE;
244 }
245#else
246#ifdef USE_WINDOWS_SSPI
247 if(neg_ctx->status == SEC_E_OK ||
248 neg_ctx->status == SEC_I_CONTINUE_NEEDED) {
249 *state = CURL_NEGO_AUTH_DONE;
250 }
251#endif
252#endif
253 }
255 if(*state == CURL_NEGO_AUTH_DONE || *state == CURL_NEGO_AUTH_SUCC) {
256 /* connection is already authenticated,
257 * do not send a header in future requests */
258 authp->done = TRUE;
259 }
261 neg_ctx->havenegdata = FALSE;
263 return CURLE_OK;
264}
266#endif /* !CURL_DISABLE_HTTP && USE_SPNEGO */
Diagnostics4 git calls · 29 ms
CallStatusSizeTime029 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=2 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 · hit23 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=22 git.response.bytes=2699 git.response.cache=HIT git.response.duration_ms=23 git.fetch.wants=66c7af47f8105cdfba07af61633049abd280bab0 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=2699 git.pkt.payload.max=2678 git.sideband.band1.bytes=2677 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
- a5e2c1c28b6389da
- Request
- d73d683a…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format