Commit fc6eff13 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

General HTTP authentication cleanup and fixes

parent e7ee1ccf
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -6,6 +6,19 @@

                                  Changelog

Daniel (3 May 2004)
- Rewritten HTTP authentication code. The previous code could not properly
  deal with the added test cases 167, 168 and 169. I've now rewritten the code
  to better separate host and proxy authentication and not re-use the same
  variables as much as before as it proved non working in the more involved
  cases. All the current tests run OK now, and so do the new ones. The curl
  tool got a new option named --proxy-digest to enable HTTP Digest
  authentication with the proxy. I also made the library support it.

- Gisle Vanem made the LDAP code work with wldap32.dll as supplied with
  Win-98/ME/2000/XP, so no extra .dlls are required when curl/libcurl is used
  on these Windows versions.

Daniel (30 April 2004)
- runtests.pl now scans the valgrind log for valgrind-detected memory leaks
  after each test case if valgrind was found and used.
+4 −1
Original line number Diff line number Diff line
@@ -2,12 +2,14 @@ Curl and libcurl 7.12.0.

 Public curl release number:               81
 Releases counted from the very beginning: 108
 Available command line options:           94
 Available command line options:           95
 Available curl_easy_setopt() options:     113
 Number of public functions in libcurl:    35

This release includes the following changes:

 o curl --proxy-digest is a new command line option
 o the Windows version of libcurl can use wldap32.dll for LDAP
 o curl_easy_strerror(), curl_multi_strerror() and curl_share_strerror()
 o IPv6-enabled Windows hosts now resolves names threaded/asynch as well
 o configure --with-libidn can be used to point out the root dir of a libidn
@@ -16,6 +18,7 @@ This release includes the following changes:

This release includes the following bugfixes:

 o HTTP Digest authentication with the proxy works
 o mulipart formposting with -F and file names with spaces work again
 o curl_easy_duphandle() now works when ares-enabled
 o HTTP Digest authentication works a lot more like the RFC says
+207 −193

File changed.

Preview size limit exceeded, changes collapsed.

+3 −3
Original line number Diff line number Diff line
@@ -45,9 +45,9 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap,

