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