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