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