2003-05-22 18:09:54 +02:00
|
|
|
/***************************************************************************
|
2004-04-29 10:18:32 +02:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
2003-05-22 18:09:54 +02:00
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2014-06-03 18:25:48 +02:00
|
|
|
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2003-05-22 18:09:54 +02:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
2004-04-29 10:18:32 +02:00
|
|
|
*
|
2003-05-22 18:09:54 +02: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-05-22 18:09:54 +02:00
|
|
|
|
2004-11-12 10:18:14 +01:00
|
|
|
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
|
2003-05-22 18:09:54 +02:00
|
|
|
|
2013-01-04 02:50:28 +01:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "rawstr.h"
|
2014-11-05 14:35:27 +01:00
|
|
|
#include "curl_sasl.h"
|
2013-01-04 02:50:28 +01:00
|
|
|
#include "http_digest.h"
|
2009-04-21 13:46:16 +02:00
|
|
|
#include "curl_memory.h"
|
2003-05-22 18:09:54 +02:00
|
|
|
|
|
|
|
#define _MPRINTF_REPLACE /* use our functions only */
|
|
|
|
#include <curl/mprintf.h>
|
|
|
|
|
|
|
|
/* The last #include file should be: */
|
2013-01-04 02:50:28 +01:00
|
|
|
#include "memdebug.h"
|
2003-05-22 18:09:54 +02:00
|
|
|
|
2004-05-04 09:52:53 +02:00
|
|
|
/* Test example headers:
|
2003-05-22 18:09:54 +02:00
|
|
|
|
|
|
|
WWW-Authenticate: Digest realm="testrealm", nonce="1053604598"
|
2004-05-04 09:52:53 +02:00
|
|
|
Proxy-Authenticate: Digest realm="testrealm", nonce="1053604598"
|
2003-05-22 18:09:54 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-11-05 13:05:34 +01:00
|
|
|
CURLcode Curl_input_digest(struct connectdata *conn,
|
|
|
|
bool proxy,
|
|
|
|
const char *header) /* rest of the *-authenticate:
|
|
|
|
header */
|
2003-05-22 18:09:54 +02:00
|
|
|
{
|
|
|
|
struct SessionHandle *data=conn->data;
|
2004-05-04 09:52:53 +02:00
|
|
|
struct digestdata *d;
|
2004-07-31 09:36:01 +02:00
|
|
|
|
2004-05-04 09:52:53 +02:00
|
|
|
if(proxy) {
|
|
|
|
d = &data->state.proxydigest;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
d = &data->state.digest;
|
|
|
|
}
|
2003-05-22 18:09:54 +02:00
|
|
|
|
2014-11-05 15:33:26 +01:00
|
|
|
if(!checkprefix("Digest", header))
|
2014-11-05 13:05:34 +01:00
|
|
|
return CURLE_BAD_CONTENT_ENCODING;
|
2003-05-22 18:09:54 +02:00
|
|
|
|
2014-11-05 15:33:26 +01:00
|
|
|
header += strlen("Digest");
|
|
|
|
while(*header && ISSPACE(*header))
|
|
|
|
header++;
|
|
|
|
|
|
|
|
return Curl_sasl_decode_digest_http_message(header, d);
|
2003-05-22 18:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode Curl_output_digest(struct connectdata *conn,
|
2004-05-04 09:52:53 +02:00
|
|
|
bool proxy,
|
2007-08-27 08:31:28 +02:00
|
|
|
const unsigned char *request,
|
|
|
|
const unsigned char *uripath)
|
2003-05-22 18:09:54 +02:00
|
|
|
{
|
2014-11-05 16:01:51 +01:00
|
|
|
CURLcode result;
|
|
|
|
struct SessionHandle *data = conn->data;
|
|
|
|
unsigned char *path;
|
2014-11-05 16:38:10 +01:00
|
|
|
char *tmp;
|
2014-11-05 16:01:51 +01:00
|
|
|
char *response;
|
|
|
|
size_t len;
|
2014-11-06 11:23:08 +01:00
|
|
|
bool have_chlg;
|
2014-11-05 16:01:51 +01:00
|
|
|
|
|
|
|
/* Point to the address of the pointer that holds the string to send to the
|
|
|
|
server, which is for a plain host or for a HTTP proxy */
|
2004-06-03 12:42:20 +02:00
|
|
|
char **allocuserpwd;
|
2014-11-05 16:01:51 +01:00
|
|
|
|
|
|
|
/* Point to the name and password for this */
|
2008-09-02 19:41:20 +02:00
|
|
|
const char *userp;
|
|
|
|
const char *passwdp;
|
2003-05-22 18:09:54 +02:00
|
|
|
|
2014-11-05 16:01:51 +01:00
|
|
|
/* Point to the correct struct with this */
|
2004-05-04 09:52:53 +02:00
|
|
|
struct digestdata *d;
|
2014-11-05 16:01:51 +01:00
|
|
|
struct auth *authp;
|
2004-05-04 09:52:53 +02:00
|
|
|
|
|
|
|
if(proxy) {
|
|
|
|
d = &data->state.proxydigest;
|
2004-06-03 12:42:20 +02:00
|
|
|
allocuserpwd = &conn->allocptr.proxyuserpwd;
|
|
|
|
userp = conn->proxyuser;
|
|
|
|
passwdp = conn->proxypasswd;
|
2004-05-04 09:52:53 +02:00
|
|
|
authp = &data->state.authproxy;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
d = &data->state.digest;
|
2004-06-03 12:42:20 +02:00
|
|
|
allocuserpwd = &conn->allocptr.userpwd;
|
|
|
|
userp = conn->user;
|
|
|
|
passwdp = conn->passwd;
|
2004-05-04 09:52:53 +02:00
|
|
|
authp = &data->state.authhost;
|
|
|
|
}
|
|
|
|
|
2013-07-12 19:32:13 +02:00
|
|
|
Curl_safefree(*allocuserpwd);
|
2007-07-22 12:17:52 +02:00
|
|
|
|
2004-06-03 12:42:20 +02:00
|
|
|
/* not set means empty */
|
|
|
|
if(!userp)
|
2008-09-02 19:41:20 +02:00
|
|
|
userp="";
|
2004-06-03 12:42:20 +02:00
|
|
|
|
|
|
|
if(!passwdp)
|
2008-09-02 19:41:20 +02:00
|
|
|
passwdp="";
|
2004-06-03 12:42:20 +02:00
|
|
|
|
2014-11-06 11:23:08 +01:00
|
|
|
#if defined(USE_WINDOWS_SSPI)
|
|
|
|
have_chlg = d->input_token ? TRUE : FALSE;
|
|
|
|
#else
|
|
|
|
have_chlg = d->nonce ? TRUE : FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!have_chlg) {
|
2004-05-04 09:52:53 +02:00
|
|
|
authp->done = FALSE;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2003-05-22 18:09:54 +02:00
|
|
|
|
2008-12-11 00:13:31 +01:00
|
|
|
/* So IE browsers < v7 cut off the URI part at the query part when they
|
|
|
|
evaluate the MD5 and some (IIS?) servers work with them so we may need to
|
|
|
|
do the Digest IE-style. Note that the different ways cause different MD5
|
|
|
|
sums to get sent.
|
|
|
|
|
|
|
|
Apache servers can be set to do the Digest IE-style automatically using
|
|
|
|
the BrowserMatch feature:
|
|
|
|
http://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#msie
|
|
|
|
|
|
|
|
Further details on Digest implementation differences:
|
|
|
|
http://www.fngtps.com/2006/09/http-authentication
|
|
|
|
*/
|
2013-12-04 23:08:17 +01:00
|
|
|
|
2014-11-05 16:01:51 +01:00
|
|
|
if(authp->iestyle && ((tmp = strchr((char *)uripath, '?')) != NULL)) {
|
|
|
|
size_t urilen = tmp - (char *)uripath;
|
2008-12-11 00:13:31 +01:00
|
|
|
|
2014-11-05 16:38:10 +01:00
|
|
|
path = (unsigned char *) aprintf("%.*s", urilen, uripath);
|
2013-06-11 00:08:13 +02:00
|
|
|
}
|
2014-11-05 16:01:51 +01:00
|
|
|
else
|
2014-11-05 16:38:10 +01:00
|
|
|
path = (unsigned char *) strdup((char *)uripath);
|
2013-06-11 00:08:13 +02:00
|
|
|
|
2014-11-05 16:01:51 +01:00
|
|
|
if(!path)
|
2004-05-12 15:24:40 +02:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
2014-11-05 16:01:51 +01:00
|
|
|
result = Curl_sasl_create_digest_http_message(data, userp, passwdp, request,
|
|
|
|
path, d, &response, &len);
|
|
|
|
free(path);
|
|
|
|
if(result)
|
|
|
|
return result;
|
2004-04-29 10:18:32 +02:00
|
|
|
|
2014-11-05 16:01:51 +01:00
|
|
|
*allocuserpwd = aprintf("%sAuthorization: Digest %s\r\n",
|
|
|
|
proxy ? "Proxy-" : "",
|
|
|
|
response);
|
2014-11-05 22:33:33 +01:00
|
|
|
free(response);
|
2004-06-03 12:42:20 +02:00
|
|
|
if(!*allocuserpwd)
|
2004-05-12 15:24:40 +02:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2004-04-29 10:18:32 +02:00
|
|
|
|
2014-11-05 16:01:51 +01:00
|
|
|
authp->done = TRUE;
|
2003-05-22 18:09:54 +02:00
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-04 09:52:53 +02:00
|
|
|
void Curl_digest_cleanup(struct SessionHandle *data)
|
|
|
|
{
|
2014-11-05 14:58:24 +01:00
|
|
|
Curl_sasl_digest_cleanup(&data->state.digest);
|
|
|
|
Curl_sasl_digest_cleanup(&data->state.proxydigest);
|
2004-05-04 09:52:53 +02:00
|
|
|
}
|
|
|
|
|
2003-05-22 18:09:54 +02:00
|
|
|
#endif
|