Revert "Imported Upstream version 7.44.0"
[platform/upstream/curl.git] / lib / curl_sasl.h
1 #ifndef HEADER_CURL_SASL_H
2 #define HEADER_CURL_SASL_H
3 /***************************************************************************
4  *                                  _   _ ____  _
5  *  Project                     ___| | | |  _ \| |
6  *                             / __| | | | |_) | |
7  *                            | (__| |_| |  _ <| |___
8  *                             \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) 2012 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
11  *
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.
15  *
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.
19  *
20  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21  * KIND, either express or implied.
22  *
23  ***************************************************************************/
24
25 #include <curl/curl.h>
26
27 struct SessionHandle;
28 struct connectdata;
29
30 #if !defined(CURL_DISABLE_CRYPTO_AUTH)
31 struct digestdata;
32 #endif
33
34 #if defined(USE_NTLM)
35 struct ntlmdata;
36 #endif
37
38 #if defined(USE_KERBEROS5)
39 struct kerberos5data;
40 #endif
41
42 /* Authentication mechanism values */
43 #define SASL_AUTH_NONE          0
44 #define SASL_AUTH_ANY           ~0U
45
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)
55
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"
65
66 enum {
67   CURLDIGESTALGO_MD5,
68   CURLDIGESTALGO_MD5SESS
69 };
70
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))
75
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);
79 #else
80 TCHAR *Curl_sasl_build_spn(const char *service, const char *instance);
81 #endif
82
83 /* This is used to generate a base64 encoded PLAIN authentication message */
84 CURLcode Curl_sasl_create_plain_message(struct SessionHandle *data,
85                                         const char *userp,
86                                         const char *passwdp,
87                                         char **outptr, size_t *outlen);
88
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,
93                                         size_t *outlen);
94
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,
98                                            size_t *outlen);
99
100 /* This is used to generate a base64 encoded CRAM-MD5 response message */
101 CURLcode Curl_sasl_create_cram_md5_message(struct SessionHandle *data,
102                                            const char *chlg,
103                                            const char *user,
104                                            const char *passwdp,
105                                            char **outptr, size_t *outlen);
106
107 /* This is used to generate a base64 encoded DIGEST-MD5 response message */
108 CURLcode Curl_sasl_create_digest_md5_message(struct SessionHandle *data,
109                                              const char *chlg64,
110                                              const char *userp,
111                                              const char *passwdp,
112                                              const char *service,
113                                              char **outptr, size_t *outlen);
114
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);
118
119 /* This is used to generate a HTTP DIGEST response message */
120 CURLcode Curl_sasl_create_digest_http_message(struct SessionHandle *data,
121                                               const char *userp,
122                                               const char *passwdp,
123                                               const unsigned char *request,
124                                               const unsigned char *uri,
125                                               struct digestdata *digest,
126                                               char **outptr, size_t *outlen);
127
128 /* This is used to clean up the digest specific data */
129 void Curl_sasl_digest_cleanup(struct digestdata *digest);
130 #endif
131
132 #ifdef USE_NTLM
133 /* This is used to generate a base64 encoded NTLM type-1 message */
134 CURLcode Curl_sasl_create_ntlm_type1_message(const char *userp,
135                                              const char *passwdp,
136                                              struct ntlmdata *ntlm,
137                                              char **outptr,
138                                              size_t *outlen);
139
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);
144
145 /* This is used to generate a base64 encoded NTLM type-3 message */
146 CURLcode Curl_sasl_create_ntlm_type3_message(struct SessionHandle *data,
147                                              const char *userp,
148                                              const char *passwdp,
149                                              struct ntlmdata *ntlm,
150                                              char **outptr, size_t *outlen);
151
152 /* This is used to clean up the ntlm specific data */
153 void Curl_sasl_ntlm_cleanup(struct ntlmdata *ntlm);
154
155 #endif /* USE_NTLM */
156
157 #if defined(USE_KERBEROS5)
158 /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) user token
159    message */
160 CURLcode Curl_sasl_create_gssapi_user_message(struct SessionHandle *data,
161                                               const char *userp,
162                                               const char *passwdp,
163                                               const char *service,
164                                               const bool mutual,
165                                               const char *chlg64,
166                                               struct kerberos5data *krb5,
167                                               char **outptr, size_t *outlen);
168
169 /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) security
170    token message */
171 CURLcode Curl_sasl_create_gssapi_security_message(struct SessionHandle *data,
172                                                   const char *input,
173                                                   struct kerberos5data *krb5,
174                                                   char **outptr,
175                                                   size_t *outlen);
176
177 /* This is used to clean up the gssapi specific data */
178 void Curl_sasl_gssapi_cleanup(struct kerberos5data *krb5);
179 #endif /* USE_KERBEROS5 */
180
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,
184                                           const char *user,
185                                           const char *bearer,
186                                           char **outptr, size_t *outlen);
187
188 /* This is used to cleanup any libraries or curl modules used by the sasl
189    functions */
190 void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused);
191
192 #endif /* HEADER_CURL_SASL_H */