]>
git.saurik.com Git - apple/network_cmds.git/blob - racoon.tproj/handler.h
484376b66128b89fa37e35dff84835162fa01b96
1 /* $KAME: handler.h,v 1.42 2001/12/12 15:29:13 sakane Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * 1 start start (1st msg received)
38 * 2 (---) 1st valid msg received
39 * 3 1st msg sent 1st msg sent
40 * 4 1st valid msg received 2st valid msg received
41 * 5 2nd msg sent 2nd msg sent
42 * 6 2nd valid msg received 3rd valid msg received
43 * 7 3rd msg sent 3rd msg sent
44 * 8 3rd valid msg received (---)
45 * 9 SA established SA established
50 * 1 start start (1st msg received)
51 * 2 (---) 1st valid msg received
52 * 3 1st msg sent 1st msg sent
53 * 4 1st valid msg received 2st valid msg received
58 * 9 SA established SA established
63 * 1 start start (1st msg received)
64 * 2 (---) 1st valid msg received
65 * 3 1st msg sent 1st msg sent
66 * 4 1st valid msg received 2st valid msg received
67 * 5 2nd msg sent (---)
71 * 9 SA established SA established
73 #define PHASE1ST_SPAWN 0
74 #define PHASE1ST_START 1
75 #define PHASE1ST_MSG1RECEIVED 2
76 #define PHASE1ST_MSG1SENT 3
77 #define PHASE1ST_MSG2RECEIVED 4
78 #define PHASE1ST_MSG2SENT 5
79 #define PHASE1ST_MSG3RECEIVED 6
80 #define PHASE1ST_MSG3SENT 7
81 #define PHASE1ST_MSG4RECEIVED 8
82 #define PHASE1ST_ESTABLISHED 9
83 #define PHASE1ST_EXPIRED 10
84 #define PHASE1ST_MAX 11
86 /* About address semantics in each case.
87 * initiator(addr=I) responder(addr=R)
89 * (local) (remote) (local) (remote)
90 * phase 1 handler I R R I
91 * phase 2 handler I R R I
99 int status
; /* status of this SA */
100 int side
; /* INITIATOR or RESPONDER */
102 struct sockaddr
*remote
; /* remote address to negosiate ph1 */
103 struct sockaddr
*local
; /* local address to negosiate ph1 */
104 /* XXX copy from rmconf due to anonymous configuration.
105 * If anonymous will be forbidden, we do delete them. */
107 struct remoteconf
*rmconf
; /* pointer to remote configuration */
109 struct isakmpsa
*approval
; /* pointer to SA(s) approved. */
110 vchar_t
*authstr
; /* place holder of string for auth. */
111 /* for example pre-shared key */
113 u_int8_t version
; /* ISAKMP version */
114 u_int8_t etype
; /* Exchange type actually for use */
115 u_int8_t flags
; /* Flags */
116 u_int32_t msgid
; /* message id */
118 struct sched
*sce
; /* schedule for expire */
120 struct sched
*scr
; /* schedule for resend */
121 int retry_counter
; /* for resend. */
122 vchar_t
*sendbuf
; /* buffer for re-sending */
124 vchar_t
*dhpriv
; /* DH; private value */
125 vchar_t
*dhpub
; /* DH; public value */
126 vchar_t
*dhpub_p
; /* DH; partner's public value */
127 vchar_t
*dhgxy
; /* DH; shared secret */
128 vchar_t
*nonce
; /* nonce value */
129 vchar_t
*nonce_p
; /* partner's nonce value */
130 vchar_t
*skeyid
; /* SKEYID */
131 vchar_t
*skeyid_d
; /* SKEYID_d */
132 vchar_t
*skeyid_a
; /* SKEYID_a, i.e. hash */
133 vchar_t
*skeyid_e
; /* SKEYID_e, i.e. encryption */
134 vchar_t
*key
; /* cipher key */
135 vchar_t
*hash
; /* HASH minus general header */
136 vchar_t
*sig
; /* SIG minus general header */
137 vchar_t
*sig_p
; /* peer's SIG minus general header */
138 cert_t
*cert
; /* CERT minus general header */
139 cert_t
*cert_p
; /* peer's CERT minus general header */
140 cert_t
*crl_p
; /* peer's CRL minus general header */
141 cert_t
*cr_p
; /* peer's CR not including general */
142 vchar_t
*id
; /* ID minus gen header */
143 vchar_t
*id_p
; /* partner's ID minus general header */
144 /* i.e. strut ipsecdoi_id_b*. */
145 struct isakmp_ivm
*ivm
; /* IVs */
147 vchar_t
*sa
; /* whole SA payload to send/to be sent*/
148 /* to calculate HASH */
149 /* NOT INCLUDING general header. */
151 vchar_t
*sa_ret
; /* SA payload to reply/to be replyed */
152 /* NOT INCLUDING general header. */
153 /* NOTE: Should be release after use. */
156 void *gssapi_state
; /* GSS-API specific state. */
157 /* Allocated when needed */
158 vchar_t
*gi_i
; /* optional initiator GSS id */
159 vchar_t
*gi_r
; /* optional responder GSS id */
162 struct isakmp_pl_hash
*pl_hash
; /* pointer to hash payload */
164 time_t created
; /* timestamp for establish */
166 struct timeval start
;
170 u_int32_t msgid2
; /* msgid counter for Phase 2 */
171 int ph2cnt
; /* the number which is negotiated by this phase 1 */
172 LIST_HEAD(_ph2ofph1_
, ph2handle
) ph2tree
;
174 LIST_ENTRY(ph1handle
) chain
;
177 /* Phase 2 handler */
178 /* allocated per a SA or SA bundles of a pair of peer's IP addresses. */
180 * initiator responder
182 * 1 start start (1st msg received)
183 * 2 acquire msg get 1st valid msg received
184 * 3 getspi request sent getspi request sent
185 * 4 getspi done getspi done
186 * 5 1st msg sent 1st msg sent
187 * 6 1st valid msg received 2nd valid msg received
188 * 7 (commit bit) (commit bit)
189 * 8 SAs added SAs added
190 * 9 SAs established SAs established
191 * 10 SAs expired SAs expired
193 #define PHASE2ST_SPAWN 0
194 #define PHASE2ST_START 1
195 #define PHASE2ST_STATUS2 2
196 #define PHASE2ST_GETSPISENT 3
197 #define PHASE2ST_GETSPIDONE 4
198 #define PHASE2ST_MSG1SENT 5
199 #define PHASE2ST_STATUS6 6
200 #define PHASE2ST_COMMIT 7
201 #define PHASE2ST_ADDSA 8
202 #define PHASE2ST_ESTABLISHED 9
203 #define PHASE2ST_EXPIRED 10
204 #define PHASE2ST_MAX 11
207 struct sockaddr
*src
; /* my address of SA. */
208 struct sockaddr
*dst
; /* peer's address of SA. */
211 * copy ip address from ID payloads when ID type is ip address.
212 * In other case, they must be null.
214 struct sockaddr
*src_id
;
215 struct sockaddr
*dst_id
;
217 u_int32_t spid
; /* policy id by kernel */
219 int status
; /* ipsec sa status */
220 u_int8_t side
; /* INITIATOR or RESPONDER */
222 struct sched
*sce
; /* schedule for expire */
223 struct sched
*scr
; /* schedule for resend */
224 int retry_counter
; /* for resend. */
225 vchar_t
*sendbuf
; /* buffer for re-sending */
226 vchar_t
*msg1
; /* buffer for re-sending */
227 /* used for responder's first message */
229 int retry_checkph1
; /* counter to wait phase 1 finished. */
230 /* NOTE: actually it's timer. */
232 u_int32_t seq
; /* sequence number used by PF_KEY */
234 * NOTE: In responder side, we can't identify each SAs
235 * with same destination address for example, when
236 * socket based SA is required. So we set a identifier
237 * number to "seq", and sent kernel by pfkey.
239 u_int8_t satype
; /* satype in PF_KEY */
241 * saved satype in the original PF_KEY request from
242 * the kernel in order to reply a error.
245 u_int8_t flags
; /* Flags for phase 2 */
246 u_int32_t msgid
; /* msgid for phase 2 */
248 struct sainfo
*sainfo
; /* place holder of sainfo */
249 struct saprop
*proposal
; /* SA(s) proposal. */
250 struct saprop
*approval
; /* SA(s) approved. */
251 caddr_t spidx_gen
; /* policy from peer's proposal */
253 struct dhgroup
*pfsgrp
; /* DH; prime number */
254 vchar_t
*dhpriv
; /* DH; private value */
255 vchar_t
*dhpub
; /* DH; public value */
256 vchar_t
*dhpub_p
; /* DH; partner's public value */
257 vchar_t
*dhgxy
; /* DH; shared secret */
258 vchar_t
*id
; /* ID minus gen header */
259 vchar_t
*id_p
; /* peer's ID minus general header */
260 vchar_t
*nonce
; /* nonce value in phase 2 */
261 vchar_t
*nonce_p
; /* partner's nonce value in phase 2 */
263 vchar_t
*sa
; /* whole SA payload to send/to be sent*/
264 /* to calculate HASH */
265 /* NOT INCLUDING general header. */
267 vchar_t
*sa_ret
; /* SA payload to reply/to be replyed */
268 /* NOT INCLUDING general header. */
269 /* NOTE: Should be release after use. */
271 struct isakmp_ivm
*ivm
; /* IVs */
274 struct timeval start
;
277 struct ph1handle
*ph1
; /* back pointer to isakmp status */
279 LIST_ENTRY(ph2handle
) chain
;
280 LIST_ENTRY(ph2handle
) ph1bind
; /* chain to ph1handle */
284 * for handling initial contact.
287 struct sockaddr
*remote
; /* remote address to negosiate ph1 */
288 LIST_ENTRY(contacted
) chain
;
292 * for checking a packet retransmited.
295 struct sockaddr
*remote
; /* the remote address */
296 struct sockaddr
*local
; /* the local address */
297 vchar_t
*hash
; /* hash of the received packet */
298 vchar_t
*sendbuf
; /* buffer for the response */
299 int retry_counter
; /* how many times to send */
300 time_t time_send
; /* timestamp to send a packet */
301 time_t created
; /* timestamp to create a queue */
303 struct sched
*scr
; /* schedule for resend, may not used */
305 LIST_ENTRY(recvdpkt
) chain
;
308 /* for parsing ISAKMP header. */
309 struct isakmp_parse_t
{
310 u_char type
; /* payload type of mine */
311 int len
; /* ntohs(ptr->len) */
312 struct isakmp_gen
*ptr
;
319 * initiator responder
320 * ------------------------- --------------------------
321 * initialize iv(A), ive(A). initialize iv(A), ive(A).
323 * save to iv(B). ---[packet(B)]--> save to ive(B).
325 * packet consistency.
326 * sync iv(B) with ive(B).
327 * check auth, integrity.
329 * save to ive(C). <--[packet(C)]--- save to iv(C).
333 * - In the case that a error is found while cipher processing,
334 * initiator responder
335 * ------------------------- --------------------------
336 * initialize iv(A), ive(A). initialize iv(A), ive(A).
338 * save to iv(B). ---[packet(B)]--> save to ive(B).
340 * packet consistency.
341 * sync iv(B) with ive(B).
342 * check auth, integrity.
345 * get ive2(X) from iv(B).
347 * get iv2(X) from iv(B). <--[packet(Y)]--- save to iv2(Y).
352 * The reason why the responder synchronizes iv with ive after checking the
353 * packet consistency is that it is required to leave the IV for decoding
354 * packet. Because there is a potential of error while checking the packet
355 * consistency. Also the reason why that is before authentication and
356 * integirty check is that the IV for informational exchange has to be made
357 * by the IV which is after packet decoded and checking the packet consistency.
358 * Otherwise IV mismatched happens between the intitiator and the responder.
361 vchar_t
*iv
; /* for decoding packet */
362 /* if phase 1, it's for computing phase2 iv */
363 vchar_t
*ive
; /* for encoding packet */
371 struct sockaddr_storage remote
;
372 struct sockaddr_storage local
;
384 extern struct ph1handle
*getph1byindex
__P((isakmp_index
*));
385 extern struct ph1handle
*getph1byindex0
__P((isakmp_index
*));
386 extern struct ph1handle
*getph1byaddr
__P((struct sockaddr
*,
388 extern vchar_t
*dumpph1
__P((void));
389 extern struct ph1handle
*newph1
__P((void));
390 extern void delph1
__P((struct ph1handle
*));
391 extern int insph1
__P((struct ph1handle
*));
392 extern void remph1
__P((struct ph1handle
*));
393 extern void flushph1
__P((void));
394 extern void initph1tree
__P((void));
396 extern struct ph2handle
*getph2byspidx
__P((struct policyindex
*));
397 extern struct ph2handle
*getph2byspid
__P((u_int32_t
));
398 extern struct ph2handle
*getph2byseq
__P((u_int32_t
));
399 extern struct ph2handle
*getph2bymsgid
__P((struct ph1handle
*, u_int32_t
));
400 extern struct ph2handle
*getph2bysaidx
__P((struct sockaddr
*,
401 struct sockaddr
*, u_int
, u_int32_t
));
402 extern struct ph2handle
*newph2
__P((void));
403 extern void initph2
__P((struct ph2handle
*));
404 extern void delph2
__P((struct ph2handle
*));
405 extern int insph2
__P((struct ph2handle
*));
406 extern void remph2
__P((struct ph2handle
*));
407 extern void flushph2
__P((void));
408 extern void deleteallph2
__P((struct sockaddr
*, struct sockaddr
*, u_int
));
409 extern void initph2tree
__P((void));
411 extern void bindph12
__P((struct ph1handle
*, struct ph2handle
*));
412 extern void unbindph12
__P((struct ph2handle
*));
414 extern struct contacted
*getcontacted
__P((struct sockaddr
*));
415 extern int inscontacted
__P((struct sockaddr
*));
416 extern void initctdtree
__P((void));
418 extern int check_recvdpkt
__P((struct sockaddr
*,
419 struct sockaddr
*, vchar_t
*));
420 extern int add_recvdpkt
__P((struct sockaddr
*, struct sockaddr
*,
421 vchar_t
*, vchar_t
*));
422 extern void init_recvdpkt
__P((void));