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.27 2000/10/02 18:38:50 gram 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));
621 if (!IS_DATA_IN_FRAME(offset)) {
622 proto_tree_add_text(ntree, NullTVB, 0, 0,
623 "Bad Offset: %u", offset);
628 if (hdr->next_payload < NUM_LOAD_TYPES) {
629 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
630 dissect_transform(pd, offset, fd, tree, protocol_id);
632 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
635 old_dissect_data(pd, offset, fd, tree);
639 dissect_key_exch(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
641 struct ke_hdr * hdr = (struct ke_hdr *)(pd + offset);
642 guint16 length = pntohs(&hdr->length);
643 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Key Exchange payload");
646 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
648 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
649 "Next payload: %s (%u)",
650 payloadtype2str(hdr->next_payload), hdr->next_payload);
651 offset += sizeof(hdr->next_payload) * 2;
653 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
654 "Length: %u", length);
655 offset += sizeof(length);
657 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Key Exchange Data");
658 offset += (length - sizeof(*hdr));
660 if (hdr->next_payload < NUM_LOAD_TYPES) {
661 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
662 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
664 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
667 old_dissect_data(pd, offset, fd, tree);
671 dissect_id(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
673 struct id_hdr * hdr = (struct id_hdr *)(pd + offset);
674 guint16 length = pntohs(&hdr->length);
675 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Identification payload");
678 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
680 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
681 "Next payload: %s (%u)",
682 payloadtype2str(hdr->next_payload), hdr->next_payload);
683 offset += sizeof(hdr->next_payload) * 2;
685 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
686 "Length: %u", length);
687 offset += sizeof(length);
689 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->id_type),
690 "ID type: %s (%u)", id2str(hdr->id_type), hdr->id_type);
691 offset += sizeof(hdr->id_type);
693 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
694 "Protocol ID: %u", hdr->protocol_id);
695 offset += sizeof(hdr->protocol_id);
697 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->port),
698 "Port: %u", pntohs(&hdr->port));
699 offset += sizeof(hdr->port);
701 switch (hdr->id_type) {
704 proto_tree_add_text(ntree, NullTVB, offset, length-sizeof(*hdr),
705 "Identification data: %s", ip_to_str(pd+offset));
709 proto_tree_add_text(ntree, NullTVB, offset, length-sizeof(*hdr),
710 "Identification data: %s", (char *)(pd+offset));
713 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Identification Data");
715 offset += (length - sizeof(*hdr));
717 if (hdr->next_payload < NUM_LOAD_TYPES) {
718 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
719 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
721 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
724 old_dissect_data(pd, offset, fd, tree);
728 dissect_cert(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
730 struct cert_hdr * hdr = (struct cert_hdr *)(pd + offset);
731 guint16 length = pntohs(&hdr->length);
732 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Certificate payload");
735 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
737 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
738 "Next payload: %s (%u)",
739 payloadtype2str(hdr->next_payload), hdr->next_payload);
740 offset += sizeof(hdr->next_payload) * 2;
742 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
743 "Length: %u", length);
744 offset += sizeof(length);
746 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->cert_enc),
747 "Certificate encoding: %u", hdr->cert_enc);
748 offset += sizeof(hdr->cert_enc);
750 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Certificate Data");
751 offset += (length - sizeof(*hdr));
753 if (hdr->next_payload < NUM_LOAD_TYPES) {
754 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
755 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
757 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
760 old_dissect_data(pd, offset, fd, tree);
764 dissect_certreq(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
766 struct certreq_hdr * hdr = (struct certreq_hdr *)(pd + offset);
767 guint16 length = pntohs(&hdr->length);
768 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Certificate Request payload");
771 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
773 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
774 "Next payload: %s (%u)",
775 payloadtype2str(hdr->next_payload), hdr->next_payload);
776 offset += sizeof(hdr->next_payload) * 2;
778 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
779 "Length: %u", length);
780 offset += sizeof(length);
782 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->cert_type),
783 "Certificate type: %u", hdr->cert_type);
784 offset += sizeof(hdr->cert_type);
786 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Certificate Authority");
787 offset += (length - sizeof(*hdr));
789 if (hdr->next_payload < NUM_LOAD_TYPES) {
790 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
791 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
793 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
796 old_dissect_data(pd, offset, fd, tree);
800 dissect_hash(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
802 struct hash_hdr * hdr = (struct hash_hdr *)(pd + offset);
803 guint16 length = pntohs(&hdr->length);
804 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Hash payload");
807 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
809 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
810 "Next payload: %s (%u)",
811 payloadtype2str(hdr->next_payload), hdr->next_payload);
812 offset += sizeof(hdr->next_payload) * 2;
814 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
815 "Length: %u", length);
816 offset += sizeof(length);
818 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Hash Data");
819 offset += (length - sizeof(*hdr));
821 if (hdr->next_payload < NUM_LOAD_TYPES) {
822 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
823 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
825 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
828 old_dissect_data(pd, offset, fd, tree);
832 dissect_sig(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
834 struct sig_hdr * hdr = (struct sig_hdr *)(pd + offset);
835 guint16 length = pntohs(&hdr->length);
836 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Signature payload");
839 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
841 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
842 "Next payload: %s (%u)",
843 payloadtype2str(hdr->next_payload), hdr->next_payload);
844 offset += sizeof(hdr->next_payload) * 2;
846 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
847 "Length: %u", length);
848 offset += sizeof(length);
850 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Signature Data");
851 offset += (length - sizeof(*hdr));
853 if (hdr->next_payload < NUM_LOAD_TYPES) {
854 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
855 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
857 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
860 old_dissect_data(pd, offset, fd, tree);
864 dissect_nonce(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
866 struct nonce_hdr * hdr = (struct nonce_hdr *)(pd + offset);
867 guint16 length = pntohs(&hdr->length);
868 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Nonce payload");
871 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
873 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
874 "Next payload: %s (%u)",
875 payloadtype2str(hdr->next_payload), hdr->next_payload);
876 offset += sizeof(hdr->next_payload) * 2;
878 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
879 "Length: %u", length);
880 offset += sizeof(length);
882 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Nonce Data");
883 offset += (length - sizeof(*hdr));
885 if (hdr->next_payload < NUM_LOAD_TYPES) {
886 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
887 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
889 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
892 old_dissect_data(pd, offset, fd, tree);
896 dissect_notif(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
898 struct notif_hdr * hdr = (struct notif_hdr *)(pd + offset);
899 guint16 length = pntohs(&hdr->length);
900 guint32 doi = pntohl(&hdr->doi);
901 guint16 msgtype = pntohs(&hdr->msgtype);
902 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Notification payload");
905 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
907 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
908 "Next payload: %s (%u)",
909 payloadtype2str(hdr->next_payload), hdr->next_payload);
910 offset += sizeof(hdr->next_payload) * 2;
912 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
913 "Length: %u", length);
914 offset += sizeof(length);
916 proto_tree_add_text(ntree, NullTVB, offset, sizeof(doi),
917 "Domain of Interpretation: %s (%u)", doitype2str(doi), doi);
918 offset += sizeof(doi);
920 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
921 "Protocol ID: %s (%u)",
922 proto2str(hdr->protocol_id), hdr->protocol_id);
923 offset += sizeof(hdr->protocol_id);
925 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->spi_size),
926 "SPI size: %u", hdr->spi_size);
927 offset += sizeof(hdr->spi_size);
929 proto_tree_add_text(ntree, NullTVB, offset, sizeof(msgtype),
930 "Message type: %s (%u)", msgtype2str(msgtype), msgtype);
931 offset += sizeof(msgtype);
934 proto_tree_add_text(ntree, NullTVB, offset, hdr->spi_size, "Security Parameter Index");
935 offset += hdr->spi_size;
938 if (length - sizeof(*hdr)) {
939 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr) - hdr->spi_size,
940 "Notification Data");
941 offset += (length - sizeof(*hdr) - hdr->spi_size);
944 if (hdr->next_payload < NUM_LOAD_TYPES) {
945 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
946 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
948 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
951 old_dissect_data(pd, offset, fd, tree);
955 dissect_delete(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
957 struct delete_hdr * hdr = (struct delete_hdr *)(pd + offset);
958 guint16 length = pntohs(&hdr->length);
959 guint32 doi = pntohl(&hdr->doi);
960 guint16 num_spis = pntohs(&hdr->num_spis);
961 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Delete payload");
965 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
967 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
968 "Next payload: %s (%u)",
969 payloadtype2str(hdr->next_payload), hdr->next_payload);
970 offset += sizeof(hdr->next_payload) * 2;
972 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
973 "Length: %u", length);
974 offset += sizeof(length);
976 proto_tree_add_text(ntree, NullTVB, offset, sizeof(doi),
977 "Domain of Interpretation: %s (%u)", doitype2str(doi), doi);
978 offset += sizeof(doi);
980 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->protocol_id),
981 "Protocol ID: %s (%u)",
982 proto2str(hdr->protocol_id), hdr->protocol_id);
983 offset += sizeof(hdr->protocol_id);
985 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->spi_size),
986 "SPI size: %u", hdr->spi_size);
987 offset += sizeof(hdr->spi_size);
989 proto_tree_add_text(ntree, NullTVB, offset, num_spis,
990 "Number of SPIs: %u", num_spis);
991 offset += sizeof(hdr->num_spis);
993 for (i = 0; i < num_spis; ++i) {
994 proto_tree_add_text(ntree, NullTVB, offset, hdr->spi_size,
996 offset += hdr->spi_size;
999 if (hdr->next_payload < NUM_LOAD_TYPES) {
1000 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
1001 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
1003 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
1006 old_dissect_data(pd, offset, fd, tree);
1010 dissect_vid(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
1012 struct vid_hdr * hdr = (struct vid_hdr *)(pd + offset);
1013 guint16 length = pntohs(&hdr->length);
1014 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Vendor ID payload");
1017 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
1019 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
1020 "Next payload: %s (%u)",
1021 payloadtype2str(hdr->next_payload), hdr->next_payload);
1022 offset += sizeof(hdr->next_payload) * 2;
1024 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
1025 "Length: %u", length);
1026 offset += sizeof(length);
1028 proto_tree_add_text(ntree, NullTVB, offset, length - sizeof(*hdr), "Vendor ID");
1029 offset += (length - sizeof(*hdr));
1031 if (hdr->next_payload < NUM_LOAD_TYPES) {
1032 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
1033 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
1035 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
1038 old_dissect_data(pd, offset, fd, tree);
1042 dissect_config(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
1044 struct cfg_hdr * hdr = (struct cfg_hdr *)(pd + offset);
1045 guint16 length = pntohs(&hdr->length);
1046 proto_item * ti = proto_tree_add_text(tree, NullTVB, offset, length, "Attribute payload");
1049 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
1051 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->next_payload),
1052 "Next payload: %s (%u)",
1053 payloadtype2str(hdr->next_payload), hdr->next_payload);
1054 offset += sizeof(hdr->next_payload) *2;
1056 proto_tree_add_text(ntree, NullTVB, offset, sizeof(length),
1057 "Length: %u", length);
1058 offset += sizeof(length);
1060 proto_tree_add_text(ntree,NullTVB, offset, sizeof(hdr->type),
1061 "Type %s (%u)",attrtype2str(hdr->type),hdr->type);
1063 offset += (sizeof(hdr->type) + sizeof(hdr->reserved2));
1065 proto_tree_add_text(ntree, NullTVB, offset, sizeof(hdr->identifier),
1066 "Identifier: %u", pntohs(&hdr->identifier));
1067 offset += sizeof(hdr->identifier);
1068 length -= sizeof(*hdr);
1071 guint16 type = pntohs(pd + offset) & 0x7fff;
1072 guint16 val_len = pntohs(pd + offset + 2);
1074 if(pd[offset] & 0x80) {
1075 proto_tree_add_text(ntree, NullTVB, offset, 4,
1076 "%s (%u)",cfgattrident2str(type),val_len);
1081 guint pack_len = 4 + val_len;
1083 proto_tree_add_text(ntree, NullTVB, offset, 4,
1084 "%s (%se)", cfgattrident2str(type), num2str(pd + offset + 4, val_len));
1090 if (hdr->next_payload < NUM_LOAD_TYPES) {
1091 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
1092 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
1094 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
1097 old_dissect_data(pd, offset, fd, tree);
1102 payloadtype2str(guint8 type) {
1104 if (type < NUM_LOAD_TYPES) return strfuncs[type].str;
1105 if (type < 128) return "RESERVED";
1106 if (type < 256) return "Private USE";
1108 return "Huh? You should never see this! Shame on you!";
1112 exchtype2str(guint8 type) {
1114 #define NUM_EXCHSTRS 7
1115 static const char * exchstrs[NUM_EXCHSTRS] = {
1118 "Identity Protection (Main Mode)",
1119 "Authentication Only",
1122 "Transaction (Config Mode)"
1125 if (type < NUM_EXCHSTRS) return exchstrs[type];
1126 if (type < 32) return "ISAKMP Future Use";
1129 return "Quick Mode";
1131 return "New Group Mode";
1133 if (type < 240) return "DOI Specific Use";
1134 if (type < 256) return "Private Use";
1136 return "Huh? You should never see this! Shame on you!";
1140 doitype2str(guint32 type) {
1141 if (type == 1) return "IPSEC";
1142 return "Unknown DOI Type";
1146 msgtype2str(guint16 type) {
1148 #define NUM_PREDEFINED 31
1149 static const char *msgs[NUM_PREDEFINED] = {
1151 "INVALID-PAYLOAD-TYPE",
1152 "DOI-NOT-SUPPORTED",
1153 "SITUATION-NOT-SUPPORTED",
1155 "INVALID-MAJOR-VERSION",
1156 "INVALID-MINOR-VERSION",
1157 "INVALID-EXCHANGE-TYPE",
1159 "INVALID-MESSAGE-ID",
1160 "INVALID-PROTOCOL-ID",
1162 "INVALID-TRANSFORM-ID",
1163 "ATTRIBUTES-NOT-SUPPORTED",
1164 "NO-PROPOSAL-CHOSEN",
1165 "BAD-PROPOSAL-SYNTAX",
1166 "PAYLOAD-MALFORMED",
1167 "INVALID-KEY-INFORMATION",
1168 "INVALID-ID-INFORMATION",
1169 "INVALID-CERT-ENCODING",
1170 "INVALID-CERTIFICATE",
1171 "CERT-TYPE-UNSUPPORTED",
1172 "INVALID-CERT-AUTHORITY",
1173 "INVALID-HASH-INFORMATION",
1174 "AUTHENTICATION-FAILED",
1175 "INVALID-SIGNATURE",
1176 "ADDRESS-NOTIFICATION",
1177 "NOTIFY-SA-LIFETIME",
1178 "CERTIFICATE-UNAVAILABLE",
1179 "UNSUPPORTED-EXCHANGE-TYPE",
1180 "UNEQUAL-PAYLOAD-LENGTHS"
1183 if (type < NUM_PREDEFINED) return msgs[type];
1184 if (type < 8192) return "RESERVED (Future Use)";
1185 if (type < 16384) return "Private Use";
1186 if (type < 16385) return "CONNECTED";
1187 if (type < 24576) return "RESERVED (Future Use) - status";
1188 if (type < 24577) return "RESPONDER-LIFETIME";
1189 if (type < 24578) return "REPLAY-STATUS";
1190 if (type < 24579) return "INITIAL-CONTACT";
1191 if (type < 32768) return "DOI-specific codes";
1192 if (type < 40960) return "Private Use - status";
1193 if (type < 65535) return "RESERVED (Future Use) - status (2)";
1195 return "Huh? You should never see this! Shame on you!";
1199 situation2str(guint32 type) {
1201 #define SIT_MSG_NUM 1024
1202 #define SIT_IDENTITY 0x01
1203 #define SIT_SECRECY 0x02
1204 #define SIT_INTEGRITY 0x04
1206 static char msg[SIT_MSG_NUM];
1210 if (type & SIT_IDENTITY) {
1211 n += snprintf(msg, SIT_MSG_NUM-n, "%sIDENTITY", sep);
1214 if (type & SIT_SECRECY) {
1215 n += snprintf(msg, SIT_MSG_NUM-n, "%sSECRECY", sep);
1218 if (type & SIT_INTEGRITY) {
1219 n += snprintf(msg, SIT_MSG_NUM-n, "%sINTEGRITY", sep);
1227 value2str(int ike_p1, guint16 att_type, guint16 value) {
1229 if (value == 0) return "RESERVED";
1235 case 1: return "Seconds";
1236 case 2: return "Kilobytes";
1237 default: return "UNKNOWN-SA-VALUE";
1240 return "Duration-Value";
1242 return "Group-Value";
1245 case 1: return "Tunnel";
1246 case 2: return "Transport";
1247 default: return "UNKNOWN-ENCAPSULATION-VALUE";
1251 case 1: return "HMAC-MD5";
1252 case 2: return "HMAC-SHA";
1253 case 3: return "DES-MAC";
1254 case 4: return "KPDK";
1255 default: return "UNKNOWN-AUTHENTICATION-VALUE";
1258 return "Key-Length";
1260 return "Key-Rounds";
1263 default: return "UNKNOWN-ATTRIBUTE-TYPE";
1270 case 1: return "DES-CBC";
1271 case 2: return "IDEA-CBC";
1272 case 3: return "BLOWFISH-CBC";
1273 case 4: return "RC5-R16-B64-CBC";
1274 case 5: return "3DES-CBC";
1275 case 6: return "CAST-CBC";
1276 default: return "UNKNOWN-ENCRYPTION-ALG";
1280 case 1: return "MD5";
1281 case 2: return "SHA";
1282 case 3: return "TIGER";
1283 default: return "UNKNOWN-HASH-ALG";
1287 case 1: return "PSK";
1288 case 2: return "DSS-SIG";
1289 case 3: return "RSA-SIG";
1290 case 4: return "RSA-ENC";
1291 case 5: return "RSA-Revised-ENC";
1292 case 64221: return "HybridInitRSA";
1293 case 64222: return "HybridRespRSA";
1294 case 64223: return "HybridInitDSS";
1295 case 64224: return "HybridRespDSS";
1296 case 65001: return "XAUTHInitPreShared";
1297 case 65002: return "XAUTHRespPreShared";
1298 case 65003: return "XAUTHInitDSS";
1299 case 65004: return "XAUTHRespDSS";
1300 case 65005: return "XAUTHInitRSA";
1301 case 65006: return "XAUTHRespRSA";
1302 case 65007: return "XAUTHInitRSAEncryption";
1303 case 65008: return "XAUTHRespRSAEncryption";
1304 case 65009: return "XAUTHInitRSARevisedEncryption";
1305 case 65010: return "XAUTHRespRSARevisedEncryption";
1306 default: return "UNKNOWN-AUTH-METHOD";
1315 return "Group-Value";
1318 case 1: return "MODP";
1319 case 2: return "ECP";
1320 case 3: return "EC2N";
1321 default: return "UNKNOWN-GROUPT-TYPE";
1325 case 1: return "Seconds";
1326 case 2: return "Kilobytes";
1327 default: return "UNKNOWN-SA-VALUE";
1330 return "Duration-Value";
1334 return "Key-Length";
1336 return "Field-Size";
1337 default: return "UNKNOWN-ATTRIBUTE-TYPE";
1343 attrtype2str(guint8 type) {
1345 case 0: return "Reserved";
1346 case 1: return "ISAKMP_CFG_REQUEST";
1347 case 2: return "ISAKMP_CFG_REPLY";
1348 case 3: return "ISAKMP_CFG_SET";
1349 case 4: return "ISAKMP_CFG_ACK";
1352 return "Future use";
1353 return "Private use";
1357 cfgattrident2str(guint16 ident) {
1358 #define NUM_ATTR_DEFINED 12
1359 static const char *msgs[NUM_PREDEFINED] = {
1361 "INTERNAL_IP4_ADDRESS",
1362 "INTERNAL_IP4_NETMASK",
1364 "INTERNAL_IP4_NBNS",
1365 "INTERNAL_ADDRESS_EXPIREY",
1366 "INTERNAL_IP4_DHCP",
1367 "APPLICATION_VERSION"
1368 "INTERNAL_IP6_ADDRESS",
1369 "INTERNAL_IP6_NETMASK",
1371 "INTERNAL_IP6_NBNS",
1372 "INTERNAL_IP6_DHCP",
1374 if(ident < NUM_ATTR_DEFINED)
1377 return "Future use";
1379 case 16520: return "XAUTH_TYPE";
1380 case 16521: return "XAUTH_USER_NAME";
1381 case 16522: return "XAUTH_USER_PASSWORD";
1382 case 16523: return "XAUTH_PASSCODE";
1383 case 16524: return "XAUTH_MESSAGE";
1384 case 16525: return "XAUTH_CHALLANGE";
1385 case 16526: return "XAUTH_DOMAIN";
1386 case 16527: return "XAUTH_STATUS";
1387 default: return "Private use";
1392 num2str(const guint8 *pd, guint16 len) {
1394 #define NUMSTR_LEN 1024
1395 static char numstr[NUMSTR_LEN];
1399 snprintf(numstr, NUMSTR_LEN, "%u", *pd);
1402 snprintf(numstr, NUMSTR_LEN, "%u", pntohs(pd));
1405 snprintf(numstr, NUMSTR_LEN, "%u", pntohl(pd) & 0x0fff);
1408 snprintf(numstr, NUMSTR_LEN, "%u", pntohl(pd));
1411 snprintf(numstr, NUMSTR_LEN, "<too big>");
1418 proto_register_isakmp(void)
1420 /* static hf_register_info hf[] = {
1422 { "Name", "isakmp.abbreviation", TYPE, VALS_POINTER }},
1424 static gint *ett[] = {
1427 &ett_isakmp_payload,
1430 proto_isakmp = proto_register_protocol("Internet Security Association and Key Management Protocol", "isakmp");
1431 /* proto_register_field_array(proto_isakmp, hf, array_length(hf));*/
1432 proto_register_subtree_array(ett, array_length(ett));
1436 proto_reg_handoff_isakmp(void)
1438 old_dissector_add("udp.port", UDP_PORT_ISAKMP, dissect_isakmp);