~ubuntu-branches/ubuntu/raring/nss/raring-security

« back to all changes in this revision

Viewing changes to mozilla/security/nss/cmd/ssltap/ssltap.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2010-03-25 13:46:06 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20100325134606-bl6liuok2w9l7snv
Tags: 3.12.6-0ubuntu1
* New upstream release 3.12.6 RTM (NSS_3_12_6_RTM)
  - fixes CVE-2009-3555 aka US-CERT VU#120541
* Adjust patches to changed upstream code base
  - update debian/patches/38_kbsd.patch
  - update debian/patches/38_mips64_build.patch
  - update debian/patches/85_security_load.patch
* Remove patches that are merged upstream
  - delete debian/patches/91_nonexec_stack.patch
  - update debian/patches/series
* Bump nspr dependency to 4.8
  - update debian/control
* Add new symbols for 3.12.6
  - update debian/libnss3-1d.symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
#include "cert.h"
67
67
#include "sslproto.h"
68
68
 
69
 
#define VERSIONSTRING "$Revision: 1.13 $ ($Date: 2009/03/13 02:24:07 $) $Author: nelson%bolyard.com $"
 
69
#define VERSIONSTRING "$Revision: 1.19 $ ($Date: 2010/02/16 18:56:47 $) $Author: wtc%google.com $"
70
70
 
71
71
 
72
72
struct _DataBufferList;
76
76
  struct _DataBuffer *first,*last;
77
77
  int size;
78
78
  int isEncrypted;
79
 
  char * msgBuf;
80
 
  int    msgBufOffset;
81
 
  int    msgBufSize;
82
 
  int    hMACsize;
 
79
  unsigned char * msgBuf;
 
80
  int             msgBufOffset;
 
81
  int             msgBufSize;
 
82
  int             hMACsize;
83
83
} DataBufferList;
84
84
 
