2003-06-10 12:22:19 +00:00
|
|
|
/***************************************************************************
|
2004-06-24 11:54:11 +00:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
2003-06-10 12:22:19 +00:00
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2019-01-04 23:34:50 +01:00
|
|
|
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2003-06-10 12:22:19 +00: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 00:19:02 +01:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2004-06-24 11:54:11 +00:00
|
|
|
*
|
2003-06-10 12:22:19 +00: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 17:23:27 +02:00
|
|
|
|
2013-01-06 19:06:49 +01:00
|
|
|
#include "curl_setup.h"
|
2003-06-10 12:22:19 +00:00
|
|
|
|
2016-03-13 20:09:15 +00:00
|
|
|
#if !defined(CURL_DISABLE_HTTP) && defined(USE_SPNEGO)
|
2003-06-10 12:22:19 +00:00
|
|
|
|
2013-01-04 02:50:28 +01:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "http_negotiate.h"
|
2015-09-12 11:48:24 +01:00
|
|
|
#include "vauth/vauth.h"
|
2003-06-10 12:22:19 +00:00
|
|
|
|
2016-04-29 15:46:40 +02:00
|
|
|
/* The last 3 #include files should be in this order */
|
|
|
|
#include "curl_printf.h"
|
2015-03-24 23:12:03 +01:00
|
|
|
#include "curl_memory.h"
|
2013-01-04 02:50:28 +01:00
|
|
|
#include "memdebug.h"
|
2003-06-10 12:22:19 +00:00
|
|
|
|
2015-01-17 11:56:27 +00:00
|
|
|
CURLcode Curl_input_negotiate(struct connectdata *conn, bool proxy,
|
|
|
|
const char *header)
|
2004-06-24 11:54:11 +00:00
|
|
|
{
|
2016-11-09 15:37:34 +02:00
|
|
|
CURLcode result;
|
2016-06-21 15:47:12 +02:00
|
|
|
struct Curl_easy *data = conn->data;
|
2016-03-13 20:09:15 +00:00
|
|
|
size_t len;
|
2015-01-18 17:36:59 +00:00
|
|
|
|
2016-03-13 20:09:15 +00:00
|
|
|
/* Point to the username, password, service and host */
|
|
|
|
const char *userp;
|
|
|
|
const char *passwdp;
|
2016-03-13 18:51:46 +00:00
|
|
|
const char *service;
|
|
|
|
const char *host;
|
2015-01-18 17:36:59 +00:00
|
|
|
|
2016-03-13 18:51:46 +00:00
|
|
|
/* Point to the correct struct with this */
|
|
|
|
struct negotiatedata *neg_ctx;
|
2015-01-18 17:36:59 +00:00
|
|
|
|
2016-03-13 18:51:46 +00:00
|
|
|
if(proxy) {
|
2016-11-16 10:49:15 -07:00
|
|
|
userp = conn->http_proxy.user;
|
|
|
|
passwdp = conn->http_proxy.passwd;
|
2016-04-08 18:41:41 +01:00
|
|
|
service = data->set.str[STRING_PROXY_SERVICE_NAME] ?
|
|
|
|
data->set.str[STRING_PROXY_SERVICE_NAME] : "HTTP";
|
2016-11-16 10:49:15 -07:00
|
|
|
host = conn->http_proxy.host.name;
|
2018-09-10 09:18:01 +02:00
|
|
|
neg_ctx = &conn->proxyneg;
|
2016-03-13 18:51:46 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-03-13 20:09:15 +00:00
|
|
|
userp = conn->user;
|
|
|
|
passwdp = conn->passwd;
|
2016-04-08 18:41:41 +01:00
|
|
|
service = data->set.str[STRING_SERVICE_NAME] ?
|
|
|
|
data->set.str[STRING_SERVICE_NAME] : "HTTP";
|
2016-04-01 21:48:35 +01:00
|
|
|
host = conn->host.name;
|
2018-09-10 09:18:01 +02:00
|
|
|
neg_ctx = &conn->negotiate;
|
2015-01-18 17:36:59 +00:00
|
|
|
}
|
2003-06-10 12:22:19 +00:00
|
|
|
|
2016-03-13 20:09:15 +00:00
|
|
|
/* Not set means empty */
|
|
|
|
if(!userp)
|
|
|
|
userp = "";
|
|
|
|
|
|
|
|
if(!passwdp)
|
|
|
|
passwdp = "";
|
|
|
|
|
2016-03-13 18:51:46 +00:00
|
|
|
/* Obtain the input token, if any */
|
2014-07-21 09:53:44 +02:00
|
|
|
header += strlen("Negotiate");
|
2006-10-17 21:32:56 +00:00
|
|
|
while(*header && ISSPACE(*header))
|
2003-06-10 12:22:19 +00:00
|
|
|
header++;
|
|
|
|
|
2016-03-13 20:09:15 +00:00
|
|
|
len = strlen(header);
|
2018-09-10 09:18:01 +02:00
|
|
|
neg_ctx->havenegdata = len != 0;
|
2016-03-13 20:09:15 +00:00
|
|
|
if(!len) {
|
2018-09-10 09:18:01 +02:00
|
|
|
if(neg_ctx->state == GSS_AUTHSUCC) {
|
|
|
|
infof(conn->data, "Negotiate auth restarted\n");
|
|
|
|
Curl_cleanup_negotiate(conn);
|
|
|
|
}
|
|
|
|
else if(neg_ctx->state != GSS_AUTHNONE) {
|
|
|
|
/* The server rejected our authentication and hasn't supplied any more
|
2016-03-13 20:09:15 +00:00
|
|
|
negotiation mechanisms */
|
2018-09-10 09:18:01 +02:00
|
|
|
Curl_cleanup_negotiate(conn);
|
2016-03-13 20:09:15 +00:00
|
|
|
return CURLE_LOGIN_DENIED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 18:26:31 +01:00
|
|
|
/* Supports SSL channel binding for Windows ISS extended protection */
|
|
|
|
#if defined(USE_WINDOWS_SSPI) && defined(SECPKG_ATTR_ENDPOINT_BINDINGS)
|
|
|
|
neg_ctx->sslContext = conn->sslContext;
|
|
|
|
#endif
|
|
|
|
|
2018-03-15 22:51:03 -04:00
|
|
|
/* Initialize the security context and decode our challenge */
|
2016-11-09 15:37:34 +02: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 11:56:27 +00:00
|
|
|
}
|
2003-06-10 12:22:19 +00:00
|
|
|
|
2007-09-21 11:05:31 +00:00
|
|
|
CURLcode Curl_output_negotiate(struct connectdata *conn, bool proxy)
|
2004-06-24 11:54:11 +00:00
|
|
|
{
|
2018-09-10 09:18:01 +02:00
|
|
|
struct negotiatedata *neg_ctx = proxy ? &conn->proxyneg :
|
|
|
|
&conn->negotiate;
|
|
|
|
struct auth *authp = proxy ? &conn->data->state.authproxy :
|
|
|
|
&conn->data->state.authhost;
|
2016-03-13 18:51:46 +00:00
|
|
|
char *base64 = NULL;
|
2011-08-24 08:07:36 +02:00
|
|
|
size_t len = 0;
|
2010-08-16 22:19:38 +02:00
|
|
|
char *userp;
|
2014-10-26 16:34:44 +00:00
|
|
|
CURLcode result;
|
2003-09-19 12:56:22 +00:00
|
|
|
|
2018-09-10 09:18:01 +02:00
|
|
|
authp->done = FALSE;
|
|
|
|
|
|
|
|
if(neg_ctx->state == GSS_AUTHRECV) {
|
|
|
|
if(neg_ctx->havenegdata) {
|
|
|
|
neg_ctx->havemultiplerequests = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(neg_ctx->state == GSS_AUTHSUCC) {
|
|
|
|
if(!neg_ctx->havenoauthpersist) {
|
|
|
|
neg_ctx->noauthpersist = !neg_ctx->havemultiplerequests;
|
|
|
|
}
|
|
|
|
}
|
2003-06-10 12:22:19 +00:00
|
|
|
|
2018-09-10 09:18:01 +02:00
|
|
|
if(neg_ctx->noauthpersist ||
|
|
|
|
(neg_ctx->state != GSS_AUTHDONE && neg_ctx->state != GSS_AUTHSUCC)) {
|
2016-03-13 18:51:46 +00:00
|
|
|
|
2018-09-10 09:18:01 +02:00
|
|
|
if(neg_ctx->noauthpersist && neg_ctx->state == GSS_AUTHSUCC) {
|
|
|
|
infof(conn->data, "Curl_output_negotiate, "
|
|
|
|
"no persistent authentication: cleanup existing context");
|
|
|
|
Curl_auth_spnego_cleanup(neg_ctx);
|
|
|
|
}
|
|
|
|
if(!neg_ctx->context) {
|
|
|
|
result = Curl_input_negotiate(conn, proxy, "Negotiate");
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = Curl_auth_create_spnego_message(conn->data,
|
|
|
|
neg_ctx, &base64, &len);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
userp = aprintf("%sAuthorization: Negotiate %s\r\n", proxy ? "Proxy-" : "",
|
|
|
|
base64);
|
|
|
|
|
|
|
|
if(proxy) {
|
|
|
|
Curl_safefree(conn->allocptr.proxyuserpwd);
|
|
|
|
conn->allocptr.proxyuserpwd = userp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Curl_safefree(conn->allocptr.userpwd);
|
|
|
|
conn->allocptr.userpwd = userp;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(base64);
|
|
|
|
|
|
|
|
if(userp == NULL) {
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
neg_ctx->state = GSS_AUTHSENT;
|
|
|
|
#ifdef HAVE_GSSAPI
|
|
|
|
if(neg_ctx->status == GSS_S_COMPLETE ||
|
|
|
|
neg_ctx->status == GSS_S_CONTINUE_NEEDED) {
|
|
|
|
neg_ctx->state = GSS_AUTHDONE;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#ifdef USE_WINDOWS_SSPI
|
|
|
|
if(neg_ctx->status == SEC_E_OK ||
|
|
|
|
neg_ctx->status == SEC_I_CONTINUE_NEEDED) {
|
|
|
|
neg_ctx->state = GSS_AUTHDONE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
2013-04-04 01:57:25 +02:00
|
|
|
}
|
2018-09-10 09:18:01 +02:00
|
|
|
|
|
|
|
if(neg_ctx->state == GSS_AUTHDONE || neg_ctx->state == GSS_AUTHSUCC) {
|
|
|
|
/* connection is already authenticated,
|
|
|
|
* don't send a header in future requests */
|
|
|
|
authp->done = TRUE;
|
2013-04-04 01:57:25 +02:00
|
|
|
}
|
|
|
|
|
2018-09-10 09:18:01 +02:00
|
|
|
neg_ctx->havenegdata = FALSE;
|
2013-04-04 01:57:25 +02:00
|
|
|
|
2018-09-10 09:18:01 +02:00
|
|
|
return CURLE_OK;
|
2003-06-10 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2018-09-10 09:18:01 +02:00
|
|
|
void Curl_cleanup_negotiate(struct connectdata *conn)
|
2007-11-20 23:17:08 +00:00
|
|
|
{
|
2018-09-10 09:18:01 +02:00
|
|
|
Curl_auth_spnego_cleanup(&conn->negotiate);
|
|
|
|
Curl_auth_spnego_cleanup(&conn->proxyneg);
|
2007-11-20 23:17:08 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 20:09:15 +00:00
|
|
|
#endif /* !CURL_DISABLE_HTTP && USE_SPNEGO */
|