2 * Routines for the Internet Security Association and Key Management Protocol
4 * Brad Robel-Forrest <brad.robel-forrest@watchguard.com>
6 * $Id: packet-isakmp.c,v 1.26 2000/08/13 14:08:18 deniel Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 #include <netinet/in.h>
44 #ifdef NEED_SNPRINTF_H
45 # include "snprintf.h"
50 static int proto_isakmp = -1;
52 static gint ett_isakmp = -1;
53 static gint ett_isakmp_flags = -1;
54 static gint ett_isakmp_payload = -1;
56 #define UDP_PORT_ISAKMP 500
58 #define NUM_PROTO_TYPES 5
59 #define proto2str(t) \
60 ((t < NUM_PROTO_TYPES) ? prototypestr[t] : "UNKNOWN-PROTO-TYPE")
62 static const char *prototypestr[NUM_PROTO_TYPES] = {
70 #define NUM_P1_ATT_TYPES 17
71 #define p1_atttype2str(t) \
72 ((t < NUM_P1_ATT_TYPES) ? p1_atttypestr[t] : "UNKNOWN-ATTRIBUTE-TYPE")
74 static const char *p1_atttypestr[NUM_P1_ATT_TYPES] = {
75 "UNKNOWN-ATTRIBUTE-TYPE",
76 "Encryption-Algorithm",
78 "Authentication-Method",
82 "Group-Generator-One",
83 "Group-Generator-Two",
94 #define NUM_ATT_TYPES 10
95 #define atttype2str(t) \
96 ((t < NUM_ATT_TYPES) ? atttypestr[t] : "UNKNOWN-ATTRIBUTE-TYPE")
98 static const char *atttypestr[NUM_ATT_TYPES] = {
99 "UNKNOWN-ATTRIBUTE-TYPE",
103 "Encapsulation-Mode",
104 "Authentication-Algorithm",
107 "Compress-Dictinary-Size",
108 "Compress-Private-Algorithm"
111 #define NUM_TRANS_TYPES 2
112 #define trans2str(t) \
113 ((t < NUM_TRANS_TYPES) ? transtypestr[t] : "UNKNOWN-TRANS-TYPE")
115 static const char *transtypestr[NUM_TRANS_TYPES] = {
120 #define NUM_AH_TRANS_TYPES 5
121 #define ah_trans2str(t) \
122 ((t < NUM_AH_TRANS_TYPES) ? ah_transtypestr[t] : "UNKNOWN-AH-TRANS-TYPE")
124 static const char *ah_transtypestr[NUM_AH_TRANS_TYPES] = {
132 #define NUM_ESP_TRANS_TYPES 12
133 #define esp_trans2str(t) \
134 ((t < NUM_ESP_TRANS_TYPES) ? esp_transtypestr[t] : "UNKNOWN-ESP-TRANS-TYPE")
136 static const char *esp_transtypestr[NUM_ESP_TRANS_TYPES] = {
151 #define NUM_ID_TYPES 12
153 ((t < NUM_ID_TYPES) ? idtypestr[t] : "UNKNOWN-ID-TYPE")
155 static const char *idtypestr[NUM_ID_TYPES] = {
180 guint8 message_id[4];
192 struct proposal_hdr {
199 guint8 num_transforms;
206 guint8 transform_num;
211 #define TRANS_LEN(p) (pntohs(&((struct trans_hdr *)(p))->length))
292 guint8 identifier[2];
295 static void dissect_none(const u_char *, int, frame_data *, proto_tree *);
296 static void dissect_sa(const u_char *, int, frame_data *, proto_tree *);
297 static void dissect_proposal(const u_char *, int, frame_data *, proto_tree *);
298 static void dissect_transform(const u_char *, int, frame_data *, proto_tree *,
300 static void dissect_key_exch(const u_char *, int, frame_data *, proto_tree *);
301 static void dissect_id(const u_char *, int, frame_data *, proto_tree *);
302 static void dissect_cert(const u_char *, int, frame_data *, proto_tree *);
303 static void dissect_certreq(const u_char *, int, frame_data *, proto_tree *);
304 static void dissect_hash(const u_char *, int, frame_data *, proto_tree *);
305 static void dissect_sig(const u_char *, int, frame_data *, proto_tree *);
306 static void dissect_nonce(const u_char *, int, frame_data *, proto_tree *);
307 static void dissect_notif(const u_char *, int, frame_data *, proto_tree *);
308 static void dissect_delete(const u_char *, int, frame_data *, proto_tree *);
309 static void dissect_vid(const u_char *, int, frame_data *, proto_tree *);
310 static void dissect_config(const u_char *, int, frame_data *, proto_tree *);
312 static const char *payloadtype2str(guint8);
313 static const char *exchtype2str(guint8);
314 static const char *doitype2str(guint32);
315 static const char *msgtype2str(guint16);
316 static const char *situation2str(guint32);
317 static const char *value2str(int, guint16, guint16);
318 static const char *num2str(const guint8 *, guint16);
319 static const char *attrtype2str(guint8);
320 static const char *cfgattrident2str(guint16);
322 #define NUM_LOAD_TYPES 15
323 #define loadtype2str(t) \
324 ((t < NUM_LOAD_TYPES) ? strfuncs[t].str : "Unknown payload type")
325 #define LOAD_TYPE_TRANSFORM 3
327 static struct strfunc {
329 void (*func)(const u_char *, int, frame_data *, proto_tree *);
330 } strfuncs[NUM_LOAD_TYPES] = {
331 {"NONE", dissect_none },
332 {"Security Association", dissect_sa },
333 {"Proposal", dissect_proposal },
334 {"Transform", NULL },
335 {"Key Exchange", dissect_key_exch },
336 {"Identification", dissect_id },
337 {"Certificate", dissect_cert },
338 {"Certificate Request", dissect_certreq },
339 {"Hash", dissect_hash },
340 {"Signature", dissect_sig },
341 {"Nonce", dissect_nonce },
342 {"Notification", dissect_notif },
343 {"Delete", dissect_delete },
344 {"Vendor ID", dissect_vid },
345 {"Attrib", dissect_config }
349 dissect_isakmp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
351 struct isakmp_hdr * hdr = (struct isakmp_hdr *)(pd + offset);
354 OLD_CHECK_DISPLAY_AS_DATA(proto_isakmp, pd, offset, fd, tree);
356 if (check_col(fd, COL_PROTOCOL))
357 col_add_str(fd, COL_PROTOCOL, "ISAKMP");
359 len = pntohl(&hdr->length);
361 if (check_col(fd, COL_INFO))
362 col_add_fstr(fd, COL_INFO, "%s", exchtype2str(hdr->exch_type));
364 if (IS_DATA_IN_FRAME(offset) && tree) {
366 proto_tree * isakmp_tree;
368 ti = proto_tree_add_item(tree, proto_isakmp, NullTVB, offset, len, FALSE);
369 isakmp_tree = proto_item_add_subtree(ti, ett_isakmp);
371 proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->icookie),
373 offset += sizeof(hdr->icookie);
375 proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->rcookie),
377 offset += sizeof(hdr->rcookie);
379 proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->next_payload),
380 "Next payload: %s (%u)",
381 payloadtype2str(hdr->next_payload), hdr->next_payload);
382 offset += sizeof(hdr->next_payload);
384 proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->version),
386 hi_nibble(hdr->version), lo_nibble(hdr->version));
387 offset += sizeof(hdr->version);
389 proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->exch_type),
390 "Exchange type: %s (%u)",
391 exchtype2str(hdr->exch_type), hdr->exch_type);
392 offset += sizeof(hdr->exch_type);
398 fti = proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->flags), "Flags");
399 ftree = proto_item_add_subtree(fti, ett_isakmp_flags);
401 proto_tree_add_text(ftree, NullTVB, offset, 1, "%s",
402 decode_boolean_bitfield(hdr->flags, E_FLAG, sizeof(hdr->flags)*8,
403 "Encryption", "No encryption"));
404 proto_tree_add_text(ftree, NullTVB, offset, 1, "%s",
405 decode_boolean_bitfield(hdr->flags, C_FLAG, sizeof(hdr->flags)*8,
406 "Commit", "No commit"));
407 proto_tree_add_text(ftree, NullTVB, offset, 1, "%s",
408 decode_boolean_bitfield(hdr->flags, A_FLAG, sizeof(hdr->flags)*8,
409 "Authentication", "No authentication"));
410 offset += sizeof(hdr->flags);
413 proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->message_id), "Message ID");
414 offset += sizeof(hdr->message_id);
416 proto_tree_add_text(isakmp_tree, NullTVB, offset, sizeof(hdr->length),
418 offset += sizeof(hdr->length);
420 if (hdr->flags & E_FLAG) {
421 if (IS_DATA_IN_FRAME(offset) && isakmp_tree) {
422 proto_tree_add_text(isakmp_tree, NullTVB, offset, END_OF_FRAME,
423 "Encrypted payload (%d byte%s)",
424 END_OF_FRAME, plurality(END_OF_FRAME, "", "s"));
427 if (hdr->next_payload < NUM_LOAD_TYPES) {
428 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
429 dissect_transform(pd, offset, fd, isakmp_tree, 0); /* XXX - protocol ID? */
431 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, isakmp_tree);
434 old_dissect_data(pd, offset, fd, isakmp_tree);
440 dissect_none(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
444 dissect_sa(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
446 struct sa_hdr * hdr = (struct sa_hdr *)(pd + offset);
447 guint16 length = pntohs(&hdr->length);
448 guint32 doi = pntohl(&hdr->doi);
449 guint32 situation = pntohl(&hdr->situation);
450 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Security Association payload");
453 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
455 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
456 "Next payload: %s (%u)",
457 payloadtype2str(hdr->next_payload), hdr->next_payload);
458 offset += sizeof(hdr->next_payload) * 2;
460 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
461 "Length: %u", length);
462 offset += sizeof(length);
464 proto_tree_add_text(ntree, NullTVB, offset, sizeof(doi),
465 "Domain of interpretation: %s (%u)",
466 doitype2str(doi), doi);
467 offset += sizeof(doi);
469 proto_tree_add_text(ntree, NullTVB, offset, sizeof(situation),
470 "Situation: %s (%u)",
471 situation2str(situation), situation);
472 offset += sizeof(situation);
474 dissect_proposal(pd, offset, fd, ntree);
475 offset += (length - sizeof(*hdr));
477 if (hdr->next_payload < NUM_LOAD_TYPES) {
478 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
479 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
481 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
484 old_dissect_data(pd, offset, fd, tree);
488 dissect_proposal(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
490 struct proposal_hdr * hdr = (struct proposal_hdr *)(pd + offset);
491 guint16 length = pntohs(&hdr->length);
492 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Proposal payload");
495 int next_hdr_offset = offset + length;
497 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
499 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
500 "Next payload: %s (%u)",
501 payloadtype2str(hdr->next_payload), hdr->next_payload);
502 offset += sizeof(hdr->next_payload) * 2;
504 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
505 "Length: %u", length);
506 offset += sizeof(length);
508 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->proposal_num),
509 "Proposal number: %u", hdr->proposal_num);
510 offset += sizeof(hdr->proposal_num);
512 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
513 "Protocol ID: %s (%u)",
514 proto2str(hdr->protocol_id), hdr->protocol_id);
515 offset += sizeof(hdr->protocol_id);
517 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->spi_size),
518 "SPI size: %u", hdr->spi_size);
519 offset += sizeof(hdr->spi_size);
521 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->num_transforms),
522 "Number of transforms: %u", hdr->num_transforms);
523 offset += sizeof(hdr->num_transforms);
526 proto_tree_add_text(ntree, NullTVB, offset, hdr->spi_size, "SPI");
527 offset += hdr->spi_size;
530 if (hdr->num_transforms > 0)
531 dissect_transform(pd, offset, fd, ntree, hdr->protocol_id);
533 if (hdr->next_payload < NUM_LOAD_TYPES) {
534 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
535 dissect_transform(pd, next_hdr_offset, fd, tree, 0); /* XXX - protocol ID? */
537 (*strfuncs[hdr->next_payload].func)(pd, next_hdr_offset, fd, tree);
540 old_dissect_data(pd, next_hdr_offset, fd, tree);
544 dissect_transform(const u_char *pd, int offset, frame_data *fd,
545 proto_tree *tree, guint8 protocol_id)
548 struct trans_hdr * hdr = (struct trans_hdr *)(pd + offset);
549 guint16 length = pntohs(&hdr->length);
550 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Transform payload");
553 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
555 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
556 "Next payload: %s (%u)",
557 payloadtype2str(hdr->next_payload), hdr->next_payload);
558 offset += sizeof(hdr->next_payload) * 2;
560 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
561 "Length: %u", length);
562 offset += sizeof(length);
564 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->transform_num),
565 "Transform number: %u", hdr->transform_num);
566 offset += sizeof(hdr->transform_num);
568 switch (protocol_id) {
571 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->transform_id),
572 "Transform ID: %s (%u)",
573 trans2str(hdr->transform_id), hdr->transform_id);
576 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->transform_id),
577 "Transform ID: %s (%u)",
578 ah_trans2str(hdr->transform_id), hdr->transform_id);
581 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->transform_id),
582 "Transform ID: %s (%u)",
583 esp_trans2str(hdr->transform_id), hdr->transform_id);
586 offset += sizeof(hdr->transform_id) + sizeof(hdr->reserved2);
588 length -= sizeof(*hdr);
590 const char *str = NULL;
592 guint16 type = pntohs(pd + offset) & 0x7fff;
593 guint16 val_len = pntohs(pd + offset + 2);
595 if (protocol_id == 1 && hdr->transform_id == 1) {
597 str = p1_atttype2str(type);
600 str = atttype2str(type);
603 if (pd[offset] & 0x80) {
604 proto_tree_add_text(ntree, NullTVB, offset, 4,
607 value2str(ike_phase1, type, val_len), val_len);
612 guint16 pack_len = 4 + val_len;
614 proto_tree_add_text(ntree, NullTVB, offset, pack_len,
617 num2str(pd + offset + 4, val_len));
623 if (hdr->next_payload < NUM_LOAD_TYPES) {
624 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
625 dissect_transform(pd, offset, fd, tree, protocol_id);
627 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
630 old_dissect_data(pd, offset, fd, tree);
634 dissect_key_exch(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
636 struct ke_hdr * hdr = (struct ke_hdr *)(pd + offset);
637 guint16 length = pntohs(&hdr->length);
638 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Key Exchange payload");
641 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
643 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
644 "Next payload: %s (%u)",
645 payloadtype2str(hdr->next_payload), hdr->next_payload);
646 offset += sizeof(hdr->next_payload) * 2;
648 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
649 "Length: %u", length);
650 offset += sizeof(length);
652 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Key Exchange Data");
653 offset += (length - sizeof(*hdr));
655 if (hdr->next_payload < NUM_LOAD_TYPES) {
656 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
657 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
659 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
662 old_dissect_data(pd, offset, fd, tree);
666 dissect_id(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
668 struct id_hdr * hdr = (struct id_hdr *)(pd + offset);
669 guint16 length = pntohs(&hdr->length);
670 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Identification payload");
673 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
675 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
676 "Next payload: %s (%u)",
677 payloadtype2str(hdr->next_payload), hdr->next_payload);
678 offset += sizeof(hdr->next_payload) * 2;
680 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
681 "Length: %u", length);
682 offset += sizeof(length);
684 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->id_type),
685 "ID type: %s (%u)", id2str(hdr->id_type), hdr->id_type);
686 offset += sizeof(hdr->id_type);
688 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
689 "Protocol ID: %u", hdr->protocol_id);
690 offset += sizeof(hdr->protocol_id);
692 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->port),
693 "Port: %u", pntohs(&hdr->port));
694 offset += sizeof(hdr->port);
696 switch (hdr->id_type) {
699 proto_tree_add_text(ntree, NullTVB, offset, length-sizeof(*hdr),
700 "Identification data: %s", ip_to_str(pd+offset));
704 proto_tree_add_text(ntree, NullTVB, offset, length-sizeof(*hdr),
705 "Identification data: %s", (char *)(pd+offset));
708 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Identification Data");
710 offset += (length - sizeof(*hdr));
712 if (hdr->next_payload < NUM_LOAD_TYPES) {
713 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
714 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
716 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
719 old_dissect_data(pd, offset, fd, tree);
723 dissect_cert(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
725 struct cert_hdr * hdr = (struct cert_hdr *)(pd + offset);
726 guint16 length = pntohs(&hdr->length);
727 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Certificate payload");
730 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
732 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
733 "Next payload: %s (%u)",
734 payloadtype2str(hdr->next_payload), hdr->next_payload);
735 offset += sizeof(hdr->next_payload) * 2;
737 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
738 "Length: %u", length);
739 offset += sizeof(length);
741 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->cert_enc),
742 "Certificate encoding: %u", hdr->cert_enc);
743 offset += sizeof(hdr->cert_enc);
745 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Certificate Data");
746 offset += (length - sizeof(*hdr));
748 if (hdr->next_payload < NUM_LOAD_TYPES) {
749 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
750 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
752 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
755 old_dissect_data(pd, offset, fd, tree);
759 dissect_certreq(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
761 struct certreq_hdr * hdr = (struct certreq_hdr *)(pd + offset);
762 guint16 length = pntohs(&hdr->length);
763 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Certificate Request payload");
766 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
768 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
769 "Next payload: %s (%u)",
770 payloadtype2str(hdr->next_payload), hdr->next_payload);
771 offset += sizeof(hdr->next_payload) * 2;
773 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
774 "Length: %u", length);
775 offset += sizeof(length);
777 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->cert_type),
778 "Certificate type: %u", hdr->cert_type);
779 offset += sizeof(hdr->cert_type);
781 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Certificate Authority");
782 offset += (length - sizeof(*hdr));
784 if (hdr->next_payload < NUM_LOAD_TYPES) {
785 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
786 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
788 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
791 old_dissect_data(pd, offset, fd, tree);
795 dissect_hash(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
797 struct hash_hdr * hdr = (struct hash_hdr *)(pd + offset);
798 guint16 length = pntohs(&hdr->length);
799 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Hash payload");
802 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
804 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
805 "Next payload: %s (%u)",
806 payloadtype2str(hdr->next_payload), hdr->next_payload);
807 offset += sizeof(hdr->next_payload) * 2;
809 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
810 "Length: %u", length);
811 offset += sizeof(length);
813 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Hash Data");
814 offset += (length - sizeof(*hdr));
816 if (hdr->next_payload < NUM_LOAD_TYPES) {
817 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
818 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
820 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
823 old_dissect_data(pd, offset, fd, tree);
827 dissect_sig(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
829 struct sig_hdr * hdr = (struct sig_hdr *)(pd + offset);
830 guint16 length = pntohs(&hdr->length);
831 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Signature payload");
834 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
836 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
837 "Next payload: %s (%u)",
838 payloadtype2str(hdr->next_payload), hdr->next_payload);
839 offset += sizeof(hdr->next_payload) * 2;
841 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
842 "Length: %u", length);
843 offset += sizeof(length);
845 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Signature Data");
846 offset += (length - sizeof(*hdr));
848 if (hdr->next_payload < NUM_LOAD_TYPES) {
849 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
850 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
852 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
855 old_dissect_data(pd, offset, fd, tree);
859 dissect_nonce(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
861 struct nonce_hdr * hdr = (struct nonce_hdr *)(pd + offset);
862 guint16 length = pntohs(&hdr->length);
863 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Nonce payload");
866 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
868 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
869 "Next payload: %s (%u)",
870 payloadtype2str(hdr->next_payload), hdr->next_payload);
871 offset += sizeof(hdr->next_payload) * 2;
873 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
874 "Length: %u", length);
875 offset += sizeof(length);
877 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Nonce Data");
878 offset += (length - sizeof(*hdr));
880 if (hdr->next_payload < NUM_LOAD_TYPES) {
881 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
882 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
884 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
887 old_dissect_data(pd, offset, fd, tree);
891 dissect_notif(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
893 struct notif_hdr * hdr = (struct notif_hdr *)(pd + offset);
894 guint16 length = pntohs(&hdr->length);
895 guint32 doi = pntohl(&hdr->doi);
896 guint16 msgtype = pntohs(&hdr->msgtype);
897 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Notification payload");
900 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
902 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
903 "Next payload: %s (%u)",
904 payloadtype2str(hdr->next_payload), hdr->next_payload);
905 offset += sizeof(hdr->next_payload) * 2;
907 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
908 "Length: %u", length);
909 offset += sizeof(length);
911 proto_tree_add_text(ntree, NullTVB, offset, sizeof(doi),
912 "Domain of Interpretation: %s (%u)", doitype2str(doi), doi);
913 offset += sizeof(doi);
915 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
916 "Protocol ID: %s (%u)",
917 proto2str(hdr->protocol_id), hdr->protocol_id);
918 offset += sizeof(hdr->protocol_id);
920 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->spi_size),
921 "SPI size: %u", hdr->spi_size);
922 offset += sizeof(hdr->spi_size);
924 proto_tree_add_text(ntree, NullTVB, offset, sizeof(msgtype),
925 "Message type: %s (%u)", msgtype2str(msgtype), msgtype);
926 offset += sizeof(msgtype);
929 proto_tree_add_text(ntree, NullTVB, offset, hdr->spi_size, "Security Parameter Index");
930 offset += hdr->spi_size;
933 if (length - sizeof(*hdr)) {
934 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr) - hdr->spi_size,
935 "Notification Data");
936 offset += (length - sizeof(*hdr) - hdr->spi_size);
939 if (hdr->next_payload < NUM_LOAD_TYPES) {
940 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
941 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
943 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
946 old_dissect_data(pd, offset, fd, tree);
950 dissect_delete(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
952 struct delete_hdr * hdr = (struct delete_hdr *)(pd + offset);
953 guint16 length = pntohs(&hdr->length);
954 guint32 doi = pntohl(&hdr->doi);
955 guint16 num_spis = pntohs(&hdr->num_spis);
956 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Delete payload");
960 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
962 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
963 "Next payload: %s (%u)",
964 payloadtype2str(hdr->next_payload), hdr->next_payload);
965 offset += sizeof(hdr->next_payload) * 2;
967 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
968 "Length: %u", length);
969 offset += sizeof(length);
971 proto_tree_add_text(ntree, NullTVB, offset, sizeof(doi),
972 "Domain of Interpretation: %s (%u)", doitype2str(doi), doi);
973 offset += sizeof(doi);
975 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
976 "Protocol ID: %s (%u)",
977 proto2str(hdr->protocol_id), hdr->protocol_id);
978 offset += sizeof(hdr->protocol_id);
980 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->spi_size),
981 "SPI size: %u", hdr->spi_size);
982 offset += sizeof(hdr->spi_size);
984 proto_tree_add_text(ntree, NullTVB, offset, num_spis,
985 "Number of SPIs: %u", num_spis);
986 offset += sizeof(hdr->num_spis);
988 for (i = 0; i < num_spis; ++i) {
989 proto_tree_add_text(ntree, NullTVB, offset, hdr->spi_size,
991 offset += hdr->spi_size;
994 if (hdr->next_payload < NUM_LOAD_TYPES) {
995 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
996 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
998 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
1001 old_dissect_data(pd, offset, fd, tree);
1005 dissect_vid(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
1007 struct vid_hdr * hdr = (struct vid_hdr *)(pd + offset);
1008 guint16 length = pntohs(&hdr->length);
1009 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Vendor ID payload");
1012 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
1014 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
1015 "Next payload: %s (%u)",
1016 payloadtype2str(hdr->next_payload), hdr->next_payload);
1017 offset += sizeof(hdr->next_payload) * 2;
1019 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
1020 "Length: %u", length);
1021 offset += sizeof(length);
1023 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Vendor ID");
1024 offset += (length - sizeof(*hdr));
1026 if (hdr->next_payload < NUM_LOAD_TYPES) {
1027 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
1028 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
1030 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
1033 old_dissect_data(pd, offset, fd, tree);
1037 dissect_config(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
1039 struct cfg_hdr * hdr = (struct cfg_hdr *)(pd + offset);
1040 guint16 length = pntohs(&hdr->length);
1041 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Attribute payload");
1044 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
1046 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
1047 "Next payload: %s (%u)",
1048 payloadtype2str(hdr->next_payload), hdr->next_payload);
1049 offset += sizeof(hdr->next_payload) *2;
1051 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
1052 "Length: %u", length);
1053 offset += sizeof(length);
1055 proto_tree_add_text(ntree,NullTVB, offset, sizeof(hdr->type),
1056 "Type %s (%u)",attrtype2str(hdr->type),hdr->type);
1058 offset += (sizeof(hdr->type) + sizeof(hdr->reserved2));
1060 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->identifier),
1061 "Identifier: %u", pntohs(&hdr->identifier));
1062 offset += sizeof(hdr->identifier);
1063 length -= sizeof(*hdr);
1066 guint16 type = pntohs(pd + offset) & 0x7fff;
1067 guint16 val_len = pntohs(pd + offset + 2);
1069 if(pd[offset] & 0x80) {
1070 proto_tree_add_text(ntree, NullTVB, offset, 4,
1071 "%s (%u)",cfgattrident2str(type),val_len);
1076 guint pack_len = 4 + val_len;
1078 proto_tree_add_text(ntree, NullTVB, offset, 4,
1079 "%s (%se)", cfgattrident2str(type), num2str(pd + offset + 4, val_len));
1085 if (hdr->next_payload < NUM_LOAD_TYPES) {
1086 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
1087 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
1089 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
1092 old_dissect_data(pd, offset, fd, tree);
1097 payloadtype2str(guint8 type) {
1099 if (type < NUM_LOAD_TYPES) return strfuncs[type].str;
1100 if (type < 128) return "RESERVED";
1101 if (type < 256) return "Private USE";
1103 return "Huh? You should never see this! Shame on you!";
1107 exchtype2str(guint8 type) {
1109 #define NUM_EXCHSTRS 7
1110 static const char * exchstrs[NUM_EXCHSTRS] = {
1113 "Identity Protection (Main Mode)",
1114 "Authentication Only",
1117 "Transaction (Config Mode)"
1120 if (type < NUM_EXCHSTRS) return exchstrs[type];
1121 if (type < 32) return "ISAKMP Future Use";
1124 return "Quick Mode";
1126 return "New Group Mode";
1128 if (type < 240) return "DOI Specific Use";
1129 if (type < 256) return "Private Use";
1131 return "Huh? You should never see this! Shame on you!";
1135 doitype2str(guint32 type) {
1136 if (type == 1) return "IPSEC";
1137 return "Unknown DOI Type";
1141 msgtype2str(guint16 type) {
1143 #define NUM_PREDEFINED 31
1144 static const char *msgs[NUM_PREDEFINED] = {
1146 "INVALID-PAYLOAD-TYPE",
1147 "DOI-NOT-SUPPORTED",
1148 "SITUATION-NOT-SUPPORTED",
1150 "INVALID-MAJOR-VERSION",
1151 "INVALID-MINOR-VERSION",
1152 "INVALID-EXCHANGE-TYPE",
1154 "INVALID-MESSAGE-ID",
1155 "INVALID-PROTOCOL-ID",
1157 "INVALID-TRANSFORM-ID",
1158 "ATTRIBUTES-NOT-SUPPORTED",
1159 "NO-PROPOSAL-CHOSEN",
1160 "BAD-PROPOSAL-SYNTAX",
1161 "PAYLOAD-MALFORMED",
1162 "INVALID-KEY-INFORMATION",
1163 "INVALID-ID-INFORMATION",
1164 "INVALID-CERT-ENCODING",
1165 "INVALID-CERTIFICATE",
1166 "CERT-TYPE-UNSUPPORTED",
1167 "INVALID-CERT-AUTHORITY",
1168 "INVALID-HASH-INFORMATION",
1169 "AUTHENTICATION-FAILED",
1170 "INVALID-SIGNATURE",
1171 "ADDRESS-NOTIFICATION",
1172 "NOTIFY-SA-LIFETIME",
1173 "CERTIFICATE-UNAVAILABLE",
1174 "UNSUPPORTED-EXCHANGE-TYPE",
1175 "UNEQUAL-PAYLOAD-LENGTHS"
1178 if (type < NUM_PREDEFINED) return msgs[type];
1179 if (type < 8192) return "RESERVED (Future Use)";
1180 if (type < 16384) return "Private Use";
1181 if (type < 16385) return "CONNECTED";
1182 if (type < 24576) return "RESERVED (Future Use) - status";
1183 if (type < 24577) return "RESPONDER-LIFETIME";
1184 if (type < 24578) return "REPLAY-STATUS";
1185 if (type < 24579) return "INITIAL-CONTACT";
1186 if (type < 32768) return "DOI-specific codes";
1187 if (type < 40960) return "Private Use - status";
1188 if (type < 65535) return "RESERVED (Future Use) - status (2)";
1190 return "Huh? You should never see this! Shame on you!";
1194 situation2str(guint32 type) {
1196 #define SIT_MSG_NUM 1024
1197 #define SIT_IDENTITY 0x01
1198 #define SIT_SECRECY 0x02
1199 #define SIT_INTEGRITY 0x04
1201 static char msg[SIT_MSG_NUM];
1205 if (type & SIT_IDENTITY) {
1206 n += snprintf(msg, SIT_MSG_NUM-n, "%sIDENTITY", sep);
1209 if (type & SIT_SECRECY) {
1210 n += snprintf(msg, SIT_MSG_NUM-n, "%sSECRECY", sep);
1213 if (type & SIT_INTEGRITY) {
1214 n += snprintf(msg, SIT_MSG_NUM-n, "%sINTEGRITY", sep);
1222 value2str(int ike_p1, guint16 att_type, guint16 value) {
1224 if (value == 0) return "RESERVED";
1230 case 1: return "Seconds";
1231 case 2: return "Kilobytes";
1232 default: return "UNKNOWN-SA-VALUE";
1235 return "Duration-Value";
1237 return "Group-Value";
1240 case 1: return "Tunnel";
1241 case 2: return "Transport";
1242 default: return "UNKNOWN-ENCAPSULATION-VALUE";
1246 case 1: return "HMAC-MD5";
1247 case 2: return "HMAC-SHA";
1248 case 3: return "DES-MAC";
1249 case 4: return "KPDK";
1250 default: return "UNKNOWN-AUTHENTICATION-VALUE";
1253 return "Key-Length";
1255 return "Key-Rounds";
1258 default: return "UNKNOWN-ATTRIBUTE-TYPE";
1265 case 1: return "DES-CBC";
1266 case 2: return "IDEA-CBC";
1267 case 3: return "BLOWFISH-CBC";
1268 case 4: return "RC5-R16-B64-CBC";
1269 case 5: return "3DES-CBC";
1270 case 6: return "CAST-CBC";
1271 default: return "UNKNOWN-ENCRYPTION-ALG";
1275 case 1: return "MD5";
1276 case 2: return "SHA";
1277 case 3: return "TIGER";
1278 default: return "UNKNOWN-HASH-ALG";
1282 case 1: return "PSK";
1283 case 2: return "DSS-SIG";
1284 case 3: return "RSA-SIG";
1285 case 4: return "RSA-ENC";
1286 case 5: return "RSA-Revised-ENC";
1287 case 64221: return "HybridInitRSA";
1288 case 64222: return "HybridRespRSA";
1289 case 64223: return "HybridInitDSS";
1290 case 64224: return "HybridRespDSS";
1291 case 65001: return "XAUTHInitPreShared";
1292 case 65002: return "XAUTHRespPreShared";
1293 case 65003: return "XAUTHInitDSS";
1294 case 65004: return "XAUTHRespDSS";
1295 case 65005: return "XAUTHInitRSA";
1296 case 65006: return "XAUTHRespRSA";
1297 case 65007: return "XAUTHInitRSAEncryption";
1298 case 65008: return "XAUTHRespRSAEncryption";
1299 case 65009: return "XAUTHInitRSARevisedEncryption";
1300 case 65010: return "XAUTHRespRSARevisedEncryption";
1301 default: return "UNKNOWN-AUTH-METHOD";
1310 return "Group-Value";
1313 case 1: return "MODP";
1314 case 2: return "ECP";
1315 case 3: return "EC2N";
1316 default: return "UNKNOWN-GROUPT-TYPE";
1320 case 1: return "Seconds";
1321 case 2: return "Kilobytes";
1322 default: return "UNKNOWN-SA-VALUE";
1325 return "Duration-Value";
1329 return "Key-Length";
1331 return "Field-Size";
1332 default: return "UNKNOWN-ATTRIBUTE-TYPE";
1338 attrtype2str(guint8 type) {
1340 case 0: return "Reserved";
1341 case 1: return "ISAKMP_CFG_REQUEST";
1342 case 2: return "ISAKMP_CFG_REPLY";
1343 case 3: return "ISAKMP_CFG_SET";
1344 case 4: return "ISAKMP_CFG_ACK";
1347 return "Future use";
1348 return "Private use";
1352 cfgattrident2str(guint16 ident) {
1353 #define NUM_ATTR_DEFINED 12
1354 static const char *msgs[NUM_PREDEFINED] = {
1356 "INTERNAL_IP4_ADDRESS",
1357 "INTERNAL_IP4_NETMASK",
1359 "INTERNAL_IP4_NBNS",
1360 "INTERNAL_ADDRESS_EXPIREY",
1361 "INTERNAL_IP4_DHCP",
1362 "APPLICATION_VERSION"
1363 "INTERNAL_IP6_ADDRESS",
1364 "INTERNAL_IP6_NETMASK",
1366 "INTERNAL_IP6_NBNS",
1367 "INTERNAL_IP6_DHCP",
1369 if(ident < NUM_ATTR_DEFINED)
1372 return "Future use";
1374 case 16520: return "XAUTH_TYPE";
1375 case 16521: return "XAUTH_USER_NAME";
1376 case 16522: return "XAUTH_USER_PASSWORD";
1377 case 16523: return "XAUTH_PASSCODE";
1378 case 16524: return "XAUTH_MESSAGE";
1379 case 16525: return "XAUTH_CHALLANGE";
1380 case 16526: return "XAUTH_DOMAIN";
1381 case 16527: return "XAUTH_STATUS";
1382 default: return "Private use";
1387 num2str(const guint8 *pd, guint16 len) {
1389 #define NUMSTR_LEN 1024
1390 static char numstr[NUMSTR_LEN];
1394 snprintf(numstr, NUMSTR_LEN, "%u", *pd);
1397 snprintf(numstr, NUMSTR_LEN, "%u", pntohs(pd));
1400 snprintf(numstr, NUMSTR_LEN, "%u", pntohl(pd) & 0x0fff);
1403 snprintf(numstr, NUMSTR_LEN, "%u", pntohl(pd));
1406 snprintf(numstr, NUMSTR_LEN, "<too big>");
1413 proto_register_isakmp(void)
1415 /* static hf_register_info hf[] = {
1417 { "Name", "isakmp.abbreviation", TYPE, VALS_POINTER }},
1419 static gint *ett[] = {
1422 &ett_isakmp_payload,
1425 proto_isakmp = proto_register_protocol("Internet Security Association and Key Management Protocol", "isakmp");
1426 /* proto_register_field_array(proto_isakmp, hf, array_length(hf));*/
1427 proto_register_subtree_array(ett, array_length(ett));
1431 proto_reg_handoff_isakmp(void)
1433 old_dissector_add("udp.port", UDP_PORT_ISAKMP, dissect_isakmp);