2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
29 /* YIPS @(#)$Id: isakmp.h,v 1.11 2007-08-29 02:38:14 mcr Exp $ */
31 /* refer to RFC 2408 */
33 /* must include <netinet/in.h> */
35 #if !defined(_ISAKMP_H_)
38 typedef u_char cookie_t
[8];
39 typedef u_char msgid_t
[4];
41 typedef struct { /* i_cookie + r_cookie */
49 #define PORT_ISAKMP 500
54 /* Phase of oakley definition */
58 | |||| ++++--> negosiation number in phase
59 | ++++-------> phase number
60 +---------------> expire ?
62 #define ISAKMP_PH1 0x0010
63 #define ISAKMP_PH2 0x0020
64 #define ISAKMP_EXPIRED 0x0100
66 #define ISAKMP_NGP_0 0x0000
67 #define ISAKMP_NGP_1 0x0001
68 #define ISAKMP_NGP_2 0x0002
69 #define ISAKMP_NGP_3 0x0003
70 #define ISAKMP_NGP_4 0x0004
72 #define ISAKMP_PH1_N (ISAKMP_PH1 | ISAKMP_NGP_0) /* i.e. spawn */
73 #define ISAKMP_PH1_1 (ISAKMP_PH1 | ISAKMP_NGP_1)
74 #define ISAKMP_PH1_2 (ISAKMP_PH1 | ISAKMP_NGP_2)
75 #define ISAKMP_PH1_3 (ISAKMP_PH1 | ISAKMP_NGP_3)
76 #define ISAKMP_PH2_N (ISAKMP_PH2 | ISAKMP_NGP_0)
77 #define ISAKMP_PH2_1 (ISAKMP_PH2 | ISAKMP_NGP_1)
78 #define ISAKMP_PH2_2 (ISAKMP_PH2 | ISAKMP_NGP_2)
79 #define ISAKMP_PH2_3 (ISAKMP_PH2 | ISAKMP_NGP_3)
81 #define ISAKMP_TIMER_DEFAULT 10 /* seconds */
82 #define ISAKMP_TRY_DEFAULT 3 /* times */
84 /* 3.1 ISAKMP Header Format (IKEv1 and IKEv2)
85 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
86 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
89 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
92 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
93 ! Next Payload ! MjVer ! MnVer ! Exchange Type ! Flags !
94 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
96 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
98 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
101 cookie_t i_ck
; /* Initiator Cookie */
102 cookie_t r_ck
; /* Responder Cookie */
103 u_int8_t np
; /* Next Payload Type */
105 #define ISAKMP_VERS_MAJOR 0xf0
106 #define ISAKMP_VERS_MAJOR_SHIFT 4
107 #define ISAKMP_VERS_MINOR 0x0f
108 #define ISAKMP_VERS_MINOR_SHIFT 0
109 u_int8_t etype
; /* Exchange Type */
110 u_int8_t flags
; /* Flags */
112 u_int32_t len
; /* Length */
115 /* Next Payload Type */
116 #define ISAKMP_NPTYPE_NONE 0 /* NONE*/
117 #define ISAKMP_NPTYPE_SA 1 /* Security Association */
118 #define ISAKMP_NPTYPE_P 2 /* Proposal */
119 #define ISAKMP_NPTYPE_T 3 /* Transform */
120 #define ISAKMP_NPTYPE_KE 4 /* Key Exchange */
121 #define ISAKMP_NPTYPE_ID 5 /* Identification */
122 #define ISAKMP_NPTYPE_CERT 6 /* Certificate */
123 #define ISAKMP_NPTYPE_CR 7 /* Certificate Request */
124 #define ISAKMP_NPTYPE_HASH 8 /* Hash */
125 #define ISAKMP_NPTYPE_SIG 9 /* Signature */
126 #define ISAKMP_NPTYPE_NONCE 10 /* Nonce */
127 #define ISAKMP_NPTYPE_N 11 /* Notification */
128 #define ISAKMP_NPTYPE_D 12 /* Delete */
129 #define ISAKMP_NPTYPE_VID 13 /* Vendor ID */
131 #define IKEv1_MAJOR_VERSION 1
132 #define IKEv1_MINOR_VERSION 0
134 #define IKEv2_MAJOR_VERSION 2
135 #define IKEv2_MINOR_VERSION 0
138 #define ISAKMP_ETYPE_NONE 0 /* NONE */
139 #define ISAKMP_ETYPE_BASE 1 /* Base */
140 #define ISAKMP_ETYPE_IDENT 2 /* Identity Proteciton */
141 #define ISAKMP_ETYPE_AUTH 3 /* Authentication Only */
142 #define ISAKMP_ETYPE_AGG 4 /* Aggressive */
143 #define ISAKMP_ETYPE_INF 5 /* Informational */
146 #define ISAKMP_FLAG_E 0x01 /* Encryption Bit */
147 #define ISAKMP_FLAG_C 0x02 /* Commit Bit */
148 #define ISAKMP_FLAG_extra 0x04
151 #define ISAKMP_FLAG_I (1 << 3) /* (I)nitiator */
152 #define ISAKMP_FLAG_V (1 << 4) /* (V)ersion */
153 #define ISAKMP_FLAG_R (1 << 5) /* (R)esponse */
156 /* 3.2 Payload Generic Header
157 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
158 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
159 ! Next Payload ! RESERVED ! Payload Length !
160 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
163 u_int8_t np
; /* Next Payload */
164 u_int8_t critical
; /* bit 7 - critical, rest is RESERVED */
165 u_int16_t len
; /* Payload Length */
168 /* 3.3 Data Attributes
169 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
170 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
171 !A! Attribute Type ! AF=0 Attribute Length !
172 !F! ! AF=1 Attribute Value !
173 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
174 . AF=0 Attribute Value .
175 . AF=1 Not Transmitted .
176 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
179 u_int16_t type
; /* defined by DOI-spec, and Attribute Format */
180 u_int16_t lorv
; /* if f equal 1, Attribute Length */
181 /* if f equal 0, Attribute Value */
182 /* if f equal 1, Attribute Value */
184 #define ISAKMP_GEN_TLV 0x0000
185 #define ISAKMP_GEN_TV 0x8000
186 /* mask for type of attribute format */
187 #define ISAKMP_GEN_MASK 0x8000
189 /* 3.4 Security Association Payload */
190 /* MAY NOT be used, because of being defined in ipsec-doi. */
192 If the current payload is the last in the message,
193 then the value of the next payload field will be 0.
194 This field MUST NOT contain the
195 values for the Proposal or Transform payloads as they are considered
196 part of the security association negotiation. For example, this
197 field would contain the value "10" (Nonce payload) in the first
198 message of a Base Exchange (see Section 4.4) and the value "0" in the
199 first message of an Identity Protect Exchange (see Section 4.5).
203 u_int32_t doi
; /* Domain of Interpretation */
204 u_int32_t sit
; /* Situation */
207 /* 3.5 Proposal Payload */
209 The value of the next payload field MUST only contain the value "2"
210 or "0". If there are additional Proposal payloads in the message,
211 then this field will be 2. If the current Proposal payload is the
212 last within the security association proposal, then this field will
217 u_int8_t p_no
; /* Proposal # */
218 u_int8_t prot_id
; /* Protocol */
219 u_int8_t spi_size
; /* SPI Size */
220 u_int8_t num_t
; /* Number of Transforms */
224 /* 3.6 Transform Payload */
226 The value of the next payload field MUST only contain the value "3"
227 or "0". If there are additional Transform payloads in the proposal,
228 then this field will be 3. If the current Transform payload is the
229 last within the proposal, then this field will be 0.
233 u_int8_t t_no
; /* Transform # */
234 u_int8_t t_id
; /* Transform-Id */
235 u_int16_t reserved
; /* RESERVED2 */
239 /* 3.7 Key Exchange Payload */
242 /* Key Exchange Data */
245 /* 3.8 Identification Payload */
246 /* MUST NOT to be used, because of being defined in ipsec-doi. */
250 u_int8_t id_type
; /* ID Type */
251 u_int32_t doi_data
; /* DOI Specific ID Data */
253 /* Identification Data */
256 /* 3.9 Certificate Payload */
257 struct ikev1_pl_cert
{
259 u_int8_t encode
; /* Cert Encoding */
260 char cert
; /* Certificate Data */
262 This field indicates the type of
263 certificate or certificate-related information contained in the
264 Certificate Data field.
268 /* Certificate Type */
269 #define ISAKMP_CERT_NONE 0
270 #define ISAKMP_CERT_PKCS 1
271 #define ISAKMP_CERT_PGP 2
272 #define ISAKMP_CERT_DNS 3
273 #define ISAKMP_CERT_SIGN 4
274 #define ISAKMP_CERT_KE 5
275 #define ISAKMP_CERT_KT 6
276 #define ISAKMP_CERT_CRL 7
277 #define ISAKMP_CERT_ARL 8
278 #define ISAKMP_CERT_SPKI 9
280 /* 3.10 Certificate Request Payload */
283 u_int8_t num_cert
; /* # Cert. Types */
285 Certificate Types (variable length)
286 -- Contains a list of the types of certificates requested,
287 sorted in order of preference. Each individual certificate
288 type is 1 octet. This field is NOT requiredo
290 /* # Certificate Authorities (1 octet) */
291 /* Certificate Authorities (variable length) */
294 /* 3.11 Hash Payload */
295 /* may not be used, because of having only data. */
296 struct ikev1_pl_hash
{
301 /* 3.12 Signature Payload */
302 /* may not be used, because of having only data. */
303 struct ikev1_pl_sig
{
308 /* 3.13 Nonce Payload */
309 /* may not be used, because of having only data. */
310 struct ikev1_pl_nonce
{
315 /* 3.14 Notification Payload */
318 u_int32_t doi
; /* Domain of Interpretation */
319 u_int8_t prot_id
; /* Protocol-ID */
320 u_int8_t spi_size
; /* SPI Size */
321 u_int16_t type
; /* Notify Message Type */
323 /* Notification Data */
326 /* 3.14.1 Notify Message Types */
327 /* NOTIFY MESSAGES - ERROR TYPES */
328 #define ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE 1
329 #define ISAKMP_NTYPE_DOI_NOT_SUPPORTED 2
330 #define ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED 3
331 #define ISAKMP_NTYPE_INVALID_COOKIE 4
332 #define ISAKMP_NTYPE_INVALID_MAJOR_VERSION 5
333 #define ISAKMP_NTYPE_INVALID_MINOR_VERSION 6
334 #define ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE 7
335 #define ISAKMP_NTYPE_INVALID_FLAGS 8
336 #define ISAKMP_NTYPE_INVALID_MESSAGE_ID 9
337 #define ISAKMP_NTYPE_INVALID_PROTOCOL_ID 10
338 #define ISAKMP_NTYPE_INVALID_SPI 11
339 #define ISAKMP_NTYPE_INVALID_TRANSFORM_ID 12
340 #define ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED 13
341 #define ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN 14
342 #define ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX 15
343 #define ISAKMP_NTYPE_PAYLOAD_MALFORMED 16
344 #define ISAKMP_NTYPE_INVALID_KEY_INFORMATION 17
345 #define ISAKMP_NTYPE_INVALID_ID_INFORMATION 18
346 #define ISAKMP_NTYPE_INVALID_CERT_ENCODING 19
347 #define ISAKMP_NTYPE_INVALID_CERTIFICATE 20
348 #define ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX 21
349 #define ISAKMP_NTYPE_INVALID_CERT_AUTHORITY 22
350 #define ISAKMP_NTYPE_INVALID_HASH_INFORMATION 23
351 #define ISAKMP_NTYPE_AUTHENTICATION_FAILED 24
352 #define ISAKMP_NTYPE_INVALID_SIGNATURE 25
353 #define ISAKMP_NTYPE_ADDRESS_NOTIFICATION 26
354 /* NOTIFY MESSAGES - STATUS TYPES */
355 #define ISAKMP_NTYPE_CONNECTED 16384
356 /* using only to log */
357 #define ISAKMP_LOG_RETRY_LIMIT_REACHED 65530
359 /* 3.15 Delete Payload */
362 u_int32_t doi
; /* Domain of Interpretation */
363 u_int8_t prot_id
; /* Protocol-Id */
364 u_int8_t spi_size
; /* SPI Size */
365 u_int16_t num_spi
; /* # of SPIs */
370 struct ikev1_ph1tab
{
371 struct ikev1_ph1
*head
;
372 struct ikev1_ph1
*tail
;
376 struct isakmp_ph2tab
{
377 struct ikev1_ph2
*head
;
378 struct ikev1_ph2
*tail
;
382 #define EXCHANGE_PROXY 1
383 #define EXCHANGE_MYSELF 0
388 /* IKEv2 (RFC4306) */
390 /* 3.3 Security Association Payload -- generic header */
391 /* 3.3.1. Proposal Substructure */
394 u_int8_t p_no
; /* Proposal # */
395 u_int8_t prot_id
; /* Protocol */
396 u_int8_t spi_size
; /* SPI Size */
397 u_int8_t num_t
; /* Number of Transforms */
400 /* 3.3.2. Transform Substructure */
403 u_int8_t t_type
; /* Transform Type (ENCR,PRF,INTEG,etc.*/
404 u_int8_t res2
; /* reserved byte */
405 u_int16_t t_id
; /* Transform ID */
416 /* 3.4. Key Exchange Payload */
425 /* 3.10 Notification Payload */
428 u_int8_t prot_id
; /* Protocol-ID */
429 u_int8_t spi_size
; /* SPI Size */
430 u_int16_t type
; /* Notify Message Type */
432 /* Notification Data */
436 IV2_NOTIFY_UNSUPPORTED_CRITICAL_PAYLOAD
= 1,
437 IV2_NOTIFY_INVALID_IKE_SPI
= 4,
438 IV2_NOTIFY_INVALID_MAJOR_VERSION
= 5,
439 IV2_NOTIFY_INVALID_SYNTAX
= 7,
440 IV2_NOTIFY_INVALID_MESSAGE_ID
= 9,
441 IV2_NOTIFY_INVALID_SPI
=11,
442 IV2_NOTIFY_NO_PROPOSAL_CHOSEN
=14,
443 IV2_NOTIFY_INVALID_KE_PAYLOAD
=17,
444 IV2_NOTIFY_AUTHENTICATION_FAILED
=24,
445 IV2_NOTIFY_SINGLE_PAIR_REQUIRED
=34,
446 IV2_NOTIFY_NO_ADDITIONAL_SAS
=35,
447 IV2_NOTIFY_INTERNAL_ADDRESS_FAILURE
=36,
448 IV2_NOTIFY_FAILED_CP_REQUIRED
=37,
449 IV2_NOTIFY_INVALID_SELECTORS
=39,
450 IV2_NOTIFY_INITIAL_CONTACT
=16384,
451 IV2_NOTIFY_SET_WINDOW_SIZE
=16385,
452 IV2_NOTIFY_ADDITIONAL_TS_POSSIBLE
=16386,
453 IV2_NOTIFY_IPCOMP_SUPPORTED
=16387,
454 IV2_NOTIFY_NAT_DETECTION_SOURCE_IP
=16388,
455 IV2_NOTIFY_NAT_DETECTION_DESTINATION_IP
=16389,
456 IV2_NOTIFY_COOKIE
=16390,
457 IV2_NOTIFY_USE_TRANSPORT_MODE
=16391,
458 IV2_NOTIFY_HTTP_CERT_LOOKUP_SUPPORTED
=16392,
459 IV2_NOTIFY_REKEY_SA
=16393,
460 IV2_NOTIFY_ESP_TFC_PADDING_NOT_SUPPORTED
=16394,
461 IV2_NOTIFY_NON_FIRST_FRAGMENTS_ALSO
=16395
464 struct notify_messages
{
469 /* 3.8 Notification Payload */
472 u_int8_t auth_method
; /* Protocol-ID */
473 u_int8_t reserved
[3];
474 /* authentication data */
477 enum ikev2_auth_type
{
483 #endif /* !defined(_ISAKMP_H_) */