Bug 430743: Added the GET_32 macro for reading uint32. Use {...} (with
authorwtc%google.com
Wed, 07 May 2008 15:42:59 +0000
changeset 8585 6e90db810e434cc270b4ef14e4abf996e8dd258d
parent 8581 f741aabd21cffe0e478f0d2f6f2708e5bf637a47
child 8586 2257549ecdf00efbe8c760442a9122818a644332
push idunknown
push userunknown
push dateunknown
bugs430743
Bug 430743: Added the GET_32 macro for reading uint32. Use {...} (with three dots) for consistency. Parse the NewSessionTicket handshake message. r=nelson.
security/nss/cmd/ssltap/ssltap.c
--- a/security/nss/cmd/ssltap/ssltap.c
+++ b/security/nss/cmd/ssltap/ssltap.c
@@ -154,16 +154,25 @@ int hMACsize=0;
 #define GET_SHORT(x) ((PRUint16)(((PRUint16)((PRUint8*)x)[0]) << 8) + ((PRUint16)((PRUint8*)x)[1]))
 #define GET_24(x) ((PRUint32)   (  \
 				 (((PRUint32)((PRUint8*)x)[0]) << 16) \
 				 +                          \
 				 (((PRUint32)((PRUint8*)x)[1]) << 8)  \
 				 +                          \
 				 (((PRUint32)((PRUint8*)x)[2]) << 0)  \
 				 ) )
+#define GET_32(x) ((PRUint32)   (  \
+				 (((PRUint32)((PRUint8*)x)[0]) << 24) \
+				 +                          \
+				 (((PRUint32)((PRUint8*)x)[1]) << 16) \
+				 +                          \
+				 (((PRUint32)((PRUint8*)x)[2]) << 8)  \
+				 +                          \
+				 (((PRUint32)((PRUint8*)x)[3]) << 0)  \
+				 ) )
 
 void print_hex(int amt, unsigned char *buf);
 void read_stream_bytes(unsigned char *d, DataBufferList *db, int length);
 
 void myhalt(int dblsize,int collectedsize) {
 
   while(1) ;
 
@@ -753,17 +762,17 @@ void print_ssl3_handshake(unsigned char 
 	  PR_fprintf(PR_STDOUT,"            random = {...}\n");
 	  if (sslhexparse) print_hex(32,&hsdata[2]);
 
 	  /* pretty print Session ID */
 	  {
 	    int sidlength = (int)hsdata[2+32];
 	    PR_fprintf(PR_STDOUT,"            session ID = {\n");
 	    PR_fprintf(PR_STDOUT,"                length = %d\n",sidlength);
-	    PR_fprintf(PR_STDOUT,"                contents = {..}\n");
+	    PR_fprintf(PR_STDOUT,"                contents = {...}\n");
 	    if (sslhexparse) print_hex(sidlength,&hsdata[2+32+1]);
 	    PR_fprintf(PR_STDOUT,"            }\n");
 	    pos = 2+32+1+sidlength;
 	  }
 
 	  /* pretty print cipher suites */
 	  {
 	    int csuitelength = GET_SHORT((hsdata+pos));
@@ -819,17 +828,17 @@ void print_ssl3_handshake(unsigned char 
 
 	PR_fprintf(PR_STDOUT,"            server_version = {%d, %d}\n",
 		   (PRUint8)hsdata[0],(PRUint8)hsdata[1]);
 	PR_fprintf(PR_STDOUT,"            random = {...}\n");
 	if (sslhexparse) print_hex(32,&hsdata[2]);
 	PR_fprintf(PR_STDOUT,"            session ID = {\n");
 	sidlength = (int)hsdata[2+32];
 	PR_fprintf(PR_STDOUT,"                length = %d\n",sidlength);
-	PR_fprintf(PR_STDOUT,"                contents = {..}\n");
+	PR_fprintf(PR_STDOUT,"                contents = {...}\n");
 	if (sslhexparse) print_hex(sidlength,&hsdata[2+32+1]);
 	PR_fprintf(PR_STDOUT,"            }\n");
 	pos = 2+32+1+sidlength;
 
 	/* pretty print chosen cipher suite */
 	{
 	  PRUint32 cs_int    = GET_SHORT((hsdata+pos));
 	  const char *cs_str = V2CipherString(cs_int);
@@ -845,26 +854,41 @@ void print_ssl3_handshake(unsigned char 
 	pos = print_hello_extension(hsdata, sslh.length, pos);
 
 	PR_fprintf(PR_STDOUT,"         }\n");
       }
       break;
 
     case 4: /* new session ticket */
       {
-        /*
-         * XXX: parse the message:
-         * struct {
-         *     uint32 ticket_lifetime_hint;
-         *     opaque ticket<0..2^16-1>;
-         * } NewSessionTicket;
-         */
-	PR_fprintf(PR_STDOUT,"         NewSessionTicket [%d] {\n",
-	                     sslh.length);
-	if (sslhexparse) print_hex(sslh.length, hsdata);
+	PRUint32 lifetimehint;
+	PRUint16 ticketlength;
+	char lifetime[32];
+	lifetimehint = GET_32(hsdata);
+	if (lifetimehint) {
+	  PRExplodedTime et;
+	  PRTime t = lifetimehint;
+	  t *= PR_USEC_PER_SEC;
+	  PR_ExplodeTime(t, PR_GMTParameters, &et);
+	  /* use HTTP Cookie header's date format */
+	  PR_FormatTimeUSEnglish(lifetime, sizeof lifetime,
+				 "%a, %d-%b-%Y %H:%M:%S GMT", &et);
+	} else {
+	  /* 0 means the lifetime of the ticket is unspecified */
+	  strcpy(lifetime, "unspecified");
+	}
+	ticketlength = GET_SHORT((hsdata+4));
+	PR_fprintf(PR_STDOUT,"         NewSessionTicket {\n");
+	PR_fprintf(PR_STDOUT,"            ticket_lifetime_hint = %s\n",
+		   lifetime);
+	PR_fprintf(PR_STDOUT,"            ticket = {\n");
+	PR_fprintf(PR_STDOUT,"                length = %d\n",ticketlength);
+	PR_fprintf(PR_STDOUT,"                contents = {...}\n");
+	if (sslhexparse) print_hex(ticketlength,&hsdata[4+2]);
+	PR_fprintf(PR_STDOUT,"            }\n");
 	PR_fprintf(PR_STDOUT,"         }\n");
       }
       break;
 
     case 11: /* certificate */
       {
 	PRFileDesc *cfd;
 	int         pos;