Coverage Report

Created: 2026-12-01 06:27

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
#if (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)) && defined(USE_SPNEGO)
42
struct negotiatedata;
43
#endif
44
45
#ifdef USE_GSASL
46
struct gsasldata;
47
#endif
48
49
#ifdef USE_WINDOWS_SSPI
50
#include "curl_sspi.h"
51
#define GSS_ERROR(status) ((status) & 0x80000000)
52
#endif
53
54
/*
55
 * Curl_auth_allowed_to_host() tells if authentication, cookies or other
56
 * "sensitive data" can (still) be sent to this host.
57
 */
58
bool Curl_auth_allowed_to_host(struct Curl_easy *data);
59
bool Curl_auth_allowed_to_origin(struct Curl_easy *data,
60
                                 struct Curl_peer *origin);
61
62
/* This is used to build an SPN string */
63
#ifndef USE_WINDOWS_SSPI
64
char *Curl_auth_build_spn(const char *service, const char *host,
65
                          const char *realm);
66
#else
67
TCHAR *Curl_auth_build_spn(const char *service, const char *host,
68
                           const char *realm);
69
#endif
70
71
/* This is used to test if the user contains a Windows domain name */
72
bool Curl_auth_user_contains_domain(struct Curl_creds *creds);
73
74
/* This is used to generate a PLAIN cleartext message */
75
CURLcode Curl_auth_create_plain_message(struct Curl_creds *creds,
76
                                        struct bufref *out);
77
78
/* This is used to generate a LOGIN cleartext message */
79
void Curl_auth_create_login_message(const char *value, struct bufref *out);
80
81
/* This is used to generate an EXTERNAL cleartext message */
82
void Curl_auth_create_external_message(const char *user, struct bufref *out);
83
84
#ifndef CURL_DISABLE_DIGEST_AUTH
85
/* This is used to generate a CRAM-MD5 response message */
86
CURLcode Curl_auth_create_cram_md5_message(const struct bufref *chlg,
87
                                           struct Curl_creds *creds,
88
                                           struct bufref *out);
89
90
/* This is used to evaluate if DIGEST is supported */
91
bool Curl_auth_is_digest_supported(void);
92
93
/* This is used to generate a base64 encoded DIGEST-MD5 response message */
94
CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
95
                                             const struct bufref *chlg,
96
                                             struct Curl_creds *creds,
97
                                             const char *default_service,
98
                                             struct bufref *out);
99
100
/* This is used to decode an HTTP DIGEST challenge message */
101
CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
102
                                              struct digestdata *digest);
103
104
/* This is used to generate an HTTP DIGEST response message */
105
CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
106
                                              struct Curl_creds *creds,
107
                                              const unsigned char *request,
108
                                              const unsigned char *uripath,
109
                                              struct digestdata *digest,
110
                                              char **outptr, size_t *outlen);
111
112
/* This is used to clean up the digest specific data */
113
void Curl_auth_digest_cleanup(struct digestdata *digest);
114
#else
115
#define Curl_auth_digest_cleanup(x)
116
#define Curl_auth_is_digest_supported()       FALSE
117
#endif /* !CURL_DISABLE_DIGEST_AUTH */
118
119
#ifdef USE_GSASL
120
121
/* meta key for storing GSASL meta at connection */
122
#define CURL_META_GSASL_CONN   "meta:auth:gsasl:conn"
123
124
#include <gsasl.h>
125
struct gsasldata {
126
  Gsasl *ctx;
127
  Gsasl_session *client;
128
};
129
130
struct gsasldata *Curl_auth_gsasl_get(struct connectdata *conn);
131
132
/* This is used to evaluate if MECH is supported by gsasl */
133
bool Curl_auth_gsasl_is_supported(struct Curl_easy *data,
134
                                  const char *mech,
135
                                  struct gsasldata *gsasl);
136
/* This is used to start a gsasl method */
137
CURLcode Curl_auth_gsasl_start(struct Curl_easy *data,
138
                               struct Curl_creds *creds,
139
                               struct gsasldata *gsasl);
140
141
/* This is used to process and generate a new SASL token */
142
CURLcode Curl_auth_gsasl_token(struct Curl_easy *data,
143
                               const struct bufref *chlg,
144
                               struct gsasldata *gsasl,
145
                               struct bufref *out);
146
147
/* This is used to clean up the gsasl specific data */
148
void Curl_auth_gsasl_cleanup(struct gsasldata *gsasl);
149
#endif
150
151
/* This is used to generate a base64 encoded OAuth 2.0 message */
152
CURLcode Curl_auth_create_oauth_bearer_message(struct Curl_creds *creds,
153
                                               const char *host,
154
                                               const long port,
155
                                               struct bufref *out);
