mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
Better Digest stuff
This commit is contained in:
parent
9f69deec7d
commit
a39d77227f
@ -670,7 +670,9 @@ CURLcode Curl_http(struct connectdata *conn)
|
|||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else if((conn->bits.user_passwd) && !checkheaders(data, "Authorization:")) {
|
else if(!data->set.httpdigest && /* not if Digest is enabled */
|
||||||
|
conn->bits.user_passwd &&
|
||||||
|
!checkheaders(data, "Authorization:")) {
|
||||||
char *authorization;
|
char *authorization;
|
||||||
|
|
||||||
/* To prevent the user+password to get sent to other than the original
|
/* To prevent the user+password to get sent to other than the original
|
||||||
|
@ -65,7 +65,8 @@ CURLdigest Curl_input_digest(struct connectdata *conn,
|
|||||||
if(checkprefix("Digest", header)) {
|
if(checkprefix("Digest", header)) {
|
||||||
header += strlen("Digest");
|
header += strlen("Digest");
|
||||||
|
|
||||||
data->state.digest.algo = CURLDIGESTALGO_MD5; /* default algorithm */
|
/* clear off any former leftovers and init to defaults */
|
||||||
|
Curl_digest_cleanup(data);
|
||||||
|
|
||||||
while(more) {
|
while(more) {
|
||||||
char value[32];
|
char value[32];
|
||||||
@ -207,4 +208,21 @@ CURLcode Curl_output_digest(struct connectdata *conn,
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Curl_digest_cleanup(struct SessionHandle *data)
|
||||||
|
{
|
||||||
|
if(data->state.digest.nonce)
|
||||||
|
free(data->state.digest.nonce);
|
||||||
|
data->state.digest.nonce = NULL;
|
||||||
|
|
||||||
|
if(data->state.digest.cnonce)
|
||||||
|
free(data->state.digest.cnonce);
|
||||||
|
data->state.digest.cnonce = NULL;
|
||||||
|
|
||||||
|
if(data->state.digest.realm)
|
||||||
|
free(data->state.digest.realm);
|
||||||
|
data->state.digest.realm = NULL;
|
||||||
|
|
||||||
|
data->state.digest.algo = CURLDIGESTALGO_MD5; /* default algorithm */
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,4 +43,6 @@ CURLdigest Curl_input_digest(struct connectdata *conn, char *header);
|
|||||||
CURLcode Curl_output_digest(struct connectdata *conn,
|
CURLcode Curl_output_digest(struct connectdata *conn,
|
||||||
unsigned char *request,
|
unsigned char *request,
|
||||||
unsigned char *uripath);
|
unsigned char *uripath);
|
||||||
|
void Curl_digest_cleanup(struct SessionHandle *data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -704,15 +704,20 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
|||||||
}
|
}
|
||||||
else if(checkprefix("WWW-Authenticate:", k->p) &&
|
else if(checkprefix("WWW-Authenticate:", k->p) &&
|
||||||
(401 == k->httpcode) &&
|
(401 == k->httpcode) &&
|
||||||
1 /* TODO: replace with a check for Digest authentication
|
data->set.httpdigest /* Digest authentication is
|
||||||
activated */) {
|
activated */) {
|
||||||
CURLdigest dig = Curl_input_digest(conn, k->p+
|
CURLdigest dig = CURLDIGEST_BAD;
|
||||||
strlen("WWW-Authenticate:"));
|
|
||||||
if(CURLDIGEST_FINE == dig) {
|
if(data->state.digest.nonce)
|
||||||
|
infof(data, "Authentication problem. Ignoring this.");
|
||||||
|
else
|
||||||
|
dig = Curl_input_digest(conn,
|
||||||
|
k->p+strlen("WWW-Authenticate:"));
|
||||||
|
|
||||||
|
if(CURLDIGEST_FINE == dig)
|
||||||
/* We act on it. Store our new url, which happens to be
|
/* We act on it. Store our new url, which happens to be
|
||||||
the same one we already use! */
|
the same one we already use! */
|
||||||
conn->newurl = strdup(data->change.url); /* clone string */
|
conn->newurl = strdup(data->change.url); /* clone string */
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if ((k->httpcode >= 300 && k->httpcode < 400) &&
|
else if ((k->httpcode >= 300 && k->httpcode < 400) &&
|
||||||
checkprefix("Location:", k->p)) {
|
checkprefix("Location:", k->p)) {
|
||||||
@ -797,7 +802,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
|||||||
/* HTTP-only checks */
|
/* HTTP-only checks */
|
||||||
if (conn->newurl) {
|
if (conn->newurl) {
|
||||||
/* abort after the headers if "follow Location" is set */
|
/* abort after the headers if "follow Location" is set */
|
||||||
infof (data, "Follow to new URL: %s\n", conn->newurl);
|
infof (data, "Send request to this URL: %s\n", conn->newurl);
|
||||||
k->keepon &= ~KEEP_READ;
|
k->keepon &= ~KEEP_READ;
|
||||||
FD_ZERO(&k->rkeepfd);
|
FD_ZERO(&k->rkeepfd);
|
||||||
*done = TRUE;
|
*done = TRUE;
|
||||||
@ -1568,7 +1573,7 @@ CURLcode Curl_follow(struct SessionHandle *data,
|
|||||||
data->change.url = newurl;
|
data->change.url = newurl;
|
||||||
newurl = NULL; /* don't free! */
|
newurl = NULL; /* don't free! */
|
||||||
|
|
||||||
infof(data, "Follows Location: to new URL: '%s'\n", data->change.url);
|
infof(data, "Issue another request to this URL: '%s'\n", data->change.url);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We get here when the HTTP code is 300-399. We need to perform
|
* We get here when the HTTP code is 300-399. We need to perform
|
||||||
|
@ -671,6 +671,7 @@ struct UserDefined {
|
|||||||
char *set_proxy; /* proxy to use */
|
char *set_proxy; /* proxy to use */
|
||||||
long use_port; /* which port to use (when not using default) */
|
long use_port; /* which port to use (when not using default) */
|
||||||
char *userpwd; /* <user:password>, if used */
|
char *userpwd; /* <user:password>, if used */
|
||||||
|
bool httpdigest; /* if HTTP Digest is enabled */
|
||||||
char *set_range; /* range, if used. See README for detailed specification
|
char *set_range; /* range, if used. See README for detailed specification
|
||||||
on this syntax. */
|
on this syntax. */
|
||||||
long followlocation; /* as in HTTP Location: */
|
long followlocation; /* as in HTTP Location: */
|
||||||
|
Loading…
Reference in New Issue
Block a user