Coverage Report

Created: 2026-09-14 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl/lib/vauth/vauth.h
Line
Count
Source
1
#ifndef HEADER_CURL_VAUTH_H
2
#define HEADER_CURL_VAUTH_H
3
/***************************************************************************
4
 *                                  _   _ ____  _
5
 *  Project                     ___| | | |  _ \| |
6
 *                             / __| | | | |_) | |
7
 *                            | (__| |_| |  _ <| |___
8
 *                             \___|\___/|_| \_\_____|
9
 *
10
 * Copyright (C) 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
 * SPDX-License-Identifier: curl
24
 *
25
 ***************************************************************************/
26
#include "curl_setup.h"
27
28
#include "bufref.h"
29
#include "curlx/dynbuf.h"
30
#include "urldata.h"
31
32
struct Curl_easy;
33
struct Curl_creds;
34
struct connectdata;
35
struct Curl_peer;
36
37
#ifndef CURL_DISABLE_DIGEST_AUTH
38
struct digestdata;
39
#endif
40
41
#ifdef USE_NTLM
42
struct ntlmdata;
43
#endif
44
45
#if (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)) && defined(USE_SPNEGO)
46
struct negotiatedata;
47
#endif
48
49
#ifdef USE_GSASL
50
struct gsasldata;
51
#endif
52
53
#ifdef USE_WINDOWS_SSPI
54
#include "curl_sspi.h"
55
#define GSS_ERROR(status) ((status) & 0x80000000)
56
#endif
57
58
/*
59
 * Curl_auth_allowed_to_host() tells if authentication, cookies or other
60
 * "sensitive data" can (still) be sent to this host.
61
 */
62
bool Curl_auth_allowed_to_host(struct Curl_easy *data);
63
bool Curl_auth_allowed_to_origin(struct Curl_easy *data,
64
                                 struct Curl_peer *origin);
65
66
/* This is used to build an SPN string */
67
#ifndef USE_WINDOWS_SSPI
68
char *Curl_auth_build_spn(const char *service, const char *host,
69
                          const char *realm);
70
#else
71
TCHAR *Curl_auth_build_spn(const char *service, const char *host,
72
                           const char *realm);
73
#endif
74
75
/* This is used to test if the user contains a Windows domain name */
76
bool Curl_auth_user_contains_domain(struct Curl_creds *creds);
77
78
/* This is used to generate a PLAIN cleartext message */
79
CURLcode Curl_auth_create_plain_message(struct Curl_creds *creds,
80
                                        struct bufref *out);
81
82
/* This is used to generate a LOGIN cleartext message */
83
void Curl_auth_create_login_message(const char *value, struct bufref *out);
84
85
/* This is used to generate an EXTERNAL cleartext message */
86
void Curl_auth_create_external_message(const char *user, struct bufref *out);
87
88
#ifndef CURL_DISABLE_DIGEST_AUTH
89
/* This is used to generate a CRAM-MD5 response message */
90
CURLcode Curl_auth_create_cram_md5_message(const struct bufref *chlg,
91
                                           struct Curl_creds *creds,
92
                                           struct bufref *out);
93
94
/* This is used to evaluate if DIGEST is supported */
95
bool Curl_auth_is_digest_supported(void);
96
97
/* This is used to generate a base64 encoded DIGEST-MD5 response message */
98
CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
99
                                             const struct bufref *chlg,
100
                                             struct Curl_creds *creds,
101
                                             const char *default_service,
102
                                             struct bufref *out);
103
104
/* This is used to decode an HTTP DIGEST challenge message */
105
CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
106
                                              struct digestdata *digest);
107
108
/* This is used to generate an HTTP DIGEST response message */
109
CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
110
                                              struct Curl_creds *creds,
111
                                              const unsigned char *request,
112
                                              const unsigned char *uripath,
113
                                              struct digestdata *digest,
114
                                              char **outptr, size_t *outlen);
