1#ifndef HEADER_CURL_VAUTH_H
2#define HEADER_CURL_VAUTH_H
3/***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) 2014 - 2021, Steve Holme, <steve_holme@hotmail.com>.
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 https://curl.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#include "bufref.h"
28
29struct Curl_easy;
30
31#if !defined(CURL_DISABLE_CRYPTO_AUTH)
32struct digestdata;
33#endif
34
35#if defined(USE_NTLM)
36struct ntlmdata;
37#endif
38
39#if defined(USE_KERBEROS5)
40struct kerberos5data;
41#endif
42
43#if (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)) && defined(USE_SPNEGO)
44struct negotiatedata;
45#endif
46
47#if defined(USE_GSASL)
48struct gsasldata;
49#endif
50
51#if defined(USE_WINDOWS_SSPI)
52#define GSS_ERROR(status) ((status) & 0x80000000)
53#endif
54
55/* This is used to build a SPN string */
56#if !defined(USE_WINDOWS_SSPI)
57char *Curl_auth_build_spn(const char *service, const char *host,
58 const char *realm);
59#else
60TCHAR *Curl_auth_build_spn(const char *service, const char *host,
61 const char *realm);
62#endif
63
64/* This is used to test if the user contains a Windows domain name */
65bool Curl_auth_user_contains_domain(const char *user);
66
67/* This is used to generate a PLAIN cleartext message */
68CURLcode Curl_auth_create_plain_message(const char *authzid,
69 const char *authcid,
70 const char *passwd,
71 struct bufref *out);
72
73/* This is used to generate a LOGIN cleartext message */
74CURLcode Curl_auth_create_login_message(const char *value,
75 struct bufref *out);
76
77/* This is used to generate an EXTERNAL cleartext message */
78CURLcode Curl_auth_create_external_message(const char *user,
79 struct bufref *out);
80
81#if !defined(CURL_DISABLE_CRYPTO_AUTH)
82/* This is used to generate a CRAM-MD5 response message */
83CURLcode Curl_auth_create_cram_md5_message(const struct bufref *chlg,
84 const char *userp,
85 const char *passwdp,
86 struct bufref *out);
87
88/* This is used to evaluate if DIGEST is supported */
89bool Curl_auth_is_digest_supported(void);
90
91/* This is used to generate a base64 encoded DIGEST-MD5 response message */
92CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
93 const struct bufref *chlg,
94 const char *userp,
95 const char *passwdp,
96 const char *service,
97 struct bufref *out);
98
99/* This is used to decode a HTTP DIGEST challenge message */
100CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
101 struct digestdata *digest);
102
103/* This is used to generate a HTTP DIGEST response message */
104CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
105 const char *userp,
106 const char *passwdp,
107 const unsigned char *request,
108 const unsigned char *uri,
109 struct digestdata *digest,
110 char **outptr, size_t *outlen);
111
112/* This is used to clean up the digest specific data */
113void Curl_auth_digest_cleanup(struct digestdata *digest);
114#endif /* !CURL_DISABLE_CRYPTO_AUTH */
115
116#ifdef USE_GSASL
117/* This is used to evaluate if MECH is supported by gsasl */
118bool Curl_auth_gsasl_is_supported(struct Curl_easy *data,
119 const char *mech,
120 struct gsasldata *gsasl);
121/* This is used to start a gsasl method */
122CURLcode Curl_auth_gsasl_start(struct Curl_easy *data,
123 const char *userp,
124 const char *passwdp,
125 struct gsasldata *gsasl);
126
127/* This is used to process and generate a new SASL token */
128CURLcode Curl_auth_gsasl_token(struct Curl_easy *data,
129 const struct bufref *chlg,
130 struct gsasldata *gsasl,
131 struct bufref *out);
132
133/* This is used to clean up the gsasl specific data */
134void Curl_auth_gsasl_cleanup(struct gsasldata *digest);
135#endif
136
137#if defined(USE_NTLM)
138/* This is used to evaluate if NTLM is supported */
139bool Curl_auth_is_ntlm_supported(void);
140
141/* This is used to generate a base64 encoded NTLM type-1 message */
142CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
143 const char *userp,
144 const char *passwdp,
145 const char *service,
146 const char *host,
147 struct ntlmdata *ntlm,
148 struct bufref *out);
149
150/* This is used to decode a base64 encoded NTLM type-2 message */
151CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data,
152 const struct bufref *type2,
153 struct ntlmdata *ntlm);
154
155/* This is used to generate a base64 encoded NTLM type-3 message */
156CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
157 const char *userp,
158 const char *passwdp,
159 struct ntlmdata *ntlm,
160 struct bufref *out);
161
162/* This is used to clean up the NTLM specific data */
163void Curl_auth_cleanup_ntlm(struct ntlmdata *ntlm);
164#endif /* USE_NTLM */
165
166/* This is used to generate a base64 encoded OAuth 2.0 message */
167CURLcode Curl_auth_create_oauth_bearer_message(const char *user,
168 const char *host,
169 const long port,
170 const char *bearer,
171 struct bufref *out);
172
173/* This is used to generate a base64 encoded XOAuth 2.0 message */
174CURLcode Curl_auth_create_xoauth_bearer_message(const char *user,
175 const char *bearer,
176 struct bufref *out);
177
178#if defined(USE_KERBEROS5)
179/* This is used to evaluate if GSSAPI (Kerberos V5) is supported */
180bool Curl_auth_is_gssapi_supported(void);
181
182/* This is used to generate a base64 encoded GSSAPI (Kerberos V5) user token
183 message */
184CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
185 const char *userp,
186 const char *passwdp,
187 const char *service,
188 const char *host,
189 const bool mutual,
190 const struct bufref *chlg,
191 struct kerberos5data *krb5,
192 struct bufref *out);
193
194/* This is used to generate a base64 encoded GSSAPI (Kerberos V5) security
195 token message */
196CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
197 const char *authzid,
198 const struct bufref *chlg,
199 struct kerberos5data *krb5,
200 struct bufref *out);
201
202/* This is used to clean up the GSSAPI specific data */
203void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5);
204#endif /* USE_KERBEROS5 */
205
206#if defined(USE_SPNEGO)
207/* This is used to evaluate if SPNEGO (Negotiate) is supported */
208bool Curl_auth_is_spnego_supported(void);
209
210/* This is used to decode a base64 encoded SPNEGO (Negotiate) challenge
211 message */
212CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
213 const char *user,
214 const char *passwood,
215 const char *service,
216 const char *host,
217 const char *chlg64,
218 struct negotiatedata *nego);
219
220/* This is used to generate a base64 encoded SPNEGO (Negotiate) response
221 message */
222CURLcode Curl_auth_create_spnego_message(struct Curl_easy *data,
223 struct negotiatedata *nego,
224 char **outptr, size_t *outlen);
225
226/* This is used to clean up the SPNEGO specifiec data */
227void Curl_auth_cleanup_spnego(struct negotiatedata *nego);
228
229#endif /* USE_SPNEGO */
230
231#endif /* HEADER_CURL_VAUTH_H */
232