85
85
typedef struct _DataBuffer {
365
365
  case 0x000039:    cs_str = "TLS/DHE-RSA/AES256-CBC/SHA";      break;
366
366
  case 0x00003A:    cs_str = "TLS/DH-ANON/AES256-CBC/SHA";      break;
367
367
 
 
368
  case 0x00003C:    cs_str = "TLS/RSA/AES128-CBC/SHA256";       break;
 
369
  case 0x00003D:    cs_str = "TLS/RSA/AES256-CBC/SHA256";       break;
 
370
  case 0x000040:    cs_str = "TLS/DHE-DSS/AES128-CBC/SHA256";   break;
 
371
 
368
372
  case 0x000041:    cs_str = "TLS/RSA/CAMELLIA128-CBC/SHA";     break;
369
373
  case 0x000042:    cs_str = "TLS/DH-DSS/CAMELLIA128-CBC/SHA";  break;
370
374
  case 0x000043:    cs_str = "TLS/DH-RSA/CAMELLIA128-CBC/SHA";  break;
380
384
  case 0x000065:    cs_str = "TLS/DHE-DSS_EXPORT1024/RC4-56/SHA";  break;
381
385
  case 0x000066:    cs_str = "TLS/DHE-DSS/RC4-128/SHA";            break;
382
386
 
 
387
  case 0x00006A:    cs_str = "TLS/DHE-DSS/AES256-CBC/SHA256";   break;
 
388
 
383
389
  case 0x000072:    cs_str = "TLS/DHE-DSS/3DESEDE-CBC/RMD160"; break;
384
390
  case 0x000073:    cs_str = "TLS/DHE-DSS/AES128-CBC/RMD160";  break;
385
391
  case 0x000074:    cs_str = "TLS/DHE-DSS/AES256-CBC/RMD160";  break;
420
426
  case 0x00009A:    cs_str = "TLS/DHE-RSA/SEED-CBC/SHA";        break;     
421
427
  case 0x00009B:    cs_str = "TLS/DH-ANON/SEED-CBC/SHA";        break;     
422
428
 
 
429
  case 0x0000FF:    cs_str = "TLS_EMPTY_RENEGOTIATION_INFO_SCSV"; break;
 
430
 
423
431
  case 0x00C001:    cs_str = "TLS/ECDH-ECDSA/NULL/SHA";         break;
424
432
  case 0x00C002:    cs_str = "TLS/ECDH-ECDSA/RC4-128/SHA";      break;
425
433
  case 0x00C003:    cs_str = "TLS/ECDH-ECDSA/3DES-EDE-CBC/SHA"; break;
446
454
  case 0x00C018:    cs_str = "TLS/ECDH-anon/AES128-CBC/SHA";    break;
447
455
  case 0x00C019:    cs_str = "TLS/ECDH-anon/AES256-CBC/SHA";    break;
448
456
 
449
 
  case 0x00feff:    cs_str = "SSL3/RSA-FIPS/3DESEDE-CBC/SHA";   break;
450
 
  case 0x00fefe:    cs_str = "SSL3/RSA-FIPS/DES-CBC/SHA";       break;
451
 
  case 0x00ffe1:    cs_str = "SSL3/RSA-FIPS/DES56-CBC/SHA";     break;
452
 
  case 0x00ffe0:    cs_str = "SSL3/RSA-FIPS/3DES192EDE-CBC/SHA";break;
 
457
  case 0x00C023:    cs_str = "TLS/ECDHE-ECDSA/AES128-CBC/SHA256"; break;
 
458
  case 0x00C024:    cs_str = "TLS/ECDHE-ECDSA/AES256-CBC/SHA384"; break;
 
459
  case 0x00C027:    cs_str = "TLS/ECDHE-RSA/AES128-CBC/SHA256"; break;
 
460
  case 0x00C028:    cs_str = "TLS/ECDHE-RSA/AES256-CBC/SHA384"; break;
 
461
  case 0x00C02B:    cs_str = "TLS/ECDHE-ECDSA/AES128-GCM/SHA256"; break;
 
462
  case 0x00C02C:    cs_str = "TLS/ECDHE-ECDSA/AES256-GCM/SHA384"; break;
 
463
 
 
464
  case 0x00FEFF:    cs_str = "SSL3/RSA-FIPS/3DESEDE-CBC/SHA";   break;
 
465
  case 0x00FEFE:    cs_str = "SSL3/RSA-FIPS/DES-CBC/SHA";       break;
 
466
  case 0x00FFE1:    cs_str = "SSL3/RSA-FIPS/DES56-CBC/SHA";     break;
 
467
  case 0x00FFE0:    cs_str = "SSL3/RSA-FIPS/3DES192EDE-CBC/SHA";break;
453
468
 
454
469
  /* the string literal is broken up to avoid trigraphs */
455
470
  default:          cs_str = "????" "/????????" "/?????????" "/???"; break;
458
473
  return cs_str;
459
474
}
460
475
 
 
476
const char * CompressionMethodString(int cm_int) 
 
477
{
 
478
  char *cm_str;
 
479
  cm_str = NULL;
 
480
  switch (cm_int) {
 
481
  case  0: cm_str = "NULL";     break;
 
482
  case  1: cm_str = "DEFLATE";  break;  /* RFC 3749 */
 
483
  case 64: cm_str = "LZS";      break;  /* RFC 3943 */
 
484
  default: cm_str = "???";      break;
 
485
  }
 
486
 
 
487
  return cm_str;
 
488
}
 
489
 
461
490
const char * helloExtensionNameString(int ex_num) 
462
491
{
463
492
  const char *ex_name = NULL;
472
501
  case  5: ex_name = "status_request";                 break;
473
502
  case 10: ex_name = "elliptic_curves";                break;
474
503
  case 11: ex_name = "ec_point_formats";               break;
 
504
  case 13: ex_name = "signature_algorithms";           break;
475
505
  case 35: ex_name = "session_ticket";                 break;
 
506
  case 0xff01: ex_name = "renegotiation_info";         break;
476
507
  default: sprintf(buf, "%d", ex_num);  ex_name = (const char *)buf; break;
477
508
  }
478
509
 
554
585
               (PRUint32)(GET_SHORT((chv2->rndlength))));
555
586
    PR_fprintf(PR_STDOUT,"           cipher-suites = { \n");
