2020-12-25 02:48:45 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 - 2021, Simon Josefsson, <simon@josefsson.org>, et al.
|
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* RFC5802 SCRAM-SHA-1 authentication
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "curl_setup.h"
|
|
|
|
|
|
|
|
#ifdef USE_GSASL
|
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
#include "vauth/vauth.h"
|
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
|
|
|
|
#include <gsasl.h>
|
|
|
|
|
|
|
|
/* The last #include files should be: */
|
|
|
|
#include "curl_memory.h"
|
|
|
|
#include "memdebug.h"
|
|
|
|
|
|
|
|
bool Curl_auth_gsasl_is_supported(struct Curl_easy *data,
|
|
|
|
const char *mech,
|
|
|
|
struct gsasldata *gsasl)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = gsasl_init(&gsasl->ctx);
|
|
|
|
if(res != GSASL_OK) {
|
|
|
|
failf(data, "gsasl init: %s\n", gsasl_strerror(res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = gsasl_client_start(gsasl->ctx, mech, &gsasl->client);
|
|
|
|
if(res != GSASL_OK) {
|
|
|
|
gsasl_done(gsasl->ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode Curl_auth_gsasl_start(struct Curl_easy *data,
|
|
|
|
const char *userp,
|
|
|
|
const char *passwdp,
|
|
|
|
struct gsasldata *gsasl)
|
|
|
|
{
|
2021-02-11 02:50:36 +08:00
|
|
|
#if GSASL_VERSION_NUMBER >= 0x010b00
|
2020-12-25 02:48:45 +08:00
|
|
|
int res;
|
|
|
|
res =
|
|
|
|
#endif
|
2021-02-11 02:50:36 +08:00
|
|
|
gsasl_property_set(gsasl->client, GSASL_AUTHID, userp);
|
|
|
|
#if GSASL_VERSION_NUMBER >= 0x010b00
|
2020-12-25 02:48:45 +08:00
|
|
|
if(res != GSASL_OK) {
|
2021-02-11 02:50:36 +08:00
|
|
|
failf(data, "setting AUTHID failed: %s\n", gsasl_strerror(res));
|
2020-12-25 02:48:45 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-02-11 02:50:36 +08:00
|
|
|
#if GSASL_VERSION_NUMBER >= 0x010b00
|
2020-12-25 02:48:45 +08:00
|
|
|
res =
|
|
|
|
#endif
|
|
|
|
gsasl_property_set(gsasl->client, GSASL_PASSWORD, passwdp);
|
2021-02-11 02:50:36 +08:00
|
|
|
#if GSASL_VERSION_NUMBER >= 0x010b00
|
2020-12-25 02:48:45 +08:00
|
|
|
if(res != GSASL_OK) {
|
2021-02-11 02:50:36 +08:00
|
|
|
failf(data, "setting PASSWORD failed: %s\n", gsasl_strerror(res));
|
2020-12-25 02:48:45 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-02-11 02:50:36 +08:00
|
|
|
(void)data;
|
|
|
|
|
2020-12-25 02:48:45 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode Curl_auth_gsasl_token(struct Curl_easy *data,
|
2021-03-18 03:09:55 +08:00
|
|
|
const struct bufref *chlg,
|
2020-12-25 02:48:45 +08:00
|
|
|
struct gsasldata *gsasl,
|
2021-03-18 03:09:55 +08:00
|
|
|
struct bufref *out)
|
2020-12-25 02:48:45 +08:00
|
|
|
{
|
2021-02-11 02:50:36 +08:00
|
|
|
int res;
|
2020-12-25 02:48:45 +08:00
|
|
|
char *response;
|
2021-03-18 03:09:55 +08:00
|
|
|
size_t outlen;
|
2020-12-25 02:48:45 +08:00
|
|
|
|
2021-02-11 02:50:36 +08:00
|
|
|
res = gsasl_step(gsasl->client,
|
2021-03-18 03:09:55 +08:00
|
|
|
(const char *) Curl_bufref_ptr(chlg), Curl_bufref_len(chlg),
|
|
|
|
&response, &outlen);
|
2021-02-11 02:50:36 +08:00
|
|
|
if(res != GSASL_OK && res != GSASL_NEEDS_MORE) {
|
|
|
|
failf(data, "GSASL step: %s\n", gsasl_strerror(res));
|
2020-12-25 02:48:45 +08:00
|
|
|
return CURLE_BAD_CONTENT_ENCODING;
|
|
|
|
}
|
|
|
|
|
2021-03-18 03:09:55 +08:00
|
|
|
Curl_bufref_set(out, response, outlen, gsasl_free);
|
|
|
|
return CURLE_OK;
|
2020-12-25 02:48:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Curl_auth_gsasl_cleanup(struct gsasldata *gsasl)
|
|
|
|
{
|
|
|
|
gsasl_finish(gsasl->client);
|
|
|
|
gsasl->client = NULL;
|
|
|
|
|
|
|
|
gsasl_done(gsasl->ctx);
|
|
|
|
gsasl->ctx = NULL;
|
|
|
|
}
|
|
|
|
#endif
|