115
116
/* This is used to clean up the digest specific data */
117
void Curl_auth_digest_cleanup(struct digestdata *digest);
118
#else
119
#define Curl_auth_digest_cleanup(x)
120
#define Curl_auth_is_digest_supported()       FALSE
121
#endif /* !CURL_DISABLE_DIGEST_AUTH */
122
123
#ifdef USE_GSASL
124
125
/* meta key for storing GSASL meta at connection */
126
#define CURL_META_GSASL_CONN   "meta:auth:gsasl:conn"
127
128
#include <gsasl.h>
129
struct gsasldata {
130
  Gsasl *ctx;
131
  Gsasl_session *client;
132
};
133
134
struct gsasldata *Curl_auth_gsasl_get(struct connectdata *conn);
135
136
/* This is used to evaluate if MECH is supported by gsasl */
137
bool Curl_auth_gsasl_is_supported(struct Curl_easy *data,
138
                                  const char *mech,
139
                                  struct gsasldata *gsasl);
140
/* This is used to start a gsasl method */
141
CURLcode Curl_auth_gsasl_start(struct Curl_easy *data,
142
                               struct Curl_creds *creds,
143
                               struct gsasldata *gsasl);
144
145
/* This is used to process and generate a new SASL token */
146
CURLcode Curl_auth_gsasl_token(struct Curl_easy *data,
147
                               const struct bufref *chlg,
148
                               struct gsasldata *gsasl,
149
                               struct bufref *out);
150
151
/* This is used to clean up the gsasl specific data */
152
void Curl_auth_gsasl_cleanup(struct gsasldata *gsasl);
153
#endif
154
155
#ifdef USE_NTLM
156
157
/* meta key for storing NTML meta at connection */
158
#define CURL_META_NTLM_CONN   "meta:auth:ntml:conn"
159
/* meta key for storing NTML-PROXY meta at connection */
160
#define CURL_META_NTLM_PROXY_CONN   "meta:auth:ntml-proxy:conn"
161
162
struct ntlmdata {
163
#ifdef USE_WINDOWS_SSPI
164
/* The sslContext is used for the Schannel bindings. The
165
 * api is available on the Windows 7 SDK and later.
166
 */
167
  CtxtHandle *sslContext;
168
  CredHandle *credentials;
169
  CtxtHandle *context;
170
  SEC_WINNT_AUTH_IDENTITY_EX identity;
171
  SEC_WINNT_AUTH_IDENTITY_EX *p_identity;
172
  size_t token_max;
173
  BYTE *output_token;
174
  BYTE *input_token;
175
  size_t input_token_len;
176
  TCHAR *spn;
177
#else
178
  unsigned int flags;
179
  unsigned char nonce[8];
180
  unsigned int target_info_len;
181
  void *target_info; /* TargetInfo received in the NTLM type-2 message */
182
#endif
183
};
184
185
/* This is used to evaluate if NTLM is supported */
186
bool Curl_auth_is_ntlm_supported(void);
187
188
struct ntlmdata *Curl_auth_ntlm_get(struct connectdata *conn, bool proxy);
189
void Curl_auth_ntlm_remove(struct connectdata *conn, bool proxy);
190
191
/* This is used to clean up the NTLM specific data */
192
void Curl_auth_cleanup_ntlm(struct ntlmdata *ntlm);
193
194
/* This is used to generate a base64 encoded NTLM type-1 message */
195
CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
196
                                             struct Curl_creds *creds,
197
                                             const char *default_service,
198
                                             const char *host,
199
                                             struct ntlmdata *ntlm,
200
                                             struct bufref *out);
201
202
/* This is used to decode a base64 encoded NTLM type-2 message */
203
CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data,
204
                                             const struct bufref *type2ref,
205
                                             struct ntlmdata *ntlm);
206
207
/* This is used to generate a base64 encoded NTLM type-3 message */
208
CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
209
                                             struct Curl_creds *creds,
210
                                             struct ntlmdata *ntlm,
211
                                             struct bufref *out);
212
213
#else
214
0
#define Curl_auth_is_ntlm_supported()     FALSE
215
#endif /* USE_NTLM */
216
217
/* This is used to generate a base64 encoded OAuth 2.0 message */
218
CURLcode Curl_auth_create_oauth_bearer_message(struct Curl_creds *creds,
219
                                               const char *host,
220
                                               const long port,
221
                                               struct bufref *out);
222
223
/* This is used to generate a base64 encoded XOAuth 2.0 message */
224
CURLcode Curl_auth_create_xoauth_bearer_message(struct Curl_creds *creds,
225
                                                struct bufref *out);
