blob: 3dfa171f2bb5d192ba327749dbf5dbe82640b41f [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
Elliott Hughese2e3bd12017-05-15 10:59:29 -070031/* \summary: Internet Security Association and Key Management Protocol (ISAKMP) printer */
32
The Android Open Source Project2949f582009-03-03 19:30:46 -080033#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif
36
JP Abgrall53f17a92014-02-12 14:02:41 -080037/* The functions from print-esp.c used in this file are only defined when both
38 * OpenSSL and evp.h are detected. Employ the same preprocessor device here.
39 */
40#ifndef HAVE_OPENSSL_EVP_H
41#undef HAVE_LIBCRYPTO
42#endif
43
Elliott Hughese2e3bd12017-05-15 10:59:29 -070044#include <netdissect-stdinc.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080045
46#include <string.h>
47
Elliott Hughese2e3bd12017-05-15 10:59:29 -070048#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080049#include "addrtoname.h"
Elliott Hughese2e3bd12017-05-15 10:59:29 -070050#include "extract.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080051
52#include "ip.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080053#include "ip6.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080054
Elliott Hughes892a68b2015-10-19 14:43:53 -070055/* refer to RFC 2408 */
56
57typedef u_char cookie_t[8];
58typedef u_char msgid_t[4];
59
60#define PORT_ISAKMP 500
61
62/* 3.1 ISAKMP Header Format (IKEv1 and IKEv2)
63 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
64 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65 ! Initiator !
66 ! Cookie !
67 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 ! Responder !
69 ! Cookie !
70 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 ! Next Payload ! MjVer ! MnVer ! Exchange Type ! Flags !
72 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 ! Message ID !
74 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75 ! Length !
76 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77*/
78struct isakmp {
79 cookie_t i_ck; /* Initiator Cookie */
80 cookie_t r_ck; /* Responder Cookie */
81 uint8_t np; /* Next Payload Type */
82 uint8_t vers;
83#define ISAKMP_VERS_MAJOR 0xf0
84#define ISAKMP_VERS_MAJOR_SHIFT 4
85#define ISAKMP_VERS_MINOR 0x0f
86#define ISAKMP_VERS_MINOR_SHIFT 0
87 uint8_t etype; /* Exchange Type */
88 uint8_t flags; /* Flags */
89 msgid_t msgid;
90 uint32_t len; /* Length */
91};
92
93/* Next Payload Type */
94#define ISAKMP_NPTYPE_NONE 0 /* NONE*/
95#define ISAKMP_NPTYPE_SA 1 /* Security Association */
96#define ISAKMP_NPTYPE_P 2 /* Proposal */
97#define ISAKMP_NPTYPE_T 3 /* Transform */
98#define ISAKMP_NPTYPE_KE 4 /* Key Exchange */
99#define ISAKMP_NPTYPE_ID 5 /* Identification */
100#define ISAKMP_NPTYPE_CERT 6 /* Certificate */
101#define ISAKMP_NPTYPE_CR 7 /* Certificate Request */
102#define ISAKMP_NPTYPE_HASH 8 /* Hash */
103#define ISAKMP_NPTYPE_SIG 9 /* Signature */
104#define ISAKMP_NPTYPE_NONCE 10 /* Nonce */
105#define ISAKMP_NPTYPE_N 11 /* Notification */
106#define ISAKMP_NPTYPE_D 12 /* Delete */
107#define ISAKMP_NPTYPE_VID 13 /* Vendor ID */
108#define ISAKMP_NPTYPE_v2E 46 /* v2 Encrypted payload */
109
110#define IKEv1_MAJOR_VERSION 1
111#define IKEv1_MINOR_VERSION 0
112
113#define IKEv2_MAJOR_VERSION 2
114#define IKEv2_MINOR_VERSION 0
115
116/* Flags */
117#define ISAKMP_FLAG_E 0x01 /* Encryption Bit */
118#define ISAKMP_FLAG_C 0x02 /* Commit Bit */
119#define ISAKMP_FLAG_extra 0x04
120
121/* IKEv2 */
122#define ISAKMP_FLAG_I (1 << 3) /* (I)nitiator */
123#define ISAKMP_FLAG_V (1 << 4) /* (V)ersion */
124#define ISAKMP_FLAG_R (1 << 5) /* (R)esponse */
125
126
127/* 3.2 Payload Generic Header
128 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
129 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
130 ! Next Payload ! RESERVED ! Payload Length !
131 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
132*/
133struct isakmp_gen {
134 uint8_t np; /* Next Payload */
135 uint8_t critical; /* bit 7 - critical, rest is RESERVED */
136 uint16_t len; /* Payload Length */
137};
138
139/* 3.3 Data Attributes
140 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
141 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142 !A! Attribute Type ! AF=0 Attribute Length !
143 !F! ! AF=1 Attribute Value !
144 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 . AF=0 Attribute Value .
146 . AF=1 Not Transmitted .
147 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
148*/
149struct isakmp_data {
150 uint16_t type; /* defined by DOI-spec, and Attribute Format */
151 uint16_t lorv; /* if f equal 1, Attribute Length */
152 /* if f equal 0, Attribute Value */
153 /* if f equal 1, Attribute Value */
154};
155
156/* 3.4 Security Association Payload */
157 /* MAY NOT be used, because of being defined in ipsec-doi. */
158 /*
159 If the current payload is the last in the message,
160 then the value of the next payload field will be 0.
161 This field MUST NOT contain the
162 values for the Proposal or Transform payloads as they are considered
163 part of the security association negotiation. For example, this
164 field would contain the value "10" (Nonce payload) in the first
165 message of a Base Exchange (see Section 4.4) and the value "0" in the
166 first message of an Identity Protect Exchange (see Section 4.5).
167 */
168struct ikev1_pl_sa {
169 struct isakmp_gen h;
170 uint32_t doi; /* Domain of Interpretation */
171 uint32_t sit; /* Situation */
172};
173
174/* 3.5 Proposal Payload */
175 /*
176 The value of the next payload field MUST only contain the value "2"
177 or "0". If there are additional Proposal payloads in the message,
178 then this field will be 2. If the current Proposal payload is the
179 last within the security association proposal, then this field will
180 be 0.
181 */
182struct ikev1_pl_p {
183 struct isakmp_gen h;
184 uint8_t p_no; /* Proposal # */
185 uint8_t prot_id; /* Protocol */
186 uint8_t spi_size; /* SPI Size */
187 uint8_t num_t; /* Number of Transforms */
188 /* SPI */
189};
190
191/* 3.6 Transform Payload */
192 /*
193 The value of the next payload field MUST only contain the value "3"
194 or "0". If there are additional Transform payloads in the proposal,
195 then this field will be 3. If the current Transform payload is the
196 last within the proposal, then this field will be 0.
197 */
198struct ikev1_pl_t {
199 struct isakmp_gen h;
200 uint8_t t_no; /* Transform # */
201 uint8_t t_id; /* Transform-Id */
202 uint16_t reserved; /* RESERVED2 */
203 /* SA Attributes */
204};
205
206/* 3.7 Key Exchange Payload */
207struct ikev1_pl_ke {
208 struct isakmp_gen h;
209 /* Key Exchange Data */
210};
211
212/* 3.8 Identification Payload */
213 /* MUST NOT to be used, because of being defined in ipsec-doi. */
214struct ikev1_pl_id {
215 struct isakmp_gen h;
216 union {
217 uint8_t id_type; /* ID Type */
218 uint32_t doi_data; /* DOI Specific ID Data */
219 } d;
220 /* Identification Data */
221};
222
223/* 3.9 Certificate Payload */
224struct ikev1_pl_cert {
225 struct isakmp_gen h;
226 uint8_t encode; /* Cert Encoding */
227 char cert; /* Certificate Data */
228 /*
229 This field indicates the type of
230 certificate or certificate-related information contained in the
231 Certificate Data field.
232 */
233};
234
235/* 3.10 Certificate Request Payload */
236struct ikev1_pl_cr {
237 struct isakmp_gen h;
238 uint8_t num_cert; /* # Cert. Types */
239 /*
240 Certificate Types (variable length)
241 -- Contains a list of the types of certificates requested,
242 sorted in order of preference. Each individual certificate
243 type is 1 octet. This field is NOT requiredo
244 */
245 /* # Certificate Authorities (1 octet) */
246 /* Certificate Authorities (variable length) */
247};
248
249/* 3.11 Hash Payload */
250 /* may not be used, because of having only data. */
251struct ikev1_pl_hash {
252 struct isakmp_gen h;
253 /* Hash Data */
254};
255
256/* 3.12 Signature Payload */
257 /* may not be used, because of having only data. */
258struct ikev1_pl_sig {
259 struct isakmp_gen h;
260 /* Signature Data */
261};
262
263/* 3.13 Nonce Payload */
264 /* may not be used, because of having only data. */
265struct ikev1_pl_nonce {
266 struct isakmp_gen h;
267 /* Nonce Data */
268};
269
270/* 3.14 Notification Payload */
271struct ikev1_pl_n {
272 struct isakmp_gen h;
273 uint32_t doi; /* Domain of Interpretation */
274 uint8_t prot_id; /* Protocol-ID */
275 uint8_t spi_size; /* SPI Size */
276 uint16_t type; /* Notify Message Type */
277 /* SPI */
278 /* Notification Data */
279};
280
281/* 3.14.1 Notify Message Types */
282/* NOTIFY MESSAGES - ERROR TYPES */
283#define ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE 1
284#define ISAKMP_NTYPE_DOI_NOT_SUPPORTED 2
285#define ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED 3
286#define ISAKMP_NTYPE_INVALID_COOKIE 4
287#define ISAKMP_NTYPE_INVALID_MAJOR_VERSION 5
288#define ISAKMP_NTYPE_INVALID_MINOR_VERSION 6
289#define ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE 7
290#define ISAKMP_NTYPE_INVALID_FLAGS 8
291#define ISAKMP_NTYPE_INVALID_MESSAGE_ID 9
292#define ISAKMP_NTYPE_INVALID_PROTOCOL_ID 10
293#define ISAKMP_NTYPE_INVALID_SPI 11
294#define ISAKMP_NTYPE_INVALID_TRANSFORM_ID 12
295#define ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED 13
296#define ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN 14
297#define ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX 15
298#define ISAKMP_NTYPE_PAYLOAD_MALFORMED 16
299#define ISAKMP_NTYPE_INVALID_KEY_INFORMATION 17
300#define ISAKMP_NTYPE_INVALID_ID_INFORMATION 18
301#define ISAKMP_NTYPE_INVALID_CERT_ENCODING 19
302#define ISAKMP_NTYPE_INVALID_CERTIFICATE 20
303#define ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX 21
304#define ISAKMP_NTYPE_INVALID_CERT_AUTHORITY 22
305#define ISAKMP_NTYPE_INVALID_HASH_INFORMATION 23
306#define ISAKMP_NTYPE_AUTHENTICATION_FAILED 24
307#define ISAKMP_NTYPE_INVALID_SIGNATURE 25
308#define ISAKMP_NTYPE_ADDRESS_NOTIFICATION 26
309
310/* 3.15 Delete Payload */
311struct ikev1_pl_d {
312 struct isakmp_gen h;
313 uint32_t doi; /* Domain of Interpretation */
314 uint8_t prot_id; /* Protocol-Id */
315 uint8_t spi_size; /* SPI Size */
316 uint16_t num_spi; /* # of SPIs */
317 /* SPI(es) */
318};
319
320struct ikev1_ph1tab {
321 struct ikev1_ph1 *head;
322 struct ikev1_ph1 *tail;
323 int len;
324};
325
326struct isakmp_ph2tab {
327 struct ikev1_ph2 *head;
328 struct ikev1_ph2 *tail;
329 int len;
330};
331
332/* IKEv2 (RFC4306) */
333
334/* 3.3 Security Association Payload -- generic header */
335/* 3.3.1. Proposal Substructure */
336struct ikev2_p {
337 struct isakmp_gen h;
338 uint8_t p_no; /* Proposal # */
339 uint8_t prot_id; /* Protocol */
340 uint8_t spi_size; /* SPI Size */
341 uint8_t num_t; /* Number of Transforms */
342};
343
344/* 3.3.2. Transform Substructure */
345struct ikev2_t {
346 struct isakmp_gen h;
347 uint8_t t_type; /* Transform Type (ENCR,PRF,INTEG,etc.*/
348 uint8_t res2; /* reserved byte */
349 uint16_t t_id; /* Transform ID */
350};
351
352enum ikev2_t_type {
353 IV2_T_ENCR = 1,
354 IV2_T_PRF = 2,
355 IV2_T_INTEG= 3,
356 IV2_T_DH = 4,
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700357 IV2_T_ESN = 5
Elliott Hughes892a68b2015-10-19 14:43:53 -0700358};
359
360/* 3.4. Key Exchange Payload */
361struct ikev2_ke {
362 struct isakmp_gen h;
363 uint16_t ke_group;
364 uint16_t ke_res1;
365 /* KE data */
366};
367
368
369/* 3.5. Identification Payloads */
370enum ikev2_id_type {
371 ID_IPV4_ADDR=1,
372 ID_FQDN=2,
373 ID_RFC822_ADDR=3,
374 ID_IPV6_ADDR=5,
375 ID_DER_ASN1_DN=9,
376 ID_DER_ASN1_GN=10,
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700377 ID_KEY_ID=11
Elliott Hughes892a68b2015-10-19 14:43:53 -0700378};
379struct ikev2_id {
380 struct isakmp_gen h;
381 uint8_t type; /* ID type */
382 uint8_t res1;
383 uint16_t res2;
384 /* SPI */
385 /* Notification Data */
386};
387
388/* 3.10 Notification Payload */
389struct ikev2_n {
390 struct isakmp_gen h;
391 uint8_t prot_id; /* Protocol-ID */
392 uint8_t spi_size; /* SPI Size */
393 uint16_t type; /* Notify Message Type */
394};
395
396enum ikev2_n_type {
397 IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD = 1,
398 IV2_NOTIFY_INVALID_IKE_SPI = 4,
399 IV2_NOTIFY_INVALID_MAJOR_VERSION = 5,
400 IV2_NOTIFY_INVALID_SYNTAX = 7,
401 IV2_NOTIFY_INVALID_MESSAGE_ID = 9,
402 IV2_NOTIFY_INVALID_SPI =11,
403 IV2_NOTIFY_NO_PROPOSAL_CHOSEN =14,
404 IV2_NOTIFY_INVALID_KE_PAYLOAD =17,
405 IV2_NOTIFY_AUTHENTICATION_FAILED =24,
406 IV2_NOTIFY_SINGLE_PAIR_REQUIRED =34,
407 IV2_NOTIFY_NO_ADDITIONAL_SAS =35,
408 IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE =36,
409 IV2_NOTIFY_FAILED_CP_REQUIRED =37,
410 IV2_NOTIFY_INVALID_SELECTORS =39,
411 IV2_NOTIFY_INITIAL_CONTACT =16384,
412 IV2_NOTIFY_SET_WINDOW_SIZE =16385,
413 IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE =16386,
414 IV2_NOTIFY_IPCOMP_SUPPORTED =16387,
415 IV2_NOTIFY_NAT_DETECTION_SOURCE_IP =16388,
416 IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP =16389,
417 IV2_NOTIFY_COOKIE =16390,
418 IV2_NOTIFY_USE_TRANSPORT_MODE =16391,
419 IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED =16392,
420 IV2_NOTIFY_REKEY_SA =16393,
421 IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED =16394,
422 IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO =16395
423};
424
425struct notify_messages {
426 uint16_t type;
427 char *msg;
428};
429
430/* 3.8 Notification Payload */
431struct ikev2_auth {
432 struct isakmp_gen h;
433 uint8_t auth_method; /* Protocol-ID */
434 uint8_t reserved[3];
435 /* authentication data */
436};
437
438enum ikev2_auth_type {
439 IV2_RSA_SIG = 1,
440 IV2_SHARED = 2,
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700441 IV2_DSS_SIG = 3
Elliott Hughes892a68b2015-10-19 14:43:53 -0700442};
443
444/* refer to RFC 2409 */
445
446#if 0
447/* isakmp sa structure */
448struct oakley_sa {
449 uint8_t proto_id; /* OAKLEY */
450 vchar_t *spi; /* spi */
451 uint8_t dhgrp; /* DH; group */
452 uint8_t auth_t; /* method of authentication */
453 uint8_t prf_t; /* type of prf */
454 uint8_t hash_t; /* type of hash */
455 uint8_t enc_t; /* type of cipher */
456 uint8_t life_t; /* type of duration of lifetime */
457 uint32_t ldur; /* life duration */
458};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800459#endif
460
Elliott Hughes892a68b2015-10-19 14:43:53 -0700461/* refer to RFC 2407 */
462
463#define IPSEC_DOI 1
464
465/* 4.2 IPSEC Situation Definition */
466#define IPSECDOI_SIT_IDENTITY_ONLY 0x00000001
467#define IPSECDOI_SIT_SECRECY 0x00000002
468#define IPSECDOI_SIT_INTEGRITY 0x00000004
469
470/* 4.4.1 IPSEC Security Protocol Identifiers */
471 /* 4.4.2 IPSEC ISAKMP Transform Values */
472#define IPSECDOI_PROTO_ISAKMP 1
473#define IPSECDOI_KEY_IKE 1
474
475/* 4.4.1 IPSEC Security Protocol Identifiers */
476#define IPSECDOI_PROTO_IPSEC_AH 2
477 /* 4.4.3 IPSEC AH Transform Values */
478#define IPSECDOI_AH_MD5 2
479#define IPSECDOI_AH_SHA 3
480#define IPSECDOI_AH_DES 4
481#define IPSECDOI_AH_SHA2_256 5
482#define IPSECDOI_AH_SHA2_384 6
483#define IPSECDOI_AH_SHA2_512 7
484
485/* 4.4.1 IPSEC Security Protocol Identifiers */
486#define IPSECDOI_PROTO_IPSEC_ESP 3
487 /* 4.4.4 IPSEC ESP Transform Identifiers */
488#define IPSECDOI_ESP_DES_IV64 1
489#define IPSECDOI_ESP_DES 2
490#define IPSECDOI_ESP_3DES 3
491#define IPSECDOI_ESP_RC5 4
492#define IPSECDOI_ESP_IDEA 5
493#define IPSECDOI_ESP_CAST 6
494#define IPSECDOI_ESP_BLOWFISH 7
495#define IPSECDOI_ESP_3IDEA 8
496#define IPSECDOI_ESP_DES_IV32 9
497#define IPSECDOI_ESP_RC4 10
498#define IPSECDOI_ESP_NULL 11
499#define IPSECDOI_ESP_RIJNDAEL 12
500#define IPSECDOI_ESP_AES 12
501
502/* 4.4.1 IPSEC Security Protocol Identifiers */
503#define IPSECDOI_PROTO_IPCOMP 4
504 /* 4.4.5 IPSEC IPCOMP Transform Identifiers */
505#define IPSECDOI_IPCOMP_OUI 1
506#define IPSECDOI_IPCOMP_DEFLATE 2
507#define IPSECDOI_IPCOMP_LZS 3
508
509/* 4.5 IPSEC Security Association Attributes */
510#define IPSECDOI_ATTR_SA_LTYPE 1 /* B */
511#define IPSECDOI_ATTR_SA_LTYPE_DEFAULT 1
512#define IPSECDOI_ATTR_SA_LTYPE_SEC 1
513#define IPSECDOI_ATTR_SA_LTYPE_KB 2
514#define IPSECDOI_ATTR_SA_LDUR 2 /* V */
515#define IPSECDOI_ATTR_SA_LDUR_DEFAULT 28800 /* 8 hours */
516#define IPSECDOI_ATTR_GRP_DESC 3 /* B */
517#define IPSECDOI_ATTR_ENC_MODE 4 /* B */
518 /* default value: host dependent */
519#define IPSECDOI_ATTR_ENC_MODE_TUNNEL 1
520#define IPSECDOI_ATTR_ENC_MODE_TRNS 2
521#define IPSECDOI_ATTR_AUTH 5 /* B */
522 /* 0 means not to use authentication. */
523#define IPSECDOI_ATTR_AUTH_HMAC_MD5 1
524#define IPSECDOI_ATTR_AUTH_HMAC_SHA1 2
525#define IPSECDOI_ATTR_AUTH_DES_MAC 3
526#define IPSECDOI_ATTR_AUTH_KPDK 4 /*RFC-1826(Key/Pad/Data/Key)*/
527 /*
528 * When negotiating ESP without authentication, the Auth
529 * Algorithm attribute MUST NOT be included in the proposal.
530 * When negotiating ESP without confidentiality, the Auth
531 * Algorithm attribute MUST be included in the proposal and
532 * the ESP transform ID must be ESP_NULL.
533 */
534#define IPSECDOI_ATTR_KEY_LENGTH 6 /* B */
535#define IPSECDOI_ATTR_KEY_ROUNDS 7 /* B */
536#define IPSECDOI_ATTR_COMP_DICT_SIZE 8 /* B */
537#define IPSECDOI_ATTR_COMP_PRIVALG 9 /* V */
538
539/* 4.6.1 Security Association Payload */
540struct ipsecdoi_sa {
541 struct isakmp_gen h;
542 uint32_t doi; /* Domain of Interpretation */
543 uint32_t sit; /* Situation */
544};
545
546struct ipsecdoi_secrecy_h {
547 uint16_t len;
548 uint16_t reserved;
549};
550
551/* 4.6.2.1 Identification Type Values */
552struct ipsecdoi_id {
553 struct isakmp_gen h;
554 uint8_t type; /* ID Type */
555 uint8_t proto_id; /* Protocol ID */
556 uint16_t port; /* Port */
557 /* Identification Data */
558};
559
560#define IPSECDOI_ID_IPV4_ADDR 1
561#define IPSECDOI_ID_FQDN 2
562#define IPSECDOI_ID_USER_FQDN 3
563#define IPSECDOI_ID_IPV4_ADDR_SUBNET 4
564#define IPSECDOI_ID_IPV6_ADDR 5
565#define IPSECDOI_ID_IPV6_ADDR_SUBNET 6
566#define IPSECDOI_ID_IPV4_ADDR_RANGE 7
567#define IPSECDOI_ID_IPV6_ADDR_RANGE 8
568#define IPSECDOI_ID_DER_ASN1_DN 9
569#define IPSECDOI_ID_DER_ASN1_GN 10
570#define IPSECDOI_ID_KEY_ID 11
571
572/* 4.6.3 IPSEC DOI Notify Message Types */
573/* Notify Messages - Status Types */
574#define IPSECDOI_NTYPE_RESPONDER_LIFETIME 24576
575#define IPSECDOI_NTYPE_REPLAY_STATUS 24577
576#define IPSECDOI_NTYPE_INITIAL_CONTACT 24578
577
JP Abgrall53f17a92014-02-12 14:02:41 -0800578#define DECLARE_PRINTER(func) static const u_char *ike##func##_print( \
579 netdissect_options *ndo, u_char tpay, \
580 const struct isakmp_gen *ext, \
581 u_int item_len, \
582 const u_char *end_pointer, \
Elliott Hughes892a68b2015-10-19 14:43:53 -0700583 uint32_t phase,\
584 uint32_t doi0, \
585 uint32_t proto0, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -0800586
587DECLARE_PRINTER(v1_sa);
588DECLARE_PRINTER(v1_p);
589DECLARE_PRINTER(v1_t);
590DECLARE_PRINTER(v1_ke);
591DECLARE_PRINTER(v1_id);
592DECLARE_PRINTER(v1_cert);
593DECLARE_PRINTER(v1_cr);
594DECLARE_PRINTER(v1_sig);
595DECLARE_PRINTER(v1_hash);
596DECLARE_PRINTER(v1_nonce);
597DECLARE_PRINTER(v1_n);
598DECLARE_PRINTER(v1_d);
599DECLARE_PRINTER(v1_vid);
600
601DECLARE_PRINTER(v2_sa);
602DECLARE_PRINTER(v2_ke);
603DECLARE_PRINTER(v2_ID);
604DECLARE_PRINTER(v2_cert);
605DECLARE_PRINTER(v2_cr);
606DECLARE_PRINTER(v2_auth);
607DECLARE_PRINTER(v2_nonce);
608DECLARE_PRINTER(v2_n);
609DECLARE_PRINTER(v2_d);
610DECLARE_PRINTER(v2_vid);
611DECLARE_PRINTER(v2_TS);
612DECLARE_PRINTER(v2_cp);
613DECLARE_PRINTER(v2_eap);
614
615static const u_char *ikev2_e_print(netdissect_options *ndo,
616 struct isakmp *base,
617 u_char tpay,
618 const struct isakmp_gen *ext,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700619 u_int item_len,
620 const u_char *end_pointer,
621 uint32_t phase,
622 uint32_t doi0,
623 uint32_t proto0, int depth);
JP Abgrall53f17a92014-02-12 14:02:41 -0800624
625
626static const u_char *ike_sub0_print(netdissect_options *ndo,u_char, const struct isakmp_gen *,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700627 const u_char *, uint32_t, uint32_t, uint32_t, int);
JP Abgrall53f17a92014-02-12 14:02:41 -0800628static const u_char *ikev1_sub_print(netdissect_options *ndo,u_char, const struct isakmp_gen *,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700629 const u_char *, uint32_t, uint32_t, uint32_t, int);
JP Abgrall53f17a92014-02-12 14:02:41 -0800630
631static const u_char *ikev2_sub_print(netdissect_options *ndo,
632 struct isakmp *base,
633 u_char np, const struct isakmp_gen *ext,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700634 const u_char *ep, uint32_t phase,
635 uint32_t doi, uint32_t proto,
JP Abgrall53f17a92014-02-12 14:02:41 -0800636 int depth);
637
638
The Android Open Source Project2949f582009-03-03 19:30:46 -0800639static char *numstr(int);
JP Abgrall53f17a92014-02-12 14:02:41 -0800640
641static void
642ikev1_print(netdissect_options *ndo,
643 const u_char *bp, u_int length,
644 const u_char *bp2, struct isakmp *base);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800645
646#define MAXINITIATORS 20
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700647static int ninitiator = 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700648union inaddr_u {
649 struct in_addr in4;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700650 struct in6_addr in6;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700651};
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700652static struct {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800653 cookie_t initiator;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700654 u_int version;
655 union inaddr_u iaddr;
656 union inaddr_u raddr;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800657} cookiecache[MAXINITIATORS];
658
659/* protocol id */
660static const char *protoidstr[] = {
661 NULL, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
662};
663
664/* isakmp->np */
665static const char *npstr[] = {
JP Abgrall53f17a92014-02-12 14:02:41 -0800666 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash", /* 0 - 8 */
667 "sig", "nonce", "n", "d", "vid", /* 9 - 13 */
668 "pay14", "pay15", "pay16", "pay17", "pay18", /* 14- 18 */
669 "pay19", "pay20", "pay21", "pay22", "pay23", /* 19- 23 */
670 "pay24", "pay25", "pay26", "pay27", "pay28", /* 24- 28 */
671 "pay29", "pay30", "pay31", "pay32", /* 29- 32 */
672 "v2sa", "v2ke", "v2IDi", "v2IDr", "v2cert",/* 33- 37 */
673 "v2cr", "v2auth","v2nonce", "v2n", "v2d", /* 38- 42 */
674 "v2vid", "v2TSi", "v2TSr", "v2e", "v2cp", /* 43- 47 */
675 "v2eap", /* 48 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700676
The Android Open Source Project2949f582009-03-03 19:30:46 -0800677};
678
679/* isakmp->np */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700680static const u_char *(*npfunc[])(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -0800681 const struct isakmp_gen *ext,
682 u_int item_len,
683 const u_char *end_pointer,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700684 uint32_t phase,
685 uint32_t doi0,
686 uint32_t proto0, int depth) = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800687 NULL,
JP Abgrall53f17a92014-02-12 14:02:41 -0800688 ikev1_sa_print,
689 ikev1_p_print,
690 ikev1_t_print,
691 ikev1_ke_print,
692 ikev1_id_print,
693 ikev1_cert_print,
694 ikev1_cr_print,
695 ikev1_hash_print,
696 ikev1_sig_print,
697 ikev1_nonce_print,
698 ikev1_n_print,
699 ikev1_d_print,
700 ikev1_vid_print, /* 13 */
701 NULL, NULL, NULL, NULL, NULL, /* 14- 18 */
702 NULL, NULL, NULL, NULL, NULL, /* 19- 23 */
703 NULL, NULL, NULL, NULL, NULL, /* 24- 28 */
704 NULL, NULL, NULL, NULL, /* 29- 32 */
705 ikev2_sa_print, /* 33 */
706 ikev2_ke_print, /* 34 */
707 ikev2_ID_print, /* 35 */
708 ikev2_ID_print, /* 36 */
709 ikev2_cert_print, /* 37 */
710 ikev2_cr_print, /* 38 */
711 ikev2_auth_print, /* 39 */
712 ikev2_nonce_print, /* 40 */
713 ikev2_n_print, /* 41 */
714 ikev2_d_print, /* 42 */
715 ikev2_vid_print, /* 43 */
716 ikev2_TS_print, /* 44 */
717 ikev2_TS_print, /* 45 */
718 NULL, /* ikev2_e_print,*/ /* 46 - special */
719 ikev2_cp_print, /* 47 */
720 ikev2_eap_print, /* 48 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800721};
722
723/* isakmp->etype */
724static const char *etypestr[] = {
JP Abgrall53f17a92014-02-12 14:02:41 -0800725/* IKEv1 exchange types */
726 "none", "base", "ident", "auth", "agg", "inf", NULL, NULL, /* 0-7 */
727 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 8-15 */
728 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 16-23 */
729 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 24-31 */
730 "oakley-quick", "oakley-newgroup", /* 32-33 */
731/* IKEv2 exchange types */
732 "ikev2_init", "ikev2_auth", "child_sa", "inf2" /* 34-37 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800733};
734
735#define STR_OR_ID(x, tab) \
736 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
737#define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
738#define NPSTR(x) STR_OR_ID(x, npstr)
739#define ETYPESTR(x) STR_OR_ID(x, etypestr)
740
JP Abgrall53f17a92014-02-12 14:02:41 -0800741#define CHECKLEN(p, np) \
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700742 if (ep < (const u_char *)(p)) { \
JP Abgrall53f17a92014-02-12 14:02:41 -0800743 ND_PRINT((ndo," [|%s]", NPSTR(np))); \
744 goto done; \
745 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700746
JP Abgrall53f17a92014-02-12 14:02:41 -0800747
The Android Open Source Project2949f582009-03-03 19:30:46 -0800748#define NPFUNC(x) \
749 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
750 ? npfunc[(x)] : NULL)
751
752static int
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700753iszero(const u_char *p, size_t l)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800754{
755 while (l--) {
756 if (*p++)
757 return 0;
758 }
759 return 1;
760}
761
762/* find cookie from initiator cache */
763static int
764cookie_find(cookie_t *in)
765{
766 int i;
767
768 for (i = 0; i < MAXINITIATORS; i++) {
769 if (memcmp(in, &cookiecache[i].initiator, sizeof(*in)) == 0)
770 return i;
771 }
772
773 return -1;
774}
775
776/* record initiator */
777static void
778cookie_record(cookie_t *in, const u_char *bp2)
779{
780 int i;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700781 const struct ip *ip;
782 const struct ip6_hdr *ip6;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800783
784 i = cookie_find(in);
785 if (0 <= i) {
786 ninitiator = (i + 1) % MAXINITIATORS;
787 return;
788 }
789
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700790 ip = (const struct ip *)bp2;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800791 switch (IP_V(ip)) {
792 case 4:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700793 cookiecache[ninitiator].version = 4;
794 UNALIGNED_MEMCPY(&cookiecache[ninitiator].iaddr.in4, &ip->ip_src, sizeof(struct in_addr));
795 UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in4, &ip->ip_dst, sizeof(struct in_addr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800796 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800797 case 6:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700798 ip6 = (const struct ip6_hdr *)bp2;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700799 cookiecache[ninitiator].version = 6;
800 UNALIGNED_MEMCPY(&cookiecache[ninitiator].iaddr.in6, &ip6->ip6_src, sizeof(struct in6_addr));
801 UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in6, &ip6->ip6_dst, sizeof(struct in6_addr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800802 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800803 default:
804 return;
805 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800806 UNALIGNED_MEMCPY(&cookiecache[ninitiator].initiator, in, sizeof(*in));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800807 ninitiator = (ninitiator + 1) % MAXINITIATORS;
808}
809
810#define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
811#define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
812static int
813cookie_sidecheck(int i, const u_char *bp2, int initiator)
814{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700815 const struct ip *ip;
816 const struct ip6_hdr *ip6;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800817
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700818 ip = (const struct ip *)bp2;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800819 switch (IP_V(ip)) {
820 case 4:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700821 if (cookiecache[i].version != 4)
822 return 0;
823 if (initiator) {
824 if (UNALIGNED_MEMCMP(&ip->ip_src, &cookiecache[i].iaddr.in4, sizeof(struct in_addr)) == 0)
825 return 1;
826 } else {
827 if (UNALIGNED_MEMCMP(&ip->ip_src, &cookiecache[i].raddr.in4, sizeof(struct in_addr)) == 0)
828 return 1;
829 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800830 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800831 case 6:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700832 if (cookiecache[i].version != 6)
833 return 0;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700834 ip6 = (const struct ip6_hdr *)bp2;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700835 if (initiator) {
836 if (UNALIGNED_MEMCMP(&ip6->ip6_src, &cookiecache[i].iaddr.in6, sizeof(struct in6_addr)) == 0)
837 return 1;
838 } else {
839 if (UNALIGNED_MEMCMP(&ip6->ip6_src, &cookiecache[i].raddr.in6, sizeof(struct in6_addr)) == 0)
840 return 1;
841 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800842 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800843 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700844 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800845 }
846
The Android Open Source Project2949f582009-03-03 19:30:46 -0800847 return 0;
848}
849
JP Abgrall53f17a92014-02-12 14:02:41 -0800850static void
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700851hexprint(netdissect_options *ndo, const uint8_t *loc, size_t len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800852{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700853 const uint8_t *p;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800854 size_t i;
855
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700856 p = loc;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800857 for (i = 0; i < len; i++)
JP Abgrall53f17a92014-02-12 14:02:41 -0800858 ND_PRINT((ndo,"%02x", p[i] & 0xff));
859}
860
861static int
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700862rawprint(netdissect_options *ndo, const uint8_t *loc, size_t len)
JP Abgrall53f17a92014-02-12 14:02:41 -0800863{
864 ND_TCHECK2(*loc, len);
865
866 hexprint(ndo, loc, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800867 return 1;
868trunc:
869 return 0;
870}
871
JP Abgrall53f17a92014-02-12 14:02:41 -0800872
873/*
874 * returns false if we run out of data buffer
875 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700876static int ike_show_somedata(netdissect_options *ndo,
JP Abgrall53f17a92014-02-12 14:02:41 -0800877 const u_char *cp, const u_char *ep)
878{
879 /* there is too much data, just show some of it */
880 const u_char *end = ep - 20;
881 int elen = 20;
882 int len = ep - cp;
883 if(len > 10) {
884 len = 10;
885 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700886
JP Abgrall53f17a92014-02-12 14:02:41 -0800887 /* really shouldn't happen because of above */
888 if(end < cp + len) {
889 end = cp+len;
890 elen = ep - end;
891 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700892
JP Abgrall53f17a92014-02-12 14:02:41 -0800893 ND_PRINT((ndo," data=("));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700894 if(!rawprint(ndo, (const uint8_t *)(cp), len)) goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -0800895 ND_PRINT((ndo, "..."));
896 if(elen) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700897 if(!rawprint(ndo, (const uint8_t *)(end), elen)) goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -0800898 }
899 ND_PRINT((ndo,")"));
900 return 1;
901
902trunc:
903 return 0;
904}
905
The Android Open Source Project2949f582009-03-03 19:30:46 -0800906struct attrmap {
907 const char *type;
908 u_int nvalue;
909 const char *value[30]; /*XXX*/
910};
911
912static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -0800913ikev1_attrmap_print(netdissect_options *ndo,
914 const u_char *p, const u_char *ep,
915 const struct attrmap *map, size_t nmap)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800916{
The Android Open Source Project2949f582009-03-03 19:30:46 -0800917 int totlen;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700918 uint32_t t, v;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800919
The Android Open Source Project2949f582009-03-03 19:30:46 -0800920 if (p[0] & 0x80)
921 totlen = 4;
922 else
JP Abgrall53f17a92014-02-12 14:02:41 -0800923 totlen = 4 + EXTRACT_16BITS(&p[2]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800924 if (ep < p + totlen) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800925 ND_PRINT((ndo,"[|attr]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800926 return ep + 1;
927 }
928
JP Abgrall53f17a92014-02-12 14:02:41 -0800929 ND_PRINT((ndo,"("));
930 t = EXTRACT_16BITS(&p[0]) & 0x7fff;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800931 if (map && t < nmap && map[t].type)
JP Abgrall53f17a92014-02-12 14:02:41 -0800932 ND_PRINT((ndo,"type=%s ", map[t].type));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800933 else
JP Abgrall53f17a92014-02-12 14:02:41 -0800934 ND_PRINT((ndo,"type=#%d ", t));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800935 if (p[0] & 0x80) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800936 ND_PRINT((ndo,"value="));
937 v = EXTRACT_16BITS(&p[2]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800938 if (map && t < nmap && v < map[t].nvalue && map[t].value[v])
JP Abgrall53f17a92014-02-12 14:02:41 -0800939 ND_PRINT((ndo,"%s", map[t].value[v]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800940 else
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700941 rawprint(ndo, (const uint8_t *)&p[2], 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800942 } else {
JP Abgrall53f17a92014-02-12 14:02:41 -0800943 ND_PRINT((ndo,"len=%d value=", EXTRACT_16BITS(&p[2])));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700944 rawprint(ndo, (const uint8_t *)&p[4], EXTRACT_16BITS(&p[2]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800945 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800946 ND_PRINT((ndo,")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800947 return p + totlen;
948}
949
950static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -0800951ikev1_attr_print(netdissect_options *ndo, const u_char *p, const u_char *ep)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800952{
The Android Open Source Project2949f582009-03-03 19:30:46 -0800953 int totlen;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700954 uint32_t t;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800955
The Android Open Source Project2949f582009-03-03 19:30:46 -0800956 if (p[0] & 0x80)
957 totlen = 4;
958 else
JP Abgrall53f17a92014-02-12 14:02:41 -0800959 totlen = 4 + EXTRACT_16BITS(&p[2]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800960 if (ep < p + totlen) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800961 ND_PRINT((ndo,"[|attr]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800962 return ep + 1;
963 }
964
JP Abgrall53f17a92014-02-12 14:02:41 -0800965 ND_PRINT((ndo,"("));
966 t = EXTRACT_16BITS(&p[0]) & 0x7fff;
967 ND_PRINT((ndo,"type=#%d ", t));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800968 if (p[0] & 0x80) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800969 ND_PRINT((ndo,"value="));
970 t = p[2];
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700971 rawprint(ndo, (const uint8_t *)&p[2], 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800972 } else {
JP Abgrall53f17a92014-02-12 14:02:41 -0800973 ND_PRINT((ndo,"len=%d value=", EXTRACT_16BITS(&p[2])));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700974 rawprint(ndo, (const uint8_t *)&p[4], EXTRACT_16BITS(&p[2]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800975 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800976 ND_PRINT((ndo,")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800977 return p + totlen;
978}
979
980static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -0800981ikev1_sa_print(netdissect_options *ndo, u_char tpay _U_,
982 const struct isakmp_gen *ext,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800983 u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700984 const u_char *ep, uint32_t phase, uint32_t doi0 _U_,
985 uint32_t proto0, int depth)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800986{
JP Abgrall53f17a92014-02-12 14:02:41 -0800987 const struct ikev1_pl_sa *p;
988 struct ikev1_pl_sa sa;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700989 uint32_t doi, sit, ident;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800990 const u_char *cp, *np;
991 int t;
992
JP Abgrall53f17a92014-02-12 14:02:41 -0800993 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_SA)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800994
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700995 p = (const struct ikev1_pl_sa *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -0800996 ND_TCHECK(*p);
997 UNALIGNED_MEMCPY(&sa, ext, sizeof(sa));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800998 doi = ntohl(sa.doi);
999 sit = ntohl(sa.sit);
1000 if (doi != 1) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001001 ND_PRINT((ndo," doi=%d", doi));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001002 ND_PRINT((ndo," situation=%u", (uint32_t)ntohl(sa.sit)));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001003 return (const u_char *)(p + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001004 }
1005
JP Abgrall53f17a92014-02-12 14:02:41 -08001006 ND_PRINT((ndo," doi=ipsec"));
1007 ND_PRINT((ndo," situation="));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001008 t = 0;
1009 if (sit & 0x01) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001010 ND_PRINT((ndo,"identity"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001011 t++;
1012 }
1013 if (sit & 0x02) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001014 ND_PRINT((ndo,"%ssecrecy", t ? "+" : ""));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001015 t++;
1016 }
1017 if (sit & 0x04)
JP Abgrall53f17a92014-02-12 14:02:41 -08001018 ND_PRINT((ndo,"%sintegrity", t ? "+" : ""));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001019
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001020 np = (const u_char *)ext + sizeof(sa);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001021 if (sit != 0x01) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001022 ND_TCHECK2(*(ext + 1), sizeof(ident));
1023 UNALIGNED_MEMCPY(&ident, ext + 1, sizeof(ident));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001024 ND_PRINT((ndo," ident=%u", (uint32_t)ntohl(ident)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001025 np += sizeof(ident);
1026 }
1027
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001028 ext = (const struct isakmp_gen *)np;
JP Abgrall53f17a92014-02-12 14:02:41 -08001029 ND_TCHECK(*ext);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001030
JP Abgrall53f17a92014-02-12 14:02:41 -08001031 cp = ikev1_sub_print(ndo, ISAKMP_NPTYPE_P, ext, ep, phase, doi, proto0,
The Android Open Source Project2949f582009-03-03 19:30:46 -08001032 depth);
1033
1034 return cp;
1035trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001036 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_SA)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001037 return NULL;
1038}
1039
1040static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001041ikev1_p_print(netdissect_options *ndo, u_char tpay _U_,
1042 const struct isakmp_gen *ext, u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001043 const u_char *ep, uint32_t phase, uint32_t doi0,
1044 uint32_t proto0 _U_, int depth)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001045{
JP Abgrall53f17a92014-02-12 14:02:41 -08001046 const struct ikev1_pl_p *p;
1047 struct ikev1_pl_p prop;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001048 const u_char *cp;
1049
JP Abgrall53f17a92014-02-12 14:02:41 -08001050 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_P)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001051
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001052 p = (const struct ikev1_pl_p *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001053 ND_TCHECK(*p);
1054 UNALIGNED_MEMCPY(&prop, ext, sizeof(prop));
1055 ND_PRINT((ndo," #%d protoid=%s transform=%d",
1056 prop.p_no, PROTOIDSTR(prop.prot_id), prop.num_t));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001057 if (prop.spi_size) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001058 ND_PRINT((ndo," spi="));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001059 if (!rawprint(ndo, (const uint8_t *)(p + 1), prop.spi_size))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001060 goto trunc;
1061 }
1062
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001063 ext = (const struct isakmp_gen *)((const u_char *)(p + 1) + prop.spi_size);
JP Abgrall53f17a92014-02-12 14:02:41 -08001064 ND_TCHECK(*ext);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001065
JP Abgrall53f17a92014-02-12 14:02:41 -08001066 cp = ikev1_sub_print(ndo, ISAKMP_NPTYPE_T, ext, ep, phase, doi0,
1067 prop.prot_id, depth);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001068
The Android Open Source Project2949f582009-03-03 19:30:46 -08001069 return cp;
1070trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001071 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_P)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001072 return NULL;
1073}
1074
JP Abgrall53f17a92014-02-12 14:02:41 -08001075static const char *ikev1_p_map[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001076 NULL, "ike",
1077};
1078
JP Abgrall53f17a92014-02-12 14:02:41 -08001079static const char *ikev2_t_type_map[]={
1080 NULL, "encr", "prf", "integ", "dh", "esn"
1081};
1082
The Android Open Source Project2949f582009-03-03 19:30:46 -08001083static const char *ah_p_map[] = {
1084 NULL, "(reserved)", "md5", "sha", "1des",
1085 "sha2-256", "sha2-384", "sha2-512",
1086};
1087
JP Abgrall53f17a92014-02-12 14:02:41 -08001088static const char *prf_p_map[] = {
1089 NULL, "hmac-md5", "hmac-sha", "hmac-tiger",
1090 "aes128_xcbc"
1091};
1092
1093static const char *integ_p_map[] = {
1094 NULL, "hmac-md5", "hmac-sha", "dec-mac",
1095 "kpdk-md5", "aes-xcbc"
1096};
1097
1098static const char *esn_p_map[] = {
1099 "no-esn", "esn"
1100};
1101
1102static const char *dh_p_map[] = {
1103 NULL, "modp768",
1104 "modp1024", /* group 2 */
1105 "EC2N 2^155", /* group 3 */
1106 "EC2N 2^185", /* group 4 */
1107 "modp1536", /* group 5 */
1108 "iana-grp06", "iana-grp07", /* reserved */
1109 "iana-grp08", "iana-grp09",
1110 "iana-grp10", "iana-grp11",
1111 "iana-grp12", "iana-grp13",
1112 "modp2048", /* group 14 */
1113 "modp3072", /* group 15 */
1114 "modp4096", /* group 16 */
1115 "modp6144", /* group 17 */
1116 "modp8192", /* group 18 */
1117};
1118
The Android Open Source Project2949f582009-03-03 19:30:46 -08001119static const char *esp_p_map[] = {
1120 NULL, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
1121 "blowfish", "3idea", "1des-iv32", "rc4", "null", "aes"
1122};
1123
1124static const char *ipcomp_p_map[] = {
1125 NULL, "oui", "deflate", "lzs",
1126};
1127
Elliott Hughes892a68b2015-10-19 14:43:53 -07001128static const struct attrmap ipsec_t_map[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001129 { NULL, 0, { NULL } },
1130 { "lifetype", 3, { NULL, "sec", "kb", }, },
1131 { "life", 0, { NULL } },
JP Abgrall53f17a92014-02-12 14:02:41 -08001132 { "group desc", 18, { NULL, "modp768",
1133 "modp1024", /* group 2 */
1134 "EC2N 2^155", /* group 3 */
1135 "EC2N 2^185", /* group 4 */
1136 "modp1536", /* group 5 */
1137 "iana-grp06", "iana-grp07", /* reserved */
1138 "iana-grp08", "iana-grp09",
1139 "iana-grp10", "iana-grp11",
1140 "iana-grp12", "iana-grp13",
1141 "modp2048", /* group 14 */
1142 "modp3072", /* group 15 */
1143 "modp4096", /* group 16 */
1144 "modp6144", /* group 17 */
1145 "modp8192", /* group 18 */
1146 }, },
The Android Open Source Project2949f582009-03-03 19:30:46 -08001147 { "enc mode", 3, { NULL, "tunnel", "transport", }, },
1148 { "auth", 5, { NULL, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
1149 { "keylen", 0, { NULL } },
1150 { "rounds", 0, { NULL } },
1151 { "dictsize", 0, { NULL } },
1152 { "privalg", 0, { NULL } },
1153};
1154
Elliott Hughes892a68b2015-10-19 14:43:53 -07001155static const struct attrmap encr_t_map[] = {
JP Abgrall53f17a92014-02-12 14:02:41 -08001156 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 0, 1 */
1157 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 2, 3 */
1158 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 4, 5 */
1159 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 6, 7 */
1160 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 8, 9 */
1161 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 10,11*/
1162 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 12,13*/
1163 { "keylen", 14, { NULL }},
1164};
1165
Elliott Hughes892a68b2015-10-19 14:43:53 -07001166static const struct attrmap oakley_t_map[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001167 { NULL, 0, { NULL } },
1168 { "enc", 8, { NULL, "1des", "idea", "blowfish", "rc5",
1169 "3des", "cast", "aes", }, },
1170 { "hash", 7, { NULL, "md5", "sha1", "tiger",
1171 "sha2-256", "sha2-384", "sha2-512", }, },
1172 { "auth", 6, { NULL, "preshared", "dss", "rsa sig", "rsa enc",
1173 "rsa enc revised", }, },
JP Abgrall53f17a92014-02-12 14:02:41 -08001174 { "group desc", 18, { NULL, "modp768",
1175 "modp1024", /* group 2 */
1176 "EC2N 2^155", /* group 3 */
1177 "EC2N 2^185", /* group 4 */
1178 "modp1536", /* group 5 */
1179 "iana-grp06", "iana-grp07", /* reserved */
1180 "iana-grp08", "iana-grp09",
1181 "iana-grp10", "iana-grp11",
1182 "iana-grp12", "iana-grp13",
1183 "modp2048", /* group 14 */
1184 "modp3072", /* group 15 */
1185 "modp4096", /* group 16 */
1186 "modp6144", /* group 17 */
1187 "modp8192", /* group 18 */
1188 }, },
The Android Open Source Project2949f582009-03-03 19:30:46 -08001189 { "group type", 4, { NULL, "MODP", "ECP", "EC2N", }, },
1190 { "group prime", 0, { NULL } },
1191 { "group gen1", 0, { NULL } },
1192 { "group gen2", 0, { NULL } },
1193 { "group curve A", 0, { NULL } },
1194 { "group curve B", 0, { NULL } },
1195 { "lifetype", 3, { NULL, "sec", "kb", }, },
1196 { "lifeduration", 0, { NULL } },
1197 { "prf", 0, { NULL } },
1198 { "keylen", 0, { NULL } },
1199 { "field", 0, { NULL } },
1200 { "order", 0, { NULL } },
1201};
1202
1203static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001204ikev1_t_print(netdissect_options *ndo, u_char tpay _U_,
1205 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001206 const u_char *ep, uint32_t phase _U_, uint32_t doi _U_,
1207 uint32_t proto, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001208{
JP Abgrall53f17a92014-02-12 14:02:41 -08001209 const struct ikev1_pl_t *p;
1210 struct ikev1_pl_t t;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001211 const u_char *cp;
1212 const char *idstr;
1213 const struct attrmap *map;
1214 size_t nmap;
1215 const u_char *ep2;
1216
JP Abgrall53f17a92014-02-12 14:02:41 -08001217 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_T)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001218
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001219 p = (const struct ikev1_pl_t *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001220 ND_TCHECK(*p);
1221 UNALIGNED_MEMCPY(&t, ext, sizeof(t));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001222
1223 switch (proto) {
1224 case 1:
JP Abgrall53f17a92014-02-12 14:02:41 -08001225 idstr = STR_OR_ID(t.t_id, ikev1_p_map);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001226 map = oakley_t_map;
1227 nmap = sizeof(oakley_t_map)/sizeof(oakley_t_map[0]);
1228 break;
1229 case 2:
1230 idstr = STR_OR_ID(t.t_id, ah_p_map);
1231 map = ipsec_t_map;
1232 nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
1233 break;
1234 case 3:
1235 idstr = STR_OR_ID(t.t_id, esp_p_map);
1236 map = ipsec_t_map;
1237 nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
1238 break;
1239 case 4:
1240 idstr = STR_OR_ID(t.t_id, ipcomp_p_map);
1241 map = ipsec_t_map;
1242 nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
1243 break;
1244 default:
1245 idstr = NULL;
1246 map = NULL;
1247 nmap = 0;
1248 break;
1249 }
1250
1251 if (idstr)
JP Abgrall53f17a92014-02-12 14:02:41 -08001252 ND_PRINT((ndo," #%d id=%s ", t.t_no, idstr));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001253 else
JP Abgrall53f17a92014-02-12 14:02:41 -08001254 ND_PRINT((ndo," #%d id=%d ", t.t_no, t.t_id));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001255 cp = (const u_char *)(p + 1);
1256 ep2 = (const u_char *)p + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001257 while (cp < ep && cp < ep2) {
1258 if (map && nmap) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001259 cp = ikev1_attrmap_print(ndo, cp, (ep < ep2) ? ep : ep2,
The Android Open Source Project2949f582009-03-03 19:30:46 -08001260 map, nmap);
1261 } else
JP Abgrall53f17a92014-02-12 14:02:41 -08001262 cp = ikev1_attr_print(ndo, cp, (ep < ep2) ? ep : ep2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001263 }
1264 if (ep < ep2)
JP Abgrall53f17a92014-02-12 14:02:41 -08001265 ND_PRINT((ndo,"..."));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001266 return cp;
1267trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001268 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_T)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001269 return NULL;
1270}
1271
1272static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001273ikev1_ke_print(netdissect_options *ndo, u_char tpay _U_,
1274 const struct isakmp_gen *ext, u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001275 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi _U_,
1276 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001277{
1278 struct isakmp_gen e;
1279
JP Abgrall53f17a92014-02-12 14:02:41 -08001280 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_KE)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001281
JP Abgrall53f17a92014-02-12 14:02:41 -08001282 ND_TCHECK(*ext);
1283 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
1284 ND_PRINT((ndo," key len=%d", ntohs(e.len) - 4));
1285 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1286 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001287 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001288 goto trunc;
1289 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001290 return (const u_char *)ext + ntohs(e.len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001291trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001292 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_KE)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001293 return NULL;
1294}
1295
1296static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001297ikev1_id_print(netdissect_options *ndo, u_char tpay _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001298 const struct isakmp_gen *ext, u_int item_len,
1299 const u_char *ep _U_, uint32_t phase, uint32_t doi _U_,
1300 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001301{
1302#define USE_IPSECDOI_IN_PHASE1 1
JP Abgrall53f17a92014-02-12 14:02:41 -08001303 const struct ikev1_pl_id *p;
1304 struct ikev1_pl_id id;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001305 static const char *idtypestr[] = {
1306 "IPv4", "IPv4net", "IPv6", "IPv6net",
1307 };
1308 static const char *ipsecidtypestr[] = {
1309 NULL, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
1310 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
1311 "keyid",
1312 };
1313 int len;
1314 const u_char *data;
1315
JP Abgrall53f17a92014-02-12 14:02:41 -08001316 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_ID)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001317
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001318 p = (const struct ikev1_pl_id *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001319 ND_TCHECK(*p);
1320 UNALIGNED_MEMCPY(&id, ext, sizeof(id));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001321 if (sizeof(*p) < item_len) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001322 data = (const u_char *)(p + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001323 len = item_len - sizeof(*p);
1324 } else {
1325 data = NULL;
1326 len = 0;
1327 }
1328
1329#if 0 /*debug*/
JP Abgrall53f17a92014-02-12 14:02:41 -08001330 ND_PRINT((ndo," [phase=%d doi=%d proto=%d]", phase, doi, proto));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001331#endif
1332 switch (phase) {
1333#ifndef USE_IPSECDOI_IN_PHASE1
1334 case 1:
1335#endif
1336 default:
JP Abgrall53f17a92014-02-12 14:02:41 -08001337 ND_PRINT((ndo," idtype=%s", STR_OR_ID(id.d.id_type, idtypestr)));
1338 ND_PRINT((ndo," doi_data=%u",
Elliott Hughes892a68b2015-10-19 14:43:53 -07001339 (uint32_t)(ntohl(id.d.doi_data) & 0xffffff)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001340 break;
1341
1342#ifdef USE_IPSECDOI_IN_PHASE1
1343 case 1:
1344#endif
1345 case 2:
1346 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001347 const struct ipsecdoi_id *doi_p;
1348 struct ipsecdoi_id doi_id;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001349 struct protoent *pe;
1350
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001351 doi_p = (const struct ipsecdoi_id *)ext;
1352 ND_TCHECK(*doi_p);
1353 UNALIGNED_MEMCPY(&doi_id, ext, sizeof(doi_id));
1354 ND_PRINT((ndo," idtype=%s", STR_OR_ID(doi_id.type, ipsecidtypestr)));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001355 /* A protocol ID of 0 DOES NOT mean IPPROTO_IP! */
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001356 pe = doi_id.proto_id ? getprotobynumber(doi_id.proto_id) : NULL;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001357 if (pe)
1358 ND_PRINT((ndo," protoid=%s", pe->p_name));
1359 else
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001360 ND_PRINT((ndo," protoid=%u", doi_id.proto_id));
1361 ND_PRINT((ndo," port=%d", ntohs(doi_id.port)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001362 if (!len)
1363 break;
1364 if (data == NULL)
1365 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08001366 ND_TCHECK2(*data, len);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001367 switch (doi_id.type) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001368 case IPSECDOI_ID_IPV4_ADDR:
1369 if (len < 4)
JP Abgrall53f17a92014-02-12 14:02:41 -08001370 ND_PRINT((ndo," len=%d [bad: < 4]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001371 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001372 ND_PRINT((ndo," len=%d %s", len, ipaddr_string(ndo, data)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001373 len = 0;
1374 break;
1375 case IPSECDOI_ID_FQDN:
1376 case IPSECDOI_ID_USER_FQDN:
1377 {
1378 int i;
JP Abgrall53f17a92014-02-12 14:02:41 -08001379 ND_PRINT((ndo," len=%d ", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001380 for (i = 0; i < len; i++)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001381 safeputchar(ndo, data[i]);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001382 len = 0;
1383 break;
1384 }
1385 case IPSECDOI_ID_IPV4_ADDR_SUBNET:
1386 {
1387 const u_char *mask;
1388 if (len < 8)
JP Abgrall53f17a92014-02-12 14:02:41 -08001389 ND_PRINT((ndo," len=%d [bad: < 8]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001390 else {
1391 mask = data + sizeof(struct in_addr);
JP Abgrall53f17a92014-02-12 14:02:41 -08001392 ND_PRINT((ndo," len=%d %s/%u.%u.%u.%u", len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001393 ipaddr_string(ndo, data),
JP Abgrall53f17a92014-02-12 14:02:41 -08001394 mask[0], mask[1], mask[2], mask[3]));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001395 }
1396 len = 0;
1397 break;
1398 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001399 case IPSECDOI_ID_IPV6_ADDR:
1400 if (len < 16)
JP Abgrall53f17a92014-02-12 14:02:41 -08001401 ND_PRINT((ndo," len=%d [bad: < 16]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001402 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001403 ND_PRINT((ndo," len=%d %s", len, ip6addr_string(ndo, data)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001404 len = 0;
1405 break;
1406 case IPSECDOI_ID_IPV6_ADDR_SUBNET:
1407 {
JP Abgrall53f17a92014-02-12 14:02:41 -08001408 const u_char *mask;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001409 if (len < 20)
JP Abgrall53f17a92014-02-12 14:02:41 -08001410 ND_PRINT((ndo," len=%d [bad: < 20]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001411 else {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001412 mask = (const u_char *)(data + sizeof(struct in6_addr));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001413 /*XXX*/
JP Abgrall53f17a92014-02-12 14:02:41 -08001414 ND_PRINT((ndo," len=%d %s/0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001415 ip6addr_string(ndo, data),
JP Abgrall53f17a92014-02-12 14:02:41 -08001416 mask[0], mask[1], mask[2], mask[3],
1417 mask[4], mask[5], mask[6], mask[7],
1418 mask[8], mask[9], mask[10], mask[11],
1419 mask[12], mask[13], mask[14], mask[15]));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001420 }
1421 len = 0;
1422 break;
1423 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001424 case IPSECDOI_ID_IPV4_ADDR_RANGE:
1425 if (len < 8)
JP Abgrall53f17a92014-02-12 14:02:41 -08001426 ND_PRINT((ndo," len=%d [bad: < 8]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001427 else {
JP Abgrall53f17a92014-02-12 14:02:41 -08001428 ND_PRINT((ndo," len=%d %s-%s", len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001429 ipaddr_string(ndo, data),
1430 ipaddr_string(ndo, data + sizeof(struct in_addr))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001431 }
1432 len = 0;
1433 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001434 case IPSECDOI_ID_IPV6_ADDR_RANGE:
1435 if (len < 32)
JP Abgrall53f17a92014-02-12 14:02:41 -08001436 ND_PRINT((ndo," len=%d [bad: < 32]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001437 else {
JP Abgrall53f17a92014-02-12 14:02:41 -08001438 ND_PRINT((ndo," len=%d %s-%s", len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001439 ip6addr_string(ndo, data),
1440 ip6addr_string(ndo, data + sizeof(struct in6_addr))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001441 }
1442 len = 0;
1443 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001444 case IPSECDOI_ID_DER_ASN1_DN:
1445 case IPSECDOI_ID_DER_ASN1_GN:
1446 case IPSECDOI_ID_KEY_ID:
1447 break;
1448 }
1449 break;
1450 }
1451 }
1452 if (data && len) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001453 ND_PRINT((ndo," len=%d", len));
1454 if (2 < ndo->ndo_vflag) {
1455 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001456 if (!rawprint(ndo, (const uint8_t *)data, len))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001457 goto trunc;
1458 }
1459 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001460 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001461trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001462 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_ID)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001463 return NULL;
1464}
1465
1466static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001467ikev1_cert_print(netdissect_options *ndo, u_char tpay _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001468 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001469 const u_char *ep _U_, uint32_t phase _U_,
1470 uint32_t doi0 _U_,
1471 uint32_t proto0 _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001472{
JP Abgrall53f17a92014-02-12 14:02:41 -08001473 const struct ikev1_pl_cert *p;
1474 struct ikev1_pl_cert cert;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001475 static const char *certstr[] = {
1476 "none", "pkcs7", "pgp", "dns",
1477 "x509sign", "x509ke", "kerberos", "crl",
1478 "arl", "spki", "x509attr",
1479 };
1480
JP Abgrall53f17a92014-02-12 14:02:41 -08001481 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_CERT)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001482
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001483 p = (const struct ikev1_pl_cert *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001484 ND_TCHECK(*p);
1485 UNALIGNED_MEMCPY(&cert, ext, sizeof(cert));
1486 ND_PRINT((ndo," len=%d", item_len - 4));
1487 ND_PRINT((ndo," type=%s", STR_OR_ID((cert.encode), certstr)));
1488 if (2 < ndo->ndo_vflag && 4 < item_len) {
1489 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001490 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001491 goto trunc;
1492 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001493 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001494trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001495 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_CERT)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001496 return NULL;
1497}
1498
1499static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001500ikev1_cr_print(netdissect_options *ndo, u_char tpay _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001501 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001502 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi0 _U_,
1503 uint32_t proto0 _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001504{
JP Abgrall53f17a92014-02-12 14:02:41 -08001505 const struct ikev1_pl_cert *p;
1506 struct ikev1_pl_cert cert;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001507 static const char *certstr[] = {
1508 "none", "pkcs7", "pgp", "dns",
1509 "x509sign", "x509ke", "kerberos", "crl",
1510 "arl", "spki", "x509attr",
1511 };
1512
JP Abgrall53f17a92014-02-12 14:02:41 -08001513 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_CR)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001514
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001515 p = (const struct ikev1_pl_cert *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001516 ND_TCHECK(*p);
1517 UNALIGNED_MEMCPY(&cert, ext, sizeof(cert));
1518 ND_PRINT((ndo," len=%d", item_len - 4));
1519 ND_PRINT((ndo," type=%s", STR_OR_ID((cert.encode), certstr)));
1520 if (2 < ndo->ndo_vflag && 4 < item_len) {
1521 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001522 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001523 goto trunc;
1524 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001525 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001526trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001527 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_CR)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001528 return NULL;
1529}
1530
1531static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001532ikev1_hash_print(netdissect_options *ndo, u_char tpay _U_,
1533 const struct isakmp_gen *ext, u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001534 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi _U_,
1535 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001536{
1537 struct isakmp_gen e;
1538
JP Abgrall53f17a92014-02-12 14:02:41 -08001539 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_HASH)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001540
JP Abgrall53f17a92014-02-12 14:02:41 -08001541 ND_TCHECK(*ext);
1542 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
1543 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1544 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1545 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001546 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001547 goto trunc;
1548 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001549 return (const u_char *)ext + ntohs(e.len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001550trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001551 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_HASH)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001552 return NULL;
1553}
1554
1555static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001556ikev1_sig_print(netdissect_options *ndo, u_char tpay _U_,
1557 const struct isakmp_gen *ext, u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001558 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi _U_,
1559 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001560{
1561 struct isakmp_gen e;
1562
JP Abgrall53f17a92014-02-12 14:02:41 -08001563 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_SIG)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001564
JP Abgrall53f17a92014-02-12 14:02:41 -08001565 ND_TCHECK(*ext);
1566 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
1567 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1568 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1569 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001570 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001571 goto trunc;
1572 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001573 return (const u_char *)ext + ntohs(e.len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001574trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001575 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_SIG)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001576 return NULL;
1577}
1578
1579static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001580ikev1_nonce_print(netdissect_options *ndo, u_char tpay _U_,
1581 const struct isakmp_gen *ext,
1582 u_int item_len _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001583 const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001584 uint32_t phase _U_, uint32_t doi _U_,
1585 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001586{
JP Abgrall53f17a92014-02-12 14:02:41 -08001587 struct isakmp_gen e;
1588
1589 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_NONCE)));
1590
1591 ND_TCHECK(*ext);
1592 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
1593 ND_PRINT((ndo," n len=%d", ntohs(e.len) - 4));
1594 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1595 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001596 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08001597 goto trunc;
1598 } else if (1 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1599 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001600 if (!ike_show_somedata(ndo, (const u_char *)(const uint8_t *)(ext + 1), ep))
JP Abgrall53f17a92014-02-12 14:02:41 -08001601 goto trunc;
1602 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001603 return (const u_char *)ext + ntohs(e.len);
JP Abgrall53f17a92014-02-12 14:02:41 -08001604trunc:
1605 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE)));
1606 return NULL;
1607}
1608
1609static const u_char *
1610ikev1_n_print(netdissect_options *ndo, u_char tpay _U_,
1611 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001612 const u_char *ep, uint32_t phase, uint32_t doi0 _U_,
1613 uint32_t proto0 _U_, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08001614{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001615 const struct ikev1_pl_n *p;
1616 struct ikev1_pl_n n;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001617 const u_char *cp;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001618 const u_char *ep2;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001619 uint32_t doi;
1620 uint32_t proto;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001621 static const char *notify_error_str[] = {
1622 NULL, "INVALID-PAYLOAD-TYPE",
1623 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
1624 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
1625 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
1626 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
1627 "INVALID-PROTOCOL-ID", "INVALID-SPI",
1628 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
1629 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
1630 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
1631 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
1632 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
1633 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
1634 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
1635 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
1636 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
1637 "UNEQUAL-PAYLOAD-LENGTHS",
1638 };
1639 static const char *ipsec_notify_error_str[] = {
1640 "RESERVED",
1641 };
1642 static const char *notify_status_str[] = {
1643 "CONNECTED",
1644 };
1645 static const char *ipsec_notify_status_str[] = {
1646 "RESPONDER-LIFETIME", "REPLAY-STATUS",
1647 "INITIAL-CONTACT",
1648 };
1649/* NOTE: these macro must be called with x in proper range */
1650
1651/* 0 - 8191 */
1652#define NOTIFY_ERROR_STR(x) \
1653 STR_OR_ID((x), notify_error_str)
1654
1655/* 8192 - 16383 */
1656#define IPSEC_NOTIFY_ERROR_STR(x) \
1657 STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str)
1658
1659/* 16384 - 24575 */
1660#define NOTIFY_STATUS_STR(x) \
1661 STR_OR_ID((u_int)((x) - 16384), notify_status_str)
1662
1663/* 24576 - 32767 */
1664#define IPSEC_NOTIFY_STATUS_STR(x) \
1665 STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str)
1666
JP Abgrall53f17a92014-02-12 14:02:41 -08001667 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_N)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001668
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001669 p = (const struct ikev1_pl_n *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001670 ND_TCHECK(*p);
1671 UNALIGNED_MEMCPY(&n, ext, sizeof(n));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001672 doi = ntohl(n.doi);
1673 proto = n.prot_id;
1674 if (doi != 1) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001675 ND_PRINT((ndo," doi=%d", doi));
1676 ND_PRINT((ndo," proto=%d", proto));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001677 if (ntohs(n.type) < 8192)
JP Abgrall53f17a92014-02-12 14:02:41 -08001678 ND_PRINT((ndo," type=%s", NOTIFY_ERROR_STR(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001679 else if (ntohs(n.type) < 16384)
JP Abgrall53f17a92014-02-12 14:02:41 -08001680 ND_PRINT((ndo," type=%s", numstr(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001681 else if (ntohs(n.type) < 24576)
JP Abgrall53f17a92014-02-12 14:02:41 -08001682 ND_PRINT((ndo," type=%s", NOTIFY_STATUS_STR(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001683 else
JP Abgrall53f17a92014-02-12 14:02:41 -08001684 ND_PRINT((ndo," type=%s", numstr(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001685 if (n.spi_size) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001686 ND_PRINT((ndo," spi="));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001687 if (!rawprint(ndo, (const uint8_t *)(p + 1), n.spi_size))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001688 goto trunc;
1689 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001690 return (const u_char *)(p + 1) + n.spi_size;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001691 }
1692
JP Abgrall53f17a92014-02-12 14:02:41 -08001693 ND_PRINT((ndo," doi=ipsec"));
1694 ND_PRINT((ndo," proto=%s", PROTOIDSTR(proto)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001695 if (ntohs(n.type) < 8192)
JP Abgrall53f17a92014-02-12 14:02:41 -08001696 ND_PRINT((ndo," type=%s", NOTIFY_ERROR_STR(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001697 else if (ntohs(n.type) < 16384)
JP Abgrall53f17a92014-02-12 14:02:41 -08001698 ND_PRINT((ndo," type=%s", IPSEC_NOTIFY_ERROR_STR(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001699 else if (ntohs(n.type) < 24576)
JP Abgrall53f17a92014-02-12 14:02:41 -08001700 ND_PRINT((ndo," type=%s", NOTIFY_STATUS_STR(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001701 else if (ntohs(n.type) < 32768)
JP Abgrall53f17a92014-02-12 14:02:41 -08001702 ND_PRINT((ndo," type=%s", IPSEC_NOTIFY_STATUS_STR(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001703 else
JP Abgrall53f17a92014-02-12 14:02:41 -08001704 ND_PRINT((ndo," type=%s", numstr(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001705 if (n.spi_size) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001706 ND_PRINT((ndo," spi="));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001707 if (!rawprint(ndo, (const uint8_t *)(p + 1), n.spi_size))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001708 goto trunc;
1709 }
1710
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001711 cp = (const u_char *)(p + 1) + n.spi_size;
1712 ep2 = (const u_char *)p + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001713
1714 if (cp < ep) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001715 ND_PRINT((ndo," orig=("));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001716 switch (ntohs(n.type)) {
1717 case IPSECDOI_NTYPE_RESPONDER_LIFETIME:
1718 {
1719 const struct attrmap *map = oakley_t_map;
1720 size_t nmap = sizeof(oakley_t_map)/sizeof(oakley_t_map[0]);
1721 while (cp < ep && cp < ep2) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001722 cp = ikev1_attrmap_print(ndo, cp,
The Android Open Source Project2949f582009-03-03 19:30:46 -08001723 (ep < ep2) ? ep : ep2, map, nmap);
1724 }
1725 break;
1726 }
1727 case IPSECDOI_NTYPE_REPLAY_STATUS:
JP Abgrall53f17a92014-02-12 14:02:41 -08001728 ND_PRINT((ndo,"replay detection %sabled",
1729 EXTRACT_32BITS(cp) ? "en" : "dis"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001730 break;
1731 case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN:
JP Abgrall53f17a92014-02-12 14:02:41 -08001732 if (ikev1_sub_print(ndo, ISAKMP_NPTYPE_SA,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001733 (const struct isakmp_gen *)cp, ep, phase, doi, proto,
JP Abgrall53f17a92014-02-12 14:02:41 -08001734 depth) == NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001735 return NULL;
1736 break;
1737 default:
1738 /* NULL is dummy */
JP Abgrall53f17a92014-02-12 14:02:41 -08001739 isakmp_print(ndo, cp,
The Android Open Source Project2949f582009-03-03 19:30:46 -08001740 item_len - sizeof(*p) - n.spi_size,
1741 NULL);
1742 }
JP Abgrall53f17a92014-02-12 14:02:41 -08001743 ND_PRINT((ndo,")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001744 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001745 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001746trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001747 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_N)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001748 return NULL;
1749}
1750
1751static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001752ikev1_d_print(netdissect_options *ndo, u_char tpay _U_,
1753 const struct isakmp_gen *ext, u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001754 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi0 _U_,
1755 uint32_t proto0 _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001756{
JP Abgrall53f17a92014-02-12 14:02:41 -08001757 const struct ikev1_pl_d *p;
1758 struct ikev1_pl_d d;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001759 const uint8_t *q;
1760 uint32_t doi;
1761 uint32_t proto;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001762 int i;
1763
JP Abgrall53f17a92014-02-12 14:02:41 -08001764 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_D)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001765
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001766 p = (const struct ikev1_pl_d *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001767 ND_TCHECK(*p);
1768 UNALIGNED_MEMCPY(&d, ext, sizeof(d));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001769 doi = ntohl(d.doi);
1770 proto = d.prot_id;
1771 if (doi != 1) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001772 ND_PRINT((ndo," doi=%u", doi));
1773 ND_PRINT((ndo," proto=%u", proto));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001774 } else {
JP Abgrall53f17a92014-02-12 14:02:41 -08001775 ND_PRINT((ndo," doi=ipsec"));
1776 ND_PRINT((ndo," proto=%s", PROTOIDSTR(proto)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001777 }
JP Abgrall53f17a92014-02-12 14:02:41 -08001778 ND_PRINT((ndo," spilen=%u", d.spi_size));
1779 ND_PRINT((ndo," nspi=%u", ntohs(d.num_spi)));
1780 ND_PRINT((ndo," spi="));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001781 q = (const uint8_t *)(p + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001782 for (i = 0; i < ntohs(d.num_spi); i++) {
1783 if (i != 0)
JP Abgrall53f17a92014-02-12 14:02:41 -08001784 ND_PRINT((ndo,","));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001785 if (!rawprint(ndo, (const uint8_t *)q, d.spi_size))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001786 goto trunc;
1787 q += d.spi_size;
1788 }
1789 return q;
1790trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001791 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_D)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001792 return NULL;
1793}
1794
1795static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001796ikev1_vid_print(netdissect_options *ndo, u_char tpay _U_,
1797 const struct isakmp_gen *ext,
1798 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001799 uint32_t phase _U_, uint32_t doi _U_,
1800 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001801{
1802 struct isakmp_gen e;
1803
JP Abgrall53f17a92014-02-12 14:02:41 -08001804 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_VID)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001805
JP Abgrall53f17a92014-02-12 14:02:41 -08001806 ND_TCHECK(*ext);
1807 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
1808 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1809 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1810 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001811 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001812 goto trunc;
1813 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001814 return (const u_char *)ext + ntohs(e.len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001815trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001816 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_VID)));
1817 return NULL;
1818}
1819
1820/************************************************************/
1821/* */
1822/* IKE v2 - rfc4306 - dissector */
1823/* */
1824/************************************************************/
1825
1826static void
1827ikev2_pay_print(netdissect_options *ndo, const char *payname, int critical)
1828{
1829 ND_PRINT((ndo,"%s%s:", payname, critical&0x80 ? "[C]" : ""));
1830}
1831
1832static const u_char *
1833ikev2_gen_print(netdissect_options *ndo, u_char tpay,
1834 const struct isakmp_gen *ext)
1835{
1836 struct isakmp_gen e;
1837
1838 ND_TCHECK(*ext);
1839 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
1840 ikev2_pay_print(ndo, NPSTR(tpay), e.critical);
1841
1842 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1843 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
1844 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001845 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08001846 goto trunc;
1847 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001848 return (const u_char *)ext + ntohs(e.len);
JP Abgrall53f17a92014-02-12 14:02:41 -08001849trunc:
1850 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001851 return NULL;
1852}
1853
1854static const u_char *
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001855ikev2_t_print(netdissect_options *ndo, int tcount,
JP Abgrall53f17a92014-02-12 14:02:41 -08001856 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001857 const u_char *ep)
JP Abgrall53f17a92014-02-12 14:02:41 -08001858{
1859 const struct ikev2_t *p;
1860 struct ikev2_t t;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001861 uint16_t t_id;
JP Abgrall53f17a92014-02-12 14:02:41 -08001862 const u_char *cp;
1863 const char *idstr;
1864 const struct attrmap *map;
1865 size_t nmap;
1866 const u_char *ep2;
1867
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001868 p = (const struct ikev2_t *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001869 ND_TCHECK(*p);
1870 UNALIGNED_MEMCPY(&t, ext, sizeof(t));
1871 ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_T), t.h.critical);
1872
1873 t_id = ntohs(t.t_id);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001874
JP Abgrall53f17a92014-02-12 14:02:41 -08001875 map = NULL;
1876 nmap = 0;
1877
1878 switch (t.t_type) {
1879 case IV2_T_ENCR:
1880 idstr = STR_OR_ID(t_id, esp_p_map);
1881 map = encr_t_map;
1882 nmap = sizeof(encr_t_map)/sizeof(encr_t_map[0]);
1883 break;
1884
1885 case IV2_T_PRF:
1886 idstr = STR_OR_ID(t_id, prf_p_map);
1887 break;
1888
1889 case IV2_T_INTEG:
1890 idstr = STR_OR_ID(t_id, integ_p_map);
1891 break;
1892
1893 case IV2_T_DH:
1894 idstr = STR_OR_ID(t_id, dh_p_map);
1895 break;
1896
1897 case IV2_T_ESN:
1898 idstr = STR_OR_ID(t_id, esn_p_map);
1899 break;
1900
1901 default:
1902 idstr = NULL;
1903 break;
1904 }
1905
1906 if (idstr)
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001907 ND_PRINT((ndo," #%u type=%s id=%s ", tcount,
JP Abgrall53f17a92014-02-12 14:02:41 -08001908 STR_OR_ID(t.t_type, ikev2_t_type_map),
1909 idstr));
1910 else
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001911 ND_PRINT((ndo," #%u type=%s id=%u ", tcount,
JP Abgrall53f17a92014-02-12 14:02:41 -08001912 STR_OR_ID(t.t_type, ikev2_t_type_map),
1913 t.t_id));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001914 cp = (const u_char *)(p + 1);
1915 ep2 = (const u_char *)p + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08001916 while (cp < ep && cp < ep2) {
1917 if (map && nmap) {
1918 cp = ikev1_attrmap_print(ndo, cp, (ep < ep2) ? ep : ep2,
1919 map, nmap);
1920 } else
1921 cp = ikev1_attr_print(ndo, cp, (ep < ep2) ? ep : ep2);
1922 }
1923 if (ep < ep2)
1924 ND_PRINT((ndo,"..."));
1925 return cp;
1926trunc:
1927 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_T)));
1928 return NULL;
1929}
1930
1931static const u_char *
1932ikev2_p_print(netdissect_options *ndo, u_char tpay _U_, int pcount _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001933 const struct isakmp_gen *ext, u_int oprop_length,
1934 const u_char *ep, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08001935{
1936 const struct ikev2_p *p;
1937 struct ikev2_p prop;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001938 u_int prop_length;
JP Abgrall53f17a92014-02-12 14:02:41 -08001939 const u_char *cp;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001940 int i;
1941 int tcount;
1942 u_char np;
1943 struct isakmp_gen e;
1944 u_int item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08001945
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001946 p = (const struct ikev2_p *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001947 ND_TCHECK(*p);
1948 UNALIGNED_MEMCPY(&prop, ext, sizeof(prop));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001949
JP Abgrall53f17a92014-02-12 14:02:41 -08001950 ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_P), prop.h.critical);
1951
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001952 /*
1953 * ikev2_sa_print() guarantees that this is >= 4.
1954 */
1955 prop_length = oprop_length - 4;
JP Abgrall53f17a92014-02-12 14:02:41 -08001956 ND_PRINT((ndo," #%u protoid=%s transform=%d len=%u",
1957 prop.p_no, PROTOIDSTR(prop.prot_id),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001958 prop.num_t, oprop_length));
1959 cp = (const u_char *)(p + 1);
1960
JP Abgrall53f17a92014-02-12 14:02:41 -08001961 if (prop.spi_size) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001962 if (prop_length < prop.spi_size)
1963 goto toolong;
JP Abgrall53f17a92014-02-12 14:02:41 -08001964 ND_PRINT((ndo," spi="));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001965 if (!rawprint(ndo, (const uint8_t *)cp, prop.spi_size))
JP Abgrall53f17a92014-02-12 14:02:41 -08001966 goto trunc;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001967 cp += prop.spi_size;
1968 prop_length -= prop.spi_size;
JP Abgrall53f17a92014-02-12 14:02:41 -08001969 }
1970
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001971 /*
1972 * Print the transforms.
1973 */
1974 tcount = 0;
1975 for (np = ISAKMP_NPTYPE_T; np != 0; np = e.np) {
1976 tcount++;
1977 ext = (const struct isakmp_gen *)cp;
1978 if (prop_length < sizeof(*ext))
1979 goto toolong;
1980 ND_TCHECK(*ext);
JP Abgrall53f17a92014-02-12 14:02:41 -08001981
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001982 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001983
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001984 /*
1985 * Since we can't have a payload length of less than 4 bytes,
1986 * we need to bail out here if the generic header is nonsensical
1987 * or truncated, otherwise we could loop forever processing
1988 * zero-length items or otherwise misdissect the packet.
1989 */
1990 item_len = ntohs(e.len);
1991 if (item_len <= 4)
1992 goto trunc;
1993
1994 if (prop_length < item_len)
1995 goto toolong;
1996 ND_TCHECK2(*cp, item_len);
1997
1998 depth++;
1999 ND_PRINT((ndo,"\n"));
2000 for (i = 0; i < depth; i++)
2001 ND_PRINT((ndo," "));
2002 ND_PRINT((ndo,"("));
2003 if (np == ISAKMP_NPTYPE_T) {
2004 cp = ikev2_t_print(ndo, tcount, ext, item_len, ep);
2005 if (cp == NULL) {
2006 /* error, already reported */
2007 return NULL;
2008 }
2009 } else {
2010 ND_PRINT((ndo, "%s", NPSTR(np)));
2011 cp += item_len;
2012 }
2013 ND_PRINT((ndo,")"));
2014 depth--;
2015 prop_length -= item_len;
2016 }
2017 return cp;
2018toolong:
2019 /*
2020 * Skip the rest of the proposal.
2021 */
2022 cp += prop_length;
2023 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_P)));
JP Abgrall53f17a92014-02-12 14:02:41 -08002024 return cp;
2025trunc:
2026 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_P)));
2027 return NULL;
2028}
2029
2030static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002031ikev2_sa_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002032 const struct isakmp_gen *ext1,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002033 u_int osa_length, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002034 uint32_t phase _U_, uint32_t doi _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002035 uint32_t proto _U_, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08002036{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002037 const struct isakmp_gen *ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08002038 struct isakmp_gen e;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002039 u_int sa_length;
2040 const u_char *cp;
2041 int i;
2042 int pcount;
2043 u_char np;
2044 u_int item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002045
2046 ND_TCHECK(*ext1);
2047 UNALIGNED_MEMCPY(&e, ext1, sizeof(e));
2048 ikev2_pay_print(ndo, "sa", e.critical);
2049
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002050 /*
2051 * ikev2_sub0_print() guarantees that this is >= 4.
2052 */
JP Abgrall53f17a92014-02-12 14:02:41 -08002053 osa_length= ntohs(e.len);
2054 sa_length = osa_length - 4;
2055 ND_PRINT((ndo," len=%d", sa_length));
2056
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002057 /*
2058 * Print the payloads.
2059 */
2060 cp = (const u_char *)(ext1 + 1);
2061 pcount = 0;
2062 for (np = ISAKMP_NPTYPE_P; np != 0; np = e.np) {
2063 pcount++;
2064 ext = (const struct isakmp_gen *)cp;
2065 if (sa_length < sizeof(*ext))
2066 goto toolong;
2067 ND_TCHECK(*ext);
JP Abgrall53f17a92014-02-12 14:02:41 -08002068
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002069 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2070
2071 /*
2072 * Since we can't have a payload length of less than 4 bytes,
2073 * we need to bail out here if the generic header is nonsensical
2074 * or truncated, otherwise we could loop forever processing
2075 * zero-length items or otherwise misdissect the packet.
2076 */
2077 item_len = ntohs(e.len);
2078 if (item_len <= 4)
2079 goto trunc;
2080
2081 if (sa_length < item_len)
2082 goto toolong;
2083 ND_TCHECK2(*cp, item_len);
2084
2085 depth++;
2086 ND_PRINT((ndo,"\n"));
2087 for (i = 0; i < depth; i++)
2088 ND_PRINT((ndo," "));
2089 ND_PRINT((ndo,"("));
2090 if (np == ISAKMP_NPTYPE_P) {
2091 cp = ikev2_p_print(ndo, np, pcount, ext, item_len,
2092 ep, depth);
2093 if (cp == NULL) {
2094 /* error, already reported */
2095 return NULL;
2096 }
2097 } else {
2098 ND_PRINT((ndo, "%s", NPSTR(np)));
2099 cp += item_len;
2100 }
2101 ND_PRINT((ndo,")"));
2102 depth--;
2103 sa_length -= item_len;
2104 }
2105 return cp;
2106toolong:
2107 /*
2108 * Skip the rest of the SA.
2109 */
2110 cp += sa_length;
2111 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2112 return cp;
JP Abgrall53f17a92014-02-12 14:02:41 -08002113trunc:
2114 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2115 return NULL;
2116}
2117
2118static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002119ikev2_ke_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002120 const struct isakmp_gen *ext,
2121 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002122 uint32_t phase _U_, uint32_t doi _U_,
2123 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002124{
2125 struct ikev2_ke ke;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002126 const struct ikev2_ke *k;
JP Abgrall53f17a92014-02-12 14:02:41 -08002127
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002128 k = (const struct ikev2_ke *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08002129 ND_TCHECK(*ext);
2130 UNALIGNED_MEMCPY(&ke, ext, sizeof(ke));
2131 ikev2_pay_print(ndo, NPSTR(tpay), ke.h.critical);
2132
2133 ND_PRINT((ndo," len=%u group=%s", ntohs(ke.h.len) - 8,
2134 STR_OR_ID(ntohs(ke.ke_group), dh_p_map)));
Elliott Hughes892a68b2015-10-19 14:43:53 -07002135
JP Abgrall53f17a92014-02-12 14:02:41 -08002136 if (2 < ndo->ndo_vflag && 8 < ntohs(ke.h.len)) {
2137 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002138 if (!rawprint(ndo, (const uint8_t *)(k + 1), ntohs(ke.h.len) - 8))
JP Abgrall53f17a92014-02-12 14:02:41 -08002139 goto trunc;
2140 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002141 return (const u_char *)ext + ntohs(ke.h.len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002142trunc:
2143 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2144 return NULL;
2145}
2146
2147static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002148ikev2_ID_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002149 const struct isakmp_gen *ext,
2150 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002151 uint32_t phase _U_, uint32_t doi _U_,
2152 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002153{
2154 struct ikev2_id id;
2155 int id_len, idtype_len, i;
2156 unsigned int dumpascii, dumphex;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002157 const unsigned char *typedata;
JP Abgrall53f17a92014-02-12 14:02:41 -08002158
2159 ND_TCHECK(*ext);
2160 UNALIGNED_MEMCPY(&id, ext, sizeof(id));
2161 ikev2_pay_print(ndo, NPSTR(tpay), id.h.critical);
2162
2163 id_len = ntohs(id.h.len);
2164
2165 ND_PRINT((ndo," len=%d", id_len - 4));
2166 if (2 < ndo->ndo_vflag && 4 < id_len) {
2167 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002168 if (!rawprint(ndo, (const uint8_t *)(ext + 1), id_len - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08002169 goto trunc;
2170 }
2171
2172 idtype_len =id_len - sizeof(struct ikev2_id);
2173 dumpascii = 0;
2174 dumphex = 0;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002175 typedata = (const unsigned char *)(ext)+sizeof(struct ikev2_id);
JP Abgrall53f17a92014-02-12 14:02:41 -08002176
2177 switch(id.type) {
2178 case ID_IPV4_ADDR:
2179 ND_PRINT((ndo, " ipv4:"));
2180 dumphex=1;
2181 break;
2182 case ID_FQDN:
2183 ND_PRINT((ndo, " fqdn:"));
2184 dumpascii=1;
2185 break;
2186 case ID_RFC822_ADDR:
2187 ND_PRINT((ndo, " rfc822:"));
2188 dumpascii=1;
2189 break;
2190 case ID_IPV6_ADDR:
2191 ND_PRINT((ndo, " ipv6:"));
2192 dumphex=1;
2193 break;
2194 case ID_DER_ASN1_DN:
2195 ND_PRINT((ndo, " dn:"));
2196 dumphex=1;
2197 break;
2198 case ID_DER_ASN1_GN:
2199 ND_PRINT((ndo, " gn:"));
2200 dumphex=1;
2201 break;
2202 case ID_KEY_ID:
2203 ND_PRINT((ndo, " keyid:"));
2204 dumphex=1;
2205 break;
2206 }
2207
2208 if(dumpascii) {
2209 ND_TCHECK2(*typedata, idtype_len);
2210 for(i=0; i<idtype_len; i++) {
2211 if(ND_ISPRINT(typedata[i])) {
2212 ND_PRINT((ndo, "%c", typedata[i]));
2213 } else {
2214 ND_PRINT((ndo, "."));
2215 }
2216 }
2217 }
2218 if(dumphex) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002219 if (!rawprint(ndo, (const uint8_t *)typedata, idtype_len))
JP Abgrall53f17a92014-02-12 14:02:41 -08002220 goto trunc;
2221 }
2222
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002223 return (const u_char *)ext + id_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002224trunc:
2225 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2226 return NULL;
2227}
2228
2229static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002230ikev2_cert_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002231 const struct isakmp_gen *ext,
2232 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002233 uint32_t phase _U_, uint32_t doi _U_,
2234 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002235{
2236 return ikev2_gen_print(ndo, tpay, ext);
2237}
2238
2239static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002240ikev2_cr_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002241 const struct isakmp_gen *ext,
2242 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002243 uint32_t phase _U_, uint32_t doi _U_,
2244 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002245{
2246 return ikev2_gen_print(ndo, tpay, ext);
2247}
2248
2249static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002250ikev2_auth_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002251 const struct isakmp_gen *ext,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002252 u_int item_len _U_, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002253 uint32_t phase _U_, uint32_t doi _U_,
2254 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002255{
2256 struct ikev2_auth a;
2257 const char *v2_auth[]={ "invalid", "rsasig",
2258 "shared-secret", "dsssig" };
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002259 const u_char *authdata = (const u_char*)ext + sizeof(a);
JP Abgrall53f17a92014-02-12 14:02:41 -08002260 unsigned int len;
2261
2262 ND_TCHECK(*ext);
2263 UNALIGNED_MEMCPY(&a, ext, sizeof(a));
2264 ikev2_pay_print(ndo, NPSTR(tpay), a.h.critical);
2265 len = ntohs(a.h.len);
2266
Elliott Hughes892a68b2015-10-19 14:43:53 -07002267 ND_PRINT((ndo," len=%d method=%s", len-4,
JP Abgrall53f17a92014-02-12 14:02:41 -08002268 STR_OR_ID(a.auth_method, v2_auth)));
2269
2270 if (1 < ndo->ndo_vflag && 4 < len) {
2271 ND_PRINT((ndo," authdata=("));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002272 if (!rawprint(ndo, (const uint8_t *)authdata, len - sizeof(a)))
JP Abgrall53f17a92014-02-12 14:02:41 -08002273 goto trunc;
2274 ND_PRINT((ndo,") "));
2275 } else if(ndo->ndo_vflag && 4 < len) {
2276 if(!ike_show_somedata(ndo, authdata, ep)) goto trunc;
2277 }
2278
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002279 return (const u_char *)ext + len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002280trunc:
2281 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2282 return NULL;
2283}
2284
2285static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002286ikev2_nonce_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002287 const struct isakmp_gen *ext,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002288 u_int item_len _U_, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002289 uint32_t phase _U_, uint32_t doi _U_,
2290 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002291{
2292 struct isakmp_gen e;
2293
2294 ND_TCHECK(*ext);
2295 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2296 ikev2_pay_print(ndo, "nonce", e.critical);
2297
2298 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
2299 if (1 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
2300 ND_PRINT((ndo," nonce=("));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002301 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08002302 goto trunc;
2303 ND_PRINT((ndo,") "));
2304 } else if(ndo->ndo_vflag && 4 < ntohs(e.len)) {
2305 if(!ike_show_somedata(ndo, (const u_char *)(ext+1), ep)) goto trunc;
2306 }
2307
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002308 return (const u_char *)ext + ntohs(e.len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002309trunc:
2310 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2311 return NULL;
2312}
2313
2314/* notify payloads */
2315static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002316ikev2_n_print(netdissect_options *ndo, u_char tpay _U_,
JP Abgrall53f17a92014-02-12 14:02:41 -08002317 const struct isakmp_gen *ext,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002318 u_int item_len, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002319 uint32_t phase _U_, uint32_t doi _U_,
2320 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002321{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002322 const struct ikev2_n *p;
2323 struct ikev2_n n;
JP Abgrall53f17a92014-02-12 14:02:41 -08002324 const u_char *cp;
2325 u_char showspi, showdata, showsomedata;
2326 const char *notify_name;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002327 uint32_t type;
JP Abgrall53f17a92014-02-12 14:02:41 -08002328
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002329 p = (const struct ikev2_n *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08002330 ND_TCHECK(*p);
2331 UNALIGNED_MEMCPY(&n, ext, sizeof(n));
2332 ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_N), n.h.critical);
2333
2334 showspi = 1;
2335 showdata = 0;
2336 showsomedata=0;
2337 notify_name=NULL;
2338
2339 ND_PRINT((ndo," prot_id=%s", PROTOIDSTR(n.prot_id)));
2340
2341 type = ntohs(n.type);
2342
2343 /* notify space is annoying sparse */
2344 switch(type) {
2345 case IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD:
2346 notify_name = "unsupported_critical_payload";
2347 showspi = 0;
2348 break;
2349
2350 case IV2_NOTIFY_INVALID_IKE_SPI:
2351 notify_name = "invalid_ike_spi";
2352 showspi = 1;
2353 break;
2354
2355 case IV2_NOTIFY_INVALID_MAJOR_VERSION:
2356 notify_name = "invalid_major_version";
2357 showspi = 0;
2358 break;
2359
2360 case IV2_NOTIFY_INVALID_SYNTAX:
2361 notify_name = "invalid_syntax";
2362 showspi = 1;
2363 break;
2364
2365 case IV2_NOTIFY_INVALID_MESSAGE_ID:
2366 notify_name = "invalid_message_id";
2367 showspi = 1;
2368 break;
2369
2370 case IV2_NOTIFY_INVALID_SPI:
2371 notify_name = "invalid_spi";
2372 showspi = 1;
2373 break;
2374
2375 case IV2_NOTIFY_NO_PROPOSAL_CHOSEN:
2376 notify_name = "no_protocol_chosen";
2377 showspi = 1;
2378 break;
2379
2380 case IV2_NOTIFY_INVALID_KE_PAYLOAD:
2381 notify_name = "invalid_ke_payload";
2382 showspi = 1;
2383 break;
2384
2385 case IV2_NOTIFY_AUTHENTICATION_FAILED:
2386 notify_name = "authentication_failed";
2387 showspi = 1;
2388 break;
2389
2390 case IV2_NOTIFY_SINGLE_PAIR_REQUIRED:
2391 notify_name = "single_pair_required";
2392 showspi = 1;
2393 break;
2394
2395 case IV2_NOTIFY_NO_ADDITIONAL_SAS:
2396 notify_name = "no_additional_sas";
2397 showspi = 0;
2398 break;
2399
2400 case IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE:
2401 notify_name = "internal_address_failure";
2402 showspi = 0;
2403 break;
2404
Elliott Hughes892a68b2015-10-19 14:43:53 -07002405 case IV2_NOTIFY_FAILED_CP_REQUIRED:
JP Abgrall53f17a92014-02-12 14:02:41 -08002406 notify_name = "failed:cp_required";
2407 showspi = 0;
2408 break;
2409
2410 case IV2_NOTIFY_INVALID_SELECTORS:
2411 notify_name = "invalid_selectors";
2412 showspi = 0;
2413 break;
2414
2415 case IV2_NOTIFY_INITIAL_CONTACT:
2416 notify_name = "initial_contact";
2417 showspi = 0;
2418 break;
2419
Elliott Hughes892a68b2015-10-19 14:43:53 -07002420 case IV2_NOTIFY_SET_WINDOW_SIZE:
JP Abgrall53f17a92014-02-12 14:02:41 -08002421 notify_name = "set_window_size";
2422 showspi = 0;
2423 break;
2424
2425 case IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE:
2426 notify_name = "additional_ts_possible";
2427 showspi = 0;
2428 break;
2429
Elliott Hughes892a68b2015-10-19 14:43:53 -07002430 case IV2_NOTIFY_IPCOMP_SUPPORTED:
JP Abgrall53f17a92014-02-12 14:02:41 -08002431 notify_name = "ipcomp_supported";
2432 showspi = 0;
2433 break;
2434
2435 case IV2_NOTIFY_NAT_DETECTION_SOURCE_IP:
2436 notify_name = "nat_detection_source_ip";
2437 showspi = 1;
2438 break;
2439
2440 case IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP:
2441 notify_name = "nat_detection_destination_ip";
2442 showspi = 1;
2443 break;
2444
2445 case IV2_NOTIFY_COOKIE:
2446 notify_name = "cookie";
2447 showspi = 1;
2448 showsomedata= 1;
2449 showdata= 0;
2450 break;
2451
2452 case IV2_NOTIFY_USE_TRANSPORT_MODE:
2453 notify_name = "use_transport_mode";
2454 showspi = 0;
2455 break;
2456
2457 case IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED:
2458 notify_name = "http_cert_lookup_supported";
2459 showspi = 0;
2460 break;
2461
2462 case IV2_NOTIFY_REKEY_SA:
2463 notify_name = "rekey_sa";
2464 showspi = 1;
2465 break;
2466
2467 case IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED:
2468 notify_name = "tfc_padding_not_supported";
2469 showspi = 0;
2470 break;
2471
2472 case IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO:
2473 notify_name = "non_first_fragment_also";
2474 showspi = 0;
2475 break;
2476
2477 default:
2478 if (type < 8192) {
2479 notify_name="error";
2480 } else if(type < 16384) {
2481 notify_name="private-error";
2482 } else if(type < 40960) {
2483 notify_name="status";
2484 } else {
2485 notify_name="private-status";
2486 }
2487 }
2488
2489 if(notify_name) {
2490 ND_PRINT((ndo," type=%u(%s)", type, notify_name));
2491 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002492
JP Abgrall53f17a92014-02-12 14:02:41 -08002493
2494 if (showspi && n.spi_size) {
2495 ND_PRINT((ndo," spi="));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002496 if (!rawprint(ndo, (const uint8_t *)(p + 1), n.spi_size))
JP Abgrall53f17a92014-02-12 14:02:41 -08002497 goto trunc;
2498 }
2499
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002500 cp = (const u_char *)(p + 1) + n.spi_size;
JP Abgrall53f17a92014-02-12 14:02:41 -08002501
2502 if(3 < ndo->ndo_vflag) {
2503 showdata = 1;
2504 }
2505
2506 if ((showdata || (showsomedata && ep-cp < 30)) && cp < ep) {
2507 ND_PRINT((ndo," data=("));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002508 if (!rawprint(ndo, (const uint8_t *)(cp), ep - cp))
JP Abgrall53f17a92014-02-12 14:02:41 -08002509 goto trunc;
2510
2511 ND_PRINT((ndo,")"));
2512
2513 } else if(showsomedata && cp < ep) {
2514 if(!ike_show_somedata(ndo, cp, ep)) goto trunc;
2515 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002516
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002517 return (const u_char *)ext + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002518trunc:
2519 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_N)));
2520 return NULL;
2521}
2522
2523static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002524ikev2_d_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002525 const struct isakmp_gen *ext,
2526 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002527 uint32_t phase _U_, uint32_t doi _U_,
2528 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002529{
2530 return ikev2_gen_print(ndo, tpay, ext);
2531}
2532
2533static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002534ikev2_vid_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002535 const struct isakmp_gen *ext,
2536 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002537 uint32_t phase _U_, uint32_t doi _U_,
2538 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002539{
2540 struct isakmp_gen e;
2541 const u_char *vid;
2542 int i, len;
2543
2544 ND_TCHECK(*ext);
2545 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2546 ikev2_pay_print(ndo, NPSTR(tpay), e.critical);
2547 ND_PRINT((ndo," len=%d vid=", ntohs(e.len) - 4));
2548
2549 vid = (const u_char *)(ext+1);
2550 len = ntohs(e.len) - 4;
2551 ND_TCHECK2(*vid, len);
2552 for(i=0; i<len; i++) {
2553 if(ND_ISPRINT(vid[i])) ND_PRINT((ndo, "%c", vid[i]));
2554 else ND_PRINT((ndo, "."));
2555 }
2556 if (2 < ndo->ndo_vflag && 4 < len) {
2557 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002558 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08002559 goto trunc;
2560 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002561 return (const u_char *)ext + ntohs(e.len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002562trunc:
2563 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2564 return NULL;
2565}
2566
2567static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002568ikev2_TS_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002569 const struct isakmp_gen *ext,
2570 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002571 uint32_t phase _U_, uint32_t doi _U_,
2572 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002573{
2574 return ikev2_gen_print(ndo, tpay, ext);
2575}
2576
2577static const u_char *
2578ikev2_e_print(netdissect_options *ndo,
2579#ifndef HAVE_LIBCRYPTO
2580 _U_
2581#endif
2582 struct isakmp *base,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002583 u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002584 const struct isakmp_gen *ext,
2585 u_int item_len _U_, const u_char *ep _U_,
2586#ifndef HAVE_LIBCRYPTO
2587 _U_
2588#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -07002589 uint32_t phase,
JP Abgrall53f17a92014-02-12 14:02:41 -08002590#ifndef HAVE_LIBCRYPTO
2591 _U_
2592#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -07002593 uint32_t doi,
JP Abgrall53f17a92014-02-12 14:02:41 -08002594#ifndef HAVE_LIBCRYPTO
2595 _U_
2596#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -07002597 uint32_t proto,
JP Abgrall53f17a92014-02-12 14:02:41 -08002598#ifndef HAVE_LIBCRYPTO
2599 _U_
2600#endif
2601 int depth)
2602{
2603 struct isakmp_gen e;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002604 const u_char *dat;
JP Abgrall53f17a92014-02-12 14:02:41 -08002605 volatile int dlen;
2606
2607 ND_TCHECK(*ext);
2608 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2609 ikev2_pay_print(ndo, NPSTR(tpay), e.critical);
2610
2611 dlen = ntohs(e.len)-4;
2612
2613 ND_PRINT((ndo," len=%d", dlen));
2614 if (2 < ndo->ndo_vflag && 4 < dlen) {
2615 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002616 if (!rawprint(ndo, (const uint8_t *)(ext + 1), dlen))
JP Abgrall53f17a92014-02-12 14:02:41 -08002617 goto trunc;
2618 }
2619
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002620 dat = (const u_char *)(ext+1);
JP Abgrall53f17a92014-02-12 14:02:41 -08002621 ND_TCHECK2(*dat, dlen);
Elliott Hughes892a68b2015-10-19 14:43:53 -07002622
JP Abgrall53f17a92014-02-12 14:02:41 -08002623#ifdef HAVE_LIBCRYPTO
2624 /* try to decypt it! */
2625 if(esp_print_decrypt_buffer_by_ikev2(ndo,
2626 base->flags & ISAKMP_FLAG_I,
2627 base->i_ck, base->r_ck,
2628 dat, dat+dlen)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002629
JP Abgrall53f17a92014-02-12 14:02:41 -08002630 ext = (const struct isakmp_gen *)ndo->ndo_packetp;
2631
2632 /* got it decrypted, print stuff inside. */
2633 ikev2_sub_print(ndo, base, e.np, ext, ndo->ndo_snapend,
2634 phase, doi, proto, depth+1);
2635 }
2636#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -07002637
JP Abgrall53f17a92014-02-12 14:02:41 -08002638
2639 /* always return NULL, because E must be at end, and NP refers
2640 * to what was inside.
2641 */
2642 return NULL;
2643trunc:
2644 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2645 return NULL;
2646}
2647
2648static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002649ikev2_cp_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002650 const struct isakmp_gen *ext,
2651 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002652 uint32_t phase _U_, uint32_t doi _U_,
2653 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002654{
2655 return ikev2_gen_print(ndo, tpay, ext);
2656}
2657
2658static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002659ikev2_eap_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002660 const struct isakmp_gen *ext,
2661 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002662 uint32_t phase _U_, uint32_t doi _U_,
2663 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002664{
2665 return ikev2_gen_print(ndo, tpay, ext);
2666}
2667
2668static const u_char *
2669ike_sub0_print(netdissect_options *ndo,
2670 u_char np, const struct isakmp_gen *ext, const u_char *ep,
2671
Elliott Hughes892a68b2015-10-19 14:43:53 -07002672 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002673{
2674 const u_char *cp;
2675 struct isakmp_gen e;
2676 u_int item_len;
2677
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002678 cp = (const u_char *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08002679 ND_TCHECK(*ext);
2680 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002681
2682 /*
2683 * Since we can't have a payload length of less than 4 bytes,
2684 * we need to bail out here if the generic header is nonsensical
2685 * or truncated, otherwise we could loop forever processing
2686 * zero-length items or otherwise misdissect the packet.
2687 */
2688 item_len = ntohs(e.len);
2689 if (item_len <= 4)
2690 return NULL;
2691
2692 if (NPFUNC(np)) {
2693 /*
2694 * XXX - what if item_len is too short, or too long,
2695 * for this payload type?
2696 */
JP Abgrall53f17a92014-02-12 14:02:41 -08002697 cp = (*npfunc[np])(ndo, np, ext, item_len, ep, phase, doi, proto, depth);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002698 } else {
JP Abgrall53f17a92014-02-12 14:02:41 -08002699 ND_PRINT((ndo,"%s", NPSTR(np)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002700 cp += item_len;
2701 }
2702
2703 return cp;
2704trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08002705 ND_PRINT((ndo," [|isakmp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002706 return NULL;
2707}
2708
2709static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08002710ikev1_sub_print(netdissect_options *ndo,
2711 u_char np, const struct isakmp_gen *ext, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002712 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002713{
2714 const u_char *cp;
2715 int i;
2716 struct isakmp_gen e;
2717
2718 cp = (const u_char *)ext;
2719
2720 while (np) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002721 ND_TCHECK(*ext);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002722
JP Abgrall53f17a92014-02-12 14:02:41 -08002723 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2724
2725 ND_TCHECK2(*ext, ntohs(e.len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002726
2727 depth++;
JP Abgrall53f17a92014-02-12 14:02:41 -08002728 ND_PRINT((ndo,"\n"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002729 for (i = 0; i < depth; i++)
JP Abgrall53f17a92014-02-12 14:02:41 -08002730 ND_PRINT((ndo," "));
2731 ND_PRINT((ndo,"("));
2732 cp = ike_sub0_print(ndo, np, ext, ep, phase, doi, proto, depth);
2733 ND_PRINT((ndo,")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002734 depth--;
2735
2736 if (cp == NULL) {
2737 /* Zero-length subitem */
2738 return NULL;
2739 }
2740
2741 np = e.np;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002742 ext = (const struct isakmp_gen *)cp;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002743 }
2744 return cp;
2745trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08002746 ND_PRINT((ndo," [|%s]", NPSTR(np)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002747 return NULL;
2748}
2749
2750static char *
2751numstr(int x)
2752{
2753 static char buf[20];
2754 snprintf(buf, sizeof(buf), "#%d", x);
2755 return buf;
2756}
2757
The Android Open Source Project2949f582009-03-03 19:30:46 -08002758static void
JP Abgrall53f17a92014-02-12 14:02:41 -08002759ikev1_print(netdissect_options *ndo,
2760 const u_char *bp, u_int length,
2761 const u_char *bp2, struct isakmp *base)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002762{
JP Abgrall53f17a92014-02-12 14:02:41 -08002763 const struct isakmp *p;
2764 const u_char *ep;
2765 u_char np;
2766 int i;
2767 int phase;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002768
JP Abgrall53f17a92014-02-12 14:02:41 -08002769 p = (const struct isakmp *)bp;
2770 ep = ndo->ndo_snapend;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002771
JP Abgrall53f17a92014-02-12 14:02:41 -08002772 phase = (EXTRACT_32BITS(base->msgid) == 0) ? 1 : 2;
2773 if (phase == 1)
2774 ND_PRINT((ndo," phase %d", phase));
2775 else
2776 ND_PRINT((ndo," phase %d/others", phase));
Elliott Hughes892a68b2015-10-19 14:43:53 -07002777
JP Abgrall53f17a92014-02-12 14:02:41 -08002778 i = cookie_find(&base->i_ck);
2779 if (i < 0) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002780 if (iszero((const u_char *)&base->r_ck, sizeof(base->r_ck))) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002781 /* the first packet */
2782 ND_PRINT((ndo," I"));
2783 if (bp2)
2784 cookie_record(&base->i_ck, bp2);
2785 } else
2786 ND_PRINT((ndo," ?"));
2787 } else {
2788 if (bp2 && cookie_isinitiator(i, bp2))
2789 ND_PRINT((ndo," I"));
2790 else if (bp2 && cookie_isresponder(i, bp2))
2791 ND_PRINT((ndo," R"));
2792 else
2793 ND_PRINT((ndo," ?"));
2794 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002795
JP Abgrall53f17a92014-02-12 14:02:41 -08002796 ND_PRINT((ndo," %s", ETYPESTR(base->etype)));
2797 if (base->flags) {
2798 ND_PRINT((ndo,"[%s%s]", base->flags & ISAKMP_FLAG_E ? "E" : "",
2799 base->flags & ISAKMP_FLAG_C ? "C" : ""));
2800 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002801
JP Abgrall53f17a92014-02-12 14:02:41 -08002802 if (ndo->ndo_vflag) {
2803 const struct isakmp_gen *ext;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002804
JP Abgrall53f17a92014-02-12 14:02:41 -08002805 ND_PRINT((ndo,":"));
Elliott Hughes892a68b2015-10-19 14:43:53 -07002806
JP Abgrall53f17a92014-02-12 14:02:41 -08002807 /* regardless of phase... */
2808 if (base->flags & ISAKMP_FLAG_E) {
2809 /*
2810 * encrypted, nothing we can do right now.
2811 * we hope to decrypt the packet in the future...
2812 */
2813 ND_PRINT((ndo," [encrypted %s]", NPSTR(base->np)));
2814 goto done;
2815 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002816
JP Abgrall53f17a92014-02-12 14:02:41 -08002817 CHECKLEN(p + 1, base->np);
2818 np = base->np;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002819 ext = (const struct isakmp_gen *)(p + 1);
JP Abgrall53f17a92014-02-12 14:02:41 -08002820 ikev1_sub_print(ndo, np, ext, ep, phase, 0, 0, 0);
2821 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002822
JP Abgrall53f17a92014-02-12 14:02:41 -08002823done:
2824 if (ndo->ndo_vflag) {
2825 if (ntohl(base->len) != length) {
2826 ND_PRINT((ndo," (len mismatch: isakmp %u/ip %u)",
Elliott Hughes892a68b2015-10-19 14:43:53 -07002827 (uint32_t)ntohl(base->len), length));
JP Abgrall53f17a92014-02-12 14:02:41 -08002828 }
2829 }
2830}
2831
2832static const u_char *
2833ikev2_sub0_print(netdissect_options *ndo, struct isakmp *base,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002834 u_char np,
JP Abgrall53f17a92014-02-12 14:02:41 -08002835 const struct isakmp_gen *ext, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002836 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08002837{
2838 const u_char *cp;
2839 struct isakmp_gen e;
2840 u_int item_len;
2841
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002842 cp = (const u_char *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08002843 ND_TCHECK(*ext);
2844 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2845
2846 /*
2847 * Since we can't have a payload length of less than 4 bytes,
2848 * we need to bail out here if the generic header is nonsensical
2849 * or truncated, otherwise we could loop forever processing
2850 * zero-length items or otherwise misdissect the packet.
2851 */
2852 item_len = ntohs(e.len);
2853 if (item_len <= 4)
2854 return NULL;
2855
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002856 if (np == ISAKMP_NPTYPE_v2E) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002857 cp = ikev2_e_print(ndo, base, np, ext, item_len,
2858 ep, phase, doi, proto, depth);
2859 } else if (NPFUNC(np)) {
2860 /*
2861 * XXX - what if item_len is too short, or too long,
2862 * for this payload type?
2863 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002864 cp = (*npfunc[np])(ndo, np, ext, item_len,
JP Abgrall53f17a92014-02-12 14:02:41 -08002865 ep, phase, doi, proto, depth);
2866 } else {
2867 ND_PRINT((ndo,"%s", NPSTR(np)));
2868 cp += item_len;
2869 }
2870
2871 return cp;
2872trunc:
2873 ND_PRINT((ndo," [|isakmp]"));
2874 return NULL;
2875}
2876
2877static const u_char *
2878ikev2_sub_print(netdissect_options *ndo,
2879 struct isakmp *base,
2880 u_char np, const struct isakmp_gen *ext, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002881 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08002882{
2883 const u_char *cp;
2884 int i;
JP Abgrall53f17a92014-02-12 14:02:41 -08002885 struct isakmp_gen e;
2886
2887 cp = (const u_char *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08002888 while (np) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002889 ND_TCHECK(*ext);
2890
2891 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2892
2893 ND_TCHECK2(*ext, ntohs(e.len));
2894
2895 depth++;
2896 ND_PRINT((ndo,"\n"));
2897 for (i = 0; i < depth; i++)
2898 ND_PRINT((ndo," "));
2899 ND_PRINT((ndo,"("));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002900 cp = ikev2_sub0_print(ndo, base, np,
JP Abgrall53f17a92014-02-12 14:02:41 -08002901 ext, ep, phase, doi, proto, depth);
2902 ND_PRINT((ndo,")"));
2903 depth--;
2904
2905 if (cp == NULL) {
2906 /* Zero-length subitem */
2907 return NULL;
2908 }
2909
2910 np = e.np;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002911 ext = (const struct isakmp_gen *)cp;
JP Abgrall53f17a92014-02-12 14:02:41 -08002912 }
2913 return cp;
2914trunc:
2915 ND_PRINT((ndo," [|%s]", NPSTR(np)));
2916 return NULL;
2917}
2918
2919static void
2920ikev2_print(netdissect_options *ndo,
2921 const u_char *bp, u_int length,
2922 const u_char *bp2 _U_, struct isakmp *base)
2923{
2924 const struct isakmp *p;
2925 const u_char *ep;
2926 u_char np;
2927 int phase;
2928
2929 p = (const struct isakmp *)bp;
2930 ep = ndo->ndo_snapend;
2931
2932 phase = (EXTRACT_32BITS(base->msgid) == 0) ? 1 : 2;
2933 if (phase == 1)
2934 ND_PRINT((ndo, " parent_sa"));
2935 else
2936 ND_PRINT((ndo, " child_sa "));
2937
2938 ND_PRINT((ndo, " %s", ETYPESTR(base->etype)));
2939 if (base->flags) {
2940 ND_PRINT((ndo, "[%s%s%s]",
2941 base->flags & ISAKMP_FLAG_I ? "I" : "",
2942 base->flags & ISAKMP_FLAG_V ? "V" : "",
2943 base->flags & ISAKMP_FLAG_R ? "R" : ""));
2944 }
2945
2946 if (ndo->ndo_vflag) {
2947 const struct isakmp_gen *ext;
2948
2949 ND_PRINT((ndo, ":"));
2950
2951 /* regardless of phase... */
2952 if (base->flags & ISAKMP_FLAG_E) {
2953 /*
2954 * encrypted, nothing we can do right now.
2955 * we hope to decrypt the packet in the future...
2956 */
2957 ND_PRINT((ndo, " [encrypted %s]", NPSTR(base->np)));
2958 goto done;
2959 }
2960
2961 CHECKLEN(p + 1, base->np)
2962
2963 np = base->np;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002964 ext = (const struct isakmp_gen *)(p + 1);
JP Abgrall53f17a92014-02-12 14:02:41 -08002965 ikev2_sub_print(ndo, base, np, ext, ep, phase, 0, 0, 0);
2966 }
2967
2968done:
2969 if (ndo->ndo_vflag) {
2970 if (ntohl(base->len) != length) {
2971 ND_PRINT((ndo, " (len mismatch: isakmp %u/ip %u)",
Elliott Hughes892a68b2015-10-19 14:43:53 -07002972 (uint32_t)ntohl(base->len), length));
JP Abgrall53f17a92014-02-12 14:02:41 -08002973 }
2974 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08002975}
2976
2977void
2978isakmp_print(netdissect_options *ndo,
2979 const u_char *bp, u_int length,
2980 const u_char *bp2)
2981{
2982 const struct isakmp *p;
2983 struct isakmp base;
2984 const u_char *ep;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002985 int major, minor;
2986
JP Abgrall53f17a92014-02-12 14:02:41 -08002987#ifdef HAVE_LIBCRYPTO
2988 /* initialize SAs */
2989 if (ndo->ndo_sa_list_head == NULL) {
2990 if (ndo->ndo_espsecret)
2991 esp_print_decodesecret(ndo);
2992 }
2993#endif
2994
The Android Open Source Project2949f582009-03-03 19:30:46 -08002995 p = (const struct isakmp *)bp;
2996 ep = ndo->ndo_snapend;
2997
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002998 if ((const struct isakmp *)ep < p + 1) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002999 ND_PRINT((ndo,"[|isakmp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003000 return;
3001 }
3002
JP Abgrall53f17a92014-02-12 14:02:41 -08003003 UNALIGNED_MEMCPY(&base, p, sizeof(base));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003004
JP Abgrall53f17a92014-02-12 14:02:41 -08003005 ND_PRINT((ndo,"isakmp"));
3006 major = (base.vers & ISAKMP_VERS_MAJOR)
3007 >> ISAKMP_VERS_MAJOR_SHIFT;
3008 minor = (base.vers & ISAKMP_VERS_MINOR)
3009 >> ISAKMP_VERS_MINOR_SHIFT;
3010
3011 if (ndo->ndo_vflag) {
3012 ND_PRINT((ndo," %d.%d", major, minor));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003013 }
3014
JP Abgrall53f17a92014-02-12 14:02:41 -08003015 if (ndo->ndo_vflag) {
3016 ND_PRINT((ndo," msgid "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07003017 hexprint(ndo, (const uint8_t *)&base.msgid, sizeof(base.msgid));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003018 }
3019
JP Abgrall53f17a92014-02-12 14:02:41 -08003020 if (1 < ndo->ndo_vflag) {
3021 ND_PRINT((ndo," cookie "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07003022 hexprint(ndo, (const uint8_t *)&base.i_ck, sizeof(base.i_ck));
JP Abgrall53f17a92014-02-12 14:02:41 -08003023 ND_PRINT((ndo,"->"));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07003024 hexprint(ndo, (const uint8_t *)&base.r_ck, sizeof(base.r_ck));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003025 }
JP Abgrall53f17a92014-02-12 14:02:41 -08003026 ND_PRINT((ndo,":"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003027
JP Abgrall53f17a92014-02-12 14:02:41 -08003028 switch(major) {
3029 case IKEv1_MAJOR_VERSION:
3030 ikev1_print(ndo, bp, length, bp2, &base);
3031 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08003032
JP Abgrall53f17a92014-02-12 14:02:41 -08003033 case IKEv2_MAJOR_VERSION:
3034 ikev2_print(ndo, bp, length, bp2, &base);
3035 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08003036 }
3037}
3038
3039void
3040isakmp_rfc3948_print(netdissect_options *ndo,
3041 const u_char *bp, u_int length,
3042 const u_char *bp2)
3043{
The Android Open Source Project2949f582009-03-03 19:30:46 -08003044
3045 if(length == 1 && bp[0]==0xff) {
3046 ND_PRINT((ndo, "isakmp-nat-keep-alive"));
3047 return;
3048 }
3049
3050 if(length < 4) {
3051 goto trunc;
3052 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07003053
The Android Open Source Project2949f582009-03-03 19:30:46 -08003054 /*
3055 * see if this is an IKE packet
3056 */
3057 if(bp[0]==0 && bp[1]==0 && bp[2]==0 && bp[3]==0) {
3058 ND_PRINT((ndo, "NONESP-encap: "));
3059 isakmp_print(ndo, bp+4, length-4, bp2);
3060 return;
3061 }
3062
3063 /* must be an ESP packet */
3064 {
3065 int nh, enh, padlen;
3066 int advance;
3067
3068 ND_PRINT((ndo, "UDP-encap: "));
3069
3070 advance = esp_print(ndo, bp, length, bp2, &enh, &padlen);
3071 if(advance <= 0)
3072 return;
3073
3074 bp += advance;
3075 length -= advance + padlen;
3076 nh = enh & 0xff;
Elliott Hughes892a68b2015-10-19 14:43:53 -07003077
The Android Open Source Project2949f582009-03-03 19:30:46 -08003078 ip_print_inner(ndo, bp, length, nh, bp2);
3079 return;
3080 }
3081
3082trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08003083 ND_PRINT((ndo,"[|isakmp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003084 return;
3085}
3086
3087/*
3088 * Local Variables:
3089 * c-style: whitesmith
3090 * c-basic-offset: 8
3091 * End:
3092 */
JP Abgrall53f17a92014-02-12 14:02:41 -08003093
3094
Elliott Hughes892a68b2015-10-19 14:43:53 -07003095
JP Abgrall53f17a92014-02-12 14:02:41 -08003096