~ubuntu-branches/ubuntu/trusty/curl/trusty-updates

« back to all changes in this revision

Viewing changes to lib/http_digest.c

  • Committer: Package Import Robot
  • Author(s): Ubuntu Merge-o-Matic
  • Date: 2013-08-12 15:39:32 UTC
  • mfrom: (3.4.41 sid)
  • Revision ID: package-import@ubuntu.com-20130812153932-pmn0qwvy9vghe66x
Tags: 7.32.0-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Drop dependencies not in main:
    + Build-Depends: Drop stunnel4 and libssh2-1-dev.
    + Drop libssh2-1-dev from binary package Depends.
  - Add new libcurl3-udeb package.
  - Add new curl-udeb package.
* Fixes freeipa-client join. (LP: #1220928)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
26
26
 
27
27
#include "urldata.h"
28
 
#include "sendf.h"
29
28
#include "rawstr.h"
30
29
#include "curl_base64.h"
31
30
#include "curl_md5.h"
32
31
#include "http_digest.h"
33
32
#include "strtok.h"
34
 
#include "url.h" /* for Curl_safefree() */
35
33
#include "curl_memory.h"
 
34
#include "sslgen.h" /* for Curl_rand() */
36
35
#include "non-ascii.h" /* included for Curl_convert_... prototypes */
37
36
#include "warnless.h"
38
37
 
283
282
    ++s;
284
283
  }
285
284
 
286
 
  dest = (char *)malloc(n);
 
285
  dest = malloc(n);
287
286
  if(dest) {
288
287
    s = source;
289
288
    d = dest;
310
309
  unsigned char md5buf[16]; /* 16 bytes/128 bits */
311
310
  unsigned char request_digest[33];
312
311
  unsigned char *md5this;
313
 
  unsigned char *ha1;
 
312
  unsigned char ha1[33];/* 32 digits and 1 zero byte */
314
313
  unsigned char ha2[33];/* 32 digits and 1 zero byte */
315
314
  char cnoncebuf[33];
316
315
  char *cnonce = NULL;
317
316
  size_t cnonce_sz = 0;
318
317
  char *tmp = NULL;
319
 
  struct timeval now;
320
 
 
321
318
  char **allocuserpwd;
322
319
  size_t userlen;
323
320
  const char *userp;
354
351
    authp = &data->state.authhost;
355
352
  }
356
353
 
357
 
  if(*allocuserpwd) {
358
 
    Curl_safefree(*allocuserpwd);
359
 
    *allocuserpwd = NULL;
360
 
  }
 
354
  Curl_safefree(*allocuserpwd);
361
355
 
362
356
  /* not set means empty */
363
357
  if(!userp)
376
370
    d->nc = 1;
377
371
 
378
372
  if(!d->cnonce) {
379
 
    /* Generate a cnonce */
380
 
    now = Curl_tvnow();
381
 
    snprintf(cnoncebuf, sizeof(cnoncebuf), "%32ld",
382
 
             (long)now.tv_sec + now.tv_usec);
 
373
    struct timeval now = Curl_tvnow();
 
374
    snprintf(cnoncebuf, sizeof(cnoncebuf), "%08x%08x%08x%08x",
 
375
             Curl_rand(data), Curl_rand(data),
 
376
             (unsigned int)now.tv_sec,
 
377
             (unsigned int)now.tv_usec);
383
378
 
384
379
    rc = Curl_base64_encode(data, cnoncebuf, strlen(cnoncebuf),
385
380
                            &cnonce, &cnonce_sz);
406
401
 
407
402
  CURL_OUTPUT_DIGEST_CONV(data, md5this); /* convert on non-ASCII machines */
408
403
  Curl_md5it(md5buf, md5this);
409
 
  free(md5this); /* free this again */
410
 
 
411
 
  ha1 = malloc(33); /* 32 digits and 1 zero byte */
412
 
  if(!ha1)
413
 
    return CURLE_OUT_OF_MEMORY;
414
 
 
 
404
  Curl_safefree(md5this);
415
405
  md5_to_ascii(md5buf, ha1);
416
406
 
417
407
  if(d->algo == CURLDIGESTALGO_MD5SESS) {
421
411
      return CURLE_OUT_OF_MEMORY;
422
412
    CURL_OUTPUT_DIGEST_CONV(data, tmp); /* convert on non-ASCII machines */
423
413
    Curl_md5it(md5buf, (unsigned char *)tmp);
424
 
    free(tmp); /* free this again */
 
414
    Curl_safefree(tmp);
425
415
    md5_to_ascii(md5buf, ha1);
426
416
  }
427
417
 
463
453
       TODO: replace md5 of empty string with entity-body for PUT/POST */
464
454
    unsigned char *md5this2 = (unsigned char *)
465
455
      aprintf("%s:%s", md5this, "d41d8cd98f00b204e9800998ecf8427e");
466
 
    free(md5this);
 
456
    Curl_safefree(md5this);
467
457
    md5this = md5this2;
468
458
  }
