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.39 2001/08/29 08:12:32 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * 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>
43 #ifdef NEED_SNPRINTF_H
44 # 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 11
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",
112 #define NUM_TRANS_TYPES 2
113 #define trans2str(t) \
114 ((t < NUM_TRANS_TYPES) ? transtypestr[t] : "UNKNOWN-TRANS-TYPE")
116 static const char *transtypestr[NUM_TRANS_TYPES] = {
121 #define NUM_AH_TRANS_TYPES 8
122 #define ah_trans2str(t) \
123 ((t < NUM_AH_TRANS_TYPES) ? ah_transtypestr[t] : "UNKNOWN-AH-TRANS-TYPE")
125 static const char *ah_transtypestr[NUM_AH_TRANS_TYPES] = {
136 #define NUM_ESP_TRANS_TYPES 13
137 #define esp_trans2str(t) \
138 ((t < NUM_ESP_TRANS_TYPES) ? esp_transtypestr[t] : "UNKNOWN-ESP-TRANS-TYPE")
140 static const char *esp_transtypestr[NUM_ESP_TRANS_TYPES] = {
156 #define NUM_ID_TYPES 12
158 ((t < NUM_ID_TYPES) ? idtypestr[t] : "UNKNOWN-ID-TYPE")
160 static const char *idtypestr[NUM_ID_TYPES] = {
185 guint8 message_id[4];
189 struct udp_encap_esp_hdr {
190 guint8 non_ike_marker[8];
195 static proto_tree *dissect_payload_header(tvbuff_t *, int, int, guint8,
196 guint8 *, guint16 *, proto_tree *);
198 static void dissect_none(tvbuff_t *, int, int, proto_tree *);
199 static void dissect_sa(tvbuff_t *, int, int, proto_tree *);
200 static void dissect_proposal(tvbuff_t *, int, int, proto_tree *);
201 static void dissect_transform(tvbuff_t *, int, int, proto_tree *, guint8);
202 static void dissect_key_exch(tvbuff_t *, int, int, proto_tree *);
203 static void dissect_id(tvbuff_t *, int, int, proto_tree *);
204 static void dissect_cert(tvbuff_t *, int, int, proto_tree *);
205 static void dissect_certreq(tvbuff_t *, int, int, proto_tree *);
206 static void dissect_hash(tvbuff_t *, int, int, proto_tree *);
207 static void dissect_sig(tvbuff_t *, int, int, proto_tree *);
208 static void dissect_nonce(tvbuff_t *, int, int, proto_tree *);
209 static void dissect_notif(tvbuff_t *, int, int, proto_tree *);
210 static void dissect_delete(tvbuff_t *, int, int, proto_tree *);
211 static void dissect_vid(tvbuff_t *, int, int, proto_tree *);
212 static void dissect_config(tvbuff_t *, int, int, proto_tree *);
214 static const char *payloadtype2str(guint8);
215 static const char *exchtype2str(guint8);
216 static const char *doitype2str(guint32);
217 static const char *msgtype2str(guint16);
218 static const char *situation2str(guint32);
219 static const char *value2str(int, guint16, guint16);
220 static const char *attrtype2str(guint8);
221 static const char *cfgattrident2str(guint16);
222 static const char *certtype2str(guint8);
224 static gboolean get_num(tvbuff_t *, int, guint16, guint32 *);
226 #define LOAD_TYPE_PROPOSAL 2 /* payload type for Proposal */
227 #define LOAD_TYPE_TRANSFORM 3 /* payload type for Transform */
228 #define NUM_LOAD_TYPES 15
229 #define loadtype2str(t) \
230 ((t < NUM_LOAD_TYPES) ? strfuncs[t].str : "Unknown payload type")
232 static struct strfunc {
234 void (*func)(tvbuff_t *, int, int, proto_tree *);
235 } strfuncs[NUM_LOAD_TYPES] = {
236 {"NONE", dissect_none },
237 {"Security Association", dissect_sa },
238 {"Proposal", dissect_proposal },
239 {"Transform", NULL },
240 {"Key Exchange", dissect_key_exch },
241 {"Identification", dissect_id },
242 {"Certificate", dissect_cert },
243 {"Certificate Request", dissect_certreq },
244 {"Hash", dissect_hash },
245 {"Signature", dissect_sig },
246 {"Nonce", dissect_nonce },
247 {"Notification", dissect_notif },
248 {"Delete", dissect_delete },
249 {"Vendor ID", dissect_vid },
250 {"Attrib", dissect_config }
253 static dissector_handle_t esp_handle;
256 dissect_isakmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
259 struct isakmp_hdr * hdr;
260 struct udp_encap_esp_hdr * udp_encap_hdr;
262 guint8 payload, next_payload;
263 guint16 payload_length;
265 static const guint8 non_ike_marker[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
268 if (check_col(pinfo->fd, COL_PROTOCOL))
269 col_set_str(pinfo->fd, COL_PROTOCOL, "ISAKMP");
270 if (check_col(pinfo->fd, COL_INFO))
271 col_clear(pinfo->fd, COL_INFO);
273 hdr = (struct isakmp_hdr *)tvb_get_ptr(tvb, 0, sizeof (struct isakmp_hdr));
274 udp_encap_hdr = (struct udp_encap_esp_hdr *)tvb_get_ptr(tvb, 0, sizeof(struct udp_encap_esp_hdr));
276 len = pntohl(&hdr->length);
278 if(memcmp(udp_encap_hdr->non_ike_marker,non_ike_marker,8) == 0) {
279 if (udp_encap_hdr->esp_SPI != 0) {
280 if (check_col(pinfo->fd, COL_INFO))
281 col_add_str(pinfo->fd, COL_INFO, "UDP encapsulated IPSec - ESP");
284 if (check_col(pinfo->fd, COL_INFO))
285 col_add_str(pinfo->fd, COL_INFO, "UDP encapsulated IPSec - AH");
289 proto_tree * isakmp_tree;
291 ti = proto_tree_add_item(tree, proto_isakmp, tvb, offset, len, FALSE);
292 isakmp_tree = proto_item_add_subtree(ti, ett_isakmp);
294 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(udp_encap_hdr->non_ike_marker),"Non-IKE-Marker");
295 offset += sizeof(udp_encap_hdr->non_ike_marker);
297 if (udp_encap_hdr->esp_SPI != 0) {
298 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
299 call_dissector(esp_handle, next_tvb, pinfo, tree);
301 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(udp_encap_hdr->esp_SPI),"Non-ESP-Marker");
302 offset += sizeof(udp_encap_hdr->esp_SPI);
305 * Dissect AH Envelope, and then call AH dissector.
312 if (check_col(pinfo->fd, COL_INFO))
313 col_add_str(pinfo->fd, COL_INFO, exchtype2str(hdr->exch_type));
317 proto_tree * isakmp_tree;
319 ti = proto_tree_add_item(tree, proto_isakmp, tvb, offset, len, FALSE);
320 isakmp_tree = proto_item_add_subtree(ti, ett_isakmp);
322 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->icookie),
324 offset += sizeof(hdr->icookie);
326 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->rcookie),
328 offset += sizeof(hdr->rcookie);
330 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->next_payload),
331 "Next payload: %s (%u)",
332 payloadtype2str(hdr->next_payload), hdr->next_payload);
333 offset += sizeof(hdr->next_payload);
335 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->version),
337 hi_nibble(hdr->version), lo_nibble(hdr->version));
338 offset += sizeof(hdr->version);
340 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->exch_type),
341 "Exchange type: %s (%u)",
342 exchtype2str(hdr->exch_type), hdr->exch_type);
343 offset += sizeof(hdr->exch_type);
349 fti = proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->flags), "Flags");
350 ftree = proto_item_add_subtree(fti, ett_isakmp_flags);
352 proto_tree_add_text(ftree, tvb, offset, 1, "%s",
353 decode_boolean_bitfield(hdr->flags, E_FLAG, sizeof(hdr->flags)*8,
354 "Encryption", "No encryption"));
355 proto_tree_add_text(ftree, tvb, offset, 1, "%s",
356 decode_boolean_bitfield(hdr->flags, C_FLAG, sizeof(hdr->flags)*8,
357 "Commit", "No commit"));
358 proto_tree_add_text(ftree, tvb, offset, 1, "%s",
359 decode_boolean_bitfield(hdr->flags, A_FLAG, sizeof(hdr->flags)*8,
360 "Authentication", "No authentication"));
361 offset += sizeof(hdr->flags);
364 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->message_id),
365 "Message ID: 0x%02x%02x%02x%02x", hdr->message_id[0],
366 hdr->message_id[1], hdr->message_id[2], hdr->message_id[3]);
367 offset += sizeof(hdr->message_id);
369 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->length),
371 offset += sizeof(hdr->length);
374 if (hdr->flags & E_FLAG) {
375 if (len && isakmp_tree) {
376 proto_tree_add_text(isakmp_tree, tvb, offset, len,
377 "Encrypted payload (%d byte%s)",
378 len, plurality(len, "", "s"));
381 for (payload = hdr->next_payload; len != 0; payload = next_payload) {
382 ntree = dissect_payload_header(tvb, offset, len, payload,
383 &next_payload, &payload_length, isakmp_tree);
386 if (payload_length >= 4) { /* XXX = > 4? */
387 if (payload < NUM_LOAD_TYPES) {
388 if (next_payload == LOAD_TYPE_TRANSFORM)
389 dissect_transform(tvb, offset + 4, payload_length - 4, ntree, 0);
390 /* XXX - protocol ID? */
392 (*strfuncs[payload].func)(tvb, offset + 4, payload_length - 4, ntree);
395 proto_tree_add_text(ntree, tvb, offset + 4, payload_length - 4,
400 proto_tree_add_text(ntree, tvb, offset + 4, 0,
401 "Payload (bogus, length is %u, must be at least 4)",
405 offset += payload_length;
406 len -= payload_length;
413 dissect_payload_header(tvbuff_t *tvb, int offset, int length, guint8 payload,
414 guint8 *next_payload_p, guint16 *payload_length_p, proto_tree *tree)
417 guint16 payload_length;
422 proto_tree_add_text(tree, tvb, offset, length,
423 "Not enough room in payload for all transforms");
426 next_payload = tvb_get_guint8(tvb, offset);
427 payload_length = tvb_get_ntohs(tvb, offset + 2);
429 ti = proto_tree_add_text(tree, tvb, offset, payload_length,
430 "%s payload", loadtype2str(payload));
431 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
433 proto_tree_add_text(ntree, tvb, offset, 1,
434 "Next payload: %s (%u)",
435 payloadtype2str(next_payload), next_payload);
436 proto_tree_add_text(ntree, tvb, offset+2, 2, "Length: %u", payload_length);
438 *next_payload_p = next_payload;
439 *payload_length_p = payload_length;
444 dissect_none(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
449 dissect_sa(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
454 guint16 payload_length;
457 doi = tvb_get_ntohl(tvb, offset);
458 proto_tree_add_text(tree, tvb, offset, 4,
459 "Domain of interpretation: %s (%u)",
460 doitype2str(doi), doi);
464 situation = tvb_get_ntohl(tvb, offset);
465 proto_tree_add_text(tree, tvb, offset, 4,
466 "Situation: %s (%u)",
467 situation2str(situation), situation);
471 ntree = dissect_payload_header(tvb, offset, length, LOAD_TYPE_PROPOSAL,
472 &next_payload, &payload_length, tree);
474 dissect_proposal(tvb, offset + 4, payload_length - 4, ntree);
478 dissect_proposal(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
482 guint8 num_transforms;
484 guint16 payload_length;
487 proto_tree_add_text(tree, tvb, offset, 1,
488 "Proposal number: %u", tvb_get_guint8(tvb, offset));
492 protocol_id = tvb_get_guint8(tvb, offset);
493 proto_tree_add_text(tree, tvb, offset, 1,
494 "Protocol ID: %s (%u)",
495 proto2str(protocol_id), protocol_id);
499 spi_size = tvb_get_guint8(tvb, offset);
500 proto_tree_add_text(tree, tvb, offset, 1,
501 "SPI size: %u", spi_size);
505 num_transforms = tvb_get_guint8(tvb, offset);
506 proto_tree_add_text(tree, tvb, offset, 1,
507 "Number of transforms: %u", num_transforms);
512 proto_tree_add_text(tree, tvb, offset, spi_size, "SPI");
517 while (num_transforms > 0) {
518 ntree = dissect_payload_header(tvb, offset, length, LOAD_TYPE_TRANSFORM,
519 &next_payload, &payload_length, tree);
522 if (length < payload_length) {
523 proto_tree_add_text(tree, tvb, offset + 4, length,
524 "Not enough room in payload for all transforms");
527 if (payload_length >= 4)
528 dissect_transform(tvb, offset + 4, payload_length - 4, ntree, protocol_id);
530 proto_tree_add_text(ntree, tvb, offset + 4, payload_length - 4, "Payload");
531 offset += payload_length;
532 length -= payload_length;
538 dissect_transform(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
543 proto_tree_add_text(tree, tvb, offset, 1,
544 "Transform number: %u", tvb_get_guint8(tvb, offset));
548 transform_id = tvb_get_guint8(tvb, offset);
549 switch (protocol_id) {
552 proto_tree_add_text(tree, tvb, offset, 1,
553 "Transform ID: %s (%u)",
554 trans2str(transform_id), transform_id);
557 proto_tree_add_text(tree, tvb, offset, 1,
558 "Transform ID: %s (%u)",
559 ah_trans2str(transform_id), transform_id);
562 proto_tree_add_text(tree, tvb, offset, 1,
563 "Transform ID: %s (%u)",
564 esp_trans2str(transform_id), transform_id);
573 guint16 aft = tvb_get_ntohs(tvb, offset);
574 guint16 type = aft & 0x7fff;
579 if (protocol_id == 1 && transform_id == 1) {
581 str = p1_atttype2str(type);
584 str = atttype2str(type);
588 val = tvb_get_ntohs(tvb, offset + 2);
589 proto_tree_add_text(tree, tvb, offset, 4,
592 value2str(ike_phase1, type, val), val);
597 len = tvb_get_ntohs(tvb, offset + 2);
599 if (!get_num(tvb, offset + 4, len, &val)) {
600 proto_tree_add_text(tree, tvb, offset, pack_len,
601 "%s (%u): <too big (%u bytes)>",
604 proto_tree_add_text(tree, tvb, offset, pack_len,
607 value2str(ike_phase1, type, val), val);
616 dissect_key_exch(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
618 proto_tree_add_text(tree, tvb, offset, length, "Key Exchange Data");
622 dissect_id(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
628 id_type = tvb_get_guint8(tvb, offset);
629 proto_tree_add_text(tree, tvb, offset, 1,
630 "ID type: %s (%u)", id2str(id_type), id_type);
634 protocol_id = tvb_get_guint8(tvb, offset);
635 if (protocol_id == 0) {
636 proto_tree_add_text(tree, tvb, offset, 1,
637 "Protocol ID: Unused");
639 proto_tree_add_text(tree, tvb, offset, 1,
640 "Protocol ID: %s (%u)",
641 ipprotostr(protocol_id), protocol_id);
646 port = tvb_get_ntohs(tvb, offset);
648 proto_tree_add_text(tree, tvb, offset, 2, "Port: Unused");
650 proto_tree_add_text(tree, tvb, offset, 2, "Port: %u", port);
657 proto_tree_add_text(tree, tvb, offset, length,
658 "Identification data: %s",
659 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
663 proto_tree_add_text(tree, tvb, offset, length,
664 "Identification data: %.*s", length,
665 tvb_get_ptr(tvb, offset, length));
668 proto_tree_add_text(tree, tvb, offset, length, "Identification Data");
674 dissect_cert(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
678 cert_enc = tvb_get_guint8(tvb, offset);
679 proto_tree_add_text(tree, tvb, offset, 1,
680 "Certificate encoding: %u - %s",
681 cert_enc, certtype2str(cert_enc));
685 proto_tree_add_text(tree, tvb, offset, length, "Certificate Data");
689 dissect_certreq(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
693 cert_type = tvb_get_guint8(tvb, offset);
694 proto_tree_add_text(tree, tvb, offset, 1,
695 "Certificate type: %u - %s",
696 cert_type, certtype2str(cert_type));
700 proto_tree_add_text(tree, tvb, offset, length, "Certificate Authority");
704 dissect_hash(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
706 proto_tree_add_text(tree, tvb, offset, length, "Hash Data");
710 dissect_sig(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
712 proto_tree_add_text(tree, tvb, offset, length, "Signature Data");
716 dissect_nonce(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
718 proto_tree_add_text(tree, tvb, offset, length, "Nonce Data");
722 dissect_notif(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
729 doi = tvb_get_ntohl(tvb, offset);
730 proto_tree_add_text(tree, tvb, offset, 4,
731 "Domain of Interpretation: %s (%u)",
732 doitype2str(doi), doi);
736 protocol_id = tvb_get_guint8(tvb, offset);
737 proto_tree_add_text(tree, tvb, offset, 1,
738 "Protocol ID: %s (%u)",
739 proto2str(protocol_id), protocol_id);
743 spi_size = tvb_get_guint8(tvb, offset);
744 proto_tree_add_text(tree, tvb, offset, 1,
745 "SPI size: %u", spi_size);
749 msgtype = tvb_get_ntohs(tvb, offset);
750 proto_tree_add_text(tree, tvb, offset, 2,
751 "Message type: %s (%u)", msgtype2str(msgtype), msgtype);
756 proto_tree_add_text(tree, tvb, offset, spi_size, "Security Parameter Index");
762 proto_tree_add_text(tree, tvb, offset, length, "Notification Data");
766 dissect_delete(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
774 doi = tvb_get_ntohl(tvb, offset);
775 proto_tree_add_text(tree, tvb, offset, 4,
776 "Domain of Interpretation: %s (%u)",
777 doitype2str(doi), doi);
781 protocol_id = tvb_get_guint8(tvb, offset);
782 proto_tree_add_text(tree, tvb, offset, 1,
783 "Protocol ID: %s (%u)",
784 proto2str(protocol_id), protocol_id);
788 spi_size = tvb_get_guint8(tvb, offset);
789 proto_tree_add_text(tree, tvb, offset, 1,
790 "SPI size: %u", spi_size);
794 num_spis = tvb_get_ntohs(tvb, offset);
795 proto_tree_add_text(tree, tvb, offset, 2,
796 "Number of SPIs: %u", num_spis);
800 for (i = 0; i < num_spis; ++i) {
801 if (length < spi_size) {
802 proto_tree_add_text(tree, tvb, offset, length,
803 "Not enough room in payload for all SPI's");
806 proto_tree_add_text(tree, tvb, offset, spi_size,
814 dissect_vid(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
816 proto_tree_add_text(tree, tvb, offset, length, "Vendor ID");
820 dissect_config(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
824 type = tvb_get_guint8(tvb, offset);
825 proto_tree_add_text(tree, tvb, offset, 1,
826 "Type %s (%u)",attrtype2str(type),type);
831 proto_tree_add_text(tree, tvb, offset, 2,
832 "Identifier: %u", tvb_get_ntohs(tvb, offset));
837 guint16 aft = tvb_get_ntohs(tvb, offset);
838 guint16 type = aft & 0x7fff;
844 val = tvb_get_ntohs(tvb, offset + 2);
845 proto_tree_add_text(tree, tvb, offset, 4,
846 "%s (%u)", cfgattrident2str(type), val);
851 len = tvb_get_ntohs(tvb, offset + 2);
853 if (!get_num(tvb, offset + 4, len, &val)) {
854 proto_tree_add_text(tree, tvb, offset, pack_len,
855 "%s: <too big (%u bytes)>",
856 cfgattrident2str(type), len);
858 proto_tree_add_text(tree, tvb, offset, 4,
859 "%s (%ue)", cfgattrident2str(type),
869 payloadtype2str(guint8 type) {
871 if (type < NUM_LOAD_TYPES) return strfuncs[type].str;
872 if (type < 128) return "RESERVED";
873 if (type < 256) return "Private USE";
875 return "Huh? You should never see this! Shame on you!";
879 exchtype2str(guint8 type) {
881 #define NUM_EXCHSTRS 7
882 static const char * exchstrs[NUM_EXCHSTRS] = {
885 "Identity Protection (Main Mode)",
886 "Authentication Only",
889 "Transaction (Config Mode)"
892 if (type < NUM_EXCHSTRS) return exchstrs[type];
893 if (type < 32) return "ISAKMP Future Use";
898 return "New Group Mode";
900 if (type < 240) return "DOI Specific Use";
901 if (type < 256) return "Private Use";
903 return "Huh? You should never see this! Shame on you!";
907 doitype2str(guint32 type) {
908 if (type == 1) return "IPSEC";
909 return "Unknown DOI Type";
913 msgtype2str(guint16 type) {
915 #define NUM_PREDEFINED 31
916 static const char *msgs[NUM_PREDEFINED] = {
918 "INVALID-PAYLOAD-TYPE",
920 "SITUATION-NOT-SUPPORTED",
922 "INVALID-MAJOR-VERSION",
923 "INVALID-MINOR-VERSION",
924 "INVALID-EXCHANGE-TYPE",
926 "INVALID-MESSAGE-ID",
927 "INVALID-PROTOCOL-ID",
929 "INVALID-TRANSFORM-ID",
930 "ATTRIBUTES-NOT-SUPPORTED",
931 "NO-PROPOSAL-CHOSEN",
932 "BAD-PROPOSAL-SYNTAX",
934 "INVALID-KEY-INFORMATION",
935 "INVALID-ID-INFORMATION",
936 "INVALID-CERT-ENCODING",
937 "INVALID-CERTIFICATE",
938 "CERT-TYPE-UNSUPPORTED",
939 "INVALID-CERT-AUTHORITY",
940 "INVALID-HASH-INFORMATION",
941 "AUTHENTICATION-FAILED",
943 "ADDRESS-NOTIFICATION",
944 "NOTIFY-SA-LIFETIME",
945 "CERTIFICATE-UNAVAILABLE",
946 "UNSUPPORTED-EXCHANGE-TYPE",
947 "UNEQUAL-PAYLOAD-LENGTHS"
950 if (type < NUM_PREDEFINED) return msgs[type];
951 if (type < 8192) return "RESERVED (Future Use)";
952 if (type < 16384) return "Private Use";
953 if (type < 16385) return "CONNECTED";
954 if (type < 24576) return "RESERVED (Future Use) - status";
955 if (type < 24577) return "RESPONDER-LIFETIME";
956 if (type < 24578) return "REPLAY-STATUS";
957 if (type < 24579) return "INITIAL-CONTACT";
958 if (type < 32768) return "DOI-specific codes";
959 if (type < 40960) return "Private Use - status";
960 if (type < 65535) return "RESERVED (Future Use) - status (2)";
962 return "Huh? You should never see this! Shame on you!";
966 situation2str(guint32 type) {
968 #define SIT_MSG_NUM 1024
969 #define SIT_IDENTITY 0x01
970 #define SIT_SECRECY 0x02
971 #define SIT_INTEGRITY 0x04
973 static char msg[SIT_MSG_NUM];
977 if (type & SIT_IDENTITY) {
978 n += snprintf(msg, SIT_MSG_NUM-n, "%sIDENTITY", sep);
981 if (type & SIT_SECRECY) {
982 n += snprintf(msg, SIT_MSG_NUM-n, "%sSECRECY", sep);
985 if (type & SIT_INTEGRITY) {
986 n += snprintf(msg, SIT_MSG_NUM-n, "%sINTEGRITY", sep);
994 value2str(int ike_p1, guint16 att_type, guint16 value) {
996 if (value == 0) return "RESERVED";
1002 case 1: return "Seconds";
1003 case 2: return "Kilobytes";
1004 default: return "UNKNOWN-SA-VALUE";
1007 return "Duration-Value";
1009 return "Group-Value";
1012 case 1: return "Tunnel";
1013 case 2: return "Transport";
1014 case 61440: return "Check Point IPSec UDP Encapsulation";
1015 case 61443: return "UDP-Encapsulated-Tunnel (draft)";
1016 case 61444: return "UDP-Encapsulated-Transport (draft)";
1017 default: return "UNKNOWN-ENCAPSULATION-VALUE";
1021 case 1: return "HMAC-MD5";
1022 case 2: return "HMAC-SHA";
1023 case 3: return "DES-MAC";
1024 case 4: return "KPDK";
1025 case 5: return "HMAC-SHA2-256";
1026 case 6: return "HMAC-SHA2-384";
1027 case 7: return "HMAC-SHA2-512";
1028 default: return "UNKNOWN-AUTHENTICATION-VALUE";
1031 return "Key-Length";
1033 return "Key-Rounds";
1036 default: return "UNKNOWN-ATTRIBUTE-TYPE";
1043 case 1: return "DES-CBC";
1044 case 2: return "IDEA-CBC";
1045 case 3: return "BLOWFISH-CBC";
1046 case 4: return "RC5-R16-B64-CBC";
1047 case 5: return "3DES-CBC";
1048 case 6: return "CAST-CBC";
1049 case 7: return "AES-CBC";
1050 default: return "UNKNOWN-ENCRYPTION-ALG";
1054 case 1: return "MD5";
1055 case 2: return "SHA";
1056 case 3: return "TIGER";
1057 case 4: return "SHA2-256";
1058 case 5: return "SHA2-384";
1059 case 6: return "SHA2-512";
1060 default: return "UNKNOWN-HASH-ALG";
1064 case 1: return "PSK";
1065 case 2: return "DSS-SIG";
1066 case 3: return "RSA-SIG";
1067 case 4: return "RSA-ENC";
1068 case 5: return "RSA-Revised-ENC";
1069 case 64221: return "HybridInitRSA";
1070 case 64222: return "HybridRespRSA";
1071 case 64223: return "HybridInitDSS";
1072 case 64224: return "HybridRespDSS";
1073 case 65001: return "XAUTHInitPreShared";
1074 case 65002: return "XAUTHRespPreShared";
1075 case 65003: return "XAUTHInitDSS";
1076 case 65004: return "XAUTHRespDSS";
1077 case 65005: return "XAUTHInitRSA";
1078 case 65006: return "XAUTHRespRSA";
1079 case 65007: return "XAUTHInitRSAEncryption";
1080 case 65008: return "XAUTHRespRSAEncryption";
1081 case 65009: return "XAUTHInitRSARevisedEncryption";
1082 case 65010: return "XAUTHRespRSARevisedEncryption";
1083 default: return "UNKNOWN-AUTH-METHOD";
1092 return "Group-Value";
1095 case 1: return "MODP";
1096 case 2: return "ECP";
1097 case 3: return "EC2N";
1098 default: return "UNKNOWN-GROUPT-TYPE";
1102 case 1: return "Seconds";
1103 case 2: return "Kilobytes";
1104 default: return "UNKNOWN-SA-VALUE";
1107 return "Duration-Value";
1111 return "Key-Length";
1113 return "Field-Size";
1114 default: return "UNKNOWN-ATTRIBUTE-TYPE";
1120 attrtype2str(guint8 type) {
1122 case 0: return "Reserved";
1123 case 1: return "ISAKMP_CFG_REQUEST";
1124 case 2: return "ISAKMP_CFG_REPLY";
1125 case 3: return "ISAKMP_CFG_SET";
1126 case 4: return "ISAKMP_CFG_ACK";
1129 return "Future use";
1130 return "Private use";
1134 cfgattrident2str(guint16 ident) {
1135 #define NUM_ATTR_DEFINED 12
1136 static const char *msgs[NUM_PREDEFINED] = {
1138 "INTERNAL_IP4_ADDRESS",
1139 "INTERNAL_IP4_NETMASK",
1141 "INTERNAL_IP4_NBNS",
1142 "INTERNAL_ADDRESS_EXPIREY",
1143 "INTERNAL_IP4_DHCP",
1144 "APPLICATION_VERSION"
1145 "INTERNAL_IP6_ADDRESS",
1146 "INTERNAL_IP6_NETMASK",
1148 "INTERNAL_IP6_NBNS",
1149 "INTERNAL_IP6_DHCP",
1151 if(ident < NUM_ATTR_DEFINED)
1154 return "Future use";
1156 case 16520: return "XAUTH_TYPE";
1157 case 16521: return "XAUTH_USER_NAME";
1158 case 16522: return "XAUTH_USER_PASSWORD";
1159 case 16523: return "XAUTH_PASSCODE";
1160 case 16524: return "XAUTH_MESSAGE";
1161 case 16525: return "XAUTH_CHALLANGE";
1162 case 16526: return "XAUTH_DOMAIN";
1163 case 16527: return "XAUTH_STATUS";
1164 default: return "Private use";
1169 certtype2str(guint8 type) {
1170 #define NUM_CERTTYPE 11
1171 static const char *msgs[NUM_CERTTYPE] = {
1173 "PKCS #7 wrapped X.509 certificate",
1176 "X.509 Certificate - Signature",
1177 "X.509 Certificate - Key Exchange",
1179 "Certificate Revocation List (CRL)",
1180 "Authority Revocation List (ARL)",
1182 "X.509 Certificate - Attribute",
1184 if(type > NUM_CERTTYPE)
1190 get_num(tvbuff_t *tvb, int offset, guint16 len, guint32 *num_p) {
1194 *num_p = tvb_get_guint8(tvb, offset);
1197 *num_p = tvb_get_ntohs(tvb, offset);
1200 *num_p = tvb_get_ntoh24(tvb, offset);
1203 *num_p = tvb_get_ntohl(tvb, offset);
1213 proto_register_isakmp(void)
1215 /* static hf_register_info hf[] = {
1217 { "Name", "isakmp.abbreviation", TYPE, VALS_POINTER }},
1219 static gint *ett[] = {
1222 &ett_isakmp_payload,
1225 proto_isakmp = proto_register_protocol("Internet Security Association and Key Management Protocol",
1226 "ISAKMP", "isakmp");
1227 /* proto_register_field_array(proto_isakmp, hf, array_length(hf));*/
1228 proto_register_subtree_array(ett, array_length(ett));
1232 proto_reg_handoff_isakmp(void)
1235 * Get handle for the ESP dissector.
1237 esp_handle = find_dissector("esp");
1239 dissector_add("udp.port", UDP_PORT_ISAKMP, dissect_isakmp, proto_isakmp);