556
587
    for (p=0;p<GET_SHORT((chv2->cslength));p+=3) {
557
 
      const char *cs_str=NULL;
558
 
      PRUint32 cs_int=0;
559
 
      cs_int = GET_24((&chv2->csuites[p]));
560
 
      cs_str = V2CipherString(cs_int);
 
588
      PRUint32 cs_int    = GET_24((&chv2->csuites[p]));
 
589
      const char *cs_str = V2CipherString(cs_int);
561
590
 
562
591
      PR_fprintf(PR_STDOUT,"                (0x%06x) %s\n",
563
592
                  cs_int, cs_str);
641
670
    PR_fprintf(PR_STDOUT,"           cipher-suites = { ");
642
671
    len = GET_SHORT((shv2->cslength));
643
672
    for (p = 0; p < len; p += 3) {
644
 
      const char *cs_str=NULL;
645
 
      PRUint32 cs_int=0;
646
 
      cs_int = GET_24((pos+p));
647
 
      cs_str = V2CipherString(cs_int);
 
673
      PRUint32 cs_int    = GET_24((pos+p));
 
674
      const char *cs_str = V2CipherString(cs_int);
648
675
      PR_fprintf(PR_STDOUT,"\n              ");
649
676
      PR_fprintf(PR_STDOUT,"(0x%06x) %s", cs_int, cs_str);
650
677
    }
727
754
  return pos;
728
755
}
729
756
 
730
 
 
 
757
/* In the case of renegotiation, handshakes that occur in an already MAC'ed 
 
758
 * channel, by the time of this call, the caller has already removed the MAC 
 
759
 * from input recordLen. The only MAC'ed record that will get here with its 
 
760
 * MAC intact (not removed) is the first Finished message on the connection.
 
761
 */
