Ethereal-dev: [Ethereal-dev] Re: [patch] eap/tls glue layer.

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Adam <adam@xxxxxxxxxxxx>
Date: Mon, 25 Feb 2002 15:26:46 -0500 (EST)

this is 3rd revison of 'eap/tls glue layer' patch. the major change
is that dissector call for 'ssl' is working correctly.

-- 
Adam
http://www.eax.com	The Supreme Headquarters of the 32 bit registers
This is patch against ethereal (http://www.ethereal.com./)
Based on cvs tree as of : Mon Feb 25 15:23:39 EST 2002

THIS IS THE 3RD REVISION OF THE PATCH.

a small fix in packet-radius (off by 2).

add TLS/EAP glue layer implementation to packet-eap.

calls dissect(tls)

        Adam Sulmicki <adam@xxxxxxxxxxxx>
	Mon Feb 25 15:23:39 EST 2002
        http://www.eax.com/patches/

-------------------------------------------------------------------------------

Index: packet-radius.c
===================================================================
RCS file: /cvsroot/ethereal/packet-radius.c,v
retrieving revision 1.44
diff -u -r1.44 packet-radius.c
--- packet-radius.c	2002/02/25 07:13:28	1.44
+++ packet-radius.c	2002/02/25 20:23:05
@@ -907,7 +907,7 @@
        tvbuff_t   *next_tvb;
        proto_tree_add_text(tree, tvb,offset,2,"t:%s(%u) l:%u",
 			   avptpstrval,avph.avp_type,avph.avp_length);
-       next_tvb = tvb_new_subset(tvb, offset+2,avph.avp_length, -1);
+       next_tvb = tvb_new_subset(tvb, offset+2,avph.avp_length-2, -1);
        call_dissector(eap_handle, next_tvb, pinfo, tree);
      } else 
        proto_tree_add_text(tree, tvb,offset,avph.avp_length,
Index: packet-ssl.c
===================================================================
RCS file: /cvsroot/ethereal/packet-ssl.c,v
retrieving revision 1.17
diff -u -r1.17 packet-ssl.c
--- packet-ssl.c	2002/02/07 18:56:55	1.17
+++ packet-ssl.c	2002/02/25 20:23:08
@@ -2597,6 +2597,9 @@
                                      "When enabled, SSL records that span multiple TCP segments are desegmented",
                                      &ssl_desegment);
     }
+  
+    register_dissector("ssl", dissect_ssl, proto_ssl);
+
 }
 
 /* If this dissector uses sub-dissector registration add a registration
Index: packet-eap.c
===================================================================
RCS file: /cvsroot/ethereal/packet-eap.c,v
retrieving revision 1.11
diff -u -r1.11 packet-eap.c
--- packet-eap.c	2002/02/24 08:10:07	1.11
+++ packet-eap.c	2002/02/25 20:23:08
@@ -36,6 +36,8 @@
 #endif
 
 #include <glib.h>
+#include <ctype.h>
+#include <string.h>
 #include <epan/packet.h>
 #include "packet-ieee8023.h"
 #include "packet-ipx.h"
@@ -51,6 +53,8 @@
 
 static gint ett_eap = -1;
 
+static dissector_handle_t ssl_handle = NULL;
+
 #define EAP_REQUEST	1
 #define EAP_RESPONSE	2
 #define EAP_SUCCESS	3
@@ -75,6 +79,36 @@
     { 0, NULL }
 };
 
+static gchar textbuffer[256];
+
+gchar *eapconvertbufftostr(gchar *dest, tvbuff_t *tvb, int offset, int length)
+{
+/*converts the raw buffer into printable text */
+        guint32 i;
+        guint32 totlen=0;
+        const guint8 *pd = tvb_get_ptr(tvb, offset, length);
+
+        dest[0]='"';
+        dest[1]=0;
+        totlen=1;
+        for (i=0; i < (guint32)length; i++)
+        {
+                if( isalnum((int)pd[i])||ispunct((int)pd[i])
+                                ||((int)pd[i]==' '))            {
+                        dest[totlen]=(gchar)pd[i];
+                        totlen++;
+                }
+                else
+                {
+                        sprintf(&(dest[totlen]), "\\%03u", pd[i]);
+                        totlen=totlen+strlen(&(dest[totlen]));
+                }
+        }
+        dest[totlen]='"';
+        dest[totlen+1]=0;
+        return dest;
+}
+
 static void
 dissect_eap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