156
157
/* This is used to generate a base64 encoded XOAuth 2.0 message */
158
CURLcode Curl_auth_create_xoauth_bearer_message(struct Curl_creds *creds,
159
                                                struct bufref *out);
160
161
#ifdef USE_KERBEROS5
162
163
/* meta key for storing KRB5 meta at connection */
164
#define CURL_META_KRB5_CONN   "meta:auth:krb5:conn"
165
166
struct kerberos5data {
167
#ifdef USE_WINDOWS_SSPI
168
  CredHandle *credentials;
169
  CtxtHandle *context;
170
  TCHAR *spn;
171
  SEC_WINNT_AUTH_IDENTITY_EX identity;
172
  SEC_WINNT_AUTH_IDENTITY_EX *p_identity;
173
  size_t token_max;
174
  BYTE *output_token;
175
#else
176
  gss_ctx_id_t context;
177
  gss_name_t spn;
178
#endif
179
};
180
181
struct kerberos5data *Curl_auth_krb5_get(struct connectdata *conn);
182
183
/* This is used to evaluate if GSSAPI (Kerberos V5) is supported */
184
bool Curl_auth_is_gssapi_supported(void);
185
186
/* This is used to generate a base64 encoded GSSAPI (Kerberos V5) user token
187
   message */
188
CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
189
                                              struct Curl_creds *creds,
190
                                              const char *default_service,
191
                                              const char *host,
192
                                              const bool mutual_auth,
193
                                              const struct bufref *chlg,
194
                                              struct kerberos5data *krb5,
195
                                              struct bufref *out);
196
197
/* This is used to generate a base64 encoded GSSAPI (Kerberos V5) security
198
   token message */
199
CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
200
                                                  const char *authzid,
201
                                                  const struct bufref *chlg,
202
                                                  struct kerberos5data *krb5,
203
                                                  struct bufref *out);
204
205
/* This is used to clean up the GSSAPI specific data */
206
void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5);
207
#else
208
0
#define Curl_auth_is_gssapi_supported()       FALSE
209
#endif /* USE_KERBEROS5 */
210
211
#ifdef USE_SPNEGO
212
213
bool Curl_auth_is_spnego_supported(void);
214
215
/* meta key for storing NEGO meta at connection */
216
#define CURL_META_NEGO_CONN         "meta:auth:nego:conn"
217
/* meta key for storing NEGO PROXY meta at connection */
218
#define CURL_META_NEGO_PROXY_CONN   "meta:auth:nego-proxy:conn"
219
220
/* Struct used for Negotiate (SPNEGO) authentication */
221
struct negotiatedata {
222
#ifdef HAVE_GSSAPI
223
  OM_uint32 status;
224
  gss_ctx_id_t context;
225
  gss_name_t spn;
226
  gss_cred_id_t cred;
227
  gss_buffer_desc output_token;
228
#ifdef GSS_C_CHANNEL_BOUND_FLAG
229
  struct dynbuf channel_binding_data;
230
#endif
231
#else
232
#ifdef USE_WINDOWS_SSPI
233
  CtxtHandle *sslContext;
234
  SECURITY_STATUS status;
235
  CredHandle *credentials;
236
  CtxtHandle *context;
237
  SEC_WINNT_AUTH_IDENTITY_EX identity;
238
  SEC_WINNT_AUTH_IDENTITY_EX *p_identity;
239
  TCHAR *spn;
240
  size_t token_max;
241
  BYTE *output_token;
242
  size_t output_token_length;
243
#endif
244
#endif
245
  BIT(noauthpersist);
246
  BIT(havenoauthpersist);
247
  BIT(havenegdata);
248
  BIT(havemultiplerequests);
249
};
250
251
struct negotiatedata *Curl_auth_nego_get(struct connectdata *conn, bool proxy);
252
253
/* This is used to decode a base64 encoded SPNEGO (Negotiate) challenge
254
   message */
255
CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
256
                                         struct Curl_creds *creds,
257
                                         const char *default_service,
258
                                         const char *host,
259
                                         const char *chlg64,
260
                                         struct negotiatedata *nego);
261
262
/* This is used to generate a base64 encoded SPNEGO (Negotiate) response
263
   message */
264
CURLcode Curl_auth_create_spnego_message(struct negotiatedata *nego,
265
                                         char **outptr, size_t *outlen);
266
267
/* This is used to clean up the SPNEGO specific data */
268
void Curl_auth_cleanup_spnego(struct negotiatedata *nego);
269
270
#endif /* USE_SPNEGO */
271
272
#endif /* HEADER_CURL_VAUTH_H */