731
762
void print_ssl3_handshake(unsigned char *recordBuf, 
732
763
                          unsigned int   recordLen,
733
764
                          SSLRecord *    sr,
742
773
  if (s->msgBufOffset && s->msgBuf) {
743
774
    /* append recordBuf to msgBuf, then use msgBuf */
744
775
    if (s->msgBufOffset + recordLen > s->msgBufSize) {
745
 
      int    newSize = s->msgBufOffset + recordLen;
746
 
      char * newBuf = PORT_Realloc(s->msgBuf, newSize);
 
776
      int             newSize = s->msgBufOffset + recordLen;
 
777
      unsigned char * newBuf = PORT_Realloc(s->msgBuf, newSize);
747
778
      if (!newBuf) {
748
779
        PR_ASSERT(newBuf);
749
780
        showErr( "Realloc failed");
757
788
    recordLen = s->msgBufOffset;
758
789
    recordBuf = s->msgBuf;
759
790
  }
760
 
  while (offset + 4 + s->hMACsize <= recordLen) {
 
791
  while (offset + 4 <= recordLen) {
761
792
    sslh.type = recordBuf[offset]; 
762
793
    sslh.length = GET_24(recordBuf+offset+1);
763
 
    if (offset + 4 + sslh.length + s->hMACsize > recordLen)
 
794
    if (offset + 4 + sslh.length > recordLen)
764
795
      break;
765
796
    /* finally have a complete message */
766
797
    if (sslhexparse) 
816
847
          /* pretty print cipher suites */
817
848
          {
818
849
            int csuitelength = GET_SHORT((hsdata+pos));
819
 
            PR_fprintf(PR_STDOUT,"            cipher_suites[%d] = { \n",
 
850
            PR_fprintf(PR_STDOUT,"            cipher_suites[%d] = {\n",
820
851
                       csuitelength/2);
821
852
            if (csuitelength % 2) {
822
853
              PR_fprintf(PR_STDOUT,
823
854
                 "*error in protocol - csuitelength shouldn't be odd*\n");
824
855
            }
825
856
            for (w=0; w<csuitelength; w+=2) {
826
 
              const char *cs_str=NULL;
827
 
              PRUint32 cs_int=0;
828
 
              cs_int = GET_SHORT((hsdata+pos+2+w));
829
 
              cs_str = V2CipherString(cs_int);
 
857
              PRUint32 cs_int    = GET_SHORT((hsdata+pos+2+w));
 
858
              const char *cs_str = V2CipherString(cs_int);
830
859
              PR_fprintf(PR_STDOUT,
831
860
                "                (0x%04x) %s\n", cs_int, cs_str);
832
861
            }
837
866
          /* pretty print compression methods */
838
867
          {
839
868
            int complength = hsdata[pos];
840
 
            PR_fprintf(PR_STDOUT,"            compression[%d] = {",
 
869
            PR_fprintf(PR_STDOUT,"            compression[%d] = {\n",
841
870
                       complength);
842
871
            for (w=0; w < complength; w++) {
843
 
              PR_fprintf(PR_STDOUT, " %02x", hsdata[pos+1+w]);
 
872
              PRUint32 cm_int    = hsdata[pos+1+w];
 
873
              const char *cm_str = CompressionMethodString(cm_int);
 
874
              PR_fprintf(PR_STDOUT,
 
875
                "                (%02x) %s\n", cm_int, cm_str);
844
876
            }
845
877
            pos += 1 + complength;
846
 
            PR_fprintf(PR_STDOUT," }\n");
 
878
            PR_fprintf(PR_STDOUT,"            }\n");
847
879
          }
848
880
 
849
881
          /* pretty print extensions, if any */
887
919
          currentcipher = cs_int;
888
920
          pos += 2;
889
921
        }
890
 
        PR_fprintf(PR_STDOUT,  "            compression method = %02x\n", 
891
 
                   hsdata[pos++]);
 
922
        /* pretty print chosen compression method */
 
923
        {
 
924
          PRUint32 cm_int    = hsdata[pos++];
 
925
          const char *cm_str = CompressionMethodString(cm_int);
 
926
          PR_fprintf(PR_STDOUT,"            compression method = (%02x) %s\n",
 
927
                     cm_int, cm_str);
 
928
        }
892
929
 
893
930
        /* pretty print extensions, if any */
894
931
        pos = print_hello_extension(hsdata, sslh.length, pos);
1057
1094
      PR_fprintf(PR_STDOUT,"         }\n");
1058
1095
 
1059
1096
      if (!isNULLmac(currentcipher) && !s->hMACsize) {
1060
 
          /* To calculate the size of MAC, we subtract the number
1061
 
           * of known bytes of message from the number of remaining
1062
 
           * bytes in the record. */
 
1097
          /* To calculate the size of MAC, we subtract the number of known 
 
1098
           * bytes of message from the number of remaining bytes in the 
 
1099
           * record. This assumes that this is the first record on the 
 
1100
           * connection to have a MAC, and that the sender has not put another 
 
1101
           * message after the finished message in the handshake record. 
 
1102
           * This is only correct for the first transition from unMACed to 
 
1103
           * MACed. If the connection switches from one cipher suite to 
 
1104
           * another one with a different MAC, this logic will not track that 
 
1105
           * change correctly.
 
1106
           */
1063
1107
          s->hMACsize = recordLen - (sslh.length + 4);
 
1108
          sslh.length += s->hMACsize;  /* skip over the MAC data */
1064
1109
      }
1065
1110
      break;
1066
1111
 
1075
1120
    }  /* end of switch sslh.type */
1076
1121
    offset += sslh.length + 4; 
1077
1122
  } /* while */
1078
 
  if (offset + s->hMACsize < recordLen) { /* stuff left over */
1079
 
    int newMsgLen = recordLen - (offset + s->hMACsize);
 
1123
  if (offset < recordLen) { /* stuff left over */
 
1124
    int newMsgLen = recordLen - offset;
1080
1125
    if (!s->msgBuf) {
1081
1126
      s->msgBuf = PORT_Alloc(newMsgLen);
1082
1127
      if (!s->msgBuf) {
1087
1132
      s->msgBufSize = newMsgLen;
1088
1133
      memcpy(s->msgBuf, recordBuf + offset, newMsgLen);
1089
1134
    } else if (newMsgLen > s->msgBufSize) {
1090
 
      char * newBuf = PORT_Realloc(s->msgBuf, newMsgLen);
 
1135
      unsigned char * newBuf = PORT_Realloc(s->msgBuf, newMsgLen);
1091
1136
      if (!newBuf) {
1092
1137
        PR_ASSERT(newBuf);
1093
1138
        showErr( "Realloc failed");