@@ -95,8 +129,16 @@
   if (check_col(pinfo->cinfo, COL_INFO))
     col_add_str(pinfo->cinfo, COL_INFO,
 		val_to_str(eap_code, eap_code_vals, "Unknown code (0x%02X)"));
+
+  eap_len = tvb_get_ntohs(tvb, 2);
+  len = eap_len;
+
+  /* at least for now, until we get defragmentation support */
+  if (len>tvb_length(tvb))
+    len=tvb_length(tvb);
+
   if (tree) {
-    ti = proto_tree_add_item(tree, proto_eap, tvb, 0, 4, FALSE);
+    ti = proto_tree_add_item(tree, proto_eap, tvb, 0, len, FALSE);
     eap_tree = proto_item_add_subtree(ti, ett_eap);
 
     proto_tree_add_uint(eap_tree, hf_eap_code, tvb, 0, 1, eap_code);
@@ -105,9 +147,6 @@
   if (tree)
     proto_tree_add_item(eap_tree, hf_eap_identifier, tvb, 1, 1, FALSE);
 
-  eap_len = tvb_get_ntohs(tvb, 2);
-  len = eap_len;
-  set_actual_length(tvb, len);
   if (tree)
     proto_tree_add_uint(eap_tree, hf_eap_len, tvb, 2, 2, eap_len);
 
@@ -121,9 +160,47 @@
 		val_to_str(eap_type, eap_type_vals, "Unknown type (0x%02X)"));
     if (tree) {
       proto_tree_add_uint(eap_tree, hf_eap_type, tvb, 4, 1, eap_type);
+
       if (len > 5) {
-        proto_tree_add_text(eap_tree, tvb, 5, len - 5, "Type-Data (%d byte%s)",
-          len - 5, plurality(len - 5, "", "s"));
+	guint   offset = 5;
+	guint   size   = len - offset;
+
+	if (eap_type==13) {		  
+
+	  guint8 flags = tvb_get_guint8(tvb, offset);
+
+	  proto_tree_add_text(eap_tree, tvb, offset, 1, "Flags(%i): %s%s%s",
+			      flags,
+			      flags & 128 ? "Length " : "",
+			      flags &  64 ? "More " : "",
+			      flags &  32 ? "Start " : "");
+	  size--;
+	  offset++;
+
+	  if (flags >> 7) {
+	    guint32 length = tvb_get_ntohl(tvb, offset);
+	    proto_tree_add_text(eap_tree, tvb, offset, 4, "Length: %i",
+				length);
+	    size   -= 4;
+	    offset += 4;
+	  }
+
+	  if (size>0) {
+	    tvbuff_t   *next_tvb;
+	    proto_tree_add_text(eap_tree, tvb, offset, size, 
+				"Data (%i)",size);
+	    next_tvb = tvb_new_subset(tvb, offset,size, -1);
+	    call_dissector(ssl_handle, next_tvb, pinfo, tree);
+	  }
+
+	}else {
+	  gchar  *msgstr = malloc(size);
+	  eapconvertbufftostr(msgstr,tvb,offset,size);
+	  proto_tree_add_text(eap_tree, tvb, offset, size, 
+			      "Type-Data (%d byte%s) Value:%s",
+			      size, plurality(size, "", "s"),msgstr);
+	  free (msgstr);
+	}
       }
     }
   }
@@ -162,6 +239,11 @@
 proto_reg_handoff_eap(void)
 {
   dissector_handle_t eap_handle;
+
+  /*
+   * Get a handle for the SSL/TLS dissector.
+   */
+  ssl_handle = find_dissector("ssl");
 
   eap_handle = find_dissector("eap");
   dissector_add("ppp.protocol", PPP_EAP, eap_handle);