469
459
 
470
 
  if(!md5this) {
471
 
    free(ha1);
 
460
  if(!md5this)
472
461
    return CURLE_OUT_OF_MEMORY;
473
 
  }
474
462
 
475
463
  CURL_OUTPUT_DIGEST_CONV(data, md5this); /* convert on non-ASCII machines */
476
464
  Curl_md5it(md5buf, md5this);
477
 
  free(md5this); /* free this again */
 
465
  Curl_safefree(md5this);
478
466
  md5_to_ascii(md5buf, ha2);
479
467
 
480
468
  if(d->qop) {
492
480
                                       d->nonce,
493
481
                                       ha2);
494
482
  }
495
 
  free(ha1);
496
483
  if(!md5this)
497
484
    return CURLE_OUT_OF_MEMORY;
498
485
 
499
486
  CURL_OUTPUT_DIGEST_CONV(data, md5this); /* convert on non-ASCII machines */
500
487
  Curl_md5it(md5buf, md5this);
501
 
  free(md5this); /* free this again */
 
488
  Curl_safefree(md5this);
502
489
  md5_to_ascii(md5buf, request_digest);
503
490
 
504
491
  /* for test case 64 (snooped from a Mozilla 1.3a request)
515
502
    chracters.
516
503
  */
517
504
  userp_quoted = string_quoted(userp);
518
 
  if(!*userp_quoted)
 
505
  if(!userp_quoted)
519
506
    return CURLE_OUT_OF_MEMORY;
520
507
 
521
508
  if(d->qop) {
559
546
               uripath, /* this is the PATH part of the URL */
560
547
               request_digest);
561
548
  }
562
 
  free(userp_quoted);
 
549
  Curl_safefree(userp_quoted);
563
550
  if(!*allocuserpwd)
564
551
    return CURLE_OUT_OF_MEMORY;
565
552
 
595
582
 
596
583
static void digest_cleanup_one(struct digestdata *d)
597
584
{
598
 
  if(d->nonce)
599
 
    free(d->nonce);
600
 
  d->nonce = NULL;
601
 
 
602
 
  if(d->cnonce)
603
 
    free(d->cnonce);
604
 
  d->cnonce = NULL;
605
 
 
606
 
  if(d->realm)
607
 
    free(d->realm);
608
 
  d->realm = NULL;
609
 
 
610
 
  if(d->opaque)
611
 
    free(d->opaque);
612
 
  d->opaque = NULL;
613
 
 
614
 
  if(d->qop)
615
 
    free(d->qop);
616
 
  d->qop = NULL;
617
 
 
618
 
  if(d->algorithm)
619
 
    free(d->algorithm);
620
 
  d->algorithm = NULL;
 
585
  Curl_safefree(d->nonce);
 
586
  Curl_safefree(d->cnonce);
 
587
  Curl_safefree(d->realm);
 
588
  Curl_safefree(d->opaque);
 
589
  Curl_safefree(d->qop);
 
590
  Curl_safefree(d->algorithm);
621
591
 
622
592
  d->nc = 0;
623
593
  d->algo = CURLDIGESTALGO_MD5; /* default algorithm */