blob: 52bf1fda5216d1f50e67120a1c015c4f90b43c06 [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
Elliott Hughes820eced2021-08-20 18:00:50 -070033/* specification: RFC 2407, RFC 2408, RFC 5996 */
34
The Android Open Source Project2949f582009-03-03 19:30:46 -080035#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070036#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080037#endif
38
JP Abgrall53f17a92014-02-12 14:02:41 -080039/* The functions from print-esp.c used in this file are only defined when both
40 * OpenSSL and evp.h are detected. Employ the same preprocessor device here.
41 */
42#ifndef HAVE_OPENSSL_EVP_H
43#undef HAVE_LIBCRYPTO
44#endif
45
Elliott Hughes820eced2021-08-20 18:00:50 -070046#include "netdissect-stdinc.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080047
48#include <string.h>
49
Elliott Hughes820eced2021-08-20 18:00:50 -070050#include "netdissect-ctype.h"
51
Elliott Hughese2e3bd12017-05-15 10:59:29 -070052#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080053#include "addrtoname.h"
Elliott Hughese2e3bd12017-05-15 10:59:29 -070054#include "extract.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080055
56#include "ip.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080057#include "ip6.h"
Elliott Hughescec480a2017-12-19 16:54:57 -080058#include "ipproto.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080059
Elliott Hughes820eced2021-08-20 18:00:50 -070060typedef nd_byte cookie_t[8];
61typedef nd_byte msgid_t[4];
Elliott Hughes892a68b2015-10-19 14:43:53 -070062
63#define PORT_ISAKMP 500
64
65/* 3.1 ISAKMP Header Format (IKEv1 and IKEv2)
66 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
67 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 ! Initiator !
69 ! Cookie !
70 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 ! Responder !
72 ! Cookie !
73 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 ! Next Payload ! MjVer ! MnVer ! Exchange Type ! Flags !
75 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 ! Message ID !
77 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78 ! Length !
79 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80*/
81struct isakmp {
82 cookie_t i_ck; /* Initiator Cookie */
83 cookie_t r_ck; /* Responder Cookie */
Elliott Hughes820eced2021-08-20 18:00:50 -070084 nd_uint8_t np; /* Next Payload Type */
85 nd_uint8_t vers;
Elliott Hughes892a68b2015-10-19 14:43:53 -070086#define ISAKMP_VERS_MAJOR 0xf0
87#define ISAKMP_VERS_MAJOR_SHIFT 4
88#define ISAKMP_VERS_MINOR 0x0f
89#define ISAKMP_VERS_MINOR_SHIFT 0
Elliott Hughes820eced2021-08-20 18:00:50 -070090 nd_uint8_t etype; /* Exchange Type */
91 nd_uint8_t flags; /* Flags */
Elliott Hughes892a68b2015-10-19 14:43:53 -070092 msgid_t msgid;
Elliott Hughes820eced2021-08-20 18:00:50 -070093 nd_uint32_t len; /* Length */
Elliott Hughes892a68b2015-10-19 14:43:53 -070094};
95
96/* Next Payload Type */
97#define ISAKMP_NPTYPE_NONE 0 /* NONE*/
98#define ISAKMP_NPTYPE_SA 1 /* Security Association */
99#define ISAKMP_NPTYPE_P 2 /* Proposal */
100#define ISAKMP_NPTYPE_T 3 /* Transform */
101#define ISAKMP_NPTYPE_KE 4 /* Key Exchange */
102#define ISAKMP_NPTYPE_ID 5 /* Identification */
103#define ISAKMP_NPTYPE_CERT 6 /* Certificate */
104#define ISAKMP_NPTYPE_CR 7 /* Certificate Request */
105#define ISAKMP_NPTYPE_HASH 8 /* Hash */
106#define ISAKMP_NPTYPE_SIG 9 /* Signature */
107#define ISAKMP_NPTYPE_NONCE 10 /* Nonce */
108#define ISAKMP_NPTYPE_N 11 /* Notification */
109#define ISAKMP_NPTYPE_D 12 /* Delete */
110#define ISAKMP_NPTYPE_VID 13 /* Vendor ID */
111#define ISAKMP_NPTYPE_v2E 46 /* v2 Encrypted payload */
112
113#define IKEv1_MAJOR_VERSION 1
114#define IKEv1_MINOR_VERSION 0
115
116#define IKEv2_MAJOR_VERSION 2
117#define IKEv2_MINOR_VERSION 0
118
119/* Flags */
120#define ISAKMP_FLAG_E 0x01 /* Encryption Bit */
121#define ISAKMP_FLAG_C 0x02 /* Commit Bit */
122#define ISAKMP_FLAG_extra 0x04
123
124/* IKEv2 */
125#define ISAKMP_FLAG_I (1 << 3) /* (I)nitiator */
126#define ISAKMP_FLAG_V (1 << 4) /* (V)ersion */
127#define ISAKMP_FLAG_R (1 << 5) /* (R)esponse */
128
129
130/* 3.2 Payload Generic Header
131 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
132 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
133 ! Next Payload ! RESERVED ! Payload Length !
134 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
135*/
136struct isakmp_gen {
Elliott Hughes820eced2021-08-20 18:00:50 -0700137 nd_uint8_t np; /* Next Payload */
138 nd_uint8_t critical; /* bit 7 - critical, rest is RESERVED */
139 nd_uint16_t len; /* Payload Length */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700140};
141
142/* 3.3 Data Attributes
143 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
144 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 !A! Attribute Type ! AF=0 Attribute Length !
146 !F! ! AF=1 Attribute Value !
147 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
148 . AF=0 Attribute Value .
149 . AF=1 Not Transmitted .
150 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
151*/
152struct isakmp_data {
Elliott Hughes820eced2021-08-20 18:00:50 -0700153 nd_uint16_t type; /* defined by DOI-spec, and Attribute Format */
154 nd_uint16_t lorv; /* if f equal 1, Attribute Length */
155 /* if f equal 0, Attribute Value */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700156 /* if f equal 1, Attribute Value */
157};
158
159/* 3.4 Security Association Payload */
160 /* MAY NOT be used, because of being defined in ipsec-doi. */
161 /*
162 If the current payload is the last in the message,
163 then the value of the next payload field will be 0.
164 This field MUST NOT contain the
165 values for the Proposal or Transform payloads as they are considered
166 part of the security association negotiation. For example, this
167 field would contain the value "10" (Nonce payload) in the first
168 message of a Base Exchange (see Section 4.4) and the value "0" in the
169 first message of an Identity Protect Exchange (see Section 4.5).
170 */
171struct ikev1_pl_sa {
172 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700173 nd_uint32_t doi; /* Domain of Interpretation */
174 nd_uint32_t sit; /* Situation */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700175};
176
177/* 3.5 Proposal Payload */
178 /*
179 The value of the next payload field MUST only contain the value "2"
180 or "0". If there are additional Proposal payloads in the message,
181 then this field will be 2. If the current Proposal payload is the
182 last within the security association proposal, then this field will
183 be 0.
184 */
185struct ikev1_pl_p {
186 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700187 nd_uint8_t p_no; /* Proposal # */
188 nd_uint8_t prot_id; /* Protocol */
189 nd_uint8_t spi_size; /* SPI Size */
190 nd_uint8_t num_t; /* Number of Transforms */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700191 /* SPI */
192};
193
194/* 3.6 Transform Payload */
195 /*
196 The value of the next payload field MUST only contain the value "3"
197 or "0". If there are additional Transform payloads in the proposal,
198 then this field will be 3. If the current Transform payload is the
199 last within the proposal, then this field will be 0.
200 */
201struct ikev1_pl_t {
202 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700203 nd_uint8_t t_no; /* Transform # */
204 nd_uint8_t t_id; /* Transform-Id */
205 nd_byte reserved[2]; /* RESERVED2 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700206 /* SA Attributes */
207};
208
209/* 3.7 Key Exchange Payload */
210struct ikev1_pl_ke {
211 struct isakmp_gen h;
212 /* Key Exchange Data */
213};
214
215/* 3.8 Identification Payload */
216 /* MUST NOT to be used, because of being defined in ipsec-doi. */
217struct ikev1_pl_id {
218 struct isakmp_gen h;
219 union {
Elliott Hughes820eced2021-08-20 18:00:50 -0700220 nd_uint8_t id_type; /* ID Type */
221 nd_uint32_t doi_data; /* DOI Specific ID Data */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700222 } d;
223 /* Identification Data */
224};
225
226/* 3.9 Certificate Payload */
227struct ikev1_pl_cert {
228 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700229 nd_uint8_t encode; /* Cert Encoding */
230 nd_uint8_t cert; /* Certificate Data */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700231 /*
232 This field indicates the type of
233 certificate or certificate-related information contained in the
234 Certificate Data field.
235 */
236};
237
238/* 3.10 Certificate Request Payload */
239struct ikev1_pl_cr {
240 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700241 nd_uint8_t num_cert; /* # Cert. Types */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700242 /*
243 Certificate Types (variable length)
244 -- Contains a list of the types of certificates requested,
245 sorted in order of preference. Each individual certificate
246 type is 1 octet. This field is NOT requiredo
247 */
248 /* # Certificate Authorities (1 octet) */
249 /* Certificate Authorities (variable length) */
250};
251
252/* 3.11 Hash Payload */
253 /* may not be used, because of having only data. */
254struct ikev1_pl_hash {
255 struct isakmp_gen h;
256 /* Hash Data */
257};
258
259/* 3.12 Signature Payload */
260 /* may not be used, because of having only data. */
261struct ikev1_pl_sig {
262 struct isakmp_gen h;
263 /* Signature Data */
264};
265
266/* 3.13 Nonce Payload */
267 /* may not be used, because of having only data. */
268struct ikev1_pl_nonce {
269 struct isakmp_gen h;
270 /* Nonce Data */
271};
272
273/* 3.14 Notification Payload */
274struct ikev1_pl_n {
275 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700276 nd_uint32_t doi; /* Domain of Interpretation */
277 nd_uint8_t prot_id; /* Protocol-ID */
278 nd_uint8_t spi_size; /* SPI Size */
279 nd_uint16_t type; /* Notify Message Type */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700280 /* SPI */
281 /* Notification Data */
282};
283
284/* 3.14.1 Notify Message Types */
285/* NOTIFY MESSAGES - ERROR TYPES */
286#define ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE 1
287#define ISAKMP_NTYPE_DOI_NOT_SUPPORTED 2
288#define ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED 3
289#define ISAKMP_NTYPE_INVALID_COOKIE 4
290#define ISAKMP_NTYPE_INVALID_MAJOR_VERSION 5
291#define ISAKMP_NTYPE_INVALID_MINOR_VERSION 6
292#define ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE 7
293#define ISAKMP_NTYPE_INVALID_FLAGS 8
294#define ISAKMP_NTYPE_INVALID_MESSAGE_ID 9
295#define ISAKMP_NTYPE_INVALID_PROTOCOL_ID 10
296#define ISAKMP_NTYPE_INVALID_SPI 11
297#define ISAKMP_NTYPE_INVALID_TRANSFORM_ID 12
298#define ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED 13
299#define ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN 14
300#define ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX 15
301#define ISAKMP_NTYPE_PAYLOAD_MALFORMED 16
302#define ISAKMP_NTYPE_INVALID_KEY_INFORMATION 17
303#define ISAKMP_NTYPE_INVALID_ID_INFORMATION 18
304#define ISAKMP_NTYPE_INVALID_CERT_ENCODING 19
305#define ISAKMP_NTYPE_INVALID_CERTIFICATE 20
306#define ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX 21
307#define ISAKMP_NTYPE_INVALID_CERT_AUTHORITY 22
308#define ISAKMP_NTYPE_INVALID_HASH_INFORMATION 23
309#define ISAKMP_NTYPE_AUTHENTICATION_FAILED 24
310#define ISAKMP_NTYPE_INVALID_SIGNATURE 25
311#define ISAKMP_NTYPE_ADDRESS_NOTIFICATION 26
312
313/* 3.15 Delete Payload */
314struct ikev1_pl_d {
315 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700316 nd_uint32_t doi; /* Domain of Interpretation */
317 nd_uint8_t prot_id; /* Protocol-Id */
318 nd_uint8_t spi_size; /* SPI Size */
319 nd_uint16_t num_spi; /* # of SPIs */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700320 /* SPI(es) */
321};
322
Elliott Hughes892a68b2015-10-19 14:43:53 -0700323/* IKEv2 (RFC4306) */
324
325/* 3.3 Security Association Payload -- generic header */
326/* 3.3.1. Proposal Substructure */
327struct ikev2_p {
328 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700329 nd_uint8_t p_no; /* Proposal # */
330 nd_uint8_t prot_id; /* Protocol */
331 nd_uint8_t spi_size; /* SPI Size */
332 nd_uint8_t num_t; /* Number of Transforms */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700333};
334
335/* 3.3.2. Transform Substructure */
336struct ikev2_t {
337 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700338 nd_uint8_t t_type; /* Transform Type (ENCR,PRF,INTEG,etc.*/
339 nd_byte res2; /* reserved byte */
340 nd_uint16_t t_id; /* Transform ID */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700341};
342
343enum ikev2_t_type {
344 IV2_T_ENCR = 1,
345 IV2_T_PRF = 2,
346 IV2_T_INTEG= 3,
347 IV2_T_DH = 4,
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700348 IV2_T_ESN = 5
Elliott Hughes892a68b2015-10-19 14:43:53 -0700349};
350
351/* 3.4. Key Exchange Payload */
352struct ikev2_ke {
353 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700354 nd_uint16_t ke_group;
355 nd_uint16_t ke_res1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700356 /* KE data */
357};
358
359
360/* 3.5. Identification Payloads */
361enum ikev2_id_type {
362 ID_IPV4_ADDR=1,
363 ID_FQDN=2,
364 ID_RFC822_ADDR=3,
365 ID_IPV6_ADDR=5,
366 ID_DER_ASN1_DN=9,
367 ID_DER_ASN1_GN=10,
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700368 ID_KEY_ID=11
Elliott Hughes892a68b2015-10-19 14:43:53 -0700369};
370struct ikev2_id {
371 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700372 nd_uint8_t type; /* ID type */
373 nd_byte res1;
374 nd_byte res2[2];
Elliott Hughes892a68b2015-10-19 14:43:53 -0700375 /* SPI */
376 /* Notification Data */
377};
378
379/* 3.10 Notification Payload */
380struct ikev2_n {
381 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700382 nd_uint8_t prot_id; /* Protocol-ID */
383 nd_uint8_t spi_size; /* SPI Size */
384 nd_uint16_t type; /* Notify Message Type */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700385};
386
387enum ikev2_n_type {
388 IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD = 1,
389 IV2_NOTIFY_INVALID_IKE_SPI = 4,
390 IV2_NOTIFY_INVALID_MAJOR_VERSION = 5,
391 IV2_NOTIFY_INVALID_SYNTAX = 7,
392 IV2_NOTIFY_INVALID_MESSAGE_ID = 9,
393 IV2_NOTIFY_INVALID_SPI =11,
394 IV2_NOTIFY_NO_PROPOSAL_CHOSEN =14,
395 IV2_NOTIFY_INVALID_KE_PAYLOAD =17,
396 IV2_NOTIFY_AUTHENTICATION_FAILED =24,
397 IV2_NOTIFY_SINGLE_PAIR_REQUIRED =34,
398 IV2_NOTIFY_NO_ADDITIONAL_SAS =35,
399 IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE =36,
400 IV2_NOTIFY_FAILED_CP_REQUIRED =37,
401 IV2_NOTIFY_INVALID_SELECTORS =39,
402 IV2_NOTIFY_INITIAL_CONTACT =16384,
403 IV2_NOTIFY_SET_WINDOW_SIZE =16385,
404 IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE =16386,
405 IV2_NOTIFY_IPCOMP_SUPPORTED =16387,
406 IV2_NOTIFY_NAT_DETECTION_SOURCE_IP =16388,
407 IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP =16389,
408 IV2_NOTIFY_COOKIE =16390,
409 IV2_NOTIFY_USE_TRANSPORT_MODE =16391,
410 IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED =16392,
411 IV2_NOTIFY_REKEY_SA =16393,
412 IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED =16394,
413 IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO =16395
414};
415
416struct notify_messages {
417 uint16_t type;
418 char *msg;
419};
420
Elliott Hughescec480a2017-12-19 16:54:57 -0800421/* 3.8 Authentication Payload */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700422struct ikev2_auth {
423 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700424 nd_uint8_t auth_method; /* Protocol-ID */
425 nd_byte reserved[3];
Elliott Hughes892a68b2015-10-19 14:43:53 -0700426 /* authentication data */
427};
428
429enum ikev2_auth_type {
430 IV2_RSA_SIG = 1,
431 IV2_SHARED = 2,
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700432 IV2_DSS_SIG = 3
Elliott Hughes892a68b2015-10-19 14:43:53 -0700433};
434
435/* refer to RFC 2409 */
436
437#if 0
438/* isakmp sa structure */
439struct oakley_sa {
440 uint8_t proto_id; /* OAKLEY */
441 vchar_t *spi; /* spi */
442 uint8_t dhgrp; /* DH; group */
443 uint8_t auth_t; /* method of authentication */
444 uint8_t prf_t; /* type of prf */
445 uint8_t hash_t; /* type of hash */
446 uint8_t enc_t; /* type of cipher */
447 uint8_t life_t; /* type of duration of lifetime */
448 uint32_t ldur; /* life duration */
449};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800450#endif
451
Elliott Hughes892a68b2015-10-19 14:43:53 -0700452/* refer to RFC 2407 */
453
454#define IPSEC_DOI 1
455
456/* 4.2 IPSEC Situation Definition */
457#define IPSECDOI_SIT_IDENTITY_ONLY 0x00000001
458#define IPSECDOI_SIT_SECRECY 0x00000002
459#define IPSECDOI_SIT_INTEGRITY 0x00000004
460
461/* 4.4.1 IPSEC Security Protocol Identifiers */
462 /* 4.4.2 IPSEC ISAKMP Transform Values */
463#define IPSECDOI_PROTO_ISAKMP 1
464#define IPSECDOI_KEY_IKE 1
465
466/* 4.4.1 IPSEC Security Protocol Identifiers */
467#define IPSECDOI_PROTO_IPSEC_AH 2
468 /* 4.4.3 IPSEC AH Transform Values */
469#define IPSECDOI_AH_MD5 2
470#define IPSECDOI_AH_SHA 3
471#define IPSECDOI_AH_DES 4
472#define IPSECDOI_AH_SHA2_256 5
473#define IPSECDOI_AH_SHA2_384 6
474#define IPSECDOI_AH_SHA2_512 7
475
476/* 4.4.1 IPSEC Security Protocol Identifiers */
477#define IPSECDOI_PROTO_IPSEC_ESP 3
478 /* 4.4.4 IPSEC ESP Transform Identifiers */
479#define IPSECDOI_ESP_DES_IV64 1
480#define IPSECDOI_ESP_DES 2
481#define IPSECDOI_ESP_3DES 3
482#define IPSECDOI_ESP_RC5 4
483#define IPSECDOI_ESP_IDEA 5
484#define IPSECDOI_ESP_CAST 6
485#define IPSECDOI_ESP_BLOWFISH 7
486#define IPSECDOI_ESP_3IDEA 8
487#define IPSECDOI_ESP_DES_IV32 9
488#define IPSECDOI_ESP_RC4 10
489#define IPSECDOI_ESP_NULL 11
490#define IPSECDOI_ESP_RIJNDAEL 12
491#define IPSECDOI_ESP_AES 12
492
493/* 4.4.1 IPSEC Security Protocol Identifiers */
494#define IPSECDOI_PROTO_IPCOMP 4
495 /* 4.4.5 IPSEC IPCOMP Transform Identifiers */
496#define IPSECDOI_IPCOMP_OUI 1
497#define IPSECDOI_IPCOMP_DEFLATE 2
498#define IPSECDOI_IPCOMP_LZS 3
499
500/* 4.5 IPSEC Security Association Attributes */
501#define IPSECDOI_ATTR_SA_LTYPE 1 /* B */
502#define IPSECDOI_ATTR_SA_LTYPE_DEFAULT 1
503#define IPSECDOI_ATTR_SA_LTYPE_SEC 1
504#define IPSECDOI_ATTR_SA_LTYPE_KB 2
505#define IPSECDOI_ATTR_SA_LDUR 2 /* V */
506#define IPSECDOI_ATTR_SA_LDUR_DEFAULT 28800 /* 8 hours */
507#define IPSECDOI_ATTR_GRP_DESC 3 /* B */
508#define IPSECDOI_ATTR_ENC_MODE 4 /* B */
509 /* default value: host dependent */
510#define IPSECDOI_ATTR_ENC_MODE_TUNNEL 1
511#define IPSECDOI_ATTR_ENC_MODE_TRNS 2
512#define IPSECDOI_ATTR_AUTH 5 /* B */
513 /* 0 means not to use authentication. */
514#define IPSECDOI_ATTR_AUTH_HMAC_MD5 1
515#define IPSECDOI_ATTR_AUTH_HMAC_SHA1 2
516#define IPSECDOI_ATTR_AUTH_DES_MAC 3
517#define IPSECDOI_ATTR_AUTH_KPDK 4 /*RFC-1826(Key/Pad/Data/Key)*/
518 /*
519 * When negotiating ESP without authentication, the Auth
520 * Algorithm attribute MUST NOT be included in the proposal.
521 * When negotiating ESP without confidentiality, the Auth
522 * Algorithm attribute MUST be included in the proposal and
523 * the ESP transform ID must be ESP_NULL.
524 */
525#define IPSECDOI_ATTR_KEY_LENGTH 6 /* B */
526#define IPSECDOI_ATTR_KEY_ROUNDS 7 /* B */
527#define IPSECDOI_ATTR_COMP_DICT_SIZE 8 /* B */
528#define IPSECDOI_ATTR_COMP_PRIVALG 9 /* V */
529
530/* 4.6.1 Security Association Payload */
531struct ipsecdoi_sa {
532 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700533 nd_uint32_t doi; /* Domain of Interpretation */
534 nd_uint32_t sit; /* Situation */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700535};
536
537struct ipsecdoi_secrecy_h {
Elliott Hughes820eced2021-08-20 18:00:50 -0700538 nd_uint16_t len;
539 nd_uint16_t reserved;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700540};
541
542/* 4.6.2.1 Identification Type Values */
543struct ipsecdoi_id {
544 struct isakmp_gen h;
Elliott Hughes820eced2021-08-20 18:00:50 -0700545 nd_uint8_t type; /* ID Type */
546 nd_uint8_t proto_id; /* Protocol ID */
547 nd_uint16_t port; /* Port */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700548 /* Identification Data */
549};
550
551#define IPSECDOI_ID_IPV4_ADDR 1
552#define IPSECDOI_ID_FQDN 2
553#define IPSECDOI_ID_USER_FQDN 3
554#define IPSECDOI_ID_IPV4_ADDR_SUBNET 4
555#define IPSECDOI_ID_IPV6_ADDR 5
556#define IPSECDOI_ID_IPV6_ADDR_SUBNET 6
557#define IPSECDOI_ID_IPV4_ADDR_RANGE 7
558#define IPSECDOI_ID_IPV6_ADDR_RANGE 8
559#define IPSECDOI_ID_DER_ASN1_DN 9
560#define IPSECDOI_ID_DER_ASN1_GN 10
561#define IPSECDOI_ID_KEY_ID 11
562
563/* 4.6.3 IPSEC DOI Notify Message Types */
564/* Notify Messages - Status Types */
565#define IPSECDOI_NTYPE_RESPONDER_LIFETIME 24576
566#define IPSECDOI_NTYPE_REPLAY_STATUS 24577
567#define IPSECDOI_NTYPE_INITIAL_CONTACT 24578
568
JP Abgrall53f17a92014-02-12 14:02:41 -0800569#define DECLARE_PRINTER(func) static const u_char *ike##func##_print( \
570 netdissect_options *ndo, u_char tpay, \
571 const struct isakmp_gen *ext, \
572 u_int item_len, \
573 const u_char *end_pointer, \
Elliott Hughes892a68b2015-10-19 14:43:53 -0700574 uint32_t phase,\
575 uint32_t doi0, \
576 uint32_t proto0, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -0800577
578DECLARE_PRINTER(v1_sa);
579DECLARE_PRINTER(v1_p);
580DECLARE_PRINTER(v1_t);
581DECLARE_PRINTER(v1_ke);
582DECLARE_PRINTER(v1_id);
583DECLARE_PRINTER(v1_cert);
584DECLARE_PRINTER(v1_cr);
585DECLARE_PRINTER(v1_sig);
586DECLARE_PRINTER(v1_hash);
587DECLARE_PRINTER(v1_nonce);
588DECLARE_PRINTER(v1_n);
589DECLARE_PRINTER(v1_d);
590DECLARE_PRINTER(v1_vid);
591
592DECLARE_PRINTER(v2_sa);
593DECLARE_PRINTER(v2_ke);
594DECLARE_PRINTER(v2_ID);
595DECLARE_PRINTER(v2_cert);
596DECLARE_PRINTER(v2_cr);
597DECLARE_PRINTER(v2_auth);
598DECLARE_PRINTER(v2_nonce);
599DECLARE_PRINTER(v2_n);
600DECLARE_PRINTER(v2_d);
601DECLARE_PRINTER(v2_vid);
602DECLARE_PRINTER(v2_TS);
603DECLARE_PRINTER(v2_cp);
604DECLARE_PRINTER(v2_eap);
605
606static const u_char *ikev2_e_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700607 const struct isakmp *base,
JP Abgrall53f17a92014-02-12 14:02:41 -0800608 u_char tpay,
609 const struct isakmp_gen *ext,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700610 u_int item_len,
611 const u_char *end_pointer,
612 uint32_t phase,
613 uint32_t doi0,
614 uint32_t proto0, int depth);
JP Abgrall53f17a92014-02-12 14:02:41 -0800615
616
617static const u_char *ike_sub0_print(netdissect_options *ndo,u_char, const struct isakmp_gen *,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700618 const u_char *, uint32_t, uint32_t, uint32_t, int);
JP Abgrall53f17a92014-02-12 14:02:41 -0800619static const u_char *ikev1_sub_print(netdissect_options *ndo,u_char, const struct isakmp_gen *,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700620 const u_char *, uint32_t, uint32_t, uint32_t, int);
JP Abgrall53f17a92014-02-12 14:02:41 -0800621
622static const u_char *ikev2_sub_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700623 const struct isakmp *base,
JP Abgrall53f17a92014-02-12 14:02:41 -0800624 u_char np, const struct isakmp_gen *ext,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700625 const u_char *ep, uint32_t phase,
626 uint32_t doi, uint32_t proto,
JP Abgrall53f17a92014-02-12 14:02:41 -0800627 int depth);
628
629
Elliott Hughes820eced2021-08-20 18:00:50 -0700630static char *numstr(u_int);
JP Abgrall53f17a92014-02-12 14:02:41 -0800631
632static void
633ikev1_print(netdissect_options *ndo,
634 const u_char *bp, u_int length,
Elliott Hughes820eced2021-08-20 18:00:50 -0700635 const u_char *bp2, const struct isakmp *base);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800636
637#define MAXINITIATORS 20
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700638static int ninitiator = 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700639union inaddr_u {
Elliott Hughes820eced2021-08-20 18:00:50 -0700640 nd_ipv4 in4;
641 nd_ipv6 in6;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700642};
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700643static struct {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800644 cookie_t initiator;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700645 u_int version;
646 union inaddr_u iaddr;
647 union inaddr_u raddr;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800648} cookiecache[MAXINITIATORS];
649
650/* protocol id */
651static const char *protoidstr[] = {
652 NULL, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp",
653};
654
655/* isakmp->np */
656static const char *npstr[] = {
JP Abgrall53f17a92014-02-12 14:02:41 -0800657 "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash", /* 0 - 8 */
658 "sig", "nonce", "n", "d", "vid", /* 9 - 13 */
659 "pay14", "pay15", "pay16", "pay17", "pay18", /* 14- 18 */
660 "pay19", "pay20", "pay21", "pay22", "pay23", /* 19- 23 */
661 "pay24", "pay25", "pay26", "pay27", "pay28", /* 24- 28 */
662 "pay29", "pay30", "pay31", "pay32", /* 29- 32 */
663 "v2sa", "v2ke", "v2IDi", "v2IDr", "v2cert",/* 33- 37 */
664 "v2cr", "v2auth","v2nonce", "v2n", "v2d", /* 38- 42 */
665 "v2vid", "v2TSi", "v2TSr", "v2e", "v2cp", /* 43- 47 */
666 "v2eap", /* 48 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700667
The Android Open Source Project2949f582009-03-03 19:30:46 -0800668};
669
670/* isakmp->np */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700671static const u_char *(*npfunc[])(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -0800672 const struct isakmp_gen *ext,
673 u_int item_len,
674 const u_char *end_pointer,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700675 uint32_t phase,
676 uint32_t doi0,
677 uint32_t proto0, int depth) = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800678 NULL,
JP Abgrall53f17a92014-02-12 14:02:41 -0800679 ikev1_sa_print,
680 ikev1_p_print,
681 ikev1_t_print,
682 ikev1_ke_print,
683 ikev1_id_print,
684 ikev1_cert_print,
685 ikev1_cr_print,
686 ikev1_hash_print,
687 ikev1_sig_print,
688 ikev1_nonce_print,
689 ikev1_n_print,
690 ikev1_d_print,
691 ikev1_vid_print, /* 13 */
692 NULL, NULL, NULL, NULL, NULL, /* 14- 18 */
693 NULL, NULL, NULL, NULL, NULL, /* 19- 23 */
694 NULL, NULL, NULL, NULL, NULL, /* 24- 28 */
695 NULL, NULL, NULL, NULL, /* 29- 32 */
696 ikev2_sa_print, /* 33 */
697 ikev2_ke_print, /* 34 */
698 ikev2_ID_print, /* 35 */
699 ikev2_ID_print, /* 36 */
700 ikev2_cert_print, /* 37 */
701 ikev2_cr_print, /* 38 */
702 ikev2_auth_print, /* 39 */
703 ikev2_nonce_print, /* 40 */
704 ikev2_n_print, /* 41 */
705 ikev2_d_print, /* 42 */
706 ikev2_vid_print, /* 43 */
707 ikev2_TS_print, /* 44 */
708 ikev2_TS_print, /* 45 */
709 NULL, /* ikev2_e_print,*/ /* 46 - special */
710 ikev2_cp_print, /* 47 */
711 ikev2_eap_print, /* 48 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800712};
713
714/* isakmp->etype */
715static const char *etypestr[] = {
JP Abgrall53f17a92014-02-12 14:02:41 -0800716/* IKEv1 exchange types */
717 "none", "base", "ident", "auth", "agg", "inf", NULL, NULL, /* 0-7 */
718 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 8-15 */
719 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 16-23 */
720 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 24-31 */
721 "oakley-quick", "oakley-newgroup", /* 32-33 */
722/* IKEv2 exchange types */
723 "ikev2_init", "ikev2_auth", "child_sa", "inf2" /* 34-37 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800724};
725
726#define STR_OR_ID(x, tab) \
727 (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x))
728#define PROTOIDSTR(x) STR_OR_ID(x, protoidstr)
729#define NPSTR(x) STR_OR_ID(x, npstr)
730#define ETYPESTR(x) STR_OR_ID(x, etypestr)
731
JP Abgrall53f17a92014-02-12 14:02:41 -0800732#define CHECKLEN(p, np) \
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700733 if (ep < (const u_char *)(p)) { \
Elliott Hughes820eced2021-08-20 18:00:50 -0700734 ND_PRINT(" [|%s]", NPSTR(np)); \
JP Abgrall53f17a92014-02-12 14:02:41 -0800735 goto done; \
736 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700737
JP Abgrall53f17a92014-02-12 14:02:41 -0800738
The Android Open Source Project2949f582009-03-03 19:30:46 -0800739#define NPFUNC(x) \
740 (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \
741 ? npfunc[(x)] : NULL)
742
743static int
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700744iszero(const u_char *p, size_t l)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800745{
Elliott Hughes820eced2021-08-20 18:00:50 -0700746 while (l != 0) {
747 if (*p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800748 return 0;
Elliott Hughes820eced2021-08-20 18:00:50 -0700749 p++;
750 l--;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800751 }
752 return 1;
753}
754
755/* find cookie from initiator cache */
756static int
Elliott Hughes820eced2021-08-20 18:00:50 -0700757cookie_find(const cookie_t *in)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800758{
759 int i;
760
761 for (i = 0; i < MAXINITIATORS; i++) {
762 if (memcmp(in, &cookiecache[i].initiator, sizeof(*in)) == 0)
763 return i;
764 }
765
766 return -1;
767}
768
769/* record initiator */
770static void
Elliott Hughes820eced2021-08-20 18:00:50 -0700771cookie_record(netdissect_options *ndo, const cookie_t *in, const u_char *bp2)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800772{
773 int i;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700774 const struct ip *ip;
775 const struct ip6_hdr *ip6;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800776
777 i = cookie_find(in);
778 if (0 <= i) {
779 ninitiator = (i + 1) % MAXINITIATORS;
780 return;
781 }
782
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700783 ip = (const struct ip *)bp2;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800784 switch (IP_V(ip)) {
785 case 4:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700786 cookiecache[ninitiator].version = 4;
Elliott Hughes820eced2021-08-20 18:00:50 -0700787 UNALIGNED_MEMCPY(&cookiecache[ninitiator].iaddr.in4,
788 ip->ip_src, sizeof(nd_ipv4));
789 UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in4,
790 ip->ip_dst, sizeof(nd_ipv4));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800791 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800792 case 6:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700793 ip6 = (const struct ip6_hdr *)bp2;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700794 cookiecache[ninitiator].version = 6;
Elliott Hughes820eced2021-08-20 18:00:50 -0700795 UNALIGNED_MEMCPY(&cookiecache[ninitiator].iaddr.in6,
796 ip6->ip6_src, sizeof(nd_ipv6));
797 UNALIGNED_MEMCPY(&cookiecache[ninitiator].raddr.in6,
798 ip6->ip6_dst, sizeof(nd_ipv6));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800799 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800800 default:
801 return;
802 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800803 UNALIGNED_MEMCPY(&cookiecache[ninitiator].initiator, in, sizeof(*in));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800804 ninitiator = (ninitiator + 1) % MAXINITIATORS;
805}
806
Elliott Hughes820eced2021-08-20 18:00:50 -0700807#define cookie_isinitiator(ndo, x, y) cookie_sidecheck(ndo, (x), (y), 1)
808#define cookie_isresponder(ndo, x, y) cookie_sidecheck(ndo, (x), (y), 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800809static int
Elliott Hughes820eced2021-08-20 18:00:50 -0700810cookie_sidecheck(netdissect_options *ndo, int i, const u_char *bp2, int initiator)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800811{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700812 const struct ip *ip;
813 const struct ip6_hdr *ip6;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800814
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700815 ip = (const struct ip *)bp2;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800816 switch (IP_V(ip)) {
817 case 4:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700818 if (cookiecache[i].version != 4)
819 return 0;
820 if (initiator) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700821 if (UNALIGNED_MEMCMP(ip->ip_src, &cookiecache[i].iaddr.in4, sizeof(nd_ipv4)) == 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700822 return 1;
823 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700824 if (UNALIGNED_MEMCMP(ip->ip_src, &cookiecache[i].raddr.in4, sizeof(nd_ipv4)) == 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700825 return 1;
826 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800827 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800828 case 6:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700829 if (cookiecache[i].version != 6)
830 return 0;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700831 ip6 = (const struct ip6_hdr *)bp2;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700832 if (initiator) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700833 if (UNALIGNED_MEMCMP(ip6->ip6_src, &cookiecache[i].iaddr.in6, sizeof(nd_ipv6)) == 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700834 return 1;
835 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700836 if (UNALIGNED_MEMCMP(ip6->ip6_src, &cookiecache[i].raddr.in6, sizeof(nd_ipv6)) == 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700837 return 1;
838 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800839 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800840 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700841 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800842 }
843
The Android Open Source Project2949f582009-03-03 19:30:46 -0800844 return 0;
845}
846
JP Abgrall53f17a92014-02-12 14:02:41 -0800847static void
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700848hexprint(netdissect_options *ndo, const uint8_t *loc, size_t len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800849{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700850 const uint8_t *p;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800851 size_t i;
852
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700853 p = loc;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800854 for (i = 0; i < len; i++)
Elliott Hughes820eced2021-08-20 18:00:50 -0700855 ND_PRINT("%02x", p[i] & 0xff);
JP Abgrall53f17a92014-02-12 14:02:41 -0800856}
857
858static int
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700859rawprint(netdissect_options *ndo, const uint8_t *loc, size_t len)
JP Abgrall53f17a92014-02-12 14:02:41 -0800860{
Elliott Hughes820eced2021-08-20 18:00:50 -0700861 ND_TCHECK_LEN(loc, len);
JP Abgrall53f17a92014-02-12 14:02:41 -0800862
863 hexprint(ndo, loc, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800864 return 1;
865trunc:
866 return 0;
867}
868
JP Abgrall53f17a92014-02-12 14:02:41 -0800869
870/*
871 * returns false if we run out of data buffer
872 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700873static int ike_show_somedata(netdissect_options *ndo,
JP Abgrall53f17a92014-02-12 14:02:41 -0800874 const u_char *cp, const u_char *ep)
875{
876 /* there is too much data, just show some of it */
877 const u_char *end = ep - 20;
Elliott Hughes820eced2021-08-20 18:00:50 -0700878 size_t elen = 20;
879 size_t len = ep - cp;
JP Abgrall53f17a92014-02-12 14:02:41 -0800880 if(len > 10) {
881 len = 10;
882 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700883
JP Abgrall53f17a92014-02-12 14:02:41 -0800884 /* really shouldn't happen because of above */
885 if(end < cp + len) {
886 end = cp+len;
887 elen = ep - end;
888 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700889
Elliott Hughes820eced2021-08-20 18:00:50 -0700890 ND_PRINT(" data=(");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700891 if(!rawprint(ndo, (const uint8_t *)(cp), len)) goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700892 ND_PRINT("...");
JP Abgrall53f17a92014-02-12 14:02:41 -0800893 if(elen) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700894 if(!rawprint(ndo, (const uint8_t *)(end), elen)) goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -0800895 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700896 ND_PRINT(")");
JP Abgrall53f17a92014-02-12 14:02:41 -0800897 return 1;
898
899trunc:
900 return 0;
901}
902
The Android Open Source Project2949f582009-03-03 19:30:46 -0800903struct attrmap {
904 const char *type;
905 u_int nvalue;
906 const char *value[30]; /*XXX*/
907};
908
909static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -0800910ikev1_attrmap_print(netdissect_options *ndo,
Elliott Hughescec480a2017-12-19 16:54:57 -0800911 const u_char *p, const u_char *ep2,
JP Abgrall53f17a92014-02-12 14:02:41 -0800912 const struct attrmap *map, size_t nmap)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800913{
Elliott Hughes820eced2021-08-20 18:00:50 -0700914 u_int totlen;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700915 uint32_t t, v;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800916
Elliott Hughes820eced2021-08-20 18:00:50 -0700917 if (GET_U_1(p) & 0x80)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800918 totlen = 4;
Elliott Hughescec480a2017-12-19 16:54:57 -0800919 else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700920 totlen = 4 + GET_BE_U_2(p + 2);
Elliott Hughescec480a2017-12-19 16:54:57 -0800921 }
922 if (ep2 < p + totlen) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700923 ND_PRINT("[|attr]");
Elliott Hughescec480a2017-12-19 16:54:57 -0800924 return ep2 + 1;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800925 }
926
Elliott Hughes820eced2021-08-20 18:00:50 -0700927 ND_PRINT("(");
928 t = GET_BE_U_2(p) & 0x7fff;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800929 if (map && t < nmap && map[t].type)
Elliott Hughes820eced2021-08-20 18:00:50 -0700930 ND_PRINT("type=%s ", map[t].type);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800931 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700932 ND_PRINT("type=#%u ", t);
933 if (GET_U_1(p) & 0x80) {
934 ND_PRINT("value=");
935 v = GET_BE_U_2(p + 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800936 if (map && t < nmap && v < map[t].nvalue && map[t].value[v])
Elliott Hughes820eced2021-08-20 18:00:50 -0700937 ND_PRINT("%s", map[t].value[v]);
Elliott Hughescec480a2017-12-19 16:54:57 -0800938 else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700939 if (!rawprint(ndo, (const uint8_t *)(p + 2), 2)) {
940 ND_PRINT(")");
Elliott Hughescec480a2017-12-19 16:54:57 -0800941 goto trunc;
942 }
943 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800944 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700945 ND_PRINT("len=%u value=", totlen - 4);
946 if (!rawprint(ndo, (const uint8_t *)(p + 4), totlen - 4)) {
947 ND_PRINT(")");
Elliott Hughescec480a2017-12-19 16:54:57 -0800948 goto trunc;
949 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800950 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700951 ND_PRINT(")");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800952 return p + totlen;
Elliott Hughescec480a2017-12-19 16:54:57 -0800953
954trunc:
955 return NULL;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800956}
957
958static const u_char *
Elliott Hughescec480a2017-12-19 16:54:57 -0800959ikev1_attr_print(netdissect_options *ndo, const u_char *p, const u_char *ep2)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800960{
Elliott Hughes820eced2021-08-20 18:00:50 -0700961 u_int totlen;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700962 uint32_t t;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800963
Elliott Hughes820eced2021-08-20 18:00:50 -0700964 if (GET_U_1(p) & 0x80)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800965 totlen = 4;
Elliott Hughescec480a2017-12-19 16:54:57 -0800966 else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700967 totlen = 4 + GET_BE_U_2(p + 2);
Elliott Hughescec480a2017-12-19 16:54:57 -0800968 }
969 if (ep2 < p + totlen) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700970 ND_PRINT("[|attr]");
Elliott Hughescec480a2017-12-19 16:54:57 -0800971 return ep2 + 1;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800972 }
973
Elliott Hughes820eced2021-08-20 18:00:50 -0700974 ND_PRINT("(");
975 t = GET_BE_U_2(p) & 0x7fff;
976 ND_PRINT("type=#%u ", t);
977 if (GET_U_1(p) & 0x80) {
978 ND_PRINT("value=");
979 t = GET_U_1(p + 2);
980 if (!rawprint(ndo, (const uint8_t *)(p + 2), 2)) {
981 ND_PRINT(")");
Elliott Hughescec480a2017-12-19 16:54:57 -0800982 goto trunc;
983 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800984 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700985 ND_PRINT("len=%u value=", totlen - 4);
986 if (!rawprint(ndo, (const uint8_t *)(p + 4), totlen - 4)) {
987 ND_PRINT(")");
Elliott Hughescec480a2017-12-19 16:54:57 -0800988 goto trunc;
989 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800990 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700991 ND_PRINT(")");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800992 return p + totlen;
Elliott Hughescec480a2017-12-19 16:54:57 -0800993
994trunc:
995 return NULL;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800996}
997
998static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -0800999ikev1_sa_print(netdissect_options *ndo, u_char tpay _U_,
1000 const struct isakmp_gen *ext,
The Android Open Source Project2949f582009-03-03 19:30:46 -08001001 u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001002 const u_char *ep, uint32_t phase, uint32_t doi0 _U_,
1003 uint32_t proto0, int depth)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001004{
JP Abgrall53f17a92014-02-12 14:02:41 -08001005 const struct ikev1_pl_sa *p;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001006 uint32_t doi, sit, ident;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001007 const u_char *cp, *np;
1008 int t;
1009
Elliott Hughes820eced2021-08-20 18:00:50 -07001010 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_SA));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001011
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001012 p = (const struct ikev1_pl_sa *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07001013 ND_TCHECK_SIZE(p);
1014 doi = GET_BE_U_4(p->doi);
1015 sit = GET_BE_U_4(p->sit);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001016 if (doi != 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001017 ND_PRINT(" doi=%u", doi);
1018 ND_PRINT(" situation=%u", sit);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001019 return (const u_char *)(p + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001020 }
1021
Elliott Hughes820eced2021-08-20 18:00:50 -07001022 ND_PRINT(" doi=ipsec");
1023 ND_PRINT(" situation=");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001024 t = 0;
1025 if (sit & 0x01) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001026 ND_PRINT("identity");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001027 t++;
1028 }
1029 if (sit & 0x02) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001030 ND_PRINT("%ssecrecy", t ? "+" : "");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001031 t++;
1032 }
1033 if (sit & 0x04)
Elliott Hughes820eced2021-08-20 18:00:50 -07001034 ND_PRINT("%sintegrity", t ? "+" : "");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001035
Elliott Hughes820eced2021-08-20 18:00:50 -07001036 np = (const u_char *)ext + sizeof(struct ikev1_pl_sa);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001037 if (sit != 0x01) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001038 ident = GET_BE_U_4(ext + 1);
1039 ND_PRINT(" ident=%u", ident);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001040 np += sizeof(ident);
1041 }
1042
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001043 ext = (const struct isakmp_gen *)np;
Elliott Hughes820eced2021-08-20 18:00:50 -07001044 ND_TCHECK_SIZE(ext);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001045
JP Abgrall53f17a92014-02-12 14:02:41 -08001046 cp = ikev1_sub_print(ndo, ISAKMP_NPTYPE_P, ext, ep, phase, doi, proto0,
The Android Open Source Project2949f582009-03-03 19:30:46 -08001047 depth);
1048
1049 return cp;
1050trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001051 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_SA));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001052 return NULL;
1053}
1054
1055static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001056ikev1_p_print(netdissect_options *ndo, u_char tpay _U_,
1057 const struct isakmp_gen *ext, u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001058 const u_char *ep, uint32_t phase, uint32_t doi0,
1059 uint32_t proto0 _U_, int depth)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001060{
JP Abgrall53f17a92014-02-12 14:02:41 -08001061 const struct ikev1_pl_p *p;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001062 const u_char *cp;
Elliott Hughes820eced2021-08-20 18:00:50 -07001063 uint8_t spi_size;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001064
Elliott Hughes820eced2021-08-20 18:00:50 -07001065 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_P));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001066
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001067 p = (const struct ikev1_pl_p *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07001068 ND_TCHECK_SIZE(p);
1069 ND_PRINT(" #%u protoid=%s transform=%u",
1070 GET_U_1(p->p_no), PROTOIDSTR(GET_U_1(p->prot_id)),
1071 GET_U_1(p->num_t));
1072 spi_size = GET_U_1(p->spi_size);
1073 if (spi_size) {
1074 ND_PRINT(" spi=");
1075 if (!rawprint(ndo, (const uint8_t *)(p + 1), spi_size))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001076 goto trunc;
1077 }
1078
Elliott Hughes820eced2021-08-20 18:00:50 -07001079 ext = (const struct isakmp_gen *)((const u_char *)(p + 1) + spi_size);
1080 ND_TCHECK_SIZE(ext);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001081
JP Abgrall53f17a92014-02-12 14:02:41 -08001082 cp = ikev1_sub_print(ndo, ISAKMP_NPTYPE_T, ext, ep, phase, doi0,
Elliott Hughes820eced2021-08-20 18:00:50 -07001083 GET_U_1(p->prot_id), depth);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001084
The Android Open Source Project2949f582009-03-03 19:30:46 -08001085 return cp;
1086trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001087 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_P));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001088 return NULL;
1089}
1090
JP Abgrall53f17a92014-02-12 14:02:41 -08001091static const char *ikev1_p_map[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001092 NULL, "ike",
1093};
1094
JP Abgrall53f17a92014-02-12 14:02:41 -08001095static const char *ikev2_t_type_map[]={
1096 NULL, "encr", "prf", "integ", "dh", "esn"
1097};
1098
The Android Open Source Project2949f582009-03-03 19:30:46 -08001099static const char *ah_p_map[] = {
1100 NULL, "(reserved)", "md5", "sha", "1des",
1101 "sha2-256", "sha2-384", "sha2-512",
1102};
1103
JP Abgrall53f17a92014-02-12 14:02:41 -08001104static const char *prf_p_map[] = {
1105 NULL, "hmac-md5", "hmac-sha", "hmac-tiger",
1106 "aes128_xcbc"
1107};
1108
1109static const char *integ_p_map[] = {
1110 NULL, "hmac-md5", "hmac-sha", "dec-mac",
1111 "kpdk-md5", "aes-xcbc"
1112};
1113
1114static const char *esn_p_map[] = {
1115 "no-esn", "esn"
1116};
1117
1118static const char *dh_p_map[] = {
1119 NULL, "modp768",
1120 "modp1024", /* group 2 */
1121 "EC2N 2^155", /* group 3 */
1122 "EC2N 2^185", /* group 4 */
1123 "modp1536", /* group 5 */
1124 "iana-grp06", "iana-grp07", /* reserved */
1125 "iana-grp08", "iana-grp09",
1126 "iana-grp10", "iana-grp11",
1127 "iana-grp12", "iana-grp13",
1128 "modp2048", /* group 14 */
1129 "modp3072", /* group 15 */
1130 "modp4096", /* group 16 */
1131 "modp6144", /* group 17 */
1132 "modp8192", /* group 18 */
1133};
1134
The Android Open Source Project2949f582009-03-03 19:30:46 -08001135static const char *esp_p_map[] = {
1136 NULL, "1des-iv64", "1des", "3des", "rc5", "idea", "cast",
1137 "blowfish", "3idea", "1des-iv32", "rc4", "null", "aes"
1138};
1139
1140static const char *ipcomp_p_map[] = {
1141 NULL, "oui", "deflate", "lzs",
1142};
1143
Elliott Hughes892a68b2015-10-19 14:43:53 -07001144static const struct attrmap ipsec_t_map[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001145 { NULL, 0, { NULL } },
1146 { "lifetype", 3, { NULL, "sec", "kb", }, },
1147 { "life", 0, { NULL } },
JP Abgrall53f17a92014-02-12 14:02:41 -08001148 { "group desc", 18, { NULL, "modp768",
1149 "modp1024", /* group 2 */
1150 "EC2N 2^155", /* group 3 */
1151 "EC2N 2^185", /* group 4 */
1152 "modp1536", /* group 5 */
1153 "iana-grp06", "iana-grp07", /* reserved */
1154 "iana-grp08", "iana-grp09",
1155 "iana-grp10", "iana-grp11",
1156 "iana-grp12", "iana-grp13",
1157 "modp2048", /* group 14 */
1158 "modp3072", /* group 15 */
1159 "modp4096", /* group 16 */
1160 "modp6144", /* group 17 */
1161 "modp8192", /* group 18 */
1162 }, },
The Android Open Source Project2949f582009-03-03 19:30:46 -08001163 { "enc mode", 3, { NULL, "tunnel", "transport", }, },
1164 { "auth", 5, { NULL, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, },
1165 { "keylen", 0, { NULL } },
1166 { "rounds", 0, { NULL } },
1167 { "dictsize", 0, { NULL } },
1168 { "privalg", 0, { NULL } },
1169};
1170
Elliott Hughes892a68b2015-10-19 14:43:53 -07001171static const struct attrmap encr_t_map[] = {
Elliott Hughes820eced2021-08-20 18:00:50 -07001172 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 0, 1 */
JP Abgrall53f17a92014-02-12 14:02:41 -08001173 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 2, 3 */
1174 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 4, 5 */
1175 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 6, 7 */
1176 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 8, 9 */
1177 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 10,11*/
1178 { NULL, 0, { NULL } }, { NULL, 0, { NULL } }, /* 12,13*/
1179 { "keylen", 14, { NULL }},
1180};
1181
Elliott Hughes892a68b2015-10-19 14:43:53 -07001182static const struct attrmap oakley_t_map[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001183 { NULL, 0, { NULL } },
1184 { "enc", 8, { NULL, "1des", "idea", "blowfish", "rc5",
Elliott Hughes820eced2021-08-20 18:00:50 -07001185 "3des", "cast", "aes", }, },
The Android Open Source Project2949f582009-03-03 19:30:46 -08001186 { "hash", 7, { NULL, "md5", "sha1", "tiger",
1187 "sha2-256", "sha2-384", "sha2-512", }, },
1188 { "auth", 6, { NULL, "preshared", "dss", "rsa sig", "rsa enc",
1189 "rsa enc revised", }, },
JP Abgrall53f17a92014-02-12 14:02:41 -08001190 { "group desc", 18, { NULL, "modp768",
1191 "modp1024", /* group 2 */
1192 "EC2N 2^155", /* group 3 */
1193 "EC2N 2^185", /* group 4 */
1194 "modp1536", /* group 5 */
1195 "iana-grp06", "iana-grp07", /* reserved */
1196 "iana-grp08", "iana-grp09",
1197 "iana-grp10", "iana-grp11",
1198 "iana-grp12", "iana-grp13",
1199 "modp2048", /* group 14 */
1200 "modp3072", /* group 15 */
1201 "modp4096", /* group 16 */
1202 "modp6144", /* group 17 */
1203 "modp8192", /* group 18 */
1204 }, },
The Android Open Source Project2949f582009-03-03 19:30:46 -08001205 { "group type", 4, { NULL, "MODP", "ECP", "EC2N", }, },
1206 { "group prime", 0, { NULL } },
1207 { "group gen1", 0, { NULL } },
1208 { "group gen2", 0, { NULL } },
1209 { "group curve A", 0, { NULL } },
1210 { "group curve B", 0, { NULL } },
1211 { "lifetype", 3, { NULL, "sec", "kb", }, },
1212 { "lifeduration", 0, { NULL } },
1213 { "prf", 0, { NULL } },
1214 { "keylen", 0, { NULL } },
1215 { "field", 0, { NULL } },
1216 { "order", 0, { NULL } },
1217};
1218
1219static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001220ikev1_t_print(netdissect_options *ndo, u_char tpay _U_,
1221 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001222 const u_char *ep, uint32_t phase _U_, uint32_t doi _U_,
1223 uint32_t proto, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001224{
JP Abgrall53f17a92014-02-12 14:02:41 -08001225 const struct ikev1_pl_t *p;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001226 const u_char *cp;
1227 const char *idstr;
1228 const struct attrmap *map;
1229 size_t nmap;
1230 const u_char *ep2;
1231
Elliott Hughes820eced2021-08-20 18:00:50 -07001232 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_T));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001233
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001234 p = (const struct ikev1_pl_t *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07001235 ND_TCHECK_SIZE(p);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001236
1237 switch (proto) {
1238 case 1:
Elliott Hughes820eced2021-08-20 18:00:50 -07001239 idstr = STR_OR_ID(GET_U_1(p->t_id), ikev1_p_map);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001240 map = oakley_t_map;
1241 nmap = sizeof(oakley_t_map)/sizeof(oakley_t_map[0]);
1242 break;
1243 case 2:
Elliott Hughes820eced2021-08-20 18:00:50 -07001244 idstr = STR_OR_ID(GET_U_1(p->t_id), ah_p_map);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001245 map = ipsec_t_map;
1246 nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
1247 break;
1248 case 3:
Elliott Hughes820eced2021-08-20 18:00:50 -07001249 idstr = STR_OR_ID(GET_U_1(p->t_id), esp_p_map);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001250 map = ipsec_t_map;
1251 nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
1252 break;
1253 case 4:
Elliott Hughes820eced2021-08-20 18:00:50 -07001254 idstr = STR_OR_ID(GET_U_1(p->t_id), ipcomp_p_map);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001255 map = ipsec_t_map;
1256 nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]);
1257 break;
1258 default:
1259 idstr = NULL;
1260 map = NULL;
1261 nmap = 0;
1262 break;
1263 }
1264
1265 if (idstr)
Elliott Hughes820eced2021-08-20 18:00:50 -07001266 ND_PRINT(" #%u id=%s ", GET_U_1(p->t_no), idstr);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001267 else
Elliott Hughes820eced2021-08-20 18:00:50 -07001268 ND_PRINT(" #%u id=%u ", GET_U_1(p->t_no), GET_U_1(p->t_id));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001269 cp = (const u_char *)(p + 1);
1270 ep2 = (const u_char *)p + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001271 while (cp < ep && cp < ep2) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001272 if (map && nmap)
1273 cp = ikev1_attrmap_print(ndo, cp, ep2, map, nmap);
1274 else
1275 cp = ikev1_attr_print(ndo, cp, ep2);
1276 if (cp == NULL)
1277 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001278 }
1279 if (ep < ep2)
Elliott Hughes820eced2021-08-20 18:00:50 -07001280 ND_PRINT("...");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001281 return cp;
1282trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001283 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_T));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001284 return NULL;
1285}
1286
1287static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001288ikev1_ke_print(netdissect_options *ndo, u_char tpay _U_,
Elliott Hughes820eced2021-08-20 18:00:50 -07001289 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001290 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi _U_,
1291 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001292{
Elliott Hughes820eced2021-08-20 18:00:50 -07001293 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_KE));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001294
Elliott Hughes820eced2021-08-20 18:00:50 -07001295 ND_TCHECK_SIZE(ext);
1296 /*
1297 * Our caller has ensured that the length is >= 4.
1298 */
1299 ND_PRINT(" key len=%u", item_len - 4);
1300 if (2 < ndo->ndo_vflag && item_len > 4) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001301 /* Print the entire payload in hex */
Elliott Hughes820eced2021-08-20 18:00:50 -07001302 ND_PRINT(" ");
1303 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001304 goto trunc;
1305 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001306 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001307trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001308 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_KE));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001309 return NULL;
1310}
1311
1312static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001313ikev1_id_print(netdissect_options *ndo, u_char tpay _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001314 const struct isakmp_gen *ext, u_int item_len,
1315 const u_char *ep _U_, uint32_t phase, uint32_t doi _U_,
1316 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001317{
1318#define USE_IPSECDOI_IN_PHASE1 1
JP Abgrall53f17a92014-02-12 14:02:41 -08001319 const struct ikev1_pl_id *p;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001320 static const char *idtypestr[] = {
1321 "IPv4", "IPv4net", "IPv6", "IPv6net",
1322 };
1323 static const char *ipsecidtypestr[] = {
1324 NULL, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6",
1325 "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN",
1326 "keyid",
1327 };
Elliott Hughes820eced2021-08-20 18:00:50 -07001328 u_int len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001329 const u_char *data;
1330
Elliott Hughes820eced2021-08-20 18:00:50 -07001331 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_ID));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001332
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001333 p = (const struct ikev1_pl_id *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07001334 ND_TCHECK_SIZE(p);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001335 if (sizeof(*p) < item_len) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001336 data = (const u_char *)(p + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001337 len = item_len - sizeof(*p);
1338 } else {
1339 data = NULL;
1340 len = 0;
1341 }
1342
1343#if 0 /*debug*/
Elliott Hughes820eced2021-08-20 18:00:50 -07001344 ND_PRINT(" [phase=%u doi=%u proto=%u]", phase, doi, proto);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001345#endif
1346 switch (phase) {
1347#ifndef USE_IPSECDOI_IN_PHASE1
1348 case 1:
1349#endif
1350 default:
Elliott Hughes820eced2021-08-20 18:00:50 -07001351 ND_PRINT(" idtype=%s",
1352 STR_OR_ID(GET_U_1(p->d.id_type), idtypestr));
1353 ND_PRINT(" doi_data=%u",
1354 GET_BE_U_4(p->d.doi_data) & 0xffffff);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001355 break;
1356
1357#ifdef USE_IPSECDOI_IN_PHASE1
1358 case 1:
1359#endif
1360 case 2:
1361 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001362 const struct ipsecdoi_id *doi_p;
Elliott Hughescec480a2017-12-19 16:54:57 -08001363 const char *p_name;
Elliott Hughes820eced2021-08-20 18:00:50 -07001364 uint8_t type, proto_id;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001365
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001366 doi_p = (const struct ipsecdoi_id *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07001367 ND_TCHECK_SIZE(doi_p);
1368 type = GET_U_1(doi_p->type);
1369 ND_PRINT(" idtype=%s", STR_OR_ID(type, ipsecidtypestr));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001370 /* A protocol ID of 0 DOES NOT mean IPPROTO_IP! */
Elliott Hughes820eced2021-08-20 18:00:50 -07001371 proto_id = GET_U_1(doi_p->proto_id);
1372 if (!ndo->ndo_nflag && proto_id && (p_name = netdb_protoname(proto_id)) != NULL)
1373 ND_PRINT(" protoid=%s", p_name);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001374 else
Elliott Hughes820eced2021-08-20 18:00:50 -07001375 ND_PRINT(" protoid=%u", proto_id);
1376 ND_PRINT(" port=%u", GET_BE_U_2(doi_p->port));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001377 if (!len)
1378 break;
1379 if (data == NULL)
1380 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001381 ND_TCHECK_LEN(data, len);
1382 switch (type) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001383 case IPSECDOI_ID_IPV4_ADDR:
1384 if (len < 4)
Elliott Hughes820eced2021-08-20 18:00:50 -07001385 ND_PRINT(" len=%u [bad: < 4]", len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001386 else
Elliott Hughes820eced2021-08-20 18:00:50 -07001387 ND_PRINT(" len=%u %s", len, GET_IPADDR_STRING(data));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001388 len = 0;
1389 break;
1390 case IPSECDOI_ID_FQDN:
1391 case IPSECDOI_ID_USER_FQDN:
1392 {
Elliott Hughes820eced2021-08-20 18:00:50 -07001393 u_int i;
1394 ND_PRINT(" len=%u ", len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001395 for (i = 0; i < len; i++)
Elliott Hughes820eced2021-08-20 18:00:50 -07001396 fn_print_char(ndo, GET_U_1(data + i));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001397 len = 0;
1398 break;
1399 }
1400 case IPSECDOI_ID_IPV4_ADDR_SUBNET:
1401 {
1402 const u_char *mask;
1403 if (len < 8)
Elliott Hughes820eced2021-08-20 18:00:50 -07001404 ND_PRINT(" len=%u [bad: < 8]", len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001405 else {
Elliott Hughes820eced2021-08-20 18:00:50 -07001406 mask = data + sizeof(nd_ipv4);
1407 ND_PRINT(" len=%u %s/%u.%u.%u.%u", len,
1408 GET_IPADDR_STRING(data),
1409 GET_U_1(mask), GET_U_1(mask + 1),
1410 GET_U_1(mask + 2),
1411 GET_U_1(mask + 3));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001412 }
1413 len = 0;
1414 break;
1415 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001416 case IPSECDOI_ID_IPV6_ADDR:
1417 if (len < 16)
Elliott Hughes820eced2021-08-20 18:00:50 -07001418 ND_PRINT(" len=%u [bad: < 16]", len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001419 else
Elliott Hughes820eced2021-08-20 18:00:50 -07001420 ND_PRINT(" len=%u %s", len, GET_IP6ADDR_STRING(data));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001421 len = 0;
1422 break;
1423 case IPSECDOI_ID_IPV6_ADDR_SUBNET:
1424 {
JP Abgrall53f17a92014-02-12 14:02:41 -08001425 const u_char *mask;
Elliott Hughescec480a2017-12-19 16:54:57 -08001426 if (len < 32)
Elliott Hughes820eced2021-08-20 18:00:50 -07001427 ND_PRINT(" len=%u [bad: < 32]", len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001428 else {
Elliott Hughes820eced2021-08-20 18:00:50 -07001429 mask = (const u_char *)(data + sizeof(nd_ipv6));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001430 /*XXX*/
Elliott Hughes820eced2021-08-20 18:00:50 -07001431 ND_PRINT(" len=%u %s/0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", len,
1432 GET_IP6ADDR_STRING(data),
1433 GET_U_1(mask), GET_U_1(mask + 1),
1434 GET_U_1(mask + 2),
1435 GET_U_1(mask + 3),
1436 GET_U_1(mask + 4),
1437 GET_U_1(mask + 5),
1438 GET_U_1(mask + 6),
1439 GET_U_1(mask + 7),
1440 GET_U_1(mask + 8),
1441 GET_U_1(mask + 9),
1442 GET_U_1(mask + 10),
1443 GET_U_1(mask + 11),
1444 GET_U_1(mask + 12),
1445 GET_U_1(mask + 13),
1446 GET_U_1(mask + 14),
1447 GET_U_1(mask + 15));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001448 }
1449 len = 0;
1450 break;
1451 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001452 case IPSECDOI_ID_IPV4_ADDR_RANGE:
1453 if (len < 8)
Elliott Hughes820eced2021-08-20 18:00:50 -07001454 ND_PRINT(" len=%u [bad: < 8]", len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001455 else {
Elliott Hughes820eced2021-08-20 18:00:50 -07001456 ND_PRINT(" len=%u %s-%s", len,
1457 GET_IPADDR_STRING(data),
1458 GET_IPADDR_STRING(data + sizeof(nd_ipv4)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001459 }
1460 len = 0;
1461 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001462 case IPSECDOI_ID_IPV6_ADDR_RANGE:
1463 if (len < 32)
Elliott Hughes820eced2021-08-20 18:00:50 -07001464 ND_PRINT(" len=%u [bad: < 32]", len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001465 else {
Elliott Hughes820eced2021-08-20 18:00:50 -07001466 ND_PRINT(" len=%u %s-%s", len,
1467 GET_IP6ADDR_STRING(data),
1468 GET_IP6ADDR_STRING(data + sizeof(nd_ipv6)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001469 }
1470 len = 0;
1471 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001472 case IPSECDOI_ID_DER_ASN1_DN:
1473 case IPSECDOI_ID_DER_ASN1_GN:
1474 case IPSECDOI_ID_KEY_ID:
1475 break;
1476 }
1477 break;
1478 }
1479 }
1480 if (data && len) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001481 ND_PRINT(" len=%u", len);
JP Abgrall53f17a92014-02-12 14:02:41 -08001482 if (2 < ndo->ndo_vflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001483 ND_PRINT(" ");
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001484 if (!rawprint(ndo, (const uint8_t *)data, len))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001485 goto trunc;
1486 }
1487 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001488 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001489trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001490 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_ID));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001491 return NULL;
1492}
1493
1494static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001495ikev1_cert_print(netdissect_options *ndo, u_char tpay _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001496 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001497 const u_char *ep _U_, uint32_t phase _U_,
1498 uint32_t doi0 _U_,
1499 uint32_t proto0 _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001500{
JP Abgrall53f17a92014-02-12 14:02:41 -08001501 const struct ikev1_pl_cert *p;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001502 static const char *certstr[] = {
1503 "none", "pkcs7", "pgp", "dns",
1504 "x509sign", "x509ke", "kerberos", "crl",
1505 "arl", "spki", "x509attr",
1506 };
1507
Elliott Hughes820eced2021-08-20 18:00:50 -07001508 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_CERT));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001509
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001510 p = (const struct ikev1_pl_cert *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07001511 ND_TCHECK_SIZE(p);
1512 /*
1513 * Our caller has ensured that the length is >= 4.
1514 */
1515 ND_PRINT(" len=%u", item_len - 4);
1516 ND_PRINT(" type=%s", STR_OR_ID(GET_U_1(p->encode), certstr));
JP Abgrall53f17a92014-02-12 14:02:41 -08001517 if (2 < ndo->ndo_vflag && 4 < item_len) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001518 /* Print the entire payload in hex */
Elliott Hughes820eced2021-08-20 18:00:50 -07001519 ND_PRINT(" ");
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001520 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001521 goto trunc;
1522 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001523 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001524trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001525 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_CERT));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001526 return NULL;
1527}
1528
1529static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001530ikev1_cr_print(netdissect_options *ndo, u_char tpay _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001531 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001532 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi0 _U_,
1533 uint32_t proto0 _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001534{
JP Abgrall53f17a92014-02-12 14:02:41 -08001535 const struct ikev1_pl_cert *p;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001536 static const char *certstr[] = {
1537 "none", "pkcs7", "pgp", "dns",
1538 "x509sign", "x509ke", "kerberos", "crl",
1539 "arl", "spki", "x509attr",
1540 };
1541
Elliott Hughes820eced2021-08-20 18:00:50 -07001542 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_CR));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001543
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001544 p = (const struct ikev1_pl_cert *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07001545 ND_TCHECK_SIZE(p);
1546 /*
1547 * Our caller has ensured that the length is >= 4.
1548 */
1549 ND_PRINT(" len=%u", item_len - 4);
1550 ND_PRINT(" type=%s", STR_OR_ID(GET_U_1(p->encode), certstr));
JP Abgrall53f17a92014-02-12 14:02:41 -08001551 if (2 < ndo->ndo_vflag && 4 < item_len) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001552 /* Print the entire payload in hex */
Elliott Hughes820eced2021-08-20 18:00:50 -07001553 ND_PRINT(" ");
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:
Elliott Hughes820eced2021-08-20 18:00:50 -07001559 ND_PRINT(" [|%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_,
Elliott Hughes820eced2021-08-20 18:00:50 -07001565 const struct isakmp_gen *ext, u_int item_len,
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{
Elliott Hughes820eced2021-08-20 18:00:50 -07001569 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_HASH));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001570
Elliott Hughes820eced2021-08-20 18:00:50 -07001571 ND_TCHECK_SIZE(ext);
1572 /*
1573 * Our caller has ensured that the length is >= 4.
1574 */
1575 ND_PRINT(" len=%u", item_len - 4);
1576 if (2 < ndo->ndo_vflag && 4 < item_len) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001577 /* Print the entire payload in hex */
Elliott Hughes820eced2021-08-20 18:00:50 -07001578 ND_PRINT(" ");
1579 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001580 goto trunc;
1581 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001582 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001583trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001584 ND_PRINT(" [|%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_,
Elliott Hughes820eced2021-08-20 18:00:50 -07001590 const struct isakmp_gen *ext, u_int item_len,
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{
Elliott Hughes820eced2021-08-20 18:00:50 -07001594 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_SIG));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001595
Elliott Hughes820eced2021-08-20 18:00:50 -07001596 ND_TCHECK_SIZE(ext);
1597 /*
1598 * Our caller has ensured that the length is >= 4.
1599 */
1600 ND_PRINT(" len=%u", item_len - 4);
1601 if (2 < ndo->ndo_vflag && 4 < item_len) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001602 /* Print the entire payload in hex */
Elliott Hughes820eced2021-08-20 18:00:50 -07001603 ND_PRINT(" ");
1604 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001605 goto trunc;
1606 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001607 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001608trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001609 ND_PRINT(" [|%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,
Elliott Hughes820eced2021-08-20 18:00:50 -07001616 u_int item_len,
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{
Elliott Hughes820eced2021-08-20 18:00:50 -07001621 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_NONCE));
JP Abgrall53f17a92014-02-12 14:02:41 -08001622
Elliott Hughes820eced2021-08-20 18:00:50 -07001623 ND_TCHECK_SIZE(ext);
Elliott Hughescec480a2017-12-19 16:54:57 -08001624 /*
1625 * Our caller has ensured that the length is >= 4.
1626 */
Elliott Hughes820eced2021-08-20 18:00:50 -07001627 ND_PRINT(" n len=%u", item_len - 4);
1628 if (item_len > 4) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001629 if (ndo->ndo_vflag > 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001630 ND_PRINT(" ");
1631 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
Elliott Hughescec480a2017-12-19 16:54:57 -08001632 goto trunc;
1633 } else if (ndo->ndo_vflag > 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001634 ND_PRINT(" ");
Elliott Hughescec480a2017-12-19 16:54:57 -08001635 if (!ike_show_somedata(ndo, (const u_char *)(ext + 1), ep))
1636 goto trunc;
1637 }
JP Abgrall53f17a92014-02-12 14:02:41 -08001638 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001639 return (const u_char *)ext + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08001640trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001641 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE));
JP Abgrall53f17a92014-02-12 14:02:41 -08001642 return NULL;
1643}
1644
1645static const u_char *
1646ikev1_n_print(netdissect_options *ndo, u_char tpay _U_,
1647 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughescec480a2017-12-19 16:54:57 -08001648 const u_char *ep, uint32_t phase _U_, uint32_t doi0 _U_,
1649 uint32_t proto0 _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08001650{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001651 const struct ikev1_pl_n *p;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001652 const u_char *cp;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001653 const u_char *ep2;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001654 uint32_t doi;
1655 uint32_t proto;
Elliott Hughes820eced2021-08-20 18:00:50 -07001656 uint16_t type;
1657 uint8_t spi_size;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001658 static const char *notify_error_str[] = {
1659 NULL, "INVALID-PAYLOAD-TYPE",
1660 "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED",
1661 "INVALID-COOKIE", "INVALID-MAJOR-VERSION",
1662 "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE",
1663 "INVALID-FLAGS", "INVALID-MESSAGE-ID",
1664 "INVALID-PROTOCOL-ID", "INVALID-SPI",
1665 "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED",
1666 "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX",
1667 "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION",
1668 "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING",
1669 "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED",
1670 "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION",
1671 "AUTHENTICATION-FAILED", "INVALID-SIGNATURE",
1672 "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME",
1673 "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE",
1674 "UNEQUAL-PAYLOAD-LENGTHS",
1675 };
1676 static const char *ipsec_notify_error_str[] = {
1677 "RESERVED",
1678 };
1679 static const char *notify_status_str[] = {
1680 "CONNECTED",
1681 };
1682 static const char *ipsec_notify_status_str[] = {
1683 "RESPONDER-LIFETIME", "REPLAY-STATUS",
1684 "INITIAL-CONTACT",
1685 };
1686/* NOTE: these macro must be called with x in proper range */
1687
1688/* 0 - 8191 */
1689#define NOTIFY_ERROR_STR(x) \
1690 STR_OR_ID((x), notify_error_str)
1691
1692/* 8192 - 16383 */
1693#define IPSEC_NOTIFY_ERROR_STR(x) \
1694 STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str)
1695
1696/* 16384 - 24575 */
1697#define NOTIFY_STATUS_STR(x) \
1698 STR_OR_ID((u_int)((x) - 16384), notify_status_str)
1699
1700/* 24576 - 32767 */
1701#define IPSEC_NOTIFY_STATUS_STR(x) \
1702 STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str)
1703
Elliott Hughes820eced2021-08-20 18:00:50 -07001704 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_N));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001705
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001706 p = (const struct ikev1_pl_n *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07001707 ND_TCHECK_SIZE(p);
1708 doi = GET_BE_U_4(p->doi);
1709 proto = GET_U_1(p->prot_id);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001710 if (doi != 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001711 ND_PRINT(" doi=%u", doi);
1712 ND_PRINT(" proto=%u", proto);
1713 type = GET_BE_U_2(p->type);
1714 if (type < 8192)
1715 ND_PRINT(" type=%s", NOTIFY_ERROR_STR(type));
1716 else if (type < 16384)
1717 ND_PRINT(" type=%s", numstr(type));
1718 else if (type < 24576)
1719 ND_PRINT(" type=%s", NOTIFY_STATUS_STR(type));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001720 else
Elliott Hughes820eced2021-08-20 18:00:50 -07001721 ND_PRINT(" type=%s", numstr(type));
1722 spi_size = GET_U_1(p->spi_size);
1723 if (spi_size) {
1724 ND_PRINT(" spi=");
1725 if (!rawprint(ndo, (const uint8_t *)(p + 1), spi_size))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001726 goto trunc;
1727 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001728 return (const u_char *)(p + 1) + spi_size;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001729 }
1730
Elliott Hughes820eced2021-08-20 18:00:50 -07001731 ND_PRINT(" doi=ipsec");
1732 ND_PRINT(" proto=%s", PROTOIDSTR(proto));
1733 type = GET_BE_U_2(p->type);
1734 if (type < 8192)
1735 ND_PRINT(" type=%s", NOTIFY_ERROR_STR(type));
1736 else if (type < 16384)
1737 ND_PRINT(" type=%s", IPSEC_NOTIFY_ERROR_STR(type));
1738 else if (type < 24576)
1739 ND_PRINT(" type=%s", NOTIFY_STATUS_STR(type));
1740 else if (type < 32768)
1741 ND_PRINT(" type=%s", IPSEC_NOTIFY_STATUS_STR(type));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001742 else
Elliott Hughes820eced2021-08-20 18:00:50 -07001743 ND_PRINT(" type=%s", numstr(type));
1744 spi_size = GET_U_1(p->spi_size);
1745 if (spi_size) {
1746 ND_PRINT(" spi=");
1747 if (!rawprint(ndo, (const uint8_t *)(p + 1), spi_size))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001748 goto trunc;
1749 }
1750
Elliott Hughes820eced2021-08-20 18:00:50 -07001751 cp = (const u_char *)(p + 1) + spi_size;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001752 ep2 = (const u_char *)p + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001753
1754 if (cp < ep) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001755 switch (type) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001756 case IPSECDOI_NTYPE_RESPONDER_LIFETIME:
1757 {
1758 const struct attrmap *map = oakley_t_map;
1759 size_t nmap = sizeof(oakley_t_map)/sizeof(oakley_t_map[0]);
Elliott Hughes820eced2021-08-20 18:00:50 -07001760 ND_PRINT(" attrs=(");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001761 while (cp < ep && cp < ep2) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001762 cp = ikev1_attrmap_print(ndo, cp, ep2, map, nmap);
1763 if (cp == NULL) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001764 ND_PRINT(")");
Elliott Hughescec480a2017-12-19 16:54:57 -08001765 goto trunc;
1766 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001767 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001768 ND_PRINT(")");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001769 break;
1770 }
1771 case IPSECDOI_NTYPE_REPLAY_STATUS:
Elliott Hughes820eced2021-08-20 18:00:50 -07001772 ND_PRINT(" status=(");
1773 ND_PRINT("replay detection %sabled",
1774 GET_BE_U_4(cp) ? "en" : "dis");
1775 ND_PRINT(")");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001776 break;
1777 default:
Elliott Hughescec480a2017-12-19 16:54:57 -08001778 /*
1779 * XXX - fill in more types here; see, for example,
1780 * draft-ietf-ipsec-notifymsg-04.
1781 */
1782 if (ndo->ndo_vflag > 3) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001783 ND_PRINT(" data=(");
Elliott Hughescec480a2017-12-19 16:54:57 -08001784 if (!rawprint(ndo, (const uint8_t *)(cp), ep - cp))
1785 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001786 ND_PRINT(")");
Elliott Hughescec480a2017-12-19 16:54:57 -08001787 } else {
1788 if (!ike_show_somedata(ndo, cp, ep))
1789 goto trunc;
1790 }
1791 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001792 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001793 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001794 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001795trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001796 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_N));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001797 return NULL;
1798}
1799
1800static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001801ikev1_d_print(netdissect_options *ndo, u_char tpay _U_,
1802 const struct isakmp_gen *ext, u_int item_len _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001803 const u_char *ep _U_, uint32_t phase _U_, uint32_t doi0 _U_,
1804 uint32_t proto0 _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001805{
JP Abgrall53f17a92014-02-12 14:02:41 -08001806 const struct ikev1_pl_d *p;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001807 const uint8_t *q;
1808 uint32_t doi;
1809 uint32_t proto;
Elliott Hughes820eced2021-08-20 18:00:50 -07001810 uint8_t spi_size;
1811 uint16_t num_spi;
1812 u_int i;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001813
Elliott Hughes820eced2021-08-20 18:00:50 -07001814 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_D));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001815
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001816 p = (const struct ikev1_pl_d *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07001817 ND_TCHECK_SIZE(p);
1818 doi = GET_BE_U_4(p->doi);
1819 proto = GET_U_1(p->prot_id);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001820 if (doi != 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001821 ND_PRINT(" doi=%u", doi);
1822 ND_PRINT(" proto=%u", proto);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001823 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -07001824 ND_PRINT(" doi=ipsec");
1825 ND_PRINT(" proto=%s", PROTOIDSTR(proto));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001826 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001827 spi_size = GET_U_1(p->spi_size);
1828 ND_PRINT(" spilen=%u", spi_size);
1829 num_spi = GET_BE_U_2(p->num_spi);
1830 ND_PRINT(" nspi=%u", num_spi);
1831 ND_PRINT(" spi=");
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001832 q = (const uint8_t *)(p + 1);
Elliott Hughes820eced2021-08-20 18:00:50 -07001833 for (i = 0; i < num_spi; i++) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001834 if (i != 0)
Elliott Hughes820eced2021-08-20 18:00:50 -07001835 ND_PRINT(",");
1836 if (!rawprint(ndo, (const uint8_t *)q, spi_size))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001837 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001838 q += spi_size;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001839 }
1840 return q;
1841trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001842 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_D));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001843 return NULL;
1844}
1845
1846static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08001847ikev1_vid_print(netdissect_options *ndo, u_char tpay _U_,
1848 const struct isakmp_gen *ext,
Elliott Hughes820eced2021-08-20 18:00:50 -07001849 u_int item_len, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001850 uint32_t phase _U_, uint32_t doi _U_,
1851 uint32_t proto _U_, int depth _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001852{
Elliott Hughes820eced2021-08-20 18:00:50 -07001853 ND_PRINT("%s:", NPSTR(ISAKMP_NPTYPE_VID));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001854
Elliott Hughes820eced2021-08-20 18:00:50 -07001855 ND_TCHECK_SIZE(ext);
1856 /*
1857 * Our caller has ensured that the length is >= 4.
1858 */
1859 ND_PRINT(" len=%u", item_len - 4);
1860 if (2 < ndo->ndo_vflag && 4 < item_len) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001861 /* Print the entire payload in hex */
Elliott Hughes820eced2021-08-20 18:00:50 -07001862 ND_PRINT(" ");
1863 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001864 goto trunc;
1865 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001866 return (const u_char *)ext + item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001867trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001868 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_VID));
JP Abgrall53f17a92014-02-12 14:02:41 -08001869 return NULL;
1870}
1871
1872/************************************************************/
1873/* */
1874/* IKE v2 - rfc4306 - dissector */
1875/* */
1876/************************************************************/
1877
1878static void
Elliott Hughes820eced2021-08-20 18:00:50 -07001879ikev2_pay_print(netdissect_options *ndo, const char *payname, uint8_t critical)
JP Abgrall53f17a92014-02-12 14:02:41 -08001880{
Elliott Hughes820eced2021-08-20 18:00:50 -07001881 ND_PRINT("%s%s:", payname, critical&0x80 ? "[C]" : "");
JP Abgrall53f17a92014-02-12 14:02:41 -08001882}
1883
1884static const u_char *
1885ikev2_gen_print(netdissect_options *ndo, u_char tpay,
Elliott Hughes820eced2021-08-20 18:00:50 -07001886 const struct isakmp_gen *ext, u_int item_len)
JP Abgrall53f17a92014-02-12 14:02:41 -08001887{
Elliott Hughes820eced2021-08-20 18:00:50 -07001888 const struct isakmp_gen *p = (const struct isakmp_gen *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08001889
Elliott Hughes820eced2021-08-20 18:00:50 -07001890 ND_TCHECK_SIZE(ext);
1891 ikev2_pay_print(ndo, NPSTR(tpay), GET_U_1(p->critical));
JP Abgrall53f17a92014-02-12 14:02:41 -08001892
Elliott Hughes820eced2021-08-20 18:00:50 -07001893 /*
1894 * Our caller has ensured that the length is >= 4.
1895 */
1896 ND_PRINT(" len=%u", item_len - 4);
1897 if (2 < ndo->ndo_vflag && 4 < item_len) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001898 /* Print the entire payload in hex */
Elliott Hughes820eced2021-08-20 18:00:50 -07001899 ND_PRINT(" ");
1900 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08001901 goto trunc;
1902 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001903 return (const u_char *)ext + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08001904trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001905 ND_PRINT(" [|%s]", NPSTR(tpay));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001906 return NULL;
1907}
1908
1909static const u_char *
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001910ikev2_t_print(netdissect_options *ndo, int tcount,
JP Abgrall53f17a92014-02-12 14:02:41 -08001911 const struct isakmp_gen *ext, u_int item_len,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001912 const u_char *ep)
JP Abgrall53f17a92014-02-12 14:02:41 -08001913{
1914 const struct ikev2_t *p;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001915 uint16_t t_id;
Elliott Hughes820eced2021-08-20 18:00:50 -07001916 uint8_t t_type;
JP Abgrall53f17a92014-02-12 14:02:41 -08001917 const u_char *cp;
1918 const char *idstr;
1919 const struct attrmap *map;
1920 size_t nmap;
1921 const u_char *ep2;
1922
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001923 p = (const struct ikev2_t *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07001924 ND_TCHECK_SIZE(p);
1925 ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_T), GET_U_1(p->h.critical));
JP Abgrall53f17a92014-02-12 14:02:41 -08001926
Elliott Hughes820eced2021-08-20 18:00:50 -07001927 t_id = GET_BE_U_2(p->t_id);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001928
JP Abgrall53f17a92014-02-12 14:02:41 -08001929 map = NULL;
1930 nmap = 0;
1931
Elliott Hughes820eced2021-08-20 18:00:50 -07001932 t_type = GET_U_1(p->t_type);
1933 switch (t_type) {
JP Abgrall53f17a92014-02-12 14:02:41 -08001934 case IV2_T_ENCR:
1935 idstr = STR_OR_ID(t_id, esp_p_map);
1936 map = encr_t_map;
1937 nmap = sizeof(encr_t_map)/sizeof(encr_t_map[0]);
1938 break;
1939
1940 case IV2_T_PRF:
1941 idstr = STR_OR_ID(t_id, prf_p_map);
1942 break;
1943
1944 case IV2_T_INTEG:
1945 idstr = STR_OR_ID(t_id, integ_p_map);
1946 break;
1947
1948 case IV2_T_DH:
1949 idstr = STR_OR_ID(t_id, dh_p_map);
1950 break;
1951
1952 case IV2_T_ESN:
1953 idstr = STR_OR_ID(t_id, esn_p_map);
1954 break;
1955
1956 default:
1957 idstr = NULL;
1958 break;
1959 }
1960
1961 if (idstr)
Elliott Hughes820eced2021-08-20 18:00:50 -07001962 ND_PRINT(" #%u type=%s id=%s ", tcount,
1963 STR_OR_ID(t_type, ikev2_t_type_map),
1964 idstr);
JP Abgrall53f17a92014-02-12 14:02:41 -08001965 else
Elliott Hughes820eced2021-08-20 18:00:50 -07001966 ND_PRINT(" #%u type=%s id=%u ", tcount,
1967 STR_OR_ID(t_type, ikev2_t_type_map),
1968 t_id);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001969 cp = (const u_char *)(p + 1);
1970 ep2 = (const u_char *)p + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08001971 while (cp < ep && cp < ep2) {
1972 if (map && nmap) {
Elliott Hughescec480a2017-12-19 16:54:57 -08001973 cp = ikev1_attrmap_print(ndo, cp, ep2, map, nmap);
JP Abgrall53f17a92014-02-12 14:02:41 -08001974 } else
Elliott Hughescec480a2017-12-19 16:54:57 -08001975 cp = ikev1_attr_print(ndo, cp, ep2);
1976 if (cp == NULL)
1977 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08001978 }
1979 if (ep < ep2)
Elliott Hughes820eced2021-08-20 18:00:50 -07001980 ND_PRINT("...");
JP Abgrall53f17a92014-02-12 14:02:41 -08001981 return cp;
1982trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001983 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_T));
JP Abgrall53f17a92014-02-12 14:02:41 -08001984 return NULL;
1985}
1986
1987static const u_char *
1988ikev2_p_print(netdissect_options *ndo, u_char tpay _U_, int pcount _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001989 const struct isakmp_gen *ext, u_int oprop_length,
1990 const u_char *ep, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08001991{
1992 const struct ikev2_p *p;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001993 u_int prop_length;
Elliott Hughes820eced2021-08-20 18:00:50 -07001994 uint8_t spi_size;
JP Abgrall53f17a92014-02-12 14:02:41 -08001995 const u_char *cp;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001996 int i;
1997 int tcount;
1998 u_char np;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001999 u_int item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002000
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002001 p = (const struct ikev2_p *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07002002 ND_TCHECK_SIZE(p);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002003
Elliott Hughes820eced2021-08-20 18:00:50 -07002004 ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_P), GET_U_1(p->h.critical));
JP Abgrall53f17a92014-02-12 14:02:41 -08002005
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002006 /*
2007 * ikev2_sa_print() guarantees that this is >= 4.
2008 */
2009 prop_length = oprop_length - 4;
Elliott Hughes820eced2021-08-20 18:00:50 -07002010 ND_PRINT(" #%u protoid=%s transform=%u len=%u",
2011 GET_U_1(p->p_no), PROTOIDSTR(GET_U_1(p->prot_id)),
2012 GET_U_1(p->num_t), oprop_length);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002013 cp = (const u_char *)(p + 1);
2014
Elliott Hughes820eced2021-08-20 18:00:50 -07002015 spi_size = GET_U_1(p->spi_size);
2016 if (spi_size) {
2017 if (prop_length < spi_size)
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002018 goto toolong;
Elliott Hughes820eced2021-08-20 18:00:50 -07002019 ND_PRINT(" spi=");
2020 if (!rawprint(ndo, (const uint8_t *)cp, spi_size))
JP Abgrall53f17a92014-02-12 14:02:41 -08002021 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07002022 cp += spi_size;
2023 prop_length -= spi_size;
JP Abgrall53f17a92014-02-12 14:02:41 -08002024 }
2025
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002026 /*
2027 * Print the transforms.
2028 */
2029 tcount = 0;
Elliott Hughes820eced2021-08-20 18:00:50 -07002030 for (np = ISAKMP_NPTYPE_T; np != 0; np = GET_U_1(ext->np)) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002031 tcount++;
2032 ext = (const struct isakmp_gen *)cp;
2033 if (prop_length < sizeof(*ext))
2034 goto toolong;
Elliott Hughes820eced2021-08-20 18:00:50 -07002035 ND_TCHECK_SIZE(ext);
Elliott Hughes892a68b2015-10-19 14:43:53 -07002036
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002037 /*
2038 * Since we can't have a payload length of less than 4 bytes,
2039 * we need to bail out here if the generic header is nonsensical
2040 * or truncated, otherwise we could loop forever processing
2041 * zero-length items or otherwise misdissect the packet.
2042 */
Elliott Hughes820eced2021-08-20 18:00:50 -07002043 item_len = GET_BE_U_2(ext->len);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002044 if (item_len <= 4)
2045 goto trunc;
2046
2047 if (prop_length < item_len)
2048 goto toolong;
Elliott Hughes820eced2021-08-20 18:00:50 -07002049 ND_TCHECK_LEN(cp, item_len);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002050
2051 depth++;
Elliott Hughes820eced2021-08-20 18:00:50 -07002052 ND_PRINT("\n");
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002053 for (i = 0; i < depth; i++)
Elliott Hughes820eced2021-08-20 18:00:50 -07002054 ND_PRINT(" ");
2055 ND_PRINT("(");
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002056 if (np == ISAKMP_NPTYPE_T) {
2057 cp = ikev2_t_print(ndo, tcount, ext, item_len, ep);
2058 if (cp == NULL) {
2059 /* error, already reported */
2060 return NULL;
2061 }
2062 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -07002063 ND_PRINT("%s", NPSTR(np));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002064 cp += item_len;
2065 }
Elliott Hughes820eced2021-08-20 18:00:50 -07002066 ND_PRINT(")");
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002067 depth--;
2068 prop_length -= item_len;
2069 }
2070 return cp;
2071toolong:
2072 /*
2073 * Skip the rest of the proposal.
2074 */
2075 cp += prop_length;
Elliott Hughes820eced2021-08-20 18:00:50 -07002076 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_P));
JP Abgrall53f17a92014-02-12 14:02:41 -08002077 return cp;
2078trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002079 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_P));
JP Abgrall53f17a92014-02-12 14:02:41 -08002080 return NULL;
2081}
2082
2083static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002084ikev2_sa_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002085 const struct isakmp_gen *ext1,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002086 u_int osa_length, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002087 uint32_t phase _U_, uint32_t doi _U_,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002088 uint32_t proto _U_, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08002089{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002090 const struct isakmp_gen *ext;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002091 u_int sa_length;
2092 const u_char *cp;
2093 int i;
2094 int pcount;
2095 u_char np;
2096 u_int item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002097
Elliott Hughes820eced2021-08-20 18:00:50 -07002098 ND_TCHECK_SIZE(ext1);
2099 ikev2_pay_print(ndo, "sa", GET_U_1(ext1->critical));
JP Abgrall53f17a92014-02-12 14:02:41 -08002100
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002101 /*
2102 * ikev2_sub0_print() guarantees that this is >= 4.
2103 */
Elliott Hughes820eced2021-08-20 18:00:50 -07002104 osa_length= GET_BE_U_2(ext1->len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002105 sa_length = osa_length - 4;
Elliott Hughes820eced2021-08-20 18:00:50 -07002106 ND_PRINT(" len=%u", sa_length);
JP Abgrall53f17a92014-02-12 14:02:41 -08002107
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002108 /*
2109 * Print the payloads.
2110 */
2111 cp = (const u_char *)(ext1 + 1);
2112 pcount = 0;
Elliott Hughes820eced2021-08-20 18:00:50 -07002113 for (np = ISAKMP_NPTYPE_P; np != 0; np = GET_U_1(ext->np)) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002114 pcount++;
2115 ext = (const struct isakmp_gen *)cp;
2116 if (sa_length < sizeof(*ext))
2117 goto toolong;
Elliott Hughes820eced2021-08-20 18:00:50 -07002118 ND_TCHECK_SIZE(ext);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002119
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 */
Elliott Hughes820eced2021-08-20 18:00:50 -07002126 item_len = GET_BE_U_2(ext->len);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002127 if (item_len <= 4)
2128 goto trunc;
2129
2130 if (sa_length < item_len)
2131 goto toolong;
Elliott Hughes820eced2021-08-20 18:00:50 -07002132 ND_TCHECK_LEN(cp, item_len);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002133
2134 depth++;
Elliott Hughes820eced2021-08-20 18:00:50 -07002135 ND_PRINT("\n");
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002136 for (i = 0; i < depth; i++)
Elliott Hughes820eced2021-08-20 18:00:50 -07002137 ND_PRINT(" ");
2138 ND_PRINT("(");
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002139 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 {
Elliott Hughes820eced2021-08-20 18:00:50 -07002147 ND_PRINT("%s", NPSTR(np));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002148 cp += item_len;
2149 }
Elliott Hughes820eced2021-08-20 18:00:50 -07002150 ND_PRINT(")");
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002151 depth--;
2152 sa_length -= item_len;
2153 }
2154 return cp;
2155toolong:
2156 /*
2157 * Skip the rest of the SA.
2158 */
2159 cp += sa_length;
Elliott Hughes820eced2021-08-20 18:00:50 -07002160 ND_PRINT(" [|%s]", NPSTR(tpay));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002161 return cp;
JP Abgrall53f17a92014-02-12 14:02:41 -08002162trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002163 ND_PRINT(" [|%s]", NPSTR(tpay));
JP Abgrall53f17a92014-02-12 14:02:41 -08002164 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,
Elliott Hughes820eced2021-08-20 18:00:50 -07002170 u_int item_len, 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{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002174 const struct ikev2_ke *k;
JP Abgrall53f17a92014-02-12 14:02:41 -08002175
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002176 k = (const struct ikev2_ke *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07002177 ND_TCHECK_SIZE(k);
2178 ikev2_pay_print(ndo, NPSTR(tpay), GET_U_1(k->h.critical));
JP Abgrall53f17a92014-02-12 14:02:41 -08002179
Elliott Hughes820eced2021-08-20 18:00:50 -07002180 if (item_len < 8) {
2181 ND_PRINT(" len=%u < 8", item_len);
2182 return (const u_char *)ext + item_len;
2183 }
2184 ND_PRINT(" len=%u group=%s", item_len - 8,
2185 STR_OR_ID(GET_BE_U_2(k->ke_group), dh_p_map));
Elliott Hughes892a68b2015-10-19 14:43:53 -07002186
Elliott Hughes820eced2021-08-20 18:00:50 -07002187 if (2 < ndo->ndo_vflag && 8 < item_len) {
2188 ND_PRINT(" ");
2189 if (!rawprint(ndo, (const uint8_t *)(k + 1), item_len - 8))
JP Abgrall53f17a92014-02-12 14:02:41 -08002190 goto trunc;
2191 }
Elliott Hughes820eced2021-08-20 18:00:50 -07002192 return (const u_char *)ext + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002193trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002194 ND_PRINT(" [|%s]", NPSTR(tpay));
JP Abgrall53f17a92014-02-12 14:02:41 -08002195 return NULL;
2196}
2197
2198static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002199ikev2_ID_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002200 const struct isakmp_gen *ext,
Elliott Hughes820eced2021-08-20 18:00:50 -07002201 u_int item_len, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002202 uint32_t phase _U_, uint32_t doi _U_,
2203 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002204{
Elliott Hughescec480a2017-12-19 16:54:57 -08002205 const struct ikev2_id *idp;
Elliott Hughes820eced2021-08-20 18:00:50 -07002206 u_int idtype_len, i;
JP Abgrall53f17a92014-02-12 14:02:41 -08002207 unsigned int dumpascii, dumphex;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002208 const unsigned char *typedata;
JP Abgrall53f17a92014-02-12 14:02:41 -08002209
Elliott Hughescec480a2017-12-19 16:54:57 -08002210 idp = (const struct ikev2_id *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07002211 ND_TCHECK_SIZE(idp);
2212 ikev2_pay_print(ndo, NPSTR(tpay), GET_U_1(idp->h.critical));
JP Abgrall53f17a92014-02-12 14:02:41 -08002213
Elliott Hughes820eced2021-08-20 18:00:50 -07002214 /*
2215 * Our caller has ensured that the length is >= 4.
2216 */
2217 ND_PRINT(" len=%u", item_len - 4);
2218 if (2 < ndo->ndo_vflag && 4 < item_len) {
Elliott Hughescec480a2017-12-19 16:54:57 -08002219 /* Print the entire payload in hex */
Elliott Hughes820eced2021-08-20 18:00:50 -07002220 ND_PRINT(" ");
2221 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08002222 goto trunc;
2223 }
2224
Elliott Hughes820eced2021-08-20 18:00:50 -07002225 idtype_len =item_len - sizeof(struct ikev2_id);
JP Abgrall53f17a92014-02-12 14:02:41 -08002226 dumpascii = 0;
2227 dumphex = 0;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002228 typedata = (const unsigned char *)(ext)+sizeof(struct ikev2_id);
JP Abgrall53f17a92014-02-12 14:02:41 -08002229
Elliott Hughes820eced2021-08-20 18:00:50 -07002230 switch(GET_U_1(idp->type)) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002231 case ID_IPV4_ADDR:
Elliott Hughes820eced2021-08-20 18:00:50 -07002232 ND_PRINT(" ipv4:");
JP Abgrall53f17a92014-02-12 14:02:41 -08002233 dumphex=1;
2234 break;
2235 case ID_FQDN:
Elliott Hughes820eced2021-08-20 18:00:50 -07002236 ND_PRINT(" fqdn:");
JP Abgrall53f17a92014-02-12 14:02:41 -08002237 dumpascii=1;
2238 break;
2239 case ID_RFC822_ADDR:
Elliott Hughes820eced2021-08-20 18:00:50 -07002240 ND_PRINT(" rfc822:");
JP Abgrall53f17a92014-02-12 14:02:41 -08002241 dumpascii=1;
2242 break;
2243 case ID_IPV6_ADDR:
Elliott Hughes820eced2021-08-20 18:00:50 -07002244 ND_PRINT(" ipv6:");
JP Abgrall53f17a92014-02-12 14:02:41 -08002245 dumphex=1;
2246 break;
2247 case ID_DER_ASN1_DN:
Elliott Hughes820eced2021-08-20 18:00:50 -07002248 ND_PRINT(" dn:");
JP Abgrall53f17a92014-02-12 14:02:41 -08002249 dumphex=1;
2250 break;
2251 case ID_DER_ASN1_GN:
Elliott Hughes820eced2021-08-20 18:00:50 -07002252 ND_PRINT(" gn:");
JP Abgrall53f17a92014-02-12 14:02:41 -08002253 dumphex=1;
2254 break;
2255 case ID_KEY_ID:
Elliott Hughes820eced2021-08-20 18:00:50 -07002256 ND_PRINT(" keyid:");
JP Abgrall53f17a92014-02-12 14:02:41 -08002257 dumphex=1;
2258 break;
2259 }
2260
2261 if(dumpascii) {
Elliott Hughes820eced2021-08-20 18:00:50 -07002262 ND_TCHECK_LEN(typedata, idtype_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002263 for(i=0; i<idtype_len; i++) {
Elliott Hughes820eced2021-08-20 18:00:50 -07002264 if(ND_ASCII_ISPRINT(GET_U_1(typedata + i))) {
2265 ND_PRINT("%c", GET_U_1(typedata + i));
JP Abgrall53f17a92014-02-12 14:02:41 -08002266 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -07002267 ND_PRINT(".");
JP Abgrall53f17a92014-02-12 14:02:41 -08002268 }
2269 }
2270 }
2271 if(dumphex) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002272 if (!rawprint(ndo, (const uint8_t *)typedata, idtype_len))
JP Abgrall53f17a92014-02-12 14:02:41 -08002273 goto trunc;
2274 }
2275
Elliott Hughes820eced2021-08-20 18:00:50 -07002276 return (const u_char *)ext + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002277trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002278 ND_PRINT(" [|%s]", NPSTR(tpay));
JP Abgrall53f17a92014-02-12 14:02:41 -08002279 return NULL;
2280}
2281
2282static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002283ikev2_cert_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002284 const struct isakmp_gen *ext,
Elliott Hughes820eced2021-08-20 18:00:50 -07002285 u_int item_len, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002286 uint32_t phase _U_, uint32_t doi _U_,
2287 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002288{
Elliott Hughes820eced2021-08-20 18:00:50 -07002289 return ikev2_gen_print(ndo, tpay, ext, item_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002290}
2291
2292static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002293ikev2_cr_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002294 const struct isakmp_gen *ext,
Elliott Hughes820eced2021-08-20 18:00:50 -07002295 u_int item_len, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002296 uint32_t phase _U_, uint32_t doi _U_,
2297 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002298{
Elliott Hughes820eced2021-08-20 18:00:50 -07002299 return ikev2_gen_print(ndo, tpay, ext, item_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002300}
2301
2302static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002303ikev2_auth_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002304 const struct isakmp_gen *ext,
Elliott Hughes820eced2021-08-20 18:00:50 -07002305 u_int item_len, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002306 uint32_t phase _U_, uint32_t doi _U_,
2307 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002308{
Elliott Hughes820eced2021-08-20 18:00:50 -07002309 const struct ikev2_auth *p;
JP Abgrall53f17a92014-02-12 14:02:41 -08002310 const char *v2_auth[]={ "invalid", "rsasig",
2311 "shared-secret", "dsssig" };
Elliott Hughes820eced2021-08-20 18:00:50 -07002312 const u_char *authdata = (const u_char*)ext + sizeof(struct ikev2_auth);
JP Abgrall53f17a92014-02-12 14:02:41 -08002313
Elliott Hughes820eced2021-08-20 18:00:50 -07002314 ND_TCHECK_LEN(ext, sizeof(struct ikev2_auth));
2315 p = (const struct ikev2_auth *)ext;
2316 ikev2_pay_print(ndo, NPSTR(tpay), GET_U_1(p->h.critical));
JP Abgrall53f17a92014-02-12 14:02:41 -08002317
Elliott Hughescec480a2017-12-19 16:54:57 -08002318 /*
2319 * Our caller has ensured that the length is >= 4.
2320 */
Elliott Hughes820eced2021-08-20 18:00:50 -07002321 ND_PRINT(" len=%u method=%s", item_len-4,
2322 STR_OR_ID(GET_U_1(p->auth_method), v2_auth));
2323 if (item_len > 4) {
Elliott Hughescec480a2017-12-19 16:54:57 -08002324 if (ndo->ndo_vflag > 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -07002325 ND_PRINT(" authdata=(");
2326 if (!rawprint(ndo, (const uint8_t *)authdata, item_len - sizeof(struct ikev2_auth)))
Elliott Hughescec480a2017-12-19 16:54:57 -08002327 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07002328 ND_PRINT(") ");
Elliott Hughescec480a2017-12-19 16:54:57 -08002329 } else if (ndo->ndo_vflag) {
2330 if (!ike_show_somedata(ndo, authdata, ep))
2331 goto trunc;
2332 }
JP Abgrall53f17a92014-02-12 14:02:41 -08002333 }
2334
Elliott Hughes820eced2021-08-20 18:00:50 -07002335 return (const u_char *)ext + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002336trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002337 ND_PRINT(" [|%s]", NPSTR(tpay));
JP Abgrall53f17a92014-02-12 14:02:41 -08002338 return NULL;
2339}
2340
2341static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002342ikev2_nonce_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002343 const struct isakmp_gen *ext,
Elliott Hughes820eced2021-08-20 18:00:50 -07002344 u_int item_len, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002345 uint32_t phase _U_, uint32_t doi _U_,
2346 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002347{
Elliott Hughes820eced2021-08-20 18:00:50 -07002348 ND_TCHECK_SIZE(ext);
2349 ikev2_pay_print(ndo, "nonce", GET_U_1(ext->critical));
JP Abgrall53f17a92014-02-12 14:02:41 -08002350
Elliott Hughes820eced2021-08-20 18:00:50 -07002351 /*
2352 * Our caller has ensured that the length is >= 4.
2353 */
2354 ND_PRINT(" len=%u", item_len - 4);
2355 if (1 < ndo->ndo_vflag && 4 < item_len) {
2356 ND_PRINT(" nonce=(");
2357 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08002358 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07002359 ND_PRINT(") ");
2360 } else if(ndo->ndo_vflag && 4 < item_len) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002361 if(!ike_show_somedata(ndo, (const u_char *)(ext+1), ep)) goto trunc;
2362 }
2363
Elliott Hughes820eced2021-08-20 18:00:50 -07002364 return (const u_char *)ext + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002365trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002366 ND_PRINT(" [|%s]", NPSTR(tpay));
JP Abgrall53f17a92014-02-12 14:02:41 -08002367 return NULL;
2368}
2369
2370/* notify payloads */
2371static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002372ikev2_n_print(netdissect_options *ndo, u_char tpay _U_,
JP Abgrall53f17a92014-02-12 14:02:41 -08002373 const struct isakmp_gen *ext,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002374 u_int item_len, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002375 uint32_t phase _U_, uint32_t doi _U_,
2376 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002377{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002378 const struct ikev2_n *p;
Elliott Hughes820eced2021-08-20 18:00:50 -07002379 uint16_t type;
2380 uint8_t spi_size;
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;
JP Abgrall53f17a92014-02-12 14:02:41 -08002384
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002385 p = (const struct ikev2_n *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07002386 ND_TCHECK_SIZE(p);
2387 ikev2_pay_print(ndo, NPSTR(ISAKMP_NPTYPE_N), GET_U_1(p->h.critical));
JP Abgrall53f17a92014-02-12 14:02:41 -08002388
2389 showspi = 1;
JP Abgrall53f17a92014-02-12 14:02:41 -08002390 showsomedata=0;
2391 notify_name=NULL;
2392
Elliott Hughes820eced2021-08-20 18:00:50 -07002393 ND_PRINT(" prot_id=%s", PROTOIDSTR(GET_U_1(p->prot_id)));
JP Abgrall53f17a92014-02-12 14:02:41 -08002394
Elliott Hughes820eced2021-08-20 18:00:50 -07002395 type = GET_BE_U_2(p->type);
JP Abgrall53f17a92014-02-12 14:02:41 -08002396
2397 /* notify space is annoying sparse */
2398 switch(type) {
2399 case IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD:
2400 notify_name = "unsupported_critical_payload";
2401 showspi = 0;
2402 break;
2403
2404 case IV2_NOTIFY_INVALID_IKE_SPI:
2405 notify_name = "invalid_ike_spi";
2406 showspi = 1;
2407 break;
2408
2409 case IV2_NOTIFY_INVALID_MAJOR_VERSION:
2410 notify_name = "invalid_major_version";
2411 showspi = 0;
2412 break;
2413
2414 case IV2_NOTIFY_INVALID_SYNTAX:
2415 notify_name = "invalid_syntax";
2416 showspi = 1;
2417 break;
2418
2419 case IV2_NOTIFY_INVALID_MESSAGE_ID:
2420 notify_name = "invalid_message_id";
2421 showspi = 1;
2422 break;
2423
2424 case IV2_NOTIFY_INVALID_SPI:
2425 notify_name = "invalid_spi";
2426 showspi = 1;
2427 break;
2428
2429 case IV2_NOTIFY_NO_PROPOSAL_CHOSEN:
2430 notify_name = "no_protocol_chosen";
2431 showspi = 1;
2432 break;
2433
2434 case IV2_NOTIFY_INVALID_KE_PAYLOAD:
2435 notify_name = "invalid_ke_payload";
2436 showspi = 1;
2437 break;
2438
2439 case IV2_NOTIFY_AUTHENTICATION_FAILED:
2440 notify_name = "authentication_failed";
2441 showspi = 1;
2442 break;
2443
2444 case IV2_NOTIFY_SINGLE_PAIR_REQUIRED:
2445 notify_name = "single_pair_required";
2446 showspi = 1;
2447 break;
2448
2449 case IV2_NOTIFY_NO_ADDITIONAL_SAS:
2450 notify_name = "no_additional_sas";
2451 showspi = 0;
2452 break;
2453
2454 case IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE:
2455 notify_name = "internal_address_failure";
2456 showspi = 0;
2457 break;
2458
Elliott Hughes892a68b2015-10-19 14:43:53 -07002459 case IV2_NOTIFY_FAILED_CP_REQUIRED:
JP Abgrall53f17a92014-02-12 14:02:41 -08002460 notify_name = "failed:cp_required";
2461 showspi = 0;
2462 break;
2463
2464 case IV2_NOTIFY_INVALID_SELECTORS:
2465 notify_name = "invalid_selectors";
2466 showspi = 0;
2467 break;
2468
2469 case IV2_NOTIFY_INITIAL_CONTACT:
2470 notify_name = "initial_contact";
2471 showspi = 0;
2472 break;
2473
Elliott Hughes892a68b2015-10-19 14:43:53 -07002474 case IV2_NOTIFY_SET_WINDOW_SIZE:
JP Abgrall53f17a92014-02-12 14:02:41 -08002475 notify_name = "set_window_size";
2476 showspi = 0;
2477 break;
2478
2479 case IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE:
2480 notify_name = "additional_ts_possible";
2481 showspi = 0;
2482 break;
2483
Elliott Hughes892a68b2015-10-19 14:43:53 -07002484 case IV2_NOTIFY_IPCOMP_SUPPORTED:
JP Abgrall53f17a92014-02-12 14:02:41 -08002485 notify_name = "ipcomp_supported";
2486 showspi = 0;
2487 break;
2488
2489 case IV2_NOTIFY_NAT_DETECTION_SOURCE_IP:
2490 notify_name = "nat_detection_source_ip";
2491 showspi = 1;
2492 break;
2493
2494 case IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP:
2495 notify_name = "nat_detection_destination_ip";
2496 showspi = 1;
2497 break;
2498
2499 case IV2_NOTIFY_COOKIE:
2500 notify_name = "cookie";
2501 showspi = 1;
2502 showsomedata= 1;
JP Abgrall53f17a92014-02-12 14:02:41 -08002503 break;
2504
2505 case IV2_NOTIFY_USE_TRANSPORT_MODE:
2506 notify_name = "use_transport_mode";
2507 showspi = 0;
2508 break;
2509
2510 case IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED:
2511 notify_name = "http_cert_lookup_supported";
2512 showspi = 0;
2513 break;
2514
2515 case IV2_NOTIFY_REKEY_SA:
2516 notify_name = "rekey_sa";
2517 showspi = 1;
2518 break;
2519
2520 case IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED:
2521 notify_name = "tfc_padding_not_supported";
2522 showspi = 0;
2523 break;
2524
2525 case IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO:
2526 notify_name = "non_first_fragment_also";
2527 showspi = 0;
2528 break;
2529
2530 default:
2531 if (type < 8192) {
2532 notify_name="error";
2533 } else if(type < 16384) {
2534 notify_name="private-error";
2535 } else if(type < 40960) {
2536 notify_name="status";
2537 } else {
2538 notify_name="private-status";
2539 }
2540 }
2541
2542 if(notify_name) {
Elliott Hughes820eced2021-08-20 18:00:50 -07002543 ND_PRINT(" type=%u(%s)", type, notify_name);
JP Abgrall53f17a92014-02-12 14:02:41 -08002544 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002545
JP Abgrall53f17a92014-02-12 14:02:41 -08002546
Elliott Hughes820eced2021-08-20 18:00:50 -07002547 spi_size = GET_U_1(p->spi_size);
2548 if (showspi && spi_size) {
2549 ND_PRINT(" spi=");
2550 if (!rawprint(ndo, (const uint8_t *)(p + 1), spi_size))
JP Abgrall53f17a92014-02-12 14:02:41 -08002551 goto trunc;
2552 }
2553
Elliott Hughes820eced2021-08-20 18:00:50 -07002554 cp = (const u_char *)(p + 1) + spi_size;
JP Abgrall53f17a92014-02-12 14:02:41 -08002555
Elliott Hughescec480a2017-12-19 16:54:57 -08002556 if (cp < ep) {
2557 if (ndo->ndo_vflag > 3 || (showsomedata && ep-cp < 30)) {
Elliott Hughes820eced2021-08-20 18:00:50 -07002558 ND_PRINT(" data=(");
Elliott Hughescec480a2017-12-19 16:54:57 -08002559 if (!rawprint(ndo, (const uint8_t *)(cp), ep - cp))
2560 goto trunc;
JP Abgrall53f17a92014-02-12 14:02:41 -08002561
Elliott Hughes820eced2021-08-20 18:00:50 -07002562 ND_PRINT(")");
Elliott Hughescec480a2017-12-19 16:54:57 -08002563 } else if (showsomedata) {
2564 if (!ike_show_somedata(ndo, cp, ep))
2565 goto trunc;
2566 }
JP Abgrall53f17a92014-02-12 14:02:41 -08002567 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002568
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002569 return (const u_char *)ext + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002570trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002571 ND_PRINT(" [|%s]", NPSTR(ISAKMP_NPTYPE_N));
JP Abgrall53f17a92014-02-12 14:02:41 -08002572 return NULL;
2573}
2574
2575static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002576ikev2_d_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002577 const struct isakmp_gen *ext,
Elliott Hughes820eced2021-08-20 18:00:50 -07002578 u_int item_len, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002579 uint32_t phase _U_, uint32_t doi _U_,
2580 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002581{
Elliott Hughes820eced2021-08-20 18:00:50 -07002582 return ikev2_gen_print(ndo, tpay, ext, item_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002583}
2584
2585static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002586ikev2_vid_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002587 const struct isakmp_gen *ext,
Elliott Hughes820eced2021-08-20 18:00:50 -07002588 u_int item_len, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002589 uint32_t phase _U_, uint32_t doi _U_,
2590 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002591{
JP Abgrall53f17a92014-02-12 14:02:41 -08002592 const u_char *vid;
Elliott Hughes820eced2021-08-20 18:00:50 -07002593 u_int i, len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002594
Elliott Hughes820eced2021-08-20 18:00:50 -07002595 ND_TCHECK_SIZE(ext);
2596 ikev2_pay_print(ndo, NPSTR(tpay), GET_U_1(ext->critical));
2597
2598 /*
2599 * Our caller has ensured that the length is >= 4.
2600 */
2601 ND_PRINT(" len=%u vid=", item_len - 4);
JP Abgrall53f17a92014-02-12 14:02:41 -08002602
2603 vid = (const u_char *)(ext+1);
Elliott Hughes820eced2021-08-20 18:00:50 -07002604 len = item_len - 4;
2605 ND_TCHECK_LEN(vid, len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002606 for(i=0; i<len; i++) {
Elliott Hughes820eced2021-08-20 18:00:50 -07002607 if(ND_ASCII_ISPRINT(GET_U_1(vid + i)))
2608 ND_PRINT("%c", GET_U_1(vid + i));
2609 else ND_PRINT(".");
JP Abgrall53f17a92014-02-12 14:02:41 -08002610 }
2611 if (2 < ndo->ndo_vflag && 4 < len) {
Elliott Hughescec480a2017-12-19 16:54:57 -08002612 /* Print the entire payload in hex */
Elliott Hughes820eced2021-08-20 18:00:50 -07002613 ND_PRINT(" ");
2614 if (!rawprint(ndo, (const uint8_t *)(ext + 1), item_len - 4))
JP Abgrall53f17a92014-02-12 14:02:41 -08002615 goto trunc;
2616 }
Elliott Hughes820eced2021-08-20 18:00:50 -07002617 return (const u_char *)ext + item_len;
JP Abgrall53f17a92014-02-12 14:02:41 -08002618trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002619 ND_PRINT(" [|%s]", NPSTR(tpay));
JP Abgrall53f17a92014-02-12 14:02:41 -08002620 return NULL;
2621}
2622
2623static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002624ikev2_TS_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002625 const struct isakmp_gen *ext,
Elliott Hughes820eced2021-08-20 18:00:50 -07002626 u_int item_len, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002627 uint32_t phase _U_, uint32_t doi _U_,
2628 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002629{
Elliott Hughes820eced2021-08-20 18:00:50 -07002630 return ikev2_gen_print(ndo, tpay, ext, item_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002631}
2632
2633static const u_char *
2634ikev2_e_print(netdissect_options *ndo,
2635#ifndef HAVE_LIBCRYPTO
2636 _U_
2637#endif
Elliott Hughes820eced2021-08-20 18:00:50 -07002638 const struct isakmp *base,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002639 u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002640 const struct isakmp_gen *ext,
Elliott Hughes820eced2021-08-20 18:00:50 -07002641 u_int item_len, const u_char *ep _U_,
JP Abgrall53f17a92014-02-12 14:02:41 -08002642#ifndef HAVE_LIBCRYPTO
2643 _U_
2644#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -07002645 uint32_t phase,
JP Abgrall53f17a92014-02-12 14:02:41 -08002646#ifndef HAVE_LIBCRYPTO
2647 _U_
2648#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -07002649 uint32_t doi,
JP Abgrall53f17a92014-02-12 14:02:41 -08002650#ifndef HAVE_LIBCRYPTO
2651 _U_
2652#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -07002653 uint32_t proto,
JP Abgrall53f17a92014-02-12 14:02:41 -08002654#ifndef HAVE_LIBCRYPTO
2655 _U_
2656#endif
2657 int depth)
2658{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002659 const u_char *dat;
Elliott Hughes820eced2021-08-20 18:00:50 -07002660 u_int dlen;
2661#ifdef HAVE_LIBCRYPTO
2662 uint8_t np;
2663#endif
JP Abgrall53f17a92014-02-12 14:02:41 -08002664
Elliott Hughes820eced2021-08-20 18:00:50 -07002665 ND_TCHECK_SIZE(ext);
2666 ikev2_pay_print(ndo, NPSTR(tpay), GET_U_1(ext->critical));
JP Abgrall53f17a92014-02-12 14:02:41 -08002667
Elliott Hughes820eced2021-08-20 18:00:50 -07002668 dlen = item_len-4;
JP Abgrall53f17a92014-02-12 14:02:41 -08002669
Elliott Hughes820eced2021-08-20 18:00:50 -07002670 ND_PRINT(" len=%u", dlen);
JP Abgrall53f17a92014-02-12 14:02:41 -08002671 if (2 < ndo->ndo_vflag && 4 < dlen) {
Elliott Hughes820eced2021-08-20 18:00:50 -07002672 ND_PRINT(" ");
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002673 if (!rawprint(ndo, (const uint8_t *)(ext + 1), dlen))
JP Abgrall53f17a92014-02-12 14:02:41 -08002674 goto trunc;
2675 }
2676
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002677 dat = (const u_char *)(ext+1);
Elliott Hughes820eced2021-08-20 18:00:50 -07002678 ND_TCHECK_LEN(dat, dlen);
Elliott Hughes892a68b2015-10-19 14:43:53 -07002679
JP Abgrall53f17a92014-02-12 14:02:41 -08002680#ifdef HAVE_LIBCRYPTO
Elliott Hughes820eced2021-08-20 18:00:50 -07002681 np = GET_U_1(ext->np);
2682
2683 /* try to decrypt it! */
2684 if(esp_decrypt_buffer_by_ikev2_print(ndo,
2685 GET_U_1(base->flags) & ISAKMP_FLAG_I,
JP Abgrall53f17a92014-02-12 14:02:41 -08002686 base->i_ck, base->r_ck,
2687 dat, dat+dlen)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07002688
JP Abgrall53f17a92014-02-12 14:02:41 -08002689 ext = (const struct isakmp_gen *)ndo->ndo_packetp;
2690
2691 /* got it decrypted, print stuff inside. */
Elliott Hughes820eced2021-08-20 18:00:50 -07002692 ikev2_sub_print(ndo, base, np, ext,
2693 ndo->ndo_snapend, phase, doi, proto, depth+1);
2694
2695 /*
2696 * esp_decrypt_buffer_by_ikev2_print pushed information
2697 * on the buffer stack; we're done with the buffer, so
2698 * pop it (which frees the buffer)
2699 */
2700 nd_pop_packet_info(ndo);
JP Abgrall53f17a92014-02-12 14:02:41 -08002701 }
2702#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -07002703
JP Abgrall53f17a92014-02-12 14:02:41 -08002704
2705 /* always return NULL, because E must be at end, and NP refers
2706 * to what was inside.
2707 */
2708 return NULL;
2709trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002710 ND_PRINT(" [|%s]", NPSTR(tpay));
JP Abgrall53f17a92014-02-12 14:02:41 -08002711 return NULL;
2712}
2713
2714static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002715ikev2_cp_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002716 const struct isakmp_gen *ext,
Elliott Hughes820eced2021-08-20 18:00:50 -07002717 u_int item_len, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002718 uint32_t phase _U_, uint32_t doi _U_,
2719 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002720{
Elliott Hughes820eced2021-08-20 18:00:50 -07002721 return ikev2_gen_print(ndo, tpay, ext, item_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002722}
2723
2724static const u_char *
Elliott Hughes892a68b2015-10-19 14:43:53 -07002725ikev2_eap_print(netdissect_options *ndo, u_char tpay,
JP Abgrall53f17a92014-02-12 14:02:41 -08002726 const struct isakmp_gen *ext,
Elliott Hughes820eced2021-08-20 18:00:50 -07002727 u_int item_len, const u_char *ep _U_,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002728 uint32_t phase _U_, uint32_t doi _U_,
2729 uint32_t proto _U_, int depth _U_)
JP Abgrall53f17a92014-02-12 14:02:41 -08002730{
Elliott Hughes820eced2021-08-20 18:00:50 -07002731 return ikev2_gen_print(ndo, tpay, ext, item_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002732}
2733
2734static const u_char *
2735ike_sub0_print(netdissect_options *ndo,
2736 u_char np, const struct isakmp_gen *ext, const u_char *ep,
2737
Elliott Hughes892a68b2015-10-19 14:43:53 -07002738 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002739{
2740 const u_char *cp;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002741 u_int item_len;
2742
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002743 cp = (const u_char *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07002744 ND_TCHECK_SIZE(ext);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002745
2746 /*
2747 * Since we can't have a payload length of less than 4 bytes,
2748 * we need to bail out here if the generic header is nonsensical
2749 * or truncated, otherwise we could loop forever processing
2750 * zero-length items or otherwise misdissect the packet.
2751 */
Elliott Hughes820eced2021-08-20 18:00:50 -07002752 item_len = GET_BE_U_2(ext->len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002753 if (item_len <= 4)
2754 return NULL;
2755
2756 if (NPFUNC(np)) {
2757 /*
2758 * XXX - what if item_len is too short, or too long,
2759 * for this payload type?
2760 */
JP Abgrall53f17a92014-02-12 14:02:41 -08002761 cp = (*npfunc[np])(ndo, np, ext, item_len, ep, phase, doi, proto, depth);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002762 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -07002763 ND_PRINT("%s", NPSTR(np));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002764 cp += item_len;
2765 }
2766
2767 return cp;
2768trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002769 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002770 return NULL;
2771}
2772
2773static const u_char *
JP Abgrall53f17a92014-02-12 14:02:41 -08002774ikev1_sub_print(netdissect_options *ndo,
2775 u_char np, const struct isakmp_gen *ext, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002776 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002777{
2778 const u_char *cp;
2779 int i;
Elliott Hughes820eced2021-08-20 18:00:50 -07002780 u_int item_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002781
2782 cp = (const u_char *)ext;
2783
2784 while (np) {
Elliott Hughes820eced2021-08-20 18:00:50 -07002785 ND_TCHECK_SIZE(ext);
JP Abgrall53f17a92014-02-12 14:02:41 -08002786
Elliott Hughes820eced2021-08-20 18:00:50 -07002787 item_len = GET_BE_U_2(ext->len);
2788 ND_TCHECK_LEN(ext, item_len);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002789
2790 depth++;
Elliott Hughes820eced2021-08-20 18:00:50 -07002791 ND_PRINT("\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -08002792 for (i = 0; i < depth; i++)
Elliott Hughes820eced2021-08-20 18:00:50 -07002793 ND_PRINT(" ");
2794 ND_PRINT("(");
JP Abgrall53f17a92014-02-12 14:02:41 -08002795 cp = ike_sub0_print(ndo, np, ext, ep, phase, doi, proto, depth);
Elliott Hughes820eced2021-08-20 18:00:50 -07002796 ND_PRINT(")");
The Android Open Source Project2949f582009-03-03 19:30:46 -08002797 depth--;
2798
2799 if (cp == NULL) {
2800 /* Zero-length subitem */
2801 return NULL;
2802 }
2803
Elliott Hughes820eced2021-08-20 18:00:50 -07002804 np = GET_U_1(ext->np);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002805 ext = (const struct isakmp_gen *)cp;
The Android Open Source Project2949f582009-03-03 19:30:46 -08002806 }
2807 return cp;
2808trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002809 ND_PRINT(" [|%s]", NPSTR(np));
The Android Open Source Project2949f582009-03-03 19:30:46 -08002810 return NULL;
2811}
2812
2813static char *
Elliott Hughes820eced2021-08-20 18:00:50 -07002814numstr(u_int x)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002815{
2816 static char buf[20];
Elliott Hughes820eced2021-08-20 18:00:50 -07002817 snprintf(buf, sizeof(buf), "#%u", x);
The Android Open Source Project2949f582009-03-03 19:30:46 -08002818 return buf;
2819}
2820
The Android Open Source Project2949f582009-03-03 19:30:46 -08002821static void
JP Abgrall53f17a92014-02-12 14:02:41 -08002822ikev1_print(netdissect_options *ndo,
2823 const u_char *bp, u_int length,
Elliott Hughes820eced2021-08-20 18:00:50 -07002824 const u_char *bp2, const struct isakmp *base)
The Android Open Source Project2949f582009-03-03 19:30:46 -08002825{
JP Abgrall53f17a92014-02-12 14:02:41 -08002826 const struct isakmp *p;
2827 const u_char *ep;
Elliott Hughes820eced2021-08-20 18:00:50 -07002828 u_int flags;
JP Abgrall53f17a92014-02-12 14:02:41 -08002829 u_char np;
2830 int i;
Elliott Hughes820eced2021-08-20 18:00:50 -07002831 u_int phase;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002832
JP Abgrall53f17a92014-02-12 14:02:41 -08002833 p = (const struct isakmp *)bp;
2834 ep = ndo->ndo_snapend;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002835
Elliott Hughes820eced2021-08-20 18:00:50 -07002836 phase = (GET_BE_U_4(base->msgid) == 0) ? 1 : 2;
JP Abgrall53f17a92014-02-12 14:02:41 -08002837 if (phase == 1)
Elliott Hughes820eced2021-08-20 18:00:50 -07002838 ND_PRINT(" phase %u", phase);
JP Abgrall53f17a92014-02-12 14:02:41 -08002839 else
Elliott Hughes820eced2021-08-20 18:00:50 -07002840 ND_PRINT(" phase %u/others", phase);
Elliott Hughes892a68b2015-10-19 14:43:53 -07002841
JP Abgrall53f17a92014-02-12 14:02:41 -08002842 i = cookie_find(&base->i_ck);
2843 if (i < 0) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002844 if (iszero((const u_char *)&base->r_ck, sizeof(base->r_ck))) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002845 /* the first packet */
Elliott Hughes820eced2021-08-20 18:00:50 -07002846 ND_PRINT(" I");
JP Abgrall53f17a92014-02-12 14:02:41 -08002847 if (bp2)
Elliott Hughes820eced2021-08-20 18:00:50 -07002848 cookie_record(ndo, &base->i_ck, bp2);
JP Abgrall53f17a92014-02-12 14:02:41 -08002849 } else
Elliott Hughes820eced2021-08-20 18:00:50 -07002850 ND_PRINT(" ?");
JP Abgrall53f17a92014-02-12 14:02:41 -08002851 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -07002852 if (bp2 && cookie_isinitiator(ndo, i, bp2))
2853 ND_PRINT(" I");
2854 else if (bp2 && cookie_isresponder(ndo, i, bp2))
2855 ND_PRINT(" R");
JP Abgrall53f17a92014-02-12 14:02:41 -08002856 else
Elliott Hughes820eced2021-08-20 18:00:50 -07002857 ND_PRINT(" ?");
JP Abgrall53f17a92014-02-12 14:02:41 -08002858 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002859
Elliott Hughes820eced2021-08-20 18:00:50 -07002860 ND_PRINT(" %s", ETYPESTR(GET_U_1(base->etype)));
2861 flags = GET_U_1(base->flags);
2862 if (flags) {
2863 ND_PRINT("[%s%s]", flags & ISAKMP_FLAG_E ? "E" : "",
2864 flags & ISAKMP_FLAG_C ? "C" : "");
JP Abgrall53f17a92014-02-12 14:02:41 -08002865 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002866
JP Abgrall53f17a92014-02-12 14:02:41 -08002867 if (ndo->ndo_vflag) {
2868 const struct isakmp_gen *ext;
Elliott Hughes892a68b2015-10-19 14:43:53 -07002869
Elliott Hughes820eced2021-08-20 18:00:50 -07002870 ND_PRINT(":");
2871
2872 np = GET_U_1(base->np);
Elliott Hughes892a68b2015-10-19 14:43:53 -07002873
JP Abgrall53f17a92014-02-12 14:02:41 -08002874 /* regardless of phase... */
Elliott Hughes820eced2021-08-20 18:00:50 -07002875 if (flags & ISAKMP_FLAG_E) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002876 /*
2877 * encrypted, nothing we can do right now.
2878 * we hope to decrypt the packet in the future...
2879 */
Elliott Hughes820eced2021-08-20 18:00:50 -07002880 ND_PRINT(" [encrypted %s]", NPSTR(np));
JP Abgrall53f17a92014-02-12 14:02:41 -08002881 goto done;
2882 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002883
Elliott Hughes820eced2021-08-20 18:00:50 -07002884 CHECKLEN(p + 1, np);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002885 ext = (const struct isakmp_gen *)(p + 1);
JP Abgrall53f17a92014-02-12 14:02:41 -08002886 ikev1_sub_print(ndo, np, ext, ep, phase, 0, 0, 0);
2887 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07002888
JP Abgrall53f17a92014-02-12 14:02:41 -08002889done:
2890 if (ndo->ndo_vflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -07002891 if (GET_BE_U_4(base->len) != length) {
2892 ND_PRINT(" (len mismatch: isakmp %u/ip %u)",
2893 GET_BE_U_4(base->len), length);
JP Abgrall53f17a92014-02-12 14:02:41 -08002894 }
2895 }
2896}
2897
2898static const u_char *
Elliott Hughes820eced2021-08-20 18:00:50 -07002899ikev2_sub0_print(netdissect_options *ndo, const struct isakmp *base,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002900 u_char np,
JP Abgrall53f17a92014-02-12 14:02:41 -08002901 const struct isakmp_gen *ext, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002902 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08002903{
2904 const u_char *cp;
JP Abgrall53f17a92014-02-12 14:02:41 -08002905 u_int item_len;
2906
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002907 cp = (const u_char *)ext;
Elliott Hughes820eced2021-08-20 18:00:50 -07002908 ND_TCHECK_SIZE(ext);
JP Abgrall53f17a92014-02-12 14:02:41 -08002909
2910 /*
2911 * Since we can't have a payload length of less than 4 bytes,
2912 * we need to bail out here if the generic header is nonsensical
2913 * or truncated, otherwise we could loop forever processing
2914 * zero-length items or otherwise misdissect the packet.
2915 */
Elliott Hughes820eced2021-08-20 18:00:50 -07002916 item_len = GET_BE_U_2(ext->len);
JP Abgrall53f17a92014-02-12 14:02:41 -08002917 if (item_len <= 4)
2918 return NULL;
2919
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002920 if (np == ISAKMP_NPTYPE_v2E) {
JP Abgrall53f17a92014-02-12 14:02:41 -08002921 cp = ikev2_e_print(ndo, base, np, ext, item_len,
2922 ep, phase, doi, proto, depth);
2923 } else if (NPFUNC(np)) {
2924 /*
2925 * XXX - what if item_len is too short, or too long,
2926 * for this payload type?
2927 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002928 cp = (*npfunc[np])(ndo, np, ext, item_len,
JP Abgrall53f17a92014-02-12 14:02:41 -08002929 ep, phase, doi, proto, depth);
2930 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -07002931 ND_PRINT("%s", NPSTR(np));
JP Abgrall53f17a92014-02-12 14:02:41 -08002932 cp += item_len;
2933 }
2934
2935 return cp;
2936trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002937 nd_print_trunc(ndo);
JP Abgrall53f17a92014-02-12 14:02:41 -08002938 return NULL;
2939}
2940
2941static const u_char *
2942ikev2_sub_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -07002943 const struct isakmp *base,
JP Abgrall53f17a92014-02-12 14:02:41 -08002944 u_char np, const struct isakmp_gen *ext, const u_char *ep,
Elliott Hughes892a68b2015-10-19 14:43:53 -07002945 uint32_t phase, uint32_t doi, uint32_t proto, int depth)
JP Abgrall53f17a92014-02-12 14:02:41 -08002946{
2947 const u_char *cp;
2948 int i;
JP Abgrall53f17a92014-02-12 14:02:41 -08002949
2950 cp = (const u_char *)ext;
JP Abgrall53f17a92014-02-12 14:02:41 -08002951 while (np) {
Elliott Hughes820eced2021-08-20 18:00:50 -07002952 ND_TCHECK_SIZE(ext);
JP Abgrall53f17a92014-02-12 14:02:41 -08002953
Elliott Hughes820eced2021-08-20 18:00:50 -07002954 ND_TCHECK_LEN(ext, GET_BE_U_2(ext->len));
JP Abgrall53f17a92014-02-12 14:02:41 -08002955
2956 depth++;
Elliott Hughes820eced2021-08-20 18:00:50 -07002957 ND_PRINT("\n");
JP Abgrall53f17a92014-02-12 14:02:41 -08002958 for (i = 0; i < depth; i++)
Elliott Hughes820eced2021-08-20 18:00:50 -07002959 ND_PRINT(" ");
2960 ND_PRINT("(");
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002961 cp = ikev2_sub0_print(ndo, base, np,
JP Abgrall53f17a92014-02-12 14:02:41 -08002962 ext, ep, phase, doi, proto, depth);
Elliott Hughes820eced2021-08-20 18:00:50 -07002963 ND_PRINT(")");
JP Abgrall53f17a92014-02-12 14:02:41 -08002964 depth--;
2965
2966 if (cp == NULL) {
2967 /* Zero-length subitem */
2968 return NULL;
2969 }
2970
Elliott Hughes820eced2021-08-20 18:00:50 -07002971 np = GET_U_1(ext->np);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07002972 ext = (const struct isakmp_gen *)cp;
JP Abgrall53f17a92014-02-12 14:02:41 -08002973 }
2974 return cp;
2975trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07002976 ND_PRINT(" [|%s]", NPSTR(np));
JP Abgrall53f17a92014-02-12 14:02:41 -08002977 return NULL;
2978}
2979
2980static void
2981ikev2_print(netdissect_options *ndo,
2982 const u_char *bp, u_int length,
Elliott Hughes820eced2021-08-20 18:00:50 -07002983 const u_char *bp2 _U_, const struct isakmp *base)
JP Abgrall53f17a92014-02-12 14:02:41 -08002984{
2985 const struct isakmp *p;
2986 const u_char *ep;
Elliott Hughes820eced2021-08-20 18:00:50 -07002987 uint8_t flags;
JP Abgrall53f17a92014-02-12 14:02:41 -08002988 u_char np;
Elliott Hughes820eced2021-08-20 18:00:50 -07002989 u_int phase;
JP Abgrall53f17a92014-02-12 14:02:41 -08002990
2991 p = (const struct isakmp *)bp;
2992 ep = ndo->ndo_snapend;
2993
Elliott Hughes820eced2021-08-20 18:00:50 -07002994 phase = (GET_BE_U_4(base->msgid) == 0) ? 1 : 2;
JP Abgrall53f17a92014-02-12 14:02:41 -08002995 if (phase == 1)
Elliott Hughes820eced2021-08-20 18:00:50 -07002996 ND_PRINT(" parent_sa");
JP Abgrall53f17a92014-02-12 14:02:41 -08002997 else
Elliott Hughes820eced2021-08-20 18:00:50 -07002998 ND_PRINT(" child_sa ");
JP Abgrall53f17a92014-02-12 14:02:41 -08002999
Elliott Hughes820eced2021-08-20 18:00:50 -07003000 ND_PRINT(" %s", ETYPESTR(GET_U_1(base->etype)));
3001 flags = GET_U_1(base->flags);
3002 if (flags) {
3003 ND_PRINT("[%s%s%s]",
3004 flags & ISAKMP_FLAG_I ? "I" : "",
3005 flags & ISAKMP_FLAG_V ? "V" : "",
3006 flags & ISAKMP_FLAG_R ? "R" : "");
JP Abgrall53f17a92014-02-12 14:02:41 -08003007 }
3008
3009 if (ndo->ndo_vflag) {
3010 const struct isakmp_gen *ext;
3011
Elliott Hughes820eced2021-08-20 18:00:50 -07003012 ND_PRINT(":");
3013
3014 np = GET_U_1(base->np);
JP Abgrall53f17a92014-02-12 14:02:41 -08003015
3016 /* regardless of phase... */
Elliott Hughes820eced2021-08-20 18:00:50 -07003017 if (flags & ISAKMP_FLAG_E) {
JP Abgrall53f17a92014-02-12 14:02:41 -08003018 /*
3019 * encrypted, nothing we can do right now.
3020 * we hope to decrypt the packet in the future...
3021 */
Elliott Hughes820eced2021-08-20 18:00:50 -07003022 ND_PRINT(" [encrypted %s]", NPSTR(np));
JP Abgrall53f17a92014-02-12 14:02:41 -08003023 goto done;
3024 }
3025
Elliott Hughes820eced2021-08-20 18:00:50 -07003026 CHECKLEN(p + 1, np)
Elliott Hughese2e3bd12017-05-15 10:59:29 -07003027 ext = (const struct isakmp_gen *)(p + 1);
JP Abgrall53f17a92014-02-12 14:02:41 -08003028 ikev2_sub_print(ndo, base, np, ext, ep, phase, 0, 0, 0);
3029 }
3030
3031done:
3032 if (ndo->ndo_vflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -07003033 if (GET_BE_U_4(base->len) != length) {
3034 ND_PRINT(" (len mismatch: isakmp %u/ip %u)",
3035 GET_BE_U_4(base->len), length);
JP Abgrall53f17a92014-02-12 14:02:41 -08003036 }
3037 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08003038}
3039
3040void
3041isakmp_print(netdissect_options *ndo,
3042 const u_char *bp, u_int length,
3043 const u_char *bp2)
3044{
3045 const struct isakmp *p;
The Android Open Source Project2949f582009-03-03 19:30:46 -08003046 const u_char *ep;
Elliott Hughes820eced2021-08-20 18:00:50 -07003047 u_int major, minor;
The Android Open Source Project2949f582009-03-03 19:30:46 -08003048
Elliott Hughes820eced2021-08-20 18:00:50 -07003049 ndo->ndo_protocol = "isakmp";
JP Abgrall53f17a92014-02-12 14:02:41 -08003050#ifdef HAVE_LIBCRYPTO
3051 /* initialize SAs */
3052 if (ndo->ndo_sa_list_head == NULL) {
3053 if (ndo->ndo_espsecret)
Elliott Hughes820eced2021-08-20 18:00:50 -07003054 esp_decodesecret_print(ndo);
JP Abgrall53f17a92014-02-12 14:02:41 -08003055 }
3056#endif
3057
The Android Open Source Project2949f582009-03-03 19:30:46 -08003058 p = (const struct isakmp *)bp;
3059 ep = ndo->ndo_snapend;
3060
Elliott Hughese2e3bd12017-05-15 10:59:29 -07003061 if ((const struct isakmp *)ep < p + 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -07003062 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -08003063 return;
3064 }
3065
Elliott Hughes820eced2021-08-20 18:00:50 -07003066 ND_PRINT("isakmp");
3067 major = (GET_U_1(p->vers) & ISAKMP_VERS_MAJOR)
JP Abgrall53f17a92014-02-12 14:02:41 -08003068 >> ISAKMP_VERS_MAJOR_SHIFT;
Elliott Hughes820eced2021-08-20 18:00:50 -07003069 minor = (GET_U_1(p->vers) & ISAKMP_VERS_MINOR)
JP Abgrall53f17a92014-02-12 14:02:41 -08003070 >> ISAKMP_VERS_MINOR_SHIFT;
3071
3072 if (ndo->ndo_vflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -07003073 ND_PRINT(" %u.%u", major, minor);
The Android Open Source Project2949f582009-03-03 19:30:46 -08003074 }
3075
JP Abgrall53f17a92014-02-12 14:02:41 -08003076 if (ndo->ndo_vflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -07003077 ND_PRINT(" msgid ");
3078 hexprint(ndo, p->msgid, sizeof(p->msgid));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003079 }
3080
JP Abgrall53f17a92014-02-12 14:02:41 -08003081 if (1 < ndo->ndo_vflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -07003082 ND_PRINT(" cookie ");
3083 hexprint(ndo, p->i_ck, sizeof(p->i_ck));
3084 ND_PRINT("->");
3085 hexprint(ndo, p->r_ck, sizeof(p->r_ck));
The Android Open Source Project2949f582009-03-03 19:30:46 -08003086 }
Elliott Hughes820eced2021-08-20 18:00:50 -07003087 ND_PRINT(":");
The Android Open Source Project2949f582009-03-03 19:30:46 -08003088
JP Abgrall53f17a92014-02-12 14:02:41 -08003089 switch(major) {
3090 case IKEv1_MAJOR_VERSION:
Elliott Hughes820eced2021-08-20 18:00:50 -07003091 ikev1_print(ndo, bp, length, bp2, p);
JP Abgrall53f17a92014-02-12 14:02:41 -08003092 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08003093
JP Abgrall53f17a92014-02-12 14:02:41 -08003094 case IKEv2_MAJOR_VERSION:
Elliott Hughes820eced2021-08-20 18:00:50 -07003095 ikev2_print(ndo, bp, length, bp2, p);
JP Abgrall53f17a92014-02-12 14:02:41 -08003096 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08003097 }
3098}
3099
3100void
3101isakmp_rfc3948_print(netdissect_options *ndo,
3102 const u_char *bp, u_int length,
Elliott Hughes820eced2021-08-20 18:00:50 -07003103 const u_char *bp2, int ver, int fragmented, u_int ttl_hl)
The Android Open Source Project2949f582009-03-03 19:30:46 -08003104{
Elliott Hughes820eced2021-08-20 18:00:50 -07003105 ndo->ndo_protocol = "isakmp_rfc3948";
3106 if(length == 1 && GET_U_1(bp)==0xff) {
3107 ND_PRINT("isakmp-nat-keep-alive");
The Android Open Source Project2949f582009-03-03 19:30:46 -08003108 return;
3109 }
3110
3111 if(length < 4) {
3112 goto trunc;
3113 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07003114
The Android Open Source Project2949f582009-03-03 19:30:46 -08003115 /*
3116 * see if this is an IKE packet
3117 */
Elliott Hughes820eced2021-08-20 18:00:50 -07003118 if (GET_BE_U_4(bp) == 0) {
3119 ND_PRINT("NONESP-encap: ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08003120 isakmp_print(ndo, bp+4, length-4, bp2);
3121 return;
3122 }
3123
3124 /* must be an ESP packet */
3125 {
Elliott Hughes820eced2021-08-20 18:00:50 -07003126 ND_PRINT("UDP-encap: ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08003127
Elliott Hughes820eced2021-08-20 18:00:50 -07003128 esp_print(ndo, bp, length, bp2, ver, fragmented, ttl_hl);
The Android Open Source Project2949f582009-03-03 19:30:46 -08003129
Elliott Hughes820eced2021-08-20 18:00:50 -07003130 /*
3131 * Either this has decrypted the payload and
3132 * printed it, in which case there's nothing more
3133 * to do, or it hasn't, in which case there's
3134 * nothing more to do.
3135 */
The Android Open Source Project2949f582009-03-03 19:30:46 -08003136 return;
3137 }
3138
3139trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07003140 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -08003141}