1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

bug 1097: Better digest proxy authentication.

Added nc to the auth_entry. nc is incremented every time new
digest request is sent.
This commit is contained in:
Witold Filipczyk 2010-08-07 15:02:51 +02:00 committed by Witold Filipczyk
parent cbf5ef6680
commit 2d906e0886
3 changed files with 31 additions and 3 deletions

View File

@ -27,6 +27,8 @@ struct auth_entry {
unsigned char user[AUTH_USER_MAXLEN];
unsigned char password[AUTH_PASSWORD_MAXLEN];
unsigned int nc; /* nonce count */
unsigned int blocked:1; /* A dialog is asking user for validation */
unsigned int valid:1; /* The entry has been validated by user */
unsigned int digest:1; /* It is an HTTP Digest entry */

View File

@ -4,6 +4,7 @@
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@ -92,6 +93,15 @@ init_uri_method_digest(md5_digest_hex_T uri_method, struct uri *uri)
/* FIXME: Support for also digesting: <nonce-count> ':' <cnonce> ':' <qoup> ':'
* before digesting the H(A2) value if the qop Digest header entry parameter is
* non-empty. */
static unsigned char *
hexl(unsigned int nc)
{
static unsigned char buf[9];
snprintf(buf, 9, "%08x", nc);
return buf;
}
static void
init_response_digest(md5_digest_hex_T response, struct auth_entry *entry,
struct uri *uri, md5_digest_hex_T cnonce)
@ -110,7 +120,7 @@ init_response_digest(md5_digest_hex_T response, struct auth_entry *entry,
if (entry->nonce)
MD5_Update(&MD5Ctx, entry->nonce, strlen(entry->nonce));
MD5_Update(&MD5Ctx, ":", 1);
MD5_Update(&MD5Ctx, "00000001", 8);
MD5_Update(&MD5Ctx, hexl(entry->nc), 8);
MD5_Update(&MD5Ctx, ":", 1);
MD5_Update(&MD5Ctx, cnonce, sizeof(md5_digest_hex_T));
MD5_Update(&MD5Ctx, ":", 1);
@ -133,6 +143,7 @@ get_http_auth_digest_response(struct auth_entry *entry, struct uri *uri)
if (!init_string(&string))
return NULL;
++entry->nc;
init_cnonce_digest(cnonce);
init_response_digest(response, entry, uri, cnonce);
@ -150,8 +161,12 @@ get_http_auth_digest_response(struct auth_entry *entry, struct uri *uri)
add_to_string(&string, "uri=\"/");
add_bytes_to_string(&string, uri->data, uri->datalen);
add_to_string(&string, "\", ");
add_to_string(&string, "qop=auth, nc=00000001, ");
add_to_string(&string, "cnonce=\"");
add_to_string(&string, "qop=auth, ");
add_to_string(&string, "nc=");
add_to_string(&string, hexl(entry->nc));
add_to_string(&string, ", cnonce=\"");
add_bytes_to_string(&string, cnonce, sizeof(md5_digest_hex_T));
add_to_string(&string, "\", ");
add_to_string(&string, "response=\"");

View File

@ -1746,6 +1746,7 @@ again:
}
if (h == 407) {
unsigned char *str;
int st = 0;
d = parse_header(conn->cached->head, "Proxy-Authenticate", &str);
while (d) {
@ -1763,7 +1764,13 @@ again:
unsigned char *realm = get_header_param(d, "realm");
unsigned char *nonce = get_header_param(d, "nonce");
unsigned char *opaque = get_header_param(d, "opaque");
unsigned char *stale = get_header_param(d, "stale");
if (stale) {
if (strcasecmp(stale, "true")) st = 1;
else st = 0;
mem_free(stale);
}
mem_free_set(&proxy_auth.realm, realm);
mem_free_set(&proxy_auth.nonce, nonce);
mem_free_set(&proxy_auth.opaque, opaque);
@ -1776,6 +1783,10 @@ again:
mem_free(d);
d = parse_header(str, "Proxy-Authenticate", &str);
}
if (st) {
retry_connection(conn, connection_state(S_RESTART));
return;
}
}
kill_buffer_data(rb, a);