2012-05-26 04:49:25 +08:00
|
|
|
#ifndef HEADER_CURL_SASL_H
|
|
|
|
#define HEADER_CURL_SASL_H
|
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2021-01-09 00:58:15 +08:00
|
|
|
* Copyright (C) 2012 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2012-05-26 04:49:25 +08: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 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2012-05-26 04:49:25 +08: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.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2014-04-07 00:09:16 +08:00
|
|
|
#include <curl/curl.h>
|
|
|
|
|
2021-10-03 00:05:26 +08:00
|
|
|
#include "bufref.h"
|
|
|
|
|
2016-06-21 21:47:12 +08:00
|
|
|
struct Curl_easy;
|
2014-04-07 00:09:16 +08:00
|
|
|
struct connectdata;
|
2014-11-06 02:20:01 +08:00
|
|
|
|
2013-09-25 03:12:48 +08: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-06 01:09:40 +08:00
|
|
|
#define SASL_MECH_OAUTHBEARER (1 << 8)
|
2020-12-25 02:48:45 +08:00
|
|
|
#define SASL_MECH_SCRAM_SHA_1 (1 << 9)
|
|
|
|
#define SASL_MECH_SCRAM_SHA_256 (1 << 10)
|
2013-09-25 03:12:48 +08:00
|
|
|
|
2015-01-28 00:24:55 +08:00
|
|
|
/* Authentication mechanism values */
|
|
|
|
#define SASL_AUTH_NONE 0
|
2021-05-11 17:11:40 +08:00
|
|
|
#define SASL_AUTH_ANY 0xffff
|
2015-11-13 03:45:24 +08:00
|
|
|
#define SASL_AUTH_DEFAULT (SASL_AUTH_ANY & ~SASL_MECH_EXTERNAL)
|
2015-01-28 00:24:55 +08:00
|
|
|
|
2013-09-25 03:12:48 +08:00
|
|
|
/* Authentication mechanism strings */
|
2021-10-03 00:05:26 +08: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-25 03:12:48 +08:00
|
|
|
|
2015-01-21 00:33:05 +08:00
|
|
|
/* SASL machine states */
|
|
|
|
typedef enum {
|
|
|
|
SASL_STOP,
|
|
|
|
SASL_PLAIN,
|
|
|
|
SASL_LOGIN,
|
|
|
|
SASL_LOGIN_PASSWD,
|
2015-01-28 00:24:55 +08:00
|
|
|
SASL_EXTERNAL,
|
2015-01-21 00:33:05 +08:00
|
|
|
SASL_CRAMMD5,
|
|
|
|
SASL_DIGESTMD5,
|
|
|
|
SASL_DIGESTMD5_RESP,
|
|
|
|
SASL_NTLM,
|
|
|
|
SASL_NTLM_TYPE2MSG,
|
|
|
|
SASL_GSSAPI,
|
|
|
|
SASL_GSSAPI_TOKEN,
|
|
|
|
SASL_GSSAPI_NO_DATA,
|
2015-09-06 00:32:37 +08:00
|
|
|
SASL_OAUTH2,
|
2015-09-06 01:35:47 +08:00
|
|
|
SASL_OAUTH2_RESP,
|
2020-12-25 02:48:45 +08:00
|
|
|
SASL_GSASL,
|
2015-01-21 00:33:05 +08: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-03 00:05:26 +08:00
|
|
|
CURLcode (*sendauth)(struct Curl_easy *data, const char *mech,
|
|
|
|
const struct bufref *ir);
|
2015-01-21 00:33:05 +08:00
|
|
|
/* Send authentication command */
|
2021-10-03 00:05:26 +08:00
|
|
|
CURLcode (*contauth)(struct Curl_easy *data, const char *mech,
|
|
|
|
const struct bufref *contauth);
|
2015-01-21 00:33:05 +08:00
|
|
|
/* Send authentication continuation */
|
2021-10-03 00:05:26 +08:00
|
|
|
CURLcode (*cancelauth)(struct Curl_easy *data, const char *mech);
|
|
|
|
/* Cancel authentication. */
|
|
|
|
CURLcode (*getmessage)(struct Curl_easy *data, struct bufref *out);
|
2015-01-21 00:33:05 +08:00
|
|
|
/* Get SASL response message */
|
2021-10-03 00:05:26 +08: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-21 00:33:05 +08:00
|
|
|
};
|
|
|
|
|
2015-01-20 21:14:26 +08:00
|
|
|
/* Per-connection parameters */
|
|
|
|
struct SASL {
|
2015-01-21 00:33:05 +08:00
|
|
|
const struct SASLproto *params; /* Protocol dependent parameters */
|
2021-10-03 00:05:26 +08:00
|
|
|
saslstate state; /* Current machine state */
|
|
|
|
const char *curmech; /* Current mechanism id. */
|
2021-05-11 17:11:40 +08:00
|
|
|
unsigned short authmechs; /* Accepted authentication mechanisms */
|
|
|
|
unsigned short prefmech; /* Preferred authentication mechanism */
|
|
|
|
unsigned short authused; /* Auth mechanism used for the connection */
|
2021-10-03 00:05:26 +08:00
|
|
|
bool resetprefs; /* For URL auth option parsing. */
|
|
|
|
bool mutual_auth; /* Mutual authentication enabled (GSSAPI only) */
|
|
|
|
bool force_ir; /* Protocol always supports initial response */
|
2015-01-20 21:14:26 +08:00
|
|
|
};
|
|
|
|
|
2013-09-25 03:12:48 +08: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 18:07:58 +08:00
|
|
|
/* This is used to cleanup any libraries or curl modules used by the sasl
|
|
|
|
functions */
|
2021-10-03 00:05:26 +08:00
|
|
|
void Curl_sasl_cleanup(struct connectdata *conn, unsigned short authused);
|
2012-06-02 18:07:58 +08:00
|
|
|
|
2015-01-20 22:27:25 +08:00
|
|
|
/* Convert a mechanism name to a token */
|
2021-05-11 17:11:40 +08:00
|
|
|
unsigned short Curl_sasl_decode_mech(const char *ptr,
|
|
|
|
size_t maxlen, size_t *len);
|
2015-01-20 22:27:25 +08: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-03 00:05:26 +08:00
|
|
|
void Curl_sasl_init(struct SASL *sasl, struct Curl_easy *data,
|
|
|
|
const struct SASLproto *params);
|
2015-01-21 00:33:05 +08:00
|
|
|
|
2015-01-28 00:24:55 +08:00
|
|
|
/* Check if we have enough auth data and capabilities to authenticate */
|
|
|
|
bool Curl_sasl_can_authenticate(struct SASL *sasl, struct connectdata *conn);
|
|
|
|
|
2015-01-21 00:33:05 +08:00
|
|
|
/* Calculate the required login details for SASL authentication */
|
2021-01-21 07:38:52 +08:00
|
|
|
CURLcode Curl_sasl_start(struct SASL *sasl, struct Curl_easy *data,
|
2015-01-21 00:33:05 +08:00
|
|
|
bool force_ir, saslprogress *progress);
|
|
|
|
|
|
|
|
/* Continue an SASL authentication */
|
2021-01-21 07:38:52 +08:00
|
|
|
CURLcode Curl_sasl_continue(struct SASL *sasl, struct Curl_easy *data,
|
2015-01-23 04:47:38 +08:00
|
|
|
int code, saslprogress *progress);
|
2015-01-20 22:27:25 +08:00
|
|
|
|
2012-05-26 04:49:25 +08:00
|
|
|
#endif /* HEADER_CURL_SASL_H */
|