226
227
#ifdef USE_KERBEROS5
228
229
/* meta key for storing KRB5 meta at connection */
230
#define CURL_META_KRB5_CONN   "meta:auth:krb5:conn"
231
232
struct kerberos5data {
233
#ifdef USE_WINDOWS_SSPI
234
  CredHandle *credentials;
235
  CtxtHandle *context;
236
  TCHAR *spn;
237
  SEC_WINNT_AUTH_IDENTITY_EX identity;
238
  SEC_WINNT_AUTH_IDENTITY_EX *p_identity;
239
  size_t token_max;
240
  BYTE *output_token;
241
#else
242
  gss_ctx_id_t context;
243
  gss_name_t spn;
244
#endif
245
};
246
247
struct kerberos5data *Curl_auth_krb5_get(struct connectdata *conn);
248
249
/* This is used to evaluate if GSSAPI (Kerberos V5) is supported */
250
bool Curl_auth_is_gssapi_supported(void);
251
252
/* This is used to generate a base64 encoded GSSAPI (Kerberos V5) user token
253
   message */
254
CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
255
                                              struct Curl_creds *creds,
256
                                              const char *default_service,
257
                                              const char *host,
258
                                              const bool mutual_auth,
259
                                              const struct bufref *chlg,
260
                                              struct kerberos5data *krb5,
261
                                              struct bufref *out);
262
263
/* This is used to generate a base64 encoded GSSAPI (Kerberos V5) security
264
   token message */
265
CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
266
                                                  const char *authzid,
267
                                                  const struct bufref *chlg,
268
                                                  struct kerberos5data *krb5,
269
                                                  struct bufref *out);
270
271
/* This is used to clean up the GSSAPI specific data */
272
void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5);
273
#else
274
0
#define Curl_auth_is_gssapi_supported()       FALSE
275
#endif /* USE_KERBEROS5 */
276
277
#ifdef USE_SPNEGO
278
279
bool Curl_auth_is_spnego_supported(void);
280
281
/* meta key for storing NEGO meta at connection */
282
#define CURL_META_NEGO_CONN         "meta:auth:nego:conn"
283
/* meta key for storing NEGO PROXY meta at connection */
284
#define CURL_META_NEGO_PROXY_CONN   "meta:auth:nego-proxy:conn"
285
286
/* Struct used for Negotiate (SPNEGO) authentication */
287
struct negotiatedata {
288
#ifdef HAVE_GSSAPI
289
  OM_uint32 status;
290
  gss_ctx_id_t context;
291
  gss_name_t spn;
292
  gss_cred_id_t cred;
293
  gss_buffer_desc output_token;
294
#ifdef GSS_C_CHANNEL_BOUND_FLAG
295
  struct dynbuf channel_binding_data;
296
#endif
297
#else
298
#ifdef USE_WINDOWS_SSPI
299
  CtxtHandle *sslContext;
300
  SECURITY_STATUS status;
301
  CredHandle *credentials;
302
  CtxtHandle *context;
303
  SEC_WINNT_AUTH_IDENTITY_EX identity;
304
  SEC_WINNT_AUTH_IDENTITY_EX *p_identity;
305
  TCHAR *spn;
306
  size_t token_max;
307
  BYTE *output_token;
308
  size_t output_token_length;
309
#endif
310
#endif
311
  BIT(noauthpersist);
312
  BIT(havenoauthpersist);
313
  BIT(havenegdata);
314
  BIT(havemultiplerequests);
315
};
316
317
struct negotiatedata *Curl_auth_nego_get(struct connectdata *conn, bool proxy);
318
319
/* This is used to decode a base64 encoded SPNEGO (Negotiate) challenge
320
   message */
321
CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
322
                                         struct Curl_creds *creds,
323
                                         const char *default_service,
324
                                         const char *host,
325
                                         const char *chlg64,
326
                                         struct negotiatedata *nego);
327
328
/* This is used to generate a base64 encoded SPNEGO (Negotiate) response
329
   message */
330
CURLcode Curl_auth_create_spnego_message(struct negotiatedata *nego,
331
                                         char **outptr, size_t *outlen);
332
333
/* This is used to clean up the SPNEGO specific data */
334
void Curl_auth_cleanup_spnego(struct negotiatedata *nego);
335
336
#endif /* USE_SPNEGO */
337
338
#endif /* HEADER_CURL_VAUTH_H */