1 #ifndef HEADER_CURL_SASL_H
2 #define HEADER_CURL_SASL_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 2012 - 2014, 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 values */
43 #define SASL_AUTH_NONE 0
44 #define SASL_AUTH_ANY ~0U
46 /* Authentication mechanism flags */
47 #define SASL_MECH_LOGIN (1 << 0)
48 #define SASL_MECH_PLAIN (1 << 1)
49 #define SASL_MECH_CRAM_MD5 (1 << 2)
50 #define SASL_MECH_DIGEST_MD5 (1 << 3)
51 #define SASL_MECH_GSSAPI (1 << 4)
52 #define SASL_MECH_EXTERNAL (1 << 5)
53 #define SASL_MECH_NTLM (1 << 6)
54 #define SASL_MECH_XOAUTH2 (1 << 7)
56 /* Authentication mechanism strings */
57 #define SASL_MECH_STRING_LOGIN "LOGIN"
58 #define SASL_MECH_STRING_PLAIN "PLAIN"
59 #define SASL_MECH_STRING_CRAM_MD5 "CRAM-MD5"
60 #define SASL_MECH_STRING_DIGEST_MD5 "DIGEST-MD5"
61 #define SASL_MECH_STRING_GSSAPI "GSSAPI"
62 #define SASL_MECH_STRING_EXTERNAL "EXTERNAL"
63 #define SASL_MECH_STRING_NTLM "NTLM"
64 #define SASL_MECH_STRING_XOAUTH2 "XOAUTH2"
68 CURLDIGESTALGO_MD5SESS
71 /* This is used to test whether the line starts with the given mechanism */
72 #define sasl_mech_equal(line, wordlen, mech) \
73 (wordlen == (sizeof(mech) - 1) / sizeof(char) && \
74 !memcmp(line, mech, wordlen))
76 /* This is used to build a SPN string */
77 #if !defined(USE_WINDOWS_SSPI)
78 char *Curl_sasl_build_spn(const char *service, const char *instance);
80 TCHAR *Curl_sasl_build_spn(const char *service, const char *instance);
83 /* This is used to generate a base64 encoded PLAIN authentication message */
84 CURLcode Curl_sasl_create_plain_message(struct SessionHandle *data,
87 char **outptr, size_t *outlen);
89 /* This is used to generate a base64 encoded LOGIN authentication message
90 containing either the user name or password details */
91 CURLcode Curl_sasl_create_login_message(struct SessionHandle *data,
92 const char *valuep, char **outptr,
95 #ifndef CURL_DISABLE_CRYPTO_AUTH
96 /* This is used to decode a base64 encoded CRAM-MD5 challange message */
97 CURLcode Curl_sasl_decode_cram_md5_message(const char *chlg64, char **outptr,
100 /* This is used to generate a base64 encoded CRAM-MD5 response message */
101 CURLcode Curl_sasl_create_cram_md5_message(struct SessionHandle *data,
105 char **outptr, size_t *outlen);
107 /* This is used to generate a base64 encoded DIGEST-MD5 response message */
108 CURLcode Curl_sasl_create_digest_md5_message(struct SessionHandle *data,
113 char **outptr, size_t *outlen);
115 /* This is used to decode a HTTP DIGEST challenge message */
116 CURLcode Curl_sasl_decode_digest_http_message(const char *chlg,
117 struct digestdata *digest);
119 /* This is used to generate a HTTP DIGEST response message */
120 CURLcode Curl_sasl_create_digest_http_message(struct SessionHandle *data,
123 const unsigned char *request,
124 const unsigned char *uri,
125 struct digestdata *digest,
126 char **outptr, size_t *outlen);
128 /* This is used to clean up the digest specific data */
129 void Curl_sasl_digest_cleanup(struct digestdata *digest);
133 /* This is used to generate a base64 encoded NTLM type-1 message */
134 CURLcode Curl_sasl_create_ntlm_type1_message(const char *userp,
136 struct ntlmdata *ntlm,
140 /* This is used to decode a base64 encoded NTLM type-2 message */
141 CURLcode Curl_sasl_decode_ntlm_type2_message(struct SessionHandle *data,
142 const char *type2msg,
143 struct ntlmdata *ntlm);
145 /* This is used to generate a base64 encoded NTLM type-3 message */
146 CURLcode Curl_sasl_create_ntlm_type3_message(struct SessionHandle *data,
149 struct ntlmdata *ntlm,
150 char **outptr, size_t *outlen);
152 /* This is used to clean up the ntlm specific data */
153 void Curl_sasl_ntlm_cleanup(struct ntlmdata *ntlm);
155 #endif /* USE_NTLM */
157 #if defined(USE_KERBEROS5)
158 /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) user token
160 CURLcode Curl_sasl_create_gssapi_user_message(struct SessionHandle *data,
166 struct kerberos5data *krb5,
167 char **outptr, size_t *outlen);
169 /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) security
171 CURLcode Curl_sasl_create_gssapi_security_message(struct SessionHandle *data,
173 struct kerberos5data *krb5,
177 /* This is used to clean up the gssapi specific data */
178 void Curl_sasl_gssapi_cleanup(struct kerberos5data *krb5);
179 #endif /* USE_KERBEROS5 */
181 /* This is used to generate a base64 encoded XOAUTH2 authentication message
182 containing the user name and bearer token */
183 CURLcode Curl_sasl_create_xoauth2_message(struct SessionHandle *data,
186 char **outptr, size_t *outlen);
188 /* This is used to cleanup any libraries or curl modules used by the sasl
190 void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused);
192 #endif /* HEADER_CURL_SASL_H */