2 * Routines for the Internet Security Association and Key Management Protocol
3 * (ISAKMP) (RFC 2408) and the Internet IP Security Domain of Interpretation
4 * for ISAKMP (RFC 2407)
5 * Brad Robel-Forrest <brad.robel-forrest@watchguard.com>
7 * $Id: packet-isakmp.c,v 1.55 2002/05/20 01:29:07 guy Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
11 * 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>
39 #ifdef HAVE_NETINET_IN_H
40 #include <netinet/in.h>
45 #ifdef NEED_SNPRINTF_H
46 # include "snprintf.h"
49 #include <epan/packet.h>
52 static int proto_isakmp = -1;
54 static gint ett_isakmp = -1;
55 static gint ett_isakmp_flags = -1;
56 static gint ett_isakmp_payload = -1;
58 #define UDP_PORT_ISAKMP 500
59 #define TCP_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 11
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",
115 #define NUM_TRANS_TYPES 2
116 #define trans2str(t) \
117 ((t < NUM_TRANS_TYPES) ? transtypestr[t] : "UNKNOWN-TRANS-TYPE")
119 static const char *transtypestr[NUM_TRANS_TYPES] = {
124 #define NUM_AH_TRANS_TYPES 8
125 #define ah_trans2str(t) \
126 ((t < NUM_AH_TRANS_TYPES) ? ah_transtypestr[t] : "UNKNOWN-AH-TRANS-TYPE")
128 static const char *ah_transtypestr[NUM_AH_TRANS_TYPES] = {
139 #define NUM_ESP_TRANS_TYPES 13
140 #define esp_trans2str(t) \
141 ((t < NUM_ESP_TRANS_TYPES) ? esp_transtypestr[t] : "UNKNOWN-ESP-TRANS-TYPE")
143 static const char *esp_transtypestr[NUM_ESP_TRANS_TYPES] = {
159 #define NUM_IPCOMP_TRANS_TYPES 5
160 #define ipcomp_trans2str(t) \
161 ((t < NUM_IPCOMP_TRANS_TYPES) ? ipcomp_transtypestr[t] : "UNKNOWN-IPCOMP-TRANS-TYPE")
163 static const char *ipcomp_transtypestr[NUM_IPCOMP_TRANS_TYPES] = {
171 #define NUM_ID_TYPES 12
173 ((t < NUM_ID_TYPES) ? idtypestr[t] : "UNKNOWN-ID-TYPE")
175 static const char *idtypestr[NUM_ID_TYPES] = {
200 guint8 message_id[4];
204 struct udp_encap_hdr {
205 guint8 non_esp_marker[4];
209 static proto_tree *dissect_payload_header(tvbuff_t *, int, int, guint8,
210 guint8 *, guint16 *, proto_tree *);
212 static void dissect_sa(tvbuff_t *, int, int, proto_tree *, int);
213 static void dissect_proposal(tvbuff_t *, int, int, proto_tree *, int);
214 static void dissect_transform(tvbuff_t *, int, int, proto_tree *, int);
215 static void dissect_key_exch(tvbuff_t *, int, int, proto_tree *, int);
216 static void dissect_id(tvbuff_t *, int, int, proto_tree *, int);
217 static void dissect_cert(tvbuff_t *, int, int, proto_tree *, int);
218 static void dissect_certreq(tvbuff_t *, int, int, proto_tree *, int);
219 static void dissect_hash(tvbuff_t *, int, int, proto_tree *, int);
220 static void dissect_sig(tvbuff_t *, int, int, proto_tree *, int);
221 static void dissect_nonce(tvbuff_t *, int, int, proto_tree *, int);
222 static void dissect_notif(tvbuff_t *, int, int, proto_tree *, int);
223 static void dissect_delete(tvbuff_t *, int, int, proto_tree *, int);
224 static void dissect_vid(tvbuff_t *, int, int, proto_tree *, int);
225 static void dissect_config(tvbuff_t *, int, int, proto_tree *, int);
227 static const char *payloadtype2str(guint8);
228 static const char *exchtype2str(guint8);
229 static const char *doitype2str(guint32);
230 static const char *msgtype2str(guint16);
231 static const char *situation2str(guint32);
232 static const char *value2str(int, guint16, guint16);
233 static const char *attrtype2str(guint8);
234 static const char *cfgattrident2str(guint16);
235 static const char *certtype2str(guint8);
237 static gboolean get_num(tvbuff_t *, int, guint16, guint32 *);
239 #define LOAD_TYPE_NONE 0 /* payload type for None */
240 #define LOAD_TYPE_PROPOSAL 2 /* payload type for Proposal */
241 #define LOAD_TYPE_TRANSFORM 3 /* payload type for Transform */
242 #define NUM_LOAD_TYPES 15
243 #define loadtype2str(t) \
244 ((t < NUM_LOAD_TYPES) ? strfuncs[t].str : "Unknown payload type")
246 static struct strfunc {
248 void (*func)(tvbuff_t *, int, int, proto_tree *, int);
249 } strfuncs[NUM_LOAD_TYPES] = {
251 {"Security Association", dissect_sa },
252 {"Proposal", dissect_proposal },
253 {"Transform", dissect_transform },
254 {"Key Exchange", dissect_key_exch },
255 {"Identification", dissect_id },
256 {"Certificate", dissect_cert },
257 {"Certificate Request", dissect_certreq },
258 {"Hash", dissect_hash },
259 {"Signature", dissect_sig },
260 {"Nonce", dissect_nonce },
261 {"Notification", dissect_notif },
262 {"Delete", dissect_delete },
263 {"Vendor ID", dissect_vid },
264 {"Attrib", dissect_config }
267 static dissector_handle_t esp_handle;
268 static dissector_handle_t ah_handle;
271 dissect_payloads(tvbuff_t *tvb, proto_tree *tree, guint8 initial_payload,
272 int offset, int length)
274 guint8 payload, next_payload;
275 guint16 payload_length;
278 for (payload = initial_payload; length != 0; payload = next_payload) {
279 if (payload == LOAD_TYPE_NONE) {
281 * What? There's more stuff in this chunk of data, but the
282 * previous payload had a "next payload" type of None?
284 proto_tree_add_text(tree, tvb, offset, length,
286 tvb_bytes_to_str(tvb, offset, length));
289 ntree = dissect_payload_header(tvb, offset, length, payload,
290 &next_payload, &payload_length, tree);
293 if (payload_length >= 4) { /* XXX = > 4? */
294 if (payload < NUM_LOAD_TYPES) {
295 (*strfuncs[payload].func)(tvb, offset + 4, payload_length - 4, ntree,
299 proto_tree_add_text(ntree, tvb, offset + 4, payload_length - 4,
304 proto_tree_add_text(ntree, tvb, offset + 4, 0,
305 "Payload (bogus, length is %u, must be at least 4)",
309 offset += payload_length;
310 length -= payload_length;
315 dissect_isakmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
318 struct isakmp_hdr * hdr;
320 proto_tree * isakmp_tree = NULL;
321 struct udp_encap_hdr * encap_hdr;
323 static const guint8 non_esp_marker[4] = { 0, 0, 0, 0 };
326 if (check_col(pinfo->cinfo, COL_PROTOCOL))
327 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ISAKMP");
328 if (check_col(pinfo->cinfo, COL_INFO))
329 col_clear(pinfo->cinfo, COL_INFO);
331 hdr = (struct isakmp_hdr *)tvb_get_ptr(tvb, 0, sizeof (struct isakmp_hdr));
332 len = pntohl(&hdr->length);
335 ti = proto_tree_add_item(tree, proto_isakmp, tvb, offset, len, FALSE);
336 isakmp_tree = proto_item_add_subtree(ti, ett_isakmp);
339 encap_hdr = (struct udp_encap_hdr *)tvb_get_ptr(tvb, 0, sizeof(struct udp_encap_hdr));
341 if (encap_hdr->non_esp_marker[0] == 0xFF) {
342 if (check_col(pinfo->cinfo, COL_INFO))
343 col_set_str(pinfo->cinfo, COL_INFO, "UDP encapsulated IPSec - NAT Keepalive");
346 if (memcmp(encap_hdr->non_esp_marker,non_esp_marker,4) == 0) {
347 if (check_col(pinfo->cinfo, COL_INFO))
348 col_set_str(pinfo->cinfo, COL_INFO, "UDP encapsulated IPSec - ESP");
350 proto_tree_add_text(isakmp_tree, tvb, offset,
351 sizeof(encap_hdr->non_esp_marker),
353 offset += sizeof(encap_hdr->non_esp_marker);
354 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
355 call_dissector(esp_handle, next_tvb, pinfo, tree);
359 if (check_col(pinfo->cinfo, COL_INFO))
360 col_add_str(pinfo->cinfo, COL_INFO, exchtype2str(hdr->exch_type));
363 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->icookie),
365 offset += sizeof(hdr->icookie);
367 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->rcookie),
369 offset += sizeof(hdr->rcookie);
371 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->next_payload),
372 "Next payload: %s (%u)",
373 payloadtype2str(hdr->next_payload), hdr->next_payload);
374 offset += sizeof(hdr->next_payload);
376 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->version),
378 hi_nibble(hdr->version), lo_nibble(hdr->version));
379 offset += sizeof(hdr->version);
381 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->exch_type),
382 "Exchange type: %s (%u)",
383 exchtype2str(hdr->exch_type), hdr->exch_type);
384 offset += sizeof(hdr->exch_type);
390 fti = proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->flags), "Flags");
391 ftree = proto_item_add_subtree(fti, ett_isakmp_flags);
393 proto_tree_add_text(ftree, tvb, offset, 1, "%s",
394 decode_boolean_bitfield(hdr->flags, E_FLAG, sizeof(hdr->flags)*8,
395 "Encryption", "No encryption"));
396 proto_tree_add_text(ftree, tvb, offset, 1, "%s",
397 decode_boolean_bitfield(hdr->flags, C_FLAG, sizeof(hdr->flags)*8,
398 "Commit", "No commit"));
399 proto_tree_add_text(ftree, tvb, offset, 1, "%s",
400 decode_boolean_bitfield(hdr->flags, A_FLAG, sizeof(hdr->flags)*8,
401 "Authentication", "No authentication"));
402 offset += sizeof(hdr->flags);
405 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->message_id),
406 "Message ID: 0x%02x%02x%02x%02x", hdr->message_id[0],
407 hdr->message_id[1], hdr->message_id[2], hdr->message_id[3]);
408 offset += sizeof(hdr->message_id);
410 proto_tree_add_text(isakmp_tree, tvb, offset, sizeof(hdr->length),
412 offset += sizeof(hdr->length);
415 if (hdr->flags & E_FLAG) {
416 if (len && isakmp_tree) {
417 proto_tree_add_text(isakmp_tree, tvb, offset, len,
418 "Encrypted payload (%d byte%s)",
419 len, plurality(len, "", "s"));
422 dissect_payloads(tvb, isakmp_tree, hdr->next_payload, offset, len);
427 dissect_payload_header(tvbuff_t *tvb, int offset, int length, guint8 payload,
428 guint8 *next_payload_p, guint16 *payload_length_p, proto_tree *tree)
431 guint16 payload_length;
436 proto_tree_add_text(tree, tvb, offset, length,
437 "Not enough room in payload for all transforms");
440 next_payload = tvb_get_guint8(tvb, offset);
441 payload_length = tvb_get_ntohs(tvb, offset + 2);
443 ti = proto_tree_add_text(tree, tvb, offset, payload_length,
444 "%s payload", loadtype2str(payload));
445 ntree = proto_item_add_subtree(ti, ett_isakmp_payload);
447 proto_tree_add_text(ntree, tvb, offset, 1,
448 "Next payload: %s (%u)",
449 payloadtype2str(next_payload), next_payload);
450 proto_tree_add_text(ntree, tvb, offset+2, 2, "Length: %u", payload_length);
452 *next_payload_p = next_payload;
453 *payload_length_p = payload_length;
458 dissect_sa(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
465 proto_tree_add_text(tree, tvb, offset, length,
466 "DOI %s (length is %u, should be >= 4)",
467 tvb_bytes_to_str(tvb, offset, length), length);
470 doi = tvb_get_ntohl(tvb, offset);
471 proto_tree_add_text(tree, tvb, offset, 4,
472 "Domain of interpretation: %s (%u)",
473 doitype2str(doi), doi);
480 proto_tree_add_text(tree, tvb, offset, length,
481 "Situation: %s (length is %u, should be >= 4)",
482 tvb_bytes_to_str(tvb, offset, length), length);
485 situation = tvb_get_ntohl(tvb, offset);
486 proto_tree_add_text(tree, tvb, offset, 4,
487 "Situation: %s (%u)",
488 situation2str(situation), situation);
492 dissect_payloads(tvb, tree, LOAD_TYPE_PROPOSAL, offset, length);
495 proto_tree_add_text(tree, tvb, offset, length,
497 tvb_bytes_to_str(tvb, offset, length));
502 dissect_proposal(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
507 guint8 num_transforms;
509 guint16 payload_length;
512 proto_tree_add_text(tree, tvb, offset, 1,
513 "Proposal number: %u", tvb_get_guint8(tvb, offset));
517 protocol_id = tvb_get_guint8(tvb, offset);
518 proto_tree_add_text(tree, tvb, offset, 1,
519 "Protocol ID: %s (%u)",
520 proto2str(protocol_id), protocol_id);
524 spi_size = tvb_get_guint8(tvb, offset);
525 proto_tree_add_text(tree, tvb, offset, 1,
526 "SPI size: %u", spi_size);
530 num_transforms = tvb_get_guint8(tvb, offset);
531 proto_tree_add_text(tree, tvb, offset, 1,
532 "Number of transforms: %u", num_transforms);
537 proto_tree_add_text(tree, tvb, offset, spi_size, "SPI: %s",
538 tvb_bytes_to_str(tvb, offset, spi_size));
543 while (num_transforms > 0) {
544 ntree = dissect_payload_header(tvb, offset, length, LOAD_TYPE_TRANSFORM,
545 &next_payload, &payload_length, tree);
548 if (length < payload_length) {
549 proto_tree_add_text(tree, tvb, offset + 4, length,
550 "Not enough room in payload for all transforms");
553 if (payload_length >= 4)
554 dissect_transform(tvb, offset + 4, payload_length - 4, ntree, protocol_id);
556 proto_tree_add_text(ntree, tvb, offset + 4, payload_length - 4, "Payload");
557 offset += payload_length;
558 length -= payload_length;
564 dissect_transform(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
569 proto_tree_add_text(tree, tvb, offset, 1,
570 "Transform number: %u", tvb_get_guint8(tvb, offset));
574 transform_id = tvb_get_guint8(tvb, offset);
575 switch (protocol_id) {
577 proto_tree_add_text(tree, tvb, offset, 1,
578 "Transform ID: %u", transform_id);
581 proto_tree_add_text(tree, tvb, offset, 1,
582 "Transform ID: %s (%u)",
583 trans2str(transform_id), transform_id);
586 proto_tree_add_text(tree, tvb, offset, 1,
587 "Transform ID: %s (%u)",
588 ah_trans2str(transform_id), transform_id);
591 proto_tree_add_text(tree, tvb, offset, 1,
592 "Transform ID: %s (%u)",
593 esp_trans2str(transform_id), transform_id);
596 proto_tree_add_text(tree, tvb, offset, 1,
597 "Transform ID: %s (%u)",
598 ipcomp_trans2str(transform_id), transform_id);
607 guint16 aft = tvb_get_ntohs(tvb, offset);
608 guint16 type = aft & 0x7fff;
613 if (protocol_id == 1 && transform_id == 1) {
615 str = p1_atttype2str(type);
618 str = atttype2str(type);
622 val = tvb_get_ntohs(tvb, offset + 2);
623 proto_tree_add_text(tree, tvb, offset, 4,
626 value2str(ike_phase1, type, val), val);
631 len = tvb_get_ntohs(tvb, offset + 2);
633 if (!get_num(tvb, offset + 4, len, &val)) {
634 proto_tree_add_text(tree, tvb, offset, pack_len,
635 "%s (%u): <too big (%u bytes)>",
638 proto_tree_add_text(tree, tvb, offset, pack_len,
641 value2str(ike_phase1, type, val), val);
650 dissect_key_exch(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
653 proto_tree_add_text(tree, tvb, offset, length, "Key Exchange Data");
657 dissect_id(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
664 id_type = tvb_get_guint8(tvb, offset);
665 proto_tree_add_text(tree, tvb, offset, 1,
666 "ID type: %s (%u)", id2str(id_type), id_type);
670 protocol_id = tvb_get_guint8(tvb, offset);
671 if (protocol_id == 0) {
672 proto_tree_add_text(tree, tvb, offset, 1,
673 "Protocol ID: Unused");
675 proto_tree_add_text(tree, tvb, offset, 1,
676 "Protocol ID: %s (%u)",
677 ipprotostr(protocol_id), protocol_id);
682 port = tvb_get_ntohs(tvb, offset);
684 proto_tree_add_text(tree, tvb, offset, 2, "Port: Unused");
686 proto_tree_add_text(tree, tvb, offset, 2, "Port: %u", port);
692 proto_tree_add_text(tree, tvb, offset, length,
693 "Identification data: %s",
694 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
698 proto_tree_add_text(tree, tvb, offset, length,
699 "Identification data: %.*s", length,
700 tvb_get_ptr(tvb, offset, length));
703 proto_tree_add_text(tree, tvb, offset, length,
704 "Identification data: %s/%s",
705 ip_to_str(tvb_get_ptr(tvb, offset, 4)),
706 ip_to_str(tvb_get_ptr(tvb, offset+4, 4)));
709 proto_tree_add_text(tree, tvb, offset, length, "Identification Data");
715 dissect_cert(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
720 cert_enc = tvb_get_guint8(tvb, offset);
721 proto_tree_add_text(tree, tvb, offset, 1,
722 "Certificate encoding: %u - %s",
723 cert_enc, certtype2str(cert_enc));
727 proto_tree_add_text(tree, tvb, offset, length, "Certificate Data");
731 dissect_certreq(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
736 cert_type = tvb_get_guint8(tvb, offset);
737 proto_tree_add_text(tree, tvb, offset, 1,
738 "Certificate type: %u - %s",
739 cert_type, certtype2str(cert_type));
743 proto_tree_add_text(tree, tvb, offset, length, "Certificate Authority");
747 dissect_hash(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
750 proto_tree_add_text(tree, tvb, offset, length, "Hash Data");
754 dissect_sig(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
757 proto_tree_add_text(tree, tvb, offset, length, "Signature Data");
761 dissect_nonce(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
764 proto_tree_add_text(tree, tvb, offset, length, "Nonce Data");
768 dissect_notif(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
776 doi = tvb_get_ntohl(tvb, offset);
777 proto_tree_add_text(tree, tvb, offset, 4,
778 "Domain of Interpretation: %s (%u)",
779 doitype2str(doi), doi);
783 protocol_id = tvb_get_guint8(tvb, offset);
784 proto_tree_add_text(tree, tvb, offset, 1,
785 "Protocol ID: %s (%u)",
786 proto2str(protocol_id), protocol_id);
790 spi_size = tvb_get_guint8(tvb, offset);
791 proto_tree_add_text(tree, tvb, offset, 1,
792 "SPI size: %u", spi_size);
796 msgtype = tvb_get_ntohs(tvb, offset);
797 proto_tree_add_text(tree, tvb, offset, 2,
798 "Message type: %s (%u)", msgtype2str(msgtype), msgtype);
803 proto_tree_add_text(tree, tvb, offset, spi_size, "Security Parameter Index");
809 proto_tree_add_text(tree, tvb, offset, length, "Notification Data");
813 dissect_delete(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
822 doi = tvb_get_ntohl(tvb, offset);
823 proto_tree_add_text(tree, tvb, offset, 4,
824 "Domain of Interpretation: %s (%u)",
825 doitype2str(doi), doi);
829 protocol_id = tvb_get_guint8(tvb, offset);
830 proto_tree_add_text(tree, tvb, offset, 1,
831 "Protocol ID: %s (%u)",
832 proto2str(protocol_id), protocol_id);
836 spi_size = tvb_get_guint8(tvb, offset);
837 proto_tree_add_text(tree, tvb, offset, 1,
838 "SPI size: %u", spi_size);
842 num_spis = tvb_get_ntohs(tvb, offset);
843 proto_tree_add_text(tree, tvb, offset, 2,
844 "Number of SPIs: %u", num_spis);
848 for (i = 0; i < num_spis; ++i) {
849 if (length < spi_size) {
850 proto_tree_add_text(tree, tvb, offset, length,
851 "Not enough room in payload for all SPI's");
854 proto_tree_add_text(tree, tvb, offset, spi_size,
862 dissect_vid(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
865 proto_tree_add_text(tree, tvb, offset, length, "Vendor ID");
869 dissect_config(tvbuff_t *tvb, int offset, int length, proto_tree *tree,
874 type = tvb_get_guint8(tvb, offset);
875 proto_tree_add_text(tree, tvb, offset, 1,
876 "Type %s (%u)",attrtype2str(type),type);
881 proto_tree_add_text(tree, tvb, offset, 2,
882 "Identifier: %u", tvb_get_ntohs(tvb, offset));
887 guint16 aft = tvb_get_ntohs(tvb, offset);
888 guint16 type = aft & 0x7fff;
894 val = tvb_get_ntohs(tvb, offset + 2);
895 proto_tree_add_text(tree, tvb, offset, 4,
896 "%s (%u)", cfgattrident2str(type), val);
901 len = tvb_get_ntohs(tvb, offset + 2);
903 if (!get_num(tvb, offset + 4, len, &val)) {
904 proto_tree_add_text(tree, tvb, offset, pack_len,
905 "%s: <too big (%u bytes)>",
906 cfgattrident2str(type), len);
908 proto_tree_add_text(tree, tvb, offset, 4,
909 "%s (%ue)", cfgattrident2str(type),
919 payloadtype2str(guint8 type) {
921 if (type < NUM_LOAD_TYPES) return strfuncs[type].str;
922 if (type < 128) return "RESERVED";
923 if (type < 256) return "Private USE";
925 return "Huh? You should never see this! Shame on you!";
929 exchtype2str(guint8 type) {
931 #define NUM_EXCHSTRS 7
932 static const char * exchstrs[NUM_EXCHSTRS] = {
935 "Identity Protection (Main Mode)",
936 "Authentication Only",
939 "Transaction (Config Mode)"
942 if (type < NUM_EXCHSTRS) return exchstrs[type];
943 if (type < 32) return "ISAKMP Future Use";
948 return "New Group Mode";
950 if (type < 240) return "DOI Specific Use";
951 if (type < 256) return "Private Use";
953 return "Huh? You should never see this! Shame on you!";
957 doitype2str(guint32 type) {
958 if (type == 1) return "IPSEC";
959 return "Unknown DOI Type";
963 msgtype2str(guint16 type) {
965 #define NUM_PREDEFINED 31
966 static const char *msgs[NUM_PREDEFINED] = {
968 "INVALID-PAYLOAD-TYPE",
970 "SITUATION-NOT-SUPPORTED",
972 "INVALID-MAJOR-VERSION",
973 "INVALID-MINOR-VERSION",
974 "INVALID-EXCHANGE-TYPE",
976 "INVALID-MESSAGE-ID",
977 "INVALID-PROTOCOL-ID",
979 "INVALID-TRANSFORM-ID",
980 "ATTRIBUTES-NOT-SUPPORTED",
981 "NO-PROPOSAL-CHOSEN",
982 "BAD-PROPOSAL-SYNTAX",
984 "INVALID-KEY-INFORMATION",
985 "INVALID-ID-INFORMATION",
986 "INVALID-CERT-ENCODING",
987 "INVALID-CERTIFICATE",
988 "CERT-TYPE-UNSUPPORTED",
989 "INVALID-CERT-AUTHORITY",
990 "INVALID-HASH-INFORMATION",
991 "AUTHENTICATION-FAILED",
993 "ADDRESS-NOTIFICATION",
994 "NOTIFY-SA-LIFETIME",
995 "CERTIFICATE-UNAVAILABLE",
996 "UNSUPPORTED-EXCHANGE-TYPE",
997 "UNEQUAL-PAYLOAD-LENGTHS"
1000 if (type < NUM_PREDEFINED) return msgs[type];
1001 if (type < 8192) return "RESERVED (Future Use)";
1002 if (type < 16384) return "Private Use";
1003 if (type < 16385) return "CONNECTED";
1004 if (type < 24576) return "RESERVED (Future Use) - status";
1005 if (type < 24577) return "RESPONDER-LIFETIME";
1006 if (type < 24578) return "REPLAY-STATUS";
1007 if (type < 24579) return "INITIAL-CONTACT";
1008 if (type < 32768) return "DOI-specific codes";
1009 if (type < 40960) return "Private Use - status";
1010 if (type < 65535) return "RESERVED (Future Use) - status (2)";
1012 return "Huh? You should never see this! Shame on you!";
1016 situation2str(guint32 type) {
1018 #define SIT_MSG_NUM 1024
1019 #define SIT_IDENTITY 0x01
1020 #define SIT_SECRECY 0x02
1021 #define SIT_INTEGRITY 0x04
1023 static char msg[SIT_MSG_NUM];
1028 if (type & SIT_IDENTITY) {
1029 ret = snprintf(msg, SIT_MSG_NUM-n, "%sIDENTITY", sep);
1031 /* Some versions of snprintf return -1 if they'd truncate the output. */
1037 if (type & SIT_SECRECY) {
1038 if (n >= SIT_MSG_NUM) {
1042 ret = snprintf(msg, SIT_MSG_NUM-n, "%sSECRECY", sep);
1044 /* Some versions of snprintf return -1 if they'd truncate the output. */
1050 if (type & SIT_INTEGRITY) {
1051 if (n >= SIT_MSG_NUM) {
1055 ret = snprintf(msg, SIT_MSG_NUM-n, "%sINTEGRITY", sep);
1057 /* Some versions of snprintf return -1 if they'd truncate the output. */
1068 value2str(int ike_p1, guint16 att_type, guint16 value) {
1070 if (value == 0) return "RESERVED";
1076 case 1: return "Seconds";
1077 case 2: return "Kilobytes";
1078 default: return "UNKNOWN-SA-VALUE";
1081 return "Duration-Value";
1083 return "Group-Value";
1086 case 1: return "Tunnel";
1087 case 2: return "Transport";
1088 case 61440: return "Check Point IPSec UDP Encapsulation";
1089 case 61443: return "UDP-Encapsulated-Tunnel (draft)";
1090 case 61444: return "UDP-Encapsulated-Transport (draft)";
1091 default: return "UNKNOWN-ENCAPSULATION-VALUE";
1095 case 1: return "HMAC-MD5";
1096 case 2: return "HMAC-SHA";
1097 case 3: return "DES-MAC";
1098 case 4: return "KPDK";
1099 case 5: return "HMAC-SHA2-256";
1100 case 6: return "HMAC-SHA2-384";
1101 case 7: return "HMAC-SHA2-512";
1102 default: return "UNKNOWN-AUTHENTICATION-VALUE";
1105 return "Key-Length";
1107 return "Key-Rounds";
1110 default: return "UNKNOWN-ATTRIBUTE-TYPE";
1117 case 1: return "DES-CBC";
1118 case 2: return "IDEA-CBC";
1119 case 3: return "BLOWFISH-CBC";
1120 case 4: return "RC5-R16-B64-CBC";
1121 case 5: return "3DES-CBC";
1122 case 6: return "CAST-CBC";
1123 case 7: return "AES-CBC";
1124 default: return "UNKNOWN-ENCRYPTION-ALG";
1128 case 1: return "MD5";
1129 case 2: return "SHA";
1130 case 3: return "TIGER";
1131 case 4: return "SHA2-256";
1132 case 5: return "SHA2-384";
1133 case 6: return "SHA2-512";
1134 default: return "UNKNOWN-HASH-ALG";
1138 case 1: return "PSK";
1139 case 2: return "DSS-SIG";
1140 case 3: return "RSA-SIG";
1141 case 4: return "RSA-ENC";
1142 case 5: return "RSA-Revised-ENC";
1143 case 64221: return "HybridInitRSA";
1144 case 64222: return "HybridRespRSA";
1145 case 64223: return "HybridInitDSS";
1146 case 64224: return "HybridRespDSS";
1147 case 65001: return "XAUTHInitPreShared";
1148 case 65002: return "XAUTHRespPreShared";
1149 case 65003: return "XAUTHInitDSS";
1150 case 65004: return "XAUTHRespDSS";
1151 case 65005: return "XAUTHInitRSA";
1152 case 65006: return "XAUTHRespRSA";
1153 case 65007: return "XAUTHInitRSAEncryption";
1154 case 65008: return "XAUTHRespRSAEncryption";
1155 case 65009: return "XAUTHInitRSARevisedEncryption";
1156 case 65010: return "XAUTHRespRSARevisedEncryption";
1157 default: return "UNKNOWN-AUTH-METHOD";
1166 return "Group-Value";
1169 case 1: return "MODP";
1170 case 2: return "ECP";
1171 case 3: return "EC2N";
1172 default: return "UNKNOWN-GROUPT-TYPE";
1176 case 1: return "Seconds";
1177 case 2: return "Kilobytes";
1178 default: return "UNKNOWN-SA-VALUE";
1181 return "Duration-Value";
1185 return "Key-Length";
1187 return "Field-Size";
1188 default: return "UNKNOWN-ATTRIBUTE-TYPE";
1194 attrtype2str(guint8 type) {
1196 case 0: return "Reserved";
1197 case 1: return "ISAKMP_CFG_REQUEST";
1198 case 2: return "ISAKMP_CFG_REPLY";
1199 case 3: return "ISAKMP_CFG_SET";
1200 case 4: return "ISAKMP_CFG_ACK";
1203 return "Future use";
1204 return "Private use";
1208 cfgattrident2str(guint16 ident) {
1209 #define NUM_ATTR_DEFINED 12
1210 static const char *msgs[NUM_PREDEFINED] = {
1212 "INTERNAL_IP4_ADDRESS",
1213 "INTERNAL_IP4_NETMASK",
1215 "INTERNAL_IP4_NBNS",
1216 "INTERNAL_ADDRESS_EXPIREY",
1217 "INTERNAL_IP4_DHCP",
1218 "APPLICATION_VERSION"
1219 "INTERNAL_IP6_ADDRESS",
1220 "INTERNAL_IP6_NETMASK",
1222 "INTERNAL_IP6_NBNS",
1223 "INTERNAL_IP6_DHCP",
1225 if(ident < NUM_ATTR_DEFINED)
1228 return "Future use";
1230 case 16520: return "XAUTH_TYPE";
1231 case 16521: return "XAUTH_USER_NAME";
1232 case 16522: return "XAUTH_USER_PASSWORD";
1233 case 16523: return "XAUTH_PASSCODE";
1234 case 16524: return "XAUTH_MESSAGE";
1235 case 16525: return "XAUTH_CHALLANGE";
1236 case 16526: return "XAUTH_DOMAIN";
1237 case 16527: return "XAUTH_STATUS";
1238 case 16528: return "XAUTH_NEXT_PIN";
1239 case 16529: return "XAUTH_ANSWER";
1240 default: return "Private use";
1245 certtype2str(guint8 type) {
1246 #define NUM_CERTTYPE 11
1247 static const char *msgs[NUM_CERTTYPE] = {
1249 "PKCS #7 wrapped X.509 certificate",
1252 "X.509 Certificate - Signature",
1253 "X.509 Certificate - Key Exchange",
1255 "Certificate Revocation List (CRL)",
1256 "Authority Revocation List (ARL)",
1258 "X.509 Certificate - Attribute",
1260 if(type > NUM_CERTTYPE)
1266 get_num(tvbuff_t *tvb, int offset, guint16 len, guint32 *num_p) {
1270 *num_p = tvb_get_guint8(tvb, offset);
1273 *num_p = tvb_get_ntohs(tvb, offset);
1276 *num_p = tvb_get_ntoh24(tvb, offset);
1279 *num_p = tvb_get_ntohl(tvb, offset);
1289 proto_register_isakmp(void)
1291 /* static hf_register_info hf[] = {
1293 { "Name", "isakmp.abbreviation", TYPE, VALS_POINTER }},
1295 static gint *ett[] = {
1298 &ett_isakmp_payload,
1301 proto_isakmp = proto_register_protocol("Internet Security Association and Key Management Protocol",
1302 "ISAKMP", "isakmp");
1303 /* proto_register_field_array(proto_isakmp, hf, array_length(hf));*/
1304 proto_register_subtree_array(ett, array_length(ett));
1308 proto_reg_handoff_isakmp(void)
1310 dissector_handle_t isakmp_handle;
1313 * Get handle for the AH & ESP dissectors.
1315 esp_handle = find_dissector("esp");
1316 ah_handle = find_dissector("ah");
1318 isakmp_handle = create_dissector_handle(dissect_isakmp, proto_isakmp);
1319 dissector_add("udp.port", UDP_PORT_ISAKMP, isakmp_handle);
1320 dissector_add("tcp.port", TCP_PORT_ISAKMP, isakmp_handle);