1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 2020 - 2022, Simon Josefsson, <simon@josefsson.org>, et al.
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.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 * SPDX-License-Identifier: curl
23 * RFC5802 SCRAM-SHA-1 authentication
25 ***************************************************************************/
27 #include "curl_setup.h"
31 #include <curl/curl.h>
33 #include "vauth/vauth.h"
39 /* The last 3 #include files should be in this order */
40 #include "curl_printf.h"
41 #include "curl_memory.h"
44 bool Curl_auth_gsasl_is_supported(struct Curl_easy *data,
46 struct gsasldata *gsasl)
50 res = gsasl_init(&gsasl->ctx);
52 failf(data, "gsasl init: %s\n", gsasl_strerror(res));
56 res = gsasl_client_start(gsasl->ctx, mech, &gsasl->client);
58 gsasl_done(gsasl->ctx);
65 CURLcode Curl_auth_gsasl_start(struct Curl_easy *data,
68 struct gsasldata *gsasl)
70 #if GSASL_VERSION_NUMBER >= 0x010b00
74 gsasl_property_set(gsasl->client, GSASL_AUTHID, userp);
75 #if GSASL_VERSION_NUMBER >= 0x010b00
77 failf(data, "setting AUTHID failed: %s\n", gsasl_strerror(res));
78 return CURLE_OUT_OF_MEMORY;
82 #if GSASL_VERSION_NUMBER >= 0x010b00
85 gsasl_property_set(gsasl->client, GSASL_PASSWORD, passwdp);
86 #if GSASL_VERSION_NUMBER >= 0x010b00
88 failf(data, "setting PASSWORD failed: %s\n", gsasl_strerror(res));
89 return CURLE_OUT_OF_MEMORY;
98 CURLcode Curl_auth_gsasl_token(struct Curl_easy *data,
99 const struct bufref *chlg,
100 struct gsasldata *gsasl,
107 res = gsasl_step(gsasl->client,
108 (const char *) Curl_bufref_ptr(chlg), Curl_bufref_len(chlg),
110 if(res != GSASL_OK && res != GSASL_NEEDS_MORE) {
111 failf(data, "GSASL step: %s\n", gsasl_strerror(res));
112 return CURLE_BAD_CONTENT_ENCODING;
115 Curl_bufref_set(out, response, outlen, gsasl_free);
119 void Curl_auth_gsasl_cleanup(struct gsasldata *gsasl)
121 gsasl_finish(gsasl->client);
122 gsasl->client = NULL;
124 gsasl_done(gsasl->ctx);