1 /* $Id: ipsec_doi.c,v 1.26.2.16 2006/02/02 14:37:17 vanhu 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
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/socket.h>
38 #include <netinet/in.h>
40 #ifndef HAVE_NETINET6_IPSEC
41 #include <netinet/ipsec.h>
43 #include <netinet6/ipsec.h>
51 #if TIME_WITH_SYS_TIME
52 # include <sys/time.h>
56 # include <sys/time.h>
68 #include "cfparse_proto.h"
69 #include "isakmp_var.h"
71 #include "ipsec_doi.h"
73 #include "remoteconf.h"
74 #include "localconf.h"
78 #include "algorithm.h"
81 #include "crypto_openssl.h"
86 #include "nattraversal.h"
89 static int switch_authmethod(int);
95 #ifdef HAVE_ICONV_2ND_CONST
96 #define __iconv_const const
102 int verbose_proposal_check
= 1;
104 static vchar_t
*get_ph1approval
__P((struct ph1handle
*, struct prop_pair
**));
105 static struct isakmpsa
*get_ph1approvalx
__P((struct prop_pair
*,
106 struct isakmpsa
*, struct isakmpsa
*, int));
107 static void print_ph1mismatched
__P((struct prop_pair
*, struct isakmpsa
*));
108 static int t2isakmpsa
__P((struct isakmp_pl_t
*, struct isakmpsa
*));
109 static int cmp_aproppair_i
__P((struct prop_pair
*, struct prop_pair
*));
110 static struct prop_pair
*get_ph2approval
__P((struct ph2handle
*,
111 struct prop_pair
**));
112 static struct prop_pair
*get_ph2approvalx
__P((struct ph2handle
*,
113 struct prop_pair
*));
114 static void free_proppair0
__P((struct prop_pair
*));
116 static int get_transform
117 __P((struct isakmp_pl_p
*, struct prop_pair
**, int *));
118 static u_int32_t ipsecdoi_set_ld
__P((vchar_t
*));
120 static int check_doi
__P((u_int32_t
));
121 static int check_situation
__P((u_int32_t
));
123 static int check_prot_main
__P((int));
124 static int check_prot_quick
__P((int));
125 static int (*check_protocol
[]) __P((int)) = {
126 check_prot_main
, /* IPSECDOI_TYPE_PH1 */
127 check_prot_quick
, /* IPSECDOI_TYPE_PH2 */
130 static int check_spi_size
__P((int, int));
132 static int check_trns_isakmp
__P((int));
133 static int check_trns_ah
__P((int));
134 static int check_trns_esp
__P((int));
135 static int check_trns_ipcomp
__P((int));
136 static int (*check_transform
[]) __P((int)) = {
138 check_trns_isakmp
, /* IPSECDOI_PROTO_ISAKMP */
139 check_trns_ah
, /* IPSECDOI_PROTO_IPSEC_AH */
140 check_trns_esp
, /* IPSECDOI_PROTO_IPSEC_ESP */
141 check_trns_ipcomp
, /* IPSECDOI_PROTO_IPCOMP */
144 static int check_attr_isakmp
__P((struct isakmp_pl_t
*));
145 static int check_attr_ah
__P((struct isakmp_pl_t
*));
146 static int check_attr_esp
__P((struct isakmp_pl_t
*));
147 static int check_attr_ipsec
__P((int, struct isakmp_pl_t
*));
148 static int check_attr_ipcomp
__P((struct isakmp_pl_t
*));
149 static int (*check_attributes
[]) __P((struct isakmp_pl_t
*)) = {
151 check_attr_isakmp
, /* IPSECDOI_PROTO_ISAKMP */
152 check_attr_ah
, /* IPSECDOI_PROTO_IPSEC_AH */
153 check_attr_esp
, /* IPSECDOI_PROTO_IPSEC_ESP */
154 check_attr_ipcomp
, /* IPSECDOI_PROTO_IPCOMP */
157 static int setph1prop
__P((struct isakmpsa
*, caddr_t
));
158 static int setph1trns
__P((struct isakmpsa
*, caddr_t
));
159 static int setph1attr
__P((struct isakmpsa
*, caddr_t
));
160 static vchar_t
*setph2proposal0
__P((const struct ph2handle
*,
161 const struct saprop
*, const struct saproto
*));
163 static vchar_t
*getidval
__P((int, vchar_t
*));
166 static struct isakmpsa
*fixup_initiator_sa
__P((struct isakmpsa
*,
172 * check phase 1 SA payload.
173 * make new SA payload to be replyed not including general header.
174 * the pointer to one of isakmpsa in proposal is set into iph1->approval.
176 * positive: the pointer to new buffer of SA payload.
177 * network byte order.
178 * NULL : error occurd.
181 ipsecdoi_checkph1proposal(sa
, iph1
)
183 struct ph1handle
*iph1
;
185 vchar_t
*newsa
; /* new SA payload approved. */
186 struct prop_pair
**pair
;
188 /* get proposal pair */
189 pair
= get_proppair(sa
, IPSECDOI_TYPE_PH1
);
193 /* check and get one SA for use */
194 newsa
= get_ph1approval(iph1
, pair
);
201 iph1
->sa_ret
= newsa
;
207 * acceptable check for remote configuration.
208 * return a new SA payload to be reply to peer.
211 get_ph1approval(iph1
, pair
)
212 struct ph1handle
*iph1
;
213 struct prop_pair
**pair
;
216 struct isakmpsa
*sa
, tsa
;
217 struct prop_pair
*s
, *p
;
221 if (iph1
->approval
) {
222 delisakmpsa(iph1
->approval
);
223 iph1
->approval
= NULL
;
226 for (i
= 0; i
< MAXPROPPAIRLEN
; i
++) {
229 for (s
= pair
[i
]; s
; s
= s
->next
) {
231 sizeof(struct isakmp_pl_p
) + s
->prop
->spi_size
;
233 /* compare proposal and select one */
234 for (p
= s
; p
; p
= p
->tnext
) {
235 if ((sa
= get_ph1approvalx(p
,
236 iph1
->rmconf
->proposal
, &tsa
,
237 iph1
->rmconf
->pcheck_level
)) != NULL
)
244 * if there is no suitable proposal, racoon complains about all of
245 * mismatched items in those proposal.
247 if (verbose_proposal_check
) {
248 for (i
= 0; i
< MAXPROPPAIRLEN
; i
++) {
251 for (s
= pair
[i
]; s
; s
= s
->next
) {
252 prophlen
= sizeof(struct isakmp_pl_p
)
254 for (p
= s
; p
; p
= p
->tnext
) {
255 print_ph1mismatched(p
,
256 iph1
->rmconf
->proposal
);
261 plog(LLV_ERROR
, LOCATION
, NULL
, "no suitable proposal found.\n");
266 plog(LLV_DEBUG
, LOCATION
, NULL
, "an acceptable proposal found.\n");
268 /* check DH group settings */
270 if (sa
->dhgrp
->prime
&& sa
->dhgrp
->gen1
) {
274 plog(LLV_WARNING
, LOCATION
, NULL
,
275 "invalid DH parameter found, use default.\n");
276 oakley_dhgrp_free(sa
->dhgrp
);
280 if (oakley_setdhgroup(sa
->dh_group
, &sa
->dhgrp
) == -1) {
288 if (sa
->gssid
!= NULL
)
289 plog(LLV_DEBUG
, LOCATION
, NULL
, "gss id in new sa '%.*s'\n",
290 (int)sa
->gssid
->l
, sa
->gssid
->v
);
291 if (iph1
-> side
== INITIATOR
) {
292 if (iph1
->rmconf
->proposal
->gssid
!= NULL
)
293 iph1
->gi_i
= vdup(iph1
->rmconf
->proposal
->gssid
);
294 if (tsa
.gssid
!= NULL
)
295 iph1
->gi_r
= vdup(tsa
.gssid
);
296 iph1
->approval
= fixup_initiator_sa(sa
, &tsa
);
298 if (tsa
.gssid
!= NULL
) {
299 iph1
->gi_r
= vdup(tsa
.gssid
);
300 iph1
->gi_i
= gssapi_get_id(iph1
);
301 if (sa
->gssid
== NULL
&& iph1
->gi_i
!= NULL
)
302 sa
->gssid
= vdup(iph1
->gi_i
);
306 if (iph1
->gi_i
!= NULL
)
307 plog(LLV_DEBUG
, LOCATION
, NULL
, "GIi is %.*s\n",
308 (int)iph1
->gi_i
->l
, iph1
->gi_i
->v
);
309 if (iph1
->gi_r
!= NULL
)
310 plog(LLV_DEBUG
, LOCATION
, NULL
, "GIr is %.*s\n",
311 (int)iph1
->gi_r
->l
, iph1
->gi_r
->v
);
316 plog(LLV_DEBUG
, LOCATION
, NULL
, "agreed on %s auth.\n",
317 s_oakley_attr_method(iph1
->approval
->authmethod
));
320 newsa
= get_sabyproppair(p
, iph1
);
322 delisakmpsa(iph1
->approval
);
323 iph1
->approval
= NULL
;
330 * compare peer's single proposal and all of my proposal.
331 * and select one if suiatable.
332 * p : one of peer's proposal.
333 * proposal: my proposals.
335 static struct isakmpsa
*
336 get_ph1approvalx(p
, proposal
, sap
, check_level
)
338 struct isakmpsa
*proposal
, *sap
;
341 struct isakmp_pl_p
*prop
= p
->prop
;
342 struct isakmp_pl_t
*trns
= p
->trns
;
343 struct isakmpsa sa
, *s
, *tsap
;
347 plog(LLV_DEBUG
, LOCATION
, NULL
,
348 "prop#=%d, prot-id=%s, spi-size=%d, #trns=%d\n",
349 prop
->p_no
, s_ipsecdoi_proto(prop
->proto_id
),
350 prop
->spi_size
, prop
->num_t
);
352 plog(LLV_DEBUG
, LOCATION
, NULL
,
353 "trns#=%d, trns-id=%s\n",
355 s_ipsecdoi_trns(prop
->proto_id
, trns
->t_id
));
357 tsap
= sap
!= NULL
? sap
: &sa
;
359 memset(tsap
, 0, sizeof(*tsap
));
360 if (t2isakmpsa(trns
, tsap
) < 0)
362 for (s
= proposal
; s
!= NULL
; s
= s
->next
) {
364 authmethod
= switch_authmethod(s
->authmethod
);
365 tsap_authmethod
= switch_authmethod(tsap
->authmethod
);
367 authmethod
= s
->authmethod
;
368 tsap_authmethod
= tsap
->authmethod
;
370 plog(LLV_DEBUG
, LOCATION
, NULL
, "Compared: DB:Peer\n");
371 plog(LLV_DEBUG
, LOCATION
, NULL
, "(lifetime = %ld:%ld)\n",
372 (long)s
->lifetime
, (long)tsap
->lifetime
);
373 plog(LLV_DEBUG
, LOCATION
, NULL
, "(lifebyte = %zu:%zu)\n",
374 s
->lifebyte
, tsap
->lifebyte
);
375 plog(LLV_DEBUG
, LOCATION
, NULL
, "enctype = %s:%s\n",
376 s_oakley_attr_v(OAKLEY_ATTR_ENC_ALG
,
378 s_oakley_attr_v(OAKLEY_ATTR_ENC_ALG
,
380 plog(LLV_DEBUG
, LOCATION
, NULL
, "(encklen = %d:%d)\n",
381 s
->encklen
, tsap
->encklen
);
382 plog(LLV_DEBUG
, LOCATION
, NULL
, "hashtype = %s:%s\n",
383 s_oakley_attr_v(OAKLEY_ATTR_HASH_ALG
,
385 s_oakley_attr_v(OAKLEY_ATTR_HASH_ALG
,
387 plog(LLV_DEBUG
, LOCATION
, NULL
, "authmethod = %s:%s\n",
388 s_oakley_attr_v(OAKLEY_ATTR_AUTH_METHOD
,
390 s_oakley_attr_v(OAKLEY_ATTR_AUTH_METHOD
,
392 plog(LLV_DEBUG
, LOCATION
, NULL
, "dh_group = %s:%s\n",
393 s_oakley_attr_v(OAKLEY_ATTR_GRP_DESC
,
395 s_oakley_attr_v(OAKLEY_ATTR_GRP_DESC
,
398 /* XXX to be considered ? */
399 if (tsap
->lifebyte
> s
->lifebyte
) ;
402 * if responder side and peer's key length in proposal
403 * is bigger than mine, it might be accepted.
405 if(tsap
->enctype
== s
->enctype
&&
406 (tsap
->authmethod
== authmethod
|| tsap_authmethod
== authmethod
) &&
407 tsap
->hashtype
== s
->hashtype
&&
408 tsap
->dh_group
== s
->dh_group
&&
409 tsap
->encklen
== s
->encklen
) {
410 switch(check_level
) {
411 case PROP_CHECK_OBEY
:
415 case PROP_CHECK_STRICT
:
416 if ((tsap
->lifetime
> s
->lifetime
) ||
417 (tsap
->lifebyte
> s
->lifebyte
))
422 case PROP_CHECK_CLAIM
:
423 if (tsap
->lifetime
< s
->lifetime
)
424 s
->lifetime
= tsap
->lifetime
;
425 if (tsap
->lifebyte
< s
->lifebyte
)
426 s
->lifebyte
= tsap
->lifebyte
;
430 case PROP_CHECK_EXACT
:
431 if ((tsap
->lifetime
!= s
->lifetime
) ||
432 (tsap
->lifebyte
!= s
->lifebyte
))
438 plog(LLV_ERROR
, LOCATION
, NULL
,
439 "Unexpected proposal_check value\n");
447 if (tsap
->dhgrp
!= NULL
){
448 oakley_dhgrp_free(tsap
->dhgrp
);
452 if ((s
= dupisakmpsa(s
)) != NULL
) {
453 switch(check_level
) {
454 case PROP_CHECK_OBEY
:
455 s
->lifetime
= tsap
->lifetime
;
456 s
->lifebyte
= tsap
->lifebyte
;
459 case PROP_CHECK_STRICT
:
460 s
->lifetime
= tsap
->lifetime
;
461 s
->lifebyte
= tsap
->lifebyte
;
464 case PROP_CHECK_CLAIM
:
465 if (tsap
->lifetime
< s
->lifetime
)
466 s
->lifetime
= tsap
->lifetime
;
467 if (tsap
->lifebyte
< s
->lifebyte
)
468 s
->lifebyte
= tsap
->lifebyte
;
474 // hack to get around cisco rekeys
475 if (tsap
->authmethod
!= authmethod
&& tsap_authmethod
== authmethod
) {
476 s
->authmethod
= tsap
->authmethod
;
483 * print all of items in peer's proposal which are mismatched to my proposal.
484 * p : one of peer's proposal.
485 * proposal: my proposals.
488 print_ph1mismatched(p
, proposal
)
490 struct isakmpsa
*proposal
;
492 struct isakmpsa sa
, *s
;
494 memset(&sa
, 0, sizeof(sa
));
495 if (t2isakmpsa(p
->trns
, &sa
) < 0)
497 for (s
= proposal
; s
; s
= s
->next
) {
498 if (sa
.enctype
!= s
->enctype
) {
499 plog(LLV_ERROR
, LOCATION
, NULL
,
501 "DB(prop#%d:trns#%d):Peer(prop#%d:trns#%d) = "
503 s
->prop_no
, s
->trns_no
,
504 p
->prop
->p_no
, p
->trns
->t_no
,
505 s_oakley_attr_v(OAKLEY_ATTR_ENC_ALG
,
507 s_oakley_attr_v(OAKLEY_ATTR_ENC_ALG
,
510 if (sa
.authmethod
!= s
->authmethod
) {
511 plog(LLV_ERROR
, LOCATION
, NULL
,
512 "rejected authmethod: "
513 "DB(prop#%d:trns#%d):Peer(prop#%d:trns#%d) = "
515 s
->prop_no
, s
->trns_no
,
516 p
->prop
->p_no
, p
->trns
->t_no
,
517 s_oakley_attr_v(OAKLEY_ATTR_AUTH_METHOD
,
519 s_oakley_attr_v(OAKLEY_ATTR_AUTH_METHOD
,
522 if (sa
.hashtype
!= s
->hashtype
) {
523 plog(LLV_ERROR
, LOCATION
, NULL
,
524 "rejected hashtype: "
525 "DB(prop#%d:trns#%d):Peer(prop#%d:trns#%d) = "
527 s
->prop_no
, s
->trns_no
,
528 p
->prop
->p_no
, p
->trns
->t_no
,
529 s_oakley_attr_v(OAKLEY_ATTR_HASH_ALG
,
531 s_oakley_attr_v(OAKLEY_ATTR_HASH_ALG
,
534 if (sa
.dh_group
!= s
->dh_group
) {
535 plog(LLV_ERROR
, LOCATION
, NULL
,
536 "rejected dh_group: "
537 "DB(prop#%d:trns#%d):Peer(prop#%d:trns#%d) = "
539 s
->prop_no
, s
->trns_no
,
540 p
->prop
->p_no
, p
->trns
->t_no
,
541 s_oakley_attr_v(OAKLEY_ATTR_GRP_DESC
,
543 s_oakley_attr_v(OAKLEY_ATTR_GRP_DESC
,
548 if (sa
.dhgrp
!= NULL
){
549 oakley_dhgrp_free(sa
.dhgrp
);
555 * get ISAKMP data attributes
559 struct isakmp_pl_t
*trns
;
562 struct isakmp_data
*d
, *prev
;
571 tlen
= ntohs(trns
->h
.len
) - sizeof(*trns
);
572 prev
= (struct isakmp_data
*)NULL
;
573 d
= (struct isakmp_data
*)(trns
+ 1);
576 life_t
= OAKLEY_ATTR_SA_LD_TYPE_DEFAULT
;
577 sa
->lifetime
= OAKLEY_ATTR_SA_LD_SEC_DEFAULT
;
579 sa
->dhgrp
= racoon_calloc(1, sizeof(struct dhgroup
));
585 type
= ntohs(d
->type
) & ~ISAKMP_GEN_MASK
;
586 flag
= ntohs(d
->type
) & ISAKMP_GEN_MASK
;
588 plog(LLV_DEBUG
, LOCATION
, NULL
,
589 "type=%s, flag=0x%04x, lorv=%s\n",
590 s_oakley_attr(type
), flag
,
591 s_oakley_attr_v(type
, ntohs(d
->lorv
)));
593 /* get variable-sized item */
595 case OAKLEY_ATTR_GRP_PI
:
596 case OAKLEY_ATTR_GRP_GEN_ONE
:
597 case OAKLEY_ATTR_GRP_GEN_TWO
:
598 case OAKLEY_ATTR_GRP_CURVE_A
:
599 case OAKLEY_ATTR_GRP_CURVE_B
:
600 case OAKLEY_ATTR_SA_LD
:
601 case OAKLEY_ATTR_GRP_ORDER
:
604 p
= (u_char
*)&d
->lorv
;
606 len
= ntohs(d
->lorv
);
608 plog(LLV_ERROR
, LOCATION
, NULL
,
609 "invalid ISAKMP-SA attr, attr-len %d, overall-len %d\n",
613 p
= (u_char
*)(d
+ 1);
618 memcpy(val
->v
, p
, len
);
626 case OAKLEY_ATTR_ENC_ALG
:
627 sa
->enctype
= (u_int16_t
)ntohs(d
->lorv
);
630 case OAKLEY_ATTR_HASH_ALG
:
631 sa
->hashtype
= (u_int16_t
)ntohs(d
->lorv
);
634 case OAKLEY_ATTR_AUTH_METHOD
:
635 sa
->authmethod
= ntohs(d
->lorv
);
638 case OAKLEY_ATTR_GRP_DESC
:
639 sa
->dh_group
= (u_int16_t
)ntohs(d
->lorv
);
642 case OAKLEY_ATTR_GRP_TYPE
:
644 int type
= (int)ntohs(d
->lorv
);
645 if (type
== OAKLEY_ATTR_GRP_TYPE_MODP
)
646 sa
->dhgrp
->type
= type
;
651 case OAKLEY_ATTR_GRP_PI
:
652 sa
->dhgrp
->prime
= val
;
655 case OAKLEY_ATTR_GRP_GEN_ONE
:
658 sa
->dhgrp
->gen1
= ntohs(d
->lorv
);
660 int len
= ntohs(d
->lorv
);
664 memcpy(&sa
->dhgrp
->gen1
, d
+ 1, len
);
665 sa
->dhgrp
->gen1
= ntohl(sa
->dhgrp
->gen1
);
669 case OAKLEY_ATTR_GRP_GEN_TWO
:
672 sa
->dhgrp
->gen2
= ntohs(d
->lorv
);
674 int len
= ntohs(d
->lorv
);
678 memcpy(&sa
->dhgrp
->gen2
, d
+ 1, len
);
679 sa
->dhgrp
->gen2
= ntohl(sa
->dhgrp
->gen2
);
683 case OAKLEY_ATTR_GRP_CURVE_A
:
684 sa
->dhgrp
->curve_a
= val
;
687 case OAKLEY_ATTR_GRP_CURVE_B
:
688 sa
->dhgrp
->curve_b
= val
;
691 case OAKLEY_ATTR_SA_LD_TYPE
:
693 int type
= (int)ntohs(d
->lorv
);
695 case OAKLEY_ATTR_SA_LD_TYPE_SEC
:
696 case OAKLEY_ATTR_SA_LD_TYPE_KB
:
700 life_t
= OAKLEY_ATTR_SA_LD_TYPE_DEFAULT
;
705 case OAKLEY_ATTR_SA_LD
:
707 || (ntohs(prev
->type
) & ~ISAKMP_GEN_MASK
) !=
708 OAKLEY_ATTR_SA_LD_TYPE
) {
709 plog(LLV_ERROR
, LOCATION
, NULL
,
710 "life duration must follow ltype\n");
715 case IPSECDOI_ATTR_SA_LD_TYPE_SEC
:
716 sa
->lifetime
= ipsecdoi_set_ld(val
);
718 if (sa
->lifetime
== 0) {
719 plog(LLV_ERROR
, LOCATION
, NULL
,
720 "invalid life duration.\n");
724 case IPSECDOI_ATTR_SA_LD_TYPE_KB
:
725 sa
->lifebyte
= ipsecdoi_set_ld(val
);
727 if (sa
->lifebyte
== 0) {
728 plog(LLV_ERROR
, LOCATION
, NULL
,
729 "invalid life duration.\n");
735 plog(LLV_ERROR
, LOCATION
, NULL
,
736 "invalid life type: %d\n", life_t
);
741 case OAKLEY_ATTR_KEY_LEN
:
743 int len
= ntohs(d
->lorv
);
745 plog(LLV_ERROR
, LOCATION
, NULL
,
746 "keylen %d: not multiple of 8\n",
750 sa
->encklen
= (u_int16_t
)len
;
754 case OAKLEY_ATTR_PRF
:
755 case OAKLEY_ATTR_FIELD_SIZE
:
759 case OAKLEY_ATTR_GRP_ORDER
:
760 sa
->dhgrp
->order
= val
;
763 case OAKLEY_ATTR_GSS_ID
:
766 iconv_t cd
= (iconv_t
) -1;
767 size_t srcleft
, dstleft
, rv
;
768 __iconv_const
char *src
;
770 int len
= ntohs(d
->lorv
);
773 * Older verions of racoon just placed the
774 * ISO-Latin-1 string on the wire directly.
775 * Check to see if we are configured to be
776 * compatible with this behavior.
778 if (lcconf
->gss_id_enc
== LC_GSSENC_LATIN1
) {
779 if ((sa
->gssid
= vmalloc(len
)) == NULL
) {
780 plog(LLV_ERROR
, LOCATION
, NULL
,
781 "failed to allocate memory\n");
784 memcpy(sa
->gssid
->v
, d
+ 1, len
);
785 plog(LLV_DEBUG
, LOCATION
, NULL
,
786 "received old-style gss "
787 "id '%.*s' (len %zu)\n",
788 (int)sa
->gssid
->l
, sa
->gssid
->v
,
795 * For Windows 2000 compatibility, we expect
796 * the GSS ID attribute on the wire to be
797 * encoded in UTF-16LE. Internally, we work
798 * in ISO-Latin-1. Therefore, we should need
799 * 1/2 the specified length, which should always
800 * be a multiple of 2 octets.
802 cd
= iconv_open("latin1", "utf-16le");
803 if (cd
== (iconv_t
) -1) {
804 plog(LLV_ERROR
, LOCATION
, NULL
,
805 "unable to initialize utf-16le -> latin1 "
806 "conversion descriptor: %s\n",
811 if ((sa
->gssid
= vmalloc(len
/ 2)) == NULL
) {
812 plog(LLV_ERROR
, LOCATION
, NULL
,
813 "failed to allocate memory\n");
817 src
= (__iconv_const
char *)(d
+ 1);
823 rv
= iconv(cd
, (__iconv_const
char **)&src
, &srcleft
,
827 plog(LLV_ERROR
, LOCATION
, NULL
,
828 "unable to convert GSS ID from "
829 "utf-16le -> latin1: %s\n",
832 plog(LLV_ERROR
, LOCATION
, NULL
,
833 "%zd character%s in GSS ID cannot "
834 "be represented in latin1\n",
835 rv
, rv
== 1 ? "" : "s");
840 /* XXX dstleft should always be 0; assert it? */
841 sa
->gssid
->l
= (len
/ 2) - dstleft
;
843 plog(LLV_DEBUG
, LOCATION
, NULL
,
844 "received gss id '%.*s' (len %zu)\n",
845 (int)sa
->gssid
->l
, sa
->gssid
->v
, sa
->gssid
->l
);
849 if (cd
!= (iconv_t
)-1)
850 (void)iconv_close(cd
);
852 if ((error
!= 0) && (sa
->gssid
!= NULL
)) {
858 #endif /* HAVE_GSSAPI */
867 d
= (struct isakmp_data
*)((char *)d
+ sizeof(*d
));
869 tlen
-= (sizeof(*d
) + ntohs(d
->lorv
));
870 d
= (struct isakmp_data
*)((char *)d
+ sizeof(*d
) + ntohs(d
->lorv
));
874 /* key length must not be specified on some algorithms */
876 if (sa
->enctype
== OAKLEY_ATTR_ENC_ALG_DES
877 #ifdef HAVE_OPENSSL_IDEA_H
878 || sa
->enctype
== OAKLEY_ATTR_ENC_ALG_IDEA
880 || sa
->enctype
== OAKLEY_ATTR_ENC_ALG_3DES
) {
881 plog(LLV_ERROR
, LOCATION
, NULL
,
882 "keylen must not be specified "
883 "for encryption algorithm %d\n",
896 * check phase 2 SA payload and select single proposal.
897 * make new SA payload to be replyed not including general header.
898 * This function is called by responder only.
904 ipsecdoi_selectph2proposal(iph2
)
905 struct ph2handle
*iph2
;
907 struct prop_pair
**pair
;
908 struct prop_pair
*ret
;
910 /* get proposal pair */
911 pair
= get_proppair(iph2
->sa
, IPSECDOI_TYPE_PH2
);
915 /* check and select a proposal. */
916 ret
= get_ph2approval(iph2
, pair
);
921 /* make a SA to be replayed. */
922 /* SPI must be updated later. */
923 iph2
->sa_ret
= get_sabyproppair(ret
, iph2
->ph1
);
925 if (iph2
->sa_ret
== NULL
)
932 * check phase 2 SA payload returned from responder.
933 * This function is called by initiator only.
939 ipsecdoi_checkph2proposal(iph2
)
940 struct ph2handle
*iph2
;
942 struct prop_pair
**rpair
= NULL
, **spair
= NULL
;
946 vchar_t
*sa_ret
= NULL
;
948 /* get proposal pair of SA sent. */
949 spair
= get_proppair(iph2
->sa
, IPSECDOI_TYPE_PH2
);
951 plog(LLV_ERROR
, LOCATION
, NULL
,
952 "failed to get prop pair.\n");
956 /* XXX should check the number of transform */
958 /* get proposal pair of SA replayed */
959 rpair
= get_proppair(iph2
->sa_ret
, IPSECDOI_TYPE_PH2
);
961 plog(LLV_ERROR
, LOCATION
, NULL
,
962 "failed to get prop pair.\n");
966 /* check proposal is only one ? */
969 for (i
= 0; i
< MAXPROPPAIRLEN
; i
++) {
976 plog(LLV_ERROR
, LOCATION
, NULL
,
977 "no proposal received.\n");
981 plog(LLV_ERROR
, LOCATION
, NULL
,
982 "some proposals received.\n");
986 if (spair
[n
] == NULL
) {
987 plog(LLV_WARNING
, LOCATION
, NULL
,
988 "invalid proposal number:%d received.\n", i
);
992 if (rpair
[n
]->tnext
!= NULL
) {
993 plog(LLV_ERROR
, LOCATION
, NULL
,
994 "multi transforms replyed.\n");
998 if (cmp_aproppair_i(rpair
[n
], spair
[n
])) {
999 plog(LLV_ERROR
, LOCATION
, NULL
,
1000 "proposal mismathed.\n");
1005 * check and select a proposal.
1006 * ensure that there is no modification of the proposal by
1009 p
= get_ph2approval(iph2
, rpair
);
1013 /* make a SA to be replayed. */
1014 sa_ret
= iph2
->sa_ret
;
1015 iph2
->sa_ret
= get_sabyproppair(p
, iph2
->ph1
);
1017 if (iph2
->sa_ret
== NULL
)
1024 free_proppair(rpair
);
1026 free_proppair(spair
);
1034 * compare two prop_pair which is assumed to have same proposal number.
1035 * the case of bundle or single SA, NOT multi transforms.
1036 * a: a proposal that is multi protocols and single transform, usually replyed.
1037 * b: a proposal that is multi protocols and multi transform, usually sent.
1038 * NOTE: this function is for initiator.
1042 * XXX cannot understand the comment!
1045 cmp_aproppair_i(a
, b
)
1046 struct prop_pair
*a
, *b
;
1048 struct prop_pair
*p
, *q
, *r
;
1051 for (p
= a
, q
= b
; p
&& q
; p
= p
->next
, q
= q
->next
) {
1052 for (r
= q
; r
; r
= r
->tnext
) {
1054 if (p
->trns
->t_no
== r
->trns
->t_no
)
1058 /* no suitable transform found */
1059 plog(LLV_ERROR
, LOCATION
, NULL
,
1060 "no suitable transform found.\n");
1065 if (p
->prop
->p_no
!= r
->prop
->p_no
) {
1066 plog(LLV_WARNING
, LOCATION
, NULL
,
1067 "proposal #%d mismatched, "
1069 r
->prop
->p_no
, p
->prop
->p_no
);
1073 if (p
->prop
->proto_id
!= r
->prop
->proto_id
) {
1074 plog(LLV_ERROR
, LOCATION
, NULL
,
1075 "proto_id mismathed: my:%d peer:%d\n",
1076 r
->prop
->proto_id
, p
->prop
->proto_id
);
1080 if (p
->prop
->proto_id
!= r
->prop
->proto_id
) {
1081 plog(LLV_ERROR
, LOCATION
, NULL
,
1082 "invalid spi size: %d.\n",
1087 /* check #of transforms */
1088 if (p
->prop
->num_t
!= 1) {
1089 plog(LLV_WARNING
, LOCATION
, NULL
,
1090 "#of transform is %d, "
1091 "but expected 1.\n", p
->prop
->num_t
);
1095 if (p
->trns
->t_id
!= r
->trns
->t_id
) {
1096 plog(LLV_WARNING
, LOCATION
, NULL
,
1097 "transform number has been modified.\n");
1100 if (p
->trns
->reserved
!= r
->trns
->reserved
) {
1101 plog(LLV_WARNING
, LOCATION
, NULL
,
1102 "reserved field should be zero.\n");
1106 /* compare attribute */
1107 len
= ntohs(r
->trns
->h
.len
) - sizeof(*p
->trns
);
1108 if (memcmp(p
->trns
+ 1, r
->trns
+ 1, len
) != 0) {
1109 plog(LLV_WARNING
, LOCATION
, NULL
,
1110 "attribute has been modified.\n");
1114 if ((p
&& !q
) || (!p
&& q
)) {
1115 /* # of protocols mismatched */
1116 plog(LLV_ERROR
, LOCATION
, NULL
,
1117 "#of protocols mismatched.\n");
1125 * acceptable check for policy configuration.
1126 * return a new SA payload to be reply to peer.
1128 static struct prop_pair
*
1129 get_ph2approval(iph2
, pair
)
1130 struct ph2handle
*iph2
;
1131 struct prop_pair
**pair
;
1133 struct prop_pair
*ret
;
1136 iph2
->approval
= NULL
;
1138 plog(LLV_DEBUG
, LOCATION
, NULL
,
1139 "begin compare proposals.\n");
1141 for (i
= 0; i
< MAXPROPPAIRLEN
; i
++) {
1142 if (pair
[i
] == NULL
)
1144 plog(LLV_DEBUG
, LOCATION
, NULL
,
1145 "pair[%d]: %p\n", i
, pair
[i
]);
1146 print_proppair(LLV_DEBUG
, pair
[i
]);;
1148 /* compare proposal and select one */
1149 ret
= get_ph2approvalx(iph2
, pair
[i
]);
1156 plog(LLV_ERROR
, LOCATION
, NULL
, "no suitable policy found.\n");
1162 * compare my proposal and peers just one proposal.
1165 static struct prop_pair
*
1166 get_ph2approvalx(iph2
, pp
)
1167 struct ph2handle
*iph2
;
1168 struct prop_pair
*pp
;
1170 struct prop_pair
*ret
= NULL
;
1171 struct saprop
*pr0
, *pr
= NULL
;
1172 struct saprop
*q1
, *q2
;
1174 pr0
= aproppair2saprop(pp
);
1178 for (q1
= pr0
; q1
; q1
= q1
->next
) {
1179 for (q2
= iph2
->proposal
; q2
; q2
= q2
->next
) {
1180 plog(LLV_DEBUG
, LOCATION
, NULL
,
1181 "peer's single bundle:\n");
1182 printsaprop0(LLV_DEBUG
, q1
);
1183 plog(LLV_DEBUG
, LOCATION
, NULL
,
1184 "my single bundle:\n");
1185 printsaprop0(LLV_DEBUG
, q2
);
1187 pr
= cmpsaprop_alloc(iph2
->ph1
, q1
, q2
, iph2
->side
);
1191 plog(LLV_ERROR
, LOCATION
, NULL
,
1195 /* no proposal matching */
1202 plog(LLV_DEBUG
, LOCATION
, NULL
, "matched\n");
1203 iph2
->approval
= pr
;
1207 struct prop_pair
*p
, *x
;
1208 struct prop_pair
*n
= NULL
;
1212 for (p
= pp
; p
; p
= p
->next
) {
1214 * find a proposal with matching proto_id.
1215 * we have analyzed validity already, in cmpsaprop_alloc().
1217 for (sp
= pr
->head
; sp
; sp
= sp
->next
) {
1218 if (sp
->proto_id
== p
->prop
->proto_id
)
1226 for (x
= p
; x
; x
= x
->tnext
)
1227 if (sp
->head
->trns_no
== x
->trns
->t_no
)
1232 n
= racoon_calloc(1, sizeof(struct prop_pair
));
1234 plog(LLV_ERROR
, LOCATION
, NULL
,
1235 "failed to get buffer.\n");
1242 /* need to preserve the order */
1243 for (x
= ret
; x
&& x
->next
; x
= x
->next
)
1245 if (x
&& x
->prop
== n
->prop
) {
1246 for (/*nothing*/; x
&& x
->tnext
; x
= x
->tnext
)
1257 /* #of transforms should be updated ? */
1266 struct prop_pair
**pair
;
1270 for (i
= 0; i
< MAXPROPPAIRLEN
; i
++) {
1271 free_proppair0(pair
[i
]);
1278 free_proppair0(pair
)
1279 struct prop_pair
*pair
;
1281 struct prop_pair
*p
, *q
, *r
, *s
;
1297 * get proposal pairs from SA payload.
1298 * tiny check for proposal payload.
1301 get_proppair(sa
, mode
)
1305 struct prop_pair
**pair
= NULL
;
1306 int num_p
= 0; /* number of proposal for use */
1310 struct ipsecdoi_sa_b
*sab
= (struct ipsecdoi_sa_b
*)sa
->v
;
1312 plog(LLV_DEBUG
, LOCATION
, NULL
, "total SA len=%zu\n", sa
->l
);
1313 plogdump(LLV_DEBUG
, sa
->v
, sa
->l
);
1315 /* check SA payload size */
1316 if (sa
->l
< sizeof(*sab
)) {
1317 plog(LLV_ERROR
, LOCATION
, NULL
,
1318 "Invalid SA length = %zu.\n", sa
->l
);
1323 if (check_doi(ntohl(sab
->doi
)) < 0)
1326 /* check SITUATION */
1327 if (check_situation(ntohl(sab
->sit
)) < 0)
1330 pair
= racoon_calloc(1, MAXPROPPAIRLEN
* sizeof(*pair
));
1332 plog(LLV_ERROR
, LOCATION
, NULL
,
1333 "failed to get buffer.\n");
1336 memset(pair
, 0, sizeof(pair
));
1338 bp
= (caddr_t
)(sab
+ 1);
1339 tlen
= sa
->l
- sizeof(*sab
);
1342 struct isakmp_pl_p
*prop
;
1344 vchar_t
*pbuf
= NULL
;
1345 struct isakmp_parse_t
*pa
;
1347 pbuf
= isakmp_parsewoh(ISAKMP_NPTYPE_P
, (struct isakmp_gen
*)bp
, tlen
);
1351 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
1352 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1354 /* check the value of next payload */
1355 if (pa
->type
!= ISAKMP_NPTYPE_P
) {
1356 plog(LLV_ERROR
, LOCATION
, NULL
,
1357 "Invalid payload type=%u\n", pa
->type
);
1362 prop
= (struct isakmp_pl_p
*)pa
->ptr
;
1365 plog(LLV_DEBUG
, LOCATION
, NULL
,
1366 "proposal #%u len=%d\n", prop
->p_no
, proplen
);
1369 plog(LLV_ERROR
, LOCATION
, NULL
,
1370 "invalid proposal with length %d\n", proplen
);
1375 /* check Protocol ID */
1376 if (!check_protocol
[mode
]) {
1377 plog(LLV_ERROR
, LOCATION
, NULL
,
1378 "unsupported mode %d\n", mode
);
1382 if (check_protocol
[mode
](prop
->proto_id
) < 0)
1385 /* check SPI length when IKE. */
1386 if (check_spi_size(prop
->proto_id
, prop
->spi_size
) < 0)
1390 if (get_transform(prop
, pair
, &num_p
) < 0) {
1401 struct prop_pair
*p
, *q
;
1403 /* check for proposals with no transforms */
1404 for (i
= 0; i
< MAXPROPPAIRLEN
; i
++) {
1408 plog(LLV_DEBUG
, LOCATION
, NULL
, "pair %d:\n", i
);
1409 print_proppair(LLV_DEBUG
, pair
[i
]);
1411 notrans
= nprop
= 0;
1412 for (p
= pair
[i
]; p
; p
= p
->next
) {
1413 if (p
->trns
== NULL
) {
1417 for (q
= p
; q
; q
= q
->tnext
)
1423 * XXX at this moment, we cannot accept proposal group
1424 * with multiple proposals. this should be fixed.
1426 if (pair
[i
]->next
) {
1427 plog(LLV_WARNING
, LOCATION
, NULL
,
1428 "proposal #%u ignored "
1429 "(multiple proposal not supported)\n",
1430 pair
[i
]->prop
->p_no
);
1436 for (p
= pair
[i
]; p
; p
= q
) {
1443 plog(LLV_DEBUG
, LOCATION
, NULL
,
1444 "proposal #%u: %d transform\n",
1445 pair
[i
]->prop
->p_no
, nprop
);
1450 /* bark if no proposal is found. */
1452 plog(LLV_ERROR
, LOCATION
, NULL
,
1453 "no Proposal found.\n");
1465 * check transform payload.
1467 * positive: return the pointer to the payload of valid transform.
1468 * 0 : No valid transform found.
1471 get_transform(prop
, pair
, num_p
)
1472 struct isakmp_pl_p
*prop
;
1473 struct prop_pair
**pair
;
1476 int tlen
; /* total length of all transform in a proposal */
1478 struct isakmp_pl_t
*trns
;
1480 vchar_t
*pbuf
= NULL
;
1481 struct isakmp_parse_t
*pa
;
1482 struct prop_pair
*p
= NULL
, *q
;
1485 bp
= (caddr_t
)prop
+ sizeof(struct isakmp_pl_p
) + prop
->spi_size
;
1486 tlen
= ntohs(prop
->h
.len
)
1487 - (sizeof(struct isakmp_pl_p
) + prop
->spi_size
);
1488 pbuf
= isakmp_parsewoh(ISAKMP_NPTYPE_T
, (struct isakmp_gen
*)bp
, tlen
);
1492 /* check and get transform for use */
1494 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
1495 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1500 /* check the value of next payload */
1501 if (pa
->type
!= ISAKMP_NPTYPE_T
) {
1502 plog(LLV_ERROR
, LOCATION
, NULL
,
1503 "Invalid payload type=%u\n", pa
->type
);
1507 trns
= (struct isakmp_pl_t
*)pa
->ptr
;
1510 plog(LLV_DEBUG
, LOCATION
, NULL
,
1511 "transform #%u len=%u\n", trns
->t_no
, trnslen
);
1513 /* check transform ID */
1514 if (prop
->proto_id
>= ARRAYLEN(check_transform
)) {
1515 plog(LLV_WARNING
, LOCATION
, NULL
,
1516 "unsupported proto_id %u\n",
1520 if (prop
->proto_id
>= ARRAYLEN(check_attributes
)) {
1521 plog(LLV_WARNING
, LOCATION
, NULL
,
1522 "unsupported proto_id %u\n",
1527 if (!check_transform
[prop
->proto_id
]
1528 || !check_attributes
[prop
->proto_id
]) {
1529 plog(LLV_WARNING
, LOCATION
, NULL
,
1530 "unsupported proto_id %u\n",
1534 if (check_transform
[prop
->proto_id
](trns
->t_id
) < 0)
1537 /* check data attributes */
1538 if (check_attributes
[prop
->proto_id
](trns
) != 0)
1541 p
= racoon_calloc(1, sizeof(*p
));
1543 plog(LLV_ERROR
, LOCATION
, NULL
,
1544 "failed to get buffer.\n");
1551 /* need to preserve the order */
1552 for (q
= pair
[prop
->p_no
]; q
&& q
->next
; q
= q
->next
)
1554 if (q
&& q
->prop
== p
->prop
) {
1555 for (/*nothing*/; q
&& q
->tnext
; q
= q
->tnext
)
1562 pair
[prop
->p_no
] = p
;
1574 * make a new SA payload from prop_pair.
1575 * NOTE: this function make spi value clear.
1578 get_sabyproppair(pair
, iph1
)
1579 struct prop_pair
*pair
;
1580 struct ph1handle
*iph1
;
1584 u_int8_t
*np_p
= NULL
;
1585 struct prop_pair
*p
;
1586 int prophlen
, trnslen
;
1589 newtlen
= sizeof(struct ipsecdoi_sa_b
);
1590 for (p
= pair
; p
; p
= p
->next
) {
1591 newtlen
+= sizeof(struct isakmp_pl_p
);
1592 newtlen
+= p
->prop
->spi_size
;
1593 newtlen
+= ntohs(p
->trns
->h
.len
);
1596 newsa
= vmalloc(newtlen
);
1597 if (newsa
== NULL
) {
1598 plog(LLV_ERROR
, LOCATION
, NULL
, "failed to get newsa.\n");
1603 ((struct isakmp_gen
*)bp
)->len
= htons(newtlen
);
1605 /* update some of values in SA header */
1606 ((struct ipsecdoi_sa_b
*)bp
)->doi
= htonl(iph1
->rmconf
->doitype
);
1607 ((struct ipsecdoi_sa_b
*)bp
)->sit
= htonl(iph1
->rmconf
->sittype
);
1608 bp
+= sizeof(struct ipsecdoi_sa_b
);
1610 /* create proposal payloads */
1611 for (p
= pair
; p
; p
= p
->next
) {
1612 prophlen
= sizeof(struct isakmp_pl_p
)
1613 + p
->prop
->spi_size
;
1614 trnslen
= ntohs(p
->trns
->h
.len
);
1617 *np_p
= ISAKMP_NPTYPE_P
;
1619 /* create proposal */
1621 memcpy(bp
, p
->prop
, prophlen
);
1622 ((struct isakmp_pl_p
*)bp
)->h
.np
= ISAKMP_NPTYPE_NONE
;
1623 ((struct isakmp_pl_p
*)bp
)->h
.len
= htons(prophlen
+ trnslen
);
1624 ((struct isakmp_pl_p
*)bp
)->num_t
= 1;
1625 np_p
= &((struct isakmp_pl_p
*)bp
)->h
.np
;
1626 memset(bp
+ sizeof(struct isakmp_pl_p
), 0, p
->prop
->spi_size
);
1629 /* create transform */
1630 memcpy(bp
, p
->trns
, trnslen
);
1631 ((struct isakmp_pl_t
*)bp
)->h
.np
= ISAKMP_NPTYPE_NONE
;
1632 ((struct isakmp_pl_t
*)bp
)->h
.len
= htons(trnslen
);
1640 * update responder's spi
1643 ipsecdoi_updatespi(iph2
)
1644 struct ph2handle
*iph2
;
1646 struct prop_pair
**pair
, *p
;
1653 pair
= get_proppair(iph2
->sa_ret
, IPSECDOI_TYPE_PH2
);
1656 for (i
= 0; i
< MAXPROPPAIRLEN
; i
++) {
1660 if (i
== MAXPROPPAIRLEN
|| pair
[i
]->tnext
) {
1661 /* multiple transform must be filtered by selectph2proposal.*/
1665 pp
= iph2
->approval
;
1667 /* create proposal payloads */
1668 for (p
= pair
[i
]; p
; p
= p
->next
) {
1670 * find a proposal/transform with matching proto_id/t_id.
1671 * we have analyzed validity already, in cmpsaprop_alloc().
1673 for (pr
= pp
->head
; pr
; pr
= pr
->next
) {
1674 if (p
->prop
->proto_id
== pr
->proto_id
&&
1675 p
->trns
->t_id
== pr
->head
->trns_id
) {
1683 * XXX SPI bits are left-filled, for use with IPComp.
1684 * we should be switching to variable-length spi field...
1686 spi
= (u_int8_t
*)&pr
->spi
;
1687 spi
+= sizeof(pr
->spi
);
1689 memcpy((caddr_t
)p
->prop
+ sizeof(*p
->prop
), spi
, pr
->spisize
);
1694 free_proppair(pair
);
1699 * make a new SA payload from prop_pair.
1702 get_sabysaprop(pp0
, sa0
)
1706 struct prop_pair
**pair
= NULL
;
1707 vchar_t
*newsa
= NULL
;
1709 u_int8_t
*np_p
= NULL
;
1710 struct prop_pair
*p
= NULL
;
1714 int prophlen
, trnslen
;
1718 /* get proposal pair */
1719 pair
= get_proppair(sa0
, IPSECDOI_TYPE_PH2
);
1723 newtlen
= sizeof(struct ipsecdoi_sa_b
);
1724 for (pp
= pp0
; pp
; pp
= pp
->next
) {
1726 if (pair
[pp
->prop_no
] == NULL
)
1729 for (pr
= pp
->head
; pr
; pr
= pr
->next
) {
1730 newtlen
+= (sizeof(struct isakmp_pl_p
)
1733 for (tr
= pr
->head
; tr
; tr
= tr
->next
) {
1734 for (p
= pair
[pp
->prop_no
]; p
; p
= p
->tnext
) {
1735 if (tr
->trns_no
== p
->trns
->t_no
)
1741 newtlen
+= ntohs(p
->trns
->h
.len
);
1746 newsa
= vmalloc(newtlen
);
1747 if (newsa
== NULL
) {
1748 plog(LLV_ERROR
, LOCATION
, NULL
, "failed to get newsa.\n");
1753 /* some of values of SA must be updated in the out of this function */
1754 ((struct isakmp_gen
*)bp
)->len
= htons(newtlen
);
1755 bp
+= sizeof(struct ipsecdoi_sa_b
);
1757 /* create proposal payloads */
1758 for (pp
= pp0
; pp
; pp
= pp
->next
) {
1760 for (pr
= pp
->head
; pr
; pr
= pr
->next
) {
1761 prophlen
= sizeof(struct isakmp_pl_p
)
1762 + p
->prop
->spi_size
;
1764 for (tr
= pr
->head
; tr
; tr
= tr
->next
) {
1765 for (p
= pair
[pp
->prop_no
]; p
; p
= p
->tnext
) {
1766 if (tr
->trns_no
== p
->trns
->t_no
)
1772 trnslen
= ntohs(p
->trns
->h
.len
);
1775 *np_p
= ISAKMP_NPTYPE_P
;
1777 /* create proposal */
1779 memcpy(bp
, p
->prop
, prophlen
);
1780 ((struct isakmp_pl_p
*)bp
)->h
.np
= ISAKMP_NPTYPE_NONE
;
1781 ((struct isakmp_pl_p
*)bp
)->h
.len
= htons(prophlen
+ trnslen
);
1782 ((struct isakmp_pl_p
*)bp
)->num_t
= 1;
1783 np_p
= &((struct isakmp_pl_p
*)bp
)->h
.np
;
1786 /* create transform */
1787 memcpy(bp
, p
->trns
, trnslen
);
1788 ((struct isakmp_pl_t
*)bp
)->h
.np
= ISAKMP_NPTYPE_NONE
;
1789 ((struct isakmp_pl_t
*)bp
)->h
.len
= htons(trnslen
);
1801 if (newsa
!= NULL
) {
1811 * If some error happens then return 0. Although 0 means that lifetime is zero,
1812 * such a value should not be accepted.
1813 * Also 0 of lifebyte should not be included in a packet although 0 means not
1817 ipsecdoi_set_ld(buf
)
1827 ld
= ntohs(*(u_int16_t
*)buf
->v
);
1830 ld
= ntohl(*(u_int32_t
*)buf
->v
);
1833 plog(LLV_ERROR
, LOCATION
, NULL
,
1834 "length %zu of life duration "
1835 "isn't supported.\n", buf
->l
);
1854 plog(LLV_ERROR
, LOCATION
, NULL
,
1855 "invalid value of DOI 0x%08x.\n", doi
);
1865 check_situation(sit
)
1869 case IPSECDOI_SIT_IDENTITY_ONLY
:
1872 case IPSECDOI_SIT_SECRECY
:
1873 case IPSECDOI_SIT_INTEGRITY
:
1874 plog(LLV_ERROR
, LOCATION
, NULL
,
1875 "situation 0x%08x unsupported yet.\n", sit
);
1879 plog(LLV_ERROR
, LOCATION
, NULL
,
1880 "invalid situation 0x%08x.\n", sit
);
1887 * check protocol id in main mode
1890 check_prot_main(proto_id
)
1894 case IPSECDOI_PROTO_ISAKMP
:
1898 plog(LLV_ERROR
, LOCATION
, NULL
,
1899 "Illegal protocol id=%u.\n", proto_id
);
1906 * check protocol id in quick mode
1909 check_prot_quick(proto_id
)
1913 case IPSECDOI_PROTO_IPSEC_AH
:
1914 case IPSECDOI_PROTO_IPSEC_ESP
:
1917 case IPSECDOI_PROTO_IPCOMP
:
1921 plog(LLV_ERROR
, LOCATION
, NULL
,
1922 "invalid protocol id %d.\n", proto_id
);
1929 check_spi_size(proto_id
, size
)
1933 case IPSECDOI_PROTO_ISAKMP
:
1936 plog(LLV_WARNING
, LOCATION
, NULL
,
1937 "SPI size isn't zero, but IKE proposal.\n");
1941 case IPSECDOI_PROTO_IPSEC_AH
:
1942 case IPSECDOI_PROTO_IPSEC_ESP
:
1944 plog(LLV_ERROR
, LOCATION
, NULL
,
1945 "invalid SPI size=%d for IPSEC proposal.\n",
1951 case IPSECDOI_PROTO_IPCOMP
:
1952 if (size
!= 2 && size
!= 4) {
1953 plog(LLV_ERROR
, LOCATION
, NULL
,
1954 "invalid SPI size=%d for IPCOMP proposal.\n",
1968 * check transform ID in ISAKMP.
1971 check_trns_isakmp(t_id
)
1975 case IPSECDOI_KEY_IKE
:
1978 plog(LLV_ERROR
, LOCATION
, NULL
,
1979 "invalid transform-id=%u in proto_id=%u.\n",
1980 t_id
, IPSECDOI_KEY_IKE
);
1987 * check transform ID in AH.
1994 case IPSECDOI_AH_MD5
:
1995 case IPSECDOI_AH_SHA
:
1996 case IPSECDOI_AH_SHA256
:
1997 case IPSECDOI_AH_SHA384
:
1998 case IPSECDOI_AH_SHA512
:
2000 case IPSECDOI_AH_DES
:
2001 plog(LLV_ERROR
, LOCATION
, NULL
,
2002 "not support transform-id=%u in AH.\n", t_id
);
2005 plog(LLV_ERROR
, LOCATION
, NULL
,
2006 "invalid transform-id=%u in AH.\n", t_id
);
2013 * check transform ID in ESP.
2016 check_trns_esp(t_id
)
2020 case IPSECDOI_ESP_DES
:
2021 case IPSECDOI_ESP_3DES
:
2022 case IPSECDOI_ESP_NULL
:
2023 case IPSECDOI_ESP_RC5
:
2024 case IPSECDOI_ESP_CAST
:
2025 case IPSECDOI_ESP_BLOWFISH
:
2026 case IPSECDOI_ESP_AES
:
2027 case IPSECDOI_ESP_TWOFISH
:
2029 case IPSECDOI_ESP_DES_IV32
:
2030 case IPSECDOI_ESP_DES_IV64
:
2031 case IPSECDOI_ESP_IDEA
:
2032 case IPSECDOI_ESP_3IDEA
:
2033 case IPSECDOI_ESP_RC4
:
2034 plog(LLV_ERROR
, LOCATION
, NULL
,
2035 "not support transform-id=%u in ESP.\n", t_id
);
2038 plog(LLV_ERROR
, LOCATION
, NULL
,
2039 "invalid transform-id=%u in ESP.\n", t_id
);
2046 * check transform ID in IPCOMP.
2049 check_trns_ipcomp(t_id
)
2053 case IPSECDOI_IPCOMP_OUI
:
2054 case IPSECDOI_IPCOMP_DEFLATE
:
2055 case IPSECDOI_IPCOMP_LZS
:
2058 plog(LLV_ERROR
, LOCATION
, NULL
,
2059 "invalid transform-id=%u in IPCOMP.\n", t_id
);
2066 * check data attributes in IKE.
2069 check_attr_isakmp(trns
)
2070 struct isakmp_pl_t
*trns
;
2072 struct isakmp_data
*d
;
2077 tlen
= ntohs(trns
->h
.len
) - sizeof(struct isakmp_pl_t
);
2078 d
= (struct isakmp_data
*)((caddr_t
)trns
+ sizeof(struct isakmp_pl_t
));
2081 type
= ntohs(d
->type
) & ~ISAKMP_GEN_MASK
;
2082 flag
= ntohs(d
->type
) & ISAKMP_GEN_MASK
;
2083 lorv
= ntohs(d
->lorv
);
2085 plog(LLV_DEBUG
, LOCATION
, NULL
,
2086 "type=%s, flag=0x%04x, lorv=%s\n",
2087 s_oakley_attr(type
), flag
,
2088 s_oakley_attr_v(type
, lorv
));
2091 * some of the attributes must be encoded in TV.
2092 * see RFC2409 Appendix A "Attribute Classes".
2095 case OAKLEY_ATTR_ENC_ALG
:
2096 case OAKLEY_ATTR_HASH_ALG
:
2097 case OAKLEY_ATTR_AUTH_METHOD
:
2098 case OAKLEY_ATTR_GRP_DESC
:
2099 case OAKLEY_ATTR_GRP_TYPE
:
2100 case OAKLEY_ATTR_SA_LD_TYPE
:
2101 case OAKLEY_ATTR_PRF
:
2102 case OAKLEY_ATTR_KEY_LEN
:
2103 case OAKLEY_ATTR_FIELD_SIZE
:
2104 if (!flag
) { /* TLV*/
2105 plog(LLV_ERROR
, LOCATION
, NULL
,
2106 "oakley attribute %d must be TV.\n",
2113 /* sanity check for TLV. length must be specified. */
2114 if (!flag
&& lorv
== 0) { /*TLV*/
2115 plog(LLV_ERROR
, LOCATION
, NULL
,
2116 "invalid length %d for TLV attribute %d.\n",
2122 case OAKLEY_ATTR_ENC_ALG
:
2123 if (!alg_oakley_encdef_ok(lorv
)) {
2124 plog(LLV_ERROR
, LOCATION
, NULL
,
2125 "invalied encryption algorithm=%d.\n",
2131 case OAKLEY_ATTR_HASH_ALG
:
2132 if (!alg_oakley_hashdef_ok(lorv
)) {
2133 plog(LLV_ERROR
, LOCATION
, NULL
,
2134 "invalied hash algorithm=%d.\n",
2140 case OAKLEY_ATTR_AUTH_METHOD
:
2142 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
2143 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
2144 #ifdef ENABLE_HYBRID
2145 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
2146 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
2147 #if 0 /* Clashes with OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB */
2148 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_I
:
2150 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
:
2152 case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
:
2154 case OAKLEY_ATTR_AUTH_METHOD_DSSSIG
:
2155 #ifdef ENABLE_HYBRID
2156 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
:
2157 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
:
2158 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I
:
2159 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R
:
2160 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_I
:
2161 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_R
:
2162 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
2163 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_R
:
2164 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
2165 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_R
:
2167 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
2168 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
2169 plog(LLV_ERROR
, LOCATION
, NULL
,
2170 "auth method %s isn't supported.\n",
2171 s_oakley_attr_method(lorv
));
2174 plog(LLV_ERROR
, LOCATION
, NULL
,
2175 "invalid auth method %d.\n",
2181 case OAKLEY_ATTR_GRP_DESC
:
2182 if (!alg_oakley_dhdef_ok(lorv
)) {
2183 plog(LLV_ERROR
, LOCATION
, NULL
,
2184 "invalid DH group %d.\n",
2190 case OAKLEY_ATTR_GRP_TYPE
:
2192 case OAKLEY_ATTR_GRP_TYPE_MODP
:
2195 plog(LLV_ERROR
, LOCATION
, NULL
,
2196 "unsupported DH group type %d.\n",
2202 case OAKLEY_ATTR_GRP_PI
:
2203 case OAKLEY_ATTR_GRP_GEN_ONE
:
2204 /* sanity checks? */
2207 case OAKLEY_ATTR_GRP_GEN_TWO
:
2208 case OAKLEY_ATTR_GRP_CURVE_A
:
2209 case OAKLEY_ATTR_GRP_CURVE_B
:
2210 plog(LLV_ERROR
, LOCATION
, NULL
,
2211 "attr type=%u isn't supported.\n", type
);
2214 case OAKLEY_ATTR_SA_LD_TYPE
:
2216 case OAKLEY_ATTR_SA_LD_TYPE_SEC
:
2217 case OAKLEY_ATTR_SA_LD_TYPE_KB
:
2220 plog(LLV_ERROR
, LOCATION
, NULL
,
2221 "invalid life type %d.\n", lorv
);
2226 case OAKLEY_ATTR_SA_LD
:
2227 /* should check the value */
2230 case OAKLEY_ATTR_PRF
:
2231 case OAKLEY_ATTR_KEY_LEN
:
2234 case OAKLEY_ATTR_FIELD_SIZE
:
2235 plog(LLV_ERROR
, LOCATION
, NULL
,
2236 "attr type=%u isn't supported.\n", type
);
2239 case OAKLEY_ATTR_GRP_ORDER
:
2242 case OAKLEY_ATTR_GSS_ID
:
2246 plog(LLV_ERROR
, LOCATION
, NULL
,
2247 "invalid attribute type %d.\n", type
);
2253 d
= (struct isakmp_data
*)((char *)d
2256 tlen
-= (sizeof(*d
) + lorv
);
2257 d
= (struct isakmp_data
*)((char *)d
2258 + sizeof(*d
) + lorv
);
2266 * check data attributes in IPSEC AH/ESP.
2270 struct isakmp_pl_t
*trns
;
2272 return check_attr_ipsec(IPSECDOI_PROTO_IPSEC_AH
, trns
);
2276 check_attr_esp(trns
)
2277 struct isakmp_pl_t
*trns
;
2279 return check_attr_ipsec(IPSECDOI_PROTO_IPSEC_ESP
, trns
);
2283 check_attr_ipsec(proto_id
, trns
)
2285 struct isakmp_pl_t
*trns
;
2287 struct isakmp_data
*d
;
2291 int attrseen
[16]; /* XXX magic number */
2293 tlen
= ntohs(trns
->h
.len
) - sizeof(struct isakmp_pl_t
);
2294 d
= (struct isakmp_data
*)((caddr_t
)trns
+ sizeof(struct isakmp_pl_t
));
2295 memset(attrseen
, 0, sizeof(attrseen
));
2298 type
= ntohs(d
->type
) & ~ISAKMP_GEN_MASK
;
2299 flag
= ntohs(d
->type
) & ISAKMP_GEN_MASK
;
2300 lorv
= ntohs(d
->lorv
);
2302 plog(LLV_DEBUG
, LOCATION
, NULL
,
2303 "type=%s, flag=0x%04x, lorv=%s\n",
2304 s_ipsecdoi_attr(type
), flag
,
2305 s_ipsecdoi_attr_v(type
, lorv
));
2307 if (type
< sizeof(attrseen
)/sizeof(attrseen
[0]))
2311 case IPSECDOI_ATTR_ENC_MODE
:
2313 plog(LLV_ERROR
, LOCATION
, NULL
,
2314 "must be TV when ENC_MODE.\n");
2319 case IPSECDOI_ATTR_ENC_MODE_TUNNEL
:
2320 case IPSECDOI_ATTR_ENC_MODE_TRNS
:
2323 case IPSECDOI_ATTR_ENC_MODE_UDPTUNNEL_RFC
:
2324 case IPSECDOI_ATTR_ENC_MODE_UDPTRNS_RFC
:
2325 case IPSECDOI_ATTR_ENC_MODE_UDPTUNNEL_DRAFT
:
2326 case IPSECDOI_ATTR_ENC_MODE_UDPTRNS_DRAFT
:
2327 plog(LLV_DEBUG
, LOCATION
, NULL
,
2328 "UDP encapsulation requested\n");
2332 plog(LLV_ERROR
, LOCATION
, NULL
,
2333 "invalid encryption mode=%u.\n",
2339 case IPSECDOI_ATTR_AUTH
:
2341 plog(LLV_ERROR
, LOCATION
, NULL
,
2342 "must be TV when AUTH.\n");
2347 case IPSECDOI_ATTR_AUTH_HMAC_MD5
:
2348 if (proto_id
== IPSECDOI_PROTO_IPSEC_AH
&&
2349 trns
->t_id
!= IPSECDOI_AH_MD5
) {
2351 plog(LLV_ERROR
, LOCATION
, NULL
,
2352 "auth algorithm %u conflicts "
2353 "with transform %u.\n",
2358 case IPSECDOI_ATTR_AUTH_HMAC_SHA1
:
2359 if (proto_id
== IPSECDOI_PROTO_IPSEC_AH
) {
2360 if (trns
->t_id
!= IPSECDOI_AH_SHA
)
2364 case IPSECDOI_ATTR_AUTH_HMAC_SHA2_256
:
2365 if (proto_id
== IPSECDOI_PROTO_IPSEC_AH
) {
2366 if (trns
->t_id
!= IPSECDOI_AH_SHA256
)
2370 case IPSECDOI_ATTR_AUTH_HMAC_SHA2_384
:
2371 if (proto_id
== IPSECDOI_PROTO_IPSEC_AH
) {
2372 if (trns
->t_id
!= IPSECDOI_AH_SHA384
)
2376 case IPSECDOI_ATTR_AUTH_HMAC_SHA2_512
:
2377 if (proto_id
== IPSECDOI_PROTO_IPSEC_AH
) {
2378 if (trns
->t_id
!= IPSECDOI_AH_SHA512
)
2382 case IPSECDOI_ATTR_AUTH_DES_MAC
:
2383 case IPSECDOI_ATTR_AUTH_KPDK
:
2384 plog(LLV_ERROR
, LOCATION
, NULL
,
2385 "auth algorithm %u isn't supported.\n",
2389 plog(LLV_ERROR
, LOCATION
, NULL
,
2390 "invalid auth algorithm=%u.\n",
2396 case IPSECDOI_ATTR_SA_LD_TYPE
:
2398 plog(LLV_ERROR
, LOCATION
, NULL
,
2399 "must be TV when LD_TYPE.\n");
2404 case IPSECDOI_ATTR_SA_LD_TYPE_SEC
:
2405 case IPSECDOI_ATTR_SA_LD_TYPE_KB
:
2408 plog(LLV_ERROR
, LOCATION
, NULL
,
2409 "invalid life type %d.\n", lorv
);
2414 case IPSECDOI_ATTR_SA_LD
:
2416 /* i.e. ISAKMP_GEN_TV */
2417 plog(LLV_DEBUG
, LOCATION
, NULL
,
2418 "life duration was in TLV.\n");
2420 /* i.e. ISAKMP_GEN_TLV */
2422 plog(LLV_ERROR
, LOCATION
, NULL
,
2423 "invalid length of LD\n");
2429 case IPSECDOI_ATTR_GRP_DESC
:
2431 plog(LLV_ERROR
, LOCATION
, NULL
,
2432 "must be TV when GRP_DESC.\n");
2436 if (!alg_oakley_dhdef_ok(lorv
)) {
2437 plog(LLV_ERROR
, LOCATION
, NULL
,
2438 "invalid group description=%u.\n",
2444 case IPSECDOI_ATTR_KEY_LENGTH
:
2446 plog(LLV_ERROR
, LOCATION
, NULL
,
2447 "must be TV when KEY_LENGTH.\n");
2452 case IPSECDOI_ATTR_KEY_ROUNDS
:
2453 case IPSECDOI_ATTR_COMP_DICT_SIZE
:
2454 case IPSECDOI_ATTR_COMP_PRIVALG
:
2455 plog(LLV_ERROR
, LOCATION
, NULL
,
2456 "attr type=%u isn't supported.\n", type
);
2460 plog(LLV_ERROR
, LOCATION
, NULL
,
2461 "invalid attribute type %d.\n", type
);
2467 d
= (struct isakmp_data
*)((char *)d
2470 tlen
-= (sizeof(*d
) + lorv
);
2471 d
= (struct isakmp_data
*)((caddr_t
)d
2472 + sizeof(*d
) + lorv
);
2476 if (proto_id
== IPSECDOI_PROTO_IPSEC_AH
&&
2477 !attrseen
[IPSECDOI_ATTR_AUTH
]) {
2478 plog(LLV_ERROR
, LOCATION
, NULL
,
2479 "attr AUTH must be present for AH.\n");
2483 if (proto_id
== IPSECDOI_PROTO_IPSEC_ESP
&&
2484 trns
->t_id
== IPSECDOI_ESP_NULL
&&
2485 !attrseen
[IPSECDOI_ATTR_AUTH
]) {
2486 plog(LLV_ERROR
, LOCATION
, NULL
,
2487 "attr AUTH must be present for ESP NULL encryption.\n");
2495 check_attr_ipcomp(trns
)
2496 struct isakmp_pl_t
*trns
;
2498 struct isakmp_data
*d
;
2502 int attrseen
[16]; /* XXX magic number */
2504 tlen
= ntohs(trns
->h
.len
) - sizeof(struct isakmp_pl_t
);
2505 d
= (struct isakmp_data
*)((caddr_t
)trns
+ sizeof(struct isakmp_pl_t
));
2506 memset(attrseen
, 0, sizeof(attrseen
));
2509 type
= ntohs(d
->type
) & ~ISAKMP_GEN_MASK
;
2510 flag
= ntohs(d
->type
) & ISAKMP_GEN_MASK
;
2511 lorv
= ntohs(d
->lorv
);
2513 plog(LLV_DEBUG
, LOCATION
, NULL
,
2514 "type=%d, flag=0x%04x, lorv=0x%04x\n",
2517 if (type
< sizeof(attrseen
)/sizeof(attrseen
[0]))
2521 case IPSECDOI_ATTR_ENC_MODE
:
2523 plog(LLV_ERROR
, LOCATION
, NULL
,
2524 "must be TV when ENC_MODE.\n");
2529 case IPSECDOI_ATTR_ENC_MODE_TUNNEL
:
2530 case IPSECDOI_ATTR_ENC_MODE_TRNS
:
2533 case IPSECDOI_ATTR_ENC_MODE_UDPTUNNEL_RFC
:
2534 case IPSECDOI_ATTR_ENC_MODE_UDPTRNS_RFC
:
2535 case IPSECDOI_ATTR_ENC_MODE_UDPTUNNEL_DRAFT
:
2536 case IPSECDOI_ATTR_ENC_MODE_UDPTRNS_DRAFT
:
2537 plog(LLV_DEBUG
, LOCATION
, NULL
,
2538 "UDP encapsulation requested\n");
2542 plog(LLV_ERROR
, LOCATION
, NULL
,
2543 "invalid encryption mode=%u.\n",
2549 case IPSECDOI_ATTR_SA_LD_TYPE
:
2551 plog(LLV_ERROR
, LOCATION
, NULL
,
2552 "must be TV when LD_TYPE.\n");
2557 case IPSECDOI_ATTR_SA_LD_TYPE_SEC
:
2558 case IPSECDOI_ATTR_SA_LD_TYPE_KB
:
2561 plog(LLV_ERROR
, LOCATION
, NULL
,
2562 "invalid life type %d.\n", lorv
);
2567 case IPSECDOI_ATTR_SA_LD
:
2569 /* i.e. ISAKMP_GEN_TV */
2570 plog(LLV_DEBUG
, LOCATION
, NULL
,
2571 "life duration was in TLV.\n");
2573 /* i.e. ISAKMP_GEN_TLV */
2575 plog(LLV_ERROR
, LOCATION
, NULL
,
2576 "invalid length of LD\n");
2582 case IPSECDOI_ATTR_GRP_DESC
:
2584 plog(LLV_ERROR
, LOCATION
, NULL
,
2585 "must be TV when GRP_DESC.\n");
2589 if (!alg_oakley_dhdef_ok(lorv
)) {
2590 plog(LLV_ERROR
, LOCATION
, NULL
,
2591 "invalid group description=%u.\n",
2597 case IPSECDOI_ATTR_AUTH
:
2598 plog(LLV_ERROR
, LOCATION
, NULL
,
2599 "invalid attr type=%u.\n", type
);
2602 case IPSECDOI_ATTR_KEY_LENGTH
:
2603 case IPSECDOI_ATTR_KEY_ROUNDS
:
2604 case IPSECDOI_ATTR_COMP_DICT_SIZE
:
2605 case IPSECDOI_ATTR_COMP_PRIVALG
:
2606 plog(LLV_ERROR
, LOCATION
, NULL
,
2607 "attr type=%u isn't supported.\n", type
);
2611 plog(LLV_ERROR
, LOCATION
, NULL
,
2612 "invalid attribute type %d.\n", type
);
2618 d
= (struct isakmp_data
*)((char *)d
2621 tlen
-= (sizeof(*d
) + lorv
);
2622 d
= (struct isakmp_data
*)((caddr_t
)d
2623 + sizeof(*d
) + lorv
);
2628 if (proto_id
== IPSECDOI_PROTO_IPCOMP
&&
2629 !attrseen
[IPSECDOI_ATTR_AUTH
]) {
2630 plog(LLV_ERROR
, LOCATION
, NULL
,
2631 "attr AUTH must be present for AH.\n", type
);
2641 * create phase1 proposal from remote configuration.
2642 * NOT INCLUDING isakmp general header of SA payload
2645 ipsecdoi_setph1proposal(props
)
2646 struct isakmpsa
*props
;
2651 /* count total size of SA minus isakmp general header */
2652 /* not including isakmp general header of SA payload */
2653 sablen
= sizeof(struct ipsecdoi_sa_b
);
2654 sablen
+= setph1prop(props
, NULL
);
2656 mysa
= vmalloc(sablen
);
2658 plog(LLV_ERROR
, LOCATION
, NULL
,
2659 "failed to allocate my sa buffer\n");
2663 /* create SA payload */
2664 /* not including isakmp general header */
2665 ((struct ipsecdoi_sa_b
*)mysa
->v
)->doi
= htonl(props
->rmconf
->doitype
);
2666 ((struct ipsecdoi_sa_b
*)mysa
->v
)->sit
= htonl(props
->rmconf
->sittype
);
2668 (void)setph1prop(props
, mysa
->v
+ sizeof(struct ipsecdoi_sa_b
));
2674 setph1prop(props
, buf
)
2675 struct isakmpsa
*props
;
2678 struct isakmp_pl_p
*prop
= NULL
;
2679 struct isakmpsa
*s
= NULL
;
2680 int proplen
, trnslen
;
2681 u_int8_t
*np_t
; /* pointer next trns type in previous header */
2685 proplen
= sizeof(*prop
);
2687 /* create proposal */
2688 prop
= (struct isakmp_pl_p
*)p
;
2689 prop
->h
.np
= ISAKMP_NPTYPE_NONE
;
2690 prop
->p_no
= props
->prop_no
;
2691 prop
->proto_id
= IPSECDOI_PROTO_ISAKMP
;
2699 for (s
= props
; s
!= NULL
; s
= s
->next
) {
2701 *np_t
= ISAKMP_NPTYPE_T
;
2703 trnslen
= setph1trns(s
, p
);
2706 /* save buffer to pre-next payload */
2707 np_t
= &((struct isakmp_pl_t
*)p
)->h
.np
;
2710 /* count up transform length */
2715 /* update proposal length */
2717 prop
->h
.len
= htons(proplen
);
2718 prop
->num_t
= trns_num
;
2726 struct isakmpsa
*sa
;
2729 struct isakmp_pl_t
*trns
= NULL
;
2730 int trnslen
, attrlen
;
2733 trnslen
= sizeof(*trns
);
2735 /* create transform */
2736 trns
= (struct isakmp_pl_t
*)p
;
2737 trns
->h
.np
= ISAKMP_NPTYPE_NONE
;
2738 trns
->t_no
= sa
->trns_no
;
2739 trns
->t_id
= IPSECDOI_KEY_IKE
;
2743 attrlen
= setph1attr(sa
, p
);
2749 trns
->h
.len
= htons(trnslen
);
2756 struct isakmpsa
*sa
;
2763 u_int32_t lifetime
= htonl((u_int32_t
)sa
->lifetime
);
2765 attrlen
+= sizeof(struct isakmp_data
)
2766 + sizeof(struct isakmp_data
);
2767 if (sa
->lifetime
> 0xffff)
2768 attrlen
+= sizeof(lifetime
);
2770 p
= isakmp_set_attr_l(p
, OAKLEY_ATTR_SA_LD_TYPE
,
2771 OAKLEY_ATTR_SA_LD_TYPE_SEC
);
2772 if (sa
->lifetime
> 0xffff) {
2773 p
= isakmp_set_attr_v(p
, OAKLEY_ATTR_SA_LD
,
2777 p
= isakmp_set_attr_l(p
, OAKLEY_ATTR_SA_LD
,
2784 u_int32_t lifebyte
= htonl((u_int32_t
)sa
->lifebyte
);
2786 attrlen
+= sizeof(struct isakmp_data
)
2787 + sizeof(struct isakmp_data
);
2788 if (sa
->lifebyte
> 0xffff)
2789 attrlen
+= sizeof(lifebyte
);
2791 p
= isakmp_set_attr_l(p
, OAKLEY_ATTR_SA_LD_TYPE
,
2792 OAKLEY_ATTR_SA_LD_TYPE_KB
);
2793 if (sa
->lifebyte
> 0xffff) {
2794 p
= isakmp_set_attr_v(p
, OAKLEY_ATTR_SA_LD
,
2798 p
= isakmp_set_attr_l(p
, OAKLEY_ATTR_SA_LD
,
2805 attrlen
+= sizeof(struct isakmp_data
);
2807 p
= isakmp_set_attr_l(p
, OAKLEY_ATTR_ENC_ALG
, sa
->enctype
);
2810 attrlen
+= sizeof(struct isakmp_data
);
2812 p
= isakmp_set_attr_l(p
, OAKLEY_ATTR_KEY_LEN
, sa
->encklen
);
2814 if (sa
->authmethod
) {
2817 #ifdef ENABLE_HYBRID
2818 authmethod
= switch_authmethod(sa
->authmethod
);
2820 authmethod
= sa
->authmethod
;
2822 attrlen
+= sizeof(struct isakmp_data
);
2824 p
= isakmp_set_attr_l(p
, OAKLEY_ATTR_AUTH_METHOD
, authmethod
);
2827 attrlen
+= sizeof(struct isakmp_data
);
2829 p
= isakmp_set_attr_l(p
, OAKLEY_ATTR_HASH_ALG
, sa
->hashtype
);
2831 switch (sa
->dh_group
) {
2832 case OAKLEY_ATTR_GRP_DESC_MODP768
:
2833 case OAKLEY_ATTR_GRP_DESC_MODP1024
:
2834 case OAKLEY_ATTR_GRP_DESC_MODP1536
:
2835 case OAKLEY_ATTR_GRP_DESC_MODP2048
:
2836 case OAKLEY_ATTR_GRP_DESC_MODP3072
:
2837 case OAKLEY_ATTR_GRP_DESC_MODP4096
:
2838 case OAKLEY_ATTR_GRP_DESC_MODP6144
:
2839 case OAKLEY_ATTR_GRP_DESC_MODP8192
:
2840 /* don't attach group type for known groups */
2841 attrlen
+= sizeof(struct isakmp_data
);
2843 p
= isakmp_set_attr_l(p
, OAKLEY_ATTR_GRP_DESC
,
2847 case OAKLEY_ATTR_GRP_DESC_EC2N155
:
2848 case OAKLEY_ATTR_GRP_DESC_EC2N185
:
2849 /* don't attach group type for known groups */
2850 attrlen
+= sizeof(struct isakmp_data
);
2852 p
= isakmp_set_attr_l(p
, OAKLEY_ATTR_GRP_TYPE
,
2853 OAKLEY_ATTR_GRP_TYPE_EC2N
);
2862 if (sa
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
2863 sa
->gssid
!= NULL
) {
2864 attrlen
+= sizeof(struct isakmp_data
);
2866 * Older versions of racoon just placed the ISO-Latin-1
2867 * string on the wire directly. Check to see if we are
2868 * configured to be compatible with this behavior. Otherwise,
2869 * we encode the GSS ID as UTF-16LE for Windows 2000
2870 * compatibility, which requires twice the number of octets.
2872 if (lcconf
->gss_id_enc
== LC_GSSENC_LATIN1
)
2873 attrlen
+= sa
->gssid
->l
;
2875 attrlen
+= sa
->gssid
->l
* 2;
2877 plog(LLV_DEBUG
, LOCATION
, NULL
, "gss id attr: len %zu, "
2878 "val '%.*s'\n", sa
->gssid
->l
, (int)sa
->gssid
->l
,
2880 if (lcconf
->gss_id_enc
== LC_GSSENC_LATIN1
) {
2881 p
= isakmp_set_attr_v(p
, OAKLEY_ATTR_GSS_ID
,
2882 (caddr_t
)sa
->gssid
->v
,
2885 size_t dstleft
= sa
->gssid
->l
* 2;
2886 size_t srcleft
= sa
->gssid
->l
;
2887 const char *src
= (const char *)sa
->gssid
->v
;
2888 char *odst
, *dst
= racoon_malloc(dstleft
);
2892 cd
= iconv_open("utf-16le", "latin1");
2893 if (cd
== (iconv_t
) -1) {
2894 plog(LLV_ERROR
, LOCATION
, NULL
,
2895 "unable to initialize "
2896 "latin1 -> utf-16le "
2897 "converstion descriptor: %s\n",
2899 attrlen
-= sa
->gssid
->l
* 2;
2903 rv
= iconv(cd
, (__iconv_const
char **)&src
,
2904 &srcleft
, &dst
, &dstleft
);
2907 plog(LLV_ERROR
, LOCATION
, NULL
,
2908 "unable to convert GSS ID "
2909 "from latin1 -> utf-16le: "
2910 "%s\n", strerror(errno
));
2912 /* should never happen */
2913 plog(LLV_ERROR
, LOCATION
, NULL
,
2914 "%zd character%s in GSS ID "
2915 "cannot be represented "
2917 rv
, rv
== 1 ? "" : "s");
2919 (void) iconv_close(cd
);
2920 attrlen
-= sa
->gssid
->l
* 2;
2923 (void) iconv_close(cd
);
2925 /* XXX Check srcleft and dstleft? */
2927 p
= isakmp_set_attr_v(p
, OAKLEY_ATTR_GSS_ID
,
2928 odst
, sa
->gssid
->l
* 2);
2935 #endif /* HAVE_GSSAPI */
2941 setph2proposal0(iph2
, pp
, pr
)
2942 const struct ph2handle
*iph2
;
2943 const struct saprop
*pp
;
2944 const struct saproto
*pr
;
2947 struct isakmp_pl_p
*prop
;
2948 struct isakmp_pl_t
*trns
;
2953 u_int8_t
*np_t
; /* pointer next trns type in previous header */
2954 const u_int8_t
*spi
;
2956 p
= vmalloc(sizeof(*prop
) + sizeof(pr
->spi
));
2960 /* create proposal */
2961 prop
= (struct isakmp_pl_p
*)p
->v
;
2962 prop
->h
.np
= ISAKMP_NPTYPE_NONE
;
2963 prop
->p_no
= pp
->prop_no
;
2964 prop
->proto_id
= pr
->proto_id
;
2967 spi
= (const u_int8_t
*)&pr
->spi
;
2968 switch (pr
->proto_id
) {
2969 case IPSECDOI_PROTO_IPCOMP
:
2971 * draft-shacham-ippcp-rfc2393bis-05.txt:
2972 * construct 16bit SPI (CPI).
2973 * XXX we may need to provide a configuration option to
2974 * generate 32bit SPI. otherwise we cannot interoeprate
2975 * with nodes that uses 32bit SPI, in case we are initiator.
2977 prop
->spi_size
= sizeof(u_int16_t
);
2978 spi
+= sizeof(pr
->spi
) - sizeof(u_int16_t
);
2979 p
->l
-= sizeof(pr
->spi
);
2980 p
->l
+= sizeof(u_int16_t
);
2983 prop
->spi_size
= sizeof(pr
->spi
);
2986 memcpy(prop
+ 1, spi
, prop
->spi_size
);
2988 /* create transform */
2989 trnsoff
= sizeof(*prop
) + prop
->spi_size
;
2992 for (tr
= pr
->head
; tr
; tr
= tr
->next
) {
2994 switch (pr
->proto_id
) {
2995 case IPSECDOI_PROTO_IPSEC_ESP
:
2997 * don't build a null encryption
2998 * with no authentication transform.
3000 if (tr
->trns_id
== IPSECDOI_ESP_NULL
&&
3001 tr
->authtype
== IPSECDOI_ATTR_AUTH_NONE
)
3007 *np_t
= ISAKMP_NPTYPE_T
;
3011 /* get attribute length */
3014 attrlen
+= sizeof(struct isakmp_data
)
3015 + sizeof(struct isakmp_data
);
3016 if (pp
->lifetime
> 0xffff)
3017 attrlen
+= sizeof(u_int32_t
);
3019 if (pp
->lifebyte
&& pp
->lifebyte
!= IPSECDOI_ATTR_SA_LD_KB_MAX
) {
3020 attrlen
+= sizeof(struct isakmp_data
)
3021 + sizeof(struct isakmp_data
);
3022 if (pp
->lifebyte
> 0xffff)
3023 attrlen
+= sizeof(u_int32_t
);
3025 attrlen
+= sizeof(struct isakmp_data
); /* enc mode */
3027 attrlen
+= sizeof(struct isakmp_data
);
3029 switch (pr
->proto_id
) {
3030 case IPSECDOI_PROTO_IPSEC_ESP
:
3031 /* non authentication mode ? */
3032 if (tr
->authtype
!= IPSECDOI_ATTR_AUTH_NONE
)
3033 attrlen
+= sizeof(struct isakmp_data
);
3035 case IPSECDOI_PROTO_IPSEC_AH
:
3036 if (tr
->authtype
== IPSECDOI_ATTR_AUTH_NONE
) {
3037 plog(LLV_ERROR
, LOCATION
, NULL
,
3038 "no authentication algorithm found "
3039 "but protocol is AH.\n");
3043 attrlen
+= sizeof(struct isakmp_data
);
3045 case IPSECDOI_PROTO_IPCOMP
:
3048 plog(LLV_ERROR
, LOCATION
, NULL
,
3049 "invalid protocol: %d\n", pr
->proto_id
);
3054 if (alg_oakley_dhdef_ok(iph2
->sainfo
->pfs_group
))
3055 attrlen
+= sizeof(struct isakmp_data
);
3057 p
= vrealloc(p
, p
->l
+ sizeof(*trns
) + attrlen
);
3060 prop
= (struct isakmp_pl_p
*)p
->v
;
3062 /* set transform's values */
3063 trns
= (struct isakmp_pl_t
*)(p
->v
+ trnsoff
);
3064 trns
->h
.np
= ISAKMP_NPTYPE_NONE
;
3065 trns
->t_no
= tr
->trns_no
;
3066 trns
->t_id
= tr
->trns_id
;
3068 /* set attributes */
3069 x
= x0
= p
->v
+ trnsoff
+ sizeof(*trns
);
3072 x
= isakmp_set_attr_l(x
, IPSECDOI_ATTR_SA_LD_TYPE
,
3073 IPSECDOI_ATTR_SA_LD_TYPE_SEC
);
3074 if (pp
->lifetime
> 0xffff) {
3075 u_int32_t v
= htonl((u_int32_t
)pp
->lifetime
);
3076 x
= isakmp_set_attr_v(x
, IPSECDOI_ATTR_SA_LD
,
3077 (caddr_t
)&v
, sizeof(v
));
3079 x
= isakmp_set_attr_l(x
, IPSECDOI_ATTR_SA_LD
,
3084 if (pp
->lifebyte
&& pp
->lifebyte
!= IPSECDOI_ATTR_SA_LD_KB_MAX
) {
3085 x
= isakmp_set_attr_l(x
, IPSECDOI_ATTR_SA_LD_TYPE
,
3086 IPSECDOI_ATTR_SA_LD_TYPE_KB
);
3087 if (pp
->lifebyte
> 0xffff) {
3088 u_int32_t v
= htonl((u_int32_t
)pp
->lifebyte
);
3089 x
= isakmp_set_attr_v(x
, IPSECDOI_ATTR_SA_LD
,
3090 (caddr_t
)&v
, sizeof(v
));
3092 x
= isakmp_set_attr_l(x
, IPSECDOI_ATTR_SA_LD
,
3097 x
= isakmp_set_attr_l(x
, IPSECDOI_ATTR_ENC_MODE
, pr
->encmode
);
3100 x
= isakmp_set_attr_l(x
, IPSECDOI_ATTR_KEY_LENGTH
, tr
->encklen
);
3102 /* mandatory check has done above. */
3103 if ((pr
->proto_id
== IPSECDOI_PROTO_IPSEC_ESP
&& tr
->authtype
!= IPSECDOI_ATTR_AUTH_NONE
)
3104 || pr
->proto_id
== IPSECDOI_PROTO_IPSEC_AH
)
3105 x
= isakmp_set_attr_l(x
, IPSECDOI_ATTR_AUTH
, tr
->authtype
);
3107 if (alg_oakley_dhdef_ok(iph2
->sainfo
->pfs_group
))
3108 x
= isakmp_set_attr_l(x
, IPSECDOI_ATTR_GRP_DESC
,
3109 iph2
->sainfo
->pfs_group
);
3111 /* update length of this transform. */
3112 trns
= (struct isakmp_pl_t
*)(p
->v
+ trnsoff
);
3113 trns
->h
.len
= htons(sizeof(*trns
) + attrlen
);
3115 /* save buffer to pre-next payload */
3118 trnsoff
+= (sizeof(*trns
) + attrlen
);
3122 plog(LLV_ERROR
, LOCATION
, NULL
,
3123 "no suitable proposal was created.\n");
3127 /* update length of this protocol. */
3128 prop
->h
.len
= htons(p
->l
);
3134 * create phase2 proposal from policy configuration.
3135 * NOT INCLUDING isakmp general header of SA payload.
3136 * This function is called by initiator only.
3139 ipsecdoi_setph2proposal(iph2
)
3140 struct ph2handle
*iph2
;
3142 struct saprop
*proposal
, *a
;
3143 struct saproto
*b
= NULL
;
3145 struct ipsecdoi_sa_b
*sab
;
3146 struct isakmp_pl_p
*prop
;
3147 size_t propoff
; /* for previous field of type of next payload. */
3149 proposal
= iph2
->proposal
;
3151 iph2
->sa
= vmalloc(sizeof(*sab
));
3152 if (iph2
->sa
== NULL
) {
3153 plog(LLV_ERROR
, LOCATION
, NULL
,
3154 "failed to allocate my sa buffer\n");
3158 /* create SA payload */
3159 sab
= (struct ipsecdoi_sa_b
*)iph2
->sa
->v
;
3160 sab
->doi
= htonl(IPSEC_DOI
);
3161 sab
->sit
= htonl(IPSECDOI_SIT_IDENTITY_ONLY
); /* XXX configurable ? */
3165 for (a
= proposal
; a
; a
= a
->next
) {
3166 for (b
= a
->head
; b
; b
= b
->next
) {
3168 if (iph2
->ph1
->natt_flags
& NAT_DETECTED
) {
3169 int udp_diff
= iph2
->ph1
->natt_options
->mode_udp_diff
;
3170 plog (LLV_INFO
, LOCATION
, NULL
,
3171 "NAT detected -> UDP encapsulation "
3172 "(ENC_MODE %d->%d).\n",
3174 b
->encmode
+udp_diff
);
3175 /* Tunnel -> UDP-Tunnel, Transport -> UDP_Transport */
3176 b
->encmode
+= udp_diff
;
3181 q
= setph2proposal0(iph2
, a
, b
);
3187 iph2
->sa
= vrealloc(iph2
->sa
, iph2
->sa
->l
+ q
->l
);
3188 if (iph2
->sa
== NULL
) {
3189 plog(LLV_ERROR
, LOCATION
, NULL
,
3190 "failed to allocate my sa buffer\n");
3195 memcpy(iph2
->sa
->v
+ iph2
->sa
->l
- q
->l
, q
->v
, q
->l
);
3197 prop
= (struct isakmp_pl_p
*)(iph2
->sa
->v
+
3199 prop
->h
.np
= ISAKMP_NPTYPE_P
;
3201 propoff
= iph2
->sa
->l
- q
->l
;
3211 * return 1 if all of the given protocols are tunnel mode.
3214 ipsecdoi_tunnelmode(iph2
)
3215 struct ph2handle
*iph2
;
3218 struct saproto
*pr
= NULL
;
3220 for (pp
= iph2
->proposal
; pp
; pp
= pp
->next
) {
3221 for (pr
= pp
->head
; pr
; pr
= pr
->next
) {
3222 if (pr
->encmode
!= IPSECDOI_ATTR_ENC_MODE_TUNNEL
&&
3223 pr
->encmode
!= IPSECDOI_ATTR_ENC_MODE_UDPTUNNEL_RFC
&&
3224 pr
->encmode
!= IPSECDOI_ATTR_ENC_MODE_UDPTUNNEL_DRAFT
)
3233 * return 1 if any of the given protocols are transport mode.
3236 ipsecdoi_any_transportmode(pp
)
3239 struct saproto
*pr
= NULL
;
3241 for (; pp
; pp
= pp
->next
) {
3242 for (pr
= pp
->head
; pr
; pr
= pr
->next
) {
3243 if (pr
->encmode
== IPSECDOI_ATTR_ENC_MODE_TRNS
||
3244 pr
->encmode
== IPSECDOI_ATTR_ENC_MODE_UDPTRNS_RFC
||
3245 pr
->encmode
== IPSECDOI_ATTR_ENC_MODE_UDPTRNS_DRAFT
)
3254 * return 1 if all of the given protocols are transport mode.
3257 ipsecdoi_transportmode(pp
)
3260 struct saproto
*pr
= NULL
;
3262 for (; pp
; pp
= pp
->next
) {
3263 for (pr
= pp
->head
; pr
; pr
= pr
->next
) {
3264 if (pr
->encmode
!= IPSECDOI_ATTR_ENC_MODE_TRNS
)
3273 ipsecdoi_get_defaultlifetime()
3275 return IPSECDOI_ATTR_SA_LD_SEC_DEFAULT
;
3279 ipsecdoi_checkalgtypes(proto_id
, enc
, auth
, comp
)
3280 int proto_id
, enc
, auth
, comp
;
3282 #define TMPALGTYPE2STR(n) s_algtype(algclass_ipsec_##n, n)
3284 case IPSECDOI_PROTO_IPSEC_ESP
:
3285 if (enc
== 0 || comp
!= 0) {
3286 plog(LLV_ERROR
, LOCATION
, NULL
,
3287 "illegal algorithm defined "
3288 "ESP enc=%s auth=%s comp=%s.\n",
3289 TMPALGTYPE2STR(enc
),
3290 TMPALGTYPE2STR(auth
),
3291 TMPALGTYPE2STR(comp
));
3295 case IPSECDOI_PROTO_IPSEC_AH
:
3296 if (enc
!= 0 || auth
== 0 || comp
!= 0) {
3297 plog(LLV_ERROR
, LOCATION
, NULL
,
3298 "illegal algorithm defined "
3299 "AH enc=%s auth=%s comp=%s.\n",
3300 TMPALGTYPE2STR(enc
),
3301 TMPALGTYPE2STR(auth
),
3302 TMPALGTYPE2STR(comp
));
3306 case IPSECDOI_PROTO_IPCOMP
:
3307 if (enc
!= 0 || auth
!= 0 || comp
== 0) {
3308 plog(LLV_ERROR
, LOCATION
, NULL
,
3309 "illegal algorithm defined "
3310 "IPcomp enc=%s auth=%s comp=%s.\n",
3311 TMPALGTYPE2STR(enc
),
3312 TMPALGTYPE2STR(auth
),
3313 TMPALGTYPE2STR(comp
));
3318 plog(LLV_ERROR
, LOCATION
, NULL
,
3319 "invalid ipsec protocol %d\n", proto_id
);
3322 #undef TMPALGTYPE2STR
3332 return IPSECDOI_PROTO_IPSEC_AH
;
3334 return IPSECDOI_PROTO_IPSEC_ESP
;
3335 case IPPROTO_IPCOMP
:
3336 return IPSECDOI_PROTO_IPCOMP
;
3338 return -1; /* XXX */
3346 case IPSECDOI_PROTO_IPSEC_AH
:
3348 case IPSECDOI_PROTO_IPSEC_ESP
:
3350 case IPSECDOI_PROTO_IPCOMP
:
3351 return IPPROTO_IPCOMP
;
3353 return -1; /* XXX */
3357 * Check if a subnet id is valid for comparison
3358 * with an address id ( address length mask )
3366 ipsecdoi_subnetisaddr_v4( subnet
, address
)
3367 const vchar_t
*subnet
;
3368 const vchar_t
*address
;
3370 struct in_addr
*mask
;
3372 if (address
->l
!= sizeof(struct in_addr
))
3375 if (subnet
->l
!= (sizeof(struct in_addr
)*2))
3378 mask
= (struct in_addr
*)(subnet
->v
+ sizeof(struct in_addr
));
3380 if (mask
->s_addr
!=0xffffffff)
3383 return memcmp(subnet
->v
,address
->v
,address
->l
);
3389 ipsecdoi_subnetisaddr_v6( subnet
, address
)
3390 const vchar_t
*subnet
;
3391 const vchar_t
*address
;
3393 struct in6_addr
*mask
;
3396 if (address
->l
!= sizeof(struct in6_addr
))
3399 if (subnet
->l
!= (sizeof(struct in6_addr
)*2))
3402 mask
= (struct in6_addr
*)(subnet
->v
+ sizeof(struct in6_addr
));
3404 for (i
=0; i
<16; i
++)
3405 if(mask
->s6_addr
[i
]!=0xff)
3408 return memcmp(subnet
->v
,address
->v
,address
->l
);
3415 * Check and Compare two IDs
3416 * - specify 0 for exact if wildcards are allowed
3420 * = -1 for integrity error
3424 ipsecdoi_chkcmpids( idt
, ids
, exact
)
3425 const vchar_t
*idt
; /* id cmp target */
3426 const vchar_t
*ids
; /* id cmp source */
3429 struct ipsecdoi_id_b
*id_bt
;
3430 struct ipsecdoi_id_b
*id_bs
;
3435 /* handle wildcard IDs */
3437 if (idt
== NULL
|| ids
== NULL
)
3441 plog(LLV_DEBUG
, LOCATION
, NULL
,
3442 "check and compare ids : values matched (ANONYMOUS)\n" );
3447 plog(LLV_DEBUG
, LOCATION
, NULL
,
3448 "check and compare ids : value mismatch (ANONYMOUS)\n" );
3453 /* make sure the ids are of the same type */
3455 id_bt
= (struct ipsecdoi_id_b
*) idt
->v
;
3456 id_bs
= (struct ipsecdoi_id_b
*) ids
->v
;
3458 ident_t
.v
= idt
->v
+ sizeof(*id_bt
);
3459 ident_t
.l
= idt
->l
- sizeof(*id_bt
);
3460 ident_s
.v
= ids
->v
+ sizeof(*id_bs
);
3461 ident_s
.l
= ids
->l
- sizeof(*id_bs
);
3463 if (id_bs
->type
!= id_bt
->type
)
3466 * special exception for comparing
3467 * address to subnet id types when
3468 * the netmask is address length
3471 if ((id_bs
->type
== IPSECDOI_ID_IPV4_ADDR
)&&
3472 (id_bt
->type
== IPSECDOI_ID_IPV4_ADDR_SUBNET
)) {
3473 result
= ipsecdoi_subnetisaddr_v4(&ident_t
,&ident_s
);
3477 if ((id_bs
->type
== IPSECDOI_ID_IPV4_ADDR_SUBNET
)&&
3478 (id_bt
->type
== IPSECDOI_ID_IPV4_ADDR
)) {
3479 result
= ipsecdoi_subnetisaddr_v4(&ident_s
,&ident_t
);
3484 if ((id_bs
->type
== IPSECDOI_ID_IPV6_ADDR
)&&
3485 (id_bt
->type
== IPSECDOI_ID_IPV6_ADDR_SUBNET
)) {
3486 result
= ipsecdoi_subnetisaddr_v6(&ident_t
,&ident_s
);
3490 if ((id_bs
->type
== IPSECDOI_ID_IPV6_ADDR_SUBNET
)&&
3491 (id_bt
->type
== IPSECDOI_ID_IPV6_ADDR
)) {
3492 result
= ipsecdoi_subnetisaddr_v6(&ident_s
,&ident_t
);
3496 plog(LLV_DEBUG
, LOCATION
, NULL
,
3497 "check and compare ids : id type mismatch %s != %s\n",
3498 s_ipsecdoi_ident(id_bs
->type
),
3499 s_ipsecdoi_ident(id_bt
->type
));
3504 if(id_bs
->proto_id
!= id_bt
->proto_id
){
3505 plog(LLV_DEBUG
, LOCATION
, NULL
,
3506 "check and compare ids : proto_id mismatch %d != %d\n",
3507 id_bs
->proto_id
, id_bt
->proto_id
);
3512 /* compare the ID data. */
3514 switch (id_bt
->type
) {
3515 case IPSECDOI_ID_DER_ASN1_DN
:
3516 case IPSECDOI_ID_DER_ASN1_GN
:
3517 /* compare asn1 ids */
3518 result
= eay_cmp_asn1dn(&ident_t
, &ident_s
);
3521 case IPSECDOI_ID_IPV4_ADDR
:
3522 /* validate lengths */
3523 if ((ident_t
.l
!= sizeof(struct in_addr
))||
3524 (ident_s
.l
!= sizeof(struct in_addr
)))
3528 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
3529 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
3530 /* validate lengths */
3531 if ((ident_t
.l
!= (sizeof(struct in_addr
)*2))||
3532 (ident_s
.l
!= (sizeof(struct in_addr
)*2)))
3537 case IPSECDOI_ID_IPV6_ADDR
:
3538 /* validate lengths */
3539 if ((ident_t
.l
!= sizeof(struct in6_addr
))||
3540 (ident_s
.l
!= sizeof(struct in6_addr
)))
3544 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
3545 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
3546 /* validate lengths */
3547 if ((ident_t
.l
!= (sizeof(struct in6_addr
)*2))||
3548 (ident_s
.l
!= (sizeof(struct in6_addr
)*2)))
3552 case IPSECDOI_ID_FQDN
:
3553 case IPSECDOI_ID_USER_FQDN
:
3554 case IPSECDOI_ID_KEY_ID
:
3558 plog(LLV_ERROR
, LOCATION
, NULL
,
3559 "Unhandled id type %i specified for comparison\n",
3564 /* validate matching data and length */
3565 if (ident_t
.l
== ident_s
.l
)
3566 result
= memcmp(ident_t
.v
,ident_s
.v
,ident_t
.l
);
3572 /* debug level output */
3573 if(loglevel
>= LLV_DEBUG
) {
3574 char *idstrt
= ipsecdoi_id2str(idt
);
3575 char *idstrs
= ipsecdoi_id2str(ids
);
3578 plog(LLV_DEBUG
, LOCATION
, NULL
,
3579 "check and compare ids : values matched (%s)\n",
3580 s_ipsecdoi_ident(id_bs
->type
) );
3582 plog(LLV_DEBUG
, LOCATION
, NULL
,
3583 "check and compare ids : value mismatch (%s)\n",
3584 s_ipsecdoi_ident(id_bs
->type
));
3586 plog(LLV_DEBUG
, LOCATION
, NULL
, "cmpid target: \'%s\'\n", idstrt
);
3587 plog(LLV_DEBUG
, LOCATION
, NULL
, "cmpid source: \'%s\'\n", idstrs
);
3589 racoon_free(idstrs
);
3590 racoon_free(idstrt
);
3601 /* id integrity error */
3602 plog(LLV_DEBUG
, LOCATION
, NULL
, "check and compare ids : %s integrity error\n",
3603 s_ipsecdoi_ident(id_bs
->type
));
3604 plog(LLV_DEBUG
, LOCATION
, NULL
, "cmpid target: length = \'%zu\'\n", ident_t
.l
);
3605 plog(LLV_DEBUG
, LOCATION
, NULL
, "cmpid source: length = \'%zu\'\n", ident_s
.l
);
3612 * check the following:
3613 * - In main mode with pre-shared key, only address type can be used.
3614 * - if proper type for phase 1 ?
3615 * - if phase 1 ID payload conformed RFC2407 4.6.2.
3616 * (proto, port) must be (0, 0), (udp, 500) or (udp, [specified]).
3617 * - if ID payload sent from peer is equal to the ID expected by me.
3619 * both of "id" and "id_p" should be ID payload without general header,
3622 ipsecdoi_checkid1(iph1
)
3623 struct ph1handle
*iph1
;
3625 struct ipsecdoi_id_b
*id_b
;
3626 struct sockaddr
*sa
;
3629 if (iph1
->id_p
== NULL
) {
3630 plog(LLV_ERROR
, LOCATION
, NULL
,
3631 "invalid iph1 passed id_p == NULL\n");
3632 return ISAKMP_INTERNAL_ERROR
;
3634 if (iph1
->id_p
->l
< sizeof(*id_b
)) {
3635 plog(LLV_ERROR
, LOCATION
, NULL
,
3636 "invalid value passed as \"ident\" (len=%lu)\n",
3637 (u_long
)iph1
->id_p
->l
);
3638 return ISAKMP_NTYPE_INVALID_ID_INFORMATION
;
3641 id_b
= (struct ipsecdoi_id_b
*)iph1
->id_p
->v
;
3643 /* In main mode with pre-shared key, only address type can be used.
3644 * If NAT Traversal being used and peer is behind nat and
3645 * natt version = 02 - allow non-address ID type.
3647 if (iph1
->etype
== ISAKMP_ETYPE_IDENT
3648 && iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_PSKEY
3650 && (iph1
->natt_flags
& NAT_DETECTED_PEER
) == 0
3653 if (id_b
->type
!= IPSECDOI_ID_IPV4_ADDR
3654 && id_b
->type
!= IPSECDOI_ID_IPV6_ADDR
) {
3655 plog(LLV_ERROR
, LOCATION
, NULL
,
3656 "Expecting IP address type in main mode, "
3657 "but %s.\n", s_ipsecdoi_ident(id_b
->type
));
3658 return ISAKMP_NTYPE_INVALID_ID_INFORMATION
;
3662 /* if proper type for phase 1 ? */
3663 switch (id_b
->type
) {
3664 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
3665 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
3666 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
3667 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
3668 plog(LLV_WARNING
, LOCATION
, NULL
,
3669 "such ID type %s is not proper.\n",
3670 s_ipsecdoi_ident(id_b
->type
));
3674 /* if phase 1 ID payload conformed RFC2407 4.6.2. */
3675 if (id_b
->type
== IPSECDOI_ID_IPV4_ADDR
||
3676 id_b
->type
== IPSECDOI_ID_IPV6_ADDR
) {
3678 if (id_b
->proto_id
== 0 && ntohs(id_b
->port
) != 0) {
3679 plog(LLV_WARNING
, LOCATION
, NULL
,
3680 "protocol ID and Port mismatched. "
3681 "proto_id:%d port:%d\n",
3682 id_b
->proto_id
, ntohs(id_b
->port
));
3685 } else if (id_b
->proto_id
== IPPROTO_UDP
) {
3687 * copmaring with expected port.
3688 * always permit if port is equal to PORT_ISAKMP
3690 if (ntohs(id_b
->port
) != PORT_ISAKMP
) {
3694 switch (iph1
->remote
->sa_family
) {
3696 port
= ((struct sockaddr_in
*)iph1
->remote
)->sin_port
;
3700 port
= ((struct sockaddr_in6
*)iph1
->remote
)->sin6_port
;
3704 plog(LLV_ERROR
, LOCATION
, NULL
,
3705 "invalid family: %d\n",
3706 iph1
->remote
->sa_family
);
3707 return ISAKMP_NTYPE_INVALID_ID_INFORMATION
;
3709 if (ntohs(id_b
->port
) != port
) {
3710 plog(LLV_WARNING
, LOCATION
, NULL
,
3711 "port %d expected, but %d\n",
3712 port
, ntohs(id_b
->port
));
3719 /* compare with the ID if specified. */
3720 if (genlist_next(iph1
->rmconf
->idvl_p
, 0)) {
3721 vchar_t
*ident0
= NULL
;
3724 struct genlist_entry
*gpb
;
3726 for (id
= genlist_next (iph1
->rmconf
->idvl_p
, &gpb
); id
; id
= genlist_next (0, &gpb
)) {
3727 /* check the type of both IDs */
3728 if (id
->idtype
!= doi2idtype(id_b
->type
))
3729 continue; /* ID type mismatch */
3733 /* compare defined ID with the ID sent by peer. */
3736 ident0
= getidval(id
->idtype
, id
->id
);
3738 switch (id
->idtype
) {
3741 ident
.v
= iph1
->id_p
->v
+ sizeof(*id_b
);
3742 ident
.l
= iph1
->id_p
->l
- sizeof(*id_b
);
3743 if (eay_cmp_asn1dn(ident0
, &ident
) == 0)
3746 plog(LLV_WARNING
, LOCATION
, NULL
, "ASN1DN ID matching not implemented - passed.\n");
3747 goto matched
; //%%%%%% hack for now until we have code to do this.
3750 case IDTYPE_ADDRESS
:
3751 sa
= (struct sockaddr
*)ident0
->v
;
3752 sa2
= (caddr_t
)(id_b
+ 1);
3753 switch (sa
->sa_family
) {
3755 if (iph1
->id_p
->l
- sizeof(*id_b
) != sizeof(struct in_addr
))
3756 continue; /* ID value mismatch */
3757 sa1
= (caddr_t
)&((struct sockaddr_in
*)sa
)->sin_addr
;
3758 if (memcmp(sa1
, sa2
, sizeof(struct in_addr
)) == 0)
3763 if (iph1
->id_p
->l
- sizeof(*id_b
) != sizeof(struct in6_addr
))
3764 continue; /* ID value mismatch */
3765 sa1
= (caddr_t
)&((struct sockaddr_in6
*)sa
)->sin6_addr
;
3766 if (memcmp(sa1
, sa2
, sizeof(struct in6_addr
)) == 0)
3775 if (memcmp(ident0
->v
, id_b
+ 1, ident0
->l
) == 0)
3780 if (ident0
!= NULL
) {
3784 plog(LLV_WARNING
, LOCATION
, NULL
, "No ID match.\n");
3785 if (iph1
->rmconf
->verify_identifier
)
3786 return ISAKMP_NTYPE_INVALID_ID_INFORMATION
;
3787 matched
: /* ID value match */
3796 * create ID payload for phase 1 and set into iph1->id.
3797 * NOT INCLUDING isakmp general header.
3798 * see, RFC2407 4.6.2.1
3801 ipsecdoi_setid1(iph1
)
3802 struct ph1handle
*iph1
;
3804 vchar_t
*ret
= NULL
;
3805 struct ipsecdoi_id_b id_b
;
3806 vchar_t
*ident
= NULL
;
3807 struct sockaddr
*ipid
= NULL
;
3814 switch (iph1
->rmconf
->idvtype
) {
3816 id_b
.type
= IPSECDOI_ID_FQDN
;
3817 ident
= getidval(iph1
->rmconf
->idvtype
, iph1
->rmconf
->idv
);
3819 case IDTYPE_USERFQDN
:
3820 id_b
.type
= IPSECDOI_ID_USER_FQDN
;
3821 ident
= getidval(iph1
->rmconf
->idvtype
, iph1
->rmconf
->idv
);
3824 case IDTYPE_KEYIDUSE
:
3825 id_b
.type
= IPSECDOI_ID_KEY_ID
;
3826 ident
= getidval(iph1
->rmconf
->idvtype
, iph1
->rmconf
->idv
);
3829 id_b
.type
= IPSECDOI_ID_DER_ASN1_DN
;
3830 if (iph1
->rmconf
->idv
) {
3831 /* XXX it must be encoded to asn1dn. */
3832 ident
= vdup(iph1
->rmconf
->idv
);
3834 if (oakley_getmycert(iph1
) < 0) {
3835 plog(LLV_ERROR
, LOCATION
, NULL
,
3836 "failed to get own CERT.\n");
3839 #if TARGET_OS_EMBEDDED
3841 SecCertificateRef certificate
;
3846 certificate
= crypto_cssm_x509cert_get_SecCertificateRef(&iph1
->cert
->cert
);
3847 if (certificate
== NULL
) {
3848 plog(LLV_ERROR
, LOCATION
, NULL
,
3849 "failed to get SecCertificateRef\n");
3852 subject
= SecCertificateCopySubjectSequence(certificate
);
3853 if (subject
== NULL
) {
3854 plog(LLV_ERROR
, LOCATION
, NULL
,
3855 "failed to get subjectName\n");
3856 CFRelease(certificate
);
3859 len
= CFDataGetLength(subject
);
3860 namePtr
= CFDataGetBytePtr(subject
);
3861 ident
= vmalloc(len
);
3862 if (ident
== NULL
) {
3863 plog(LLV_ERROR
, LOCATION
, NULL
,
3864 "failed to get subjectName\n");
3865 CFRelease(certificate
);
3869 memcpy(ident
->v
, namePtr
, len
);
3870 CFRelease(certificate
);
3875 ident
= eay_get_x509asn1subjectname(&iph1
->cert
->cert
);
3879 case IDTYPE_ADDRESS
:
3881 * if the value of the id type was set by the configuration
3882 * file, then use it. otherwise the value is get from local
3883 * ip address by using ike negotiation.
3885 if (iph1
->rmconf
->idv
)
3886 ipid
= (struct sockaddr
*)iph1
->rmconf
->idv
->v
;
3896 /* use IP address */
3897 switch (ipid
->sa_family
) {
3899 id_b
.type
= IPSECDOI_ID_IPV4_ADDR
;
3900 l
= sizeof(struct in_addr
);
3901 p
= (caddr_t
)&((struct sockaddr_in
*)ipid
)->sin_addr
;
3905 id_b
.type
= IPSECDOI_ID_IPV6_ADDR
;
3906 l
= sizeof(struct in6_addr
);
3907 p
= (caddr_t
)&((struct sockaddr_in6
*)ipid
)->sin6_addr
;
3911 plog(LLV_ERROR
, LOCATION
, NULL
,
3912 "invalid address family.\n");
3915 id_b
.proto_id
= IPPROTO_UDP
;
3916 id_b
.port
= htons(PORT_ISAKMP
);
3919 plog(LLV_ERROR
, LOCATION
, NULL
,
3920 "failed to get ID buffer.\n");
3923 memcpy(ident
->v
, p
, ident
->l
);
3927 plog(LLV_ERROR
, LOCATION
, NULL
,
3928 "failed to get ID buffer.\n");
3932 ret
= vmalloc(sizeof(id_b
) + ident
->l
);
3934 plog(LLV_ERROR
, LOCATION
, NULL
,
3935 "failed to get ID buffer.\n");
3939 memcpy(ret
->v
, &id_b
, sizeof(id_b
));
3940 memcpy(ret
->v
+ sizeof(id_b
), ident
->v
, ident
->l
);
3944 plog(LLV_DEBUG
, LOCATION
, NULL
,
3945 "use ID type of %s\n", s_ipsecdoi_ident(id_b
.type
));
3946 plogdump(LLV_DEBUG
, iph1
->id
->v
, iph1
->id
->l
);
3954 plog(LLV_ERROR
, LOCATION
, NULL
, "failed get my ID\n");
3963 vchar_t
*new = NULL
;
3967 else if (lcconf
->ident
[type
])
3968 new = vdup(lcconf
->ident
[type
]);
3973 /* it's only called by cfparse.y. */
3975 set_identifier(vpp
, type
, value
)
3976 vchar_t
**vpp
, *value
;
3979 return set_identifier_qual(vpp
, type
, value
, IDQUAL_UNSPEC
);
3983 set_identifier_qual(vpp
, type
, value
, qual
)
3984 vchar_t
**vpp
, *value
;
3988 vchar_t
*new = NULL
;
3990 /* simply return if value is null. */
3992 if( type
== IDTYPE_FQDN
|| type
== IDTYPE_USERFQDN
){
3993 plog(LLV_ERROR
, LOCATION
, NULL
,
3994 "No %s\n", type
== IDTYPE_FQDN
? "fqdn":"user fqdn");
4002 case IDTYPE_USERFQDN
:
4004 plog(LLV_ERROR
, LOCATION
, NULL
,
4005 "Empty %s\n", type
== IDTYPE_FQDN
? "fqdn":"user fqdn");
4008 case IDTYPE_KEYIDUSE
:
4009 #ifdef ENABLE_HYBRID
4012 /* length is adjusted since QUOTEDSTRING teminates NULL. */
4013 new = vmalloc(value
->l
- 1);
4016 memcpy(new->v
, value
->v
, new->l
);
4020 * If no qualifier is specified: IDQUAL_UNSPEC. It means
4021 * to use a file for backward compatibility sake.
4025 case IDQUAL_UNSPEC
: {
4030 fp
= fopen(value
->v
, "r");
4032 plog(LLV_ERROR
, LOCATION
, NULL
,
4033 "can not open %s\n", value
->v
);
4037 while ((len
= fread(b
, 1, sizeof(b
), fp
)) != 0) {
4038 new = vrealloc(new, tlen
+ len
);
4043 memcpy(new->v
+ tlen
, b
, len
);
4051 new = vmalloc(value
->l
- 1);
4053 plog(LLV_ERROR
, LOCATION
, NULL
,
4054 "can not allocate memory");
4057 memcpy(new->v
, value
->v
, new->l
);
4061 plog(LLV_ERROR
, LOCATION
, NULL
,
4062 "unknown qualifier");
4067 case IDTYPE_ADDRESS
: {
4068 struct sockaddr
*sa
;
4070 /* length is adjusted since QUOTEDSTRING teminates NULL. */
4074 sa
= str2saddr(value
->v
, NULL
);
4076 plog(LLV_ERROR
, LOCATION
, NULL
,
4077 "invalid ip address %s\n", value
->v
);
4081 new = vmalloc(sysdep_sa_len(sa
));
4086 memcpy(new->v
, sa
, new->l
);
4092 if (value
->v
[0] == '~')
4093 /* Hex-encoded ASN1 strings */
4094 new = eay_hex2asn1dn(value
->v
+ 1, - 1);
4096 /* DN encoded strings */
4097 new = eay_str2asn1dn(value
->v
, value
->l
- 1);
4102 if (loglevel
>= LLV_DEBUG
) {
4105 unsigned char *ptr
= (unsigned char *) new->v
, *buf
;
4109 xn
= d2i_X509_NAME(NULL
, (void *)&ptr
, new->l
);
4110 bio
= BIO_new(BIO_s_mem());
4112 X509_NAME_print_ex(bio
, xn
, 0, 0);
4113 len
= BIO_get_mem_data(bio
, &ptr
);
4116 plog(LLV_DEBUG
, LOCATION
, NULL
, "Parsed DN: %s\n", ptr
);
4122 plog(LLV_DEBUG
, LOCATION
, NULL
, "Setting ID type ASN1DN from string not supported\n");
4135 * create ID payload for phase 2, and set into iph2->id and id_p. There are
4136 * NOT INCLUDING isakmp general header.
4137 * this function is for initiator. responder will get to copy from payload.
4138 * responder ID type is always address type.
4139 * see, RFC2407 4.6.2.1
4142 ipsecdoi_setid2(iph2
)
4143 struct ph2handle
*iph2
;
4145 struct secpolicy
*sp
;
4147 /* check there is phase 2 handler ? */
4148 sp
= getspbyspid(iph2
->spid
);
4150 plog(LLV_ERROR
, LOCATION
, NULL
,
4151 "no policy found for spid:%u.\n", iph2
->spid
);
4155 iph2
->id
= ipsecdoi_sockaddr2id((struct sockaddr
*)&sp
->spidx
.src
,
4156 sp
->spidx
.prefs
, sp
->spidx
.ul_proto
);
4157 if (iph2
->id
== NULL
) {
4158 plog(LLV_ERROR
, LOCATION
, NULL
,
4159 "failed to get ID for %s\n",
4160 spidx2str(&sp
->spidx
));
4163 if ((((struct ipsecdoi_id_b
*)iph2
->id
->v
)->type
== IPSECDOI_ID_IPV4_ADDR
||
4164 ((struct ipsecdoi_id_b
*)iph2
->id
->v
)->type
== IPSECDOI_ID_IPV4_ADDR_SUBNET
) &&
4165 iph2
->side
== RESPONDER
&&
4166 iph2
->ph1
&& (iph2
->ph1
->natt_flags
& NAT_DETECTED_ME
) &&
4167 lcconf
->ext_nat_id
) {
4169 if (!(iph2
->id
= vdup(lcconf
->ext_nat_id
))) {
4173 plog(LLV_DEBUG
, LOCATION
, NULL
, "use local ID type %s\n",
4174 s_ipsecdoi_ident(((struct ipsecdoi_id_b
*)iph2
->id
->v
)->type
));
4175 plogdump(LLV_DEBUG
, iph2
->id
->v
, iph2
->id
->l
);
4178 iph2
->id_p
= ipsecdoi_sockaddr2id((struct sockaddr
*)&sp
->spidx
.dst
,
4179 sp
->spidx
.prefd
, sp
->spidx
.ul_proto
);
4180 if (iph2
->id_p
== NULL
) {
4181 plog(LLV_ERROR
, LOCATION
, NULL
,
4182 "failed to get ID for %s\n",
4183 spidx2str(&sp
->spidx
));
4187 plog(LLV_DEBUG
, LOCATION
, NULL
,
4188 "use remote ID type %s\n",
4189 s_ipsecdoi_ident(((struct ipsecdoi_id_b
*)iph2
->id_p
->v
)->type
));
4190 plogdump(LLV_DEBUG
, iph2
->id
->v
, iph2
->id
->l
);
4196 * set address type of ID.
4197 * NOT INCLUDING general header.
4200 ipsecdoi_sockaddr2id(saddr
, prefixlen
, ul_proto
)
4201 struct sockaddr
*saddr
;
4206 int type
, len1
, len2
;
4211 * Q. When type is SUBNET, is it allowed to be ::1/128.
4212 * A. Yes. (consensus at bake-off)
4214 switch (saddr
->sa_family
) {
4216 len1
= sizeof(struct in_addr
);
4217 if (prefixlen
== (sizeof(struct in_addr
) << 3)) {
4218 type
= IPSECDOI_ID_IPV4_ADDR
;
4221 type
= IPSECDOI_ID_IPV4_ADDR_SUBNET
;
4222 len2
= sizeof(struct in_addr
);
4224 sa
= (caddr_t
)&((struct sockaddr_in
*)(saddr
))->sin_addr
;
4225 port
= ((struct sockaddr_in
*)(saddr
))->sin_port
;
4229 len1
= sizeof(struct in6_addr
);
4230 if (prefixlen
== (sizeof(struct in6_addr
) << 3)) {
4231 type
= IPSECDOI_ID_IPV6_ADDR
;
4234 type
= IPSECDOI_ID_IPV6_ADDR_SUBNET
;
4235 len2
= sizeof(struct in6_addr
);
4237 sa
= (caddr_t
)&((struct sockaddr_in6
*)(saddr
))->sin6_addr
;
4238 port
= ((struct sockaddr_in6
*)(saddr
))->sin6_port
;
4242 plog(LLV_ERROR
, LOCATION
, NULL
,
4243 "invalid family: %d.\n", saddr
->sa_family
);
4248 new = vmalloc(sizeof(struct ipsecdoi_id_b
) + len1
+ len2
);
4250 plog(LLV_ERROR
, LOCATION
, NULL
,
4251 "failed to get ID buffer.\n");
4255 memset(new->v
, 0, new->l
);
4257 /* set the part of header. */
4258 ((struct ipsecdoi_id_b
*)new->v
)->type
= type
;
4260 /* set ul_proto and port */
4262 * NOTE: we use both IPSEC_ULPROTO_ANY and IPSEC_PORT_ANY as wild card
4263 * because 0 means port number of 0. Instead of 0, we use IPSEC_*_ANY.
4265 ((struct ipsecdoi_id_b
*)new->v
)->proto_id
=
4266 ul_proto
== IPSEC_ULPROTO_ANY
? 0 : ul_proto
;
4267 ((struct ipsecdoi_id_b
*)new->v
)->port
=
4268 port
== IPSEC_PORT_ANY
? 0 : port
;
4269 memcpy(new->v
+ sizeof(struct ipsecdoi_id_b
), sa
, len1
);
4275 u_char
*p
= (unsigned char *) new->v
+
4276 sizeof(struct ipsecdoi_id_b
) + len1
;
4277 u_int bits
= prefixlen
;
4285 *p
= ~((1 << (8 - bits
)) - 1);
4292 ipsecdoi_sockrange2id(laddr
, haddr
, ul_proto
)
4293 struct sockaddr
*laddr
, *haddr
;
4297 int type
, len1
, len2
;
4300 if (laddr
->sa_family
!= haddr
->sa_family
) {
4301 plog(LLV_ERROR
, LOCATION
, NULL
, "Address family mismatch\n");
4305 switch (laddr
->sa_family
) {
4307 type
= IPSECDOI_ID_IPV4_ADDR_RANGE
;
4308 len1
= sizeof(struct in_addr
);
4309 len2
= sizeof(struct in_addr
);
4313 type
= IPSECDOI_ID_IPV6_ADDR_RANGE
;
4314 len1
= sizeof(struct in6_addr
);
4315 len2
= sizeof(struct in6_addr
);
4319 plog(LLV_ERROR
, LOCATION
, NULL
,
4320 "invalid family: %d.\n", laddr
->sa_family
);
4325 new = vmalloc(sizeof(struct ipsecdoi_id_b
) + len1
+ len2
);
4327 plog(LLV_ERROR
, LOCATION
, NULL
,
4328 "failed to get ID buffer.\n");
4332 memset(new->v
, 0, new->l
);
4333 /* set the part of header. */
4334 ((struct ipsecdoi_id_b
*)new->v
)->type
= type
;
4336 /* set ul_proto and port */
4338 * NOTE: we use both IPSEC_ULPROTO_ANY and IPSEC_PORT_ANY as wild card
4339 * because 0 means port number of 0. Instead of 0, we use IPSEC_*_ANY.
4341 ((struct ipsecdoi_id_b
*)new->v
)->proto_id
=
4342 ul_proto
== IPSEC_ULPROTO_ANY
? 0 : ul_proto
;
4343 port
= ((struct sockaddr_in
*)(laddr
))->sin_port
;
4344 ((struct ipsecdoi_id_b
*)new->v
)->port
=
4345 port
== IPSEC_PORT_ANY
? 0 : port
;
4346 memcpy(new->v
+ sizeof(struct ipsecdoi_id_b
),
4347 (caddr_t
)&((struct sockaddr_in
*)(laddr
))->sin_addr
,
4349 memcpy(new->v
+ sizeof(struct ipsecdoi_id_b
) + len1
,
4350 (caddr_t
)&((struct sockaddr_in
*)haddr
)->sin_addr
,
4357 * create sockaddr structure from ID payload (buf).
4358 * buffers (saddr, prefixlen, ul_proto) must be allocated.
4359 * see, RFC2407 4.6.2.1
4362 ipsecdoi_id2sockaddr(buf
, saddr
, prefixlen
, ul_proto
)
4364 struct sockaddr
*saddr
;
4365 u_int8_t
*prefixlen
;
4366 u_int16_t
*ul_proto
;
4368 struct ipsecdoi_id_b
*id_b
= (struct ipsecdoi_id_b
*)buf
->v
;
4372 * When a ID payload of subnet type with a IP address of full bit
4373 * masked, it has to be processed as host address.
4374 * e.g. below 2 type are same.
4375 * type = ipv6 subnet, data = 2001::1/128
4376 * type = ipv6 address, data = 2001::1
4378 switch (id_b
->type
) {
4379 case IPSECDOI_ID_IPV4_ADDR
:
4380 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
4381 saddr
->sa_len
= sizeof(struct sockaddr_in
);
4382 saddr
->sa_family
= AF_INET
;
4383 ((struct sockaddr_in
*)saddr
)->sin_port
=
4386 : id_b
->port
); /* see sockaddr2id() */
4387 memcpy(&((struct sockaddr_in
*)saddr
)->sin_addr
,
4388 buf
->v
+ sizeof(*id_b
), sizeof(struct in_addr
));
4391 case IPSECDOI_ID_IPV6_ADDR
:
4392 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
4393 saddr
->sa_len
= sizeof(struct sockaddr_in6
);
4394 saddr
->sa_family
= AF_INET6
;
4395 ((struct sockaddr_in6
*)saddr
)->sin6_port
=
4398 : id_b
->port
); /* see sockaddr2id() */
4399 memcpy(&((struct sockaddr_in6
*)saddr
)->sin6_addr
,
4400 buf
->v
+ sizeof(*id_b
), sizeof(struct in6_addr
));
4404 plog(LLV_ERROR
, LOCATION
, NULL
,
4405 "unsupported ID type %d\n", id_b
->type
);
4406 return ISAKMP_NTYPE_INVALID_ID_INFORMATION
;
4409 /* get prefix length */
4410 switch (id_b
->type
) {
4411 case IPSECDOI_ID_IPV4_ADDR
:
4412 plen
= sizeof(struct in_addr
) << 3;
4415 case IPSECDOI_ID_IPV6_ADDR
:
4416 plen
= sizeof(struct in6_addr
) << 3;
4419 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
4421 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
4426 int alen
= sizeof(struct in_addr
);
4428 switch (id_b
->type
) {
4429 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
4430 alen
= sizeof(struct in_addr
);
4433 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
4434 alen
= sizeof(struct in6_addr
);
4441 return ISAKMP_INTERNAL_ERROR
;
4443 /* get subnet mask length */
4447 p
= (unsigned char *) buf
->v
4448 + sizeof(struct ipsecdoi_id_b
)
4451 for (; *p
== 0xff; p
++) {
4474 *ul_proto
= id_b
->proto_id
== 0
4476 : id_b
->proto_id
; /* see sockaddr2id() */
4482 * make printable string from ID payload except of general header.
4492 static char buf
[BUFLEN
];
4493 struct ipsecdoi_id_b
*id_b
= (struct ipsecdoi_id_b
*)id
->v
;
4494 struct sockaddr_storage saddr
;
4497 bzero(&saddr
, sizeof(saddr
));
4499 switch (id_b
->type
) {
4500 case IPSECDOI_ID_IPV4_ADDR
:
4501 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
4502 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
4504 ((struct sockaddr
*)&saddr
)->sa_len
= sizeof(struct sockaddr_in
);
4505 ((struct sockaddr
*)&saddr
)->sa_family
= AF_INET
;
4506 ((struct sockaddr_in
*)&saddr
)->sin_port
= IPSEC_PORT_ANY
;
4507 memcpy(&((struct sockaddr_in
*)&saddr
)->sin_addr
,
4508 id
->v
+ sizeof(*id_b
), sizeof(struct in_addr
));
4511 case IPSECDOI_ID_IPV6_ADDR
:
4512 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
4513 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
4514 ((struct sockaddr
*)&saddr
)->sa_len
= sizeof(struct sockaddr_in6
);
4515 ((struct sockaddr
*)&saddr
)->sa_family
= AF_INET6
;
4516 ((struct sockaddr_in6
*)&saddr
)->sin6_port
= IPSEC_PORT_ANY
;
4517 memcpy(&((struct sockaddr_in6
*)&saddr
)->sin6_addr
,
4518 id
->v
+ sizeof(*id_b
), sizeof(struct in6_addr
));
4519 ((struct sockaddr_in6
*)&saddr
)->sin6_scope_id
=
4520 (IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6
*)&saddr
)->sin6_addr
)
4521 ? ((struct sockaddr_in6
*)id_b
)->sin6_scope_id
4527 switch (id_b
->type
) {
4528 case IPSECDOI_ID_IPV4_ADDR
:
4530 case IPSECDOI_ID_IPV6_ADDR
:
4532 len
= snprintf( buf
, sizeof(buf
), "%s", saddrwop2str((struct sockaddr
*)&saddr
));
4535 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
4537 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
4542 int alen
= sizeof(struct in_addr
);
4544 switch (id_b
->type
) {
4545 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
4546 alen
= sizeof(struct in_addr
);
4549 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
4550 alen
= sizeof(struct in6_addr
);
4561 /* get subnet mask length */
4565 p
= (unsigned char *) id
->v
4566 + sizeof(struct ipsecdoi_id_b
)
4569 for (; *p
== 0xff; p
++) {
4588 len
= snprintf( buf
, sizeof(buf
), "%s/%i", saddrwop2str((struct sockaddr
*)&saddr
), plen
);
4592 case IPSECDOI_ID_IPV4_ADDR_RANGE
:
4594 len
= snprintf( buf
, sizeof(buf
), "%s-", saddrwop2str((struct sockaddr
*)&saddr
));
4596 ((struct sockaddr
*)&saddr
)->sa_len
= sizeof(struct sockaddr_in
);
4597 ((struct sockaddr
*)&saddr
)->sa_family
= AF_INET
;
4598 ((struct sockaddr_in
*)&saddr
)->sin_port
= IPSEC_PORT_ANY
;
4599 memcpy(&((struct sockaddr_in
*)&saddr
)->sin_addr
,
4600 id
->v
+ sizeof(*id_b
) + sizeof(struct in_addr
),
4601 sizeof(struct in_addr
));
4604 len
+= snprintf( buf
+ len
, sizeof(buf
) - len
, "%s", saddrwop2str((struct sockaddr
*)&saddr
));
4610 case IPSECDOI_ID_IPV6_ADDR_RANGE
:
4612 len
= snprintf( buf
, sizeof(buf
), "%s-", saddrwop2str((struct sockaddr
*)&saddr
));
4614 ((struct sockaddr
*)&saddr
)->sa_len
= sizeof(struct sockaddr_in6
);
4615 ((struct sockaddr
*)&saddr
)->sa_family
= AF_INET6
;
4616 ((struct sockaddr_in6
*)&saddr
)->sin6_port
= IPSEC_PORT_ANY
;
4617 memcpy(&((struct sockaddr_in6
*)&saddr
)->sin6_addr
,
4618 id
->v
+ sizeof(*id_b
) + sizeof(struct in6_addr
),
4619 sizeof(struct in6_addr
));
4620 ((struct sockaddr_in6
*)&saddr
)->sin6_scope_id
=
4621 (IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6
*)&saddr
)->sin6_addr
)
4622 ? ((struct sockaddr_in6
*)id_b
)->sin6_scope_id
4626 len
+= snprintf( buf
+ len
, sizeof(buf
) - len
, "%s", saddrwop2str((struct sockaddr
*)&saddr
));
4632 case IPSECDOI_ID_FQDN
:
4633 case IPSECDOI_ID_USER_FQDN
:
4634 len
= id
->l
- sizeof(*id_b
);
4637 memcpy(buf
, id
->v
+ sizeof(*id_b
), len
);
4640 case IPSECDOI_ID_DER_ASN1_DN
:
4641 case IPSECDOI_ID_DER_ASN1_GN
:
4644 X509_NAME
*xn
= NULL
;
4647 dat
= id
->v
+ sizeof(*id_b
);
4648 len
= id
->l
- sizeof(*id_b
);
4650 if (d2i_X509_NAME(&xn
, (void*) &dat
, len
) != NULL
) {
4651 BIO
*bio
= BIO_new(BIO_s_mem());
4652 X509_NAME_print_ex(bio
, xn
, 0, 0);
4653 len
= BIO_get_mem_data(bio
, &dat
);
4656 memcpy(buf
,dat
,len
);
4663 plog(LLV_ERROR
, LOCATION
, NULL
,
4664 "unable to extract asn1dn from id\n");
4666 len
= snprintf(buf
, sizeof(buf
), "<ASN1-DN>");
4672 /* currently unhandled id types */
4673 case IPSECDOI_ID_KEY_ID
:
4674 len
= snprintf( buf
, sizeof(buf
), "<KEY-ID>");
4678 plog(LLV_ERROR
, LOCATION
, NULL
,
4679 "unknown ID type %d\n", id_b
->type
);
4683 len
= snprintf( buf
, sizeof(buf
), "<?>");
4685 ret
= racoon_malloc(len
+1);
4687 memcpy(ret
,buf
,len
);
4695 * set IPsec data attributes into a proposal.
4696 * NOTE: MUST called per a transform.
4699 ipsecdoi_t2satrns(t
, pp
, pr
, tr
)
4700 struct isakmp_pl_t
*t
;
4705 struct isakmp_data
*d
, *prev
;
4711 tr
->trns_no
= t
->t_no
;
4712 tr
->trns_id
= t
->t_id
;
4714 tlen
= ntohs(t
->h
.len
) - sizeof(*t
);
4715 prev
= (struct isakmp_data
*)NULL
;
4716 d
= (struct isakmp_data
*)(t
+ 1);
4719 life_t
= IPSECDOI_ATTR_SA_LD_TYPE_DEFAULT
;
4720 pp
->lifetime
= IPSECDOI_ATTR_SA_LD_SEC_DEFAULT
;
4722 tr
->authtype
= IPSECDOI_ATTR_AUTH_NONE
;
4726 type
= ntohs(d
->type
) & ~ISAKMP_GEN_MASK
;
4727 flag
= ntohs(d
->type
) & ISAKMP_GEN_MASK
;
4729 plog(LLV_DEBUG
, LOCATION
, NULL
,
4730 "type=%s, flag=0x%04x, lorv=%s\n",
4731 s_ipsecdoi_attr(type
), flag
,
4732 s_ipsecdoi_attr_v(type
, ntohs(d
->lorv
)));
4735 case IPSECDOI_ATTR_SA_LD_TYPE
:
4737 int type
= ntohs(d
->lorv
);
4739 case IPSECDOI_ATTR_SA_LD_TYPE_SEC
:
4740 case IPSECDOI_ATTR_SA_LD_TYPE_KB
:
4744 plog(LLV_WARNING
, LOCATION
, NULL
,
4745 "invalid life duration type. "
4747 life_t
= IPSECDOI_ATTR_SA_LD_TYPE_DEFAULT
;
4752 case IPSECDOI_ATTR_SA_LD
:
4754 || (ntohs(prev
->type
) & ~ISAKMP_GEN_MASK
) !=
4755 IPSECDOI_ATTR_SA_LD_TYPE
) {
4756 plog(LLV_ERROR
, LOCATION
, NULL
,
4757 "life duration must follow ltype\n");
4763 vchar_t
*ld_buf
= NULL
;
4766 /* i.e. ISAKMP_GEN_TV */
4767 ld_buf
= vmalloc(sizeof(d
->lorv
));
4768 if (ld_buf
== NULL
) {
4769 plog(LLV_ERROR
, LOCATION
, NULL
,
4770 "failed to get LD buffer.\n");
4773 memcpy(ld_buf
->v
, &d
->lorv
, sizeof(d
->lorv
));
4775 int len
= ntohs(d
->lorv
);
4776 /* i.e. ISAKMP_GEN_TLV */
4777 ld_buf
= vmalloc(len
);
4778 if (ld_buf
== NULL
) {
4779 plog(LLV_ERROR
, LOCATION
, NULL
,
4780 "failed to get LD buffer.\n");
4783 memcpy(ld_buf
->v
, d
+ 1, len
);
4786 case IPSECDOI_ATTR_SA_LD_TYPE_SEC
:
4787 t
= ipsecdoi_set_ld(ld_buf
);
4790 plog(LLV_ERROR
, LOCATION
, NULL
,
4791 "invalid life duration.\n");
4794 /* lifetime must be equal in a proposal. */
4795 if (pp
->lifetime
== IPSECDOI_ATTR_SA_LD_SEC_DEFAULT
)
4797 else if (pp
->lifetime
!= t
) {
4798 plog(LLV_ERROR
, LOCATION
, NULL
,
4799 "lifetime mismatched "
4801 "prev:%ld curr:%u.\n",
4802 (long)pp
->lifetime
, t
);
4806 case IPSECDOI_ATTR_SA_LD_TYPE_KB
:
4807 t
= ipsecdoi_set_ld(ld_buf
);
4810 plog(LLV_ERROR
, LOCATION
, NULL
,
4811 "invalid life duration.\n");
4814 /* lifebyte must be equal in a proposal. */
4815 if (pp
->lifebyte
== 0)
4817 else if (pp
->lifebyte
!= t
) {
4818 plog(LLV_ERROR
, LOCATION
, NULL
,
4819 "lifebyte mismatched "
4821 "prev:%d curr:%u.\n",
4828 plog(LLV_ERROR
, LOCATION
, NULL
,
4829 "invalid life type: %d\n", life_t
);
4835 case IPSECDOI_ATTR_GRP_DESC
:
4837 * RFC2407: 4.5 IPSEC Security Association Attributes
4838 * Specifies the Oakley Group to be used in a PFS QM
4839 * negotiation. For a list of supported values, see
4840 * Appendix A of [IKE].
4842 if (pp
->pfs_group
== 0)
4843 pp
->pfs_group
= (u_int16_t
)ntohs(d
->lorv
);
4844 else if (pp
->pfs_group
!= (u_int16_t
)ntohs(d
->lorv
)) {
4845 plog(LLV_ERROR
, LOCATION
, NULL
,
4846 "pfs_group mismatched "
4847 "in a proposal.\n");
4852 case IPSECDOI_ATTR_ENC_MODE
:
4854 pr
->encmode
!= (u_int16_t
)ntohs(d
->lorv
)) {
4855 plog(LLV_ERROR
, LOCATION
, NULL
,
4856 "multiple encmode exist "
4857 "in a transform.\n");
4860 pr
->encmode
= (u_int16_t
)ntohs(d
->lorv
);
4863 case IPSECDOI_ATTR_AUTH
:
4864 if (tr
->authtype
!= IPSECDOI_ATTR_AUTH_NONE
) {
4865 plog(LLV_ERROR
, LOCATION
, NULL
,
4866 "multiple authtype exist "
4867 "in a transform.\n");
4870 tr
->authtype
= (u_int16_t
)ntohs(d
->lorv
);
4873 case IPSECDOI_ATTR_KEY_LENGTH
:
4874 if (pr
->proto_id
!= IPSECDOI_PROTO_IPSEC_ESP
) {
4875 plog(LLV_ERROR
, LOCATION
, NULL
,
4876 "key length defined but not ESP");
4879 tr
->encklen
= ntohs(d
->lorv
);
4882 case IPSECDOI_ATTR_KEY_ROUNDS
:
4883 case IPSECDOI_ATTR_COMP_DICT_SIZE
:
4884 case IPSECDOI_ATTR_COMP_PRIVALG
:
4892 d
= (struct isakmp_data
*)((char *)d
+ sizeof(*d
));
4894 tlen
-= (sizeof(*d
) + ntohs(d
->lorv
));
4895 d
= (struct isakmp_data
*)((caddr_t
)d
+ sizeof(*d
) + ntohs(d
->lorv
));
4905 ipsecdoi_authalg2trnsid(alg
)
4909 case IPSECDOI_ATTR_AUTH_HMAC_MD5
:
4910 return IPSECDOI_AH_MD5
;
4911 case IPSECDOI_ATTR_AUTH_HMAC_SHA1
:
4912 return IPSECDOI_AH_SHA
;
4913 case IPSECDOI_ATTR_AUTH_HMAC_SHA2_256
:
4914 return IPSECDOI_AH_SHA256
;
4915 case IPSECDOI_ATTR_AUTH_HMAC_SHA2_384
:
4916 return IPSECDOI_AH_SHA384
;
4917 case IPSECDOI_ATTR_AUTH_HMAC_SHA2_512
:
4918 return IPSECDOI_AH_SHA512
;
4919 case IPSECDOI_ATTR_AUTH_DES_MAC
:
4920 return IPSECDOI_AH_DES
;
4921 case IPSECDOI_ATTR_AUTH_KPDK
:
4922 return IPSECDOI_AH_MD5
; /* XXX */
4924 plog(LLV_ERROR
, LOCATION
, NULL
,
4925 "invalid authentication algorithm:%d\n", alg
);
4932 fixup_initiator_sa(match
, received
)
4933 struct isakmpsa
*match
, *received
;
4935 if (received
->gssid
!= NULL
)
4936 match
->gssid
= vdup(received
->gssid
);
4942 static int rm_idtype2doi
[] = {
4943 255, /* IDTYPE_UNDEFINED, 0 */
4944 IPSECDOI_ID_FQDN
, /* IDTYPE_FQDN, 1 */
4945 IPSECDOI_ID_USER_FQDN
, /* IDTYPE_USERFQDN, 2 */
4946 IPSECDOI_ID_KEY_ID
, /* IDTYPE_KEYID, 3 */
4947 255, /* IDTYPE_ADDRESS, 4
4948 * it expands into 4 types by another function. */
4949 IPSECDOI_ID_DER_ASN1_DN
, /* IDTYPE_ASN1DN, 5 */
4953 * convert idtype to DOI value.
4961 if (ARRAYLEN(rm_idtype2doi
) > idtype
)
4962 return rm_idtype2doi
[idtype
];
4971 case IPSECDOI_ID_FQDN
:
4972 return(IDTYPE_FQDN
);
4973 case IPSECDOI_ID_USER_FQDN
:
4974 return(IDTYPE_USERFQDN
);
4975 case IPSECDOI_ID_KEY_ID
:
4976 return(IDTYPE_KEYID
);
4977 case IPSECDOI_ID_DER_ASN1_DN
:
4978 return(IDTYPE_ASN1DN
);
4979 case IPSECDOI_ID_IPV4_ADDR
:
4980 case IPSECDOI_ID_IPV4_ADDR_SUBNET
:
4981 case IPSECDOI_ID_IPV6_ADDR
:
4982 case IPSECDOI_ID_IPV6_ADDR_SUBNET
:
4983 return(IDTYPE_ADDRESS
);
4985 plog(LLV_WARNING
, LOCATION
, NULL
,
4986 "Inproper idtype:%s in this function.\n",
4987 s_ipsecdoi_ident(doi
));
4988 return(IDTYPE_ADDRESS
); /* XXX */
4993 #ifdef ENABLE_HYBRID
4995 switch_authmethod(authmethod
)
4998 switch(authmethod
) {
4999 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
:
5000 authmethod
= OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
;
5002 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R
:
5003 authmethod
= OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I
;
5005 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
:
5006 authmethod
= OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_I
;
5008 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
:
5009 authmethod
= OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
;
5011 /* Those are not implemented */
5012 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_R
:
5013 authmethod
= OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_I
;
5015 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_R
:
5016 authmethod
= OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
;
5018 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_R
:
5019 authmethod
= OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
;