2003-06-10 16:22:19 +04:00
|
|
|
/***************************************************************************
|
2004-06-24 15:54:11 +04:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
2003-06-10 16:22:19 +04:00
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2016-03-13 14:28:42 +03:00
|
|
|
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2003-06-10 16:22:19 +04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-03 02:19:02 +03:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2004-06-24 15:54:11 +04:00
|
|
|
*
|
2003-06-10 16:22:19 +04:00
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2011-07-26 19:23:27 +04:00
|
|
|
|
2013-01-06 22:06:49 +04:00
|
|
|
#include "curl_setup.h"
|
2003-06-10 16:22:19 +04:00
|
|
|
|
2016-03-13 23:09:15 +03:00
|
|
|
#if !defined(CURL_DISABLE_HTTP) && defined(USE_SPNEGO)
|
2003-06-10 16:22:19 +04:00
|
|
|
|
2013-01-04 05:50:28 +04:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "http_negotiate.h"
|
2015-09-12 13:48:24 +03:00
|
|
|
#include "vauth/vauth.h"
|
2003-06-10 16:22:19 +04:00
|
|
|
|
2016-04-29 16:46:40 +03:00
|
|
|
/* The last 3 #include files should be in this order */
|
|
|
|
#include "curl_printf.h"
|
2015-03-25 01:12:03 +03:00
|
|
|
#include "curl_memory.h"
|
2013-01-04 05:50:28 +04:00
|
|
|
#include "memdebug.h"
|
2003-06-10 16:22:19 +04:00
|
|
|
|
2015-01-17 14:56:27 +03:00
|
|
|
CURLcode Curl_input_negotiate(struct connectdata *conn, bool proxy,
|
|
|
|
const char *header)
|
2004-06-24 15:54:11 +04:00
|
|
|
{
|
2016-11-09 16:37:34 +03:00
|
|
|
CURLcode result;
|
2016-06-21 16:47:12 +03:00
|
|
|
struct Curl_easy *data = conn->data;
|
2016-03-13 23:09:15 +03:00
|
|
|
size_t len;
|
2015-01-18 20:36:59 +03:00
|
|
|
|
2016-03-13 23:09:15 +03:00
|
|
|
/* Point to the username, password, service and host */
|
|
|
|
const char *userp;
|
|
|
|
const char *passwdp;
|
2016-03-13 21:51:46 +03:00
|
|
|
const char *service;
|
|
|
|
const char *host;
|
2015-01-18 20:36:59 +03:00
|
|
|
|
2016-03-13 21:51:46 +03:00
|
|
|
/* Point to the correct struct with this */
|
|
|
|
struct negotiatedata *neg_ctx;
|
2015-01-18 20:36:59 +03:00
|
|
|
|
2016-03-13 21:51:46 +03:00
|
|
|
if(proxy) {
|
2016-11-16 20:49:15 +03:00
|
|
|
userp = conn->http_proxy.user;
|
|
|
|
passwdp = conn->http_proxy.passwd;
|
2016-04-08 20:41:41 +03:00
|
|
|
service = data->set.str[STRING_PROXY_SERVICE_NAME] ?
|
|
|
|
data->set.str[STRING_PROXY_SERVICE_NAME] : "HTTP";
|
2016-11-16 20:49:15 +03:00
|
|
|
host = conn->http_proxy.host.name;
|
2016-03-13 21:51:46 +03:00
|
|
|
neg_ctx = &data->state.proxyneg;
|
|
|
|
}
|
|
|
|
else {
|
2016-03-13 23:09:15 +03:00
|
|
|
userp = conn->user;
|
|
|
|
passwdp = conn->passwd;
|
2016-04-08 20:41:41 +03:00
|
|
|
service = data->set.str[STRING_SERVICE_NAME] ?
|
|
|
|
data->set.str[STRING_SERVICE_NAME] : "HTTP";
|
2016-04-01 23:48:35 +03:00
|
|
|
host = conn->host.name;
|
2016-03-13 21:51:46 +03:00
|
|
|
neg_ctx = &data->state.negotiate;
|
2015-01-18 20:36:59 +03:00
|
|
|
}
|
2003-06-10 16:22:19 +04:00
|
|
|
|
2016-03-13 23:09:15 +03:00
|
|
|
/* Not set means empty */
|
|
|
|
if(!userp)
|
|
|
|
userp = "";
|
|
|
|
|
|
|
|
if(!passwdp)
|
|
|
|
passwdp = "";
|
|
|
|
|
2016-03-13 21:51:46 +03:00
|
|
|
/* Obtain the input token, if any */
|
2014-07-21 11:53:44 +04:00
|
|
|
header += strlen("Negotiate");
|
2006-10-18 01:32:56 +04:00
|
|
|
while(*header && ISSPACE(*header))
|
2003-06-10 16:22:19 +04:00
|
|
|
header++;
|
|
|
|
|
2016-03-13 23:09:15 +03:00
|
|
|
len = strlen(header);
|
|
|
|
if(!len) {
|
|
|
|
/* Is this the first call in a new negotiation? */
|
|
|
|
if(neg_ctx->context) {
|
|
|
|
/* The server rejected our authentication and hasn't suppled any more
|
|
|
|
negotiation mechanisms */
|
|
|
|
return CURLE_LOGIN_DENIED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-13 21:51:46 +03:00
|
|
|
/* Initilise the security context and decode our challenge */
|
2016-11-09 16:37:34 +03:00
|
|
|
result = Curl_auth_decode_spnego_message(data, userp, passwdp, service,
|
|
|
|
host, header, neg_ctx);
|
|
|
|
|
|
|
|
if(result)
|
|
|
|
Curl_auth_spnego_cleanup(neg_ctx);
|
|
|
|
|
|
|
|
return result;
|
2015-01-17 14:56:27 +03:00
|
|
|
}
|
2003-06-10 16:22:19 +04:00
|
|
|
|
2007-09-21 15:05:31 +04:00
|
|
|
CURLcode Curl_output_negotiate(struct connectdata *conn, bool proxy)
|
2004-06-24 15:54:11 +04:00
|
|
|
{
|
2016-03-13 23:09:15 +03:00
|
|
|
struct negotiatedata *neg_ctx = proxy ? &conn->data->state.proxyneg :
|
2007-11-21 02:17:08 +03:00
|
|
|
&conn->data->state.negotiate;
|
2016-03-13 21:51:46 +03:00
|
|
|
char *base64 = NULL;
|
2011-08-24 10:07:36 +04:00
|
|
|
size_t len = 0;
|
2010-08-17 00:19:38 +04:00
|
|
|
char *userp;
|
2014-10-26 19:34:44 +03:00
|
|
|
CURLcode result;
|
2003-09-19 16:56:22 +04:00
|
|
|
|
2016-03-13 21:51:46 +03:00
|
|
|
result = Curl_auth_create_spnego_message(conn->data, neg_ctx, &base64, &len);
|
|
|
|
if(result)
|
|
|
|
return result;
|
2003-06-10 16:22:19 +04:00
|
|
|
|
2014-07-21 11:53:44 +04:00
|
|
|
userp = aprintf("%sAuthorization: Negotiate %s\r\n", proxy ? "Proxy-" : "",
|
2016-03-13 21:51:46 +03:00
|
|
|
base64);
|
|
|
|
|
2013-04-04 03:57:25 +04:00
|
|
|
if(proxy) {
|
|
|
|
Curl_safefree(conn->allocptr.proxyuserpwd);
|
2010-08-17 00:19:38 +04:00
|
|
|
conn->allocptr.proxyuserpwd = userp;
|
2013-04-04 03:57:25 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Curl_safefree(conn->allocptr.userpwd);
|
2010-08-17 00:19:38 +04:00
|
|
|
conn->allocptr.userpwd = userp;
|
2013-04-04 03:57:25 +04:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:51:46 +03:00
|
|
|
free(base64);
|
2013-04-04 03:57:25 +04:00
|
|
|
|
2010-08-17 00:19:38 +04:00
|
|
|
return (userp == NULL) ? CURLE_OUT_OF_MEMORY : CURLE_OK;
|
2003-06-10 16:22:19 +04:00
|
|
|
}
|
|
|
|
|
2016-06-21 16:47:12 +03:00
|
|
|
void Curl_cleanup_negotiate(struct Curl_easy *data)
|
2007-11-21 02:17:08 +03:00
|
|
|
{
|
2016-03-13 21:51:46 +03:00
|
|
|
Curl_auth_spnego_cleanup(&data->state.negotiate);
|
|
|
|
Curl_auth_spnego_cleanup(&data->state.proxyneg);
|
2007-11-21 02:17:08 +03:00
|
|
|
}
|
|
|
|
|
2016-03-13 23:09:15 +03:00
|
|
|
#endif /* !CURL_DISABLE_HTTP && USE_SPNEGO */
|