1 #ifndef HEADER_CURL_SASL_H
2 #define HEADER_CURL_SASL_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 2012 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at http://curl.haxx.se/docs/copyright.html.
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ***************************************************************************/
25 #include <curl/curl.h>
30 #if !defined(CURL_DISABLE_CRYPTO_AUTH)
38 #if defined(USE_KERBEROS5)
42 /* Authentication mechanism flags */
43 #define SASL_MECH_LOGIN (1 << 0)
44 #define SASL_MECH_PLAIN (1 << 1)
45 #define SASL_MECH_CRAM_MD5 (1 << 2)
46 #define SASL_MECH_DIGEST_MD5 (1 << 3)
47 #define SASL_MECH_GSSAPI (1 << 4)
48 #define SASL_MECH_EXTERNAL (1 << 5)
49 #define SASL_MECH_NTLM (1 << 6)
50 #define SASL_MECH_XOAUTH2 (1 << 7)
52 /* Authentication mechanism values */
53 #define SASL_AUTH_NONE 0
54 #define SASL_AUTH_ANY ~0U
55 #define SASL_AUTH_DEFAULT (SASL_AUTH_ANY & \
56 ~(SASL_MECH_EXTERNAL | SASL_MECH_XOAUTH2))
58 /* Authentication mechanism strings */
59 #define SASL_MECH_STRING_LOGIN "LOGIN"
60 #define SASL_MECH_STRING_PLAIN "PLAIN"
61 #define SASL_MECH_STRING_CRAM_MD5 "CRAM-MD5"
62 #define SASL_MECH_STRING_DIGEST_MD5 "DIGEST-MD5"
63 #define SASL_MECH_STRING_GSSAPI "GSSAPI"
64 #define SASL_MECH_STRING_EXTERNAL "EXTERNAL"
65 #define SASL_MECH_STRING_NTLM "NTLM"
66 #define SASL_MECH_STRING_XOAUTH2 "XOAUTH2"
68 #if !defined(CURL_DISABLE_CRYPTO_AUTH)
69 #define DIGEST_MAX_VALUE_LENGTH 256
70 #define DIGEST_MAX_CONTENT_LENGTH 1024
75 CURLDIGESTALGO_MD5SESS
78 /* SASL machine states */
98 /* Progress indicator */
105 /* Protocol dependent SASL parameters */
107 const char *service; /* The service name */
108 int contcode; /* Code to receive when continuation is expected */
109 int finalcode; /* Code to receive upon authentication success */
110 size_t maxirlen; /* Maximum initial response length */
111 CURLcode (*sendauth)(struct connectdata *conn,
112 const char *mech, const char *ir);
113 /* Send authentication command */
114 CURLcode (*sendcont)(struct connectdata *conn, const char *contauth);
115 /* Send authentication continuation */
116 void (*getmessage)(char *buffer, char **outptr);
117 /* Get SASL response message */
120 /* Per-connection parameters */
122 const struct SASLproto *params; /* Protocol dependent parameters */
123 saslstate state; /* Current machine state */
124 unsigned int authmechs; /* Accepted authentication mechanisms */
125 unsigned int prefmech; /* Preferred authentication mechanism */
126 unsigned int authused; /* Auth mechanism used for the connection */
127 bool resetprefs; /* For URL auth option parsing. */
128 bool mutual_auth; /* Mutual authentication enabled (GSSAPI only) */
129 bool force_ir; /* Protocol always supports initial response */
132 /* This is used to test whether the line starts with the given mechanism */
133 #define sasl_mech_equal(line, wordlen, mech) \
134 (wordlen == (sizeof(mech) - 1) / sizeof(char) && \
135 !memcmp(line, mech, wordlen))
137 /* This is used to build a SPN string */
138 #if !defined(USE_WINDOWS_SSPI)
139 char *Curl_sasl_build_spn(const char *service, const char *instance);
141 TCHAR *Curl_sasl_build_spn(const char *service, const char *instance);
144 /* This is used to extract the realm from a challenge message */
145 int Curl_sasl_digest_get_pair(const char *str, char *value, char *content,
146 const char **endptr);
148 #if defined(HAVE_GSSAPI)
149 char *Curl_sasl_build_gssapi_spn(const char *service, const char *host);
152 #ifndef CURL_DISABLE_CRYPTO_AUTH
154 /* This is used to generate a base64 encoded DIGEST-MD5 response message */
155 CURLcode Curl_sasl_create_digest_md5_message(struct SessionHandle *data,
160 char **outptr, size_t *outlen);
162 /* This is used to decode a HTTP DIGEST challenge message */
163 CURLcode Curl_sasl_decode_digest_http_message(const char *chlg,
164 struct digestdata *digest);
166 /* This is used to generate a HTTP DIGEST response message */
167 CURLcode Curl_sasl_create_digest_http_message(struct SessionHandle *data,
170 const unsigned char *request,
171 const unsigned char *uri,
172 struct digestdata *digest,
173 char **outptr, size_t *outlen);
175 /* This is used to clean up the digest specific data */
176 void Curl_sasl_digest_cleanup(struct digestdata *digest);
180 /* This is used to generate a base64 encoded NTLM type-1 message */
181 CURLcode Curl_sasl_create_ntlm_type1_message(const char *userp,
183 struct ntlmdata *ntlm,
187 /* This is used to decode a base64 encoded NTLM type-2 message */
188 CURLcode Curl_sasl_decode_ntlm_type2_message(struct SessionHandle *data,
189 const char *type2msg,
190 struct ntlmdata *ntlm);
192 /* This is used to generate a base64 encoded NTLM type-3 message */
193 CURLcode Curl_sasl_create_ntlm_type3_message(struct SessionHandle *data,
196 struct ntlmdata *ntlm,
197 char **outptr, size_t *outlen);
199 /* This is used to clean up the ntlm specific data */
200 void Curl_sasl_ntlm_cleanup(struct ntlmdata *ntlm);
202 #endif /* USE_NTLM */
204 #if defined(USE_KERBEROS5)
205 /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) user token
207 CURLcode Curl_sasl_create_gssapi_user_message(struct SessionHandle *data,
213 struct kerberos5data *krb5,
214 char **outptr, size_t *outlen);
216 /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) security
218 CURLcode Curl_sasl_create_gssapi_security_message(struct SessionHandle *data,
220 struct kerberos5data *krb5,
224 /* This is used to clean up the gssapi specific data */
225 void Curl_sasl_gssapi_cleanup(struct kerberos5data *krb5);
226 #endif /* USE_KERBEROS5 */
228 /* This is used to cleanup any libraries or curl modules used by the sasl
230 void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused);
232 /* Convert a mechanism name to a token */
233 unsigned int Curl_sasl_decode_mech(const char *ptr,
234 size_t maxlen, size_t *len);
236 /* Parse the URL login options */
237 CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
238 const char *value, size_t len);
240 /* Initializes an SASL structure */
241 void Curl_sasl_init(struct SASL *sasl, const struct SASLproto *params);
243 /* Check if we have enough auth data and capabilities to authenticate */
244 bool Curl_sasl_can_authenticate(struct SASL *sasl, struct connectdata *conn);
246 /* Calculate the required login details for SASL authentication */
247 CURLcode Curl_sasl_start(struct SASL *sasl, struct connectdata *conn,
248 bool force_ir, saslprogress *progress);
250 /* Continue an SASL authentication */
251 CURLcode Curl_sasl_continue(struct SASL *sasl, struct connectdata *conn,
252 int code, saslprogress *progress);
254 #endif /* HEADER_CURL_SASL_H */