blob: 04374b0b3298ee702cdf03e62ded3ba912b81348 [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"
Elliott Hughescec480a2017-12-19 16:54:57 -080054#include "ipproto.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080055
Elliott Hughes892a68b2015-10-19 14:43:53 -070056/* refer to RFC 2408 */
57
58typedef u_char cookie_t[8];
59typedef u_char msgid_t[4];
60
61#define PORT_ISAKMP 500
62
63/* 3.1 ISAKMP Header Format (IKEv1 and IKEv2)
64 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
65 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 ! Initiator !
67 ! Cookie !
68 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69 ! Responder !
70 ! Cookie !
71 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72 ! Next Payload ! MjVer ! MnVer ! Exchange Type ! Flags !
73 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 ! Message ID !
75 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 ! Length !
77 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78*/
79struct isakmp {
80 cookie_t i_ck; /* Initiator Cookie */
81 cookie_t r_ck; /* Responder Cookie */
82 uint8_t np; /* Next Payload Type */
83 uint8_t vers;
84#define ISAKMP_VERS_MAJOR 0xf0
85#define ISAKMP_VERS_MAJOR_SHIFT 4
86#define ISAKMP_VERS_MINOR 0x0f
87#define ISAKMP_VERS_MINOR_SHIFT 0
88 uint8_t etype; /* Exchange Type */
89 uint8_t flags; /* Flags */
90 msgid_t msgid;
91 uint32_t len; /* Length */
92};
93
94/* Next Payload Type */
95#define ISAKMP_NPTYPE_NONE 0 /* NONE*/
96#define ISAKMP_NPTYPE_SA 1 /* Security Association */
97#define ISAKMP_NPTYPE_P 2 /* Proposal */
98#define ISAKMP_NPTYPE_T 3 /* Transform */
99#define ISAKMP_NPTYPE_KE 4 /* Key Exchange */
100#define ISAKMP_NPTYPE_ID 5 /* Identification */
101#define ISAKMP_NPTYPE_CERT 6 /* Certificate */
102#define ISAKMP_NPTYPE_CR 7 /* Certificate Request */
103#define ISAKMP_NPTYPE_HASH 8 /* Hash */
104#define ISAKMP_NPTYPE_SIG 9 /* Signature */
105#define ISAKMP_NPTYPE_NONCE 10 /* Nonce */
106#define ISAKMP_NPTYPE_N 11 /* Notification */
107#define ISAKMP_NPTYPE_D 12 /* Delete */
108#define ISAKMP_NPTYPE_VID 13 /* Vendor ID */
109#define ISAKMP_NPTYPE_v2E 46 /* v2 Encrypted payload */
110
111#define IKEv1_MAJOR_VERSION 1
112#define IKEv1_MINOR_VERSION 0
113
114#define IKEv2_MAJOR_VERSION 2
115#define IKEv2_MINOR_VERSION 0
116
117/* Flags */
118#define ISAKMP_FLAG_E 0x01 /* Encryption Bit */
119#define ISAKMP_FLAG_C 0x02 /* Commit Bit */
120#define ISAKMP_FLAG_extra 0x04
121
122/* IKEv2 */
123#define ISAKMP_FLAG_I (1 << 3) /* (I)nitiator */
124#define ISAKMP_FLAG_V (1 << 4) /* (V)ersion */
125#define ISAKMP_FLAG_R (1 << 5) /* (R)esponse */
126
127
128/* 3.2 Payload Generic Header
129 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
130 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
131 ! Next Payload ! RESERVED ! Payload Length !
132 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
133*/
134struct isakmp_gen {
135 uint8_t np; /* Next Payload */
136 uint8_t critical; /* bit 7 - critical, rest is RESERVED */
137 uint16_t len; /* Payload Length */
138};
139
140/* 3.3 Data Attributes
141 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
142 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143 !A! Attribute Type ! AF=0 Attribute Length !
144 !F! ! AF=1 Attribute Value !
145 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
146 . AF=0 Attribute Value .
147 . AF=1 Not Transmitted .
148 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
149*/
150struct isakmp_data {
151 uint16_t type; /* defined by DOI-spec, and Attribute Format */
152 uint16_t lorv; /* if f equal 1, Attribute Length */
153 /* if f equal 0, Attribute Value */
154 /* if f equal 1, Attribute Value */
155};
156
157/* 3.4 Security Association Payload */
158 /* MAY NOT be used, because of being defined in ipsec-doi. */
159 /*
160 If the current payload is the last in the message,
161 then the value of the next payload field will be 0.
162 This field MUST NOT contain the
163 values for the Proposal or Transform payloads as they are considered
164 part of the security association negotiation. For example, this
165 field would contain the value "10" (Nonce payload) in the first
166 message of a Base Exchange (see Section 4.4) and the value "0" in the
167 first message of an Identity Protect Exchange (see Section 4.5).
168 */
169struct ikev1_pl_sa {
170 struct isakmp_gen h;
171 uint32_t doi; /* Domain of Interpretation */
172 uint32_t sit; /* Situation */
173};
174
175/* 3.5 Proposal Payload */
176 /*
177 The value of the next payload field MUST only contain the value "2"
178 or "0". If there are additional Proposal payloads in the message,
179 then this field will be 2. If the current Proposal payload is the
180 last within the security association proposal, then this field will
181 be 0.
182 */
183struct ikev1_pl_p {
184 struct isakmp_gen h;
185 uint8_t p_no; /* Proposal # */
186 uint8_t prot_id; /* Protocol */
187 uint8_t spi_size; /* SPI Size */
188 uint8_t num_t; /* Number of Transforms */
189 /* SPI */
190};
191
192/* 3.6 Transform Payload */
193 /*
194 The value of the next payload field MUST only contain the value "3"
195 or "0". If there are additional Transform payloads in the proposal,
196 then this field will be 3. If the current Transform payload is the
197 last within the proposal, then this field will be 0.
198 */
199struct ikev1_pl_t {
200 struct isakmp_gen h;
201 uint8_t t_no; /* Transform # */
202 uint8_t t_id; /* Transform-Id */
203 uint16_t reserved; /* RESERVED2 */
204 /* SA Attributes */
205};
206
207/* 3.7 Key Exchange Payload */
208struct ikev1_pl_ke {
209 struct isakmp_gen h;
210 /* Key Exchange Data */
211};
212
213/* 3.8 Identification Payload */
214 /* MUST NOT to be used, because of being defined in ipsec-doi. */
215struct ikev1_pl_id {
216 struct isakmp_gen h;
217 union {
218 uint8_t id_type; /* ID Type */
219 uint32_t doi_data; /* DOI Specific ID Data */
220 } d;
221 /* Identification Data */
222};
223
224/* 3.9 Certificate Payload */
225struct ikev1_pl_cert {
226 struct isakmp_gen h;
227 uint8_t encode; /* Cert Encoding */
228 char cert; /* Certificate Data */
229 /*
230 This field indicates the type of
231 certificate or certificate-related information contained in the
232 Certificate Data field.
233 */
234};
235
236/* 3.10 Certificate Request Payload */
237struct ikev1_pl_cr {
238 struct isakmp_gen h;
239 uint8_t num_cert; /* # Cert. Types */
240 /*
241 Certificate Types (variable length)
242 -- Contains a list of the types of certificates requested,
243 sorted in order of preference. Each individual certificate
244 type is 1 octet. This field is NOT requiredo
245 */
246 /* # Certificate Authorities (1 octet) */
247 /* Certificate Authorities (variable length) */
248};
249
250/* 3.11 Hash Payload */
251 /* may not be used, because of having only data. */
252struct ikev1_pl_hash {
253 struct isakmp_gen h;
254 /* Hash Data */
255};
256
257/* 3.12 Signature Payload */
258 /* may not be used, because of having only data. */
259struct ikev1_pl_sig {
260 struct isakmp_gen h;
261 /* Signature Data */
262};
263
264/* 3.13 Nonce Payload */
265 /* may not be used, because of having only data. */
266struct ikev1_pl_nonce {
267 struct isakmp_gen h;
268 /* Nonce Data */
269};
270
271/* 3.14 Notification Payload */
272struct ikev1_pl_n {
273 struct isakmp_gen h;
274 uint32_t doi; /* Domain of Interpretation */
275 uint8_t prot_id; /* Protocol-ID */
276 uint8_t spi_size; /* SPI Size */
277 uint16_t type; /* Notify Message Type */
278 /* SPI */
279 /* Notification Data */
280};
281
282/* 3.14.1 Notify Message Types */
283/* NOTIFY MESSAGES - ERROR TYPES */
284#define ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE 1
285#define ISAKMP_NTYPE_DOI_NOT_SUPPORTED 2
286#define ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED 3
287#define ISAKMP_NTYPE_INVALID_COOKIE 4
288#define ISAKMP_NTYPE_INVALID_MAJOR_VERSION 5
289#define ISAKMP_NTYPE_INVALID_MINOR_VERSION 6
290#define ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE 7
291#define ISAKMP_NTYPE_INVALID_FLAGS 8
292#define ISAKMP_NTYPE_INVALID_MESSAGE_ID 9
293#define ISAKMP_NTYPE_INVALID_PROTOCOL_ID 10
294#define ISAKMP_NTYPE_INVALID_SPI 11
295#define ISAKMP_NTYPE_INVALID_TRANSFORM_ID 12
296#define ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED 13
297#define ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN 14
298#define ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX 15
299#define ISAKMP_NTYPE_PAYLOAD_MALFORMED 16
300#define ISAKMP_NTYPE_INVALID_KEY_INFORMATION 17
301#define ISAKMP_NTYPE_INVALID_ID_INFORMATION 18
302#define ISAKMP_NTYPE_INVALID_CERT_ENCODING 19
303#define ISAKMP_NTYPE_INVALID_CERTIFICATE 20
304#define ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX 21
305#define ISAKMP_NTYPE_INVALID_CERT_AUTHORITY 22
306#define ISAKMP_NTYPE_INVALID_HASH_INFORMATION 23
307#define ISAKMP_NTYPE_AUTHENTICATION_FAILED 24
308#define ISAKMP_NTYPE_INVALID_SIGNATURE 25
309#define ISAKMP_NTYPE_ADDRESS_NOTIFICATION 26
310
311/* 3.15 Delete Payload */
312struct ikev1_pl_d {
313 struct isakmp_gen h;
314 uint32_t doi; /* Domain of Interpretation */
315 uint8_t prot_id; /* Protocol-Id */
316 uint8_t spi_size; /* SPI Size */
317 uint16_t num_spi; /* # of SPIs */
318 /* SPI(es) */
319};
320
321struct ikev1_ph1tab {
322 struct ikev1_ph1 *head;
323 struct ikev1_ph1 *tail;
324 int len;
325};
326
327struct isakmp_ph2tab {
328 struct ikev1_ph2 *head;
329 struct ikev1_ph2 *tail;
330 int len;
331};
332
333/* IKEv2 (RFC4306) */
334
335/* 3.3 Security Association Payload -- generic header */
336/* 3.3.1. Proposal Substructure */
337struct ikev2_p {
338 struct isakmp_gen h;
339 uint8_t p_no; /* Proposal # */
340 uint8_t prot_id; /* Protocol */
341 uint8_t spi_size; /* SPI Size */
342 uint8_t num_t; /* Number of Transforms */
343};
344
345/* 3.3.2. Transform Substructure */
346struct ikev2_t {
347 struct isakmp_gen h;
348 uint8_t t_type; /* Transform Type (ENCR,PRF,INTEG,etc.*/
349 uint8_t res2; /* reserved byte */
350 uint16_t t_id; /* Transform ID */
351};
352
353enum ikev2_t_type {
354 IV2_T_ENCR = 1,
355 IV2_T_PRF = 2,
356 IV2_T_INTEG= 3,
357 IV2_T_DH = 4,
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700358 IV2_T_ESN = 5
Elliott Hughes892a68b2015-10-19 14:43:53 -0700359};
360
361/* 3.4. Key Exchange Payload */
362struct ikev2_ke {
363 struct isakmp_gen h;
364 uint16_t ke_group;
365 uint16_t ke_res1;
366 /* KE data */
367};
368
369
370/* 3.5. Identification Payloads */
371enum ikev2_id_type {
372 ID_IPV4_ADDR=1,
373 ID_FQDN=2,
374 ID_RFC822_ADDR=3,
375 ID_IPV6_ADDR=5,
376 ID_DER_ASN1_DN=9,
377 ID_DER_ASN1_GN=10,
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700378 ID_KEY_ID=11
Elliott Hughes892a68b2015-10-19 14:43:53 -0700379};
380struct ikev2_id {
381 struct isakmp_gen h;
382 uint8_t type; /* ID type */
383 uint8_t res1;
384 uint16_t res2;
385 /* SPI */
386 /* Notification Data */
387};
388
389/* 3.10 Notification Payload */
390struct ikev2_n {
391 struct isakmp_gen h;
392 uint8_t prot_id; /* Protocol-ID */
393 uint8_t spi_size; /* SPI Size */
394 uint16_t type; /* Notify Message Type */
395};
396
397enum ikev2_n_type {
398 IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD = 1,
399 IV2_NOTIFY_INVALID_IKE_SPI = 4,
400 IV2_NOTIFY_INVALID_MAJOR_VERSION = 5,
401 IV2_NOTIFY_INVALID_SYNTAX = 7,
402 IV2_NOTIFY_INVALID_MESSAGE_ID = 9,
403 IV2_NOTIFY_INVALID_SPI =11,
404 IV2_NOTIFY_NO_PROPOSAL_CHOSEN =14,
405 IV2_NOTIFY_INVALID_KE_PAYLOAD =17,
406 IV2_NOTIFY_AUTHENTICATION_FAILED =24,
407 IV2_NOTIFY_SINGLE_PAIR_REQUIRED =34,
408 IV2_NOTIFY_NO_ADDITIONAL_SAS =35,
409 IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE =36,
410 IV2_NOTIFY_FAILED_CP_REQUIRED =37,
411 IV2_NOTIFY_INVALID_SELECTORS =39,
412 IV2_NOTIFY_INITIAL_CONTACT =16384,
413 IV2_NOTIFY_SET_WINDOW_SIZE =16385,
414 IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE =16386,
415 IV2_NOTIFY_IPCOMP_SUPPORTED =16387,
416 IV2_NOTIFY_NAT_DETECTION_SOURCE_IP =16388,
417 IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP =16389,
418 IV2_NOTIFY_COOKIE =16390,
419 IV2_NOTIFY_USE_TRANSPORT_MODE =16391,
420 IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED =16392,
421 IV2_NOTIFY_REKEY_SA =16393,
422 IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED =16394,
423 IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO =16395
424};
425
426struct notify_messages {
427 uint16_t type;
428 char *msg;
429};
430
Elliott Hughescec480a2017-12-19 16:54:57 -0800431/* 3.8 Authentication Payload */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700432struct ikev2_auth {
433 struct isakmp_gen h;
434 uint8_t auth_method; /* Protocol-ID */
435 uint8_t reserved[3];
436 /* authentication data */
437};
438
439enum ikev2_auth_type {
440 IV2_RSA_SIG = 1,
441 IV2_SHARED = 2,
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700442 IV2_DSS_SIG = 3
Elliott Hughes892a68b2015-10-19 14:43:53 -0700443};
444
445/* refer to RFC 2409 */
446
447#if 0
448/* isakmp sa structure */
449struct oakley_sa {
450 uint8_t proto_id; /* OAKLEY */
451 vchar_t *spi; /* spi */
452 uint8_t dhgrp; /* DH; group */
453 uint8_t auth_t; /* method of authentication */
454 uint8_t prf_t; /* type of prf */
455 uint8_t hash_t; /* type of hash */
456 uint8_t enc_t; /* type of cipher */
457 uint8_t life_t; /* type of duration of lifetime */
458 uint32_t ldur; /* life duration */
459};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800460#endif
461
Elliott Hughes892a68b2015-10-19 14:43:53 -0700462/* refer to RFC 2407 */
463
464#define IPSEC_DOI 1
465
466/* 4.2 IPSEC Situation Definition */
467#define IPSECDOI_SIT_IDENTITY_ONLY 0x00000001
468#define IPSECDOI_SIT_SECRECY 0x00000002
469#define IPSECDOI_SIT_INTEGRITY 0x00000004
470
471/* 4.4.1 IPSEC Security Protocol Identifiers */
472 /* 4.4.2 IPSEC ISAKMP Transform Values */
473#define IPSECDOI_PROTO_ISAKMP 1
474#define IPSECDOI_KEY_IKE 1
475
476/* 4.4.1 IPSEC Security Protocol Identifiers */
477#define IPSECDOI_PROTO_IPSEC_AH 2
478 /* 4.4.3 IPSEC AH Transform Values */
479#define IPSECDOI_AH_MD5 2
480#define IPSECDOI_AH_SHA 3
481#define IPSECDOI_AH_DES 4
482#define IPSECDOI_AH_SHA2_256 5
483#define IPSECDOI_AH_SHA2_384 6
484#define IPSECDOI_AH_SHA2_512 7
485
486/* 4.4.1 IPSEC Security Protocol Identifiers */
487#define IPSECDOI_PROTO_IPSEC_ESP 3
488 /* 4.4.4 IPSEC ESP Transform Identifiers */
489#define IPSECDOI_ESP_DES_IV64 1
490#define IPSECDOI_ESP_DES 2
491#define IPSECDOI_ESP_3DES 3
492#define IPSECDOI_ESP_RC5 4
493#define IPSECDOI_ESP_IDEA 5
494#define IPSECDOI_ESP_CAST 6
495#define IPSECDOI_ESP_BLOWFISH 7
496#define IPSECDOI_ESP_3IDEA 8
497#define IPSECDOI_ESP_DES_IV32 9
498#define IPSECDOI_ESP_RC4 10
499#define IPSECDOI_ESP_NULL 11
500#define IPSECDOI_ESP_RIJNDAEL 12
501#define IPSECDOI_ESP_AES 12
502
503/* 4.4.1 IPSEC Security Protocol Identifiers */
504#define IPSECDOI_PROTO_IPCOMP 4
505 /* 4.4.5 IPSEC IPCOMP Transform Identifiers */
506#define IPSECDOI_IPCOMP_OUI 1
507#define IPSECDOI_IPCOMP_DEFLATE 2
508#define IPSECDOI_IPCOMP_LZS 3
509
510/* 4.5 IPSEC Security Association Attributes */
511#define IPSECDOI_ATTR_SA_LTYPE 1 /* B */
512#define IPSECDOI_ATTR_SA_LTYPE_DEFAULT 1
513#define IPSECDOI_ATTR_SA_LTYPE_SEC 1
514#define IPSECDOI_ATTR_SA_LTYPE_KB 2
515#define IPSECDOI_ATTR_SA_LDUR 2 /* V */
516#define IPSECDOI_ATTR_SA_LDUR_DEFAULT 28800 /* 8 hours */
517#define IPSECDOI_ATTR_GRP_DESC 3 /* B */
518#define IPSECDOI_ATTR_ENC_MODE 4 /* B */
519 /* default value: host dependent */
520#define IPSECDOI_ATTR_ENC_MODE_TUNNEL 1
521#define IPSECDOI_ATTR_ENC_MODE_TRNS 2
522#define IPSECDOI_ATTR_AUTH 5 /* B */
523 /* 0 means not to use authentication. */
524#define IPSECDOI_ATTR_AUTH_HMAC_MD5 1
525#define IPSECDOI_ATTR_AUTH_HMAC_SHA1 2
526#define IPSECDOI_ATTR_AUTH_DES_MAC 3
527#define IPSECDOI_ATTR_AUTH_KPDK 4 /*RFC-1826(Key/Pad/Data/Key)*/
528 /*
529 * When negotiating ESP without authentication, the Auth
530 * Algorithm attribute MUST NOT be included in the proposal.
531 * When negotiating ESP without confidentiality, the Auth
532 * Algorithm attribute MUST be included in the proposal and
533 * the ESP transform ID must be ESP_NULL.
534 */
535#define IPSECDOI_ATTR_KEY_LENGTH 6 /* B */
536#define IPSECDOI_ATTR_KEY_ROUNDS 7 /* B */
537#define IPSECDOI_ATTR_COMP_DICT_SIZE 8 /* B */
538#define IPSECDOI_ATTR_COMP_PRIVALG 9 /* V */
539
540/* 4.6.1 Security Association Payload */
541struct ipsecdoi_sa {
542 struct isakmp_gen h;
543 uint32_t doi; /* Domain of Interpretation */
544 uint32_t sit; /* Situation */
545};
546
547struct ipsecdoi_secrecy_h {
548 uint16_t len;
549 uint16_t reserved;
550};
551
552/* 4.6.2.1 Identification Type Values */
553struct ipsecdoi_id {
554 struct isakmp_gen h;
555 uint8_t type; /* ID Type */
556 uint8_t proto_id; /* Protocol ID */
557 uint16_t port; /* Port */
558 /* Identification Data */
559};
560
561#define IPSECDOI_ID_IPV4_ADDR 1
562#define IPSECDOI_ID_FQDN 2
563#define IPSECDOI_ID_USER_FQDN 3
564#define IPSECDOI_ID_IPV4_ADDR_SUBNET 4
565#define IPSECDOI_ID_IPV6_ADDR 5
566#define IPSECDOI_ID_IPV6_ADDR_SUBNET 6
567#define IPSECDOI_ID_IPV4_ADDR_RANGE 7
568#define IPSECDOI_ID_IPV6_ADDR_RANGE 8
569#define IPSECDOI_ID_DER_ASN1_DN 9
570#define IPSECDOI_ID_DER_ASN1_GN 10
571#define IPSECDOI_ID_KEY_ID 11
572
573/* 4.6.3 IPSEC DOI Notify Message Types */
574/* Notify Messages - Status Types */
575#define IPSECDOI_NTYPE_RESPONDER_LIFETIME 24576
576#define IPSECDOI_NTYPE_REPLAY_STATUS 24577
577#define IPSECDOI_NTYPE_INITIAL_CONTACT 24578
578
JP Abgrall53f17a92014-02-12 14:02:41 -0800579#define DECLARE_PRINTER(func) static const u_char *ike##func##_print( \
580 netdissect_options *ndo, u_char tpay, \
581 const struct isakmp_gen *ext, \
582 u_int item_len, \
583 const u_char *end_pointer, \
Elliott Hughes892a68b2015-10-19 14:43:53 -0700584 uint32_t phase,\
585 uint32_t doi0, \
586 uint32_t proto0, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -0800587
588DECLARE_PRINTER(v1_sa);
589DECLARE_PRINTER(v1_p);
590DECLARE_PRINTER(v1_t);
591DECLARE_PRINTER(v1_ke);
592DECLARE_PRINTER(v1_id);
593DECLARE_PRINTER(v1_cert);
594DECLARE_PRINTER(v1_cr);
595DECLARE_PRINTER(v1_sig);
596DECLARE_PRINTER(v1_hash);
597DECLARE_PRINTER(v1_nonce);
598DECLARE_PRINTER(v1_n);
599DECLARE_PRINTER(v1_d);
600DECLARE_PRINTER(v1_vid);
601
602DECLARE_PRINTER(v2_sa);
603DECLARE_PRINTER(v2_ke);
604DECLARE_PRINTER(v2_ID);
605DECLARE_PRINTER(v2_cert);
606DECLARE_PRINTER(v2_cr);
607DECLARE_PRINTER(v2_auth);
608DECLARE_PRINTER(v2_nonce);
609DECLARE_PRINTER(v2_n);
610DECLARE_PRINTER(v2_d);
611DECLARE_PRINTER(v2_vid);
612DECLARE_PRINTER(v2_TS);
613DECLARE_PRINTER(v2_cp);
614DECLARE_PRINTER(v2_eap);
615
616static const u_char *ikev2_e_print(netdissect_options *ndo,
617 struct isakmp *base,
618 u_char tpay,
619 const struct isakmp_gen *ext,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700620 u_int item_len,
621 const u_char *end_pointer,
622 uint32_t phase,
623 uint32_t doi0,
624 uint32_t proto0, int depth);
JP Abgrall53f17a92014-02-12 14:02:41 -0800625
626
627static const u_char *ike_sub0_print(netdissect_options *ndo,u_char, const struct isakmp_gen *,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700628 const u_char *, uint32_t, uint32_t, uint32_t, int);
JP Abgrall53f17a92014-02-12 14:02:41 -0800629static const u_char *ikev1_sub_print(netdissect_options *ndo,u_char, const struct isakmp_gen *,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700630 const u_char *, uint32_t, uint32_t, uint32_t, int);
JP Abgrall53f17a92014-02-12 14:02:41 -0800631
632static const u_char *ikev2_sub_print(netdissect_options *ndo,
633 struct isakmp *base,
634 u_char np, const struct isakmp_gen *ext,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700635 const u_char *ep, uint32_t phase,
636 uint32_t doi, uint32_t proto,
JP Abgrall53f17a92014-02-12 14:02:41 -0800637 int depth);
638
639
The Android Open Source Project2949f582009-03-03 19:30:46 -0800640static char *numstr(int);
JP Abgrall53f17a92014-02-12 14:02:41 -0800641
642static void
643ikev1_print(netdissect_options *ndo,
644 const u_char *bp, u_int length,
645 const u_char *bp2, struct isakmp *base);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800646
647#define MAXINITIATORS 20
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700648static int ninitiator = 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700649union inaddr_u {
650 struct in_addr in4;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700651 struct in6_addr in6;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700652};
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700653static struct {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800654 cookie_t initiator;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700655 u_int version;
656 union inaddr_u iaddr;
657 union inaddr_u raddr;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800658} cookiecache[MAXINITIATORS];
659
660/* protocol id */
661static const char *protoidstr[] = {
662 NULL, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
663};
664
665/* isakmp->np */
666static const char *npstr[] = {
JP Abgrall53f17a92014-02-12 14:02:41 -0800667 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash", /* 0 - 8 */
668 "sig", "nonce", "n", "d", "vid", /* 9 - 13 */
669 "pay14", "pay15", "pay16", "pay17", "pay18", /* 14- 18 */
670 "pay19", "pay20", "pay21", "pay22", "pay23", /* 19- 23 */
671 "pay24", "pay25", "pay26", "pay27", "pay28", /* 24- 28 */
672 "pay29", "pay30", "pay31", "pay32", /* 29- 32 */
673 "v2sa", "v2ke", "v2IDi", "v2IDr", "v2cert",/* 33- 37 */
674 "v2cr", "v2auth","v2nonce", "v2n", "v2d", /* 38- 42 */
675 "v2vid", "v2TSi", "v2TSr", "v2e", "v2cp", /* 43- 47 */
676 "v2eap", /* 48 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700677
The Android Open Source Project2949f582009-03-03 19:30:46 -0800678};
679
680/* isakmp->np */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700681static const u_char *(*npfunc[])(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -0800682 const struct isakmp_gen *ext,
683 u_int item_len,
684 const u_char *end_pointer,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700685 uint32_t phase,
686 uint32_t doi0,
687 uint32_t proto0, int depth) = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800688 NULL,
JP Abgrall53f17a92014-02-12 14:02:41 -0800689 ikev1_sa_print,
690 ikev1_p_print,
691 ikev1_t_print,
692 ikev1_ke_print,
693 ikev1_id_print,
694 ikev1_cert_print,
695 ikev1_cr_print,
696 ikev1_hash_print,
697 ikev1_sig_print,
698 ikev1_nonce_print,
699 ikev1_n_print,
700 ikev1_d_print,
701 ikev1_vid_print, /* 13 */
702 NULL, NULL, NULL, NULL, NULL, /* 14- 18 */
703 NULL, NULL, NULL, NULL, NULL, /* 19- 23 */
704 NULL, NULL, NULL, NULL, NULL, /* 24- 28 */
705 NULL, NULL, NULL, NULL, /* 29- 32 */
706 ikev2_sa_print, /* 33 */
707 ikev2_ke_print, /* 34 */
708 ikev2_ID_print, /* 35 */
709 ikev2_ID_print, /* 36 */
710 ikev2_cert_print, /* 37 */
711 ikev2_cr_print, /* 38 */
712 ikev2_auth_print, /* 39 */
713 ikev2_nonce_print, /* 40 */
714 ikev2_n_print, /* 41 */
715 ikev2_d_print, /* 42 */
716 ikev2_vid_print, /* 43 */
717 ikev2_TS_print, /* 44 */
718 ikev2_TS_print, /* 45 */
719 NULL, /* ikev2_e_print,*/ /* 46 - special */
720 ikev2_cp_print, /* 47 */
721 ikev2_eap_print, /* 48 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800722};
723
724/* isakmp->etype */
725static const char *etypestr[] = {
JP Abgrall53f17a92014-02-12 14:02:41 -0800726/* IKEv1 exchange types */
727 "none", "base", "ident", "auth", "agg", "inf", NULL, NULL, /* 0-7 */
728 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 8-15 */
729 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 16-23 */
730 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 24-31 */
731 "oakley-quick", "oakley-newgroup", /* 32-33 */
732/* IKEv2 exchange types */
733 "ikev2_init", "ikev2_auth", "child_sa", "inf2" /* 34-37 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800734};
735
736#define STR_OR_ID(x, tab) \
737 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
738#define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
739#define NPSTR(x) STR_OR_ID(x, npstr)
740#define ETYPESTR(x) STR_OR_ID(x, etypestr)
741
JP Abgrall53f17a92014-02-12 14:02:41 -0800742#define CHECKLEN(p, np) \
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700743 if (ep < (const u_char *)(p)) { \
JP Abgrall53f17a92014-02-12 14:02:41 -0800744 ND_PRINT((ndo," [|%s]", NPSTR(np))); \
745 goto done; \
746 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700747
JP Abgrall53f17a92014-02-12 14:02:41 -0800748
The Android Open Source Project2949f582009-03-03 19:30:46 -0800749#define NPFUNC(x) \
750 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
751 ? npfunc[(x)] : NULL)
752
753static int
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700754iszero(const u_char *p, size_t l)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800755{
756 while (l--) {
757 if (*p++)
758 return 0;
759 }
760 return 1;
761}
762
763/* find cookie from initiator cache */
764static int
765cookie_find(cookie_t *in)
766{
767 int i;
768
769 for (i = 0; i < MAXINITIATORS; i++) {
770 if (memcmp(in, &cookiecache[i].initiator, sizeof(*in)) == 0)
771 return i;
772 }
773
774 return -1;
775}
776
777/* record initiator */
778static void
779cookie_record(cookie_t *in, const u_char *bp2)
780{
781 int i;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700782 const struct ip *ip;
783 const struct ip6_hdr *ip6;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800784
785 i = cookie_find(in);
786 if (0 <= i) {
787 ninitiator = (i + 1) % MAXINITIATORS;
788 return;
789 }
790
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700791 ip = (const struct ip *)bp2;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800792 switch (IP_V(ip)) {
793 case 4:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700794 cookiecache[ninitiator].version = 4;
795 UNALIGNED_MEMCPY(&cookiecache[ninitiator].iaddr.in4, &ip->ip_src, sizeof(struct in_addr));
796 UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in4, &ip->ip_dst, sizeof(struct in_addr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800797 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800798 case 6:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700799 ip6 = (const struct ip6_hdr *)bp2;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700800 cookiecache[ninitiator].version = 6;
801 UNALIGNED_MEMCPY(&cookiecache[ninitiator].iaddr.in6, &ip6->ip6_src, sizeof(struct in6_addr));
802 UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in6, &ip6->ip6_dst, sizeof(struct in6_addr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800803 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800804 default:
805 return;
806 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800807 UNALIGNED_MEMCPY(&cookiecache[ninitiator].initiator, in, sizeof(*in));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800808 ninitiator = (ninitiator + 1) % MAXINITIATORS;
809}
810
811#define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1)
812#define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0)
813static int
814cookie_sidecheck(int i, const u_char *bp2, int initiator)
815{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700816 const struct ip *ip;
817 const struct ip6_hdr *ip6;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800818
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700819 ip = (const struct ip *)bp2;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800820 switch (IP_V(ip)) {
821 case 4:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700822 if (cookiecache[i].version != 4)
823 return 0;
824 if (initiator) {
825 if (UNALIGNED_MEMCMP(&ip->ip_src, &cookiecache[i].iaddr.in4, sizeof(struct in_addr)) == 0)
826 return 1;
827 } else {
828 if (UNALIGNED_MEMCMP(&ip->ip_src, &cookiecache[i].raddr.in4, sizeof(struct in_addr)) == 0)
829 return 1;
830 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800831 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800832 case 6:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700833 if (cookiecache[i].version != 6)
834 return 0;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700835 ip6 = (const struct ip6_hdr *)bp2;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700836 if (initiator) {
837 if (UNALIGNED_MEMCMP(&ip6->ip6_src, &cookiecache[i].iaddr.in6, sizeof(struct in6_addr)) == 0)
838 return 1;
839 } else {
840 if (UNALIGNED_MEMCMP(&ip6->ip6_src, &cookiecache[i].raddr.in6, sizeof(struct in6_addr)) == 0)
841 return 1;
842 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800843 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800844 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700845 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800846 }
847
The Android Open Source Project2949f582009-03-03 19:30:46 -0800848 return 0;
849}
850
JP Abgrall53f17a92014-02-12 14:02:41 -0800851static void
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700852hexprint(netdissect_options *ndo, const uint8_t *loc, size_t len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800853{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700854 const uint8_t *p;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800855 size_t i;
856
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700857 p = loc;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800858 for (i = 0; i < len; i++)
JP Abgrall53f17a92014-02-12 14:02:41 -0800859 ND_PRINT((ndo,"%02x", p[i] & 0xff));
860}
861
862static int
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700863rawprint(netdissect_options *ndo, const uint8_t *loc, size_t len)
JP Abgrall53f17a92014-02-12 14:02:41 -0800864{
865 ND_TCHECK2(*loc, len);
866
867 hexprint(ndo, loc, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800868 return 1;
869trunc:
870 return 0;
871}
872
JP Abgrall53f17a92014-02-12 14:02:41 -0800873
874/*
875 * returns false if we run out of data buffer
876 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700877static int ike_show_somedata(netdissect_options *ndo,
JP Abgrall53f17a92014-02-12 14:02:41 -0800878 const u_char *cp, const u_char *ep)
879{
880 /* there is too much data, just show some of it */
881 const u_char *end = ep - 20;
882 int elen = 20;
883 int len = ep - cp;
884 if(len > 10) {
885 len = 10;
886 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700887
JP Abgrall53f17a92014-02-12 14:02:41 -0800888 /* really shouldn't happen because of above */
889 if(end < cp + len) {
890 end = cp+len;
891 elen = ep - end;
892 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700893
JP Abgrall53f17a92014-02-12 14:02:41 -0800894 ND_PRINT((ndo," data=("));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700895 if(!rawprint(ndo, (const uint8_t *)(cp), len)) goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -0800896 ND_PRINT((ndo, "..."));
897 if(elen) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700898 if(!rawprint(ndo, (const uint8_t *)(end), elen)) goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -0800899 }
900 ND_PRINT((ndo,")"));
901 return 1;
902
903trunc:
904 return 0;
905}
906
The Android Open Source Project2949f582009-03-03 19:30:46 -0800907struct attrmap {
908 const char *type;
909 u_int nvalue;
910 const char *value[30]; /*XXX*/
911};
912
913static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -0800914ikev1_attrmap_print(netdissect_options *ndo,
Elliott Hughescec480a2017-12-19 16:54:57 -0800915 const u_char *p, const u_char *ep2,
JP Abgrall53f17a92014-02-12 14:02:41 -0800916 const struct attrmap *map, size_t nmap)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800917{
The Android Open Source Project2949f582009-03-03 19:30:46 -0800918 int totlen;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700919 uint32_t t, v;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800920
Elliott Hughescec480a2017-12-19 16:54:57 -0800921 ND_TCHECK(p[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800922 if (p[0] & 0x80)
923 totlen = 4;
Elliott Hughescec480a2017-12-19 16:54:57 -0800924 else {
925 ND_TCHECK_16BITS(&p[2]);
JP Abgrall53f17a92014-02-12 14:02:41 -0800926 totlen = 4 + EXTRACT_16BITS(&p[2]);
Elliott Hughescec480a2017-12-19 16:54:57 -0800927 }
928 if (ep2 < p + totlen) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800929 ND_PRINT((ndo,"[|attr]"));
Elliott Hughescec480a2017-12-19 16:54:57 -0800930 return ep2 + 1;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800931 }
932
Elliott Hughescec480a2017-12-19 16:54:57 -0800933 ND_TCHECK_16BITS(&p[0]);
JP Abgrall53f17a92014-02-12 14:02:41 -0800934 ND_PRINT((ndo,"("));
935 t = EXTRACT_16BITS(&p[0]) & 0x7fff;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800936 if (map && t < nmap && map[t].type)
JP Abgrall53f17a92014-02-12 14:02:41 -0800937 ND_PRINT((ndo,"type=%s ", map[t].type));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800938 else
JP Abgrall53f17a92014-02-12 14:02:41 -0800939 ND_PRINT((ndo,"type=#%d ", t));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800940 if (p[0] & 0x80) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800941 ND_PRINT((ndo,"value="));
Elliott Hughescec480a2017-12-19 16:54:57 -0800942 ND_TCHECK_16BITS(&p[2]);
JP Abgrall53f17a92014-02-12 14:02:41 -0800943 v = EXTRACT_16BITS(&p[2]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800944 if (map && t < nmap && v < map[t].nvalue && map[t].value[v])
JP Abgrall53f17a92014-02-12 14:02:41 -0800945 ND_PRINT((ndo,"%s", map[t].value[v]));
Elliott Hughescec480a2017-12-19 16:54:57 -0800946 else {
947 if (!rawprint(ndo, (const uint8_t *)&p[2], 2)) {
948 ND_PRINT((ndo,")"));
949 goto trunc;
950 }
951 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800952 } else {
Elliott Hughescec480a2017-12-19 16:54:57 -0800953 ND_PRINT((ndo,"len=%d value=", totlen - 4));
954 if (!rawprint(ndo, (const uint8_t *)&p[4], totlen - 4)) {
955 ND_PRINT((ndo,")"));
956 goto trunc;
957 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800958 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800959 ND_PRINT((ndo,")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800960 return p + totlen;
Elliott Hughescec480a2017-12-19 16:54:57 -0800961
962trunc:
963 return NULL;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800964}
965
966static const u_char *
Elliott Hughescec480a2017-12-19 16:54:57 -0800967ikev1_attr_print(netdissect_options *ndo, const u_char *p, const u_char *ep2)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800968{
The Android Open Source Project2949f582009-03-03 19:30:46 -0800969 int totlen;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700970 uint32_t t;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800971
Elliott Hughescec480a2017-12-19 16:54:57 -0800972 ND_TCHECK(p[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800973 if (p[0] & 0x80)
974 totlen = 4;
Elliott Hughescec480a2017-12-19 16:54:57 -0800975 else {
976 ND_TCHECK_16BITS(&p[2]);
JP Abgrall53f17a92014-02-12 14:02:41 -0800977 totlen = 4 + EXTRACT_16BITS(&p[2]);
Elliott Hughescec480a2017-12-19 16:54:57 -0800978 }
979 if (ep2 < p + totlen) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800980 ND_PRINT((ndo,"[|attr]"));
Elliott Hughescec480a2017-12-19 16:54:57 -0800981 return ep2 + 1;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800982 }
983
Elliott Hughescec480a2017-12-19 16:54:57 -0800984 ND_TCHECK_16BITS(&p[0]);
JP Abgrall53f17a92014-02-12 14:02:41 -0800985 ND_PRINT((ndo,"("));
986 t = EXTRACT_16BITS(&p[0]) & 0x7fff;
987 ND_PRINT((ndo,"type=#%d ", t));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800988 if (p[0] & 0x80) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800989 ND_PRINT((ndo,"value="));
990 t = p[2];
Elliott Hughescec480a2017-12-19 16:54:57 -0800991 if (!rawprint(ndo, (const uint8_t *)&p[2], 2)) {
992 ND_PRINT((ndo,")"));
993 goto trunc;
994 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800995 } else {
Elliott Hughescec480a2017-12-19 16:54:57 -0800996 ND_PRINT((ndo,"len=%d value=", totlen - 4));
997 if (!rawprint(ndo, (const uint8_t *)&p[4], totlen - 4)) {
998 ND_PRINT((ndo,")"));
999 goto trunc;
1000 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001001 }
JP Abgrall53f17a92014-02-12 14:02:41 -08001002 ND_PRINT((ndo,")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001003 return p + totlen;
Elliott Hughescec480a2017-12-19 16:54:57 -08001004
1005trunc:
1006 return NULL;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001007}
1008
1009static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001010ikev1_sa_print(netdissect_options *ndo, u_char tpay _U_,
1011 const struct isakmp_gen *ext,
The Android Open Source Project2949f582009-03-03 19:30:46 -08001012 u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001013 const u_char *ep, uint32_t phase, uint32_t doi0 _U_,
1014 uint32_t proto0, int depth)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001015{
JP Abgrall53f17a92014-02-12 14:02:41 -08001016 const struct ikev1_pl_sa *p;
1017 struct ikev1_pl_sa sa;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001018 uint32_t doi, sit, ident;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001019 const u_char *cp, *np;
1020 int t;
1021
JP Abgrall53f17a92014-02-12 14:02:41 -08001022 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_SA)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001023
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001024 p = (const struct ikev1_pl_sa *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001025 ND_TCHECK(*p);
1026 UNALIGNED_MEMCPY(&sa, ext, sizeof(sa));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001027 doi = ntohl(sa.doi);
1028 sit = ntohl(sa.sit);
1029 if (doi != 1) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001030 ND_PRINT((ndo," doi=%d", doi));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001031 ND_PRINT((ndo," situation=%u", (uint32_t)ntohl(sa.sit)));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001032 return (const u_char *)(p + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001033 }
1034
JP Abgrall53f17a92014-02-12 14:02:41 -08001035 ND_PRINT((ndo," doi=ipsec"));
1036 ND_PRINT((ndo," situation="));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001037 t = 0;
1038 if (sit & 0x01) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001039 ND_PRINT((ndo,"identity"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001040 t++;
1041 }
1042 if (sit & 0x02) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001043 ND_PRINT((ndo,"%ssecrecy", t ? "+" : ""));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001044 t++;
1045 }
1046 if (sit & 0x04)
JP Abgrall53f17a92014-02-12 14:02:41 -08001047 ND_PRINT((ndo,"%sintegrity", t ? "+" : ""));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001048
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001049 np = (const u_char *)ext + sizeof(sa);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001050 if (sit != 0x01) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001051 ND_TCHECK2(*(ext + 1), sizeof(ident));
1052 UNALIGNED_MEMCPY(&ident, ext + 1, sizeof(ident));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001053 ND_PRINT((ndo," ident=%u", (uint32_t)ntohl(ident)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001054 np += sizeof(ident);
1055 }
1056
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001057 ext = (const struct isakmp_gen *)np;
JP Abgrall53f17a92014-02-12 14:02:41 -08001058 ND_TCHECK(*ext);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001059
JP Abgrall53f17a92014-02-12 14:02:41 -08001060 cp = ikev1_sub_print(ndo, ISAKMP_NPTYPE_P, ext, ep, phase, doi, proto0,
The Android Open Source Project2949f582009-03-03 19:30:46 -08001061 depth);
1062
1063 return cp;
1064trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001065 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_SA)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001066 return NULL;
1067}
1068
1069static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001070ikev1_p_print(netdissect_options *ndo, u_char tpay _U_,
1071 const struct isakmp_gen *ext, u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001072 const u_char *ep, uint32_t phase, uint32_t doi0,
1073 uint32_t proto0 _U_, int depth)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001074{
JP Abgrall53f17a92014-02-12 14:02:41 -08001075 const struct ikev1_pl_p *p;
1076 struct ikev1_pl_p prop;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001077 const u_char *cp;
1078
JP Abgrall53f17a92014-02-12 14:02:41 -08001079 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_P)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001080
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001081 p = (const struct ikev1_pl_p *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001082 ND_TCHECK(*p);
1083 UNALIGNED_MEMCPY(&prop, ext, sizeof(prop));
1084 ND_PRINT((ndo," #%d protoid=%s transform=%d",
1085 prop.p_no, PROTOIDSTR(prop.prot_id), prop.num_t));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001086 if (prop.spi_size) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001087 ND_PRINT((ndo," spi="));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001088 if (!rawprint(ndo, (const uint8_t *)(p + 1), prop.spi_size))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001089 goto trunc;
1090 }
1091
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001092 ext = (const struct isakmp_gen *)((const u_char *)(p + 1) + prop.spi_size);
JP Abgrall53f17a92014-02-12 14:02:41 -08001093 ND_TCHECK(*ext);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001094
JP Abgrall53f17a92014-02-12 14:02:41 -08001095 cp = ikev1_sub_print(ndo, ISAKMP_NPTYPE_T, ext, ep, phase, doi0,
1096 prop.prot_id, depth);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001097
The Android Open Source Project2949f582009-03-03 19:30:46 -08001098 return cp;
1099trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001100 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_P)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001101 return NULL;
1102}
1103
JP Abgrall53f17a92014-02-12 14:02:41 -08001104static const char *ikev1_p_map[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001105 NULL, "ike",
1106};
1107
JP Abgrall53f17a92014-02-12 14:02:41 -08001108static const char *ikev2_t_type_map[]={
1109 NULL, "encr", "prf", "integ", "dh", "esn"
1110};
1111
The Android Open Source Project2949f582009-03-03 19:30:46 -08001112static const char *ah_p_map[] = {
1113 NULL, "(reserved)", "md5", "sha", "1des",
1114 "sha2-256", "sha2-384", "sha2-512",
1115};
1116
JP Abgrall53f17a92014-02-12 14:02:41 -08001117static const char *prf_p_map[] = {
1118 NULL, "hmac-md5", "hmac-sha", "hmac-tiger",
1119 "aes128_xcbc"
1120};
1121
1122static const char *integ_p_map[] = {
1123 NULL, "hmac-md5", "hmac-sha", "dec-mac",
1124 "kpdk-md5", "aes-xcbc"
1125};
1126
1127static const char *esn_p_map[] = {
1128 "no-esn", "esn"
1129};
1130
1131static const char *dh_p_map[] = {
1132 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};
1147
The Android Open Source Project2949f582009-03-03 19:30:46 -08001148static const char *esp_p_map[] = {
1149 NULL, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
1150 "blowfish", "3idea", "1des-iv32", "rc4", "null", "aes"
1151};
1152
1153static const char *ipcomp_p_map[] = {
1154 NULL, "oui", "deflate", "lzs",
1155};
1156
Elliott Hughes892a68b2015-10-19 14:43:53 -07001157static const struct attrmap ipsec_t_map[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001158 { NULL, 0, { NULL } },
1159 { "lifetype", 3, { NULL, "sec", "kb", }, },
1160 { "life", 0, { NULL } },
JP Abgrall53f17a92014-02-12 14:02:41 -08001161 { "group desc", 18, { NULL, "modp768",
1162 "modp1024", /* group 2 */
1163 "EC2N 2^155", /* group 3 */
1164 "EC2N 2^185", /* group 4 */
1165 "modp1536", /* group 5 */
1166 "iana-grp06", "iana-grp07", /* reserved */
1167 "iana-grp08", "iana-grp09",
1168 "iana-grp10", "iana-grp11",
1169 "iana-grp12", "iana-grp13",
1170 "modp2048", /* group 14 */
1171 "modp3072", /* group 15 */
1172 "modp4096", /* group 16 */
1173 "modp6144", /* group 17 */
1174 "modp8192", /* group 18 */
1175 }, },
The Android Open Source Project2949f582009-03-03 19:30:46 -08001176 { "enc mode", 3, { NULL, "tunnel", "transport", }, },
1177 { "auth", 5, { NULL, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
1178 { "keylen", 0, { NULL } },
1179 { "rounds", 0, { NULL } },
1180 { "dictsize", 0, { NULL } },
1181 { "privalg", 0, { NULL } },
1182};
1183
Elliott Hughes892a68b2015-10-19 14:43:53 -07001184static const struct attrmap encr_t_map[] = {
JP Abgrall53f17a92014-02-12 14:02:41 -08001185 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 0, 1 */
1186 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 2, 3 */
1187 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 4, 5 */
1188 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 6, 7 */
1189 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 8, 9 */
1190 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 10,11*/
1191 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 12,13*/
1192 { "keylen", 14, { NULL }},
1193};
1194
Elliott Hughes892a68b2015-10-19 14:43:53 -07001195static const struct attrmap oakley_t_map[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001196 { NULL, 0, { NULL } },
1197 { "enc", 8, { NULL, "1des", "idea", "blowfish", "rc5",
1198 "3des", "cast", "aes", }, },
1199 { "hash", 7, { NULL, "md5", "sha1", "tiger",
1200 "sha2-256", "sha2-384", "sha2-512", }, },
1201 { "auth", 6, { NULL, "preshared", "dss", "rsa sig", "rsa enc",
1202 "rsa enc revised", }, },
JP Abgrall53f17a92014-02-12 14:02:41 -08001203 { "group desc", 18, { NULL, "modp768",
1204 "modp1024", /* group 2 */
1205 "EC2N 2^155", /* group 3 */
1206 "EC2N 2^185", /* group 4 */
1207 "modp1536", /* group 5 */
1208 "iana-grp06", "iana-grp07", /* reserved */
1209 "iana-grp08", "iana-grp09",
1210 "iana-grp10", "iana-grp11",
1211 "iana-grp12", "iana-grp13",
1212 "modp2048", /* group 14 */
1213 "modp3072", /* group 15 */
1214 "modp4096", /* group 16 */
1215 "modp6144", /* group 17 */
1216 "modp8192", /* group 18 */
1217 }, },
The Android Open Source Project2949f582009-03-03 19:30:46 -08001218 { "group type", 4, { NULL, "MODP", "ECP", "EC2N", }, },
1219 { "group prime", 0, { NULL } },
1220 { "group gen1", 0, { NULL } },
1221 { "group gen2", 0, { NULL } },
1222 { "group curve A", 0, { NULL } },
1223 { "group curve B", 0, { NULL } },
1224 { "lifetype", 3, { NULL, "sec", "kb", }, },
1225 { "lifeduration", 0, { NULL } },
1226 { "prf", 0, { NULL } },
1227 { "keylen", 0, { NULL } },
1228 { "field", 0, { NULL } },
1229 { "order", 0, { NULL } },
1230};
1231
1232static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001233ikev1_t_print(netdissect_options *ndo, u_char tpay _U_,
1234 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001235 const u_char *ep, uint32_t phase _U_, uint32_t doi _U_,
1236 uint32_t proto, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001237{
JP Abgrall53f17a92014-02-12 14:02:41 -08001238 const struct ikev1_pl_t *p;
1239 struct ikev1_pl_t t;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001240 const u_char *cp;
1241 const char *idstr;
1242 const struct attrmap *map;
1243 size_t nmap;
1244 const u_char *ep2;
1245
JP Abgrall53f17a92014-02-12 14:02:41 -08001246 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_T)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001247
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001248 p = (const struct ikev1_pl_t *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001249 ND_TCHECK(*p);
1250 UNALIGNED_MEMCPY(&t, ext, sizeof(t));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001251
1252 switch (proto) {
1253 case 1:
JP Abgrall53f17a92014-02-12 14:02:41 -08001254 idstr = STR_OR_ID(t.t_id, ikev1_p_map);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001255 map = oakley_t_map;
1256 nmap = sizeof(oakley_t_map)/sizeof(oakley_t_map[0]);
1257 break;
1258 case 2:
1259 idstr = STR_OR_ID(t.t_id, ah_p_map);
1260 map = ipsec_t_map;
1261 nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
1262 break;
1263 case 3:
1264 idstr = STR_OR_ID(t.t_id, esp_p_map);
1265 map = ipsec_t_map;
1266 nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
1267 break;
1268 case 4:
1269 idstr = STR_OR_ID(t.t_id, ipcomp_p_map);
1270 map = ipsec_t_map;
1271 nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
1272 break;
1273 default:
1274 idstr = NULL;
1275 map = NULL;
1276 nmap = 0;
1277 break;
1278 }
1279
1280 if (idstr)
JP Abgrall53f17a92014-02-12 14:02:41 -08001281 ND_PRINT((ndo," #%d id=%s ", t.t_no, idstr));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001282 else
JP Abgrall53f17a92014-02-12 14:02:41 -08001283 ND_PRINT((ndo," #%d id=%d ", t.t_no, t.t_id));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001284 cp = (const u_char *)(p + 1);
1285 ep2 = (const u_char *)p + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001286 while (cp < ep && cp < ep2) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001287 if (map && nmap)
1288 cp = ikev1_attrmap_print(ndo, cp, ep2, map, nmap);
1289 else
1290 cp = ikev1_attr_print(ndo, cp, ep2);
1291 if (cp == NULL)
1292 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001293 }
1294 if (ep < ep2)
JP Abgrall53f17a92014-02-12 14:02:41 -08001295 ND_PRINT((ndo,"..."));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001296 return cp;
1297trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001298 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_T)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001299 return NULL;
1300}
1301
1302static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001303ikev1_ke_print(netdissect_options *ndo, u_char tpay _U_,
1304 const struct isakmp_gen *ext, u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001305 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi _U_,
1306 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001307{
1308 struct isakmp_gen e;
1309
JP Abgrall53f17a92014-02-12 14:02:41 -08001310 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_KE)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001311
JP Abgrall53f17a92014-02-12 14:02:41 -08001312 ND_TCHECK(*ext);
1313 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
1314 ND_PRINT((ndo," key len=%d", ntohs(e.len) - 4));
1315 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001316 /* Print the entire payload in hex */
JP Abgrall53f17a92014-02-12 14:02:41 -08001317 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001318 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001319 goto trunc;
1320 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001321 return (const u_char *)ext + ntohs(e.len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001322trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001323 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_KE)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001324 return NULL;
1325}
1326
1327static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001328ikev1_id_print(netdissect_options *ndo, u_char tpay _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001329 const struct isakmp_gen *ext, u_int item_len,
1330 const u_char *ep _U_, uint32_t phase, uint32_t doi _U_,
1331 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001332{
1333#define USE_IPSECDOI_IN_PHASE1 1
JP Abgrall53f17a92014-02-12 14:02:41 -08001334 const struct ikev1_pl_id *p;
1335 struct ikev1_pl_id id;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001336 static const char *idtypestr[] = {
1337 "IPv4", "IPv4net", "IPv6", "IPv6net",
1338 };
1339 static const char *ipsecidtypestr[] = {
1340 NULL, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
1341 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
1342 "keyid",
1343 };
1344 int len;
1345 const u_char *data;
1346
JP Abgrall53f17a92014-02-12 14:02:41 -08001347 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_ID)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001348
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001349 p = (const struct ikev1_pl_id *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001350 ND_TCHECK(*p);
1351 UNALIGNED_MEMCPY(&id, ext, sizeof(id));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001352 if (sizeof(*p) < item_len) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001353 data = (const u_char *)(p + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001354 len = item_len - sizeof(*p);
1355 } else {
1356 data = NULL;
1357 len = 0;
1358 }
1359
1360#if 0 /*debug*/
JP Abgrall53f17a92014-02-12 14:02:41 -08001361 ND_PRINT((ndo," [phase=%d doi=%d proto=%d]", phase, doi, proto));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001362#endif
1363 switch (phase) {
1364#ifndef USE_IPSECDOI_IN_PHASE1
1365 case 1:
1366#endif
1367 default:
JP Abgrall53f17a92014-02-12 14:02:41 -08001368 ND_PRINT((ndo," idtype=%s", STR_OR_ID(id.d.id_type, idtypestr)));
1369 ND_PRINT((ndo," doi_data=%u",
Elliott Hughes892a68b2015-10-19 14:43:53 -07001370 (uint32_t)(ntohl(id.d.doi_data) & 0xffffff)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001371 break;
1372
1373#ifdef USE_IPSECDOI_IN_PHASE1
1374 case 1:
1375#endif
1376 case 2:
1377 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001378 const struct ipsecdoi_id *doi_p;
1379 struct ipsecdoi_id doi_id;
Elliott Hughescec480a2017-12-19 16:54:57 -08001380 const char *p_name;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001381
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001382 doi_p = (const struct ipsecdoi_id *)ext;
1383 ND_TCHECK(*doi_p);
1384 UNALIGNED_MEMCPY(&doi_id, ext, sizeof(doi_id));
1385 ND_PRINT((ndo," idtype=%s", STR_OR_ID(doi_id.type, ipsecidtypestr)));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001386 /* A protocol ID of 0 DOES NOT mean IPPROTO_IP! */
Elliott Hughescec480a2017-12-19 16:54:57 -08001387 if (!ndo->ndo_nflag && doi_id.proto_id && (p_name = netdb_protoname(doi_id.proto_id)) != NULL)
1388 ND_PRINT((ndo," protoid=%s", p_name));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001389 else
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001390 ND_PRINT((ndo," protoid=%u", doi_id.proto_id));
1391 ND_PRINT((ndo," port=%d", ntohs(doi_id.port)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001392 if (!len)
1393 break;
1394 if (data == NULL)
1395 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08001396 ND_TCHECK2(*data, len);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001397 switch (doi_id.type) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001398 case IPSECDOI_ID_IPV4_ADDR:
1399 if (len < 4)
JP Abgrall53f17a92014-02-12 14:02:41 -08001400 ND_PRINT((ndo," len=%d [bad: < 4]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001401 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001402 ND_PRINT((ndo," len=%d %s", len, ipaddr_string(ndo, data)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001403 len = 0;
1404 break;
1405 case IPSECDOI_ID_FQDN:
1406 case IPSECDOI_ID_USER_FQDN:
1407 {
1408 int i;
JP Abgrall53f17a92014-02-12 14:02:41 -08001409 ND_PRINT((ndo," len=%d ", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001410 for (i = 0; i < len; i++)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001411 safeputchar(ndo, data[i]);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001412 len = 0;
1413 break;
1414 }
1415 case IPSECDOI_ID_IPV4_ADDR_SUBNET:
1416 {
1417 const u_char *mask;
1418 if (len < 8)
JP Abgrall53f17a92014-02-12 14:02:41 -08001419 ND_PRINT((ndo," len=%d [bad: < 8]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001420 else {
1421 mask = data + sizeof(struct in_addr);
JP Abgrall53f17a92014-02-12 14:02:41 -08001422 ND_PRINT((ndo," len=%d %s/%u.%u.%u.%u", len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001423 ipaddr_string(ndo, data),
JP Abgrall53f17a92014-02-12 14:02:41 -08001424 mask[0], mask[1], mask[2], mask[3]));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001425 }
1426 len = 0;
1427 break;
1428 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001429 case IPSECDOI_ID_IPV6_ADDR:
1430 if (len < 16)
JP Abgrall53f17a92014-02-12 14:02:41 -08001431 ND_PRINT((ndo," len=%d [bad: < 16]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001432 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001433 ND_PRINT((ndo," len=%d %s", len, ip6addr_string(ndo, data)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001434 len = 0;
1435 break;
1436 case IPSECDOI_ID_IPV6_ADDR_SUBNET:
1437 {
JP Abgrall53f17a92014-02-12 14:02:41 -08001438 const u_char *mask;
Elliott Hughescec480a2017-12-19 16:54:57 -08001439 if (len < 32)
1440 ND_PRINT((ndo," len=%d [bad: < 32]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001441 else {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001442 mask = (const u_char *)(data + sizeof(struct in6_addr));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001443 /*XXX*/
JP Abgrall53f17a92014-02-12 14:02:41 -08001444 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 -07001445 ip6addr_string(ndo, data),
JP Abgrall53f17a92014-02-12 14:02:41 -08001446 mask[0], mask[1], mask[2], mask[3],
1447 mask[4], mask[5], mask[6], mask[7],
1448 mask[8], mask[9], mask[10], mask[11],
1449 mask[12], mask[13], mask[14], mask[15]));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001450 }
1451 len = 0;
1452 break;
1453 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001454 case IPSECDOI_ID_IPV4_ADDR_RANGE:
1455 if (len < 8)
JP Abgrall53f17a92014-02-12 14:02:41 -08001456 ND_PRINT((ndo," len=%d [bad: < 8]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001457 else {
JP Abgrall53f17a92014-02-12 14:02:41 -08001458 ND_PRINT((ndo," len=%d %s-%s", len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001459 ipaddr_string(ndo, data),
1460 ipaddr_string(ndo, data + sizeof(struct in_addr))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001461 }
1462 len = 0;
1463 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001464 case IPSECDOI_ID_IPV6_ADDR_RANGE:
1465 if (len < 32)
JP Abgrall53f17a92014-02-12 14:02:41 -08001466 ND_PRINT((ndo," len=%d [bad: < 32]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001467 else {
JP Abgrall53f17a92014-02-12 14:02:41 -08001468 ND_PRINT((ndo," len=%d %s-%s", len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001469 ip6addr_string(ndo, data),
1470 ip6addr_string(ndo, data + sizeof(struct in6_addr))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001471 }
1472 len = 0;
1473 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001474 case IPSECDOI_ID_DER_ASN1_DN:
1475 case IPSECDOI_ID_DER_ASN1_GN:
1476 case IPSECDOI_ID_KEY_ID:
1477 break;
1478 }
1479 break;
1480 }
1481 }
1482 if (data && len) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001483 ND_PRINT((ndo," len=%d", len));
1484 if (2 < ndo->ndo_vflag) {
1485 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001486 if (!rawprint(ndo, (const uint8_t *)data, len))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001487 goto trunc;
1488 }
1489 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001490 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001491trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001492 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_ID)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001493 return NULL;
1494}
1495
1496static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001497ikev1_cert_print(netdissect_options *ndo, u_char tpay _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001498 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001499 const u_char *ep _U_, uint32_t phase _U_,
1500 uint32_t doi0 _U_,
1501 uint32_t proto0 _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001502{
JP Abgrall53f17a92014-02-12 14:02:41 -08001503 const struct ikev1_pl_cert *p;
1504 struct ikev1_pl_cert cert;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001505 static const char *certstr[] = {
1506 "none", "pkcs7", "pgp", "dns",
1507 "x509sign", "x509ke", "kerberos", "crl",
1508 "arl", "spki", "x509attr",
1509 };
1510
JP Abgrall53f17a92014-02-12 14:02:41 -08001511 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_CERT)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001512
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001513 p = (const struct ikev1_pl_cert *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001514 ND_TCHECK(*p);
1515 UNALIGNED_MEMCPY(&cert, ext, sizeof(cert));
1516 ND_PRINT((ndo," len=%d", item_len - 4));
1517 ND_PRINT((ndo," type=%s", STR_OR_ID((cert.encode), certstr)));
1518 if (2 < ndo->ndo_vflag && 4 < item_len) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001519 /* Print the entire payload in hex */
JP Abgrall53f17a92014-02-12 14:02:41 -08001520 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001521 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001522 goto trunc;
1523 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001524 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001525trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001526 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_CERT)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001527 return NULL;
1528}
1529
1530static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001531ikev1_cr_print(netdissect_options *ndo, u_char tpay _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001532 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001533 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi0 _U_,
1534 uint32_t proto0 _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001535{
JP Abgrall53f17a92014-02-12 14:02:41 -08001536 const struct ikev1_pl_cert *p;
1537 struct ikev1_pl_cert cert;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001538 static const char *certstr[] = {
1539 "none", "pkcs7", "pgp", "dns",
1540 "x509sign", "x509ke", "kerberos", "crl",
1541 "arl", "spki", "x509attr",
1542 };
1543
JP Abgrall53f17a92014-02-12 14:02:41 -08001544 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_CR)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001545
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001546 p = (const struct ikev1_pl_cert *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001547 ND_TCHECK(*p);
1548 UNALIGNED_MEMCPY(&cert, ext, sizeof(cert));
1549 ND_PRINT((ndo," len=%d", item_len - 4));
1550 ND_PRINT((ndo," type=%s", STR_OR_ID((cert.encode), certstr)));
1551 if (2 < ndo->ndo_vflag && 4 < item_len) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001552 /* Print the entire payload in hex */
JP Abgrall53f17a92014-02-12 14:02:41 -08001553 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001554 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001555 goto trunc;
1556 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001557 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001558trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001559 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_CR)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001560 return NULL;
1561}
1562
1563static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001564ikev1_hash_print(netdissect_options *ndo, u_char tpay _U_,
1565 const struct isakmp_gen *ext, u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001566 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi _U_,
1567 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001568{
1569 struct isakmp_gen e;
1570
JP Abgrall53f17a92014-02-12 14:02:41 -08001571 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_HASH)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001572
JP Abgrall53f17a92014-02-12 14:02:41 -08001573 ND_TCHECK(*ext);
1574 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
1575 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1576 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001577 /* Print the entire payload in hex */
JP Abgrall53f17a92014-02-12 14:02:41 -08001578 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001579 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001580 goto trunc;
1581 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001582 return (const u_char *)ext + ntohs(e.len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001583trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001584 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_HASH)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001585 return NULL;
1586}
1587
1588static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001589ikev1_sig_print(netdissect_options *ndo, u_char tpay _U_,
1590 const struct isakmp_gen *ext, u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001591 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi _U_,
1592 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001593{
1594 struct isakmp_gen e;
1595
JP Abgrall53f17a92014-02-12 14:02:41 -08001596 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_SIG)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001597
JP Abgrall53f17a92014-02-12 14:02:41 -08001598 ND_TCHECK(*ext);
1599 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
1600 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1601 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001602 /* Print the entire payload in hex */
JP Abgrall53f17a92014-02-12 14:02:41 -08001603 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001604 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001605 goto trunc;
1606 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001607 return (const u_char *)ext + ntohs(e.len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001608trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001609 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_SIG)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001610 return NULL;
1611}
1612
1613static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001614ikev1_nonce_print(netdissect_options *ndo, u_char tpay _U_,
1615 const struct isakmp_gen *ext,
1616 u_int item_len _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001617 const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001618 uint32_t phase _U_, uint32_t doi _U_,
1619 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001620{
JP Abgrall53f17a92014-02-12 14:02:41 -08001621 struct isakmp_gen e;
1622
1623 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_NONCE)));
1624
1625 ND_TCHECK(*ext);
1626 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
Elliott Hughescec480a2017-12-19 16:54:57 -08001627 /*
1628 * Our caller has ensured that the length is >= 4.
1629 */
1630 ND_PRINT((ndo," n len=%u", ntohs(e.len) - 4));
1631 if (ntohs(e.len) > 4) {
1632 if (ndo->ndo_vflag > 2) {
1633 ND_PRINT((ndo, " "));
1634 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
1635 goto trunc;
1636 } else if (ndo->ndo_vflag > 1) {
1637 ND_PRINT((ndo, " "));
1638 if (!ike_show_somedata(ndo, (const u_char *)(ext + 1), ep))
1639 goto trunc;
1640 }
JP Abgrall53f17a92014-02-12 14:02:41 -08001641 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001642 return (const u_char *)ext + ntohs(e.len);
JP Abgrall53f17a92014-02-12 14:02:41 -08001643trunc:
1644 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE)));
1645 return NULL;
1646}
1647
1648static const u_char *
1649ikev1_n_print(netdissect_options *ndo, u_char tpay _U_,
1650 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughescec480a2017-12-19 16:54:57 -08001651 const u_char *ep, uint32_t phase _U_, uint32_t doi0 _U_,
1652 uint32_t proto0 _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08001653{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001654 const struct ikev1_pl_n *p;
1655 struct ikev1_pl_n n;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001656 const u_char *cp;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001657 const u_char *ep2;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001658 uint32_t doi;
1659 uint32_t proto;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001660 static const char *notify_error_str[] = {
1661 NULL, "INVALID-PAYLOAD-TYPE",
1662 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
1663 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
1664 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
1665 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
1666 "INVALID-PROTOCOL-ID", "INVALID-SPI",
1667 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
1668 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
1669 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
1670 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
1671 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
1672 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
1673 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
1674 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
1675 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
1676 "UNEQUAL-PAYLOAD-LENGTHS",
1677 };
1678 static const char *ipsec_notify_error_str[] = {
1679 "RESERVED",
1680 };
1681 static const char *notify_status_str[] = {
1682 "CONNECTED",
1683 };
1684 static const char *ipsec_notify_status_str[] = {
1685 "RESPONDER-LIFETIME", "REPLAY-STATUS",
1686 "INITIAL-CONTACT",
1687 };
1688/* NOTE: these macro must be called with x in proper range */
1689
1690/* 0 - 8191 */
1691#define NOTIFY_ERROR_STR(x) \
1692 STR_OR_ID((x), notify_error_str)
1693
1694/* 8192 - 16383 */
1695#define IPSEC_NOTIFY_ERROR_STR(x) \
1696 STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str)
1697
1698/* 16384 - 24575 */
1699#define NOTIFY_STATUS_STR(x) \
1700 STR_OR_ID((u_int)((x) - 16384), notify_status_str)
1701
1702/* 24576 - 32767 */
1703#define IPSEC_NOTIFY_STATUS_STR(x) \
1704 STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str)
1705
JP Abgrall53f17a92014-02-12 14:02:41 -08001706 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_N)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001707
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001708 p = (const struct ikev1_pl_n *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001709 ND_TCHECK(*p);
1710 UNALIGNED_MEMCPY(&n, ext, sizeof(n));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001711 doi = ntohl(n.doi);
1712 proto = n.prot_id;
1713 if (doi != 1) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001714 ND_PRINT((ndo," doi=%d", doi));
1715 ND_PRINT((ndo," proto=%d", proto));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001716 if (ntohs(n.type) < 8192)
JP Abgrall53f17a92014-02-12 14:02:41 -08001717 ND_PRINT((ndo," type=%s", NOTIFY_ERROR_STR(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001718 else if (ntohs(n.type) < 16384)
JP Abgrall53f17a92014-02-12 14:02:41 -08001719 ND_PRINT((ndo," type=%s", numstr(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001720 else if (ntohs(n.type) < 24576)
JP Abgrall53f17a92014-02-12 14:02:41 -08001721 ND_PRINT((ndo," type=%s", NOTIFY_STATUS_STR(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001722 else
JP Abgrall53f17a92014-02-12 14:02:41 -08001723 ND_PRINT((ndo," type=%s", numstr(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001724 if (n.spi_size) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001725 ND_PRINT((ndo," spi="));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001726 if (!rawprint(ndo, (const uint8_t *)(p + 1), n.spi_size))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001727 goto trunc;
1728 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001729 return (const u_char *)(p + 1) + n.spi_size;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001730 }
1731
JP Abgrall53f17a92014-02-12 14:02:41 -08001732 ND_PRINT((ndo," doi=ipsec"));
1733 ND_PRINT((ndo," proto=%s", PROTOIDSTR(proto)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001734 if (ntohs(n.type) < 8192)
JP Abgrall53f17a92014-02-12 14:02:41 -08001735 ND_PRINT((ndo," type=%s", NOTIFY_ERROR_STR(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001736 else if (ntohs(n.type) < 16384)
JP Abgrall53f17a92014-02-12 14:02:41 -08001737 ND_PRINT((ndo," type=%s", IPSEC_NOTIFY_ERROR_STR(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001738 else if (ntohs(n.type) < 24576)
JP Abgrall53f17a92014-02-12 14:02:41 -08001739 ND_PRINT((ndo," type=%s", NOTIFY_STATUS_STR(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001740 else if (ntohs(n.type) < 32768)
JP Abgrall53f17a92014-02-12 14:02:41 -08001741 ND_PRINT((ndo," type=%s", IPSEC_NOTIFY_STATUS_STR(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001742 else
JP Abgrall53f17a92014-02-12 14:02:41 -08001743 ND_PRINT((ndo," type=%s", numstr(ntohs(n.type))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001744 if (n.spi_size) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001745 ND_PRINT((ndo," spi="));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001746 if (!rawprint(ndo, (const uint8_t *)(p + 1), n.spi_size))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001747 goto trunc;
1748 }
1749
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001750 cp = (const u_char *)(p + 1) + n.spi_size;
1751 ep2 = (const u_char *)p + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001752
1753 if (cp < ep) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001754 switch (ntohs(n.type)) {
1755 case IPSECDOI_NTYPE_RESPONDER_LIFETIME:
1756 {
1757 const struct attrmap *map = oakley_t_map;
1758 size_t nmap = sizeof(oakley_t_map)/sizeof(oakley_t_map[0]);
Elliott Hughescec480a2017-12-19 16:54:57 -08001759 ND_PRINT((ndo," attrs=("));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001760 while (cp < ep && cp < ep2) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001761 cp = ikev1_attrmap_print(ndo, cp, ep2, map, nmap);
1762 if (cp == NULL) {
1763 ND_PRINT((ndo,")"));
1764 goto trunc;
1765 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001766 }
Elliott Hughescec480a2017-12-19 16:54:57 -08001767 ND_PRINT((ndo,")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001768 break;
1769 }
1770 case IPSECDOI_NTYPE_REPLAY_STATUS:
Elliott Hughescec480a2017-12-19 16:54:57 -08001771 ND_PRINT((ndo," status=("));
JP Abgrall53f17a92014-02-12 14:02:41 -08001772 ND_PRINT((ndo,"replay detection %sabled",
1773 EXTRACT_32BITS(cp) ? "en" : "dis"));
Elliott Hughescec480a2017-12-19 16:54:57 -08001774 ND_PRINT((ndo,")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001775 break;
1776 default:
Elliott Hughescec480a2017-12-19 16:54:57 -08001777 /*
1778 * XXX - fill in more types here; see, for example,
1779 * draft-ietf-ipsec-notifymsg-04.
1780 */
1781 if (ndo->ndo_vflag > 3) {
1782 ND_PRINT((ndo," data=("));
1783 if (!rawprint(ndo, (const uint8_t *)(cp), ep - cp))
1784 goto trunc;
1785 ND_PRINT((ndo,")"));
1786 } else {
1787 if (!ike_show_somedata(ndo, cp, ep))
1788 goto trunc;
1789 }
1790 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001791 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001792 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001793 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001794trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001795 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_N)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001796 return NULL;
1797}
1798
1799static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001800ikev1_d_print(netdissect_options *ndo, u_char tpay _U_,
1801 const struct isakmp_gen *ext, u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001802 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi0 _U_,
1803 uint32_t proto0 _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001804{
JP Abgrall53f17a92014-02-12 14:02:41 -08001805 const struct ikev1_pl_d *p;
1806 struct ikev1_pl_d d;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001807 const uint8_t *q;
1808 uint32_t doi;
1809 uint32_t proto;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001810 int i;
1811
JP Abgrall53f17a92014-02-12 14:02:41 -08001812 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_D)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001813
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001814 p = (const struct ikev1_pl_d *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001815 ND_TCHECK(*p);
1816 UNALIGNED_MEMCPY(&d, ext, sizeof(d));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001817 doi = ntohl(d.doi);
1818 proto = d.prot_id;
1819 if (doi != 1) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001820 ND_PRINT((ndo," doi=%u", doi));
1821 ND_PRINT((ndo," proto=%u", proto));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001822 } else {
JP Abgrall53f17a92014-02-12 14:02:41 -08001823 ND_PRINT((ndo," doi=ipsec"));
1824 ND_PRINT((ndo," proto=%s", PROTOIDSTR(proto)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001825 }
JP Abgrall53f17a92014-02-12 14:02:41 -08001826 ND_PRINT((ndo," spilen=%u", d.spi_size));
1827 ND_PRINT((ndo," nspi=%u", ntohs(d.num_spi)));
1828 ND_PRINT((ndo," spi="));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001829 q = (const uint8_t *)(p + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001830 for (i = 0; i < ntohs(d.num_spi); i++) {
1831 if (i != 0)
JP Abgrall53f17a92014-02-12 14:02:41 -08001832 ND_PRINT((ndo,","));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001833 if (!rawprint(ndo, (const uint8_t *)q, d.spi_size))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001834 goto trunc;
1835 q += d.spi_size;
1836 }
1837 return q;
1838trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001839 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_D)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001840 return NULL;
1841}
1842
1843static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001844ikev1_vid_print(netdissect_options *ndo, u_char tpay _U_,
1845 const struct isakmp_gen *ext,
1846 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001847 uint32_t phase _U_, uint32_t doi _U_,
1848 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001849{
1850 struct isakmp_gen e;
1851
JP Abgrall53f17a92014-02-12 14:02:41 -08001852 ND_PRINT((ndo,"%s:", NPSTR(ISAKMP_NPTYPE_VID)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001853
JP Abgrall53f17a92014-02-12 14:02:41 -08001854 ND_TCHECK(*ext);
1855 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
1856 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1857 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001858 /* Print the entire payload in hex */
JP Abgrall53f17a92014-02-12 14:02:41 -08001859 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001860 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001861 goto trunc;
1862 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001863 return (const u_char *)ext + ntohs(e.len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001864trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08001865 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_VID)));
1866 return NULL;
1867}
1868
1869/************************************************************/
1870/* */
1871/* IKE v2 - rfc4306 - dissector */
1872/* */
1873/************************************************************/
1874
1875static void
1876ikev2_pay_print(netdissect_options *ndo, const char *payname, int critical)
1877{
1878 ND_PRINT((ndo,"%s%s:", payname, critical&0x80 ? "[C]" : ""));
1879}
1880
1881static const u_char *
1882ikev2_gen_print(netdissect_options *ndo, u_char tpay,
1883 const struct isakmp_gen *ext)
1884{
1885 struct isakmp_gen e;
1886
1887 ND_TCHECK(*ext);
1888 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
1889 ikev2_pay_print(ndo, NPSTR(tpay), e.critical);
1890
1891 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
1892 if (2 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001893 /* Print the entire payload in hex */
JP Abgrall53f17a92014-02-12 14:02:41 -08001894 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001895 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08001896 goto trunc;
1897 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001898 return (const u_char *)ext + ntohs(e.len);
JP Abgrall53f17a92014-02-12 14:02:41 -08001899trunc:
1900 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001901 return NULL;
1902}
1903
1904static const u_char *
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001905ikev2_t_print(netdissect_options *ndo, int tcount,
JP Abgrall53f17a92014-02-12 14:02:41 -08001906 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001907 const u_char *ep)
JP Abgrall53f17a92014-02-12 14:02:41 -08001908{
1909 const struct ikev2_t *p;
1910 struct ikev2_t t;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001911 uint16_t t_id;
JP Abgrall53f17a92014-02-12 14:02:41 -08001912 const u_char *cp;
1913 const char *idstr;
1914 const struct attrmap *map;
1915 size_t nmap;
1916 const u_char *ep2;
1917
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001918 p = (const struct ikev2_t *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001919 ND_TCHECK(*p);
1920 UNALIGNED_MEMCPY(&t, ext, sizeof(t));
1921 ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_T), t.h.critical);
1922
1923 t_id = ntohs(t.t_id);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001924
JP Abgrall53f17a92014-02-12 14:02:41 -08001925 map = NULL;
1926 nmap = 0;
1927
1928 switch (t.t_type) {
1929 case IV2_T_ENCR:
1930 idstr = STR_OR_ID(t_id, esp_p_map);
1931 map = encr_t_map;
1932 nmap = sizeof(encr_t_map)/sizeof(encr_t_map[0]);
1933 break;
1934
1935 case IV2_T_PRF:
1936 idstr = STR_OR_ID(t_id, prf_p_map);
1937 break;
1938
1939 case IV2_T_INTEG:
1940 idstr = STR_OR_ID(t_id, integ_p_map);
1941 break;
1942
1943 case IV2_T_DH:
1944 idstr = STR_OR_ID(t_id, dh_p_map);
1945 break;
1946
1947 case IV2_T_ESN:
1948 idstr = STR_OR_ID(t_id, esn_p_map);
1949 break;
1950
1951 default:
1952 idstr = NULL;
1953 break;
1954 }
1955
1956 if (idstr)
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001957 ND_PRINT((ndo," #%u type=%s id=%s ", tcount,
JP Abgrall53f17a92014-02-12 14:02:41 -08001958 STR_OR_ID(t.t_type, ikev2_t_type_map),
1959 idstr));
1960 else
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001961 ND_PRINT((ndo," #%u type=%s id=%u ", tcount,
JP Abgrall53f17a92014-02-12 14:02:41 -08001962 STR_OR_ID(t.t_type, ikev2_t_type_map),
1963 t.t_id));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001964 cp = (const u_char *)(p + 1);
1965 ep2 = (const u_char *)p + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08001966 while (cp < ep && cp < ep2) {
1967 if (map && nmap) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001968 cp = ikev1_attrmap_print(ndo, cp, ep2, map, nmap);
JP Abgrall53f17a92014-02-12 14:02:41 -08001969 } else
Elliott Hughescec480a2017-12-19 16:54:57 -08001970 cp = ikev1_attr_print(ndo, cp, ep2);
1971 if (cp == NULL)
1972 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08001973 }
1974 if (ep < ep2)
1975 ND_PRINT((ndo,"..."));
1976 return cp;
1977trunc:
1978 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_T)));
1979 return NULL;
1980}
1981
1982static const u_char *
1983ikev2_p_print(netdissect_options *ndo, u_char tpay _U_, int pcount _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001984 const struct isakmp_gen *ext, u_int oprop_length,
1985 const u_char *ep, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08001986{
1987 const struct ikev2_p *p;
1988 struct ikev2_p prop;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001989 u_int prop_length;
JP Abgrall53f17a92014-02-12 14:02:41 -08001990 const u_char *cp;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001991 int i;
1992 int tcount;
1993 u_char np;
1994 struct isakmp_gen e;
1995 u_int item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08001996
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001997 p = (const struct ikev2_p *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001998 ND_TCHECK(*p);
1999 UNALIGNED_MEMCPY(&prop, ext, sizeof(prop));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002000
JP Abgrall53f17a92014-02-12 14:02:41 -08002001 ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_P), prop.h.critical);
2002
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002003 /*
2004 * ikev2_sa_print() guarantees that this is >= 4.
2005 */
2006 prop_length = oprop_length - 4;
JP Abgrall53f17a92014-02-12 14:02:41 -08002007 ND_PRINT((ndo," #%u protoid=%s transform=%d len=%u",
2008 prop.p_no, PROTOIDSTR(prop.prot_id),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002009 prop.num_t, oprop_length));
2010 cp = (const u_char *)(p + 1);
2011
JP Abgrall53f17a92014-02-12 14:02:41 -08002012 if (prop.spi_size) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002013 if (prop_length < prop.spi_size)
2014 goto toolong;
JP Abgrall53f17a92014-02-12 14:02:41 -08002015 ND_PRINT((ndo," spi="));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002016 if (!rawprint(ndo, (const uint8_t *)cp, prop.spi_size))
JP Abgrall53f17a92014-02-12 14:02:41 -08002017 goto trunc;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002018 cp += prop.spi_size;
2019 prop_length -= prop.spi_size;
JP Abgrall53f17a92014-02-12 14:02:41 -08002020 }
2021
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002022 /*
2023 * Print the transforms.
2024 */
2025 tcount = 0;
2026 for (np = ISAKMP_NPTYPE_T; np != 0; np = e.np) {
2027 tcount++;
2028 ext = (const struct isakmp_gen *)cp;
2029 if (prop_length < sizeof(*ext))
2030 goto toolong;
2031 ND_TCHECK(*ext);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002032 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
Elliott Hughes892a68b2015-10-19 14:43:53 -07002033
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002034 /*
2035 * Since we can't have a payload length of less than 4 bytes,
2036 * we need to bail out here if the generic header is nonsensical
2037 * or truncated, otherwise we could loop forever processing
2038 * zero-length items or otherwise misdissect the packet.
2039 */
2040 item_len = ntohs(e.len);
2041 if (item_len <= 4)
2042 goto trunc;
2043
2044 if (prop_length < item_len)
2045 goto toolong;
2046 ND_TCHECK2(*cp, item_len);
2047
2048 depth++;
2049 ND_PRINT((ndo,"\n"));
2050 for (i = 0; i < depth; i++)
2051 ND_PRINT((ndo," "));
2052 ND_PRINT((ndo,"("));
2053 if (np == ISAKMP_NPTYPE_T) {
2054 cp = ikev2_t_print(ndo, tcount, ext, item_len, ep);
2055 if (cp == NULL) {
2056 /* error, already reported */
2057 return NULL;
2058 }
2059 } else {
2060 ND_PRINT((ndo, "%s", NPSTR(np)));
2061 cp += item_len;
2062 }
2063 ND_PRINT((ndo,")"));
2064 depth--;
2065 prop_length -= item_len;
2066 }
2067 return cp;
2068toolong:
2069 /*
2070 * Skip the rest of the proposal.
2071 */
2072 cp += prop_length;
2073 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_P)));
JP Abgrall53f17a92014-02-12 14:02:41 -08002074 return cp;
2075trunc:
2076 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_P)));
2077 return NULL;
2078}
2079
2080static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002081ikev2_sa_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002082 const struct isakmp_gen *ext1,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002083 u_int osa_length, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002084 uint32_t phase _U_, uint32_t doi _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002085 uint32_t proto _U_, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08002086{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002087 const struct isakmp_gen *ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08002088 struct isakmp_gen e;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002089 u_int sa_length;
2090 const u_char *cp;
2091 int i;
2092 int pcount;
2093 u_char np;
2094 u_int item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002095
2096 ND_TCHECK(*ext1);
2097 UNALIGNED_MEMCPY(&e, ext1, sizeof(e));
2098 ikev2_pay_print(ndo, "sa", e.critical);
2099
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002100 /*
2101 * ikev2_sub0_print() guarantees that this is >= 4.
2102 */
JP Abgrall53f17a92014-02-12 14:02:41 -08002103 osa_length= ntohs(e.len);
2104 sa_length = osa_length - 4;
2105 ND_PRINT((ndo," len=%d", sa_length));
2106
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002107 /*
2108 * Print the payloads.
2109 */
2110 cp = (const u_char *)(ext1 + 1);
2111 pcount = 0;
2112 for (np = ISAKMP_NPTYPE_P; np != 0; np = e.np) {
2113 pcount++;
2114 ext = (const struct isakmp_gen *)cp;
2115 if (sa_length < sizeof(*ext))
2116 goto toolong;
2117 ND_TCHECK(*ext);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002118 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2119
2120 /*
2121 * Since we can't have a payload length of less than 4 bytes,
2122 * we need to bail out here if the generic header is nonsensical
2123 * or truncated, otherwise we could loop forever processing
2124 * zero-length items or otherwise misdissect the packet.
2125 */
2126 item_len = ntohs(e.len);
2127 if (item_len <= 4)
2128 goto trunc;
2129
2130 if (sa_length < item_len)
2131 goto toolong;
2132 ND_TCHECK2(*cp, item_len);
2133
2134 depth++;
2135 ND_PRINT((ndo,"\n"));
2136 for (i = 0; i < depth; i++)
2137 ND_PRINT((ndo," "));
2138 ND_PRINT((ndo,"("));
2139 if (np == ISAKMP_NPTYPE_P) {
2140 cp = ikev2_p_print(ndo, np, pcount, ext, item_len,
2141 ep, depth);
2142 if (cp == NULL) {
2143 /* error, already reported */
2144 return NULL;
2145 }
2146 } else {
2147 ND_PRINT((ndo, "%s", NPSTR(np)));
2148 cp += item_len;
2149 }
2150 ND_PRINT((ndo,")"));
2151 depth--;
2152 sa_length -= item_len;
2153 }
2154 return cp;
2155toolong:
2156 /*
2157 * Skip the rest of the SA.
2158 */
2159 cp += sa_length;
2160 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2161 return cp;
JP Abgrall53f17a92014-02-12 14:02:41 -08002162trunc:
2163 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2164 return NULL;
2165}
2166
2167static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002168ikev2_ke_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002169 const struct isakmp_gen *ext,
2170 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002171 uint32_t phase _U_, uint32_t doi _U_,
2172 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002173{
2174 struct ikev2_ke ke;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002175 const struct ikev2_ke *k;
JP Abgrall53f17a92014-02-12 14:02:41 -08002176
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002177 k = (const struct ikev2_ke *)ext;
Elliott Hughescec480a2017-12-19 16:54:57 -08002178 ND_TCHECK(*k);
JP Abgrall53f17a92014-02-12 14:02:41 -08002179 UNALIGNED_MEMCPY(&ke, ext, sizeof(ke));
2180 ikev2_pay_print(ndo, NPSTR(tpay), ke.h.critical);
2181
2182 ND_PRINT((ndo," len=%u group=%s", ntohs(ke.h.len) - 8,
2183 STR_OR_ID(ntohs(ke.ke_group), dh_p_map)));
Elliott Hughes892a68b2015-10-19 14:43:53 -07002184
JP Abgrall53f17a92014-02-12 14:02:41 -08002185 if (2 < ndo->ndo_vflag && 8 < ntohs(ke.h.len)) {
2186 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002187 if (!rawprint(ndo, (const uint8_t *)(k + 1), ntohs(ke.h.len) - 8))
JP Abgrall53f17a92014-02-12 14:02:41 -08002188 goto trunc;
2189 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002190 return (const u_char *)ext + ntohs(ke.h.len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002191trunc:
2192 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2193 return NULL;
2194}
2195
2196static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002197ikev2_ID_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002198 const struct isakmp_gen *ext,
2199 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002200 uint32_t phase _U_, uint32_t doi _U_,
2201 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002202{
Elliott Hughescec480a2017-12-19 16:54:57 -08002203 const struct ikev2_id *idp;
JP Abgrall53f17a92014-02-12 14:02:41 -08002204 struct ikev2_id id;
2205 int id_len, idtype_len, i;
2206 unsigned int dumpascii, dumphex;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002207 const unsigned char *typedata;
JP Abgrall53f17a92014-02-12 14:02:41 -08002208
Elliott Hughescec480a2017-12-19 16:54:57 -08002209 idp = (const struct ikev2_id *)ext;
2210 ND_TCHECK(*idp);
JP Abgrall53f17a92014-02-12 14:02:41 -08002211 UNALIGNED_MEMCPY(&id, ext, sizeof(id));
2212 ikev2_pay_print(ndo, NPSTR(tpay), id.h.critical);
2213
2214 id_len = ntohs(id.h.len);
2215
2216 ND_PRINT((ndo," len=%d", id_len - 4));
2217 if (2 < ndo->ndo_vflag && 4 < id_len) {
Elliott Hughescec480a2017-12-19 16:54:57 -08002218 /* Print the entire payload in hex */
JP Abgrall53f17a92014-02-12 14:02:41 -08002219 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002220 if (!rawprint(ndo, (const uint8_t *)(ext + 1), id_len - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08002221 goto trunc;
2222 }
2223
2224 idtype_len =id_len - sizeof(struct ikev2_id);
2225 dumpascii = 0;
2226 dumphex = 0;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002227 typedata = (const unsigned char *)(ext)+sizeof(struct ikev2_id);
JP Abgrall53f17a92014-02-12 14:02:41 -08002228
2229 switch(id.type) {
2230 case ID_IPV4_ADDR:
2231 ND_PRINT((ndo, " ipv4:"));
2232 dumphex=1;
2233 break;
2234 case ID_FQDN:
2235 ND_PRINT((ndo, " fqdn:"));
2236 dumpascii=1;
2237 break;
2238 case ID_RFC822_ADDR:
2239 ND_PRINT((ndo, " rfc822:"));
2240 dumpascii=1;
2241 break;
2242 case ID_IPV6_ADDR:
2243 ND_PRINT((ndo, " ipv6:"));
2244 dumphex=1;
2245 break;
2246 case ID_DER_ASN1_DN:
2247 ND_PRINT((ndo, " dn:"));
2248 dumphex=1;
2249 break;
2250 case ID_DER_ASN1_GN:
2251 ND_PRINT((ndo, " gn:"));
2252 dumphex=1;
2253 break;
2254 case ID_KEY_ID:
2255 ND_PRINT((ndo, " keyid:"));
2256 dumphex=1;
2257 break;
2258 }
2259
2260 if(dumpascii) {
2261 ND_TCHECK2(*typedata, idtype_len);
2262 for(i=0; i<idtype_len; i++) {
2263 if(ND_ISPRINT(typedata[i])) {
2264 ND_PRINT((ndo, "%c", typedata[i]));
2265 } else {
2266 ND_PRINT((ndo, "."));
2267 }
2268 }
2269 }
2270 if(dumphex) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002271 if (!rawprint(ndo, (const uint8_t *)typedata, idtype_len))
JP Abgrall53f17a92014-02-12 14:02:41 -08002272 goto trunc;
2273 }
2274
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002275 return (const u_char *)ext + id_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002276trunc:
2277 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2278 return NULL;
2279}
2280
2281static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002282ikev2_cert_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002283 const struct isakmp_gen *ext,
2284 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002285 uint32_t phase _U_, uint32_t doi _U_,
2286 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002287{
2288 return ikev2_gen_print(ndo, tpay, ext);
2289}
2290
2291static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002292ikev2_cr_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002293 const struct isakmp_gen *ext,
2294 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002295 uint32_t phase _U_, uint32_t doi _U_,
2296 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002297{
2298 return ikev2_gen_print(ndo, tpay, ext);
2299}
2300
2301static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002302ikev2_auth_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002303 const struct isakmp_gen *ext,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002304 u_int item_len _U_, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002305 uint32_t phase _U_, uint32_t doi _U_,
2306 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002307{
2308 struct ikev2_auth a;
2309 const char *v2_auth[]={ "invalid", "rsasig",
2310 "shared-secret", "dsssig" };
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002311 const u_char *authdata = (const u_char*)ext + sizeof(a);
JP Abgrall53f17a92014-02-12 14:02:41 -08002312 unsigned int len;
2313
Elliott Hughescec480a2017-12-19 16:54:57 -08002314 ND_TCHECK2(*ext, sizeof(a));
JP Abgrall53f17a92014-02-12 14:02:41 -08002315 UNALIGNED_MEMCPY(&a, ext, sizeof(a));
2316 ikev2_pay_print(ndo, NPSTR(tpay), a.h.critical);
2317 len = ntohs(a.h.len);
2318
Elliott Hughescec480a2017-12-19 16:54:57 -08002319 /*
2320 * Our caller has ensured that the length is >= 4.
2321 */
2322 ND_PRINT((ndo," len=%u method=%s", len-4,
JP Abgrall53f17a92014-02-12 14:02:41 -08002323 STR_OR_ID(a.auth_method, v2_auth)));
Elliott Hughescec480a2017-12-19 16:54:57 -08002324 if (len > 4) {
2325 if (ndo->ndo_vflag > 1) {
2326 ND_PRINT((ndo, " authdata=("));
2327 if (!rawprint(ndo, (const uint8_t *)authdata, len - sizeof(a)))
2328 goto trunc;
2329 ND_PRINT((ndo, ") "));
2330 } else if (ndo->ndo_vflag) {
2331 if (!ike_show_somedata(ndo, authdata, ep))
2332 goto trunc;
2333 }
JP Abgrall53f17a92014-02-12 14:02:41 -08002334 }
2335
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002336 return (const u_char *)ext + len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002337trunc:
2338 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2339 return NULL;
2340}
2341
2342static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002343ikev2_nonce_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002344 const struct isakmp_gen *ext,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002345 u_int item_len _U_, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002346 uint32_t phase _U_, uint32_t doi _U_,
2347 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002348{
2349 struct isakmp_gen e;
2350
2351 ND_TCHECK(*ext);
2352 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2353 ikev2_pay_print(ndo, "nonce", e.critical);
2354
2355 ND_PRINT((ndo," len=%d", ntohs(e.len) - 4));
2356 if (1 < ndo->ndo_vflag && 4 < ntohs(e.len)) {
2357 ND_PRINT((ndo," nonce=("));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002358 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08002359 goto trunc;
2360 ND_PRINT((ndo,") "));
2361 } else if(ndo->ndo_vflag && 4 < ntohs(e.len)) {
2362 if(!ike_show_somedata(ndo, (const u_char *)(ext+1), ep)) goto trunc;
2363 }
2364
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002365 return (const u_char *)ext + ntohs(e.len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002366trunc:
2367 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2368 return NULL;
2369}
2370
2371/* notify payloads */
2372static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002373ikev2_n_print(netdissect_options *ndo, u_char tpay _U_,
JP Abgrall53f17a92014-02-12 14:02:41 -08002374 const struct isakmp_gen *ext,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002375 u_int item_len, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002376 uint32_t phase _U_, uint32_t doi _U_,
2377 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002378{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002379 const struct ikev2_n *p;
2380 struct ikev2_n n;
JP Abgrall53f17a92014-02-12 14:02:41 -08002381 const u_char *cp;
Elliott Hughescec480a2017-12-19 16:54:57 -08002382 u_char showspi, showsomedata;
JP Abgrall53f17a92014-02-12 14:02:41 -08002383 const char *notify_name;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002384 uint32_t type;
JP Abgrall53f17a92014-02-12 14:02:41 -08002385
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002386 p = (const struct ikev2_n *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08002387 ND_TCHECK(*p);
2388 UNALIGNED_MEMCPY(&n, ext, sizeof(n));
2389 ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_N), n.h.critical);
2390
2391 showspi = 1;
JP Abgrall53f17a92014-02-12 14:02:41 -08002392 showsomedata=0;
2393 notify_name=NULL;
2394
2395 ND_PRINT((ndo," prot_id=%s", PROTOIDSTR(n.prot_id)));
2396
2397 type = ntohs(n.type);
2398
2399 /* notify space is annoying sparse */
2400 switch(type) {
2401 case IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD:
2402 notify_name = "unsupported_critical_payload";
2403 showspi = 0;
2404 break;
2405
2406 case IV2_NOTIFY_INVALID_IKE_SPI:
2407 notify_name = "invalid_ike_spi";
2408 showspi = 1;
2409 break;
2410
2411 case IV2_NOTIFY_INVALID_MAJOR_VERSION:
2412 notify_name = "invalid_major_version";
2413 showspi = 0;
2414 break;
2415
2416 case IV2_NOTIFY_INVALID_SYNTAX:
2417 notify_name = "invalid_syntax";
2418 showspi = 1;
2419 break;
2420
2421 case IV2_NOTIFY_INVALID_MESSAGE_ID:
2422 notify_name = "invalid_message_id";
2423 showspi = 1;
2424 break;
2425
2426 case IV2_NOTIFY_INVALID_SPI:
2427 notify_name = "invalid_spi";
2428 showspi = 1;
2429 break;
2430
2431 case IV2_NOTIFY_NO_PROPOSAL_CHOSEN:
2432 notify_name = "no_protocol_chosen";
2433 showspi = 1;
2434 break;
2435
2436 case IV2_NOTIFY_INVALID_KE_PAYLOAD:
2437 notify_name = "invalid_ke_payload";
2438 showspi = 1;
2439 break;
2440
2441 case IV2_NOTIFY_AUTHENTICATION_FAILED:
2442 notify_name = "authentication_failed";
2443 showspi = 1;
2444 break;
2445
2446 case IV2_NOTIFY_SINGLE_PAIR_REQUIRED:
2447 notify_name = "single_pair_required";
2448 showspi = 1;
2449 break;
2450
2451 case IV2_NOTIFY_NO_ADDITIONAL_SAS:
2452 notify_name = "no_additional_sas";
2453 showspi = 0;
2454 break;
2455
2456 case IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE:
2457 notify_name = "internal_address_failure";
2458 showspi = 0;
2459 break;
2460
Elliott Hughes892a68b2015-10-19 14:43:53 -07002461 case IV2_NOTIFY_FAILED_CP_REQUIRED:
JP Abgrall53f17a92014-02-12 14:02:41 -08002462 notify_name = "failed:cp_required";
2463 showspi = 0;
2464 break;
2465
2466 case IV2_NOTIFY_INVALID_SELECTORS:
2467 notify_name = "invalid_selectors";
2468 showspi = 0;
2469 break;
2470
2471 case IV2_NOTIFY_INITIAL_CONTACT:
2472 notify_name = "initial_contact";
2473 showspi = 0;
2474 break;
2475
Elliott Hughes892a68b2015-10-19 14:43:53 -07002476 case IV2_NOTIFY_SET_WINDOW_SIZE:
JP Abgrall53f17a92014-02-12 14:02:41 -08002477 notify_name = "set_window_size";
2478 showspi = 0;
2479 break;
2480
2481 case IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE:
2482 notify_name = "additional_ts_possible";
2483 showspi = 0;
2484 break;
2485
Elliott Hughes892a68b2015-10-19 14:43:53 -07002486 case IV2_NOTIFY_IPCOMP_SUPPORTED:
JP Abgrall53f17a92014-02-12 14:02:41 -08002487 notify_name = "ipcomp_supported";
2488 showspi = 0;
2489 break;
2490
2491 case IV2_NOTIFY_NAT_DETECTION_SOURCE_IP:
2492 notify_name = "nat_detection_source_ip";
2493 showspi = 1;
2494 break;
2495
2496 case IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP:
2497 notify_name = "nat_detection_destination_ip";
2498 showspi = 1;
2499 break;
2500
2501 case IV2_NOTIFY_COOKIE:
2502 notify_name = "cookie";
2503 showspi = 1;
2504 showsomedata= 1;
JP Abgrall53f17a92014-02-12 14:02:41 -08002505 break;
2506
2507 case IV2_NOTIFY_USE_TRANSPORT_MODE:
2508 notify_name = "use_transport_mode";
2509 showspi = 0;
2510 break;
2511
2512 case IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED:
2513 notify_name = "http_cert_lookup_supported";
2514 showspi = 0;
2515 break;
2516
2517 case IV2_NOTIFY_REKEY_SA:
2518 notify_name = "rekey_sa";
2519 showspi = 1;
2520 break;
2521
2522 case IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED:
2523 notify_name = "tfc_padding_not_supported";
2524 showspi = 0;
2525 break;
2526
2527 case IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO:
2528 notify_name = "non_first_fragment_also";
2529 showspi = 0;
2530 break;
2531
2532 default:
2533 if (type < 8192) {
2534 notify_name="error";
2535 } else if(type < 16384) {
2536 notify_name="private-error";
2537 } else if(type < 40960) {
2538 notify_name="status";
2539 } else {
2540 notify_name="private-status";
2541 }
2542 }
2543
2544 if(notify_name) {
2545 ND_PRINT((ndo," type=%u(%s)", type, notify_name));
2546 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002547
JP Abgrall53f17a92014-02-12 14:02:41 -08002548
2549 if (showspi && n.spi_size) {
2550 ND_PRINT((ndo," spi="));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002551 if (!rawprint(ndo, (const uint8_t *)(p + 1), n.spi_size))
JP Abgrall53f17a92014-02-12 14:02:41 -08002552 goto trunc;
2553 }
2554
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002555 cp = (const u_char *)(p + 1) + n.spi_size;
JP Abgrall53f17a92014-02-12 14:02:41 -08002556
Elliott Hughescec480a2017-12-19 16:54:57 -08002557 if (cp < ep) {
2558 if (ndo->ndo_vflag > 3 || (showsomedata && ep-cp < 30)) {
2559 ND_PRINT((ndo," data=("));
2560 if (!rawprint(ndo, (const uint8_t *)(cp), ep - cp))
2561 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08002562
Elliott Hughescec480a2017-12-19 16:54:57 -08002563 ND_PRINT((ndo,")"));
2564 } else if (showsomedata) {
2565 if (!ike_show_somedata(ndo, cp, ep))
2566 goto trunc;
2567 }
JP Abgrall53f17a92014-02-12 14:02:41 -08002568 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002569
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002570 return (const u_char *)ext + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002571trunc:
2572 ND_PRINT((ndo," [|%s]", NPSTR(ISAKMP_NPTYPE_N)));
2573 return NULL;
2574}
2575
2576static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002577ikev2_d_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002578 const struct isakmp_gen *ext,
2579 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002580 uint32_t phase _U_, uint32_t doi _U_,
2581 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002582{
2583 return ikev2_gen_print(ndo, tpay, ext);
2584}
2585
2586static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002587ikev2_vid_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002588 const struct isakmp_gen *ext,
2589 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002590 uint32_t phase _U_, uint32_t doi _U_,
2591 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002592{
2593 struct isakmp_gen e;
2594 const u_char *vid;
2595 int i, len;
2596
2597 ND_TCHECK(*ext);
2598 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2599 ikev2_pay_print(ndo, NPSTR(tpay), e.critical);
2600 ND_PRINT((ndo," len=%d vid=", ntohs(e.len) - 4));
2601
2602 vid = (const u_char *)(ext+1);
2603 len = ntohs(e.len) - 4;
2604 ND_TCHECK2(*vid, len);
2605 for(i=0; i<len; i++) {
2606 if(ND_ISPRINT(vid[i])) ND_PRINT((ndo, "%c", vid[i]));
2607 else ND_PRINT((ndo, "."));
2608 }
2609 if (2 < ndo->ndo_vflag && 4 < len) {
Elliott Hughescec480a2017-12-19 16:54:57 -08002610 /* Print the entire payload in hex */
JP Abgrall53f17a92014-02-12 14:02:41 -08002611 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002612 if (!rawprint(ndo, (const uint8_t *)(ext + 1), ntohs(e.len) - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08002613 goto trunc;
2614 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002615 return (const u_char *)ext + ntohs(e.len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002616trunc:
2617 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2618 return NULL;
2619}
2620
2621static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002622ikev2_TS_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002623 const struct isakmp_gen *ext,
2624 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002625 uint32_t phase _U_, uint32_t doi _U_,
2626 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002627{
2628 return ikev2_gen_print(ndo, tpay, ext);
2629}
2630
2631static const u_char *
2632ikev2_e_print(netdissect_options *ndo,
2633#ifndef HAVE_LIBCRYPTO
2634 _U_
2635#endif
2636 struct isakmp *base,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002637 u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002638 const struct isakmp_gen *ext,
2639 u_int item_len _U_, const u_char *ep _U_,
2640#ifndef HAVE_LIBCRYPTO
2641 _U_
2642#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -07002643 uint32_t phase,
JP Abgrall53f17a92014-02-12 14:02:41 -08002644#ifndef HAVE_LIBCRYPTO
2645 _U_
2646#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -07002647 uint32_t doi,
JP Abgrall53f17a92014-02-12 14:02:41 -08002648#ifndef HAVE_LIBCRYPTO
2649 _U_
2650#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -07002651 uint32_t proto,
JP Abgrall53f17a92014-02-12 14:02:41 -08002652#ifndef HAVE_LIBCRYPTO
2653 _U_
2654#endif
2655 int depth)
2656{
2657 struct isakmp_gen e;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002658 const u_char *dat;
JP Abgrall53f17a92014-02-12 14:02:41 -08002659 volatile int dlen;
2660
2661 ND_TCHECK(*ext);
2662 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2663 ikev2_pay_print(ndo, NPSTR(tpay), e.critical);
2664
2665 dlen = ntohs(e.len)-4;
2666
2667 ND_PRINT((ndo," len=%d", dlen));
2668 if (2 < ndo->ndo_vflag && 4 < dlen) {
2669 ND_PRINT((ndo," "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002670 if (!rawprint(ndo, (const uint8_t *)(ext + 1), dlen))
JP Abgrall53f17a92014-02-12 14:02:41 -08002671 goto trunc;
2672 }
2673
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002674 dat = (const u_char *)(ext+1);
JP Abgrall53f17a92014-02-12 14:02:41 -08002675 ND_TCHECK2(*dat, dlen);
Elliott Hughes892a68b2015-10-19 14:43:53 -07002676
JP Abgrall53f17a92014-02-12 14:02:41 -08002677#ifdef HAVE_LIBCRYPTO
2678 /* try to decypt it! */
2679 if(esp_print_decrypt_buffer_by_ikev2(ndo,
2680 base->flags & ISAKMP_FLAG_I,
2681 base->i_ck, base->r_ck,
2682 dat, dat+dlen)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002683
JP Abgrall53f17a92014-02-12 14:02:41 -08002684 ext = (const struct isakmp_gen *)ndo->ndo_packetp;
2685
2686 /* got it decrypted, print stuff inside. */
2687 ikev2_sub_print(ndo, base, e.np, ext, ndo->ndo_snapend,
2688 phase, doi, proto, depth+1);
2689 }
2690#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -07002691
JP Abgrall53f17a92014-02-12 14:02:41 -08002692
2693 /* always return NULL, because E must be at end, and NP refers
2694 * to what was inside.
2695 */
2696 return NULL;
2697trunc:
2698 ND_PRINT((ndo," [|%s]", NPSTR(tpay)));
2699 return NULL;
2700}
2701
2702static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002703ikev2_cp_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002704 const struct isakmp_gen *ext,
2705 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002706 uint32_t phase _U_, uint32_t doi _U_,
2707 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002708{
2709 return ikev2_gen_print(ndo, tpay, ext);
2710}
2711
2712static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002713ikev2_eap_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002714 const struct isakmp_gen *ext,
2715 u_int item_len _U_, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002716 uint32_t phase _U_, uint32_t doi _U_,
2717 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002718{
2719 return ikev2_gen_print(ndo, tpay, ext);
2720}
2721
2722static const u_char *
2723ike_sub0_print(netdissect_options *ndo,
2724 u_char np, const struct isakmp_gen *ext, const u_char *ep,
2725
Elliott Hughes892a68b2015-10-19 14:43:53 -07002726 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002727{
2728 const u_char *cp;
2729 struct isakmp_gen e;
2730 u_int item_len;
2731
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002732 cp = (const u_char *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08002733 ND_TCHECK(*ext);
2734 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002735
2736 /*
2737 * Since we can't have a payload length of less than 4 bytes,
2738 * we need to bail out here if the generic header is nonsensical
2739 * or truncated, otherwise we could loop forever processing
2740 * zero-length items or otherwise misdissect the packet.
2741 */
2742 item_len = ntohs(e.len);
2743 if (item_len <= 4)
2744 return NULL;
2745
2746 if (NPFUNC(np)) {
2747 /*
2748 * XXX - what if item_len is too short, or too long,
2749 * for this payload type?
2750 */
JP Abgrall53f17a92014-02-12 14:02:41 -08002751 cp = (*npfunc[np])(ndo, np, ext, item_len, ep, phase, doi, proto, depth);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002752 } else {
JP Abgrall53f17a92014-02-12 14:02:41 -08002753 ND_PRINT((ndo,"%s", NPSTR(np)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002754 cp += item_len;
2755 }
2756
2757 return cp;
2758trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08002759 ND_PRINT((ndo," [|isakmp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002760 return NULL;
2761}
2762
2763static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08002764ikev1_sub_print(netdissect_options *ndo,
2765 u_char np, const struct isakmp_gen *ext, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002766 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002767{
2768 const u_char *cp;
2769 int i;
2770 struct isakmp_gen e;
2771
2772 cp = (const u_char *)ext;
2773
2774 while (np) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002775 ND_TCHECK(*ext);
JP Abgrall53f17a92014-02-12 14:02:41 -08002776 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2777
2778 ND_TCHECK2(*ext, ntohs(e.len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002779
2780 depth++;
JP Abgrall53f17a92014-02-12 14:02:41 -08002781 ND_PRINT((ndo,"\n"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002782 for (i = 0; i < depth; i++)
JP Abgrall53f17a92014-02-12 14:02:41 -08002783 ND_PRINT((ndo," "));
2784 ND_PRINT((ndo,"("));
2785 cp = ike_sub0_print(ndo, np, ext, ep, phase, doi, proto, depth);
2786 ND_PRINT((ndo,")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002787 depth--;
2788
2789 if (cp == NULL) {
2790 /* Zero-length subitem */
2791 return NULL;
2792 }
2793
2794 np = e.np;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002795 ext = (const struct isakmp_gen *)cp;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002796 }
2797 return cp;
2798trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08002799 ND_PRINT((ndo," [|%s]", NPSTR(np)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002800 return NULL;
2801}
2802
2803static char *
2804numstr(int x)
2805{
2806 static char buf[20];
2807 snprintf(buf, sizeof(buf), "#%d", x);
2808 return buf;
2809}
2810
The Android Open Source Project2949f582009-03-03 19:30:46 -08002811static void
JP Abgrall53f17a92014-02-12 14:02:41 -08002812ikev1_print(netdissect_options *ndo,
2813 const u_char *bp, u_int length,
2814 const u_char *bp2, struct isakmp *base)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002815{
JP Abgrall53f17a92014-02-12 14:02:41 -08002816 const struct isakmp *p;
2817 const u_char *ep;
2818 u_char np;
2819 int i;
2820 int phase;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002821
JP Abgrall53f17a92014-02-12 14:02:41 -08002822 p = (const struct isakmp *)bp;
2823 ep = ndo->ndo_snapend;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002824
JP Abgrall53f17a92014-02-12 14:02:41 -08002825 phase = (EXTRACT_32BITS(base->msgid) == 0) ? 1 : 2;
2826 if (phase == 1)
2827 ND_PRINT((ndo," phase %d", phase));
2828 else
2829 ND_PRINT((ndo," phase %d/others", phase));
Elliott Hughes892a68b2015-10-19 14:43:53 -07002830
JP Abgrall53f17a92014-02-12 14:02:41 -08002831 i = cookie_find(&base->i_ck);
2832 if (i < 0) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002833 if (iszero((const u_char *)&base->r_ck, sizeof(base->r_ck))) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002834 /* the first packet */
2835 ND_PRINT((ndo," I"));
2836 if (bp2)
2837 cookie_record(&base->i_ck, bp2);
2838 } else
2839 ND_PRINT((ndo," ?"));
2840 } else {
2841 if (bp2 && cookie_isinitiator(i, bp2))
2842 ND_PRINT((ndo," I"));
2843 else if (bp2 && cookie_isresponder(i, bp2))
2844 ND_PRINT((ndo," R"));
2845 else
2846 ND_PRINT((ndo," ?"));
2847 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002848
JP Abgrall53f17a92014-02-12 14:02:41 -08002849 ND_PRINT((ndo," %s", ETYPESTR(base->etype)));
2850 if (base->flags) {
2851 ND_PRINT((ndo,"[%s%s]", base->flags & ISAKMP_FLAG_E ? "E" : "",
2852 base->flags & ISAKMP_FLAG_C ? "C" : ""));
2853 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002854
JP Abgrall53f17a92014-02-12 14:02:41 -08002855 if (ndo->ndo_vflag) {
2856 const struct isakmp_gen *ext;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002857
JP Abgrall53f17a92014-02-12 14:02:41 -08002858 ND_PRINT((ndo,":"));
Elliott Hughes892a68b2015-10-19 14:43:53 -07002859
JP Abgrall53f17a92014-02-12 14:02:41 -08002860 /* regardless of phase... */
2861 if (base->flags & ISAKMP_FLAG_E) {
2862 /*
2863 * encrypted, nothing we can do right now.
2864 * we hope to decrypt the packet in the future...
2865 */
2866 ND_PRINT((ndo," [encrypted %s]", NPSTR(base->np)));
2867 goto done;
2868 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002869
JP Abgrall53f17a92014-02-12 14:02:41 -08002870 CHECKLEN(p + 1, base->np);
2871 np = base->np;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002872 ext = (const struct isakmp_gen *)(p + 1);
JP Abgrall53f17a92014-02-12 14:02:41 -08002873 ikev1_sub_print(ndo, np, ext, ep, phase, 0, 0, 0);
2874 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002875
JP Abgrall53f17a92014-02-12 14:02:41 -08002876done:
2877 if (ndo->ndo_vflag) {
2878 if (ntohl(base->len) != length) {
2879 ND_PRINT((ndo," (len mismatch: isakmp %u/ip %u)",
Elliott Hughes892a68b2015-10-19 14:43:53 -07002880 (uint32_t)ntohl(base->len), length));
JP Abgrall53f17a92014-02-12 14:02:41 -08002881 }
2882 }
2883}
2884
2885static const u_char *
2886ikev2_sub0_print(netdissect_options *ndo, struct isakmp *base,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002887 u_char np,
JP Abgrall53f17a92014-02-12 14:02:41 -08002888 const struct isakmp_gen *ext, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002889 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08002890{
2891 const u_char *cp;
2892 struct isakmp_gen e;
2893 u_int item_len;
2894
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002895 cp = (const u_char *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08002896 ND_TCHECK(*ext);
2897 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2898
2899 /*
2900 * Since we can't have a payload length of less than 4 bytes,
2901 * we need to bail out here if the generic header is nonsensical
2902 * or truncated, otherwise we could loop forever processing
2903 * zero-length items or otherwise misdissect the packet.
2904 */
2905 item_len = ntohs(e.len);
2906 if (item_len <= 4)
2907 return NULL;
2908
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002909 if (np == ISAKMP_NPTYPE_v2E) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002910 cp = ikev2_e_print(ndo, base, np, ext, item_len,
2911 ep, phase, doi, proto, depth);
2912 } else if (NPFUNC(np)) {
2913 /*
2914 * XXX - what if item_len is too short, or too long,
2915 * for this payload type?
2916 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002917 cp = (*npfunc[np])(ndo, np, ext, item_len,
JP Abgrall53f17a92014-02-12 14:02:41 -08002918 ep, phase, doi, proto, depth);
2919 } else {
2920 ND_PRINT((ndo,"%s", NPSTR(np)));
2921 cp += item_len;
2922 }
2923
2924 return cp;
2925trunc:
2926 ND_PRINT((ndo," [|isakmp]"));
2927 return NULL;
2928}
2929
2930static const u_char *
2931ikev2_sub_print(netdissect_options *ndo,
2932 struct isakmp *base,
2933 u_char np, const struct isakmp_gen *ext, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002934 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08002935{
2936 const u_char *cp;
2937 int i;
JP Abgrall53f17a92014-02-12 14:02:41 -08002938 struct isakmp_gen e;
2939
2940 cp = (const u_char *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08002941 while (np) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002942 ND_TCHECK(*ext);
JP Abgrall53f17a92014-02-12 14:02:41 -08002943 UNALIGNED_MEMCPY(&e, ext, sizeof(e));
2944
2945 ND_TCHECK2(*ext, ntohs(e.len));
2946
2947 depth++;
2948 ND_PRINT((ndo,"\n"));
2949 for (i = 0; i < depth; i++)
2950 ND_PRINT((ndo," "));
2951 ND_PRINT((ndo,"("));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002952 cp = ikev2_sub0_print(ndo, base, np,
JP Abgrall53f17a92014-02-12 14:02:41 -08002953 ext, ep, phase, doi, proto, depth);
2954 ND_PRINT((ndo,")"));
2955 depth--;
2956
2957 if (cp == NULL) {
2958 /* Zero-length subitem */
2959 return NULL;
2960 }
2961
2962 np = e.np;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002963 ext = (const struct isakmp_gen *)cp;
JP Abgrall53f17a92014-02-12 14:02:41 -08002964 }
2965 return cp;
2966trunc:
2967 ND_PRINT((ndo," [|%s]", NPSTR(np)));
2968 return NULL;
2969}
2970
2971static void
2972ikev2_print(netdissect_options *ndo,
2973 const u_char *bp, u_int length,
2974 const u_char *bp2 _U_, struct isakmp *base)
2975{
2976 const struct isakmp *p;
2977 const u_char *ep;
2978 u_char np;
2979 int phase;
2980
2981 p = (const struct isakmp *)bp;
2982 ep = ndo->ndo_snapend;
2983
2984 phase = (EXTRACT_32BITS(base->msgid) == 0) ? 1 : 2;
2985 if (phase == 1)
2986 ND_PRINT((ndo, " parent_sa"));
2987 else
2988 ND_PRINT((ndo, " child_sa "));
2989
2990 ND_PRINT((ndo, " %s", ETYPESTR(base->etype)));
2991 if (base->flags) {
2992 ND_PRINT((ndo, "[%s%s%s]",
2993 base->flags & ISAKMP_FLAG_I ? "I" : "",
2994 base->flags & ISAKMP_FLAG_V ? "V" : "",
2995 base->flags & ISAKMP_FLAG_R ? "R" : ""));
2996 }
2997
2998 if (ndo->ndo_vflag) {
2999 const struct isakmp_gen *ext;
3000
3001 ND_PRINT((ndo, ":"));
3002
3003 /* regardless of phase... */
3004 if (base->flags & ISAKMP_FLAG_E) {
3005 /*
3006 * encrypted, nothing we can do right now.
3007 * we hope to decrypt the packet in the future...
3008 */
3009 ND_PRINT((ndo, " [encrypted %s]", NPSTR(base->np)));
3010 goto done;
3011 }
3012
3013 CHECKLEN(p + 1, base->np)
3014
3015 np = base->np;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07003016 ext = (const struct isakmp_gen *)(p + 1);
JP Abgrall53f17a92014-02-12 14:02:41 -08003017 ikev2_sub_print(ndo, base, np, ext, ep, phase, 0, 0, 0);
3018 }
3019
3020done:
3021 if (ndo->ndo_vflag) {
3022 if (ntohl(base->len) != length) {
3023 ND_PRINT((ndo, " (len mismatch: isakmp %u/ip %u)",
Elliott Hughes892a68b2015-10-19 14:43:53 -07003024 (uint32_t)ntohl(base->len), length));
JP Abgrall53f17a92014-02-12 14:02:41 -08003025 }
3026 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08003027}
3028
3029void
3030isakmp_print(netdissect_options *ndo,
3031 const u_char *bp, u_int length,
3032 const u_char *bp2)
3033{
3034 const struct isakmp *p;
3035 struct isakmp base;
3036 const u_char *ep;
The Android Open Source Project2949f582009-03-03 19:30:46 -08003037 int major, minor;
3038
JP Abgrall53f17a92014-02-12 14:02:41 -08003039#ifdef HAVE_LIBCRYPTO
3040 /* initialize SAs */
3041 if (ndo->ndo_sa_list_head == NULL) {
3042 if (ndo->ndo_espsecret)
3043 esp_print_decodesecret(ndo);
3044 }
3045#endif
3046
The Android Open Source Project2949f582009-03-03 19:30:46 -08003047 p = (const struct isakmp *)bp;
3048 ep = ndo->ndo_snapend;
3049
Elliott Hughese2e3bd12017-05-15 10:59:29 -07003050 if ((const struct isakmp *)ep < p + 1) {
JP Abgrall53f17a92014-02-12 14:02:41 -08003051 ND_PRINT((ndo,"[|isakmp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003052 return;
3053 }
3054
JP Abgrall53f17a92014-02-12 14:02:41 -08003055 UNALIGNED_MEMCPY(&base, p, sizeof(base));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003056
JP Abgrall53f17a92014-02-12 14:02:41 -08003057 ND_PRINT((ndo,"isakmp"));
3058 major = (base.vers & ISAKMP_VERS_MAJOR)
3059 >> ISAKMP_VERS_MAJOR_SHIFT;
3060 minor = (base.vers & ISAKMP_VERS_MINOR)
3061 >> ISAKMP_VERS_MINOR_SHIFT;
3062
3063 if (ndo->ndo_vflag) {
3064 ND_PRINT((ndo," %d.%d", major, minor));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003065 }
3066
JP Abgrall53f17a92014-02-12 14:02:41 -08003067 if (ndo->ndo_vflag) {
3068 ND_PRINT((ndo," msgid "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07003069 hexprint(ndo, (const uint8_t *)&base.msgid, sizeof(base.msgid));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003070 }
3071
JP Abgrall53f17a92014-02-12 14:02:41 -08003072 if (1 < ndo->ndo_vflag) {
3073 ND_PRINT((ndo," cookie "));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07003074 hexprint(ndo, (const uint8_t *)&base.i_ck, sizeof(base.i_ck));
JP Abgrall53f17a92014-02-12 14:02:41 -08003075 ND_PRINT((ndo,"->"));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07003076 hexprint(ndo, (const uint8_t *)&base.r_ck, sizeof(base.r_ck));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003077 }
JP Abgrall53f17a92014-02-12 14:02:41 -08003078 ND_PRINT((ndo,":"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003079
JP Abgrall53f17a92014-02-12 14:02:41 -08003080 switch(major) {
3081 case IKEv1_MAJOR_VERSION:
3082 ikev1_print(ndo, bp, length, bp2, &base);
3083 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08003084
JP Abgrall53f17a92014-02-12 14:02:41 -08003085 case IKEv2_MAJOR_VERSION:
3086 ikev2_print(ndo, bp, length, bp2, &base);
3087 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08003088 }
3089}
3090
3091void
3092isakmp_rfc3948_print(netdissect_options *ndo,
3093 const u_char *bp, u_int length,
3094 const u_char *bp2)
3095{
Elliott Hughescec480a2017-12-19 16:54:57 -08003096 ND_TCHECK(bp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -08003097 if(length == 1 && bp[0]==0xff) {
3098 ND_PRINT((ndo, "isakmp-nat-keep-alive"));
3099 return;
3100 }
3101
3102 if(length < 4) {
3103 goto trunc;
3104 }
Elliott Hughescec480a2017-12-19 16:54:57 -08003105 ND_TCHECK(bp[3]);
Elliott Hughes892a68b2015-10-19 14:43:53 -07003106
The Android Open Source Project2949f582009-03-03 19:30:46 -08003107 /*
3108 * see if this is an IKE packet
3109 */
3110 if(bp[0]==0 && bp[1]==0 && bp[2]==0 && bp[3]==0) {
3111 ND_PRINT((ndo, "NONESP-encap: "));
3112 isakmp_print(ndo, bp+4, length-4, bp2);
3113 return;
3114 }
3115
3116 /* must be an ESP packet */
3117 {
3118 int nh, enh, padlen;
3119 int advance;
3120
3121 ND_PRINT((ndo, "UDP-encap: "));
3122
3123 advance = esp_print(ndo, bp, length, bp2, &enh, &padlen);
3124 if(advance <= 0)
3125 return;
3126
3127 bp += advance;
3128 length -= advance + padlen;
3129 nh = enh & 0xff;
Elliott Hughes892a68b2015-10-19 14:43:53 -07003130
The Android Open Source Project2949f582009-03-03 19:30:46 -08003131 ip_print_inner(ndo, bp, length, nh, bp2);
3132 return;
3133 }
3134
3135trunc:
JP Abgrall53f17a92014-02-12 14:02:41 -08003136 ND_PRINT((ndo,"[|isakmp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003137 return;
3138}
3139
3140/*
3141 * Local Variables:
3142 * c-style: whitesmith
3143 * c-basic-offset: 8
3144 * End:
3145 */