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 * RFC2195 CRAM-MD5 authentication
24 * RFC2617 Basic and Digest Access Authentication
25 * RFC2831 DIGEST-MD5 authentication
26 * RFC4422 Simple Authentication and Security Layer (SASL)
27 * RFC4616 PLAIN authentication
28 * RFC5802 SCRAM-SHA-1 authentication
29 * RFC7677 SCRAM-SHA-256 authentication
30 * RFC6749 OAuth 2.0 Authorization Framework
31 * RFC7628 A Set of SASL Mechanisms for OAuth
32 * Draft LOGIN SASL Mechanism <draft-murchison-sasl-login-00.txt>
33 *
34 ***************************************************************************/
35#include "curl_setup.h"
37#if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \
38 !defined(CURL_DISABLE_POP3) || \
39 (!defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP))
41#include "urldata.h"
42#include "curlx/base64.h"
43#include "vauth/vauth.h"
44#include "cfilters.h"
45#include "curl_sasl.h"
46#include "curl_trc.h"
48/* Supported mechanisms */
49static const struct {
50 const char *name; /* Name */
51 size_t len; /* Name length */
52 unsigned short bit; /* Flag bit */
53} mechtable[] = {
54 { "LOGIN", 5, SASL_MECH_LOGIN },
55 { "PLAIN", 5, SASL_MECH_PLAIN },
56 { "CRAM-MD5", 8, SASL_MECH_CRAM_MD5 },
57 { "DIGEST-MD5", 10, SASL_MECH_DIGEST_MD5 },
58 { "GSSAPI", 6, SASL_MECH_GSSAPI },
59 { "EXTERNAL", 8, SASL_MECH_EXTERNAL },
60 { "XOAUTH2", 7, SASL_MECH_XOAUTH2 },
61 { "OAUTHBEARER", 11, SASL_MECH_OAUTHBEARER },
62 { "SCRAM-SHA-1", 11, SASL_MECH_SCRAM_SHA_1 },
63 { "SCRAM-SHA-256",13, SASL_MECH_SCRAM_SHA_256 },
64 { ZERO_NULL, 0, 0 }
65};
67/*
68 * Curl_sasl_decode_mech()
69 *
70 * Convert a SASL mechanism name into a token.
71 *
72 * Parameters:
73 *
74 * ptr [in] - The mechanism string.
75 * maxlen [in] - Maximum mechanism string length.
76 * len [out] - If not NULL, effective name length.
77 *
78 * Returns the SASL mechanism token or 0 if no match.
79 */
80unsigned short Curl_sasl_decode_mech(const char *ptr, size_t maxlen,
81 size_t *len)
82{
83 unsigned int i;
84 char c;
86 for(i = 0; mechtable[i].name; i++) {
87 if(maxlen >= mechtable[i].len &&
88 curl_strnequal(ptr, mechtable[i].name, mechtable[i].len)) {
89 if(len)
90 *len = mechtable[i].len;
92 if(maxlen == mechtable[i].len)
93 return mechtable[i].bit;
95 c = ptr[mechtable[i].len];
96 if(!ISUPPER(c) && !ISDIGIT(c) && c != '-' && c != '_')
97 return mechtable[i].bit;
98 }
99 }
101 return 0;
102}
104/*
105 * Curl_sasl_parse_url_auth_option()
106 *
107 * Parse the URL login options.
108 */
109CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
110 const char *value, size_t len)
111{
112 CURLcode result = CURLE_OK;
113 size_t mechlen;
115 if(!len)
116 return CURLE_URL_MALFORMAT;
118 if(sasl->resetprefs) {
119 sasl->resetprefs = FALSE;
120 sasl->prefmech = SASL_AUTH_NONE;
121 }
123 if(!strncmp(value, "*", len))
124 sasl->prefmech = SASL_AUTH_DEFAULT;
125 else {
126 unsigned short mechbit = Curl_sasl_decode_mech(value, len, &mechlen);
127 if(mechbit && mechlen == len)
128 sasl->prefmech |= mechbit;
129 else
130 result = CURLE_URL_MALFORMAT;
131 }
133 return result;
134}
136/*
137 * Curl_sasl_init()
138 *
139 * Initializes the SASL structure.
140 */
141void Curl_sasl_init(struct SASL *sasl, struct Curl_easy *data,
142 const struct SASLproto *params)
143{
144 uint32_t auth = data->set.httpauth;
146 sasl->params = params; /* Set protocol dependent parameters */
147 sasl->state = SASL_STOP; /* Not yet running */
148 sasl->curmech = NULL; /* No mechanism yet. */
149 sasl->authmechs = SASL_AUTH_NONE; /* No known authentication mechanism yet */
150 sasl->prefmech = params->defmechs; /* Default preferred mechanisms */
151 sasl->authused = SASL_AUTH_NONE; /* The authentication mechanism used */
152 sasl->resetprefs = TRUE; /* Reset prefmech upon AUTH parsing. */
153 sasl->mutual_auth = FALSE; /* No mutual authentication (GSSAPI only) */
154 sasl->force_ir = FALSE; /* Respect external option */
156 if(auth != CURLAUTH_BASIC) {
157 unsigned short mechs = SASL_AUTH_NONE;
159 /* If some usable http authentication options have been set, determine
160 new defaults from them. */
161 if(auth & CURLAUTH_BASIC)
162 mechs |= SASL_MECH_PLAIN | SASL_MECH_LOGIN;
163 if(auth & CURLAUTH_DIGEST)
164 mechs |= SASL_MECH_DIGEST_MD5;
165 if(auth & CURLAUTH_BEARER)
166 mechs |= SASL_MECH_OAUTHBEARER | SASL_MECH_XOAUTH2;
167 if(auth & CURLAUTH_GSSAPI)
168 mechs |= SASL_MECH_GSSAPI;
170 if(mechs != SASL_AUTH_NONE)
171 sasl->prefmech = mechs;
172 }
173}
175/*
176 * sasl_state()
177 *
178 * This is the ONLY way to change SASL state!
179 */
180static void sasl_state(struct SASL *sasl, struct Curl_easy *data,
181 saslstate newstate)
182{
183#if defined(DEBUGBUILD) && defined(CURLVERBOSE)
184 /* for debug purposes */
185 static const char * const names[] = {
186 "STOP",
187 "PLAIN",
188 "LOGIN",
189 "LOGIN_PASSWD",
190 "EXTERNAL",
191 "CRAMMD5",
192 "DIGESTMD5",
193 "DIGESTMD5_RESP",
194 "GSSAPI",
195 "GSSAPI_TOKEN",
196 "GSSAPI_NO_DATA",
197 "OAUTH2",
198 "OAUTH2_RESP",
199 "GSASL",
200 "CANCEL",
201 "FINAL",
202 /* LAST */
203 };
205 if(sasl->state != newstate)
206 infof(data, "SASL %p state change from %s to %s",
207 (void *)sasl, names[sasl->state], names[newstate]);
208#else
209 (void)data;
210#endif
212 sasl->state = newstate;
213}
215#if defined(USE_GSASL) || defined(USE_KERBEROS5) || \
216 !defined(CURL_DISABLE_DIGEST_AUTH)
217/* Get the SASL server message and convert it to binary. */
218static CURLcode get_server_message(struct SASL *sasl, struct Curl_easy *data,
219 struct bufref *out)
220{
221 CURLcode result = CURLE_OK;
223 result = sasl->params->getmessage(data, out);
224 if(!result && (sasl->params->flags & SASL_FLAG_BASE64)) {
225 const char *serverdata = Curl_bufref_ptr(out);
227 if(!*serverdata)
228 Curl_bufref_set(out, NULL, 0, NULL);
229 else {
230 unsigned char *msg;
231 size_t msglen;
233 result = curlx_base64_decode(serverdata, &msg, &msglen);
234 if(!result)
235 Curl_bufref_set(out, msg, msglen, curl_free);
236 }
237 }
238 return result;
239}
240#endif
242/* Encode the outgoing SASL message. */
243static CURLcode build_message(struct SASL *sasl, struct bufref *msg)
244{
245 CURLcode result = CURLE_OK;
247 if(sasl->params->flags & SASL_FLAG_BASE64) {
248 if(!Curl_bufref_ptr(msg)) /* Empty message. */
249 Curl_bufref_set(msg, "", 0, NULL);
250 else if(Curl_bufref_len(msg)) {
251 char *base64;
252 size_t base64len;
254 result = curlx_base64_encode(Curl_bufref_uptr(msg),
255 Curl_bufref_len(msg), &base64, &base64len);
256 if(!result)
257 Curl_bufref_set(msg, base64, base64len, curl_free);
258 }
259 }
261 return result;
262}
264/*
265 * Curl_sasl_can_authenticate()
266 *
267 * Check if we have enough auth data and capabilities to authenticate.
268 */
269bool Curl_sasl_can_authenticate(struct SASL *sasl, struct Curl_easy *data)
270{
271 /* Have credentials been provided? */
272 if(data->conn->creds)
273 return TRUE;
275 /* EXTERNAL can authenticate without a username and/or password */
276 if(sasl->authmechs & sasl->prefmech & SASL_MECH_EXTERNAL)
277 return TRUE;
279 return FALSE;
280}
282struct sasl_ctx {
283 struct SASL *sasl;
284 struct connectdata *conn;
285 unsigned short enabledmechs;
286 const char *mech;
287 saslstate state1;
288 saslstate state2;
289 struct bufref resp;
290 CURLcode result;
291};
293static bool sasl_choose_external(struct Curl_easy *data, struct sasl_ctx *sctx)
294{
295 if((sctx->enabledmechs & SASL_MECH_EXTERNAL) &&
296 !Curl_creds_has_passwd(sctx->conn->creds)) {
297 sctx->mech = SASL_MECH_STRING_EXTERNAL;
298 sctx->state1 = SASL_EXTERNAL;
299 sctx->sasl->authused = SASL_MECH_EXTERNAL;
301 if(sctx->sasl->force_ir || data->set.sasl_ir)
302 Curl_auth_create_external_message(
303 Curl_creds_user(sctx->conn->creds), &sctx->resp);
304 return TRUE;
305 }
306 return FALSE;
307}
309#ifdef USE_KERBEROS5
310static bool sasl_choose_krb5(struct Curl_easy *data, struct sasl_ctx *sctx)
311{
312 if((sctx->enabledmechs & SASL_MECH_GSSAPI) &&
313 Curl_auth_is_gssapi_supported() &&
314 Curl_auth_user_contains_domain(sctx->conn->creds)) {
315 const char *service = Curl_creds_has_sasl_service(sctx->conn->creds) ?
316 Curl_creds_sasl_service(sctx->conn->creds) : sctx->sasl->params->service;
318 sctx->sasl->mutual_auth = FALSE;
319 sctx->mech = SASL_MECH_STRING_GSSAPI;
320 sctx->state1 = SASL_GSSAPI;
321 sctx->state2 = SASL_GSSAPI_TOKEN;
322 sctx->sasl->authused = SASL_MECH_GSSAPI;
324 if(sctx->sasl->force_ir || data->set.sasl_ir) {
325 struct kerberos5data *krb5 = Curl_auth_krb5_get(sctx->conn);
326 sctx->result = !krb5 ? CURLE_OUT_OF_MEMORY :
327 Curl_auth_create_gssapi_user_message(data, sctx->conn->creds,
328 service,
329 sctx->conn->origin->hostname,
330 (bool)sctx->sasl->mutual_auth,
331 NULL, krb5, &sctx->resp);
332 }
333 return TRUE;
334 }
335 return FALSE;
336}
337#endif /* USE_KERBEROS5 */
339#ifdef USE_GSASL
340static bool sasl_choose_gsasl(struct Curl_easy *data, struct sasl_ctx *sctx)
341{
342 struct gsasldata *gsasl;
343 struct bufref nullmsg;
345 if((sctx->enabledmechs &
346 (SASL_MECH_SCRAM_SHA_256 | SASL_MECH_SCRAM_SHA_1))) {
347 gsasl = Curl_auth_gsasl_get(sctx->conn);
348 if(!gsasl) {
349 sctx->result = CURLE_OUT_OF_MEMORY;
350 return TRUE; /* attempted, but failed */
351 }
353 if((sctx->enabledmechs & SASL_MECH_SCRAM_SHA_256) &&
354 Curl_auth_gsasl_is_supported(data, SASL_MECH_STRING_SCRAM_SHA_256,
355 gsasl)) {
356 sctx->mech = SASL_MECH_STRING_SCRAM_SHA_256;
357 sctx->sasl->authused = SASL_MECH_SCRAM_SHA_256;
358 }
359 else if((sctx->enabledmechs & SASL_MECH_SCRAM_SHA_1) &&
360 Curl_auth_gsasl_is_supported(data, SASL_MECH_STRING_SCRAM_SHA_1,
361 gsasl)) {
362 sctx->mech = SASL_MECH_STRING_SCRAM_SHA_1;
363 sctx->sasl->authused = SASL_MECH_SCRAM_SHA_1;
364 }
365 else
366 return FALSE;
368 Curl_bufref_init(&nullmsg);
369 sctx->state1 = SASL_GSASL;
370 sctx->state2 = SASL_GSASL;
371 sctx->result = Curl_auth_gsasl_start(data, sctx->conn->creds, gsasl);
372 if(!sctx->result && (sctx->sasl->force_ir || data->set.sasl_ir))
373 sctx->result = Curl_auth_gsasl_token(data, &nullmsg, gsasl, &sctx->resp);
374 return TRUE;
375 }
376 return FALSE;
377}
379#endif /* USE_GSASL */
381#ifndef CURL_DISABLE_DIGEST_AUTH
382static bool sasl_choose_digest(struct Curl_easy *data, struct sasl_ctx *sctx)
383{
384 (void)data;
385 if((sctx->enabledmechs & SASL_MECH_DIGEST_MD5) &&
386 Curl_auth_is_digest_supported()) {
387 sctx->mech = SASL_MECH_STRING_DIGEST_MD5;
388 sctx->state1 = SASL_DIGESTMD5;
389 sctx->sasl->authused = SASL_MECH_DIGEST_MD5;
390 return TRUE;
391 }
392 else if(sctx->enabledmechs & SASL_MECH_CRAM_MD5) {
393 sctx->mech = SASL_MECH_STRING_CRAM_MD5;
394 sctx->state1 = SASL_CRAMMD5;
395 sctx->sasl->authused = SASL_MECH_CRAM_MD5;
396 return TRUE;
397 }
398 return FALSE;
399}
400#endif /* !CURL_DISABLE_DIGEST_AUTH */
402static bool sasl_choose_oauth(struct Curl_easy *data, struct sasl_ctx *sctx)
403{
404 if(Curl_creds_has_oauth_bearer(data->state.creds) &&
405 (sctx->enabledmechs & SASL_MECH_OAUTHBEARER)) {
406 const char *hostname;
407 int port;
408 Curl_conn_get_current_host(data, FIRSTSOCKET, &hostname, &port);
410 sctx->mech = SASL_MECH_STRING_OAUTHBEARER;
411 sctx->state1 = SASL_OAUTH2;
412 sctx->state2 = SASL_OAUTH2_RESP;
413 sctx->sasl->authused = SASL_MECH_OAUTHBEARER;
415 if(sctx->sasl->force_ir || data->set.sasl_ir)
416 sctx->result =
417 Curl_auth_create_oauth_bearer_message(sctx->conn->creds,
418 hostname, port, &sctx->resp);
419 return TRUE;
420 }
421 return FALSE;
422}
424static bool sasl_choose_oauth2(struct Curl_easy *data, struct sasl_ctx *sctx)
425{
426 if(Curl_creds_has_oauth_bearer(sctx->conn->creds) &&
427 (sctx->enabledmechs & SASL_MECH_XOAUTH2)) {
428 sctx->mech = SASL_MECH_STRING_XOAUTH2;
429 sctx->state1 = SASL_OAUTH2;
430 sctx->sasl->authused = SASL_MECH_XOAUTH2;
432 if(sctx->sasl->force_ir || data->set.sasl_ir)
433 sctx->result = Curl_auth_create_xoauth_bearer_message(
434 sctx->conn->creds, &sctx->resp);
435 return TRUE;
436 }
437 return FALSE;
438}
440static bool sasl_choose_plain(struct Curl_easy *data, struct sasl_ctx *sctx)
441{
442 if(sctx->enabledmechs & SASL_MECH_PLAIN) {
443 sctx->mech = SASL_MECH_STRING_PLAIN;
444 sctx->state1 = SASL_PLAIN;
445 sctx->sasl->authused = SASL_MECH_PLAIN;
447 if(sctx->sasl->force_ir || data->set.sasl_ir)
448 sctx->result =
449 Curl_auth_create_plain_message(sctx->conn->creds, &sctx->resp);
450 return TRUE;
451 }
452 return FALSE;
453}
455static bool sasl_choose_login(struct Curl_easy *data, struct sasl_ctx *sctx)
456{
457 if(sctx->enabledmechs & SASL_MECH_LOGIN) {
458 sctx->mech = SASL_MECH_STRING_LOGIN;
459 sctx->state1 = SASL_LOGIN;
460 sctx->state2 = SASL_LOGIN_PASSWD;
461 sctx->sasl->authused = SASL_MECH_LOGIN;
463 if(sctx->sasl->force_ir || data->set.sasl_ir)
464 Curl_auth_create_login_message(
465 Curl_creds_user(sctx->conn->creds), &sctx->resp);
466 return TRUE;
467 }
468 return FALSE;
469}
471/*
472 * Curl_sasl_start()
473 *
474 * Calculate the required login details for SASL authentication.
475 */
476CURLcode Curl_sasl_start(struct SASL *sasl, struct Curl_easy *data,
477 bool force_ir, saslprogress *progress)
478{
479 struct sasl_ctx sctx;
481 sasl->force_ir = force_ir; /* Latch for future use */
482 sasl->authused = 0; /* No mechanism used yet */
483 *progress = SASL_IDLE;
485 memset(&sctx, 0, sizeof(sctx));
486 sctx.sasl = sasl;
487 sctx.conn = data->conn;
488 Curl_bufref_init(&sctx.resp);
489 sctx.enabledmechs = sasl->authmechs & sasl->prefmech;
490 sctx.state1 = SASL_STOP;
491 sctx.state2 = SASL_FINAL;
493 /* Calculate the supported authentication mechanism, by decreasing order of
494 security, as well as the initial response where appropriate */
495 if(sasl_choose_external(data, &sctx) ||
496#ifdef USE_KERBEROS5
497 sasl_choose_krb5(data, &sctx) ||
498#endif
499#ifdef USE_GSASL
500 sasl_choose_gsasl(data, &sctx) ||
501#endif
502#ifndef CURL_DISABLE_DIGEST_AUTH
503 sasl_choose_digest(data, &sctx) ||
504#endif
505 sasl_choose_oauth(data, &sctx) ||
506 sasl_choose_oauth2(data, &sctx) ||
507 sasl_choose_plain(data, &sctx) ||
508 sasl_choose_login(data, &sctx)) {
509 /* selected, either we have a mechanism or a failure */
510 DEBUGASSERT(sctx.mech || sctx.result);
511 }
513 if(!sctx.result && sctx.mech) {
514 sasl->curmech = sctx.mech;
515 if(Curl_bufref_ptr(&sctx.resp))
516 sctx.result = build_message(sasl, &sctx.resp);
518 if(sasl->params->maxirlen &&
519 strlen(sctx.mech) + Curl_bufref_len(&sctx.resp) >
520 sasl->params->maxirlen)
521 Curl_bufref_free(&sctx.resp);
523 if(!sctx.result)
524 sctx.result = sasl->params->sendauth(data, sctx.mech, &sctx.resp);
526 if(!sctx.result) {
527 *progress = SASL_INPROGRESS;
528 sasl_state(sasl, data, Curl_bufref_ptr(&sctx.resp) ?
529 sctx.state2 : sctx.state1);
530 }
531 }
533 Curl_bufref_free(&sctx.resp);
534 return sctx.result;
535}
537/*
538 * Curl_sasl_continue()
539 *
540 * Continue the authentication.
541 */
542CURLcode Curl_sasl_continue(struct SASL *sasl, struct Curl_easy *data,
543 int code, saslprogress *progress)
544{
545 CURLcode result = CURLE_OK;
546 struct connectdata *conn = data->conn;
547 saslstate newstate = SASL_FINAL;
548 struct bufref resp;
549 const char *hostname;
550 int port;
551 struct bufref serverdata;
553 Curl_conn_get_current_host(data, FIRSTSOCKET, &hostname, &port);
554 Curl_bufref_init(&serverdata);
555 Curl_bufref_init(&resp);
556 *progress = SASL_INPROGRESS;
558 if(sasl->state == SASL_FINAL) {
559 if(code != sasl->params->finalcode)
560 result = CURLE_LOGIN_DENIED;
561 *progress = SASL_DONE;
562 sasl_state(sasl, data, SASL_STOP);
563 return result;
564 }
566 if(sasl->state != SASL_CANCEL && sasl->state != SASL_OAUTH2_RESP &&
567 code != sasl->params->contcode) {
568 *progress = SASL_DONE;
569 sasl_state(sasl, data, SASL_STOP);
570 return CURLE_LOGIN_DENIED;
571 }
573 switch(sasl->state) {
574 case SASL_STOP:
575 *progress = SASL_DONE;
576 return result;
577 case SASL_PLAIN:
578 result = Curl_auth_create_plain_message(conn->creds, &resp);
579 break;
580 case SASL_LOGIN:
581 Curl_auth_create_login_message(Curl_creds_user(conn->creds), &resp);
582 newstate = SASL_LOGIN_PASSWD;
583 break;
584 case SASL_LOGIN_PASSWD:
585 Curl_auth_create_login_message(Curl_creds_passwd(conn->creds), &resp);
586 break;
587 case SASL_EXTERNAL:
588 Curl_auth_create_external_message(Curl_creds_user(conn->creds), &resp);
589 break;
590#ifdef USE_GSASL
591 case SASL_GSASL:
592 result = get_server_message(sasl, data, &serverdata);
593 if(!result) {
594 struct gsasldata *gsasl = Curl_auth_gsasl_get(conn);
595 result = !gsasl ? CURLE_OUT_OF_MEMORY :
596 Curl_auth_gsasl_token(data, &serverdata, gsasl, &resp);
597 }
598 if(!result && Curl_bufref_len(&resp) > 0)
599 newstate = SASL_GSASL;
600 break;
601#endif
602#ifndef CURL_DISABLE_DIGEST_AUTH
603 case SASL_CRAMMD5:
604 result = get_server_message(sasl, data, &serverdata);
605 if(!result)
606 result = Curl_auth_create_cram_md5_message(&serverdata, conn->creds,
607 &resp);
608 break;
609 case SASL_DIGESTMD5:
610 result = get_server_message(sasl, data, &serverdata);
611 if(!result)
612 result = Curl_auth_create_digest_md5_message(data, &serverdata,
613 conn->creds,
614 sasl->params->service,
615 &resp);
616 if(!result && (sasl->params->flags & SASL_FLAG_BASE64))
617 newstate = SASL_DIGESTMD5_RESP;
618 break;
619 case SASL_DIGESTMD5_RESP:
620 /* Keep response NULL to output an empty line. */
621 break;
622#endif
624#ifdef USE_KERBEROS5
625 case SASL_GSSAPI: {
626 struct kerberos5data *krb5 = Curl_auth_krb5_get(conn);
627 result = !krb5 ? CURLE_OUT_OF_MEMORY :
628 Curl_auth_create_gssapi_user_message(data, conn->creds,
629 sasl->params->service,
630 conn->origin->hostname,
631 (bool)sasl->mutual_auth, NULL,
632 krb5, &resp);
633 newstate = SASL_GSSAPI_TOKEN;
634 break;
635 }
636 case SASL_GSSAPI_TOKEN:
637 result = get_server_message(sasl, data, &serverdata);
638 if(!result) {
639 struct kerberos5data *krb5 = Curl_auth_krb5_get(conn);
640 if(!krb5)
641 result = CURLE_OUT_OF_MEMORY;
642 else if(sasl->mutual_auth) {
643 /* Decode the user token challenge and create the optional response
644 message */
645 result = Curl_auth_create_gssapi_user_message(data, NULL,
646 NULL, NULL,
647 (bool)sasl->mutual_auth,
648 &serverdata,
649 krb5, &resp);
650 newstate = SASL_GSSAPI_NO_DATA;
651 }
652 else
653 /* Decode the security challenge and create the response message */
654 result = Curl_auth_create_gssapi_security_message(
655 data, Curl_creds_sasl_authzid(conn->creds), &serverdata,
656 krb5, &resp);
657 }
658 break;
659 case SASL_GSSAPI_NO_DATA:
660 /* Decode the security challenge and create the response message */
661 result = get_server_message(sasl, data, &serverdata);
662 if(!result) {
663 struct kerberos5data *krb5 = Curl_auth_krb5_get(conn);
664 if(!krb5)
665 result = CURLE_OUT_OF_MEMORY;
666 else
667 result = Curl_auth_create_gssapi_security_message(
668 data, Curl_creds_sasl_authzid(conn->creds), &serverdata,
669 krb5, &resp);
670 }
671 break;
672#endif
674 case SASL_OAUTH2:
675 /* Create the authorization message */
676 if(sasl->authused == SASL_MECH_OAUTHBEARER) {
677 result = Curl_auth_create_oauth_bearer_message(conn->creds,
678 hostname,
679 port,
680 &resp);
682 /* Failures maybe sent by the server as continuations for OAUTHBEARER */
683 newstate = SASL_OAUTH2_RESP;
684 }
685 else
686 result = Curl_auth_create_xoauth_bearer_message(conn->creds,
687 &resp);
688 break;
690 case SASL_OAUTH2_RESP:
691 /* The continuation is optional so check the response code */
692 if(code == sasl->params->finalcode) {
693 /* Final response was received so we are done */
694 *progress = SASL_DONE;
695 sasl_state(sasl, data, SASL_STOP);
696 return result;
697 }
698 else if(code == sasl->params->contcode) {
699 /* Acknowledge the continuation by sending a 0x01 response. */
700 Curl_bufref_set(&resp, "\x01", 1, NULL);
701 break;
702 }
703 else {
704 *progress = SASL_DONE;
705 sasl_state(sasl, data, SASL_STOP);
706 return CURLE_LOGIN_DENIED;
707 }
709 case SASL_CANCEL:
710 /* Remove the offending mechanism from the supported list */
711 sasl->authmechs &= (unsigned short)~sasl->authused;
712 sasl->authused = SASL_AUTH_NONE;
713 sasl->curmech = NULL;
715 /* Start an alternative SASL authentication */
716 return Curl_sasl_start(sasl, data, (bool)sasl->force_ir, progress);
717 default:
718 failf(data, "Unsupported SASL authentication mechanism");
719 result = CURLE_UNSUPPORTED_PROTOCOL; /* Should not happen */
720 break;
721 }
723 Curl_bufref_free(&serverdata);
725 switch(result) {
726 case CURLE_BAD_CONTENT_ENCODING:
727 /* Cancel dialog */
728 result = sasl->params->cancelauth(data, sasl->curmech);
729 newstate = SASL_CANCEL;
730 break;
731 case CURLE_OK:
732 result = build_message(sasl, &resp);
733 if(!result)
734 result = sasl->params->contauth(data, sasl->curmech, &resp);
735 break;
736 default:
737 newstate = SASL_STOP; /* Stop on error */
738 *progress = SASL_DONE;
739 break;
740 }
742 Curl_bufref_free(&resp);
744 sasl_state(sasl, data, newstate);
746 return result;
747}
749#ifdef CURLVERBOSE
750static void sasl_unchosen(struct Curl_easy *data, unsigned short mech,
751 unsigned short enabledmechs,
752 bool built_in, bool platform,
753 const char *param_missing)
754{
755 const char *mname = NULL;
756 size_t i;
758 if(!(enabledmechs & mech))
759 return;
761 for(i = 0; mechtable[i].name; ++i) {
762 if(mechtable[i].bit == mech) {
763 mname = mechtable[i].name;
764 break;
765 }
766 }
767 if(!mname) /* should not happen */
768 return;
769 if(!built_in)
770 infof(data, "SASL: %s not builtin", mname);
771 else if(!platform)
772 infof(data, "SASL: %s not supported by the platform/libraries", mname);
773 else {
774 if(param_missing)
775 infof(data, "SASL: %s is missing %s", mname, param_missing);
776 if(!Curl_creds_has_user(data->conn->creds))
777 infof(data, "SASL: %s is missing username", mname);
778 }
779}
780#endif /* CURLVERBOSE */
782CURLcode Curl_sasl_is_blocked(struct SASL *sasl, struct Curl_easy *data)
783{
784#ifdef CURLVERBOSE
785#ifdef USE_KERBEROS5
786#define CURL_SASL_KERBEROS5 TRUE
787#else
788#define CURL_SASL_KERBEROS5 FALSE
789#endif
790#ifdef USE_GSASL
791#define CURL_SASL_GASL TRUE
792#else
793#define CURL_SASL_GASL FALSE
794#endif
795#ifdef CURL_DISABLE_DIGEST_AUTH
796#define CURL_SASL_DIGEST TRUE
797#else
798#define CURL_SASL_DIGEST FALSE
799#endif
801 /* Failing SASL authentication is a pain. Give a helping hand if
802 * we were unable to select an AUTH mechanism.
803 * `sasl->authmechs` are mechanisms offered by the peer
804 * `sasl->prefmech` are mechanisms preferred by us */
805 unsigned short enabledmechs = sasl->authmechs & sasl->prefmech;
807 if(!sasl->authmechs)
808 infof(data, "SASL: no auth mechanism was offered or recognized");
809 else if(!enabledmechs)
810 infof(data, "SASL: no overlap between offered and configured "
811 "auth mechanisms");
812 else {
813 infof(data, "SASL: no auth mechanism offered could be selected");
814 if((enabledmechs & SASL_MECH_EXTERNAL) &&
815 Curl_creds_has_passwd(data->conn->creds))
816 infof(data, "SASL: auth EXTERNAL not chosen with password");
817 sasl_unchosen(data, SASL_MECH_GSSAPI, enabledmechs,
818 CURL_SASL_KERBEROS5, Curl_auth_is_gssapi_supported(), NULL);
819 sasl_unchosen(data, SASL_MECH_SCRAM_SHA_256, enabledmechs,
820 CURL_SASL_GASL, FALSE, NULL);
821 sasl_unchosen(data, SASL_MECH_SCRAM_SHA_1, enabledmechs,
822 CURL_SASL_GASL, FALSE, NULL);
823 sasl_unchosen(data, SASL_MECH_DIGEST_MD5, enabledmechs,
824 CURL_SASL_DIGEST, Curl_auth_is_digest_supported(), NULL);
825 sasl_unchosen(data, SASL_MECH_CRAM_MD5, enabledmechs,
826 CURL_SASL_DIGEST, TRUE, NULL);
827 sasl_unchosen(data, SASL_MECH_OAUTHBEARER, enabledmechs, TRUE, TRUE,
828 Curl_creds_has_oauth_bearer(data->conn->creds) ?
829 NULL : "CURLOPT_XOAUTH2_BEARER");
830 sasl_unchosen(data, SASL_MECH_XOAUTH2, enabledmechs, TRUE, TRUE,
831 Curl_creds_has_oauth_bearer(data->conn->creds) ?
832 NULL : "CURLOPT_XOAUTH2_BEARER");
833 }
834#endif /* CURLVERBOSE */
835 (void)sasl;
836 (void)data;
837 return CURLE_LOGIN_DENIED;
838}
840#endif /* protocols are enabled that use SASL */
Diagnostics4 git calls · 129 ms
CallStatusSizeTime0129 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs 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 · 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
fetch2006.9 KiB124 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=124 git.response.bytes=7062 git.response.cache=MISS git.response.duration_ms=124 git.fetch.wants=1d3a3aea0f8172b61265097435224eb2477ac51b 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=7062 git.pkt.payload.max=7041 git.sideband.band1.bytes=7040 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
- a5e318660d1b3e6e
- Request
- 732ad8f8…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format