master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 * RFC4178 Simple and Protected GSS-API Negotiation Mechanism
24 *
25 ***************************************************************************/
26#include "curl_setup.h"
28#if defined(HAVE_GSSAPI) && defined(USE_SPNEGO)
30#include "vauth/vauth.h"
31#include "curlx/base64.h"
32#include "curl_gssapi.h"
33#include "curl_trc.h"
35#if defined(CURL_HAVE_DIAG) && defined(__APPLE__) && !defined(HAVE_GSSAPPLE)
36#pragma GCC diagnostic push
37#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
38#endif
40/*
41 * Curl_auth_is_spnego_supported()
42 *
43 * This is used to evaluate if SPNEGO (Negotiate) is supported.
44 *
45 * Parameters: None
46 *
47 * Returns TRUE if Negotiate supported by the GSS-API library.
48 */
49bool Curl_auth_is_spnego_supported(void)
50{
51 return TRUE;
52}
54/*
55 * Curl_auth_decode_spnego_message()
56 *
57 * This is used to decode an already encoded SPNEGO (Negotiate) challenge
58 * message.
59 *
60 * Parameters:
61 *
62 * data [in] - The session handle.
63 * userp [in] - The username in the format User or Domain\User.
64 * passwdp [in] - The user's password.
65 * service [in] - The service type such as http, smtp, pop or imap.
66 * host [in] - The hostname.
67 * chlg64 [in] - The optional base64 encoded challenge message.
68 * nego [in/out] - The Negotiate data struct being used and modified.
69 *
70 * Returns CURLE_OK on success.
71 */
72CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
73 struct Curl_creds *creds,
74 const char *default_service,
75 const char *host,
76 const char *chlg64,
77 struct negotiatedata *nego)
78{
79 CURLcode result = CURLE_OK;
80 size_t chlglen = 0;
81 unsigned char *chlg = NULL;
82 OM_uint32 major_status;
83 OM_uint32 minor_status;
84 OM_uint32 unused_status;
85 gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER;
86 gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER;
87 gss_channel_bindings_t chan_bindings = GSS_C_NO_CHANNEL_BINDINGS;
88#ifdef GSS_C_CHANNEL_BOUND_FLAG
89 struct gss_channel_bindings_struct chan;
90#endif
92 (void)creds;
94 if(nego->context && nego->status == GSS_S_COMPLETE) {
95 /* We finished successfully our part of authentication, but server
96 * rejected it (since we are again here). Exit with an error since we
97 * cannot invent anything better */
98 Curl_auth_cleanup_spnego(nego);
99 return CURLE_LOGIN_DENIED;
100 }
102 if(!nego->spn) {
103 gss_buffer_desc spn_token = GSS_C_EMPTY_BUFFER;
105 /* Generate our SPN */
106 const char *service = Curl_creds_has_sasl_service(creds) ?
107 Curl_creds_sasl_service(creds) : default_service;
108 char *spn = Curl_auth_build_spn(service, NULL, host);
109 if(!spn)
110 return CURLE_OUT_OF_MEMORY;
112 /* Populate the SPN structure */
113 spn_token.value = spn;
114 spn_token.length = strlen(spn);
116 /* Import the SPN */
117 major_status = gss_import_name(&minor_status, &spn_token,
118 GSS_C_NT_HOSTBASED_SERVICE,
119 &nego->spn);
120 if(GSS_ERROR(major_status)) {
121 Curl_gss_log_error(data, "gss_import_name() failed: ",
122 major_status, minor_status);
124 curlx_free(spn);
126 return CURLE_AUTH_ERROR;
127 }
129 curlx_free(spn);
130 }
132 if(chlg64 && *chlg64) {
133 /* Decode the base-64 encoded challenge message */
134 if(*chlg64 != '=') {
135 result = curlx_base64_decode(chlg64, &chlg, &chlglen);
136 if(result)
137 return result;
138 }
140 /* Ensure we have a valid challenge message */
141 if(!chlg) {
142 infof(data, "SPNEGO handshake failure (empty challenge message)");
143 return CURLE_BAD_CONTENT_ENCODING;
144 }
146 /* Setup the challenge "input" security buffer */
147 input_token.value = chlg;
148 input_token.length = chlglen;
149 }
151 /* Set channel binding data if available */
152#ifdef GSS_C_CHANNEL_BOUND_FLAG
153 if(curlx_dyn_len(&nego->channel_binding_data)) {
154 memset(&chan, 0, sizeof(struct gss_channel_bindings_struct));
155 chan.application_data.length = curlx_dyn_len(&nego->channel_binding_data);
156 chan.application_data.value = curlx_dyn_ptr(&nego->channel_binding_data);
157 chan_bindings = &chan;
158 }
159#endif
161#ifdef HAVE_GSS_SET_NEG_MECHS
162 /* Acquire explicit credentials and restrict SPNEGO sub-mechanisms to
163 * exclude NTLM. We enumerate all available mechanisms and filter out
164 * the NTLMSSP OID, matching SSPI's "!ntlm". */
165 if(nego->cred == GSS_C_NO_CREDENTIAL) {
166 /* OID 1.3.6.1.4.1.311.2.2.10 (NTLMSSP) */
167 static const gss_OID_desc ntlmssp_oid = {
168 10, CURL_UNCONST("\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a")
169 };
170 gss_OID_set available_mechs = GSS_C_NO_OID_SET;
171 gss_OID_set filtered_mechs = GSS_C_NO_OID_SET;
173 /* Acquire default credentials for SPNEGO */
174 major_status = Curl_gss_acquire_cred(&minor_status, GSS_C_NO_NAME,
175 GSS_C_INDEFINITE, GSS_C_NO_OID_SET,
176 GSS_C_INITIATE, &nego->cred, NULL, NULL);
177 if(GSS_ERROR(major_status)) {
178 Curl_gss_log_error(data, "gss_acquire_cred() failed: ",
179 major_status, minor_status);
180 curlx_safefree(input_token.value);
181 return CURLE_AUTH_ERROR;
182 }
184 /* Get all available mechanisms */
185 major_status = Curl_gss_indicate_mechs(&minor_status, &available_mechs);
186 if(!GSS_ERROR(major_status)) {
187 /* Build a set excluding NTLMSSP */
188 major_status = gss_create_empty_oid_set(&minor_status, &filtered_mechs);
189 if(!GSS_ERROR(major_status)) {
190 size_t i;
191 for(i = 0; i < available_mechs->count; i++) {
192 gss_OID oid = &available_mechs->elements[i];
193 if(oid->length != ntlmssp_oid.length ||
194 memcmp(oid->elements, ntlmssp_oid.elements, oid->length)) {
195 gss_add_oid_set_member(&minor_status, oid, &filtered_mechs);
196 }
197 }
198 /* Restrict SPNEGO to only use non-NTLM mechanisms */
199 major_status = Curl_gss_set_neg_mechs(&minor_status, nego->cred,
200 filtered_mechs);
201 if(GSS_ERROR(major_status)) {
202 Curl_gss_log_error(data, "gss_set_neg_mechs() failed: ",
203 major_status, minor_status);
204 }
205 gss_release_oid_set(&minor_status, &filtered_mechs);
206 }
207 gss_release_oid_set(&minor_status, &available_mechs);
208 }
209 }
210#endif /* HAVE_GSS_SET_NEG_MECHS */
212 /* Generate our challenge-response message */
213 major_status = Curl_gss_init_sec_context(data,
214 &minor_status,
215 &nego->context,
216 nego->spn,
217 &Curl_spnego_mech_oid,
218 chan_bindings,
219 &input_token,
220 &output_token,
221 TRUE,
222 NULL,
223 nego->cred);
225 /* Free the decoded challenge as it is not required anymore */
226 curlx_safefree(input_token.value);
228 nego->status = major_status;
229 if(GSS_ERROR(major_status)) {
230 if(output_token.value)
231 gss_release_buffer(&unused_status, &output_token);
233 Curl_gss_log_error(data, "gss_init_sec_context() failed: ",
234 major_status, minor_status);
236 return CURLE_AUTH_ERROR;
237 }
239 if(!output_token.value || !output_token.length) {
240 if(output_token.value)
241 gss_release_buffer(&unused_status, &output_token);
243 return CURLE_AUTH_ERROR;
244 }
246 /* Check if NTLM was selected and is disallowed */
247 if(nego->context != GSS_C_NO_CONTEXT) {
248 /* OID 1.3.6.1.4.1.311.2.2.10 (NTLMSSP) */
249 static const gss_OID_desc ntlmssp_oid = {
250 10, CURL_UNCONST("\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a")
251 };
252 OM_uint32 inquire_major, inquire_minor;
253 gss_OID mech_type = GSS_C_NO_OID;
255 inquire_major = Curl_gss_inquire_context(&inquire_minor,
256 nego->context,
257 &mech_type);
258 if(!GSS_ERROR(inquire_major) && mech_type &&
259 mech_type->length == ntlmssp_oid.length &&
260 !memcmp(mech_type->elements, ntlmssp_oid.elements,
261 ntlmssp_oid.length)) {
262 infof(data, "SPNEGO chose NTLM, but NTLM is not allowed");
263 gss_release_buffer(&unused_status, &output_token);
264 Curl_auth_cleanup_spnego(nego);
265 return CURLE_AUTH_ERROR;
266 }
267 }
269 /* Free previous token */
270 if(nego->output_token.length && nego->output_token.value)
271 gss_release_buffer(&unused_status, &nego->output_token);
273 nego->output_token = output_token;
275 return CURLE_OK;
276}
278/*
279 * Curl_auth_create_spnego_message()
280 *
281 * This is used to generate an already encoded SPNEGO (Negotiate) response
282 * message ready for sending to the recipient.
283 *
284 * Parameters:
285 *
286 * data [in] - The session handle.
287 * nego [in/out] - The Negotiate data struct being used and modified.
288 * outptr [in/out] - The address where a pointer to newly allocated memory
289 * holding the result is stored upon completion.
290 * outlen [out] - The length of the output message.
291 *
292 * Returns CURLE_OK on success.
293 */
294CURLcode Curl_auth_create_spnego_message(struct negotiatedata *nego,
295 char **outptr, size_t *outlen)
296{
297 CURLcode result;
298 OM_uint32 minor_status;
300 /* Base64 encode the already generated response */
301 result = curlx_base64_encode(nego->output_token.value,
302 nego->output_token.length,
303 outptr, outlen);
305 if(result) {
306 gss_release_buffer(&minor_status, &nego->output_token);
307 nego->output_token.value = NULL;
308 nego->output_token.length = 0;
310 return result;
311 }
313 if(!*outptr || !*outlen) {
314 gss_release_buffer(&minor_status, &nego->output_token);
315 nego->output_token.value = NULL;
316 nego->output_token.length = 0;
318 return CURLE_REMOTE_ACCESS_DENIED;
319 }
321 return CURLE_OK;
322}
324/*
325 * Curl_auth_cleanup_spnego()
326 *
327 * This is used to clean up the SPNEGO (Negotiate) specific data.
328 *
329 * Parameters:
330 *
331 * nego [in/out] - The Negotiate data struct being cleaned up.
332 *
333 */
334void Curl_auth_cleanup_spnego(struct negotiatedata *nego)
335{
336 OM_uint32 minor_status;
338 /* Free our security context */
339 if(nego->context != GSS_C_NO_CONTEXT) {
340 Curl_gss_delete_sec_context(&minor_status, &nego->context,
341 GSS_C_NO_BUFFER);
342 nego->context = GSS_C_NO_CONTEXT;
343 }
345 /* Free the output token */
346 if(nego->output_token.value) {
347 gss_release_buffer(&minor_status, &nego->output_token);
348 nego->output_token.value = NULL;
349 nego->output_token.length = 0;
350 }
352 /* Free the SPN */
353 if(nego->spn != GSS_C_NO_NAME) {
354 gss_release_name(&minor_status, &nego->spn);
355 nego->spn = GSS_C_NO_NAME;
356 }
358 /* Free our credentials */
359 if(nego->cred != GSS_C_NO_CREDENTIAL) {
360 Curl_gss_release_cred(&minor_status, &nego->cred);
361 nego->cred = GSS_C_NO_CREDENTIAL;
362 }
364 /* Reset any variables */
365 nego->status = 0;
366 nego->noauthpersist = FALSE;
367 nego->havenoauthpersist = FALSE;
368 nego->havenegdata = FALSE;
369 nego->havemultiplerequests = FALSE;
370}
372#if defined(CURL_HAVE_DIAG) && defined(__APPLE__) && !defined(HAVE_GSSAPPLE)
373#pragma GCC diagnostic pop
374#endif
376#endif /* HAVE_GSSAPI && USE_SPNEGO */
Diagnostics4 git calls · 24 ms
CallStatusSizeTime024 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=20 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2003.8 KiB · hit20 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=3894 git.response.cache=HIT git.response.duration_ms=20 git.fetch.wants=b2bc28fb3fa7c965af75b2e129a770cd5e27b28e git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=3894 git.pkt.payload.max=3873 git.sideband.band1.bytes=3872 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5eafa630ae8b1bb
- Request
- b777aa87…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format