2012-05-26 00:49:25 +04:00
|
|
|
#ifndef HEADER_CURL_SASL_H
|
|
|
|
#define HEADER_CURL_SASL_H
|
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 15:51:48 +03:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2012-05-26 00:49:25 +04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 16:02:01 +03:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2012-05-26 00:49:25 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 12:16:50 +03:00
|
|
|
*
|
2012-05-26 00:49:25 +04:00
|
|
|
***************************************************************************/
|
|
|
|
|
2014-04-06 20:09:16 +04:00
|
|
|
#include <curl/curl.h>
|
|
|
|
|
2021-10-02 19:05:26 +03:00
|
|
|
#include "bufref.h"
|
|
|
|
|
2016-06-21 16:47:12 +03:00
|
|
|
struct Curl_easy;
|
2014-04-06 20:09:16 +04:00
|
|
|
struct connectdata;
|
2014-11-05 21:20:01 +03:00
|
|
|
|
2013-09-24 23:12:48 +04:00
|
|
|
/* Authentication mechanism flags */
|
|
|
|
#define SASL_MECH_LOGIN (1 << 0)
|
|
|
|
#define SASL_MECH_PLAIN (1 << 1)
|
|
|
|
#define SASL_MECH_CRAM_MD5 (1 << 2)
|
|
|
|
#define SASL_MECH_DIGEST_MD5 (1 << 3)
|
|
|
|
#define SASL_MECH_GSSAPI (1 << 4)
|
|
|
|
#define SASL_MECH_EXTERNAL (1 << 5)
|
|
|
|
#define SASL_MECH_NTLM (1 << 6)
|
|
|
|
#define SASL_MECH_XOAUTH2 (1 << 7)
|
2015-09-05 20:09:40 +03:00
|
|
|
#define SASL_MECH_OAUTHBEARER (1 << 8)
|
2020-12-24 21:48:45 +03:00
|
|
|
#define SASL_MECH_SCRAM_SHA_1 (1 << 9)
|
|
|
|
#define SASL_MECH_SCRAM_SHA_256 (1 << 10)
|
2013-09-24 23:12:48 +04:00
|
|
|
|
2015-01-27 19:24:55 +03:00
|
|
|
/* Authentication mechanism values */
|
|
|
|
#define SASL_AUTH_NONE 0
|
2021-05-11 12:11:40 +03:00
|
|
|
#define SASL_AUTH_ANY 0xffff
|
2015-11-12 22:45:24 +03:00
|
|
|
#define SASL_AUTH_DEFAULT (SASL_AUTH_ANY & ~SASL_MECH_EXTERNAL)
|
2015-01-27 19:24:55 +03:00
|
|
|
|
2013-09-24 23:12:48 +04:00
|
|
|
/* Authentication mechanism strings */
|
2021-10-02 19:05:26 +03:00
|
|
|
#define SASL_MECH_STRING_LOGIN "LOGIN"
|
|
|
|
#define SASL_MECH_STRING_PLAIN "PLAIN"
|
|
|
|
#define SASL_MECH_STRING_CRAM_MD5 "CRAM-MD5"
|
|
|
|
#define SASL_MECH_STRING_DIGEST_MD5 "DIGEST-MD5"
|
|
|
|
#define SASL_MECH_STRING_GSSAPI "GSSAPI"
|
|
|
|
#define SASL_MECH_STRING_EXTERNAL "EXTERNAL"
|
|
|
|
#define SASL_MECH_STRING_NTLM "NTLM"
|
|
|
|
#define SASL_MECH_STRING_XOAUTH2 "XOAUTH2"
|
|
|
|
#define SASL_MECH_STRING_OAUTHBEARER "OAUTHBEARER"
|
|
|
|
#define SASL_MECH_STRING_SCRAM_SHA_1 "SCRAM-SHA-1"
|
|
|
|
#define SASL_MECH_STRING_SCRAM_SHA_256 "SCRAM-SHA-256"
|
|
|
|
|
|
|
|
/* SASL flags */
|
|
|
|
#define SASL_FLAG_BASE64 0x0001 /* Messages are base64-encoded */
|
2013-09-24 23:12:48 +04:00
|
|
|
|
2015-01-20 19:33:05 +03:00
|
|
|
/* SASL machine states */
|
|
|
|
typedef enum {
|
|
|
|
SASL_STOP,
|
|
|
|
SASL_PLAIN,
|
|
|
|
SASL_LOGIN,
|
|
|
|
SASL_LOGIN_PASSWD,
|
2015-01-27 19:24:55 +03:00
|
|
|
SASL_EXTERNAL,
|
2015-01-20 19:33:05 +03:00
|
|
|
SASL_CRAMMD5,
|
|
|
|
SASL_DIGESTMD5,
|
|
|
|
SASL_DIGESTMD5_RESP,
|
|
|
|
SASL_NTLM,
|
|
|
|
SASL_NTLM_TYPE2MSG,
|
|
|
|
SASL_GSSAPI,
|
|
|
|
SASL_GSSAPI_TOKEN,
|
|
|
|
SASL_GSSAPI_NO_DATA,
|
2015-09-05 19:32:37 +03:00
|
|
|
SASL_OAUTH2,
|
2015-09-05 20:35:47 +03:00
|
|
|
SASL_OAUTH2_RESP,
|
2020-12-24 21:48:45 +03:00
|
|
|
SASL_GSASL,
|
2015-01-20 19:33:05 +03:00
|
|
|
SASL_CANCEL,
|
|
|
|
SASL_FINAL
|
|
|
|
} saslstate;
|
|
|
|
|
|
|
|
/* Progress indicator */
|
|
|
|
typedef enum {
|
|
|
|
SASL_IDLE,
|
|
|
|
SASL_INPROGRESS,
|
|
|
|
SASL_DONE
|
|
|
|
} saslprogress;
|
|
|
|
|
|
|
|
/* Protocol dependent SASL parameters */
|
|
|
|
struct SASLproto {
|
|
|
|
const char *service; /* The service name */
|
2021-10-02 19:05:26 +03:00
|
|
|
CURLcode (*sendauth)(struct Curl_easy *data, const char *mech,
|
|
|
|
const struct bufref *ir);
|
2015-01-20 19:33:05 +03:00
|
|
|
/* Send authentication command */
|
2021-10-02 19:05:26 +03:00
|
|
|
CURLcode (*contauth)(struct Curl_easy *data, const char *mech,
|
|
|
|
const struct bufref *contauth);
|
2015-01-20 19:33:05 +03:00
|
|
|
/* Send authentication continuation */
|
2021-10-02 19:05:26 +03:00
|
|
|
CURLcode (*cancelauth)(struct Curl_easy *data, const char *mech);
|
|
|
|
/* Cancel authentication. */
|
|
|
|
CURLcode (*getmessage)(struct Curl_easy *data, struct bufref *out);
|
2015-01-20 19:33:05 +03:00
|
|
|
/* Get SASL response message */
|
2021-10-02 19:05:26 +03:00
|
|
|
size_t maxirlen; /* Maximum initial response + mechanism length,
|
|
|
|
or zero if no max. This is normally the max
|
|
|
|
command length - other characters count.
|
|
|
|
This has to be zero for non-base64 protocols. */
|
|
|
|
int contcode; /* Code to receive when continuation is expected */
|
|
|
|
int finalcode; /* Code to receive upon authentication success */
|
|
|
|
unsigned short defmechs; /* Mechanisms enabled by default */
|
|
|
|
unsigned short flags; /* Configuration flags. */
|
2015-01-20 19:33:05 +03:00
|
|
|
};
|
|
|
|
|
2015-01-20 16:14:26 +03:00
|
|
|
/* Per-connection parameters */
|
|
|
|
struct SASL {
|
2015-01-20 19:33:05 +03:00
|
|
|
const struct SASLproto *params; /* Protocol dependent parameters */
|
2021-10-02 19:05:26 +03:00
|
|
|
saslstate state; /* Current machine state */
|
|
|
|
const char *curmech; /* Current mechanism id. */
|
2021-05-11 12:11:40 +03:00
|
|
|
unsigned short authmechs; /* Accepted authentication mechanisms */
|
|
|
|
unsigned short prefmech; /* Preferred authentication mechanism */
|
|
|
|
unsigned short authused; /* Auth mechanism used for the connection */
|
2023-01-01 13:26:22 +03:00
|
|
|
BIT(resetprefs); /* For URL auth option parsing. */
|
|
|
|
BIT(mutual_auth); /* Mutual authentication enabled (GSSAPI only) */
|
|
|
|
BIT(force_ir); /* Protocol always supports initial response */
|
2015-01-20 16:14:26 +03:00
|
|
|
};
|
|
|
|
|
2013-09-24 23:12:48 +04:00
|
|
|
/* This is used to test whether the line starts with the given mechanism */
|
|
|
|
#define sasl_mech_equal(line, wordlen, mech) \
|
|
|
|
(wordlen == (sizeof(mech) - 1) / sizeof(char) && \
|
|
|
|
!memcmp(line, mech, wordlen))
|
|
|
|
|
2012-06-02 14:07:58 +04:00
|
|
|
/* This is used to cleanup any libraries or curl modules used by the sasl
|
|
|
|
functions */
|
2021-10-02 19:05:26 +03:00
|
|
|
void Curl_sasl_cleanup(struct connectdata *conn, unsigned short authused);
|
2012-06-02 14:07:58 +04:00
|
|
|
|
2015-01-20 17:27:25 +03:00
|
|
|
/* Convert a mechanism name to a token */
|
2021-05-11 12:11:40 +03:00
|
|
|
unsigned short Curl_sasl_decode_mech(const char *ptr,
|
|
|
|
size_t maxlen, size_t *len);
|
2015-01-20 17:27:25 +03:00
|
|
|
|
|
|
|
/* Parse the URL login options */
|
|
|
|
CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
|
|
|
|
const char *value, size_t len);
|
|
|
|
|
|
|
|
/* Initializes an SASL structure */
|
2021-10-02 19:05:26 +03:00
|
|
|
void Curl_sasl_init(struct SASL *sasl, struct Curl_easy *data,
|
|
|
|
const struct SASLproto *params);
|
2015-01-20 19:33:05 +03:00
|
|
|
|
2015-01-27 19:24:55 +03:00
|
|
|
/* Check if we have enough auth data and capabilities to authenticate */
|
2022-02-14 19:33:50 +03:00
|
|
|
bool Curl_sasl_can_authenticate(struct SASL *sasl, struct Curl_easy *data);
|
2015-01-27 19:24:55 +03:00
|
|
|
|
2015-01-20 19:33:05 +03:00
|
|
|
/* Calculate the required login details for SASL authentication */
|
2021-01-21 02:38:52 +03:00
|
|
|
CURLcode Curl_sasl_start(struct SASL *sasl, struct Curl_easy *data,
|
2015-01-20 19:33:05 +03:00
|
|
|
bool force_ir, saslprogress *progress);
|
|
|
|
|
|
|
|
/* Continue an SASL authentication */
|
2021-01-21 02:38:52 +03:00
|
|
|
CURLcode Curl_sasl_continue(struct SASL *sasl, struct Curl_easy *data,
|
2015-01-22 23:47:38 +03:00
|
|
|
int code, saslprogress *progress);
|
2015-01-20 17:27:25 +03:00
|
|
|
|
2012-05-26 00:49:25 +04:00
|
|
|
#endif /* HEADER_CURL_SASL_H */
|