1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
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.haxx.se/docs/copyright.html.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 #include "curl_setup.h"
25 #if !defined(CURL_DISABLE_HTTP) && defined(USE_SPNEGO)
29 #include "http_negotiate.h"
30 #include "vauth/vauth.h"
32 /* The last 3 #include files should be in this order */
33 #include "curl_printf.h"
34 #include "curl_memory.h"
37 CURLcode Curl_input_negotiate(struct connectdata *conn, bool proxy,
41 struct Curl_easy *data = conn->data;
44 /* Point to the username, password, service and host */
50 /* Point to the correct struct with this */
51 struct negotiatedata *neg_ctx;
54 userp = conn->http_proxy.user;
55 passwdp = conn->http_proxy.passwd;
56 service = data->set.str[STRING_PROXY_SERVICE_NAME] ?
57 data->set.str[STRING_PROXY_SERVICE_NAME] : "HTTP";
58 host = conn->http_proxy.host.name;
59 neg_ctx = &data->state.proxyneg;
63 passwdp = conn->passwd;
64 service = data->set.str[STRING_SERVICE_NAME] ?
65 data->set.str[STRING_SERVICE_NAME] : "HTTP";
66 host = conn->host.name;
67 neg_ctx = &data->state.negotiate;
70 /* Not set means empty */
77 /* Obtain the input token, if any */
78 header += strlen("Negotiate");
79 while(*header && ISSPACE(*header))
84 /* Is this the first call in a new negotiation? */
85 if(neg_ctx->context) {
86 /* The server rejected our authentication and hasn't suppled any more
87 negotiation mechanisms */
88 return CURLE_LOGIN_DENIED;
92 /* Initilise the security context and decode our challenge */
93 result = Curl_auth_decode_spnego_message(data, userp, passwdp, service,
94 host, header, neg_ctx);
97 Curl_auth_spnego_cleanup(neg_ctx);
102 CURLcode Curl_output_negotiate(struct connectdata *conn, bool proxy)
104 struct negotiatedata *neg_ctx = proxy ? &conn->data->state.proxyneg :
105 &conn->data->state.negotiate;
111 result = Curl_auth_create_spnego_message(conn->data, neg_ctx, &base64, &len);
115 userp = aprintf("%sAuthorization: Negotiate %s\r\n", proxy ? "Proxy-" : "",
119 Curl_safefree(conn->allocptr.proxyuserpwd);
120 conn->allocptr.proxyuserpwd = userp;
123 Curl_safefree(conn->allocptr.userpwd);
124 conn->allocptr.userpwd = userp;
129 return (userp == NULL) ? CURLE_OUT_OF_MEMORY : CURLE_OK;
132 void Curl_cleanup_negotiate(struct Curl_easy *data)
134 Curl_auth_spnego_cleanup(&data->state.negotiate);
135 Curl_auth_spnego_cleanup(&data->state.proxyneg);
138 #endif /* !CURL_DISABLE_HTTP && USE_SPNEGO */