/* These functions are in http.c */
void Curl_http_auth_stage(struct SessionHandle *data, int stage);
CURLcode Curl_http_auth(struct connectdata *conn,
CURLcode Curl_http_input_auth(struct connectdata *conn,
                              int httpcode, char *header);
void Curl_http_auth_act(struct connectdata *conn);
CURLcode Curl_http_auth_act(struct connectdata *conn);

int Curl_http_should_fail(struct connectdata *conn);
#endif
+53 −23
Original line number Diff line number Diff line
@@ -47,14 +47,16 @@
#include "memdebug.h"
#endif

/* Test example header:
/* Test example headers:

WWW-Authenticate: Digest realm="testrealm", nonce="1053604598"
Proxy-Authenticate: Digest realm="testrealm", nonce="1053604598"

*/

CURLdigest Curl_input_digest(struct connectdata *conn,
                             char *header) /* rest of the www-authenticate:
                             bool proxy,
                             char *header) /* rest of the *-authenticate:
                                              header */
{
  bool more = TRUE;
@@ -64,7 +66,14 @@ CURLdigest Curl_input_digest(struct connectdata *conn,
  bool foundAuthInt = FALSE;
  struct SessionHandle *data=conn->data;
  bool before = FALSE; /* got a nonce before */
  struct digestdata *d = &data->state.digest;
  struct digestdata *d;
  
  if(proxy) {
    d = &data->state.proxydigest;
  }
  else {
    d = &data->state.digest;
  }

  /* skip initial whitespaces */
  while(*header && isspace((int)*header))
@@ -78,7 +87,7 @@ CURLdigest Curl_input_digest(struct connectdata *conn,
      before = TRUE;

    /* clear off any former leftovers and init to defaults */
    Curl_digest_cleanup(data);
    Curl_digest_cleanup_one(d);

    while(more) {
      char value[32];
@@ -183,6 +192,7 @@ static void md5_to_ascii(unsigned char *source, /* 16 bytes */
}

CURLcode Curl_output_digest(struct connectdata *conn,
                            bool proxy,
                            unsigned char *request,
                            unsigned char *uripath)
{
@@ -198,9 +208,28 @@ CURLcode Curl_output_digest(struct connectdata *conn,
  char *cnonce;
  char *tmp = NULL;
  struct timeval now;
  struct auth *authp;
  char **userp;

  struct SessionHandle *data = conn->data;
  struct digestdata *d = &data->state.digest;
  struct digestdata *d;

  if(proxy) {
    d = &data->state.proxydigest;
    authp = &data->state.authproxy;
    userp = &conn->allocptr.proxyuserpwd;
  }
  else {
    d = &data->state.digest;
    authp = &data->state.authhost;
    userp = &conn->allocptr.userpwd;
  }

  if(!d->nonce) {
    authp->done = FALSE;
    return CURLE_OK;
  }
  authp->done = TRUE;

  ha1 = (unsigned char *)malloc(33); /* 32 digits and 1 zero byte */

@@ -293,8 +322,8 @@ CURLcode Curl_output_digest(struct connectdata *conn,
  Curl_safefree(conn->allocptr.userpwd);

  if (d->qop) {
    conn->allocptr.userpwd =
      aprintf( "Authorization: Digest "
    *userp =
      aprintf( "%sAuthorization: Digest "
               "username=\"%s\", "
               "realm=\"%s\", "
               "nonce=\"%s\", "
@@ -303,6 +332,7 @@ CURLcode Curl_output_digest(struct connectdata *conn,
               "nc=\"%08x\", "
               "qop=\"%s\", "
               "response=\"%s\"",
               proxy?"Proxy-":"",
               conn->user,
               d->realm,
               d->nonce,
@@ -318,13 +348,14 @@ CURLcode Curl_output_digest(struct connectdata *conn,
                  same nonce in the qop=auth mode. */
  }
  else {
    conn->allocptr.userpwd =
      aprintf( "Authorization: Digest "
    *userp =
      aprintf( "%sAuthorization: Digest "
               "username=\"%s\", "
               "realm=\"%s\", "
               "nonce=\"%s\", "
               "uri=\"%s\", "
               "response=\"%s\"",
               proxy?"Proxy-":"",
               conn->user,
               d->realm,
               d->nonce,
@@ -336,36 +367,28 @@ CURLcode Curl_output_digest(struct connectdata *conn,
  if(d->opaque) {
    /* append opaque */
    tmp = aprintf(", opaque=\"%s\"", d->opaque);
    conn->allocptr.userpwd = (char*)
      realloc(conn->allocptr.userpwd,
              strlen(conn->allocptr.userpwd) + strlen(tmp) + 1);
    strcat(conn->allocptr.userpwd, tmp);
    *userp = (char*) realloc(*userp, strlen(*userp) + strlen(tmp) + 1);
    strcat(*userp, tmp);
    free(tmp);
  }

  if(d->algorithm) {
    /* append algorithm */
    tmp = aprintf(", algorithm=\"%s\"", d->algorithm);
    conn->allocptr.userpwd = (char*)
      realloc(conn->allocptr.userpwd,
              strlen(conn->allocptr.userpwd) + strlen(tmp) + 1);
    *userp = (char*) realloc(*userp, strlen(*userp) + strlen(tmp) + 1);
    strcat(conn->allocptr.userpwd, tmp);
    free(tmp);
  }

  /* append CRLF to the userpwd header */
  conn->allocptr.userpwd = (char*)
    realloc(conn->allocptr.userpwd,
            strlen(conn->allocptr.userpwd) + 3 + 1);
  strcat(conn->allocptr.userpwd, "\r\n");
  *userp = (char*) realloc(*userp, strlen(*userp) + 3 + 1);
  strcat(*userp, "\r\n");

  return CURLE_OK;
}

void Curl_digest_cleanup(struct SessionHandle *data)
void Curl_digest_cleanup_one(struct digestdata *d)
{
  struct digestdata *d = &data->state.digest;

  if(d->nonce)
    free(d->nonce);
  d->nonce = NULL;
@@ -395,4 +418,11 @@ void Curl_digest_cleanup(struct SessionHandle *data)
  d->stale = FALSE; /* default means normal, not stale */
}


void Curl_digest_cleanup(struct SessionHandle *data)
{
  Curl_digest_cleanup_one(&data->state.digest);
  Curl_digest_cleanup_one(&data->state.proxydigest);
}

#endif
Loading