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