From Michael Tuexen: update for the ASAP dissector which provides
[obnox/wireshark/wip.git] / packet-wtls.c
1 /* packet-wtls.c
2  *
3  * Routines to dissect WTLS component of WAP traffic.
4  * 
5  * $Id: packet-wtls.c,v 1.19 2002/06/15 23:27:15 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * WAP dissector based on original work by Ben Fowler
12  * Updated by Neil Hunter <neil.hunter@energis-squared.com>
13  * WTLS support by Alexandre P. Ferreira (Splice IP)
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  * 
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  * 
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <stdio.h>
35 #include <stdlib.h>
36
37 #ifdef HAVE_SYS_TYPES_H
38 # include <sys/types.h>
39 #endif
40
41 #ifdef HAVE_NETINET_IN_H
42 # include <netinet/in.h>
43 #endif
44
45 #ifdef NEED_SNPRINTF_H
46 # ifdef HAVE_STDARG_H
47 #  include <stdarg.h>
48 # else
49 #  include <varargs.h>
50 # endif
51 # include "snprintf.h"
52 #endif
53
54 #include <string.h>
55 #include <glib.h>
56 #include <epan/packet.h>
57 #include "packet-wap.h"
58 #include "packet-wtls.h"
59
60 /* File scoped variables for the protocol and registered fields */
61 static int proto_wtls                                                   = HF_EMPTY;
62
63 /* These fields used by fixed part of header */
64 static int hf_wtls_record                             = HF_EMPTY;
65 static int hf_wtls_record_type                                = HF_EMPTY;
66 static int hf_wtls_record_length                      = HF_EMPTY;
67 static int hf_wtls_record_sequence                    = HF_EMPTY;
68 static int hf_wtls_record_ciphered                    = HF_EMPTY;
69 static int hf_wtls_hands                              = HF_EMPTY;
70 static int hf_wtls_hands_type                 = HF_EMPTY;
71 static int hf_wtls_hands_length                       = HF_EMPTY;
72 static int hf_wtls_hands_cli_hello            = HF_EMPTY;
73 static int hf_wtls_hands_cli_hello_version    = HF_EMPTY;
74 static int hf_wtls_hands_cli_hello_gmt                = HF_EMPTY;
75 static int hf_wtls_hands_cli_hello_random     = HF_EMPTY;
76 static int hf_wtls_hands_cli_hello_session    = HF_EMPTY;
77 static int hf_wtls_hands_cli_hello_session_str    = HF_EMPTY;
78 static int hf_wtls_hands_cli_hello_cli_key_id    = HF_EMPTY;
79 static int hf_wtls_hands_cli_hello_cli_key_len    = HF_EMPTY;
80 static int hf_wtls_hands_cli_hello_trust_key_id    = HF_EMPTY; 
81 static int hf_wtls_hands_cli_hello_key_exchange               =HF_EMPTY;
82 static int hf_wtls_hands_cli_hello_key_exchange_suite         =HF_EMPTY;
83 static int hf_wtls_hands_cli_hello_key_parameter_index                =HF_EMPTY;
84 static int hf_wtls_hands_cli_hello_key_parameter_set          =HF_EMPTY;
85 static int hf_wtls_hands_cli_hello_key_identifier_type                =HF_EMPTY;
86 static int hf_wtls_hands_cli_hello_key_identifier_charset             =HF_EMPTY;
87 static int hf_wtls_hands_cli_hello_key_identifier_size                =HF_EMPTY;
88 static int hf_wtls_hands_cli_hello_key_identifier                     =HF_EMPTY;
89 static int hf_wtls_hands_cli_hello_key_identifier_str                 =HF_EMPTY;
90 static int hf_wtls_hands_cli_hello_cipher_suite               =HF_EMPTY;
91 static int hf_wtls_hands_cli_hello_cipher_suite_item  =HF_EMPTY;
92 static int hf_wtls_hands_cli_hello_compression_methods                =HF_EMPTY;
93 static int hf_wtls_hands_cli_hello_compression                =HF_EMPTY;
94 static int hf_wtls_hands_cli_hello_sequence_mode      =HF_EMPTY;
95 static int hf_wtls_hands_cli_hello_key_refresh        =HF_EMPTY;
96 static int hf_wtls_hands_serv_hello           = HF_EMPTY;
97 static int hf_wtls_hands_serv_hello_version   = HF_EMPTY;
98 static int hf_wtls_hands_serv_hello_gmt               = HF_EMPTY;
99 static int hf_wtls_hands_serv_hello_random    = HF_EMPTY;
100 static int hf_wtls_hands_serv_hello_session   = HF_EMPTY;
101 static int hf_wtls_hands_serv_hello_session_str   = HF_EMPTY;
102 static int hf_wtls_hands_serv_hello_cli_key_id                =HF_EMPTY;
103 static int hf_wtls_hands_serv_hello_cipher_suite_item =HF_EMPTY;
104 static int hf_wtls_hands_serv_hello_cipher_bulk               =HF_EMPTY;
105 static int hf_wtls_hands_serv_hello_cipher_mac                =HF_EMPTY;
106 static int hf_wtls_hands_serv_hello_compression               =HF_EMPTY;
107 static int hf_wtls_hands_serv_hello_sequence_mode     =HF_EMPTY;
108 static int hf_wtls_hands_serv_hello_key_refresh       =HF_EMPTY;
109 static int hf_wtls_hands_certificates =HF_EMPTY;
110 static int hf_wtls_hands_certificate    =HF_EMPTY;
111 static int hf_wtls_hands_certificate_type     =HF_EMPTY;
112 static int hf_wtls_hands_certificate_wtls_version     =HF_EMPTY;
113 static int hf_wtls_hands_certificate_wtls_signature_type      =HF_EMPTY;
114 static int hf_wtls_hands_certificate_wtls_issuer_type =HF_EMPTY;
115 static int hf_wtls_hands_certificate_wtls_issuer_charset      =HF_EMPTY;
116 static int hf_wtls_hands_certificate_wtls_issuer_size =HF_EMPTY;
117 static int hf_wtls_hands_certificate_wtls_issuer_name =HF_EMPTY;
118 static int hf_wtls_hands_certificate_wtls_valid_not_before    =HF_EMPTY;
119 static int hf_wtls_hands_certificate_wtls_valid_not_after     =HF_EMPTY;
120 static int hf_wtls_hands_certificate_wtls_subject_type        =HF_EMPTY;
121 static int hf_wtls_hands_certificate_wtls_subject_charset     =HF_EMPTY;
122 static int hf_wtls_hands_certificate_wtls_subject_size        = HF_EMPTY;
123 static int hf_wtls_hands_certificate_wtls_subject_name        = HF_EMPTY;
124 static int hf_wtls_hands_certificate_wtls_public_key_type = HF_EMPTY;
125 static int hf_wtls_hands_certificate_wtls_key_parameter_index = HF_EMPTY;
126 static int hf_wtls_hands_certificate_wtls_key_parameter_set = HF_EMPTY;
127 static int hf_wtls_hands_certificate_wtls_rsa_exponent = HF_EMPTY;
128 static int hf_wtls_hands_certificate_wtls_rsa_modules = HF_EMPTY;
129 static int hf_wtls_hands_certificate_wtls_signature = HF_EMPTY;
130 static int hf_wtls_alert = HF_EMPTY;
131 static int hf_wtls_alert_level = HF_EMPTY;
132 static int hf_wtls_alert_description = HF_EMPTY;
133
134 /* Initialize the subtree pointers */
135 static gint ett_wtls                                                    = ETT_EMPTY;
136 static gint ett_wtls_rec                              = ETT_EMPTY;
137 static gint ett_wtls_msg_type                                 = ETT_EMPTY;
138 static gint ett_wtls_msg_type_item                    = ETT_EMPTY;
139 static gint ett_wtls_msg_type_item_sub                        = ETT_EMPTY;
140 static gint ett_wtls_msg_type_item_sub_sub            = ETT_EMPTY;
141
142 /* Handles for WTP and WSP dissectors */
143 static dissector_handle_t wtp_handle;
144 static dissector_handle_t wsp_handle;
145
146 static const value_string wtls_vals_record_type[] = {
147         { 1, "change_cipher_data" },
148         { 2, "alert" },
149         { 3, "handshake" },
150         { 4, "application_data" },
151         { 0, NULL }
152 };
153
154 static const value_string wtls_vals_cipher_bulk[] = {
155         { 0, "Null" },
156         { 1, "RC5 CBC 40" },
157         { 2, "RC5 CBC 56" },
158         { 3, "RC5 CBC" },
159         { 4, "DES CBC 40" },
160         { 5, "DES CBC" },
161         { 6, "3DES CBC cwEDE40" },
162         { 7, "IDEA CBC 40" },
163         { 8, "IDEA CBC 56" },
164         { 9, "IDEA CBC" },
165         { 0, NULL }
166 };
167
168 static const value_string wtls_vals_cipher_mac[] = {
169         { 0, "SHA 0" },
170         { 1, "SHA 40 " },
171         { 2, "SHA 80" },
172         { 3, "SHA" },
173         { 4, "SHA XOR 40" },
174         { 5, "MD5 40" },
175         { 6, "MD5 80" },
176         { 7, "MD5" },
177         { 0, NULL }
178 };
179
180 static const value_string wtls_vals_handshake_type[] = {
181         { 0, "Hello Request" },
182         { 1, "Client Hello" },
183         { 2, "Server Hello" },
184         { 11, "Certificate" },
185         { 12, "Server Key Exchange" },
186         { 13, "Certificate Request" },
187         { 14, "Server Hello Done" },
188         { 15, "Certificate Verify" },
189         { 16, "Client Key Exchange" },
190         { 20, "Finished" },
191         { 0x00, NULL }
192 };
193
194 static const value_string wtls_vals_key_exchange_suite[] = {
195         { 0, "NULL" },
196         { 1, "Shared Secret" },
197         { 2, "Diffie Hellman Anonymous" },
198         { 3, "Diffie Hellman Anonymous 512" },
199         { 4, "Diffie Hellman Anonymous 768" },
200         { 5, "RSA Anonymous" },
201         { 6, "RSA Anonymous 512" },
202         { 7, "RSA Anonymous 768" },
203         { 8, "RSA" },
204         { 9, "RSA 512" },
205         { 10, "RSA 768" },
206         { 11, "EC Diffie Hellman Anonymous" },
207         { 12, "EC Diffie Hellman Anonymous 113" },
208         { 13, "EC Diffie Hellman Anonymous 131" },
209         { 14, "EC Diffie Hellman ECDSA" },
210         { 15, "EC Diffie Hellman Anonymous Uncomp" },
211         { 16, "EC Diffie Hellman Anonymous Uncomp 113" },
212         { 17, "EC Diffie Hellman Anonymous Uncomp 131" },
213         { 18, "EC Diffie Hellman ECDSA Uncomp" },
214         { 0x00, NULL }
215 };
216
217 static const value_string wtls_vals_identifier_type[] = {
218         { 0, "No identifier" },
219         { 1, "Textual Name" },
220         { 2, "Binary Name" },
221         { 254, "SHA-1 Hash of Public Key" },
222         { 255, "x509 Distinguished Name" },
223         { 0x00, NULL }
224 };
225
226 static const value_string wtls_vals_certificate_type[] = {
227         { 1, "WTLS" },
228         { 2, "X.509" },
229         { 3, "X.968" },
230         { 4, "URL" },
231         { 0x00, NULL }
232 };
233
234 static const value_string wtls_vals_compression[] = {
235         { 0, "Null" },
236         { 0x00, NULL }
237 };
238
239 static const value_string wtls_vals_sequence_mode[] = {
240         { 0, "Off" },
241         { 1, "Implicit" },
242         { 2, "Explicit" },
243         { 0x00, NULL }
244 };
245
246 static const value_string wtls_vals_certificate_signature[] = {
247         { 0, "Anonymous" },
248         { 1, "ECDSA_SHA" },
249         { 2, "RSA_SHA" },
250         { 0x00, NULL }
251 };
252
253 static const value_string wtls_vals_public_key_type[] = {
254         { 2, "RSA" },
255         { 3, "ECDH" },
256         { 4, "ECSA" },
257         { 0x00, NULL }
258 };
259
260 static const value_string wtls_vals_alert_level[] = {
261         { 1, "Warning" },
262         { 2, "Critical" },
263         { 3, "Fatal" },
264         { 0x00, NULL }
265 };
266
267 static const value_string wtls_vals_alert_description[] = {
268         { 0,"connection_close_notify"},
269         { 1,"session_close_notify"},
270         { 5,"no_connection"},
271         { 10,"unexpected_message"},
272         { 11,"time_required"},
273         { 20,"bad_record_mac"},
274         { 21,"decryption_failed"},
275         { 22,"record_overflow"},
276         { 30,"decompression_failure"},
277         { 40,"handshake_failure"},
278         { 42,"bad_certificate"},
279         { 43,"unsupported_certificate"},
280         { 44,"certificate_revoked"},
281         { 45,"certificate_expired"},
282         { 46,"certificate_unknown"},
283         { 47,"illegal_parameter"},
284         { 48,"unknown_ca"},
285         { 49,"access_denied"},
286         { 50,"decode_error"},
287         { 51,"decrypt_error"},
288         { 52,"unknown_key_id"},
289         { 53,"disabled_key_id"},
290         { 54,"key_exchange_disabled"},
291         { 55,"session_not_ready"},
292         { 56,"unknown_parameter_index"},
293         { 57,"duplicate_finished_received"},
294         { 60,"export_restriction"},
295         { 70,"protocol_version"},
296         { 71,"insufficient_security"},
297         { 80,"internal_error"},
298         { 90,"user_canceled"},
299         { 100,"no_renegotiation"},
300         { 0x00, NULL }
301 };
302
303 #define WTLS_RECORD_TYPE_LENGTH         0x80
304 #define WTLS_RECORD_TYPE_SEQUENCE       0x40
305 #define WTLS_RECORD_TYPE_CIPHER_CUR     0x20
306 #define WTLS_RECORD_CONTENT_TYPE        0x0f
307
308 #define WTLS_ALERT                      0x02
309 #define WTLS_PLAIN_HANDSHAKE            0x03
310
311 #define WTLS_HANDSHAKE_CLIENT_HELLO     1
312 #define WTLS_HANDSHAKE_SERVER_HELLO     2
313 #define WTLS_HANDSHAKE_CERTIFICATE      11
314
315 #define CERTIFICATE_WTLS                1
316 #define CERTIFICATE_X509                2
317 #define CERTIFICATE_X968                3
318 #define CERTIFICATE_URL                 4
319
320 #define IDENTIFIER_NULL                 0
321 #define IDENTIFIER_TEXT                 1
322 #define IDENTIFIER_BIN                  2
323 #define IDENTIFIER_SHA_1                254
324 #define IDENTIFIER_X509                 255
325
326 #define PUBLIC_KEY_RSA                  2
327 #define PUBLIC_KEY_ECDH                 3
328 #define PUBLIC_KEY_ECDSA                4
329
330 static void dissect_wtls_handshake (proto_tree *, tvbuff_t *, guint, guint);
331
332 /* Code to actually dissect the packets */
333 static void
334 dissect_wtls(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
335 {
336         int offset = 0;
337
338         char pdut;
339         char pdu_msg_type;
340         guint count = 0;
341         guint offset_wtls = 0;
342
343 /* Set up structures we will need to add the protocol subtree and manage it */
344         proto_item *ti;
345         proto_tree *wtls_tree;
346         proto_tree *wtls_rec_tree;
347         proto_tree *wtls_msg_type_tree;
348
349         if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
350         {
351                 switch ( pinfo->match_port )
352                 {
353                         case UDP_PORT_WTLS_WSP:
354                                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "WTLS+WSP" );
355                                 break;
356                         case UDP_PORT_WTLS_WTP_WSP:
357                                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "WTLS+WTP+WSP" );
358                                 break;
359                 }
360         }
361
362         /* Develop the string to put in the Info column */
363         if (check_col(pinfo->cinfo, COL_INFO)) {
364                 col_set_str(pinfo->cinfo, COL_INFO, "WTLS" );
365         };
366
367         /* In the interest of speed, if "tree" is NULL, don't do any work not
368         necessary to generate protocol tree items. */
369
370         if (tree) {
371                 ti = proto_tree_add_item(tree, proto_wtls, tvb, offset_wtls,
372                                  -1, bo_little_endian);
373                 wtls_tree = proto_item_add_subtree(ti, ett_wtls);
374
375                 for (offset_wtls=0; offset_wtls < (tvb_reported_length(tvb)-1);) {
376                         pdut = tvb_get_guint8 (tvb, offset_wtls);
377
378                         offset = offset_wtls+1;
379
380                         if (pdut & WTLS_RECORD_TYPE_SEQUENCE) {
381                                 offset+=2;
382                         }
383                         if (pdut & WTLS_RECORD_TYPE_LENGTH) {
384                                 count = tvb_get_ntohs(tvb, offset);
385                                 offset+=2;
386                                 count += offset-offset_wtls;
387                         }
388                         else {
389                                 count = tvb_length_remaining (tvb, offset_wtls);
390                         }
391                         ti = proto_tree_add_uint(wtls_tree, hf_wtls_record, tvb, offset_wtls,
392                                  count, pdut);
393                         wtls_rec_tree = proto_item_add_subtree(ti, ett_wtls_rec);
394
395                         offset = offset_wtls;
396
397                         ti = proto_tree_add_item (wtls_rec_tree, hf_wtls_record_type,
398                                         tvb,offset,1,bo_big_endian);
399
400                         offset++;
401
402                         offset_wtls += count;
403
404                         if (pdut & WTLS_RECORD_TYPE_SEQUENCE) {
405                                 ti = proto_tree_add_item (wtls_rec_tree, hf_wtls_record_sequence,
406                                                 tvb,offset,2,bo_big_endian);
407                                 offset+=2;
408                         }
409                         if (pdut & WTLS_RECORD_TYPE_LENGTH) {
410                                 count = tvb_get_ntohs(tvb, offset);
411                                 ti = proto_tree_add_item (wtls_rec_tree, hf_wtls_record_length,
412                                                 tvb,offset,2,bo_big_endian);
413                                 offset+=2;
414                         }
415                         else {
416                                 count = tvb_length_remaining (tvb, offset);
417                         }
418
419                         if (pdut & WTLS_RECORD_TYPE_CIPHER_CUR) {
420                                 ti = proto_tree_add_item (wtls_rec_tree, hf_wtls_record_ciphered,
421                                                 tvb,offset,count,bo_big_endian);
422                                 continue;
423                         }
424
425                         switch (pdut & WTLS_RECORD_CONTENT_TYPE) {
426                                 case WTLS_PLAIN_HANDSHAKE :
427                                         dissect_wtls_handshake(wtls_rec_tree,tvb,offset,count);
428                                         break;
429                                 case WTLS_ALERT :
430                                         ti = proto_tree_add_item(wtls_rec_tree, hf_wtls_alert, tvb, offset,
431                                                          count, bo_little_endian);
432                                         wtls_msg_type_tree = proto_item_add_subtree(ti, ett_wtls_msg_type);
433                                         pdu_msg_type = tvb_get_guint8 (tvb, offset);
434                                         ti = proto_tree_add_item (wtls_msg_type_tree, hf_wtls_alert_level,
435                                                         tvb,offset,1,bo_big_endian);
436                                         offset+=1;
437                                         count = tvb_get_ntohs (tvb, offset);
438                                         ti = proto_tree_add_item (wtls_msg_type_tree, hf_wtls_alert_description,
439                                                         tvb,offset,1,bo_big_endian);
440                                         offset+=1;
441                                 default:
442                                         offset+=count;
443                                         break;
444                         }
445                 }
446         }
447 }
448
449 static int
450 add_text_identifier(tvbuff_t *tvb, int offset, int hf_charset,
451     int hf_size, int hf_str, proto_tree *tree)
452 {
453         guint8 size;
454         int client_size = 0;
455
456         proto_tree_add_item(tree, hf_charset, tvb, offset, 2, bo_big_endian);
457         offset+=2;
458         size = tvb_get_guint8 (tvb, offset);
459         proto_tree_add_item(tree, hf_size, tvb, offset, 1, bo_big_endian);
460         offset++;
461         proto_tree_add_item(tree, hf_str, tvb, offset, size, bo_big_endian);
462         offset+=size;
463         client_size+=size+3;
464 #ifdef DEBUG
465         fprintf(stderr, "text id size = %d, client_size = %d\n",
466                 size, client_size);
467 #endif /* DEBUG */
468         return client_size;
469 }
470
471 static void
472 dissect_wtls_handshake(proto_tree *tree, tvbuff_t *tvb, guint offset, guint count)
473 {
474         char pdu_msg_type;
475         nstime_t timeValue;
476         int client_size = 0;
477         guint value = 0;
478         int size = 0;
479         guint public_key = 0;
480         guint signature = 0;
481         char valStr[1024];
482         char *valBulk = NULL;
483         char *valMac = NULL;
484
485         proto_item *ti;
486         proto_item *cli_key_item;
487         proto_tree *wtls_msg_type_tree;
488         proto_tree *wtls_msg_type_item_tree;
489         proto_tree *wtls_msg_type_item_sub_tree;
490         proto_tree *wtls_msg_type_item_sub_sub_tree;
491
492         pdu_msg_type = tvb_get_guint8 (tvb, offset);
493         ti = proto_tree_add_uint(tree, hf_wtls_hands, tvb, offset,count, pdu_msg_type);
494         wtls_msg_type_tree = proto_item_add_subtree(ti, ett_wtls_msg_type);
495         
496         ti = proto_tree_add_item (wtls_msg_type_tree, hf_wtls_hands_type,
497                         tvb,offset,1,bo_big_endian);
498         offset+=1;
499         count = tvb_get_ntohs (tvb, offset);
500         ti = proto_tree_add_item (wtls_msg_type_tree, hf_wtls_hands_length,
501                         tvb,offset,2,bo_big_endian);
502         offset+=2;
503         switch(pdu_msg_type) {
504                 case WTLS_HANDSHAKE_CLIENT_HELLO :
505                         ti = proto_tree_add_item(wtls_msg_type_tree, hf_wtls_hands_cli_hello, tvb, offset,
506                                          count, bo_little_endian);
507                         wtls_msg_type_item_tree = proto_item_add_subtree(ti, ett_wtls_msg_type_item);
508                         ti = proto_tree_add_item (wtls_msg_type_item_tree, hf_wtls_hands_cli_hello_version,
509                                         tvb,offset,1,bo_big_endian);
510                         offset++;
511                         timeValue.secs = tvb_get_ntohl (tvb, offset);
512                         timeValue.nsecs = 0;
513                         ti = proto_tree_add_time (wtls_msg_type_item_tree, hf_wtls_hands_cli_hello_gmt, tvb,
514                                         offset, 4, &timeValue);
515                         offset+=4;
516                         ti = proto_tree_add_item (wtls_msg_type_item_tree, hf_wtls_hands_cli_hello_random,
517                                         tvb,offset,12,bo_big_endian);
518                         offset+=12;
519                         count = tvb_get_guint8(tvb, offset);
520                         switch(count) {
521                                 case 0:
522                                         ti = proto_tree_add_string (wtls_msg_type_item_tree, hf_wtls_hands_cli_hello_session_str,
523                                                                         tvb,offset,count+1,"NULL");
524                                         break;
525                                 case 1 :
526                                         ti = proto_tree_add_uint (wtls_msg_type_item_tree, hf_wtls_hands_cli_hello_session,
527                                                                         tvb,offset,count+1,tvb_get_guint8(tvb,offset+1));
528                                         break;
529                                 case 2 :
530                                         ti = proto_tree_add_uint (wtls_msg_type_item_tree, hf_wtls_hands_cli_hello_session,
531                                                                         tvb,offset,count+1,tvb_get_ntohs(tvb,offset+1));
532                                         break;
533                                 case 3 :
534                                         ti = proto_tree_add_uint (wtls_msg_type_item_tree, hf_wtls_hands_cli_hello_session,
535                                                                         tvb,offset,count+1,tvb_get_ntoh24(tvb,offset+1));
536                                         break;
537                                 case 4 :
538                                         ti = proto_tree_add_uint (wtls_msg_type_item_tree, hf_wtls_hands_cli_hello_session,
539                                                                         tvb,offset,count+1,tvb_get_ntohl(tvb,offset+1));
540                                         break;
541                                 default:
542                                         ti = proto_tree_add_string (wtls_msg_type_item_tree, hf_wtls_hands_cli_hello_session_str,
543                                                                         tvb,offset,count+1,"Too big");
544                                         break;
545                         }
546                         offset+=1+count;
547
548                         /* process client_key_ids structure */
549                         count = tvb_get_ntohs (tvb, offset);
550                         ti = proto_tree_add_item(wtls_msg_type_item_tree, 
551                                         hf_wtls_hands_cli_hello_cli_key_id, tvb, offset,
552                                          count+2, bo_little_endian);
553                         wtls_msg_type_item_sub_tree = proto_item_add_subtree(ti, ett_wtls_msg_type_item_sub);
554
555                         /* display length of client_key_ids structure */
556                         ti = proto_tree_add_item(wtls_msg_type_item_sub_tree,
557                                         hf_wtls_hands_cli_hello_cli_key_len,
558                                         tvb,offset,2,bo_big_endian);
559                         offset+=2;
560
561                         /* cycle through client_key_ids entries */
562                         for (;count > 0;count-=client_size) {
563                                 /* get encryption suite id (one byte) */
564                                 value = tvb_get_guint8 (tvb, offset);
565                                 cli_key_item = proto_tree_add_uint(wtls_msg_type_item_sub_tree, 
566                                                 hf_wtls_hands_cli_hello_key_exchange, tvb, offset,1,
567                                                 value);
568                                 client_size=1;
569                                 wtls_msg_type_item_sub_sub_tree = proto_item_add_subtree(cli_key_item, 
570                                                                   ett_wtls_msg_type_item_sub_sub);
571                                 ti = proto_tree_add_uint(wtls_msg_type_item_sub_sub_tree,
572                                                 hf_wtls_hands_cli_hello_key_exchange_suite,
573                                                 tvb,offset,1,value);
574                                 offset++;
575 #ifdef DEBUG
576                                 fprintf(stderr, "encryption suite = %d, client_size = %d\n", value, client_size);
577 #endif /* DEBUG */
578
579                                 /* get parameter index (one byte) */
580                                 value = tvb_get_guint8 (tvb, offset);
581                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
582                                         hf_wtls_hands_cli_hello_key_parameter_index,
583                                         tvb,offset,1,bo_big_endian);
584                                 offset++;
585                                 client_size++;
586 #ifdef DEBUG
587                                 fprintf(stderr, "parameter index = %d, client_size = %d\n", value, client_size);
588 #endif /* DEBUG */
589
590                                 /* explicit parameters present in next field */
591                                 if (value == 0xff) {
592                                         size = tvb_get_ntohs (tvb, offset);
593                                         ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
594                                                 hf_wtls_hands_cli_hello_key_parameter_set,
595                                                 tvb,offset,size+2,bo_big_endian);
596                                         offset+=size+2;
597                                         client_size+=size+2;
598                                 }
599
600                                 /* get identifier type */
601                                 value = tvb_get_guint8 (tvb, offset);
602                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
603                                                 hf_wtls_hands_cli_hello_key_identifier_type,
604                                                 tvb,offset,1,bo_big_endian);
605                                 offset++;
606                                 client_size++;
607 #ifdef DEBUG
608                                 fprintf(stderr, "identifier type = %d, client_size = %d\n", value, client_size);
609 #endif /* DEBUG */
610
611                                 /* identifier present in next field */
612                                 /* note: value 0x0 means no identifier */
613                                 switch(value) {
614                                         case IDENTIFIER_TEXT :
615                                                 /* text identifier */
616                                                 /* not tested */
617                                                 size = add_text_identifier(
618                                                         tvb, offset,
619                                                         hf_wtls_hands_cli_hello_key_identifier_charset,
620                                                         hf_wtls_hands_cli_hello_key_identifier_size,
621                                                         hf_wtls_hands_cli_hello_key_identifier_str,
622                                                         wtls_msg_type_item_sub_sub_tree);
623                                                 offset += size;
624                                                 client_size += size;
625                                                 break;
626                                         case IDENTIFIER_BIN :
627                                                 /* binary identifier */
628                                                 size = tvb_get_guint8 (tvb, offset);
629                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
630                                                                 hf_wtls_hands_cli_hello_key_identifier_size,
631                                                                 tvb,offset,1,bo_big_endian);
632                                                 offset++;
633                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
634                                                                 hf_wtls_hands_cli_hello_key_identifier,
635                                                                 tvb,offset,size,bo_big_endian);
636                                                 offset+=size;
637                                                 client_size+=size+1;
638 #ifdef DEBUG
639                                                 fprintf(stderr, "binary id size = %d, client_size = %d\n",
640                                                         size, client_size);
641 #endif /* DEBUG */
642                                                 break;
643                                         case IDENTIFIER_SHA_1 :
644                                                 /* SHA-1 hash of the public key */
645                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
646                                                                 hf_wtls_hands_cli_hello_key_identifier,
647                                                                 tvb,offset,20,bo_big_endian);
648                                                 offset+=20;
649                                                 client_size+=20;
650 #ifdef DEBUG
651                                                 fprintf(stderr, "SHA-1 hash size = 20, client_size = %d\n",
652                                                         client_size);
653 #endif /* DEBUG */
654                                                 break;
655                                         case IDENTIFIER_X509 :
656                                                 /* X.509 distinguished name */
657                                                 /* not tested */
658                                                 size = tvb_get_guint8 (tvb, offset);
659                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
660                                                                 hf_wtls_hands_cli_hello_key_identifier_size,
661                                                                 tvb,offset,1,bo_big_endian);
662                                                 offset++;
663                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
664                                                                 hf_wtls_hands_cli_hello_key_identifier,
665                                                                 tvb,offset,size,bo_big_endian);
666                                                 offset+=size;
667                                                 client_size+=size+1;
668 #ifdef DEBUG
669                                                 fprintf(stderr, "X.509 name size = %d, client_size = %d\n",
670                                                         size, client_size);
671 #endif /* DEBUG */
672                                                 break;
673                                 }
674
675                                 proto_item_set_len(cli_key_item, client_size);
676                         }
677
678                         /* process trusted_keys structure */
679                         count = tvb_get_ntohs (tvb, offset);
680                         ti = proto_tree_add_item(wtls_msg_type_item_tree, 
681                                         hf_wtls_hands_cli_hello_trust_key_id, tvb, offset,
682                                          count+2, bo_little_endian);
683                         wtls_msg_type_item_sub_tree = proto_item_add_subtree(ti, ett_wtls_msg_type_item_sub);
684
685                         /* display length of trusted_keys structure */
686                         ti = proto_tree_add_item(wtls_msg_type_item_sub_tree,
687                                         hf_wtls_hands_cli_hello_cli_key_len,
688                                         tvb,offset,2,bo_big_endian);
689
690                         offset+=2;
691                         for (;count > 0;count-=client_size) {
692                                 /* get encryption suite id (one byte) */
693                                 value = tvb_get_guint8 (tvb, offset);
694                                 cli_key_item = proto_tree_add_uint(wtls_msg_type_item_sub_tree, 
695                                                 hf_wtls_hands_cli_hello_key_exchange, tvb, offset,1,
696                                                 value);
697                                 client_size=1;
698                                 wtls_msg_type_item_sub_sub_tree = proto_item_add_subtree(cli_key_item, 
699                                                                   ett_wtls_msg_type_item_sub_sub);
700                                 ti = proto_tree_add_uint(wtls_msg_type_item_sub_sub_tree,
701                                                 hf_wtls_hands_cli_hello_key_exchange_suite,
702                                                 tvb,offset,1,value);
703                                 offset++;
704 #ifdef DEBUG
705                                 fprintf(stderr, "encryption suite = %d, client_size = %d\n", value, client_size);
706 #endif /* DEBUG */
707
708                                 /* get parameter index (one byte) */
709                                 value = tvb_get_guint8 (tvb, offset);
710                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
711                                         hf_wtls_hands_cli_hello_key_parameter_index,
712                                         tvb,offset,1,bo_big_endian);
713                                 offset++;
714                                 client_size++;
715 #ifdef DEBUG
716                                 fprintf(stderr, "parameter index = %d, client_size = %d\n", value, client_size);
717 #endif /* DEBUG */
718
719                                 /* explicit parameters present in next field */
720                                 if (value == 0xff) {
721                                         size = tvb_get_ntohs (tvb, offset);
722                                         ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
723                                                 hf_wtls_hands_cli_hello_key_parameter_set,
724                                                 tvb,offset,size+2,bo_big_endian);
725                                         offset+=size+2;
726                                         client_size+=size+2;
727                                 }
728
729                                 /* get identifier type */
730                                 value = tvb_get_guint8 (tvb, offset);
731                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
732                                                 hf_wtls_hands_cli_hello_key_identifier_type,
733                                                 tvb,offset,1,bo_big_endian);
734                                 offset++;
735                                 client_size++;
736 #ifdef DEBUG
737                                 fprintf(stderr, "identifier type = %d, client_size = %d\n", value, client_size);
738 #endif /* DEBUG */
739
740                                 /* identifier present in next field */
741                                 /* note: value 0x0 means no identifier */
742                                 switch (value) {
743                                         case IDENTIFIER_TEXT :
744                                                 /* text identifier */
745                                                 /* not tested */
746                                                 size = add_text_identifier(
747                                                         tvb, offset,
748                                                         hf_wtls_hands_cli_hello_key_identifier_charset,
749                                                         hf_wtls_hands_cli_hello_key_identifier_size,
750                                                         hf_wtls_hands_cli_hello_key_identifier_str,
751                                                         wtls_msg_type_item_sub_sub_tree);
752                                                 offset += size;
753                                                 client_size += size;
754                                                 break;
755                                         case IDENTIFIER_BIN :
756                                                 /* binary identifier */
757                                                 size = tvb_get_guint8 (tvb, offset);
758                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
759                                                                 hf_wtls_hands_cli_hello_key_identifier_size,
760                                                                 tvb,offset,1,bo_big_endian);
761                                                 offset++;
762                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
763                                                                 hf_wtls_hands_cli_hello_key_identifier,
764                                                                 tvb,offset,size,bo_big_endian);
765                                                 offset+=size;
766                                                 client_size+=size+1;
767 #ifdef DEBUG
768                                                 fprintf(stderr, "binary id size = %d, client_size = %d\n",
769                                                         size, client_size);
770 #endif /* DEBUG */
771                                                 break;
772                                         case IDENTIFIER_SHA_1 :
773                                                 /* SHA-1 hash of the public key */
774                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
775                                                                 hf_wtls_hands_cli_hello_key_identifier,
776                                                                 tvb,offset,20,bo_big_endian);
777                                                 offset+=20;
778                                                 client_size+=20;
779 #ifdef DEBUG
780                                                 fprintf(stderr, "SHA-1 hash size = 20, client_size = %d\n",
781                                                         client_size);
782 #endif /* DEBUG */
783                                                 break;
784                                         case IDENTIFIER_X509 :
785                                                 /* X.509 distinguished name */
786                                                 /* not tested */
787                                                 size = tvb_get_guint8 (tvb, offset);
788                                                 /* need to fetch identifier and display it */
789                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
790                                                                 hf_wtls_hands_cli_hello_key_identifier_size,
791                                                                 tvb,offset,1,bo_big_endian);
792                                                 offset++;
793                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_sub_tree,
794                                                                 hf_wtls_hands_cli_hello_key_identifier,
795                                                                 tvb,offset,size,bo_big_endian);
796                                                 offset+=size;
797                                                 client_size+=size+1;
798 #ifdef DEBUG
799                                                 fprintf(stderr, "X.509 name size = %d, client_size = %d\n",
800                                                         size, client_size);
801 #endif /* DEBUG */
802                                                 break;
803                                 }
804                                 proto_item_set_len(cli_key_item, client_size);
805                         }
806
807                         /* process cipher_suites structure */
808                         count = tvb_get_guint8 (tvb, offset);
809                         ti = proto_tree_add_item(wtls_msg_type_item_tree, 
810                                         hf_wtls_hands_cli_hello_cipher_suite, tvb, offset,
811                                          count+1, bo_little_endian);
812                         wtls_msg_type_item_sub_tree = proto_item_add_subtree(ti, ett_wtls_msg_type_item_sub);
813                         offset+=1;
814                         for (;count > 0;count-=client_size) {
815                                value = tvb_get_guint8 (tvb, offset);
816                                valBulk = match_strval(value, wtls_vals_cipher_bulk);
817                                offset++;
818                                client_size=1;
819                                valMac = match_strval(tvb_get_guint8 (tvb, offset), wtls_vals_cipher_mac);
820                                if (valBulk != NULL)
821                                {
822                                        if (valMac != NULL)
823                                        {
824                                                snprintf(valStr,1024,"%s, %s",valBulk,valMac);
825                                        }
826                                        else
827                                        {
828                                                snprintf(valStr,1024,"%s, Unknown MAC (0x%02x)",valBulk,tvb_get_guint8 (tvb, offset));
829                                        }
830                                }
831                                else
832                                {
833                                        if (valMac != NULL)
834                                        {
835                                                snprintf(valStr,1024,"Unknown Bulk (0x%02x), %s",value,valMac);
836                                        }
837                                        else
838                                        {
839                                                snprintf(valStr,1024,"Unknown Bulk (0x%02x), Unknown MAC (0x%02x)",value,
840                                                                tvb_get_guint8 (tvb, offset));
841                                        }
842                                 }
843                                 offset++;
844                                 client_size++;
845                                 cli_key_item = proto_tree_add_string(wtls_msg_type_item_sub_tree,
846                                                hf_wtls_hands_cli_hello_cipher_suite_item, tvb, offset-2,2,
847                                                valStr); 
848                         }
849                         count = tvb_get_guint8 (tvb, offset);
850                         ti = proto_tree_add_item(wtls_msg_type_item_tree, 
851                                         hf_wtls_hands_cli_hello_compression_methods, tvb, offset,
852                                          count+1, bo_little_endian);
853                         wtls_msg_type_item_sub_tree = proto_item_add_subtree(ti, ett_wtls_msg_type_item_sub);
854                         offset+=1;
855                         for (;count > 0;count-=client_size) {
856                                 client_size=0;
857                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_tree, 
858                                                 hf_wtls_hands_cli_hello_compression, tvb, offset,1,
859                                                 bo_little_endian);
860                                 offset++;
861                                 client_size++;
862                         }
863                         ti = proto_tree_add_item(wtls_msg_type_item_tree, 
864                                         hf_wtls_hands_cli_hello_sequence_mode, tvb, offset,
865                                          1, bo_little_endian);
866                         offset++;
867                         ti = proto_tree_add_item(wtls_msg_type_item_tree, 
868                                         hf_wtls_hands_cli_hello_key_refresh, tvb, offset,
869                                          1, bo_little_endian);
870                         break;
871                 case WTLS_HANDSHAKE_SERVER_HELLO :
872                         ti = proto_tree_add_item(wtls_msg_type_tree, hf_wtls_hands_serv_hello, tvb, offset,
873                                          count, bo_little_endian);
874                         wtls_msg_type_item_tree = proto_item_add_subtree(ti, ett_wtls_msg_type_item);
875                         ti = proto_tree_add_item (wtls_msg_type_item_tree, hf_wtls_hands_serv_hello_version,
876                                         tvb,offset,1,bo_big_endian);
877                         offset++;
878                         timeValue.secs = tvb_get_ntohl (tvb, offset);
879                         timeValue.nsecs = 0;
880                         ti = proto_tree_add_time (wtls_msg_type_item_tree, hf_wtls_hands_serv_hello_gmt, tvb,
881                                         offset, 4, &timeValue);
882                         offset+=4;
883                         ti = proto_tree_add_item (wtls_msg_type_item_tree, hf_wtls_hands_serv_hello_random,
884                                         tvb,offset,12,bo_big_endian);
885                         offset+=12;
886                         count = tvb_get_guint8(tvb, offset);
887                         switch(count) {
888                                 case 0:
889                                         ti = proto_tree_add_string (wtls_msg_type_item_tree, hf_wtls_hands_serv_hello_session_str,
890                                                                         tvb,offset,count+1,"NULL");
891                                         break;
892                                 case 1 :
893                                         ti = proto_tree_add_uint (wtls_msg_type_item_tree, hf_wtls_hands_serv_hello_session,
894                                                                         tvb,offset,count+1,tvb_get_guint8(tvb,offset+1));
895                                         break;
896                                 case 2 :
897                                         ti = proto_tree_add_uint (wtls_msg_type_item_tree, hf_wtls_hands_serv_hello_session,
898                                                                         tvb,offset,count+1,tvb_get_ntohs(tvb,offset+1));
899                                         break;
900                                 case 3 :
901                                         ti = proto_tree_add_uint (wtls_msg_type_item_tree, hf_wtls_hands_serv_hello_session,
902                                                                         tvb,offset,count+1,tvb_get_ntoh24(tvb,offset+1));
903                                         break;
904                                 case 4 :
905                                         ti = proto_tree_add_uint (wtls_msg_type_item_tree, hf_wtls_hands_serv_hello_session,
906                                                                         tvb,offset,count+1,tvb_get_ntohl(tvb,offset+1));
907                                         break;
908                                 default:
909                                         ti = proto_tree_add_string (wtls_msg_type_item_tree, hf_wtls_hands_serv_hello_session_str,
910                                                                         tvb,offset,count+1,"Too big");
911                                         break;
912                         }
913                         offset+=1+count;
914                         ti = proto_tree_add_item(wtls_msg_type_item_tree,
915                                         hf_wtls_hands_serv_hello_cli_key_id,
916                                         tvb,offset,1,bo_big_endian);
917                         offset++;
918                         cli_key_item = proto_tree_add_item(wtls_msg_type_item_tree, 
919                                         hf_wtls_hands_serv_hello_cipher_suite_item, tvb, offset,2,
920                                         bo_little_endian);
921                         wtls_msg_type_item_sub_tree = proto_item_add_subtree(cli_key_item, 
922                                                           ett_wtls_msg_type_item_sub);
923                         ti = proto_tree_add_item(wtls_msg_type_item_sub_tree,
924                                         hf_wtls_hands_serv_hello_cipher_bulk,
925                                         tvb,offset,1,bo_big_endian);
926                         offset++;
927                         value = tvb_get_guint8 (tvb, offset);
928                         ti = proto_tree_add_item(wtls_msg_type_item_sub_tree,
929                                 hf_wtls_hands_serv_hello_cipher_mac,
930                                 tvb,offset,1,bo_big_endian);
931                         offset++;
932                         ti = proto_tree_add_item(wtls_msg_type_item_tree, 
933                                         hf_wtls_hands_serv_hello_compression, tvb, offset,1,
934                                         bo_little_endian);
935                         offset++;
936                         ti = proto_tree_add_item(wtls_msg_type_item_tree, 
937                                         hf_wtls_hands_serv_hello_sequence_mode, tvb, offset,
938                                          1, bo_little_endian);
939                         offset++;
940                         ti = proto_tree_add_item(wtls_msg_type_item_tree, 
941                                         hf_wtls_hands_serv_hello_key_refresh, tvb, offset,
942                                          1, bo_little_endian);
943                         offset++;
944                         break;
945                 case WTLS_HANDSHAKE_CERTIFICATE :
946                         ti = proto_tree_add_item(wtls_msg_type_tree, hf_wtls_hands_certificates,
947                                         tvb, offset,count, bo_little_endian);
948                         wtls_msg_type_item_tree = proto_item_add_subtree(ti, ett_wtls_msg_type_item);
949                         count = tvb_get_ntohs (tvb, offset);
950                         offset+=2;
951                         for (;count > 0;count-=client_size) {
952                                 cli_key_item = proto_tree_add_item(wtls_msg_type_item_tree, 
953                                                 hf_wtls_hands_certificate, tvb, offset,1,
954                                                 bo_little_endian);
955                                 client_size=0;
956                                 wtls_msg_type_item_sub_tree = proto_item_add_subtree(cli_key_item, 
957                                                                   ett_wtls_msg_type_item_sub);
958                                 proto_item_set_len(cli_key_item, client_size);
959                                 value =  tvb_get_guint8 (tvb, offset);
960                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_tree, 
961                                                 hf_wtls_hands_certificate_type, tvb, offset,1,
962                                                 bo_little_endian);
963                                 offset++;
964                                 client_size++;
965                                 switch(value) {
966                                         case CERTIFICATE_WTLS:
967                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_tree, 
968                                                         hf_wtls_hands_certificate_wtls_version,
969                                                         tvb, offset,1,
970                                                         bo_little_endian);
971                                                 offset++;
972                                                 client_size++;
973                                                 signature =  tvb_get_guint8 (tvb, offset);
974                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_tree, 
975                                                         hf_wtls_hands_certificate_wtls_signature_type,
976                                                         tvb, offset,1,
977                                                         bo_little_endian);
978                                                 offset++;
979                                                 client_size++;
980                                                 value =  tvb_get_guint8 (tvb, offset);
981                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_tree, 
982                                                         hf_wtls_hands_certificate_wtls_issuer_type,
983                                                         tvb, offset,1,
984                                                         bo_little_endian);
985                                                 offset++;
986                                                 client_size++;
987                                                 switch (value) {
988                                                         case IDENTIFIER_NULL :
989                                                                 break;
990                                                         case IDENTIFIER_TEXT :
991                                                                 value = add_text_identifier(tvb, offset,
992                                                                         hf_wtls_hands_certificate_wtls_issuer_charset,
993                                                                         hf_wtls_hands_certificate_wtls_issuer_size,
994                                                                         hf_wtls_hands_certificate_wtls_issuer_name,
995                                                                         wtls_msg_type_item_sub_tree);
996                                                                 offset += value;
997                                                                 client_size += value;
998                                                                 break;
999                                                         case IDENTIFIER_BIN :
1000                                                                 break;
1001                                                         case IDENTIFIER_SHA_1 :
1002                                                                 break;
1003                                                         case IDENTIFIER_X509 :
1004                                                                 break;
1005                                                 }
1006                                                 timeValue.secs = tvb_get_ntohl (tvb, offset);
1007                                                 timeValue.nsecs = 0;
1008                                                 ti = proto_tree_add_time (wtls_msg_type_item_sub_tree, 
1009                                                                 hf_wtls_hands_certificate_wtls_valid_not_before,
1010                                                                 tvb, offset, 4, &timeValue);
1011                                                 offset+=4;
1012                                                 client_size+=4;
1013                                                 timeValue.secs = tvb_get_ntohl (tvb, offset);
1014                                                 timeValue.nsecs = 0;
1015                                                 ti = proto_tree_add_time (wtls_msg_type_item_sub_tree, 
1016                                                                 hf_wtls_hands_certificate_wtls_valid_not_after,
1017                                                                 tvb, offset, 4, &timeValue);
1018                                                 offset+=4;
1019                                                 client_size+=4;
1020                                                 value =  tvb_get_guint8 (tvb, offset);
1021                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_tree, 
1022                                                         hf_wtls_hands_certificate_wtls_subject_type,
1023                                                         tvb, offset,1,
1024                                                         bo_little_endian);
1025                                                 offset++;
1026                                                 client_size++;
1027                                                 switch (value) {
1028                                                         case IDENTIFIER_NULL :
1029                                                                 break;
1030                                                         case IDENTIFIER_TEXT :
1031                                                                 value = add_text_identifier(tvb, offset, 
1032                                                                         hf_wtls_hands_certificate_wtls_subject_charset,
1033                                                                         hf_wtls_hands_certificate_wtls_subject_size,
1034                                                                         hf_wtls_hands_certificate_wtls_subject_name,
1035                                                                         wtls_msg_type_item_sub_tree);
1036                                                                 offset += value;
1037                                                                 client_size += value;
1038                                                                 break;
1039                                                         case IDENTIFIER_BIN :
1040                                                                 break;
1041                                                         case IDENTIFIER_SHA_1 :
1042                                                                 break;
1043                                                         case IDENTIFIER_X509 :
1044                                                                 break;
1045                                                 }
1046                                                 public_key =  tvb_get_guint8 (tvb, offset);
1047                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_tree, 
1048                                                         hf_wtls_hands_certificate_wtls_public_key_type,
1049                                                         tvb, offset,1,
1050                                                         bo_little_endian);
1051                                                 offset++;
1052                                                 client_size++;
1053                                                 value = tvb_get_guint8 (tvb, offset);
1054                                                 ti = proto_tree_add_item(wtls_msg_type_item_sub_tree,
1055                                                         hf_wtls_hands_certificate_wtls_key_parameter_index,
1056                                                         tvb,offset,1,bo_big_endian);
1057                                                 offset++;
1058                                                 client_size++;
1059                                                 if (value == 0xff) {
1060                                                         size = tvb_get_ntohs (tvb, offset);
1061                                                         ti = proto_tree_add_item(wtls_msg_type_item_sub_tree,
1062                                                                 hf_wtls_hands_certificate_wtls_key_parameter_set,
1063                                                                 tvb,offset,size+2,bo_big_endian);
1064                                                         offset+=size+2;
1065                                                         client_size+=size+2;
1066                                                 }
1067                                                 switch (public_key) {
1068                                                         case PUBLIC_KEY_RSA :
1069                                                                 value = tvb_get_ntohs (tvb, offset);
1070                                                                 ti = proto_tree_add_uint(wtls_msg_type_item_sub_tree,
1071                                                                         hf_wtls_hands_certificate_wtls_rsa_exponent,
1072                                                                         tvb,offset,value+2,value*8);
1073                                                                 offset+=2+value;
1074                                                                 client_size+=2+value;
1075                                                                 value = tvb_get_ntohs (tvb, offset);
1076                                                                 ti = proto_tree_add_uint(wtls_msg_type_item_sub_tree,
1077                                                                         hf_wtls_hands_certificate_wtls_rsa_modules,
1078                                                                         tvb,offset,value+2,value*8);
1079                                                                 offset+=2+value;
1080                                                                 client_size+=2+value;
1081                                                                 break;
1082                                                         case PUBLIC_KEY_ECDH :
1083                                                                 break;
1084                                                         case PUBLIC_KEY_ECDSA :
1085                                                                 break;
1086                                                 }
1087                                                 value = tvb_get_ntohs (tvb, offset);
1088                                                 ti = proto_tree_add_uint(wtls_msg_type_item_sub_tree,
1089                                                         hf_wtls_hands_certificate_wtls_signature,
1090                                                         tvb,offset,2+value,value*8);
1091                                                 offset+=2+value;
1092                                                 client_size+=2+value;
1093                                                 break;
1094                                         case CERTIFICATE_X509:
1095                                         case CERTIFICATE_X968:
1096                                                 value =  tvb_get_ntohs (tvb, offset);
1097                                                 offset+=2;
1098                                                 client_size+=2;
1099                                                 client_size += value;
1100                                                 offset += value;
1101                                                 break;
1102                                         case CERTIFICATE_URL:
1103                                                 value =  tvb_get_guint8 (tvb, offset);
1104                                                 offset++;
1105                                                 client_size++;
1106                                                 client_size += value;
1107                                                 offset += value;
1108                                                 break;
1109                                 }
1110                                 proto_item_set_len(cli_key_item, client_size);
1111                         }
1112                         break;
1113                 default: 
1114                         offset+=count;
1115                         break;
1116         }
1117 }
1118
1119 /* Register the protocol with Ethereal */
1120 void
1121 proto_register_wtls(void)
1122 {                 
1123
1124 /* Setup list of header fields */
1125         static hf_register_info hf[] = {
1126                 { &hf_wtls_record,
1127                         {       "Record",           
1128                                 "wsp.wtls.record",
1129                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_record_type ), 0x0f,
1130                                 "Record", HFILL
1131                         }
1132                 },
1133                 { &hf_wtls_record_type,
1134                         {       "Record Type",           
1135                                 "wsp.wtls.rec_type",
1136                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_record_type ), 0x0f,
1137                                 "Record Type", HFILL
1138                         }
1139                 },
1140                 { &hf_wtls_record_length,
1141                         {       "Record Length",           
1142                                 "wsp.wtls.rec_length",
1143                                  FT_UINT16, BASE_DEC, NULL, 0x00,
1144                                 "Record Length", HFILL
1145                         }
1146                 },
1147                 { &hf_wtls_record_sequence,
1148                         {       "Record Sequence",           
1149                                 "wsp.wtls.rec_seq",
1150                                  FT_UINT16, BASE_DEC, NULL, 0x00,
1151                                 "Record Sequence", HFILL
1152                         }
1153                 },
1154                 { &hf_wtls_record_ciphered,
1155                         {       "Record Ciphered",           
1156                                 "wsp.wtls.rec_cipher",
1157                                  FT_NONE, BASE_NONE, NULL, 0x00,
1158                                 "Record Ciphered", HFILL
1159                         }
1160                 },
1161                 { &hf_wtls_hands,
1162                         {       "Handshake",           
1163                                 "wsp.wtls.handshake",
1164                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_handshake_type ), 0x00,
1165                                 "Handshake", HFILL
1166                         }
1167                 },
1168                 { &hf_wtls_hands_type,
1169                         {       "Type",           
1170                                 "wsp.wtls.handshake.type",
1171                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_handshake_type ), 0x00,
1172                                 "Type", HFILL
1173                         }
1174                 },
1175                 { &hf_wtls_hands_length,
1176                         {       "Length",           
1177                                 "wsp.wtls.handshake.length",
1178                                  FT_UINT16, BASE_DEC, NULL, 0x00,
1179                                 "Length", HFILL
1180                         }
1181                 },
1182                 { &hf_wtls_hands_cli_hello,
1183                         {       "Client Hello",           
1184                                 "wsp.wtls.handshake.client_hello",
1185                                  FT_NONE, BASE_NONE, NULL, 0x00,
1186                                 "Client Hello", HFILL
1187                         }
1188                 },
1189                 { &hf_wtls_hands_cli_hello_version,
1190                         {       "Version",           
1191                                 "wsp.wtls.handshake.client_hello.version",
1192                                  FT_UINT8, BASE_DEC, NULL, 0x00,
1193                                 "Version", HFILL
1194                         }
1195                 },
1196                 { &hf_wtls_hands_cli_hello_gmt,
1197                         {       "Time GMT",           
1198                                 "wsp.wtls.handshake.client_hello.gmt",
1199                                  FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
1200                                 "Time GMT", HFILL
1201                         }
1202                 },
1203                 { &hf_wtls_hands_cli_hello_random,
1204                         {       "Random",           
1205                                 "wsp.wtls.handshake.client_hello.random",
1206                                  FT_NONE, BASE_NONE, NULL, 0x00,
1207                                 "Random", HFILL
1208                         }
1209                 },
1210                 { &hf_wtls_hands_cli_hello_session,
1211                         {       "Session ID",           
1212                                 "wsp.wtls.handshake.client_hello.sessionid",
1213                                  FT_UINT32, BASE_DEC, NULL, 0x00,
1214                                 "Session ID", HFILL
1215                         }
1216                 },
1217                 { &hf_wtls_hands_cli_hello_session_str,
1218                         {       "Session ID",           
1219                                 "wsp.wtls.handshake.client_hello.session.str",
1220                                  FT_STRING, BASE_NONE, NULL, 0x00,
1221                                 "Session ID", HFILL
1222                         }
1223                 },
1224                 { &hf_wtls_hands_cli_hello_cli_key_id,
1225                         {       "Client Keys",           
1226                                 "wsp.wtls.handshake.client_hello.client_keys_id",
1227                                  FT_NONE, BASE_NONE, NULL, 0x00,
1228                                 "Client Keys"     , HFILL     
1229                         }
1230                 },
1231                 { &hf_wtls_hands_cli_hello_cli_key_len,
1232                         {       "Length",           
1233                                 "wsp.wtls.handshake.client_hello.client_keys_len",
1234                                  FT_UINT16, BASE_DEC, NULL, 0x00,
1235                                 "Length"          , HFILL
1236                         }
1237                 },
1238                 { &hf_wtls_hands_cli_hello_trust_key_id,
1239                         {       "Trusted Keys",           
1240                                 "wsp.wtls.handshake.client_hello.trusted_keys_id",
1241                                  FT_NONE, BASE_NONE, NULL, 0x00,
1242                                 "Trusted Keys"          , HFILL
1243                         }
1244                 },
1245                 { &hf_wtls_hands_cli_hello_key_exchange,
1246                         {       "Key Exchange",           
1247                                 "wsp.wtls.handshake.client_hello.key.key_exchange",
1248                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_key_exchange_suite ), 0x00,
1249                                 "Key Exchange", HFILL
1250                         }
1251                 },
1252                 { &hf_wtls_hands_cli_hello_key_exchange_suite,
1253                         {       "Suite",           
1254                                 "wsp.wtls.handshake.client_hello.key.key_exchange.suite",
1255                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_key_exchange_suite ), 0x00,
1256                                 "Suite", HFILL
1257                         }
1258                 },
1259                 { &hf_wtls_hands_cli_hello_key_parameter_index,
1260                         {       "Parameter Index",           
1261                                 "wsp.wtls.handshake.client_hello.parameter_index",
1262                                  FT_UINT8, BASE_DEC, NULL, 0x00,
1263                                 "Parameter Index", HFILL
1264                         }
1265                 },
1266                 { &hf_wtls_hands_cli_hello_key_parameter_set,
1267                         {       "Parameter Set",           
1268                                 "wsp.wtls.handshake.client_hello.parameter",
1269                                  FT_STRING, BASE_NONE, NULL, 0x00,
1270                                 "Parameter Set", HFILL
1271                         }
1272                 },
1273                 { &hf_wtls_hands_cli_hello_key_identifier_type,
1274                         {       "Identifier Type",           
1275                                 "wsp.wtls.handshake.client_hello.ident_type",
1276                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_identifier_type ), 0x00,
1277                                 "Identifier Type", HFILL
1278                         }
1279                 },
1280                 { &hf_wtls_hands_cli_hello_key_identifier_charset,
1281                         {       "Identifier CharSet",           
1282                                 "wsp.wtls.handshake.client_hello.ident_charset",
1283                                  FT_UINT16, BASE_HEX, VALS ( vals_character_sets ), 0x00,
1284                                 "Identifier CharSet", HFILL
1285                         }
1286                 },
1287                 { &hf_wtls_hands_cli_hello_key_identifier_size,
1288                         {       "Identifier Size",           
1289                                 "wsp.wtls.handshake.client_hello.ident_size",
1290                                  FT_UINT8, BASE_DEC, NULL, 0x00,
1291                                 "Identifier Size", HFILL
1292                         }
1293                 },
1294                 { &hf_wtls_hands_cli_hello_key_identifier,
1295                         {       "Identifier",           
1296                                 "wsp.wtls.handshake.client_hello.identifier",
1297                                  FT_NONE, BASE_NONE, NULL, 0x00,
1298                                 "Identifier", HFILL
1299                         }
1300                 },
1301                 { &hf_wtls_hands_cli_hello_key_identifier_str,
1302                         {       "Identifier Name",           
1303                                 "wsp.wtls.handshake.client_hello.ident_name",
1304                                  FT_STRING, BASE_NONE, NULL, 0x00,
1305                                 "Identifier Name", HFILL
1306                         }
1307                 },
1308                 { &hf_wtls_hands_cli_hello_cipher_suite,
1309                         {       "Cipher Suites",           
1310                                 "wsp.wtls.handshake.client_hello.ciphers",
1311                                  FT_NONE, BASE_NONE, NULL, 0x00,
1312                                 "Cipher Suite", HFILL
1313                         }
1314                 },
1315                 { &hf_wtls_hands_cli_hello_cipher_suite_item,
1316                         {       "Cipher",           
1317                                 "wsp.wtls.handshake.client_hello.cipher",
1318                                  FT_STRING, BASE_NONE, NULL, 0x00,
1319                                 "Cipher", HFILL
1320                         }
1321                 },
1322                 { &hf_wtls_hands_cli_hello_compression_methods,
1323                         {       "Compression Methods",           
1324                                 "wsp.wtls.handshake.client_hello.comp_methods",
1325                                  FT_NONE, BASE_NONE, NULL, 0x00,
1326                                 "Compression Methods", HFILL
1327                         }
1328                 },
1329                 { &hf_wtls_hands_cli_hello_compression,
1330                         {       "Compression",           
1331                                 "wsp.wtls.handshake.client_hello.compression",
1332                                  FT_UINT8, BASE_HEX, VALS ( wtls_vals_compression ), 0x00,
1333                                 "Compression", HFILL
1334                         }
1335                 },
1336                 { &hf_wtls_hands_cli_hello_sequence_mode,
1337                         {       "Sequence Mode",           
1338                                 "wsp.wtls.handshake.client_hello.sequence_mode",
1339                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_sequence_mode ), 0x00,
1340                                 "Sequence Mode", HFILL
1341                         }
1342                 },
1343                 { &hf_wtls_hands_cli_hello_key_refresh,
1344                         {       "Refresh",           
1345                                 "wsp.wtls.handshake.client_hello.refresh",
1346                                  FT_UINT8, BASE_DEC, NULL, 0x00,
1347                                 "Refresh", HFILL
1348                         }
1349                 },
1350                 { &hf_wtls_hands_serv_hello,
1351                         {       "Server Hello",           
1352                                 "wsp.wtls.handshake.server_hello",
1353                                  FT_NONE, BASE_NONE, NULL, 0x00,
1354                                 "Server Hello", HFILL
1355                         }
1356                 },
1357                 { &hf_wtls_hands_serv_hello_version,
1358                         {       "Version",           
1359                                 "wsp.wtls.handshake.server_hello.version",
1360                                  FT_UINT8, BASE_DEC, NULL, 0x00,
1361                                 "Version", HFILL
1362                         }
1363                 },
1364                 { &hf_wtls_hands_serv_hello_gmt,
1365                         {       "Time GMT",           
1366                                 "wsp.wtls.handshake.server_hello.gmt",
1367                                  FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
1368                                 "Time GMT", HFILL
1369                         }
1370                 },
1371                 { &hf_wtls_hands_serv_hello_random,
1372                         {       "Random",           
1373                                 "wsp.wtls.handshake.server_hello.random",
1374                                  FT_NONE, BASE_NONE, NULL, 0x00,
1375                                 "Random", HFILL
1376                         }
1377                 },
1378                 { &hf_wtls_hands_serv_hello_session,
1379                         {       "Session ID",           
1380                                 "wsp.wtls.handshake.server_hello.sessionid",
1381                                  FT_UINT32, BASE_DEC, NULL, 0x00,
1382                                 "Session ID", HFILL
1383                         }
1384                 },
1385                 { &hf_wtls_hands_serv_hello_session_str,
1386                         {       "Session ID",           
1387                                 "wsp.wtls.handshake.server_hello.session.str",
1388                                  FT_STRING, BASE_NONE, NULL, 0x00,
1389                                 "Session ID", HFILL
1390                         }
1391                 },
1392                 { &hf_wtls_hands_serv_hello_cli_key_id,
1393                         {       "Client Key ID",           
1394                                 "wsp.wtls.handshake.server_hello.key",
1395                                  FT_UINT8, BASE_HEX, NULL, 0x00,
1396                                 "Client Key ID", HFILL
1397                         }
1398                 },
1399                 { &hf_wtls_hands_serv_hello_cipher_suite_item,
1400                         {       "Cipher",           
1401                                 "wsp.wtls.handshake.server_hello.cipher",
1402                                  FT_NONE, BASE_NONE, NULL, 0x00,
1403                                 "Cipher", HFILL
1404                         }
1405                 },
1406                 { &hf_wtls_hands_serv_hello_cipher_bulk,
1407                         {       "Cipher Bulk",           
1408                                 "wsp.wtls.handshake.server_hello.cipher.bulk",
1409                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_cipher_bulk ), 0x00,
1410                                 "Cipher Bulk", HFILL
1411                         }
1412                 },
1413                 { &hf_wtls_hands_serv_hello_cipher_mac,
1414                         {       "Cipher MAC",           
1415                                 "wsp.wtls.handshake.server_hello.cipher.mac",
1416                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_cipher_mac ), 0x00,
1417                                 "Cipher MAC", HFILL
1418                         }
1419                 },
1420                 { &hf_wtls_hands_serv_hello_compression,
1421                         {       "Compression",           
1422                                 "wsp.wtls.handshake.server_hello.compression",
1423                                  FT_UINT8, BASE_HEX, VALS ( wtls_vals_compression ), 0x00,
1424                                 "Compression", HFILL
1425                         }
1426                 },
1427                 { &hf_wtls_hands_serv_hello_sequence_mode,
1428                         {       "Sequence Mode",           
1429                                 "wsp.wtls.handshake.server_hello.sequence_mode",
1430                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_sequence_mode ), 0x00,
1431                                 "Sequence Mode", HFILL
1432                         }
1433                 },
1434                 { &hf_wtls_hands_serv_hello_key_refresh,
1435                         {       "Refresh",           
1436                                 "wsp.wtls.handshake.server_hello.refresh",
1437                                  FT_UINT8, BASE_DEC, NULL, 0x00,
1438                                 "Refresh", HFILL
1439                         }
1440                 },
1441                 { &hf_wtls_hands_certificates,
1442                         {       "Certificates",
1443                                 "wsp.wtls.handshake.certificates",
1444                                  FT_NONE, BASE_NONE, NULL, 0x00,
1445                                 "Certificates", HFILL
1446                         }
1447                 },
1448                 { &hf_wtls_hands_certificate,
1449                         {       "Certificate",           
1450                                 "wsp.wtls.handshake.certificate",
1451                                  FT_NONE, BASE_NONE, NULL, 0x00,
1452                                 "Certificate", HFILL
1453                         }
1454                 },
1455                 { &hf_wtls_hands_certificate_type,
1456                         {       "Type",           
1457                                 "wsp.wtls.handshake.certificate.type",
1458                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_certificate_type ), 0x00,
1459                                 "Type", HFILL
1460                         }
1461                 },
1462                 { &hf_wtls_hands_certificate_wtls_version,
1463                         {       "Version",           
1464                                 "wsp.wtls.handshake.certificate.version",
1465                                  FT_UINT8, BASE_HEX, NULL, 0x00,
1466                                 "Version", HFILL
1467                         }
1468                 },
1469                 { &hf_wtls_hands_certificate_wtls_signature_type,
1470                         {       "Signature Type",           
1471                                 "wsp.wtls.handshake.certificate.signature.type",
1472                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_certificate_signature ), 0x00,
1473                                 "Signature Type", HFILL 
1474                         }
1475                 },
1476                 { &hf_wtls_hands_certificate_wtls_signature,
1477                         {       "Signature Size",           
1478                                 "wsp.wtls.handshake.certificate.signature.signature",
1479                                  FT_UINT32, BASE_DEC, NULL, 0x00,
1480                                 "Signature Size", HFILL
1481                         }
1482                 },
1483                 { &hf_wtls_hands_certificate_wtls_issuer_type,
1484                         {       "Issuer",           
1485                                 "wsp.wtls.handshake.certificate.issuer.type",
1486                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_identifier_type ), 0x00,
1487                                 "Issuer", HFILL
1488                         }
1489                 },
1490                 { &hf_wtls_hands_certificate_wtls_issuer_charset,
1491                         {       "Charset",           
1492                                 "wsp.wtls.handshake.certificate.issuer.charset",
1493                                  FT_UINT16, BASE_HEX, VALS ( vals_character_sets ), 0x00,
1494                                 "Charset", HFILL
1495                         }
1496                 },
1497                 { &hf_wtls_hands_certificate_wtls_issuer_size,
1498                         {       "Size",           
1499                                 "wsp.wtls.handshake.certificate.issuer.size",
1500                                  FT_UINT8, BASE_DEC, NULL, 0x00,
1501                                 "Size", HFILL
1502                         }
1503                 },
1504                 { &hf_wtls_hands_certificate_wtls_issuer_name,
1505                         {       "Name",           
1506                                 "wsp.wtls.handshake.certificate.issuer.name",
1507                                  FT_STRING, BASE_NONE, NULL, 0x00,
1508                                 "Name", HFILL
1509                         }
1510                 },
1511                 { &hf_wtls_hands_certificate_wtls_valid_not_before,
1512                         {       "Valid not before",           
1513                                 "wsp.wtls.handshake.certificate.before",
1514                                  FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
1515                                 "Valid not before", HFILL
1516                         }
1517                 },
1518                 { &hf_wtls_hands_certificate_wtls_valid_not_after,
1519                         {       "Valid not after",           
1520                                 "wsp.wtls.handshake.certificate.after",
1521                                  FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
1522                                 "Valid not after", HFILL
1523                         }
1524                 },
1525                 { &hf_wtls_hands_certificate_wtls_subject_type,
1526                         {       "Subject",           
1527                                 "wsp.wtls.handshake.certificate.subject.type",
1528                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_identifier_type ), 0x00,
1529                                 "Subject", HFILL
1530                         }
1531                 },
1532                 { &hf_wtls_hands_certificate_wtls_subject_charset,
1533                         {       "Charset",           
1534                                 "wsp.wtls.handshake.certificate.subject.charset",
1535                                  FT_UINT16, BASE_HEX, VALS ( vals_character_sets ), 0x00,
1536                                 "Charset", HFILL
1537                         }
1538                 },
1539                 { &hf_wtls_hands_certificate_wtls_subject_size,
1540                         {       "Size",           
1541                                 "wsp.wtls.handshake.certificate.subject.size",
1542                                  FT_UINT8, BASE_DEC, NULL, 0x00,
1543                                 "Size", HFILL
1544                         }
1545                 },
1546                 { &hf_wtls_hands_certificate_wtls_subject_name,
1547                         {       "Name",           
1548                                 "wsp.wtls.handshake.certificate.subject.name",
1549                                  FT_STRING, BASE_NONE, NULL, 0x00,
1550                                 "Name", HFILL
1551                         }
1552                 },
1553                 { &hf_wtls_hands_certificate_wtls_public_key_type,
1554                         {       "Public Key Type",           
1555                                 "wsp.wtls.handshake.certificate.public.type",
1556                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_public_key_type ), 0x00,
1557                                 "Public Key Type", HFILL
1558                         }
1559                 },
1560                 { &hf_wtls_hands_certificate_wtls_key_parameter_index,
1561                         {       "Parameter Index",           
1562                                 "wsp.wtls.handshake.certificate.parameter_index",
1563                                  FT_UINT8, BASE_DEC, NULL, 0x00,
1564                                 "Parameter Index", HFILL
1565                         }
1566                 },
1567                 { &hf_wtls_hands_certificate_wtls_key_parameter_set,
1568                         {       "Parameter Set",           
1569                                 "wsp.wtls.handshake.certificate.parameter",
1570                                  FT_STRING, BASE_NONE, NULL, 0x00,
1571                                 "Parameter Set", HFILL
1572                         }
1573                 },
1574                 { &hf_wtls_hands_certificate_wtls_rsa_exponent,
1575                         {       "RSA Exponent Size",           
1576                                 "wsp.wtls.handshake.certificate.rsa.exponent",
1577                                  FT_UINT32, BASE_DEC, NULL, 0x00,
1578                                 "RSA Exponent Size", HFILL
1579                         }
1580                 },
1581                 { &hf_wtls_hands_certificate_wtls_rsa_modules,
1582                         {       "RSA Modulus Size",           
1583                                 "wsp.wtls.handshake.certificate.rsa.modules",
1584                                  FT_UINT32, BASE_DEC, NULL, 0x00,
1585                                 "RSA Modulus Size", HFILL
1586                         }
1587                 },
1588                 { &hf_wtls_alert,
1589                         {       "Alert",           
1590                                 "wsp.wtls.alert",
1591                                  FT_NONE, BASE_NONE, NULL, 0x00,
1592                                 "Alert", HFILL
1593                         }
1594                 },
1595                 { &hf_wtls_alert_level,
1596                         {       "Level",           
1597                                 "wsp.wtls.alert.level",
1598                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_alert_level ), 0x00,
1599                                 "Level", HFILL
1600                         }
1601                 },
1602                 { &hf_wtls_alert_description,
1603                         {       "Description",           
1604                                 "wsp.wtls.alert.description",
1605                                  FT_UINT8, BASE_DEC, VALS ( wtls_vals_alert_description ), 0x00,
1606                                 "Description", HFILL
1607                         }
1608                 },
1609         };
1610         
1611 /* Setup protocol subtree array */
1612         static gint *ett[] = {
1613                 &ett_wtls,
1614                 &ett_wtls_rec,
1615                 &ett_wtls_msg_type,
1616                 &ett_wtls_msg_type_item,
1617                 &ett_wtls_msg_type_item_sub,
1618                 &ett_wtls_msg_type_item_sub_sub,
1619         };
1620
1621 /* Register the protocol name and description */
1622         proto_wtls = proto_register_protocol(
1623                 "Wireless Transport Layer Security",    /* protocol name for use by ethereal */ 
1624                 "WTLS",                          /* short version of name */
1625                 "wap-wtls"                      /* Abbreviated protocol name, should Match IANA 
1626                                                     < URL:http://www.isi.edu/in-notes/iana/assignments/port-numbers/ >
1627                                                   */
1628         );
1629
1630 /* Required function calls to register the header fields and subtrees used  */
1631         proto_register_field_array(proto_wtls, hf, array_length(hf));
1632         proto_register_subtree_array(ett, array_length(ett));
1633 }
1634
1635 void
1636 proto_reg_handoff_wtls(void)
1637 {
1638         dissector_handle_t wtls_handle;
1639
1640         /*
1641          * Get handles for the WTP and connectionless WSP dissectors.
1642          */
1643         wtp_handle = find_dissector("wtp");
1644         wsp_handle = find_dissector("wsp-cl");
1645
1646         wtls_handle = create_dissector_handle(dissect_wtls, proto_wtls);
1647         dissector_add("udp.port", UDP_PORT_WTLS_WSP,     wtls_handle); 
1648         dissector_add("udp.port", UDP_PORT_WTLS_WTP_WSP, wtls_handle);
1649         dissector_add("udp.port", UDP_PORT_WTLS_WSP_PUSH,wtls_handle);
1650 }