2f3587db2b3c6b671640c272cbcc7640a8c7454a
[strongswan.git] / src / pluto / constants.h
1
2 /* manifest constants
3 * Copyright (C) 1997 Angelos D. Keromytis.
4 * Copyright (C) 1998-2002 D. Hugh Redelmeier.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * RCSID $Id: constants.h,v 1.20 2006/02/28 19:13:33 as Exp $
17 */
18
19 #ifndef _CONSTANTS_H
20 #define _CONSTANTS_H
21
22 extern const char compile_time_interop_options[];
23
24 extern void init_constants(void);
25
26 /*
27 * NOTE:For debugging purposes, constants.c has tables to map numbers back to names.
28 * Any changes here should be reflected there.
29 */
30
31 #define elemsof(array) (sizeof(array) / sizeof(*(array))) /* number of elements in an array */
32
33 /* Many routines return only success or failure, but wish to describe
34 * the failure in a message. We use the convention that they return
35 * a NULL on success and a pointer to constant string on failure.
36 * The fact that the string is a constant is limiting, but it
37 * avoids storage management issues: the recipient is allowed to assume
38 * that the string will live "long enough" (usually forever).
39 * <freeswan.h> defines err_t for this return type.
40 */
41
42 typedef int bool;
43 #define FALSE 0
44 #define TRUE 1
45
46 #define NULL_FD (-1) /* NULL file descriptor */
47 #define dup_any(fd) ((fd) == NULL_FD? NULL_FD : dup(fd))
48 #define close_any(fd) { if ((fd) != NULL_FD) { close(fd); (fd) = NULL_FD; } }
49
50 #define BITS_PER_BYTE 8
51
52 #define streq(a, b) (strcmp((a), (b)) == 0) /* clearer shorthand */
53 #define strcaseeq(a, b) (strcasecmp((a), (b)) == 0) /* clearer shorthand */
54
55 /* set type with room for at least 64 elements for ALG opts (was 32 in stock FS) */
56
57 typedef unsigned long long lset_t;
58 #define LEMPTY 0ULL
59 #define LELEM(opt) (1ULL << (opt))
60 #define LRANGE(lwb, upb) LRANGES(LELEM(lwb), LELEM(upb))
61 #define LRANGES(first, last) (last - first + last)
62 #define LHAS(set, elem) ((LELEM(elem) & (set)) != LEMPTY)
63 #define LIN(subset, set) (((subset) & (set)) == (subset))
64 #define LDISJOINT(a, b) (((a) & (b)) == LEMPTY)
65
66 /* Control and lock pathnames */
67 #ifndef IPSEC_PIDDIR
68 # define IPSEC_PIDDIR "/var/run"
69 #endif
70 #ifndef DEFAULT_CTLBASE
71 # define DEFAULT_CTLBASE IPSEC_PIDDIR "/pluto"
72 #endif
73
74 #define CTL_SUFFIX ".ctl" /* for UNIX domain socket pathname */
75 #define LOCK_SUFFIX ".pid" /* for pluto's lock */
76 #define INFO_SUFFIX ".info" /* for UNIX domain socket for apps */
77
78 /* Routines to check and display values.
79 *
80 * An enum_names describes an enumeration.
81 * enum_name() returns the name of an enum value, or NULL if invalid.
82 * enum_show() is like enum_name, except it formats a numeric representation
83 * for any invalid value (in a static area!)
84 *
85 * bitnames() formats a display of a set of named bits (in a static area)
86 */
87
88 struct enum_names {
89 unsigned long en_first; /* first value in range */
90 unsigned long en_last; /* last value in range (inclusive) */
91 const char *const *en_names;
92 const struct enum_names *en_next_range; /* descriptor of next range */
93 };
94
95 typedef const struct enum_names enum_names;
96
97 extern const char *enum_name(enum_names *ed, unsigned long val);
98 extern const char *enum_show(enum_names *ed, unsigned long val);
99 extern int enum_search(enum_names *ed, const char *string);
100
101 extern bool testset(const char *const table[], lset_t val);
102 extern const char *bitnamesof(const char *const table[], lset_t val);
103
104 /* sparse_names is much like enum_names, except values are
105 * not known to be contiguous or ordered.
106 * The array of names is ended with one with the name sparse_end
107 * (this avoids having to reserve a value to signify the end).
108 * Often appropriate for enums defined by others.
109 */
110 struct sparse_name {
111 unsigned long val;
112 const char *const name;
113 };
114 typedef const struct sparse_name sparse_names[];
115
116 extern const char *sparse_name(sparse_names sd, unsigned long val);
117 extern const char *sparse_val_show(sparse_names sd, unsigned long val);
118 extern const char sparse_end[];
119
120 #define FULL_INET_ADDRESS_SIZE 6
121
122 /* Group parameters from draft-ietf-ike-01.txt section 6 */
123
124 #define MODP_GENERATOR "2"
125
126 #define MODP768_MODULUS \
127 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1 " \
128 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD " \
129 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245 " \
130 "E485B576 625E7EC6 F44C42E9 A63A3620 FFFFFFFF FFFFFFFF"
131
132 #define MODP1024_MODULUS \
133 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1 " \
134 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD " \
135 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245 " \
136 "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED " \
137 "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381 " \
138 "FFFFFFFF FFFFFFFF"
139
140 #define MODP1536_MODULUS \
141 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1 " \
142 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD " \
143 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245 " \
144 "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED " \
145 "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D " \
146 "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F " \
147 "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D " \
148 "670C354E 4ABC9804 F1746C08 CA237327 FFFFFFFF FFFFFFFF "
149
150 /* draft-ietf-ipsec-ike-modp-groups-03.txt */
151 #define MODP2048_MODULUS \
152 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1" \
153 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD" \
154 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245" \
155 "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED" \
156 "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D" \
157 "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F" \
158 "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D" \
159 "670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B" \
160 "E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9" \
161 "DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510" \
162 "15728E5A 8AACAA68 FFFFFFFF FFFFFFFF"
163
164 #define MODP3072_MODULUS \
165 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1" \
166 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD" \
167 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245" \
168 "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED" \
169 "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D" \
170 "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F" \
171 "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D" \
172 "670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B" \
173 "E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9" \
174 "DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510" \
175 "15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64" \
176 "ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7" \
177 "ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226 1AD2EE6B" \
178 "F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C" \
179 "BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31" \
180 "43DB5BFC E0FD108E 4B82D120 A93AD2CA FFFFFFFF FFFFFFFF"
181
182 #define MODP4096_MODULUS \
183 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1" \
184 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD" \
185 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245" \
186 "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED" \
187 "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D" \
188 "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F" \
189 "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D" \
190 "670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B" \
191 "E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9" \
192 "DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510" \
193 "15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64" \
194 "ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7" \
195 "ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226 1AD2EE6B" \
196 "F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C" \
197 "BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31" \
198 "43DB5BFC E0FD108E 4B82D120 A9210801 1A723C12 A787E6D7" \
199 "88719A10 BDBA5B26 99C32718 6AF4E23C 1A946834 B6150BDA" \
200 "2583E9CA 2AD44CE8 DBBBC2DB 04DE8EF9 2E8EFC14 1FBECAA6" \
201 "287C5947 4E6BC05D 99B2964F A090C3A2 233BA186 515BE7ED" \
202 "1F612970 CEE2D7AF B81BDD76 2170481C D0069127 D5B05AA9" \
203 "93B4EA98 8D8FDDC1 86FFB7DC 90A6C08F 4DF435C9 34063199" \
204 "FFFFFFFF FFFFFFFF"
205
206 /* copy&pasted from rfc3526: */
207 #define MODP6144_MODULUS \
208 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1 29024E08" \
209 "8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD EF9519B3 CD3A431B" \
210 "302B0A6D F25F1437 4FE1356D 6D51C245 E485B576 625E7EC6 F44C42E9" \
211 "A637ED6B 0BFF5CB6 F406B7ED EE386BFB 5A899FA5 AE9F2411 7C4B1FE6" \
212 "49286651 ECE45B3D C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8" \
213 "FD24CF5F 83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D" \
214 "670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B E39E772C" \
215 "180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9 DE2BCBF6 95581718" \
216 "3995497C EA956AE5 15D22618 98FA0510 15728E5A 8AAAC42D AD33170D" \
217 "04507A33 A85521AB DF1CBA64 ECFB8504 58DBEF0A 8AEA7157 5D060C7D" \
218 "B3970F85 A6E1E4C7 ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226" \
219 "1AD2EE6B F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C" \
220 "BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31 43DB5BFC" \
221 "E0FD108E 4B82D120 A9210801 1A723C12 A787E6D7 88719A10 BDBA5B26" \
222 "99C32718 6AF4E23C 1A946834 B6150BDA 2583E9CA 2AD44CE8 DBBBC2DB" \
223 "04DE8EF9 2E8EFC14 1FBECAA6 287C5947 4E6BC05D 99B2964F A090C3A2" \
224 "233BA186 515BE7ED 1F612970 CEE2D7AF B81BDD76 2170481C D0069127" \
225 "D5B05AA9 93B4EA98 8D8FDDC1 86FFB7DC 90A6C08F 4DF435C9 34028492" \
226 "36C3FAB4 D27C7026 C1D4DCB2 602646DE C9751E76 3DBA37BD F8FF9406" \
227 "AD9E530E E5DB382F 413001AE B06A53ED 9027D831 179727B0 865A8918" \
228 "DA3EDBEB CF9B14ED 44CE6CBA CED4BB1B DB7F1447 E6CC254B 33205151" \
229 "2BD7AF42 6FB8F401 378CD2BF 5983CA01 C64B92EC F032EA15 D1721D03" \
230 "F482D7CE 6E74FEF6 D55E702F 46980C82 B5A84031 900B1C9E 59E7C97F" \
231 "BEC7E8F3 23A97A7E 36CC88BE 0F1D45B7 FF585AC5 4BD407B2 2B4154AA" \
232 "CC8F6D7E BF48E1D8 14CC5ED2 0F8037E0 A79715EE F29BE328 06A1D58B" \
233 "B7C5DA76 F550AA3D 8A1FBFF0 EB19CCB1 A313D55C DA56C9EC 2EF29632" \
234 "387FE8D7 6E3C0468 043E8F66 3F4860EE 12BF2D5B 0B7474D6 E694F91E" \
235 "6DCC4024 FFFFFFFF FFFFFFFF"
236
237 /* copy&pasted from rfc3526: */
238 #define MODP8192_MODULUS \
239 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1" \
240 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD" \
241 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245" \
242 "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED" \
243 "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D" \
244 "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F" \
245 "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D" \
246 "670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B" \
247 "E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9" \
248 "DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510" \
249 "15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64" \
250 "ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7" \
251 "ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226 1AD2EE6B" \
252 "F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C" \
253 "BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31" \
254 "43DB5BFC E0FD108E 4B82D120 A9210801 1A723C12 A787E6D7" \
255 "88719A10 BDBA5B26 99C32718 6AF4E23C 1A946834 B6150BDA" \
256 "2583E9CA 2AD44CE8 DBBBC2DB 04DE8EF9 2E8EFC14 1FBECAA6" \
257 "287C5947 4E6BC05D 99B2964F A090C3A2 233BA186 515BE7ED" \
258 "1F612970 CEE2D7AF B81BDD76 2170481C D0069127 D5B05AA9" \
259 "93B4EA98 8D8FDDC1 86FFB7DC 90A6C08F 4DF435C9 34028492" \
260 "36C3FAB4 D27C7026 C1D4DCB2 602646DE C9751E76 3DBA37BD" \
261 "F8FF9406 AD9E530E E5DB382F 413001AE B06A53ED 9027D831" \
262 "179727B0 865A8918 DA3EDBEB CF9B14ED 44CE6CBA CED4BB1B" \
263 "DB7F1447 E6CC254B 33205151 2BD7AF42 6FB8F401 378CD2BF" \
264 "5983CA01 C64B92EC F032EA15 D1721D03 F482D7CE 6E74FEF6" \
265 "D55E702F 46980C82 B5A84031 900B1C9E 59E7C97F BEC7E8F3" \
266 "23A97A7E 36CC88BE 0F1D45B7 FF585AC5 4BD407B2 2B4154AA" \
267 "CC8F6D7E BF48E1D8 14CC5ED2 0F8037E0 A79715EE F29BE328" \
268 "06A1D58B B7C5DA76 F550AA3D 8A1FBFF0 EB19CCB1 A313D55C" \
269 "DA56C9EC 2EF29632 387FE8D7 6E3C0468 043E8F66 3F4860EE" \
270 "12BF2D5B 0B7474D6 E694F91E 6DBE1159 74A3926F 12FEE5E4" \
271 "38777CB6 A932DF8C D8BEC4D0 73B931BA 3BC832B6 8D9DD300" \
272 "741FA7BF 8AFC47ED 2576F693 6BA42466 3AAB639C 5AE4F568" \
273 "3423B474 2BF1C978 238F16CB E39D652D E3FDB8BE FC848AD9" \
274 "22222E04 A4037C07 13EB57A8 1A23F0C7 3473FC64 6CEA306B" \
275 "4BCBC886 2F8385DD FA9D4B7F A2C087E8 79683303 ED5BDD3A" \
276 "062B3CF5 B3A278A6 6D2A13F8 3F44F82D DF310EE0 74AB6A36" \
277 "4597E899 A0255DC1 64F31CC5 0846851D F9AB4819 5DED7EA1" \
278 "B1D510BD 7EE74D73 FAF36BC3 1ECFA268 359046F4 EB879F92" \
279 "4009438B 481C6CD7 889A002E D5EE382B C9190DA6 FC026E47" \
280 "9558E447 5677E9AA 9E3050E2 765694DF C81F56E8 80B96E71" \
281 "60C980DD 98EDD3DF FFFFFFFF FFFFFFFF"
282 #define LOCALSECRETSIZE (256 / BITS_PER_BYTE)
283
284 /* limits on nonce sizes. See RFC2409 "The internet key exchange (IKE)" 5 */
285 #define MINIMUM_NONCE_SIZE 8 /* bytes */
286 #define DEFAULT_NONCE_SIZE 16 /* bytes */
287 #define MAXIMUM_NONCE_SIZE 256 /* bytes */
288
289 #define COOKIE_SIZE 8
290 #define MAX_ISAKMP_SPI_SIZE 16
291
292 #define MD2_DIGEST_SIZE (128 / BITS_PER_BYTE) /* ought to be supplied by md2.h */
293 #define MD5_DIGEST_SIZE (128 / BITS_PER_BYTE) /* ought to be supplied by md5.h */
294 #define SHA1_DIGEST_SIZE (160 / BITS_PER_BYTE) /* ought to be supplied by sha1.h */
295
296 #define DES_CBC_BLOCK_SIZE (64 / BITS_PER_BYTE)
297
298 #define DSS_QBITS 160 /* bits in DSS's "q" (FIPS 186-1) */
299
300 /* to statically allocate IV, we need max of
301 * MD5_DIGEST_SIZE, SHA1_DIGEST_SIZE, and DES_CBC_BLOCK_SIZE.
302 * To avoid combinatorial explosion, we leave out DES_CBC_BLOCK_SIZE.
303 */
304 #define MAX_DIGEST_LEN_OLD (MD5_DIGEST_SIZE > SHA1_DIGEST_SIZE? MD5_DIGEST_SIZE : SHA1_DIGEST_SIZE)
305
306 /* for max: SHA2_512 */
307 #define MAX_DIGEST_LEN (512/BITS_PER_BYTE)
308
309 /* RFC 2404 "HMAC-SHA-1-96" section 3 */
310 #define HMAC_SHA1_KEY_LEN SHA1_DIGEST_SIZE
311
312 /* RFC 2403 "HMAC-MD5-96" section 3 */
313 #define HMAC_MD5_KEY_LEN MD5_DIGEST_SIZE
314
315 #define IKE_UDP_PORT 500
316
317 /* RFC 2560 OCSP - certificate status */
318
319 typedef enum {
320 CERT_GOOD = 0,
321 CERT_REVOKED = 1,
322 CERT_UNKNOWN = 2,
323 CERT_UNDEFINED = 3
324 } cert_status_t;
325
326 /* RFC 2459 CRL reason codes */
327
328 extern enum_names crl_reason_names;
329
330 typedef enum {
331 REASON_UNSPECIFIED = 0,
332 REASON_KEY_COMPROMISE = 1,
333 REASON_CA_COMPROMISE = 2,
334 REASON_AFFILIATION_CHANGED = 3,
335 REASON_SUPERSEDED = 4,
336 REASON_CESSATION_OF_OPERATON = 5,
337 REASON_CERTIFICATE_HOLD = 6,
338 REASON_REMOVE_FROM_CRL = 8
339 } crl_reason_t;
340
341 /* RFC 3706 Dead Peer Detection */
342
343 extern enum_names dpd_action_names;
344
345 typedef enum {
346 DPD_ACTION_NONE = 0,
347 DPD_ACTION_CLEAR = 1,
348 DPD_ACTION_HOLD = 2,
349 DPD_ACTION_RESTART = 3,
350 DPD_ACTION_UNKNOWN = 4
351 } dpd_action_t;
352
353 /* Timer events */
354
355 extern enum_names timer_event_names;
356
357 enum event_type {
358 EVENT_NULL, /* non-event */
359 EVENT_REINIT_SECRET, /* Refresh cookie secret */
360 #ifdef KLIPS
361 EVENT_SHUNT_SCAN, /* scan shunt eroutes known to kernel */
362 #endif
363 EVENT_SO_DISCARD, /* discard unfinished state object */
364 EVENT_RETRANSMIT, /* Retransmit packet */
365 EVENT_SA_REPLACE, /* SA replacement event */
366 EVENT_SA_REPLACE_IF_USED, /* SA replacement event */
367 EVENT_SA_EXPIRE, /* SA expiration event */
368 EVENT_NAT_T_KEEPALIVE, /* NAT Traversal Keepalive */
369 EVENT_DPD, /* dead peer detection */
370 EVENT_DPD_TIMEOUT, /* dead peer detection timeout */
371 EVENT_LOG_DAILY /* reset certain log events/stats */
372 };
373
374 #define EVENT_REINIT_SECRET_DELAY 3600 /* 1 hour */
375 #define EVENT_RETRANSMIT_DELAY_0 10 /* 10 seconds */
376
377 /* Misc. stuff */
378
379 #define MAXIMUM_RETRANSMISSIONS 2
380 #define MAXIMUM_RETRANSMISSIONS_INITIAL 20
381
382 #define MAX_INPUT_UDP_SIZE 65536
383 #define MAX_OUTPUT_UDP_SIZE 65536
384
385 /* Version numbers */
386
387 #define ISAKMP_MAJOR_VERSION 0x1
388 #define ISAKMP_MINOR_VERSION 0x0
389
390 extern enum_names version_names;
391
392 /* Domain of Interpretation */
393
394 extern enum_names doi_names;
395
396 #define ISAKMP_DOI_ISAKMP 0
397 #define ISAKMP_DOI_IPSEC 1
398
399 /* IPsec DOI things */
400
401 #define IPSEC_DOI_SITUATION_LENGTH 4
402 #define IPSEC_DOI_LDI_LENGTH 4
403 #define IPSEC_DOI_SPI_SIZE 4
404
405 /* SPI value 0 is invalid and values 1-255 are reserved to IANA.
406 * ESP: RFC 2402 2.4; AH: RFC 2406 2.1
407 * IPComp RFC 2393 substitutes a CPI in the place of an SPI.
408 * see also draft-shacham-ippcp-rfc2393bis-05.txt.
409 * We (FreeS/WAN) reserve 0x100 to 0xFFF for manual keying, so
410 * Pluto won't generate these values.
411 */
412 #define IPSEC_DOI_SPI_MIN 0x100
413 #define IPSEC_DOI_SPI_OUR_MIN 0x1000
414
415 /* debugging settings: a set of selections for reporting
416 * These would be more naturally situated in log.h,
417 * but they are shared with whack.
418 * IMPAIR_* actually change behaviour, usually badly,
419 * to aid in testing. Naturally, these are not included in ALL.
420 *
421 * NOTE: changes here must be done in concert with changes to DBGOPT_*
422 * in whack.c. A change to WHACK_MAGIC in whack.h will be required too.
423 */
424 #ifdef DEBUG
425 extern const char *const debug_bit_names[];
426 #endif
427
428 #define DBG_RAW LELEM(0) /* raw packet I/O */
429 #define DBG_CRYPT LELEM(1) /* encryption/decryption of messages */
430 #define DBG_PARSING LELEM(2) /* show decoding of messages */
431 #define DBG_EMITTING LELEM(3) /* show encoding of messages */
432 #define DBG_CONTROL LELEM(4) /* control flow within Pluto */
433 #define DBG_LIFECYCLE LELEM(5) /* SA lifecycle */
434 #define DBG_KLIPS LELEM(6) /* messages to KLIPS */
435 #define DBG_DNS LELEM(7) /* DNS activity */
436 #define DBG_NATT LELEM(8) /* NAT-T */
437 #define DBG_OPPO LELEM(9) /* opportunism */
438 #define DBG_CONTROLMORE LELEM(10) /* more detailed debugging */
439
440 #define DBG_PRIVATE LELEM(11) /* private information: DANGER! */
441
442 #define IMPAIR0 12 /* first bit for IMPAIR_* */
443
444 #define IMPAIR_DELAY_ADNS_KEY_ANSWER LELEM(IMPAIR0+0) /* sleep before answering */
445 #define IMPAIR_DELAY_ADNS_TXT_ANSWER LELEM(IMPAIR0+1) /* sleep before answering */
446 #define IMPAIR_BUST_MI2 LELEM(IMPAIR0+2) /* make MI2 really large */
447 #define IMPAIR_BUST_MR2 LELEM(IMPAIR0+3) /* make MI2 really large */
448
449 #define DBG_NONE 0 /* no options on, including impairments */
450 #define DBG_ALL LRANGES(DBG_RAW, DBG_CONTROLMORE) /* all logging options on EXCEPT DBG_PRIVATE */
451
452 /* State of exchanges
453 *
454 * The name of the state describes the last message sent, not the
455 * message currently being input or output (except during retry).
456 * In effect, the state represents the last completed action.
457 *
458 * Messages are named [MQ][IR]n where
459 * - M stands for Main Mode (Phase 1);
460 * Q stands for Quick Mode (Phase 2)
461 * - I stands for Initiator;
462 * R stands for Responder
463 * - n, a digit, stands for the number of the message
464 *
465 * It would be more convenient if each state accepted a message
466 * and produced one. This is the case for states at the start
467 * or end of an exchange. To fix this, we pretend that there are
468 * MR0 and QR0 messages before the MI1 and QR1 messages. Similarly,
469 * we pretend that there are MR4 and QR2 messages.
470 *
471 * STATE_MAIN_R0 and STATE_QUICK_R0 are intermediate states (not
472 * retained between messages) representing the state that accepts the
473 * first message of an exchange has been read but not processed.
474 *
475 * state_microcode state_microcode_table in demux.c describes
476 * other important details.
477 */
478
479 extern enum_names state_names;
480 extern const char *const state_story[];
481
482 enum state_kind {
483 STATE_UNDEFINED, /* 0 -- most likely accident */
484
485 /* Opportunism states: see "Opportunistic Encryption" 2.2 */
486
487 OPPO_ACQUIRE, /* got an ACQUIRE message for this pair */
488 OPPO_GW_DISCOVERED, /* got TXT specifying gateway */
489
490 /* IKE states */
491
492 STATE_MAIN_R0,
493 STATE_MAIN_I1,
494 STATE_MAIN_R1,
495 STATE_MAIN_I2,
496 STATE_MAIN_R2,
497 STATE_MAIN_I3,
498 STATE_MAIN_R3,
499 STATE_MAIN_I4,
500
501 STATE_QUICK_R0,
502 STATE_QUICK_I1,
503 STATE_QUICK_R1,
504 STATE_QUICK_I2,
505 STATE_QUICK_R2,
506
507 STATE_INFO,
508 STATE_INFO_PROTECTED,
509
510 /* XAUTH states */
511
512 STATE_XAUTH_I0, /* initiator state (client) */
513 STATE_XAUTH_R1, /* responder state (server) */
514 STATE_XAUTH_I1,
515 STATE_XAUTH_R2,
516 STATE_XAUTH_I2,
517 STATE_XAUTH_R3,
518
519 /* Mode Config pull states */
520
521 STATE_MODE_CFG_R0, /* responder state (server) */
522 STATE_MODE_CFG_I1, /* initiator state (client) */
523 STATE_MODE_CFG_R1,
524 STATE_MODE_CFG_I2,
525
526 /* Mode Config push states */
527
528 STATE_MODE_CFG_I0, /* initiator state (client) */
529 STATE_MODE_CFG_R3, /* responder state (server) */
530 STATE_MODE_CFG_I3,
531 STATE_MODE_CFG_R4,
532
533 STATE_IKE_ROOF
534 };
535
536 #define STATE_IKE_FLOOR STATE_MAIN_R0
537
538 #define PHASE1_INITIATOR_STATES (LELEM(STATE_MAIN_I1) | LELEM(STATE_MAIN_I2) \
539 | LELEM(STATE_MAIN_I3) | LELEM(STATE_MAIN_I4))
540 #define ISAKMP_SA_ESTABLISHED_STATES ( \
541 LELEM(STATE_MAIN_R3) | LELEM(STATE_MAIN_I4) \
542 | LELEM(STATE_XAUTH_R1) | LELEM(STATE_XAUTH_R2) | LELEM(STATE_XAUTH_R3) \
543 | LELEM(STATE_XAUTH_I1) | LELEM(STATE_XAUTH_I2) \
544 | LELEM(STATE_MODE_CFG_I1) | LELEM(STATE_MODE_CFG_R1) | LELEM(STATE_MODE_CFG_I2) \
545 | LELEM(STATE_MODE_CFG_R3) | LELEM(STATE_MODE_CFG_I3) | LELEM(STATE_MODE_CFG_R4))
546
547 #define IS_PHASE1(s) ((STATE_MAIN_R0 <= (s) && (s) <= STATE_MAIN_I4) \
548 || (STATE_XAUTH_I0 <= (s) && (s) <= STATE_XAUTH_R3) \
549 || (STATE_MODE_CFG_R0 <= (s) && (s) <= STATE_MODE_CFG_R4))
550
551 #define IS_QUICK(s) (STATE_QUICK_R0 <= (s) && (s) <= STATE_QUICK_R2)
552 #define IS_ISAKMP_ENCRYPTED(s) (STATE_MAIN_I2 <= (s))
553
554 #define IS_ISAKMP_SA_ESTABLISHED(s) ( \
555 (s) == STATE_MAIN_R3 \
556 || (s) == STATE_MAIN_I4 \
557 || (s) == STATE_XAUTH_R3 \
558 || (s) == STATE_XAUTH_I2 \
559 || (s) == STATE_MODE_CFG_R1 \
560 || (s) == STATE_MODE_CFG_I2 \
561 || (s) == STATE_MODE_CFG_I3 \
562 || (s) == STATE_MODE_CFG_R4)
563
564 #define IS_IPSEC_SA_ESTABLISHED(s) ((s) == STATE_QUICK_I2 || (s) == STATE_QUICK_R2)
565 #define IS_ONLY_INBOUND_IPSEC_SA_ESTABLISHED(s) ((s) == STATE_QUICK_R1)
566
567 /* kind of struct connection
568 * Ordered (mostly) by concreteness. Order is exploited.
569 */
570
571 extern enum_names connection_kind_names;
572
573 enum connection_kind {
574 CK_GROUP, /* policy group: instantiates to template */
575 CK_TEMPLATE, /* abstract connection, with wildcard */
576 CK_PERMANENT, /* normal connection */
577 CK_INSTANCE, /* instance of template, created for a particular attempt */
578 CK_GOING_AWAY /* instance being deleted -- don't delete again */
579 };
580
581
582 /* routing status.
583 * Note: routing ignores source address, but erouting does not!
584 * Note: a connection can only be routed if it is NEVER_NEGOTIATE
585 * or HAS_IPSEC_POLICY.
586 */
587
588 extern enum_names routing_story;
589
590 /* note that this is assumed to be ordered! */
591 enum routing_t {
592 RT_UNROUTED, /* unrouted */
593 RT_UNROUTED_HOLD, /* unrouted, but HOLD shunt installed */
594 RT_ROUTED_ECLIPSED, /* RT_ROUTED_PROSPECTIVE except bare HOLD or instance has eroute */
595 RT_ROUTED_PROSPECTIVE, /* routed, and prospective shunt installed */
596 RT_ROUTED_HOLD, /* routed, and HOLD shunt installed */
597 RT_ROUTED_FAILURE, /* routed, and failure-context shunt installed */
598 RT_ROUTED_TUNNEL, /* routed, and erouted to an IPSEC SA group */
599 RT_UNROUTED_KEYED /* keyed, but not routed, on purpose */
600 };
601
602 #define routed(rs) ((rs) > RT_UNROUTED_HOLD)
603 #define erouted(rs) ((rs) != RT_UNROUTED)
604 #define shunt_erouted(rs) (erouted(rs) && (rs) != RT_ROUTED_TUNNEL)
605
606 /* Payload types
607 * RFC2408 Internet Security Association and Key Management Protocol (ISAKMP)
608 * section 3.1
609 *
610 * RESERVED 14-127
611 * Private USE 128-255
612 */
613
614 extern enum_names payload_names;
615 extern const char *const payload_name[];
616
617 #define ISAKMP_NEXT_NONE 0 /* No other payload following */
618 #define ISAKMP_NEXT_SA 1 /* Security Association */
619 #define ISAKMP_NEXT_P 2 /* Proposal */
620 #define ISAKMP_NEXT_T 3 /* Transform */
621 #define ISAKMP_NEXT_KE 4 /* Key Exchange */
622 #define ISAKMP_NEXT_ID 5 /* Identification */
623 #define ISAKMP_NEXT_CERT 6 /* Certificate */
624 #define ISAKMP_NEXT_CR 7 /* Certificate Request */
625 #define ISAKMP_NEXT_HASH 8 /* Hash */
626 #define ISAKMP_NEXT_SIG 9 /* Signature */
627 #define ISAKMP_NEXT_NONCE 10 /* Nonce */
628 #define ISAKMP_NEXT_N 11 /* Notification */
629 #define ISAKMP_NEXT_D 12 /* Delete */
630 #define ISAKMP_NEXT_VID 13 /* Vendor ID */
631 #define ISAKMP_NEXT_ATTR 14 /* Mode config Attribute */
632
633 #define ISAKMP_NEXT_NATD_RFC 20 /* NAT-Traversal: NAT-D (rfc) */
634 #define ISAKMP_NEXT_NATOA_RFC 21 /* NAT-Traversal: NAT-OA (rfc) */
635 #define ISAKMP_NEXT_ROOF 22 /* roof on payload types */
636
637 #define ISAKMP_NEXT_NATD_DRAFTS 130 /* NAT-Traversal: NAT-D (drafts) */
638 #define ISAKMP_NEXT_NATOA_DRAFTS 131 /* NAT-Traversal: NAT-OA (drafts) */
639
640 /* These values are to be used within the Type field of an Attribute (14)
641 * ISAKMP payload.
642 */
643 #define ISAKMP_CFG_REQUEST 1
644 #define ISAKMP_CFG_REPLY 2
645 #define ISAKMP_CFG_SET 3
646 #define ISAKMP_CFG_ACK 4
647
648 extern enum_names attr_msg_type_names;
649
650 /* Mode Config attribute values */
651 #define INTERNAL_IP4_ADDRESS 1
652 #define INTERNAL_IP4_NETMASK 2
653 #define INTERNAL_IP4_DNS 3
654 #define INTERNAL_IP4_NBNS 4
655 #define INTERNAL_ADDRESS_EXPIRY 5
656 #define INTERNAL_IP4_DHCP 6
657 #define APPLICATION_VERSION 7
658 #define INTERNAL_IP6_ADDRESS 8
659 #define INTERNAL_IP6_NETMASK 9
660 #define INTERNAL_IP6_DNS 10
661 #define INTERNAL_IP6_NBNS 11
662 #define INTERNAL_IP6_DHCP 12
663 #define INTERNAL_IP4_SUBNET 13
664 #define SUPPORTED_ATTRIBUTES 14
665 #define INTERNAL_IP6_SUBNET 15
666
667 #define MODECFG_ROOF 16
668
669 extern enum_names modecfg_attr_names;
670
671 /* XAUTH attribute values */
672 #define XAUTH_TYPE 16520
673 #define XAUTH_USER_NAME 16521
674 #define XAUTH_USER_PASSWORD 16522
675 #define XAUTH_PASSCODE 16523
676 #define XAUTH_MESSAGE 16524
677 #define XAUTH_CHALLENGE 16525
678 #define XAUTH_DOMAIN 16526
679 #define XAUTH_STATUS 16527
680 #define XAUTH_NEXT_PIN 16528
681 #define XAUTH_ANSWER 16529
682
683 #define XAUTH_BASE XAUTH_TYPE
684 #define XAUTH_ROOF 16530
685
686 extern enum_names xauth_attr_names;
687
688 /* ISAKMP mode config attributes specific to the Unity vendor Id */
689 #define UNITY_BANNER 28672
690 #define UNITY_SAVE_PASSWD 28673
691 #define UNITY_DEF_DOMAIN 28674
692 #define UNITY_SPLITDNS_NAME 28675
693 #define UNITY_SPLIT_INCLUDE 28676
694 #define UNITY_NATT_PORT 28677
695 #define UNITY_LOCAL_LAN 28678
696 #define UNITY_PFS 28679
697 #define UNITY_FW_TYPE 28680
698 #define UNITY_BACKUP_SERVERS 28681
699 #define UNITY_DDNS_HOSTNAME 28682
700
701 #define UNITY_BASE UNITY_BANNER
702
703 extern enum_names unity_attr_names;
704
705 /* XAUTH authentication types */
706 #define XAUTH_TYPE_GENERIC 0
707 #define XAUTH_TYPE_CHAP 1
708 #define XAUTH_TYPE_OTP 2
709 #define XAUTH_TYPE_SKEY 3
710
711 /* Values for XAUTH_STATUS */
712 #define XAUTH_STATUS_FAIL 0
713 #define XAUTH_STATUS_OK 1
714
715 extern enum_names xauth_type_names;
716
717 /* Exchange types
718 * RFC2408 "Internet Security Association and Key Management Protocol (ISAKMP)"
719 * section 3.1
720 *
721 * ISAKMP Future Use 6 - 31
722 * DOI Specific Use 32 - 239
723 * Private Use 240 - 255
724 *
725 * Note: draft-ietf-ipsec-dhless-enc-mode-00.txt Appendix A
726 * defines "DHless RSA Encryption" as 6.
727 */
728
729 extern enum_names exchange_names;
730
731 #define ISAKMP_XCHG_NONE 0
732 #define ISAKMP_XCHG_BASE 1
733 #define ISAKMP_XCHG_IDPROT 2 /* ID Protection */
734 #define ISAKMP_XCHG_AO 3 /* Authentication Only */
735 #define ISAKMP_XCHG_AGGR 4 /* Aggressive */
736 #define ISAKMP_XCHG_INFO 5 /* Informational */
737 #define ISAKMP_XCHG_MODE_CFG 6 /* Mode Config */
738
739 /* Extra exchange types, defined by Oakley
740 * RFC2409 "The Internet Key Exchange (IKE)", near end of Appendix A
741 */
742 #define ISAKMP_XCHG_QUICK 32 /* Oakley Quick Mode */
743 #define ISAKMP_XCHG_NGRP 33 /* Oakley New Group Mode */
744 /* added in draft-ietf-ipsec-ike-01.txt, near end of Appendix A */
745 #define ISAKMP_XCHG_ACK_INFO 34 /* Oakley Acknowledged Informational */
746
747 /* Flag bits */
748
749 extern const char *const flag_bit_names[];
750
751 #define ISAKMP_FLAG_ENCRYPTION 0x1
752 #define ISAKMP_FLAG_COMMIT 0x2
753
754 /* Situation definition for IPsec DOI */
755
756 extern const char *const sit_bit_names[];
757
758 #define SIT_IDENTITY_ONLY 0x01
759 #define SIT_SECRECY 0x02
760 #define SIT_INTEGRITY 0x04
761
762 /* Protocol IDs
763 * RFC2407 The Internet IP security Domain of Interpretation for ISAKMP 4.4.1
764 */
765
766 extern enum_names protocol_names;
767
768 #define PROTO_ISAKMP 1
769 #define PROTO_IPSEC_AH 2
770 #define PROTO_IPSEC_ESP 3
771 #define PROTO_IPCOMP 4
772
773 /* warning: trans_show uses enum_show, so same static buffer is used */
774 #define trans_show(p, t) \
775 ((p)==PROTO_IPSEC_AH ? enum_show(&ah_transformid_names, (t)) \
776 : (p)==PROTO_IPSEC_ESP ? enum_show(&esp_transformid_names, (t)) \
777 : (p)==PROTO_IPCOMP ? enum_show(&ipcomp_transformid_names, (t)) \
778 : "??")
779
780 /* many transform values are moved to freeswan/ipsec_policy.h */
781
782 extern enum_names isakmp_transformid_names;
783
784 #define KEY_IKE 1
785
786 extern enum_names ah_transformid_names;
787 extern enum_names esp_transformid_names;
788 extern enum_names ipcomp_transformid_names;
789
790 /* the following are from RFC 2393/draft-shacham-ippcp-rfc2393bis-05.txt 3.3 */
791 typedef u_int16_t cpi_t;
792 #define IPCOMP_CPI_SIZE 2
793 #define IPCOMP_FIRST_NEGOTIATED 256
794 #define IPCOMP_LAST_NEGOTIATED 61439
795
796 /* Identification type values
797 * RFC 2407 The Internet IP security Domain of Interpretation for ISAKMP 4.6.2.1
798 */
799
800 extern enum_names ident_names;
801 extern enum_names cert_type_names;
802 extern enum_names cert_policy_names;
803
804 typedef enum certpolicy {
805 CERT_ALWAYS_SEND = 0, /* the default */
806 CERT_SEND_IF_ASKED = 1,
807 CERT_NEVER_SEND = 2,
808
809 CERT_YES_SEND = 3, /* synonym for CERT_ALWAYS_SEND */
810 CERT_NO_SEND = 4 /* synonym for CERT_NEVER_SEND */
811 } certpolicy_t;
812
813 /* Policies for establishing an SA
814 *
815 * These are used to specify attributes (eg. encryption) and techniques
816 * (eg PFS) for an SA.
817 * Note: certain CD_ definitions in whack.c parallel these -- keep them
818 * in sync!
819 */
820
821 extern const char *const sa_policy_bit_names[];
822 extern const char *prettypolicy(lset_t policy);
823
824 /* ISAKMP auth techniques (none means never negotiate) */
825 #define POLICY_PSK LELEM(0)
826 #define POLICY_RSASIG LELEM(1)
827
828 #define POLICY_ISAKMP_SHIFT 0 /* log2(POLICY_PSK) */
829 #define POLICY_ID_AUTH_MASK (POLICY_PSK | POLICY_RSASIG | POLICY_XAUTH_PSK | POLICY_XAUTH_RSASIG)
830 #define POLICY_ISAKMP_MASK POLICY_ID_AUTH_MASK /* all so far */
831
832 /* Quick Mode (IPSEC) attributes */
833 #define POLICY_ENCRYPT LELEM(2) /* must be first of IPSEC policies */
834 #define POLICY_AUTHENTICATE LELEM(3) /* must be second */
835 #define POLICY_COMPRESS LELEM(4) /* must be third */
836 #define POLICY_TUNNEL LELEM(5)
837 #define POLICY_PFS LELEM(6)
838 #define POLICY_DISABLEARRIVALCHECK LELEM(7) /* supress tunnel egress address checking */
839
840 #define POLICY_IPSEC_SHIFT 2 /* log2(POLICY_ENCRYPT) */
841 #define POLICY_IPSEC_MASK LRANGES(POLICY_ENCRYPT, POLICY_DISABLEARRIVALCHECK)
842
843 /* shunt attributes: what to do when routed without tunnel (2 bits) */
844 #define POLICY_SHUNT_SHIFT 8 /* log2(POLICY_SHUNT_PASS) */
845 #define POLICY_SHUNT_MASK (03ul << POLICY_SHUNT_SHIFT)
846
847 #define POLICY_SHUNT_TRAP (0ul << POLICY_SHUNT_SHIFT) /* default: negotiate */
848 #define POLICY_SHUNT_PASS (1ul << POLICY_SHUNT_SHIFT)
849 #define POLICY_SHUNT_DROP (2ul << POLICY_SHUNT_SHIFT)
850 #define POLICY_SHUNT_REJECT (3ul << POLICY_SHUNT_SHIFT)
851
852 /* fail attributes: what to do with failed negotiation (2 bits) */
853
854 #define POLICY_FAIL_SHIFT 10 /* log2(POLICY_FAIL_PASS) */
855 #define POLICY_FAIL_MASK (03ul << POLICY_FAIL_SHIFT)
856
857 #define POLICY_FAIL_NONE (0ul << POLICY_FAIL_SHIFT) /* default */
858 #define POLICY_FAIL_PASS (1ul << POLICY_FAIL_SHIFT)
859 #define POLICY_FAIL_DROP (2ul << POLICY_FAIL_SHIFT)
860 #define POLICY_FAIL_REJECT (3ul << POLICY_FAIL_SHIFT)
861
862 /* connection policy
863 * Other policies could vary per state object. These live in connection.
864 */
865 #define POLICY_DONT_REKEY LELEM(12) /* don't rekey state either Phase */
866 #define POLICY_OPPO LELEM(13) /* is this opportunistic? */
867 #define POLICY_GROUP LELEM(14) /* is this a group template? */
868 #define POLICY_GROUTED LELEM(15) /* do we want this group routed? */
869 #define POLICY_UP LELEM(16) /* do we want this up? */
870 #define POLICY_MODECFG_PUSH LELEM(17) /* is modecfg pushed by server? */
871 #define POLICY_XAUTH_PSK LELEM(18) /* do we support XAUTH????PreShared? */
872 #define POLICY_XAUTH_RSASIG LELEM(19) /* do we support XAUTH????RSA? */
873 #define POLICY_XAUTH_SERVER LELEM(20) /* are we an XAUTH server? */
874 #define POLICY_DONT_REAUTH LELEM(21) /* don't reauthenticate on rekeying, IKEv2 only */
875 #define POLICY_BEET LELEM(22) /* bound end2end tunnel, IKEv2 */
876
877 /* Any IPsec policy? If not, a connection description
878 * is only for ISAKMP SA, not IPSEC SA. (A pun, I admit.)
879 * Note: a connection can only be routed if it is NEVER_NEGOTIATE
880 * or HAS_IPSEC_POLICY.
881 */
882 #define HAS_IPSEC_POLICY(p) (((p) & POLICY_IPSEC_MASK) != 0)
883
884 /* Don't allow negotiation? */
885 #define NEVER_NEGOTIATE(p) (LDISJOINT((p), POLICY_ID_AUTH_MASK))
886
887
888 /* Oakley transform attributes
889 * draft-ietf-ipsec-ike-01.txt appendix A
890 */
891
892 extern enum_names oakley_attr_names;
893 extern const char *const oakley_attr_bit_names[];
894
895 #define OAKLEY_ENCRYPTION_ALGORITHM 1
896 #define OAKLEY_HASH_ALGORITHM 2
897 #define OAKLEY_AUTHENTICATION_METHOD 3
898 #define OAKLEY_GROUP_DESCRIPTION 4
899 #define OAKLEY_GROUP_TYPE 5
900 #define OAKLEY_GROUP_PRIME 6 /* B/V */
901 #define OAKLEY_GROUP_GENERATOR_ONE 7 /* B/V */
902 #define OAKLEY_GROUP_GENERATOR_TWO 8 /* B/V */
903 #define OAKLEY_GROUP_CURVE_A 9 /* B/V */
904 #define OAKLEY_GROUP_CURVE_B 10 /* B/V */
905 #define OAKLEY_LIFE_TYPE 11
906 #define OAKLEY_LIFE_DURATION 12 /* B/V */
907 #define OAKLEY_PRF 13
908 #define OAKLEY_KEY_LENGTH 14
909 #define OAKLEY_FIELD_SIZE 15
910 #define OAKLEY_GROUP_ORDER 16 /* B/V */
911 #define OAKLEY_BLOCK_SIZE 17
912
913 /* for each Oakley attribute, which enum_names describes its values? */
914 extern enum_names *oakley_attr_val_descs[];
915
916 /* IPsec DOI attributes
917 * RFC2407 The Internet IP security Domain of Interpretation for ISAKMP 4.5
918 */
919
920 extern enum_names ipsec_attr_names;
921
922 #define SA_LIFE_TYPE 1
923 #define SA_LIFE_DURATION 2 /* B/V */
924 #define GROUP_DESCRIPTION 3
925 #define ENCAPSULATION_MODE 4
926 #define AUTH_ALGORITHM 5
927 #define KEY_LENGTH 6
928 #define KEY_ROUNDS 7
929 #define COMPRESS_DICT_SIZE 8
930 #define COMPRESS_PRIVATE_ALG 9 /* B/V */
931
932 /* for each IPsec attribute, which enum_names describes its values? */
933 extern enum_names *ipsec_attr_val_descs[];
934
935 /* SA Lifetime Type attribute
936 * RFC2407 The Internet IP security Domain of Interpretation for ISAKMP 4.5
937 * Default time specified in 4.5
938 *
939 * There are two defaults for IPSEC SA lifetime, SA_LIFE_DURATION_DEFAULT,
940 * and PLUTO_SA_LIFE_DURATION_DEFAULT.
941 * SA_LIFE_DURATION_DEFAULT is specified in RFC2407 "The Internet IP
942 * Security Domain of Interpretation for ISAKMP" 4.5. It applies when
943 * an ISAKMP negotiation does not explicitly specify a life duration.
944 * PLUTO_SA_LIFE_DURATION_DEFAULT is specified in pluto(8). It applies
945 * when a connection description does not specify --ipseclifetime.
946 * The value of SA_LIFE_DURATION_MAXIMUM is our local policy.
947 */
948
949 extern enum_names sa_lifetime_names;
950
951 #define SA_LIFE_TYPE_SECONDS 1
952 #define SA_LIFE_TYPE_KBYTES 2
953
954 #define SA_LIFE_DURATION_DEFAULT 28800 /* eight hours (RFC2407 4.5) */
955 #define PLUTO_SA_LIFE_DURATION_DEFAULT 3600 /* one hour (pluto(8)) */
956 #define SA_LIFE_DURATION_MAXIMUM 86400 /* one day */
957
958 #define SA_REPLACEMENT_MARGIN_DEFAULT 540 /* (IPSEC & IKE) nine minutes */
959 #define SA_REPLACEMENT_FUZZ_DEFAULT 100 /* (IPSEC & IKE) 100% of MARGIN */
960 #define SA_REPLACEMENT_RETRIES_DEFAULT 3 /* (IPSEC & IKE) */
961
962 #define SA_LIFE_DURATION_K_DEFAULT 0xFFFFFFFFlu
963
964 /* Encapsulation Mode attribute */
965
966 extern enum_names enc_mode_names;
967
968 #define ENCAPSULATION_MODE_UNSPECIFIED 0 /* not legal -- used internally */
969 #define ENCAPSULATION_MODE_TUNNEL 1
970 #define ENCAPSULATION_MODE_TRANSPORT 2
971
972 #define ENCAPSULATION_MODE_UDP_TUNNEL_RFC 3
973 #define ENCAPSULATION_MODE_UDP_TRANSPORT_RFC 4
974
975 #define ENCAPSULATION_MODE_UDP_TUNNEL_DRAFTS 61443
976 #define ENCAPSULATION_MODE_UDP_TRANSPORT_DRAFTS 61444
977
978 /* Auth Algorithm attribute */
979
980 extern enum_names auth_alg_names, extended_auth_alg_names;
981
982 #define AUTH_ALGORITHM_NONE 0 /* our private designation */
983 #define AUTH_ALGORITHM_HMAC_MD5 1
984 #define AUTH_ALGORITHM_HMAC_SHA1 2
985 #define AUTH_ALGORITHM_DES_MAC 3
986 #define AUTH_ALGORITHM_KPDK 4
987 #define AUTH_ALGORITHM_HMAC_SHA2_256 5
988 #define AUTH_ALGORITHM_HMAC_SHA2_384 6
989 #define AUTH_ALGORITHM_HMAC_SHA2_512 7
990 #define AUTH_ALGORITHM_HMAC_RIPEMD 8
991 #define AUTH_ALGORITHM_NULL 251
992
993 /* Oakley Lifetime Type attribute
994 * draft-ietf-ipsec-ike-01.txt appendix A
995 * As far as I can see, there is not specification for
996 * OAKLEY_ISAKMP_SA_LIFETIME_DEFAULT. This could lead to interop problems!
997 * For no particular reason, we chose three hours.
998 * The value of OAKLEY_ISAKMP_SA_LIFETIME_MAXIMUM is our local policy.
999 */
1000 extern enum_names oakley_lifetime_names;
1001
1002 #define OAKLEY_LIFE_SECONDS 1
1003 #define OAKLEY_LIFE_KILOBYTES 2
1004
1005 #define OAKLEY_ISAKMP_SA_LIFETIME_DEFAULT 10800 /* three hours */
1006 #define OAKLEY_ISAKMP_SA_LIFETIME_MAXIMUM 86400 /* one day */
1007
1008 /* Oakley PRF attribute (none defined)
1009 * draft-ietf-ipsec-ike-01.txt appendix A
1010 */
1011 extern enum_names oakley_prf_names;
1012
1013 /* HMAC (see rfc2104.txt) */
1014
1015 #define HMAC_IPAD 0x36
1016 #define HMAC_OPAD 0x5C
1017 #define HMAC_BUFSIZE 64
1018
1019 /* Oakley Encryption Algorithm attribute
1020 * draft-ietf-ipsec-ike-01.txt appendix A
1021 * and from http://www.isi.edu/in-notes/iana/assignments/ipsec-registry
1022 */
1023
1024 extern enum_names oakley_enc_names;
1025
1026 #define OAKLEY_DES_CBC 1
1027 #define OAKLEY_IDEA_CBC 2
1028 #define OAKLEY_BLOWFISH_CBC 3
1029 #define OAKLEY_RC5_R16_B64_CBC 4
1030 #define OAKLEY_3DES_CBC 5
1031 #define OAKLEY_CAST_CBC 6
1032 #define OAKLEY_AES_CBC 7
1033
1034 #define OAKLEY_MARS_CBC 65001
1035 #define OAKLEY_RC6_CBC 65002
1036 #define OAKLEY_ID_65003 65003
1037 #define OAKLEY_SERPENT_CBC 65004
1038 #define OAKLEY_TWOFISH_CBC 65005
1039
1040 #define OAKLEY_TWOFISH_CBC_SSH 65289
1041
1042 #define OAKLEY_ENCRYPT_MAX 65535 /* pretty useless :) */
1043
1044 /* Oakley Hash Algorithm attribute
1045 * draft-ietf-ipsec-ike-01.txt appendix A
1046 * and from http://www.isi.edu/in-notes/iana/assignments/ipsec-registry
1047 */
1048
1049 extern enum_names oakley_hash_names;
1050
1051 #define OAKLEY_MD5 1
1052 #define OAKLEY_SHA 2
1053 #define OAKLEY_TIGER 3
1054 #define OAKLEY_SHA2_256 4
1055 #define OAKLEY_SHA2_384 5
1056 #define OAKLEY_SHA2_512 6
1057
1058 #define OAKLEY_HASH_MAX 7
1059
1060 /* Oakley Authentication Method attribute
1061 * draft-ietf-ipsec-ike-01.txt appendix A
1062 * Goofy Hybrid extensions from draft-ietf-ipsec-isakmp-hybrid-auth-05.txt
1063 * Goofy XAUTH extensions from draft-ietf-ipsec-isakmp-xauth-06.txt
1064 */
1065
1066 extern enum_names oakley_auth_names;
1067
1068 #define OAKLEY_PRESHARED_KEY 1
1069 #define OAKLEY_DSS_SIG 2
1070 #define OAKLEY_RSA_SIG 3
1071 #define OAKLEY_RSA_ENC 4
1072 #define OAKLEY_RSA_ENC_REV 5
1073 #define OAKLEY_ELGAMAL_ENC 6
1074 #define OAKLEY_ELGAMAL_ENC_REV 7
1075
1076 #define OAKLEY_AUTH_ROOF 8 /* roof on auth values THAT WE SUPPORT */
1077
1078 #define HybridInitRSA 64221
1079 #define HybridRespRSA 64222
1080 #define HybridInitDSS 64223
1081 #define HybridRespDSS 64224
1082
1083 #define XAUTHInitPreShared 65001
1084 #define XAUTHRespPreShared 65002
1085 #define XAUTHInitDSS 65003
1086 #define XAUTHRespDSS 65004
1087 #define XAUTHInitRSA 65005
1088 #define XAUTHRespRSA 65006
1089 #define XAUTHInitRSAEncryption 65007
1090 #define XAUTHRespRSAEncryption 65008
1091 #define XAUTHInitRSARevisedEncryption 65009
1092 #define XAUTHRespRSARevisedEncryption 65010
1093
1094 /* Oakley Group Description attribute
1095 * draft-ietf-ipsec-ike-01.txt appendix A
1096 */
1097 extern enum_names oakley_group_names;
1098
1099 #define OAKLEY_GROUP_MODP768 1
1100 #define OAKLEY_GROUP_MODP1024 2
1101 #define OAKLEY_GROUP_GP155 3
1102 #define OAKLEY_GROUP_GP185 4
1103 #define OAKLEY_GROUP_MODP1536 5
1104
1105 #define OAKLEY_GROUP_MODP2048 14
1106 #define OAKLEY_GROUP_MODP3072 15
1107 #define OAKLEY_GROUP_MODP4096 16
1108 #define OAKLEY_GROUP_MODP6144 17
1109 #define OAKLEY_GROUP_MODP8192 18
1110 /* you must also touch: constants.c, crypto.c */
1111
1112 /* Oakley Group Type attribute
1113 * draft-ietf-ipsec-ike-01.txt appendix A
1114 */
1115 extern enum_names oakley_group_type_names;
1116
1117 #define OAKLEY_GROUP_TYPE_MODP 1
1118 #define OAKLEY_GROUP_TYPE_ECP 2
1119 #define OAKLEY_GROUP_TYPE_EC2N 3
1120
1121
1122 /* Notify messages -- error types
1123 * See RFC2408 ISAKMP 3.14.1
1124 */
1125
1126 extern enum_names notification_names;
1127 extern enum_names ipsec_notification_names;
1128
1129 typedef enum {
1130 NOTHING_WRONG = 0, /* unofficial! */
1131
1132 INVALID_PAYLOAD_TYPE = 1,
1133 DOI_NOT_SUPPORTED = 2,
1134 SITUATION_NOT_SUPPORTED = 3,
1135 INVALID_COOKIE = 4,
1136 INVALID_MAJOR_VERSION = 5,
1137 INVALID_MINOR_VERSION = 6,
1138 INVALID_EXCHANGE_TYPE = 7,
1139 INVALID_FLAGS = 8,
1140 INVALID_MESSAGE_ID = 9,
1141 INVALID_PROTOCOL_ID = 10,
1142 INVALID_SPI = 11,
1143 INVALID_TRANSFORM_ID = 12,
1144 ATTRIBUTES_NOT_SUPPORTED = 13,
1145 NO_PROPOSAL_CHOSEN = 14,
1146 BAD_PROPOSAL_SYNTAX = 15,
1147 PAYLOAD_MALFORMED = 16,
1148 INVALID_KEY_INFORMATION = 17,
1149 INVALID_ID_INFORMATION = 18,
1150 INVALID_CERT_ENCODING = 19,
1151 INVALID_CERTIFICATE = 20,
1152 CERT_TYPE_UNSUPPORTED = 21,
1153 INVALID_CERT_AUTHORITY = 22,
1154 INVALID_HASH_INFORMATION = 23,
1155 AUTHENTICATION_FAILED = 24,
1156 INVALID_SIGNATURE = 25,
1157 ADDRESS_NOTIFICATION = 26,
1158 NOTIFY_SA_LIFETIME = 27,
1159 CERTIFICATE_UNAVAILABLE = 28,
1160 UNSUPPORTED_EXCHANGE_TYPE = 29,
1161 UNEQUAL_PAYLOAD_LENGTHS = 30,
1162
1163 /* ISAKMP status type */
1164 CONNECTED = 16384,
1165
1166 /* IPSEC DOI additions; status types (RFC2407 IPSEC DOI 4.6.3)
1167 * These must be sent under the protection of an ISAKMP SA.
1168 */
1169 IPSEC_RESPONDER_LIFETIME = 24576,
1170 IPSEC_REPLAY_STATUS = 24577,
1171 IPSEC_INITIAL_CONTACT = 24578,
1172
1173 /* RFC 3706 DPD */
1174 R_U_THERE = 36136,
1175 R_U_THERE_ACK = 36137
1176
1177 } notification_t;
1178
1179
1180 /* Public key algorithm number
1181 * Same numbering as used in DNSsec
1182 * See RFC 2535 DNSsec 3.2 The KEY Algorithm Number Specification.
1183 * Also found in BIND 8.2.2 include/isc/dst.h as DST algorithm codes.
1184 */
1185
1186 enum pubkey_alg
1187 {
1188 PUBKEY_ALG_RSA = 1,
1189 PUBKEY_ALG_DSA = 3,
1190 };
1191
1192 /* Limits on size of RSA moduli.
1193 * The upper bound matches that of DNSsec (see RFC 2537).
1194 * The lower bound must be more than 11 octets for certain
1195 * the encoding to work, but it must be much larger for any
1196 * real security. For now, we require 512 bits.
1197 */
1198
1199 #define RSA_MIN_OCTETS_RFC 12
1200
1201 #define RSA_MIN_OCTETS (512 / BITS_PER_BYTE)
1202 #define RSA_MIN_OCTETS_UGH "RSA modulus too small for security: less than 512 bits"
1203
1204 #define RSA_MAX_OCTETS (8192 / BITS_PER_BYTE)
1205 #define RSA_MAX_OCTETS_UGH "RSA modulus too large: more than 8192 bits"
1206
1207 /* Note: RFC 2537 encoding adds a few bytes. If you use a small
1208 * modulus like 3, the overhead is only 2 bytes
1209 */
1210 #define RSA_MAX_ENCODING_BYTES (RSA_MAX_OCTETS + 2)
1211
1212 /* socket address family info */
1213
1214 struct af_info
1215 {
1216 int af;
1217 const char *name;
1218 size_t ia_sz;
1219 size_t sa_sz;
1220 int mask_cnt;
1221 u_int8_t id_addr, id_subnet, id_range;
1222 const ip_address *any;
1223 const ip_subnet *none; /* 0.0.0.0/32 or IPv6 equivalent */
1224 const ip_subnet *all; /* 0.0.0.0/0 or IPv6 equivalent */
1225 };
1226
1227 extern const struct af_info
1228 af_inet4_info,
1229 af_inet6_info;
1230
1231 extern const struct af_info *aftoinfo(int af);
1232
1233 extern enum_names af_names;
1234
1235 #define subnetisaddr(sn, a) (subnetishost(sn) && addrinsubnet((a), (sn)))
1236 extern bool subnetisnone(const ip_subnet *sn);
1237
1238 /* BIND enumerated types */
1239
1240 extern enum_names
1241 rr_qtype_names,
1242 rr_type_names,
1243 rr_class_names;
1244
1245 /* How authenticated is info that might have come from DNS?
1246 * In order of increasing confidence.
1247 */
1248 enum dns_auth_level {
1249 DAL_UNSIGNED, /* AD in response, but no signature: no authentication */
1250 DAL_NOTSEC, /* no AD in response: authentication impossible */
1251 DAL_SIGNED, /* AD and signature in response: authentic */
1252 DAL_LOCAL /* locally provided (pretty good) */
1253 };
1254
1255 /*
1256 * define a macro for use in error messages
1257 */
1258
1259 #ifdef USE_KEYRR
1260 #define RRNAME "TXT or KEY"
1261 #else
1262 #define RRNAME "TXT"
1263 #endif
1264
1265 /* natt traversal types */
1266 extern const char *const natt_type_bitnames[];
1267
1268 #endif /* _CONSTANTS_H */