Fix for bug 5422:
[obnox/wireshark/wip.git] / epan / dissectors / packet-pktc.c
1 /* packet-pktc.c
2  * Routines for PacketCable (PKTC) Kerberized Key Management and
3  *              PacketCable (PKTC) MTA FQDN                  packet disassembly
4  *
5  * References:
6  * [1] PacketCable 1.0 Security Specification, PKT-SP-SEC-I11-040730, July 30,
7  *     2004, Cable Television Laboratories, Inc., http://www.PacketCable.com/
8  *
9  * Ronnie Sahlberg 2004
10  * Thomas Anders 2004
11  *
12  * $Id$
13  *
14  * Wireshark - Network traffic analyzer
15  * By Gerald Combs <gerald@wireshark.org>
16  * Copyright 1998 Gerald Combs
17  *
18  * This program is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU General Public License
20  * as published by the Free Software Foundation; either version 2
21  * of the License, or (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
31  */
32
33 #ifdef HAVE_CONFIG_H
34 # include "config.h"
35 #endif
36
37 #include <epan/packet.h>
38 #include <epan/asn1.h>
39 #include "packet-pktc.h"
40 #include "packet-kerberos.h"
41 #include "packet-snmp.h"
42
43 #define PKTC_PORT       1293
44 #define PKTC_MTAFQDN_PORT       2246
45
46 static int proto_pktc = -1;
47 static gint hf_pktc_app_spec_data = -1;
48 static gint hf_pktc_list_of_ciphersuites = -1;
49 static gint hf_pktc_list_of_ciphersuites_len = -1;
50 static gint hf_pktc_kmmid = -1;
51 static gint hf_pktc_doi = -1;
52 static gint hf_pktc_version_major = -1;
53 static gint hf_pktc_version_minor = -1;
54 static gint hf_pktc_server_nonce = -1;
55 static gint hf_pktc_server_principal = -1;
56 static gint hf_pktc_timestamp = -1;
57 static gint hf_pktc_snmpEngineID_len = -1;
58 static gint hf_pktc_snmpEngineID = -1;
59 static gint hf_pktc_snmpEngineBoots = -1;
60 static gint hf_pktc_snmpEngineTime = -1;
61 static gint hf_pktc_usmUserName_len = -1;
62 static gint hf_pktc_usmUserName = -1;
63 static gint hf_pktc_ipsec_spi = -1;
64 static gint hf_pktc_snmpAuthenticationAlgorithm = -1;
65 static gint hf_pktc_snmpEncryptionTransformID = -1;
66 static gint hf_pktc_ipsecAuthenticationAlgorithm = -1;
67 static gint hf_pktc_ipsecEncryptionTransformID = -1;
68 static gint hf_pktc_reestablish_flag = -1;
69 static gint hf_pktc_ack_required_flag = -1;
70 static gint hf_pktc_sha1_hmac = -1;
71 static gint hf_pktc_sec_param_lifetime = -1;
72 static gint hf_pktc_grace_period = -1;
73
74 static gint hf_pktc_mtafqdn_msgtype = -1;
75 static gint hf_pktc_mtafqdn_enterprise = -1;
76 static gint hf_pktc_mtafqdn_version = -1;
77 static gint hf_pktc_mtafqdn_mac = -1;
78 static gint hf_pktc_mtafqdn_pub_key_hash = -1;
79 static gint hf_pktc_mtafqdn_manu_cert_revoked = -1;
80 static gint hf_pktc_mtafqdn_fqdn = -1;
81 static gint hf_pktc_mtafqdn_ip = -1;
82
83 static gint ett_pktc = -1;
84 static gint ett_pktc_app_spec_data = -1;
85 static gint ett_pktc_list_of_ciphersuites = -1;
86 static gint ett_pktc_engineid = -1;
87
88 static gint ett_pktc_mtafqdn = -1;
89
90 #define KMMID_WAKEUP            0x01
91 #define KMMID_AP_REQUEST        0x02
92 #define KMMID_AP_REPLY          0x03
93 #define KMMID_SEC_PARAM_REC     0x04
94 #define KMMID_REKEY             0x05
95 #define KMMID_ERROR_REPLY       0x06
96 static const value_string kmmid_types[] = {
97     { KMMID_WAKEUP              , "Wake Up" },
98     { KMMID_AP_REQUEST          , "AP Request" },
99     { KMMID_AP_REPLY            , "AP Reply" },
100     { KMMID_SEC_PARAM_REC       , "Security Parameter Recovered" },
101     { KMMID_REKEY               , "Rekey" },
102     { KMMID_ERROR_REPLY         , "Error Reply" },
103     { 0, NULL }
104 };
105
106 #define DOI_IPSEC       1
107 #define DOI_SNMPv3      2
108 #define SNMPv3_NULL    0x20
109 #define SNMPv3_DES     0x21
110 #define SNMPv3_HMAC_MD5        0x21
111 #define SNMPv3_HMAC_SHA1 0x22
112 #define ESP_3DES       0x03
113 #define ESP_RC5                0x04
114 #define ESP_IDEA       0x05
115 #define ESP_CAST       0x06
116 #define ESP_BLOWFISH   0x07
117 #define ESP_NULL       0x0b
118 #define ESP_AES                0x0c
119 #define HMAC_MD5_96    0x01
120 #define HMAC_SHA1_96   0x02
121
122
123 /* Domain of Interpretation */
124 static const value_string doi_types[] = {
125     { DOI_IPSEC                , "IPsec" },
126     { DOI_SNMPv3        , "SNMPv3" },
127     { 0, NULL }
128 };
129
130 /* SNMPv3 ciphersuites */
131 static const value_string snmp_authentication_algorithm_vals[] = {
132     { SNMPv3_HMAC_MD5  , "HMAC-MD5" },
133     { SNMPv3_HMAC_SHA1 , "HMAC-SHA1" },
134     { 0        , NULL }
135 };
136 static const value_string snmp_transform_id_vals[] = {
137     { SNMPv3_NULL      , "NULL" }, /* no encryption */
138     { SNMPv3_DES       , "DES" },
139     { 0        , NULL }
140 };
141
142 /* IPsec ciphersuites */
143 static const value_string ipsec_transform_id_vals[] = {
144     { ESP_3DES         , "3DES" },
145     { ESP_RC5          , "RC5" },
146     { ESP_IDEA         , "IDEA" },
147     { ESP_CAST         , "CAST" },
148     { ESP_BLOWFISH     , "BLOWFISH" },
149     { ESP_NULL         , "NULL" }, /* no encryption, RFC 2410 */
150     { ESP_AES          , "AES-128" },
151     { 0 , NULL }
152 };
153
154 static const value_string ipsec_authentication_algorithm_vals[] = {
155     { HMAC_MD5_96      , "HMAC-MD5-96" },   /* RFC 2403 */
156     { HMAC_SHA1_96     , "HMAC-SHA-1-96" }, /* RFC 2404 */
157     { 0        , NULL }
158 };
159
160 /* MTA FQDN Message Types */
161 #define PKTC_MTAFQDN_REQ       0x01
162 #define PKTC_MTAFQDN_REP       0x02
163 #define PKTC_MTAFQDN_ERR       0x03
164 static const value_string pktc_mtafqdn_msgtype_vals[] = {
165     { PKTC_MTAFQDN_REQ,        "MTA FQDN Request" },
166     { PKTC_MTAFQDN_REP,        "MTA FQDN Reply" },
167     { PKTC_MTAFQDN_ERR,        "MTA FQDN Error Reply" },
168     { 0 , NULL }
169 };
170
171 static int
172 dissect_pktc_app_specific_data(packet_info *pinfo _U_, proto_tree *parent_tree, tvbuff_t *tvb, int offset, guint8 doi, guint8 kmmid)
173 {
174     int old_offset=offset;
175     proto_tree *tree = NULL;
176     proto_tree *engineid_tree = NULL;
177     proto_item *item = NULL;
178     proto_item *engineid_item = NULL;
179     guint8 len;
180
181     if (parent_tree) {
182         item = proto_tree_add_item(parent_tree, hf_pktc_app_spec_data, tvb, offset, -1, FALSE);
183         tree = proto_item_add_subtree(item, ett_pktc_app_spec_data);
184     }
185
186     switch(doi){
187     case DOI_SNMPv3:
188         switch(kmmid){
189         /* we dont distinguish between manager and agent engineid.
190            feel free to add separation for this if it is imporant enough
191            for you. */
192         case KMMID_AP_REQUEST:
193         case KMMID_AP_REPLY:
194             /* snmpEngineID Length */
195             len=tvb_get_guint8(tvb, offset);
196             proto_tree_add_uint(tree, hf_pktc_snmpEngineID_len, tvb, offset, 1, len);
197             offset+=1;
198
199             /* snmpEngineID */
200             engineid_item = proto_tree_add_item(tree, hf_pktc_snmpEngineID, tvb, offset, len, FALSE);
201             engineid_tree = proto_item_add_subtree(engineid_item, ett_pktc_engineid);
202             dissect_snmp_engineid(engineid_tree, tvb, offset, len);
203             offset+=len;
204
205             /* boots */
206             proto_tree_add_item(tree, hf_pktc_snmpEngineBoots, tvb, offset, 4, FALSE);
207             offset+=4;
208
209             /* time */
210             proto_tree_add_item(tree, hf_pktc_snmpEngineTime, tvb, offset, 4, FALSE);
211             offset+=4;
212
213             /* usmUserName Length */
214             len=tvb_get_guint8(tvb, offset);
215             proto_tree_add_uint(tree, hf_pktc_usmUserName_len, tvb, offset, 1, len);
216             offset+=1;
217
218             /* usmUserName */
219             proto_tree_add_item(tree, hf_pktc_usmUserName, tvb, offset, len, FALSE);
220             offset+=len;
221
222             break;
223         default:
224             proto_tree_add_text(tree, tvb, offset, 1, "Unknown KMMID");
225             tvb_get_guint8(tvb, 9999); /* bail out and inform user we cant dissect the packet */
226         };
227         break;
228     case DOI_IPSEC:
229         switch(kmmid){
230         /* we dont distinguish between SPIs for inbound Security Associations
231            of the client (AP-REQ) vs. server (AP-REP, REKEY). Feel free to add
232            separation for this if it is imporant enough for you. */
233         case KMMID_AP_REQUEST:
234         case KMMID_AP_REPLY:
235         case KMMID_REKEY:
236             /* Security Parameter Index (SPI) */
237             proto_tree_add_item(tree, hf_pktc_ipsec_spi, tvb, offset, 4, FALSE);
238             offset+=4;
239
240             break;
241         default:
242             proto_tree_add_text(tree, tvb, offset, 1, "Unknown KMMID");
243             tvb_get_guint8(tvb, 9999); /* bail out and inform user we cant dissect the packet */
244         };
245         break;
246     default:
247         proto_tree_add_text(tree, tvb, offset, 1, "Unknown DOI");
248         tvb_get_guint8(tvb, 9999); /* bail out and inform user we cant dissect the packet */
249     }
250
251     proto_item_set_len(item, offset-old_offset);
252     return offset;
253 }
254
255 static int
256 dissect_pktc_list_of_ciphersuites(packet_info *pinfo _U_, proto_tree *parent_tree, tvbuff_t *tvb, int offset, guint8 doi)
257 {
258     int old_offset=offset;
259     proto_tree *tree = NULL;
260     proto_item *item = NULL, *hidden_item;
261     guint8 len, i;
262
263     if (parent_tree) {
264         item = proto_tree_add_item(parent_tree, hf_pktc_list_of_ciphersuites, tvb, offset, -1, FALSE);
265         tree = proto_item_add_subtree(item, ett_pktc_list_of_ciphersuites);
266     }
267
268
269     /* number of ciphersuites */
270     len=tvb_get_guint8(tvb, offset);
271     if (len>0) {
272       proto_item_append_text(tree, " (%d):", len);
273     }
274     hidden_item = proto_tree_add_uint(tree, hf_pktc_list_of_ciphersuites_len, tvb, offset, 1, len);
275     PROTO_ITEM_SET_HIDDEN(hidden_item);
276     offset+=1;
277
278     switch(doi){
279     case DOI_SNMPv3:
280         for(i=0;i<len;i++){
281             /* SNMPv3 authentication algorithm */
282             proto_tree_add_item(tree, hf_pktc_snmpAuthenticationAlgorithm, tvb, offset, 1, FALSE);
283             proto_item_append_text(tree, " %s", val_to_str(tvb_get_guint8(tvb, offset), snmp_authentication_algorithm_vals, "%0x"));
284             offset+=1;
285
286             /* SNMPv3 encryption transform id */
287             proto_tree_add_item(tree, hf_pktc_snmpEncryptionTransformID, tvb, offset, 1, FALSE);
288             proto_item_append_text(tree, "/%s", val_to_str(tvb_get_guint8(tvb, offset), snmp_transform_id_vals, "%0x"));
289             offset+=1;
290         }
291         break;
292     case DOI_IPSEC:
293         for(i=0;i<len;i++){
294             /* IPsec authentication algorithm */
295             proto_tree_add_item(tree, hf_pktc_ipsecAuthenticationAlgorithm, tvb, offset, 1, FALSE);
296             proto_item_append_text(tree, " %s", val_to_str(tvb_get_guint8(tvb, offset), ipsec_authentication_algorithm_vals, "%0x"));
297             offset+=1;
298
299             /* IPsec encryption transform id */
300             proto_tree_add_item(tree, hf_pktc_ipsecEncryptionTransformID, tvb, offset, 1, FALSE);
301             proto_item_append_text(tree, "/%s", val_to_str(tvb_get_guint8(tvb, offset), ipsec_transform_id_vals, "%0x"));
302             offset+=1;
303         }
304         break;
305     default:
306         proto_tree_add_text(tree, tvb, offset, 1, "Unknown DOI");
307         tvb_get_guint8(tvb, 9999); /* bail out and inform user we cant dissect the packet */
308     }
309
310     proto_item_set_len(item, offset-old_offset);
311     return offset;
312 }
313
314 static int
315 dissect_pktc_wakeup(proto_tree *tree, tvbuff_t *tvb, int offset)
316 {
317     guint32 snonce;
318     guint string_len;
319
320     /* Server Nonce */
321     snonce=tvb_get_ntohl(tvb, offset);
322     proto_tree_add_uint(tree, hf_pktc_server_nonce, tvb, offset, 4, snonce);
323     offset+=4;
324
325     /* Server Kerberos Principal Identifier */
326     string_len=tvb_strsize(tvb, offset);
327     proto_tree_add_item(tree, hf_pktc_server_principal, tvb, offset, string_len, FALSE);
328     offset+=string_len;
329
330     return offset;
331 }
332
333 static int
334 dissect_pktc_ap_request(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, guint8 doi)
335 {
336     tvbuff_t *pktc_tvb;
337     guint32 snonce;
338
339     /* AP Request  kerberos blob */
340     pktc_tvb = tvb_new_subset_remaining(tvb, offset);
341     offset += dissect_kerberos_main(pktc_tvb, pinfo, tree, FALSE, NULL);
342
343     /* Server Nonce */
344     snonce=tvb_get_ntohl(tvb, offset);
345     proto_tree_add_uint(tree, hf_pktc_server_nonce, tvb, offset, 4, snonce);
346     offset+=4;
347
348     /* app specific data */
349     offset=dissect_pktc_app_specific_data(pinfo, tree, tvb, offset, doi, KMMID_AP_REQUEST);
350
351     /* list of ciphersuites */
352     offset=dissect_pktc_list_of_ciphersuites(pinfo, tree, tvb, offset, doi);
353
354     /* re-establish flag */
355     proto_tree_add_item(tree, hf_pktc_reestablish_flag, tvb, offset, 1, FALSE);
356     offset+=1;
357
358     /* sha-1 hmac */
359     proto_tree_add_item(tree, hf_pktc_sha1_hmac, tvb, offset, 20, FALSE);
360     offset+=20;
361
362     return offset;
363 }
364
365 static int
366 dissect_pktc_ap_reply(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, guint8 doi)
367 {
368     tvbuff_t *pktc_tvb;
369
370     /* AP Reply  kerberos blob */
371     pktc_tvb = tvb_new_subset_remaining(tvb, offset);
372     offset += dissect_kerberos_main(pktc_tvb, pinfo, tree, FALSE, NULL);
373
374     /* app specific data */
375     offset=dissect_pktc_app_specific_data(pinfo, tree, tvb, offset, doi, KMMID_AP_REPLY);
376
377     /* selected ciphersuite */
378     offset=dissect_pktc_list_of_ciphersuites(pinfo, tree, tvb, offset, doi);
379
380     /* sec param lifetime */
381     proto_tree_add_uint_format(tree, hf_pktc_sec_param_lifetime, tvb, offset, 4,
382                                tvb_get_ntohl(tvb, offset), "%s: %s",
383                                proto_registrar_get_name(hf_pktc_sec_param_lifetime),
384                                time_secs_to_str(tvb_get_ntohl(tvb, offset)));
385     offset+=4;
386
387     /* grace period */
388     proto_tree_add_item(tree, hf_pktc_grace_period, tvb, offset, 4, FALSE);
389     offset+=4;
390
391     /* re-establish flag */
392     proto_tree_add_item(tree, hf_pktc_reestablish_flag, tvb, offset, 1, FALSE);
393     offset+=1;
394
395     /* ack required flag */
396     proto_tree_add_item(tree, hf_pktc_ack_required_flag, tvb, offset, 1, FALSE);
397     offset+=1;
398
399     /* sha-1 hmac */
400     proto_tree_add_item(tree, hf_pktc_sha1_hmac, tvb, offset, 20, FALSE);
401     offset+=20;
402
403     return offset;
404 }
405
406 static int
407 dissect_pktc_sec_param_rec(proto_tree *tree, tvbuff_t *tvb, int offset)
408 {
409     /* sha-1 hmac of the subkey of the preceding AP-REP */
410     proto_tree_add_item(tree, hf_pktc_sha1_hmac, tvb, offset, 20, FALSE);
411     offset+=20;
412
413     return offset;
414 }
415
416 static int
417 dissect_pktc_rekey(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, guint8 doi)
418 {
419     guint32 snonce;
420     guint string_len;
421     const guint8 *timestr;
422
423     /* Server Nonce */
424     snonce=tvb_get_ntohl(tvb, offset);
425     proto_tree_add_uint(tree, hf_pktc_server_nonce, tvb, offset, 4, snonce);
426     offset+=4;
427
428     /* Server Kerberos Principal Identifier */
429     string_len=tvb_strsize(tvb, offset);
430     proto_tree_add_item(tree, hf_pktc_server_principal, tvb, offset, string_len, FALSE);
431     offset+=string_len;
432
433     /* Timestamp: YYMMDDhhmmssZ */
434     /* They really came up with a two-digit year in late 1990s! =8o */
435     timestr=tvb_get_ptr(tvb, offset, 13);
436     proto_tree_add_string_format(tree, hf_pktc_timestamp, tvb, offset, 13, timestr,
437                                 "%s: %.2s-%.2s-%.2s %.2s:%.2s:%.2s",
438                                 proto_registrar_get_name(hf_pktc_timestamp),
439                                  timestr, timestr+2, timestr+4, timestr+6, timestr+8, timestr+10);
440     offset+=13;
441
442     /* app specific data */
443     offset=dissect_pktc_app_specific_data(pinfo, tree, tvb, offset, doi, KMMID_REKEY);
444
445     /* list of ciphersuites */
446     offset=dissect_pktc_list_of_ciphersuites(pinfo, tree, tvb, offset, doi);
447
448     /* sec param lifetime */
449     proto_tree_add_item(tree, hf_pktc_sec_param_lifetime, tvb, offset, 4, FALSE);
450     offset+=4;
451
452     /* grace period */
453     proto_tree_add_item(tree, hf_pktc_grace_period, tvb, offset, 4, FALSE);
454     offset+=4;
455
456     /* re-establish flag */
457     proto_tree_add_item(tree, hf_pktc_reestablish_flag, tvb, offset, 1, FALSE);
458     offset+=1;
459
460     /* sha-1 hmac */
461     proto_tree_add_item(tree, hf_pktc_sha1_hmac, tvb, offset, 20, FALSE);
462     offset+=20;
463
464     return offset;
465 }
466
467 static int
468 dissect_pktc_error_reply(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset)
469 {
470     tvbuff_t *pktc_tvb;
471
472     /* KRB_ERROR */
473     pktc_tvb = tvb_new_subset_remaining(tvb, offset);
474     offset += dissect_kerberos_main(pktc_tvb, pinfo, tree, FALSE, NULL);
475
476     return offset;
477 }
478
479 static int
480 dissect_pktc_mtafqdn_krbsafeuserdata(packet_info *pinfo, tvbuff_t *tvb, proto_tree *tree)
481 {
482     int offset=0, string_len=0;
483     guint8 msgtype;
484     guint32 bignum;
485     nstime_t ts;
486
487     /* message type */
488     msgtype = tvb_get_guint8(tvb, offset);
489     proto_tree_add_uint(tree, hf_pktc_mtafqdn_msgtype, tvb, offset, 1, msgtype);
490     offset+=1;
491
492     if (check_col(pinfo->cinfo, COL_INFO))
493         col_add_str(pinfo->cinfo, COL_INFO,
494                    val_to_str(msgtype, pktc_mtafqdn_msgtype_vals, "MsgType %u"));
495
496     /* enterprise */
497     proto_tree_add_uint(tree, hf_pktc_mtafqdn_enterprise, tvb, offset, 4, tvb_get_ntohl(tvb, offset));
498     offset+=4;
499
500     /* protocol version */
501     proto_tree_add_uint(tree, hf_pktc_mtafqdn_version, tvb, offset, 1, tvb_get_guint8(tvb, offset));
502     offset+=1;
503
504     switch(msgtype) {
505     case PKTC_MTAFQDN_REQ:
506         /* MTA MAC address */
507         proto_tree_add_ether(tree, hf_pktc_mtafqdn_mac, tvb, offset, 6, tvb_get_ptr(tvb, offset, 6));
508        offset+=6;
509
510        /* MTA pub key hash */
511        proto_tree_add_item(tree, hf_pktc_mtafqdn_pub_key_hash, tvb, offset, 20, FALSE);
512        offset+=20;
513
514        /* manufacturer cert revocation time */
515        bignum = tvb_get_ntohl(tvb, offset);
516        ts.secs = bignum;
517        proto_tree_add_time_format(tree, hf_pktc_mtafqdn_manu_cert_revoked, tvb, offset, 4,
518                                   &ts, "%s: %s",
519                                   proto_registrar_get_name(hf_pktc_mtafqdn_manu_cert_revoked),
520                                   (bignum==0) ? "not revoked" : abs_time_secs_to_str(bignum, ABSOLUTE_TIME_LOCAL, TRUE));
521        break;
522
523     case PKTC_MTAFQDN_REP:
524         /* MTA FQDN */
525         string_len = tvb_length_remaining(tvb, offset) - 4;
526         if (string_len <= 0)
527                 THROW(ReportedBoundsError);
528         proto_tree_add_item(tree, hf_pktc_mtafqdn_fqdn, tvb, offset, string_len, FALSE);
529         offset+=string_len;
530
531         /* MTA IP address */
532         tvb_memcpy(tvb, (guint8 *)&bignum, offset, sizeof(bignum));
533         proto_tree_add_ipv4(tree, hf_pktc_mtafqdn_ip, tvb, offset, 4, bignum);
534
535         break;
536     }
537
538     return offset;
539 }
540
541 static kerberos_callbacks cb[] = {
542     { KRB_CBTAG_SAFE_USER_DATA,      dissect_pktc_mtafqdn_krbsafeuserdata },
543     { 0, NULL }
544 };
545
546 static void
547 dissect_pktc_mtafqdn(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
548 {
549     int offset=0;
550     proto_tree *pktc_mtafqdn_tree = NULL;
551     proto_item *item = NULL;
552     tvbuff_t *pktc_mtafqdn_tvb;
553
554     col_set_str(pinfo->cinfo, COL_PROTOCOL, "PKTC");
555
556     if (tree) {
557         item = proto_tree_add_item(tree, proto_pktc, tvb, 0, 0, FALSE);
558         pktc_mtafqdn_tree = proto_item_add_subtree(item, ett_pktc_mtafqdn);
559     }
560
561     if (check_col(pinfo->cinfo, COL_INFO)) {
562         col_add_fstr(pinfo->cinfo, COL_INFO, "MTA FQDN %s",
563                     pinfo->srcport == pinfo->match_port ? "Reply":"Request");
564     }
565
566
567     /* KRB_AP_RE[QP] */
568     pktc_mtafqdn_tvb = tvb_new_subset_remaining(tvb, offset);
569     offset += dissect_kerberos_main(pktc_mtafqdn_tvb, pinfo, pktc_mtafqdn_tree, FALSE, NULL);
570
571     /* KRB_SAFE */
572     pktc_mtafqdn_tvb = tvb_new_subset_remaining(tvb, offset);
573     offset += dissect_kerberos_main(pktc_mtafqdn_tvb, pinfo, pktc_mtafqdn_tree, FALSE, cb);
574
575     proto_item_set_len(item, offset);
576 }
577
578
579 static void
580 dissect_pktc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
581 {
582     guint8 kmmid, doi, version;
583     int offset=0;
584     proto_tree *pktc_tree = NULL;
585     proto_item *item = NULL, *hidden_item;
586
587     col_set_str(pinfo->cinfo, COL_PROTOCOL, "PKTC");
588
589     if (tree) {
590         item = proto_tree_add_item(tree, proto_pktc, tvb, 0, 3, FALSE);
591         pktc_tree = proto_item_add_subtree(item, ett_pktc);
592     }
593
594     /* key management message id */
595     kmmid=tvb_get_guint8(tvb, offset);
596     proto_tree_add_uint(pktc_tree, hf_pktc_kmmid, tvb, offset, 1, kmmid);
597     offset+=1;
598
599     /* domain of interpretation */
600     doi=tvb_get_guint8(tvb, offset);
601     proto_tree_add_uint(pktc_tree, hf_pktc_doi, tvb, offset, 1, doi);
602     offset+=1;
603
604     /* version */
605     version=tvb_get_guint8(tvb, offset);
606     proto_tree_add_text(pktc_tree, tvb, offset, 1, "Version: %d.%d", (version>>4)&0x0f, (version)&0x0f);
607     hidden_item = proto_tree_add_uint(pktc_tree, hf_pktc_version_major, tvb, offset, 1, (version>>4)&0x0f);
608     PROTO_ITEM_SET_HIDDEN(hidden_item);
609     hidden_item = proto_tree_add_uint(pktc_tree, hf_pktc_version_minor, tvb, offset, 1, (version)&0x0f);
610     PROTO_ITEM_SET_HIDDEN(hidden_item);
611     offset+=1;
612
613     /* fill COL_INFO */
614     if (check_col(pinfo->cinfo, COL_INFO)) {
615         col_add_str(pinfo->cinfo, COL_INFO,
616                     val_to_str(kmmid, kmmid_types, "Unknown KMMID %#x"));
617         col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)",
618                         val_to_str(doi, doi_types, "Unknown DOI %#x"));
619     }
620
621     switch(kmmid){
622     case KMMID_WAKEUP:
623         offset=dissect_pktc_wakeup(pktc_tree, tvb, offset);
624         break;
625     case KMMID_AP_REQUEST:
626         offset=dissect_pktc_ap_request(pinfo, pktc_tree, tvb, offset, doi);
627         break;
628     case KMMID_AP_REPLY:
629         offset=dissect_pktc_ap_reply(pinfo, pktc_tree, tvb, offset, doi);
630         break;
631     case KMMID_SEC_PARAM_REC:
632         offset=dissect_pktc_sec_param_rec(pktc_tree, tvb, offset);
633         break;
634     case KMMID_REKEY:
635         offset=dissect_pktc_rekey(pinfo, pktc_tree, tvb, offset, doi);
636         break;
637     case KMMID_ERROR_REPLY:
638         offset=dissect_pktc_error_reply(pinfo, pktc_tree, tvb, offset);
639         break;
640     };
641
642     proto_item_set_len(item, offset);
643 }
644
645 void
646 proto_register_pktc(void)
647 {
648     static hf_register_info hf[] = {
649         { &hf_pktc_kmmid, {
650             "Key Management Message ID", "pktc.kmmid", FT_UINT8, BASE_HEX,
651             VALS(kmmid_types), 0, NULL, HFILL }},
652         { &hf_pktc_doi, {
653             "Domain of Interpretation", "pktc.doi", FT_UINT8, BASE_DEC,
654             VALS(doi_types), 0, NULL, HFILL }},
655         { &hf_pktc_version_major, {
656             "Major version", "pktc.version.major", FT_UINT8, BASE_DEC,
657             NULL, 0, "Major version of PKTC", HFILL }},
658         { &hf_pktc_version_minor, {
659             "Minor version", "pktc.version.minor", FT_UINT8, BASE_DEC,
660             NULL, 0, "Minor version of PKTC", HFILL }},
661         { &hf_pktc_server_nonce, {
662             "Server Nonce", "pktc.server_nonce", FT_UINT32, BASE_HEX,
663             NULL, 0, "Server Nonce random number", HFILL }},
664         { &hf_pktc_server_principal, {
665             "Server Kerberos Principal Identifier", "pktc.server_principal", FT_STRING, BASE_NONE,
666             NULL, 0, NULL, HFILL }},
667         { &hf_pktc_timestamp, {
668             "Timestamp", "pktc.timestamp", FT_STRING, BASE_NONE,
669             NULL, 0, "Timestamp (UTC)", HFILL }},
670         { &hf_pktc_app_spec_data, {
671             "Application Specific Data", "pktc.asd", FT_NONE, BASE_NONE,
672             NULL, 0, "KMMID/DOI application specific data", HFILL }},
673         { &hf_pktc_list_of_ciphersuites, {
674             "List of Ciphersuites", "pktc.ciphers", FT_NONE, BASE_NONE,
675             NULL, 0, NULL, HFILL }},
676         { &hf_pktc_list_of_ciphersuites_len, {
677             "Number of Ciphersuites", "pktc.ciphers.len", FT_UINT8, BASE_DEC,
678             NULL, 0, NULL, HFILL }},
679         { &hf_pktc_snmpAuthenticationAlgorithm, {
680            "SNMPv3 Authentication Algorithm", "pktc.asd.snmp_auth_alg", FT_UINT8, BASE_HEX,
681            VALS(snmp_authentication_algorithm_vals), 0, NULL, HFILL }},
682         { &hf_pktc_snmpEncryptionTransformID, {
683            "SNMPv3 Encryption Transform ID", "pktc.asd.snmp_enc_alg", FT_UINT8, BASE_HEX,
684            VALS(snmp_transform_id_vals), 0, NULL, HFILL }},
685         { &hf_pktc_ipsecAuthenticationAlgorithm, {
686            "IPsec Authentication Algorithm", "pktc.asd.ipsec_auth_alg", FT_UINT8, BASE_HEX,
687            VALS(ipsec_authentication_algorithm_vals), 0, NULL, HFILL }},
688         { &hf_pktc_ipsecEncryptionTransformID, {
689            "IPsec Encryption Transform ID", "pktc.asd.ipsec_enc_alg", FT_UINT8, BASE_HEX,
690            VALS(ipsec_transform_id_vals), 0, NULL, HFILL }},
691         { &hf_pktc_snmpEngineID_len, {
692            "SNMPv3 Engine ID Length", "pktc.asd.snmp_engine_id.len", FT_UINT8, BASE_DEC,
693            NULL, 0, "Length of SNMPv3 Engine ID", HFILL }},
694         { &hf_pktc_snmpEngineID, {
695            "SNMPv3 Engine ID", "pktc.asd.snmp_engine_id", FT_BYTES, BASE_NONE,
696            NULL, 0, NULL, HFILL }},
697         { &hf_pktc_snmpEngineBoots, {
698            "SNMPv3 Engine Boots", "pktc.asd.snmp_engine_boots", FT_UINT32, BASE_DEC,
699            NULL, 0, NULL, HFILL }},
700         { &hf_pktc_snmpEngineTime, {
701            "SNMPv3 Engine Time", "pktc.asd.snmp_engine_time", FT_UINT32, BASE_DEC,
702            NULL, 0, "SNMPv3 Engine ID Time", HFILL }},
703         { &hf_pktc_usmUserName_len, {
704            "SNMPv3 USM User Name Length", "pktc.asd.snmp_usm_username.len", FT_UINT8, BASE_DEC,
705            NULL, 0, "Length of SNMPv3 USM User Name", HFILL }},
706         { &hf_pktc_usmUserName, {
707            "SNMPv3 USM User Name", "pktc.asd.snmp_usm_username", FT_STRING, BASE_NONE,
708            NULL, 0, NULL, HFILL }},
709         { &hf_pktc_ipsec_spi, {
710            "IPsec Security Parameter Index", "pktc.asd.ipsec_spi", FT_UINT32, BASE_HEX,
711            NULL, 0, "Security Parameter Index for inbound Security Association (IPsec)", HFILL }},
712         { &hf_pktc_reestablish_flag, {
713             "Re-establish Flag", "pktc.reestablish", FT_BOOLEAN, BASE_NONE,
714             NULL, 0x0, NULL, HFILL }},
715         { &hf_pktc_ack_required_flag, {
716             "ACK Required Flag", "pktc.ack_required", FT_BOOLEAN, BASE_NONE,
717             NULL, 0x0, NULL, HFILL }},
718         { &hf_pktc_sec_param_lifetime, {
719             "Security Parameter Lifetime", "pktc.spl", FT_UINT32, BASE_DEC,
720             NULL, 0, "Lifetime in seconds of security parameter", HFILL }},
721         { &hf_pktc_sha1_hmac, {
722            "SHA-1 HMAC", "pktc.sha1_hmac", FT_BYTES, BASE_NONE,
723            NULL, 0, NULL, HFILL }},
724         { &hf_pktc_grace_period, {
725             "Grace Period", "pktc.grace_period", FT_UINT32, BASE_DEC,
726             NULL, 0, "Grace Period in seconds", HFILL }},
727     };
728     static gint *ett[] = {
729         &ett_pktc,
730         &ett_pktc_app_spec_data,
731         &ett_pktc_list_of_ciphersuites,
732         &ett_pktc_engineid,
733     };
734
735     proto_pktc = proto_register_protocol("PacketCable", "PKTC", "pktc");
736     proto_register_field_array(proto_pktc, hf, array_length(hf));
737     proto_register_subtree_array(ett, array_length(ett));
738 }
739
740 void
741 proto_reg_handoff_pktc(void)
742 {
743     dissector_handle_t pktc_handle;
744
745     pktc_handle = create_dissector_handle(dissect_pktc, proto_pktc);
746     dissector_add("udp.port", PKTC_PORT, pktc_handle);
747 }
748
749
750 void
751 proto_register_pktc_mtafqdn(void)
752 {
753     static hf_register_info hf[] = {
754        { &hf_pktc_mtafqdn_msgtype, {
755            "Message Type", "pktc.mtafqdn.msgtype", FT_UINT8, BASE_DEC,
756            VALS(pktc_mtafqdn_msgtype_vals), 0, "MTA FQDN Message Type", HFILL }},
757        { &hf_pktc_mtafqdn_enterprise, {
758            "Enterprise Number", "pktc.mtafqdn.enterprise", FT_UINT32, BASE_DEC,
759            NULL, 0, NULL, HFILL }},
760        { &hf_pktc_mtafqdn_version, {
761            "Protocol Version", "pktc.mtafqdn.version", FT_UINT8, BASE_DEC,
762            NULL, 0, "MTA FQDN Protocol Version", HFILL }},
763        /* MTA FQDN REQ */
764        { &hf_pktc_mtafqdn_mac, {
765            "MTA MAC address", "pktc.mtafqdn.mac", FT_ETHER, BASE_NONE,
766            NULL, 0, NULL, HFILL }},
767        { &hf_pktc_mtafqdn_pub_key_hash, {
768            "MTA Public Key Hash", "pktc.mtafqdn.pub_key_hash", FT_BYTES, BASE_NONE,
769            NULL, 0, "MTA Public Key Hash (SHA-1)", HFILL }},
770        { &hf_pktc_mtafqdn_manu_cert_revoked, {
771            "Manufacturer Cert Revocation Time", "pktc.mtafqdn.manu_cert_revoked", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
772            NULL, 0, "Manufacturer Cert Revocation Time (UTC) or 0 if not revoked", HFILL }},
773        /* MTA FQDN REP */
774        { &hf_pktc_mtafqdn_fqdn, {
775            "MTA FQDN", "pktc.mtafqdn.fqdn", FT_STRING, BASE_NONE,
776            NULL, 0, NULL, HFILL }},
777        { &hf_pktc_mtafqdn_ip, {
778            "MTA IP Address", "pktc.mtafqdn.ip", FT_IPv4, BASE_NONE,
779            NULL, 0, "MTA IP Address (all zeros if not supplied)", HFILL }},
780     };
781     static gint *ett[] = {
782         &ett_pktc_mtafqdn,
783     };
784
785     proto_register_field_array(proto_pktc, hf, array_length(hf));
786     proto_register_subtree_array(ett, array_length(ett));
787 }
788
789 void
790 proto_reg_handoff_pktc_mtafqdn(void)
791 {
792     dissector_handle_t pktc_mtafqdn_handle;
793
794     pktc_mtafqdn_handle = create_dissector_handle(dissect_pktc_mtafqdn, proto_pktc);
795     dissector_add("udp.port", PKTC_MTAFQDN_PORT, pktc_mtafqdn_handle);
796 }