2 * Routines for the Internet Security Association and Key Management Protocol (ISAKMP)
3 * Brad Robel-Forrest <brad.robel-forrest@watchguard.com>
5 * $Id: packet-isakmp.c,v 1.14 2000/04/28 17:53:25 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
37 #ifdef HAVE_NETINET_IN_H
38 #include <netinet/in.h>
44 #ifdef NEED_SNPRINTF_H
50 # include "snprintf.h"
53 static int proto_isakmp = -1;
55 static gint ett_isakmp = -1;
56 static gint ett_isakmp_flags = -1;
57 static gint ett_isakmp_payload = -1;
59 #define UDP_PORT_ISAKMP 500
61 #define NUM_PROTO_TYPES 5
62 #define proto2str(t) \
63 ((t < NUM_PROTO_TYPES) ? prototypestr[t] : "UNKNOWN-PROTO-TYPE")
65 static const char *prototypestr[NUM_PROTO_TYPES] = {
73 #define NUM_P1_ATT_TYPES 17
74 #define p1_atttype2str(t) \
75 ((t < NUM_P1_ATT_TYPES) ? p1_atttypestr[t] : "UNKNOWN-ATTRIBUTE-TYPE")
77 static const char *p1_atttypestr[NUM_P1_ATT_TYPES] = {
78 "UNKNOWN-ATTRIBUTE-TYPE",
79 "Encryption-Algorithm",
81 "Authentication-Method",
85 "Group-Generator-One",
86 "Group-Generator-Two",
97 #define NUM_ATT_TYPES 10
98 #define atttype2str(t) \
99 ((t < NUM_ATT_TYPES) ? atttypestr[t] : "UNKNOWN-ATTRIBUTE-TYPE")
101 static const char *atttypestr[NUM_ATT_TYPES] = {
102 "UNKNOWN-ATTRIBUTE-TYPE",
106 "Encapsulation-Mode",
107 "Authentication-Algorithm",
110 "Compress-Dictinary-Size",
111 "Compress-Private-Algorithm"
114 #define NUM_TRANS_TYPES 2
115 #define trans2str(t) \
116 ((t < NUM_TRANS_TYPES) ? transtypestr[t] : "UNKNOWN-TRANS-TYPE")
118 static const char *transtypestr[NUM_TRANS_TYPES] = {
123 #define NUM_AH_TRANS_TYPES 5
124 #define ah_trans2str(t) \
125 ((t < NUM_AH_TRANS_TYPES) ? ah_transtypestr[t] : "UNKNOWN-AH-TRANS-TYPE")
127 static const char *ah_transtypestr[NUM_AH_TRANS_TYPES] = {
135 #define NUM_ESP_TRANS_TYPES 12
136 #define esp_trans2str(t) \
137 ((t < NUM_ESP_TRANS_TYPES) ? esp_transtypestr[t] : "UNKNOWN-ESP-TRANS-TYPE")
139 static const char *esp_transtypestr[NUM_ESP_TRANS_TYPES] = {
154 #define NUM_ID_TYPES 12
156 ((t < NUM_ID_TYPES) ? idtypestr[t] : "UNKNOWN-ID-TYPE")
158 static const char *idtypestr[NUM_ID_TYPES] = {
195 struct proposal_hdr {
202 guint8 num_transforms;
209 guint8 transform_num;
214 #define TRANS_LEN(p) (pntohs(&((struct trans_hdr *)(p))->length))
289 static void dissect_none(const u_char *, int, frame_data *, proto_tree *);
290 static void dissect_sa(const u_char *, int, frame_data *, proto_tree *);
291 static void dissect_proposal(const u_char *, int, frame_data *, proto_tree *);
292 static void dissect_transform(const u_char *, int, frame_data *, proto_tree *,
294 static void dissect_key_exch(const u_char *, int, frame_data *, proto_tree *);
295 static void dissect_id(const u_char *, int, frame_data *, proto_tree *);
296 static void dissect_cert(const u_char *, int, frame_data *, proto_tree *);
297 static void dissect_certreq(const u_char *, int, frame_data *, proto_tree *);
298 static void dissect_hash(const u_char *, int, frame_data *, proto_tree *);
299 static void dissect_sig(const u_char *, int, frame_data *, proto_tree *);
300 static void dissect_nonce(const u_char *, int, frame_data *, proto_tree *);
301 static void dissect_notif(const u_char *, int, frame_data *, proto_tree *);
302 static void dissect_delete(const u_char *, int, frame_data *, proto_tree *);
303 static void dissect_vid(const u_char *, int, frame_data *, proto_tree *);
305 static const char *payloadtype2str(guint8);
306 static const char *exchtype2str(guint8);
307 static const char *doitype2str(guint32);
308 static const char *msgtype2str(guint16);
309 static const char *situation2str(guint32);
310 static const char *value2str(int, guint16, guint16);
311 static const char *num2str(const guint8 *, guint16);
313 #define NUM_LOAD_TYPES 14
314 #define loadtype2str(t) \
315 ((t < NUM_LOAD_TYPES) ? strfuncs[t].str : "Unknown payload type")
316 #define LOAD_TYPE_TRANSFORM 3
318 static struct strfunc {
320 void (*func)(const u_char *, int, frame_data *, proto_tree *);
321 } strfuncs[NUM_LOAD_TYPES] = {
322 {"NONE", dissect_none },
323 {"Security Association", dissect_sa },
324 {"Proposal", dissect_proposal },
325 {"Transform", NULL },
326 {"Key Exchange", dissect_key_exch },
327 {"Identification", dissect_id },
328 {"Certificate", dissect_cert },
329 {"Certificate Request", dissect_certreq },
330 {"Hash", dissect_hash },
331 {"Signature", dissect_sig },
332 {"Nonce", dissect_nonce },
333 {"Notification", dissect_notif },
334 {"Delete", dissect_delete },
335 {"Vendor ID", dissect_vid }
339 dissect_isakmp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
341 struct isakmp_hdr * hdr = (struct isakmp_hdr *)(pd + offset);
344 if (check_col(fd, COL_PROTOCOL))
345 col_add_str(fd, COL_PROTOCOL, "ISAKMP");
347 len = pntohl(&hdr->length);
349 if (check_col(fd, COL_INFO))
350 col_add_fstr(fd, COL_INFO, "%s", exchtype2str(hdr->exch_type));
352 if (IS_DATA_IN_FRAME(offset) && tree) {
354 proto_tree * isakmp_tree;
356 ti = proto_tree_add_item(tree, proto_isakmp, offset, len, NULL);
357 isakmp_tree = proto_item_add_subtree(ti, ett_isakmp);
359 proto_tree_add_text(isakmp_tree, offset, sizeof(hdr->icookie),
361 offset += sizeof(hdr->icookie);
363 proto_tree_add_text(isakmp_tree, offset, sizeof(hdr->rcookie),
365 offset += sizeof(hdr->rcookie);
367 proto_tree_add_text(isakmp_tree, offset, sizeof(hdr->next_payload),
368 "Next payload: %s (%u)",
369 payloadtype2str(hdr->next_payload), hdr->next_payload);
370 offset += sizeof(hdr->next_payload);
372 proto_tree_add_text(isakmp_tree, offset, sizeof(hdr->version),
374 hi_nibble(hdr->version), lo_nibble(hdr->version));
375 offset += sizeof(hdr->version);
377 proto_tree_add_text(isakmp_tree, offset, sizeof(hdr->exch_type),
378 "Exchange type: %s (%u)",
379 exchtype2str(hdr->exch_type), hdr->exch_type);
380 offset += sizeof(hdr->exch_type);
386 fti = proto_tree_add_text(isakmp_tree, offset, sizeof(hdr->flags), "Flags");
387 ftree = proto_item_add_subtree(fti, ett_isakmp_flags);
389 proto_tree_add_text(ftree, offset, 1, "%s",
390 decode_boolean_bitfield(hdr->flags, E_FLAG, sizeof(hdr->flags)*8,
391 "Encryption", "No encryption"));
392 proto_tree_add_text(ftree, offset, 1, "%s",
393 decode_boolean_bitfield(hdr->flags, C_FLAG, sizeof(hdr->flags)*8,
394 "Commit", "No commit"));
395 proto_tree_add_text(ftree, offset, 1, "%s",
396 decode_boolean_bitfield(hdr->flags, A_FLAG, sizeof(hdr->flags)*8,
397 "Authentication", "No authentication"));
398 offset += sizeof(hdr->flags);
401 proto_tree_add_text(isakmp_tree, offset, sizeof(hdr->message_id), "Message ID");
402 offset += sizeof(hdr->message_id);
404 proto_tree_add_text(isakmp_tree, offset, sizeof(hdr->length),
406 offset += sizeof(hdr->length);
408 if (hdr->flags & E_FLAG) {
409 if (IS_DATA_IN_FRAME(offset) && isakmp_tree) {
410 proto_tree_add_text(isakmp_tree, offset, END_OF_FRAME,
411 "Encrypted payload (%d byte%s)",
412 END_OF_FRAME, plurality(END_OF_FRAME, "", "s"));
415 if (hdr->next_payload < NUM_LOAD_TYPES) {
416 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
417 dissect_transform(pd, offset, fd, isakmp_tree, 0); /* XXX - protocol ID? */
419 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, isakmp_tree);
422 dissect_data(pd, offset, fd, isakmp_tree);
428 dissect_none(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
432 dissect_sa(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
434 struct sa_hdr * hdr = (struct sa_hdr *)(pd + offset);
435 guint16 length = pntohs(&hdr->length);
436 guint32 doi = pntohl(&hdr->doi);
437 guint32 situation = pntohl(&hdr->situation);
438 proto_item * ti = proto_tree_add_text(tree, offset, length, "Security Association payload");
441 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
443 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
444 "Next payload: %s (%u)",
445 payloadtype2str(hdr->next_payload), hdr->next_payload);
446 offset += sizeof(hdr->next_payload) * 2;
448 proto_tree_add_text(ntree, offset, sizeof(length),
449 "Length: %u", length);
450 offset += sizeof(length);
452 proto_tree_add_text(ntree, offset, sizeof(doi),
453 "Domain of interpretation: %s (%u)",
454 doitype2str(doi), doi);
455 offset += sizeof(doi);
457 proto_tree_add_text(ntree, offset, sizeof(situation),
458 "Situation: %s (%u)",
459 situation2str(situation), situation);
460 offset += sizeof(situation);
462 dissect_proposal(pd, offset, fd, ntree);
463 offset += (length - sizeof(*hdr));
465 if (hdr->next_payload < NUM_LOAD_TYPES) {
466 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
467 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
469 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
472 dissect_data(pd, offset, fd, tree);
476 dissect_proposal(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
478 struct proposal_hdr * hdr = (struct proposal_hdr *)(pd + offset);
479 guint16 length = pntohs(&hdr->length);
480 proto_item * ti = proto_tree_add_text(tree, offset, length, "Proposal payload");
483 int next_hdr_offset = offset + length;
485 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
487 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
488 "Next payload: %s (%u)",
489 payloadtype2str(hdr->next_payload), hdr->next_payload);
490 offset += sizeof(hdr->next_payload) * 2;
492 proto_tree_add_text(ntree, offset, sizeof(length),
493 "Length: %u", length);
494 offset += sizeof(length);
496 proto_tree_add_text(ntree, offset, sizeof(hdr->proposal_num),
497 "Proposal number: %u", hdr->proposal_num);
498 offset += sizeof(hdr->proposal_num);
500 proto_tree_add_text(ntree, offset, sizeof(hdr->protocol_id),
501 "Protocol ID: %s (%u)",
502 proto2str(hdr->protocol_id), hdr->protocol_id);
503 offset += sizeof(hdr->protocol_id);
505 proto_tree_add_text(ntree, offset, sizeof(hdr->spi_size),
506 "SPI size: %u", hdr->spi_size);
507 offset += sizeof(hdr->spi_size);
509 proto_tree_add_text(ntree, offset, sizeof(hdr->num_transforms),
510 "Number of transforms: %u", hdr->num_transforms);
511 offset += sizeof(hdr->num_transforms);
514 proto_tree_add_text(ntree, offset, hdr->spi_size, "SPI");
515 offset += hdr->spi_size;
518 if (hdr->num_transforms > 0)
519 dissect_transform(pd, offset, fd, ntree, hdr->protocol_id);
521 if (hdr->next_payload < NUM_LOAD_TYPES) {
522 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
523 dissect_transform(pd, next_hdr_offset, fd, tree, 0); /* XXX - protocol ID? */
525 (*strfuncs[hdr->next_payload].func)(pd, next_hdr_offset, fd, tree);
528 dissect_data(pd, next_hdr_offset, fd, tree);
532 dissect_transform(const u_char *pd, int offset, frame_data *fd,
533 proto_tree *tree, guint8 protocol_id)
536 struct trans_hdr * hdr = (struct trans_hdr *)(pd + offset);
537 guint16 length = pntohs(&hdr->length);
538 proto_item * ti = proto_tree_add_text(tree, offset, length, "Transform payload");
541 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
543 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
544 "Next payload: %s (%u)",
545 payloadtype2str(hdr->next_payload), hdr->next_payload);
546 offset += sizeof(hdr->next_payload) * 2;
548 proto_tree_add_text(ntree, offset, sizeof(length),
549 "Length: %u", length);
550 offset += sizeof(length);
552 proto_tree_add_text(ntree, offset, sizeof(hdr->transform_num),
553 "Transform number: %u", hdr->transform_num);
554 offset += sizeof(hdr->transform_num);
556 switch (protocol_id) {
559 proto_tree_add_text(ntree, offset, sizeof(hdr->transform_id),
560 "Transform ID: %s (%u)",
561 trans2str(hdr->transform_id), hdr->transform_id);
564 proto_tree_add_text(ntree, offset, sizeof(hdr->transform_id),
565 "Transform ID: %s (%u)",
566 ah_trans2str(hdr->transform_id), hdr->transform_id);
569 proto_tree_add_text(ntree, offset, sizeof(hdr->transform_id),
570 "Transform ID: %s (%u)",
571 esp_trans2str(hdr->transform_id), hdr->transform_id);
574 offset += sizeof(hdr->transform_id) + sizeof(hdr->reserved2);
576 length -= sizeof(*hdr);
578 const char *str = NULL;
580 guint16 type = pntohs(pd + offset) & 0x7fff;
581 guint16 val_len = pntohs(pd + offset + 2);
583 if (protocol_id == 1 && hdr->transform_id == 1) {
585 str = p1_atttype2str(type);
588 str = atttype2str(type);
591 if (pd[offset] & 0xf0) {
592 proto_tree_add_text(ntree, offset, 4,
595 value2str(ike_phase1, type, val_len), val_len);
600 guint16 pack_len = 4 + val_len;
602 proto_tree_add_text(ntree, offset, pack_len,
605 num2str(pd + offset + 4, val_len));
611 if (hdr->next_payload < NUM_LOAD_TYPES) {
612 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
613 dissect_transform(pd, offset, fd, tree, protocol_id);
615 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
618 dissect_data(pd, offset, fd, tree);
622 dissect_key_exch(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
624 struct ke_hdr * hdr = (struct ke_hdr *)(pd + offset);
625 guint16 length = pntohs(&hdr->length);
626 proto_item * ti = proto_tree_add_text(tree, offset, length, "Key Exchange payload");
629 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
631 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
632 "Next payload: %s (%u)",
633 payloadtype2str(hdr->next_payload), hdr->next_payload);
634 offset += sizeof(hdr->next_payload) * 2;
636 proto_tree_add_text(ntree, offset, sizeof(length),
637 "Length: %u", length);
638 offset += sizeof(length);
640 proto_tree_add_text(ntree, offset, length - sizeof(*hdr), "Key Exchange Data");
641 offset += (length - sizeof(*hdr));
643 if (hdr->next_payload < NUM_LOAD_TYPES) {
644 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
645 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
647 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
650 dissect_data(pd, offset, fd, tree);
654 dissect_id(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
656 struct id_hdr * hdr = (struct id_hdr *)(pd + offset);
657 guint16 length = pntohs(&hdr->length);
658 proto_item * ti = proto_tree_add_text(tree, offset, length, "Identification payload");
661 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
663 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
664 "Next payload: %s (%u)",
665 payloadtype2str(hdr->next_payload), hdr->next_payload);
666 offset += sizeof(hdr->next_payload) * 2;
668 proto_tree_add_text(ntree, offset, sizeof(length),
669 "Length: %u", length);
670 offset += sizeof(length);
672 proto_tree_add_text(ntree, offset, sizeof(hdr->id_type),
673 "ID type: %s (%u)", id2str(hdr->id_type), hdr->id_type);
674 offset += sizeof(hdr->id_type);
676 proto_tree_add_text(ntree, offset, sizeof(hdr->protocol_id),
677 "Protocol ID: %u", hdr->protocol_id);
678 offset += sizeof(hdr->protocol_id);
680 proto_tree_add_text(ntree, offset, sizeof(hdr->port),
681 "Port: %u", pntohs(&hdr->port));
682 offset += sizeof(hdr->port);
684 switch (hdr->id_type) {
687 proto_tree_add_text(ntree, offset, length-sizeof(*hdr),
688 "Identification data: %s", ip_to_str(pd+offset));
692 proto_tree_add_text(ntree, offset, length-sizeof(*hdr),
693 "Identification data: %s", (char *)(pd+offset));
696 proto_tree_add_text(ntree, offset, length - sizeof(*hdr), "Identification Data");
698 offset += (length - sizeof(*hdr));
700 if (hdr->next_payload < NUM_LOAD_TYPES) {
701 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
702 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
704 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
707 dissect_data(pd, offset, fd, tree);
711 dissect_cert(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
713 struct cert_hdr * hdr = (struct cert_hdr *)(pd + offset);
714 guint16 length = pntohs(&hdr->length);
715 proto_item * ti = proto_tree_add_text(tree, offset, length, "Certificate payload");
718 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
720 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
721 "Next payload: %s (%u)",
722 payloadtype2str(hdr->next_payload), hdr->next_payload);
723 offset += sizeof(hdr->next_payload) * 2;
725 proto_tree_add_text(ntree, offset, sizeof(length),
726 "Length: %u", length);
727 offset += sizeof(length);
729 proto_tree_add_text(ntree, offset, sizeof(hdr->cert_enc),
730 "Certificate encoding: %u", hdr->cert_enc);
731 offset += sizeof(hdr->cert_enc);
733 proto_tree_add_text(ntree, offset, length - sizeof(*hdr), "Certificate Data");
734 offset += (length - sizeof(*hdr));
736 if (hdr->next_payload < NUM_LOAD_TYPES) {
737 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
738 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
740 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
743 dissect_data(pd, offset, fd, tree);
747 dissect_certreq(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
749 struct certreq_hdr * hdr = (struct certreq_hdr *)(pd + offset);
750 guint16 length = pntohs(&hdr->length);
751 proto_item * ti = proto_tree_add_text(tree, offset, length, "Certificate Request payload");
754 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
756 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
757 "Next payload: %s (%u)",
758 payloadtype2str(hdr->next_payload), hdr->next_payload);
759 offset += sizeof(hdr->next_payload) * 2;
761 proto_tree_add_text(ntree, offset, sizeof(length),
762 "Length: %u", length);
763 offset += sizeof(length);
765 proto_tree_add_text(ntree, offset, sizeof(hdr->cert_type),
766 "Certificate type: %u", hdr->cert_type);
767 offset += sizeof(hdr->cert_type);
769 proto_tree_add_text(ntree, offset, length - sizeof(*hdr), "Certificate Authority");
770 offset += (length - sizeof(*hdr));
772 if (hdr->next_payload < NUM_LOAD_TYPES) {
773 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
774 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
776 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
779 dissect_data(pd, offset, fd, tree);
783 dissect_hash(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
785 struct hash_hdr * hdr = (struct hash_hdr *)(pd + offset);
786 guint16 length = pntohs(&hdr->length);
787 proto_item * ti = proto_tree_add_text(tree, offset, length, "Hash payload");
790 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
792 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
793 "Next payload: %s (%u)",
794 payloadtype2str(hdr->next_payload), hdr->next_payload);
795 offset += sizeof(hdr->next_payload) * 2;
797 proto_tree_add_text(ntree, offset, sizeof(length),
798 "Length: %u", length);
799 offset += sizeof(length);
801 proto_tree_add_text(ntree, offset, length - sizeof(*hdr), "Hash Data");
802 offset += (length - sizeof(*hdr));
804 if (hdr->next_payload < NUM_LOAD_TYPES) {
805 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
806 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
808 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
811 dissect_data(pd, offset, fd, tree);
815 dissect_sig(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
817 struct sig_hdr * hdr = (struct sig_hdr *)(pd + offset);
818 guint16 length = pntohs(&hdr->length);
819 proto_item * ti = proto_tree_add_text(tree, offset, length, "Signature payload");
822 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
824 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
825 "Next payload: %s (%u)",
826 payloadtype2str(hdr->next_payload), hdr->next_payload);
827 offset += sizeof(hdr->next_payload) * 2;
829 proto_tree_add_text(ntree, offset, sizeof(length),
830 "Length: %u", length);
831 offset += sizeof(length);
833 proto_tree_add_text(ntree, offset, length - sizeof(*hdr), "Signature Data");
834 offset += (length - sizeof(*hdr));
836 if (hdr->next_payload < NUM_LOAD_TYPES) {
837 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
838 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
840 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
843 dissect_data(pd, offset, fd, tree);
847 dissect_nonce(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
849 struct nonce_hdr * hdr = (struct nonce_hdr *)(pd + offset);
850 guint16 length = pntohs(&hdr->length);
851 proto_item * ti = proto_tree_add_text(tree, offset, length, "Nonce payload");
854 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
856 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
857 "Next payload: %s (%u)",
858 payloadtype2str(hdr->next_payload), hdr->next_payload);
859 offset += sizeof(hdr->next_payload) * 2;
861 proto_tree_add_text(ntree, offset, sizeof(length),
862 "Length: %u", length);
863 offset += sizeof(length);
865 proto_tree_add_text(ntree, offset, length - sizeof(*hdr), "Nonce Data");
866 offset += (length - sizeof(*hdr));
868 if (hdr->next_payload < NUM_LOAD_TYPES) {
869 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
870 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
872 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
875 dissect_data(pd, offset, fd, tree);
879 dissect_notif(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
881 struct notif_hdr * hdr = (struct notif_hdr *)(pd + offset);
882 guint16 length = pntohs(&hdr->length);
883 guint32 doi = pntohl(&hdr->doi);
884 guint16 msgtype = pntohs(&hdr->msgtype);
885 proto_item * ti = proto_tree_add_text(tree, offset, length, "Notification payload");
888 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
890 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
891 "Next payload: %s (%u)",
892 payloadtype2str(hdr->next_payload), hdr->next_payload);
893 offset += sizeof(hdr->next_payload) * 2;
895 proto_tree_add_text(ntree, offset, sizeof(length),
896 "Length: %u", length);
897 offset += sizeof(length);
899 proto_tree_add_text(ntree, offset, sizeof(doi),
900 "Domain of Interpretation: %s (%u)", doitype2str(doi), doi);
901 offset += sizeof(doi);
903 proto_tree_add_text(ntree, offset, sizeof(hdr->protocol_id),
904 "Protocol ID: %s (%u)",
905 proto2str(hdr->protocol_id), hdr->protocol_id);
906 offset += sizeof(hdr->protocol_id);
908 proto_tree_add_text(ntree, offset, sizeof(hdr->spi_size),
909 "SPI size: %u", hdr->spi_size);
910 offset += sizeof(hdr->spi_size);
912 proto_tree_add_text(ntree, offset, sizeof(msgtype),
913 "Message type: %s (%u)", msgtype2str(msgtype), msgtype);
914 offset += sizeof(msgtype);
917 proto_tree_add_text(ntree, offset, hdr->spi_size, "Security Parameter Index");
918 offset += hdr->spi_size;
921 if (length - sizeof(*hdr)) {
922 proto_tree_add_text(ntree, offset, length - sizeof(*hdr) - hdr->spi_size,
923 "Notification Data");
924 offset += (length - sizeof(*hdr) - hdr->spi_size);
927 if (hdr->next_payload < NUM_LOAD_TYPES) {
928 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
929 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
931 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
934 dissect_data(pd, offset, fd, tree);
938 dissect_delete(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
940 struct delete_hdr * hdr = (struct delete_hdr *)(pd + offset);
941 guint16 length = pntohs(&hdr->length);
942 guint32 doi = pntohl(&hdr->doi);
943 guint16 num_spis = pntohs(&hdr->num_spis);
944 proto_item * ti = proto_tree_add_text(tree, offset, length, "Delete payload");
948 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
950 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
951 "Next payload: %s (%u)",
952 payloadtype2str(hdr->next_payload), hdr->next_payload);
953 offset += sizeof(hdr->next_payload) * 2;
955 proto_tree_add_text(ntree, offset, sizeof(length),
956 "Length: %u", length);
957 offset += sizeof(length);
959 proto_tree_add_text(ntree, offset, sizeof(doi),
960 "Domain of Interpretation: %s (%u)", doitype2str(doi), doi);
961 offset += sizeof(doi);
963 proto_tree_add_text(ntree, offset, sizeof(hdr->protocol_id),
964 "Protocol ID: %s (%u)",
965 proto2str(hdr->protocol_id), hdr->protocol_id);
966 offset += sizeof(hdr->protocol_id);
968 proto_tree_add_text(ntree, offset, sizeof(hdr->spi_size),
969 "SPI size: %u", hdr->spi_size);
970 offset += sizeof(hdr->spi_size);
972 proto_tree_add_text(ntree, offset, num_spis,
973 "Number of SPIs: %u", num_spis);
974 offset += sizeof(hdr->num_spis);
976 for (i = 0; i < num_spis; ++i) {
977 proto_tree_add_text(ntree, offset, hdr->spi_size,
979 offset += hdr->spi_size;
982 if (hdr->next_payload < NUM_LOAD_TYPES) {
983 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
984 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
986 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
989 dissect_data(pd, offset, fd, tree);
993 dissect_vid(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
995 struct vid_hdr * hdr = (struct vid_hdr *)(pd + offset);
996 guint16 length = pntohs(&hdr->length);
997 proto_item * ti = proto_tree_add_text(tree, offset, length, "Vendor ID payload");
1000 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
1002 proto_tree_add_text(ntree, offset, sizeof(hdr->next_payload),
1003 "Next payload: %s (%u)",
1004 payloadtype2str(hdr->next_payload), hdr->next_payload);
1005 offset += sizeof(hdr->next_payload) * 2;
1007 proto_tree_add_text(ntree, offset, sizeof(length),
1008 "Length: %u", length);
1009 offset += sizeof(length);
1011 proto_tree_add_text(ntree, offset, length - sizeof(*hdr), "Vendor ID");
1012 offset += (length - sizeof(*hdr));
1014 if (hdr->next_payload < NUM_LOAD_TYPES) {
1015 if (hdr->next_payload == LOAD_TYPE_TRANSFORM)
1016 dissect_transform(pd, offset, fd, tree, 0); /* XXX - protocol ID? */
1018 (*strfuncs[hdr->next_payload].func)(pd, offset, fd, tree);
1021 dissect_data(pd, offset, fd, tree);
1025 payloadtype2str(guint8 type) {
1027 if (type < NUM_LOAD_TYPES) return strfuncs[type].str;
1028 if (type < 128) return "RESERVED";
1029 if (type < 256) return "Private USE";
1031 return "Huh? You should never see this! Shame on you!";
1035 exchtype2str(guint8 type) {
1037 #define NUM_EXCHSTRS 6
1038 static const char * exchstrs[NUM_EXCHSTRS] = {
1041 "Identity Protection (Main Mode)",
1042 "Authentication Only",
1047 if (type < NUM_EXCHSTRS) return exchstrs[type];
1048 if (type < 32) return "ISAKMP Future Use";
1051 return "Quick Mode";
1053 return "New Group Mode";
1055 if (type < 240) return "DOI Specific Use";
1056 if (type < 256) return "Private Use";
1058 return "Huh? You should never see this! Shame on you!";
1062 doitype2str(guint32 type) {
1063 if (type == 1) return "IPSEC";
1064 return "Unknown DOI Type";
1068 msgtype2str(guint16 type) {
1070 #define NUM_PREDEFINED 31
1071 static const char *msgs[NUM_PREDEFINED] = {
1073 "INVALID-PAYLOAD-TYPE",
1074 "DOI-NOT-SUPPORTED",
1075 "SITUATION-NOT-SUPPORTED",
1077 "INVALID-MAJOR-VERSION",
1078 "INVALID-MINOR-VERSION",
1079 "INVALID-EXCHANGE-TYPE",
1081 "INVALID-MESSAGE-ID",
1082 "INVALID-PROTOCOL-ID",
1084 "INVALID-TRANSFORM-ID",
1085 "ATTRIBUTES-NOT-SUPPORTED",
1086 "NO-PROPOSAL-CHOSEN",
1087 "BAD-PROPOSAL-SYNTAX",
1088 "PAYLOAD-MALFORMED",
1089 "INVALID-KEY-INFORMATION",
1090 "INVALID-ID-INFORMATION",
1091 "INVALID-CERT-ENCODING",
1092 "INVALID-CERTIFICATE",
1093 "CERT-TYPE-UNSUPPORTED",
1094 "INVALID-CERT-AUTHORITY",
1095 "INVALID-HASH-INFORMATION",
1096 "AUTHENTICATION-FAILED",
1097 "INVALID-SIGNATURE",
1098 "ADDRESS-NOTIFICATION",
1099 "NOTIFY-SA-LIFETIME",
1100 "CERTIFICATE-UNAVAILABLE",
1101 "UNSUPPORTED-EXCHANGE-TYPE",
1102 "UNEQUAL-PAYLOAD-LENGTHS"
1105 if (type < NUM_PREDEFINED) return msgs[type];
1106 if (type < 8192) return "RESERVED (Future Use)";
1107 if (type < 16384) return "Private Use";
1108 if (type < 16385) return "CONNECTED";
1109 if (type < 24576) return "RESERVED (Future Use) - status";
1110 if (type < 24577) return "RESPONDER-LIFETIME";
1111 if (type < 24578) return "REPLAY-STATUS";
1112 if (type < 24579) return "INITIAL-CONTACT";
1113 if (type < 32768) return "DOI-specific codes";
1114 if (type < 40960) return "Private Use - status";
1115 if (type < 65535) return "RESERVED (Future Use) - status (2)";
1117 return "Huh? You should never see this! Shame on you!";
1121 situation2str(guint32 type) {
1123 #define SIT_MSG_NUM 1024
1124 #define SIT_IDENTITY 0x01
1125 #define SIT_SECRECY 0x02
1126 #define SIT_INTEGRITY 0x04
1128 static char msg[SIT_MSG_NUM];
1132 if (type & SIT_IDENTITY) {
1133 n += snprintf(msg, SIT_MSG_NUM-n, "%sIDENTITY", sep);
1136 if (type & SIT_SECRECY) {
1137 n += snprintf(msg, SIT_MSG_NUM-n, "%sSECRECY", sep);
1140 if (type & SIT_INTEGRITY) {
1141 n += snprintf(msg, SIT_MSG_NUM-n, "%sINTEGRITY", sep);
1149 value2str(int ike_p1, guint16 att_type, guint16 value) {
1151 if (value == 0) return "RESERVED";
1157 case 1: return "Seconds";
1158 case 2: return "Kilobytes";
1159 default: return "UNKNOWN-SA-VALUE";
1162 return "Duration-Value";
1164 return "Group-Value";
1167 case 1: return "Tunnel";
1168 case 2: return "Transport";
1169 default: return "UNKNOWN-ENCAPSULATION-VALUE";
1173 case 1: return "HMAC-MD5";
1174 case 2: return "HMAC-SHA";
1175 case 3: return "DES-MAC";
1176 case 4: return "KPDK";
1177 default: return "UNKNOWN-AUTHENTICATION-VALUE";
1180 return "Key-Length";
1182 return "Key-Rounds";
1185 default: return "UNKNOWN-ATTRIBUTE-TYPE";
1192 case 1: return "DES-CBC";
1193 case 2: return "IDEA-CBC";
1194 case 3: return "BLOWFISH-CBC";
1195 case 4: return "RC5-R16-B64-CBC";
1196 case 5: return "3DES-CBC";
1197 case 6: return "CAST-CBC";
1198 default: return "UNKNOWN-ENCRYPTION-ALG";
1202 case 1: return "MD5";
1203 case 2: return "SHA";
1204 case 3: return "TIGER";
1205 default: return "UNKNOWN-HASH-ALG";
1209 case 1: return "PSK";
1210 case 2: return "DSS-SIG";
1211 case 3: return "RSA-SIG";
1212 case 4: return "RSA-ENC";
1213 case 5: return "RSA-Revised-ENC";
1214 default: return "UNKNOWN-AUTH-METHOD";
1223 return "Group-Value";
1226 case 1: return "MODP";
1227 case 2: return "ECP";
1228 case 3: return "EC2N";
1229 default: return "UNKNOWN-GROUPT-TYPE";
1233 case 1: return "Seconds";
1234 case 2: return "Kilobytes";
1235 default: return "UNKNOWN-SA-VALUE";
1238 return "Duration-Value";
1242 return "Key-Length";
1244 return "Field-Size";
1245 default: return "UNKNOWN-ATTRIBUTE-TYPE";
1251 num2str(const guint8 *pd, guint16 len) {
1253 #define NUMSTR_LEN 1024
1254 static char numstr[NUMSTR_LEN];
1258 snprintf(numstr, NUMSTR_LEN, "%u", *pd);
1261 snprintf(numstr, NUMSTR_LEN, "%u", pntohs(pd));
1264 snprintf(numstr, NUMSTR_LEN, "%u", pntohl(pd) & 0x0fff);
1267 snprintf(numstr, NUMSTR_LEN, "%u", pntohl(pd));
1270 snprintf(numstr, NUMSTR_LEN, "<too big>");
1277 proto_register_isakmp(void)
1279 /* static hf_register_info hf[] = {
1281 { "Name", "isakmp.abbreviation", TYPE, VALS_POINTER }},
1283 static gint *ett[] = {
1286 &ett_isakmp_payload,
1289 proto_isakmp = proto_register_protocol("Internet Security Association and Key Management Protocol", "isakmp");
1290 /* proto_register_field_array(proto_isakmp, hf, array_length(hf));*/
1291 proto_register_subtree_array(ett, array_length(ett));
1295 proto_reg_handoff_isakmp(void)
1297 dissector_add("udp.port", UDP_PORT_ISAKMP, dissect_isakmp);