1 /* $KAME: isakmp_ident.c,v 1.63 2001/12/12 17:57:26 sakane Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 /* Identity Protecion Exchange (Main Mode) */
34 #include <sys/types.h>
35 #include <sys/param.h>
41 #include <netinet/in.h>
42 #if TIME_WITH_SYS_TIME
43 # include <sys/time.h>
47 # include <sys/time.h>
61 #include "localconf.h"
62 #include "remoteconf.h"
63 #include "isakmp_var.h"
67 #include "ipsec_doi.h"
68 #include "crypto_openssl.h"
70 #include "isakmp_ident.h"
71 #include "isakmp_inf.h"
72 #include "isakmp_natd.h"
79 static vchar_t
*ident_ir2mx
__P((struct ph1handle
*));
80 static vchar_t
*ident_ir3mx
__P((struct ph1handle
*));
83 * begin Identity Protection Mode as initiator.
93 ident_i1send(iph1
, msg
)
94 struct ph1handle
*iph1
;
95 vchar_t
*msg
; /* must be null */
97 struct isakmp_gen
*gen
;
101 vchar_t
*vid_natt_rfc
= NULL
;
102 vchar_t
*vid_natt_apple
= NULL
;
103 vchar_t
*vid_natt_02
= NULL
;
104 vchar_t
*vid_natt_02N
= NULL
;
108 plog(LLV_ERROR
, LOCATION
, NULL
,
109 "msg has to be NULL in this function.\n");
112 if (iph1
->status
!= PHASE1ST_START
) {
113 plog(LLV_ERROR
, LOCATION
, NULL
,
114 "status mismatched %d.\n", iph1
->status
);
118 /* create isakmp index */
119 memset(&iph1
->index
, 0, sizeof(iph1
->index
));
120 isakmp_newcookie((caddr_t
)&iph1
->index
, iph1
->remote
, iph1
->local
);
122 /* create SA payload for my proposal */
123 iph1
->sa
= ipsecdoi_setph1proposal(iph1
->rmconf
->proposal
);
124 if (iph1
->sa
== NULL
)
127 /* create buffer to send isakmp payload */
128 tlen
= sizeof(struct isakmp
)
129 + sizeof(*gen
) + iph1
->sa
->l
;
132 vid_natt_rfc
= set_vendorid(VENDORID_NATT_RFC
);
133 vid_natt_apple
= set_vendorid(VENDORID_NATT_APPLE
);
134 vid_natt_02
= set_vendorid(VENDORID_NATT_02
);
135 vid_natt_02N
= set_vendorid(VENDORID_NATT_02N
);
137 if (vid_natt_rfc
== NULL
||
138 vid_natt_apple
== NULL
||
139 vid_natt_02
== NULL
||
140 vid_natt_02N
== NULL
) {
141 plog(LLV_ERROR
, LOCATION
, NULL
,
142 "failed to get vendor ID buffer.\n");
145 tlen
+= sizeof(*gen
) + vid_natt_rfc
->l
;
146 tlen
+= sizeof(*gen
) + vid_natt_apple
->l
;
147 tlen
+= sizeof(*gen
) + vid_natt_02
->l
;
148 tlen
+= sizeof(*gen
) + vid_natt_02N
->l
;
151 iph1
->sendbuf
= vmalloc(tlen
);
152 if (iph1
->sendbuf
== NULL
) {
153 plog(LLV_ERROR
, LOCATION
, NULL
,
154 "failed to get buffer to send.\n");
158 /* set isakmp header */
159 p
= set_isakmp_header(iph1
->sendbuf
, iph1
, ISAKMP_NPTYPE_SA
);
163 /* set SA payload to propose */
164 p
= set_isakmp_payload(p
, iph1
->sa
, vid_natt_rfc
? ISAKMP_NPTYPE_VID
: ISAKMP_NPTYPE_NONE
);
167 p
= set_isakmp_payload(p
, vid_natt_rfc
, ISAKMP_NPTYPE_VID
);
168 p
= set_isakmp_payload(p
, vid_natt_apple
, ISAKMP_NPTYPE_VID
);
169 p
= set_isakmp_payload(p
, vid_natt_02
, ISAKMP_NPTYPE_VID
);
170 p
= set_isakmp_payload(p
, vid_natt_02N
, ISAKMP_NPTYPE_NONE
);
173 #ifdef HAVE_PRINT_ISAKMP_C
174 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
177 /* send the packet, add to the schedule to resend */
178 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
179 if (isakmp_ph1resend(iph1
) == -1)
182 iph1
->status
= PHASE1ST_MSG1SENT
;
190 vfree(vid_natt_apple
);
200 * receive from responder
207 ident_i2recv(iph1
, msg
)
208 struct ph1handle
*iph1
;
211 vchar_t
*pbuf
= NULL
;
212 struct isakmp_parse_t
*pa
;
213 vchar_t
*satmp
= NULL
;
217 if (iph1
->status
!= PHASE1ST_MSG1SENT
) {
218 plog(LLV_ERROR
, LOCATION
, NULL
,
219 "status mismatched %d.\n", iph1
->status
);
223 /* validate the type of next payload */
225 * NOTE: RedCreek(as responder) attaches N[responder-lifetime] here,
226 * if proposal-lifetime > lifetime-redcreek-wants.
228 * => According to the seciton 4.6.3 in RFC 2407, This is illegal.
229 * NOTE: we do not really care about ordering of VID and N.
231 * NOTE: even if there's multiple VID/N, we'll ignore them.
233 pbuf
= isakmp_parse(msg
);
236 pa
= (struct isakmp_parse_t
*)pbuf
->v
;
238 /* SA payload is fixed postion */
239 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
240 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
241 "received invalid next payload type %d, "
243 pa
->type
, ISAKMP_NPTYPE_SA
);
246 if (isakmp_p2ph(&satmp
, pa
->ptr
) < 0)
251 pa
->type
!= ISAKMP_NPTYPE_NONE
;
255 case ISAKMP_NPTYPE_VID
:
258 int vid
= check_vendorid(pa
->ptr
);
259 if (vid
== VENDORID_NATT_RFC
)
260 iph1
->natt_flags
|= natt_type_rfc
;
261 else if (vid
== VENDORID_NATT_APPLE
)
262 iph1
->natt_flags
|= natt_type_apple
;
263 else if (vid
== VENDORID_NATT_02
)
264 iph1
->natt_flags
|= natt_type_02
;
265 else if (vid
== VENDORID_NATT_02N
)
266 iph1
->natt_flags
|= natt_type_02N
;
271 /* don't send information, see ident_r1recv() */
272 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
273 "ignore the packet, "
274 "received unexpecting payload type %d.\n",
280 /* if natt vid(s) received - select type to use */
281 natt_select_type(iph1
);
283 /* check SA payload and set approval SA for use */
284 if (ipsecdoi_checkph1proposal(satmp
, iph1
) < 0) {
285 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
286 "failed to get valid proposal.\n");
287 /* XXX send information */
295 iph1
->status
= PHASE1ST_MSG2RECEIVED
;
311 * gssapi: HDR, KE, Ni, GSSi
312 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
313 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
314 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
317 ident_i2send(iph1
, msg
)
318 struct ph1handle
*iph1
;
324 if (iph1
->status
!= PHASE1ST_MSG2RECEIVED
) {
325 plog(LLV_ERROR
, LOCATION
, NULL
,
326 "status mismatched %d.\n", iph1
->status
);
330 /* fix isakmp index */
331 memcpy(&iph1
->index
.r_ck
, &((struct isakmp
*)msg
->v
)->r_ck
,
334 /* generate DH public value */
335 if (oakley_dh_generate(iph1
->approval
->dhgrp
,
336 &iph1
->dhpub
, &iph1
->dhpriv
) < 0)
339 /* generate NONCE value */
340 iph1
->nonce
= eay_set_random(iph1
->rmconf
->nonce_size
);
341 if (iph1
->nonce
== NULL
)
345 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
346 gssapi_get_itoken(iph1
, NULL
) < 0)
350 /* create buffer to send isakmp payload */
351 iph1
->sendbuf
= ident_ir2mx(iph1
);
352 if (iph1
->sendbuf
== NULL
)
355 #ifdef HAVE_PRINT_ISAKMP_C
356 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
359 /* send the packet, add to the schedule to resend */
360 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
361 if (isakmp_ph1resend(iph1
) == -1)
364 /* the sending message is added to the received-list. */
365 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
) == -1) {
366 plog(LLV_ERROR
, LOCATION
, NULL
,
367 "failed to add a response packet to the tree.\n");
371 iph1
->status
= PHASE1ST_MSG2SENT
;
380 * receive from responder
382 * sig: HDR, KE, Nr [, CR ]
383 * gssapi: HDR, KE, Nr, GSSr
384 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
385 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
388 ident_i3recv(iph1
, msg
)
389 struct ph1handle
*iph1
;
392 vchar_t
*pbuf
= NULL
;
393 struct isakmp_parse_t
*pa
;
396 vchar_t
*gsstoken
= NULL
;
400 if (iph1
->status
!= PHASE1ST_MSG2SENT
) {
401 plog(LLV_ERROR
, LOCATION
, NULL
,
402 "status mismatched %d.\n", iph1
->status
);
406 /* validate the type of next payload */
407 pbuf
= isakmp_parse(msg
);
411 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
412 pa
->type
!= ISAKMP_NPTYPE_NONE
;
416 case ISAKMP_NPTYPE_KE
:
417 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0)
420 case ISAKMP_NPTYPE_NONCE
:
421 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0)
424 case ISAKMP_NPTYPE_VID
:
425 (void)check_vendorid(pa
->ptr
);
427 #ifdef HAVE_SIGNING_C
428 case ISAKMP_NPTYPE_CR
:
429 if (oakley_savecr(iph1
, pa
->ptr
) < 0)
434 case ISAKMP_NPTYPE_GSS
:
435 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0)
437 gssapi_save_received_token(iph1
, gsstoken
);
440 case ISAKMP_NPTYPE_NATD_RFC
:
441 case ISAKMP_NPTYPE_NATD_DRAFT
:
442 case ISAKMP_NPTYPE_NATD_BADDRAFT
:
447 if (pa
->type
!= iph1
->natd_payload_type
) {
448 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
449 "ignore the packet, "
450 "received unexpected natd payload type %d.\n",
454 match
= natd_matches(iph1
, pa
->ptr
);
455 iph1
->natt_flags
|= natt_natd_received
;
456 if ((match
& natd_match_local
) != 0)
457 iph1
->natt_flags
|= natt_no_local_nat
;
458 if ((match
& natd_match_remote
) != 0)
459 iph1
->natt_flags
|= natt_no_remote_nat
;
464 /* don't send information, see ident_r1recv() */
465 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
466 "ignore the packet, "
467 "received unexpecting payload type %d.\n",
474 /* Determine if we need to switch to port 4500 */
475 if (natd_hasnat(iph1
))
477 /* There is a NAT between us! Switch to port 4500. */
478 if (iph1
->remote
->sa_family
== AF_INET
)
480 struct sockaddr_in
*sin
= (struct sockaddr_in
*)iph1
->remote
;
481 plog(LLV_INFO
, LOCATION
, NULL
,
482 "detected NAT, switching to port %d for %s",
483 PORT_ISAKMP_NATT
, saddr2str(iph1
->remote
));
484 sin
->sin_port
= htons(PORT_ISAKMP_NATT
);
485 sin
= (struct sockaddr_in
*)iph1
->local
;
486 sin
->sin_port
= htons(PORT_ISAKMP_NATT
);
491 /* payload existency check */
492 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
493 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
494 "few isakmp message received.\n");
498 #ifdef HAVE_SIGNING_C
499 if (oakley_checkcr(iph1
) < 0) {
500 /* Ignore this error in order to be interoperability. */
505 iph1
->status
= PHASE1ST_MSG3RECEIVED
;
513 VPTRINIT(iph1
->dhpub_p
);
514 VPTRINIT(iph1
->nonce_p
);
515 VPTRINIT(iph1
->id_p
);
516 oakley_delcert(iph1
->cr_p
);
525 * psk: HDR*, IDi1, HASH_I
526 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
527 * gssapi: HDR*, IDi1, < Gssi(n) | HASH_I >
532 ident_i3send(iph1
, msg0
)
533 struct ph1handle
*iph1
;
543 if (iph1
->status
!= PHASE1ST_MSG3RECEIVED
) {
544 plog(LLV_ERROR
, LOCATION
, NULL
,
545 "status mismatched %d.\n", iph1
->status
);
549 /* compute sharing secret of DH */
550 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub
,
551 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0)
554 /* generate SKEYIDs & IV & final cipher key */
555 if (oakley_skeyid(iph1
) < 0)
557 if (oakley_skeyid_dae(iph1
) < 0)
559 if (oakley_compute_enckey(iph1
) < 0)
561 if (oakley_newiv(iph1
) < 0)
564 /* make ID payload into isakmp status */
565 if (ipsecdoi_setid1(iph1
) < 0)
569 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
570 gssapi_more_tokens(iph1
)) {
571 plog(LLV_DEBUG
, LOCATION
, NULL
, "calling get_itoken\n");
572 if (gssapi_get_itoken(iph1
, &len
) < 0)
579 /* generate HASH to send */
581 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
582 if (iph1
->hash
== NULL
)
587 /* set encryption flag */
588 iph1
->flags
|= ISAKMP_FLAG_E
;
590 /* create HDR;ID;HASH payload */
591 iph1
->sendbuf
= ident_ir3mx(iph1
);
592 if (iph1
->sendbuf
== NULL
)
595 /* send the packet, add to the schedule to resend */
596 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
597 if (isakmp_ph1resend(iph1
) == -1)
600 /* the sending message is added to the received-list. */
601 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg0
) == -1) {
602 plog(LLV_ERROR
, LOCATION
, NULL
,
603 "failed to add a response packet to the tree.\n");
607 /* see handler.h about IV synchronization. */
608 memcpy(iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->v
, iph1
->ivm
->iv
->l
);
610 iph1
->status
= PHASE1ST_MSG3SENT
;
619 * receive from responder
620 * psk: HDR*, IDr1, HASH_R
621 * sig: HDR*, IDr1, [ CERT, ] SIG_R
622 * gssapi: HDR*, IDr1, < GSSr(n) | HASH_R >
627 ident_i4recv(iph1
, msg0
)
628 struct ph1handle
*iph1
;
631 vchar_t
*pbuf
= NULL
;
632 struct isakmp_parse_t
*pa
;
637 vchar_t
*gsstoken
= NULL
;
641 if (iph1
->status
!= PHASE1ST_MSG3SENT
) {
642 plog(LLV_ERROR
, LOCATION
, NULL
,
643 "status mismatched %d.\n", iph1
->status
);
648 if (!ISSET(((struct isakmp
*)msg0
->v
)->flags
, ISAKMP_FLAG_E
)) {
649 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
650 "ignore the packet, "
651 "expecting the packet encrypted.\n");
654 msg
= oakley_do_decrypt(iph1
, msg0
, iph1
->ivm
->iv
, iph1
->ivm
->ive
);
658 /* validate the type of next payload */
659 pbuf
= isakmp_parse(msg
);
663 iph1
->pl_hash
= NULL
;
665 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
666 pa
->type
!= ISAKMP_NPTYPE_NONE
;
670 case ISAKMP_NPTYPE_ID
:
671 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0)
674 case ISAKMP_NPTYPE_HASH
:
675 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
677 #ifdef HAVE_SIGNING_C
678 case ISAKMP_NPTYPE_CERT
:
679 if (oakley_savecert(iph1
, pa
->ptr
) < 0)
682 case ISAKMP_NPTYPE_SIG
:
683 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0)
688 case ISAKMP_NPTYPE_GSS
:
689 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0)
691 gssapi_save_received_token(iph1
, gsstoken
);
694 case ISAKMP_NPTYPE_VID
:
695 (void)check_vendorid(pa
->ptr
);
697 case ISAKMP_NPTYPE_N
:
698 isakmp_check_notify(pa
->ptr
, iph1
);
701 /* don't send information, see ident_r1recv() */
702 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
703 "ignore the packet, "
704 "received unexpecting payload type %d.\n",
710 /* payload existency check */
712 /* see handler.h about IV synchronization. */
713 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->ive
->l
);
715 /* verify identifier */
716 if (ipsecdoi_checkid1(iph1
) != 0) {
717 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
718 "invalid ID payload.\n");
722 /* validate authentication value */
724 if (gsstoken
== NULL
) {
726 type
= oakley_validate_auth(iph1
);
729 /* msg printed inner oakley_validate_auth() */
732 isakmp_info_send_n1(iph1
, type
, NULL
);
740 * XXX: Should we do compare two addresses, ph1handle's and ID
744 plog(LLV_DEBUG
, LOCATION
, iph1
->remote
, "peer's ID:");
745 plogdump(LLV_DEBUG
, iph1
->id_p
->v
, iph1
->id_p
->l
);
748 * If we got a GSS token, we need to this roundtrip again.
751 iph1
->status
= gsstoken
!= 0 ? PHASE1ST_MSG3RECEIVED
:
752 PHASE1ST_MSG4RECEIVED
;
754 iph1
->status
= PHASE1ST_MSG4RECEIVED
;
770 VPTRINIT(iph1
->id_p
);
771 oakley_delcert(iph1
->cert_p
);
773 oakley_delcert(iph1
->crl_p
);
775 VPTRINIT(iph1
->sig_p
);
782 * status update and establish isakmp sa.
785 ident_i4send(iph1
, msg
)
786 struct ph1handle
*iph1
;
792 if (iph1
->status
!= PHASE1ST_MSG4RECEIVED
) {
793 plog(LLV_ERROR
, LOCATION
, NULL
,
794 "status mismatched %d.\n", iph1
->status
);
798 /* see handler.h about IV synchronization. */
799 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->l
);
801 iph1
->status
= PHASE1ST_ESTABLISHED
;
810 * receive from initiator
817 ident_r1recv(iph1
, msg
)
818 struct ph1handle
*iph1
;
821 vchar_t
*pbuf
= NULL
;
822 struct isakmp_parse_t
*pa
;
826 if (iph1
->status
!= PHASE1ST_START
) {
827 plog(LLV_ERROR
, LOCATION
, NULL
,
828 "status mismatched %d.\n", iph1
->status
);
832 /* validate the type of next payload */
834 * NOTE: XXX even if multiple VID, we'll silently ignore those.
836 pbuf
= isakmp_parse(msg
);
839 pa
= (struct isakmp_parse_t
*)pbuf
->v
;
841 /* check the position of SA payload */
842 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
843 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
844 "received invalid next payload type %d, "
846 pa
->type
, ISAKMP_NPTYPE_SA
);
849 if (isakmp_p2ph(&iph1
->sa
, pa
->ptr
) < 0)
854 pa
->type
!= ISAKMP_NPTYPE_NONE
;
858 case ISAKMP_NPTYPE_VID
:
860 int vid
= check_vendorid(pa
->ptr
);
862 if (vid
== VENDORID_NATT_RFC
)
863 iph1
->natt_flags
|= natt_type_rfc
;
864 else if (vid
== VENDORID_NATT_APPLE
)
865 iph1
->natt_flags
|= natt_type_apple
;
866 else if (vid
== VENDORID_NATT_02
)
867 iph1
->natt_flags
|= natt_type_02
;
869 iph1
->natt_flags
|= natt_type_02N
;
875 * We don't send information to the peer even
876 * if we received malformed packet. Because we
877 * can't distinguish the malformed packet and
878 * the re-sent packet. And we do same behavior
879 * when we expect encrypted packet.
881 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
882 "ignore the packet, "
883 "received unexpecting payload type %d.\n",
889 /* if natt vid(s) received - select type to use */
890 natt_select_type(iph1
);
892 /* check SA payload and set approval SA for use */
893 if (ipsecdoi_checkph1proposal(iph1
->sa
, iph1
) < 0) {
894 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
895 "failed to get valid proposal.\n");
896 /* XXX send information */
900 iph1
->status
= PHASE1ST_MSG1RECEIVED
;
922 ident_r1send(iph1
, msg
)
923 struct ph1handle
*iph1
;
926 struct isakmp_gen
*gen
;
930 vchar_t
*gss_sa
= NULL
;
933 vchar_t
*nattvid
= NULL
;
937 if (iph1
->status
!= PHASE1ST_MSG1RECEIVED
) {
938 plog(LLV_ERROR
, LOCATION
, NULL
,
939 "status mismatched %d.\n", iph1
->status
);
943 /* set responder's cookie */
944 isakmp_newcookie((caddr_t
)&iph1
->index
.r_ck
, iph1
->remote
, iph1
->local
);
947 if (iph1
->approval
->gssid
!= NULL
)
948 gss_sa
= ipsecdoi_setph1proposal(iph1
->approval
);
951 gss_sa
= iph1
->sa_ret
;
953 /* create buffer to send isakmp payload */
954 tlen
= sizeof(struct isakmp
)
955 + sizeof(*gen
) + gss_sa
->l
;
957 if ((vid
= set_vendorid(iph1
->approval
->vendorid
)) != NULL
)
958 tlen
+= sizeof(*gen
) + vid
->l
;
962 int natt_type
= iph1
->natt_flags
& NATT_TYPE_MASK
;
964 if (natt_type
!= 0) {
965 if (natt_type
== natt_type_rfc
)
966 nattvid
= set_vendorid(VENDORID_NATT_RFC
);
967 else if (natt_type
== natt_type_apple
)
968 nattvid
= set_vendorid(VENDORID_NATT_APPLE
);
969 else if (natt_type
== natt_type_02
)
970 nattvid
= set_vendorid(VENDORID_NATT_02
);
971 else if (natt_type
== natt_type_02N
)
972 nattvid
= set_vendorid(VENDORID_NATT_02N
);
975 tlen
+= sizeof(*gen
) + nattvid
->l
;
980 iph1
->sendbuf
= vmalloc(tlen
);
981 if (iph1
->sendbuf
== NULL
) {
982 plog(LLV_ERROR
, LOCATION
, NULL
,
983 "failed to get buffer to send.\n");
987 /* set isakmp header */
988 p
= set_isakmp_header(iph1
->sendbuf
, iph1
, ISAKMP_NPTYPE_SA
);
992 /* set SA payload to reply */
993 p
= set_isakmp_payload(p
, gss_sa
,
994 (vid
|| nattvid
) ? ISAKMP_NPTYPE_VID
995 : ISAKMP_NPTYPE_NONE
);
997 /* Set Vendor ID, if necessary. */
999 p
= set_isakmp_payload(p
, vid
, nattvid
? ISAKMP_NPTYPE_VID
: ISAKMP_NPTYPE_NONE
);
1002 p
= set_isakmp_payload(p
, nattvid
, ISAKMP_NPTYPE_NONE
);
1004 #ifdef HAVE_PRINT_ISAKMP_C
1005 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
1008 /* send the packet, add to the schedule to resend */
1009 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
1010 if (isakmp_ph1resend(iph1
) == -1)
1013 /* the sending message is added to the received-list. */
1014 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
) == -1) {
1015 plog(LLV_ERROR
, LOCATION
, NULL
,
1016 "failed to add a response packet to the tree.\n");
1020 iph1
->status
= PHASE1ST_MSG1SENT
;
1026 if (gss_sa
!= iph1
->sa_ret
)
1037 * receive from initiator
1040 * gssapi: HDR, KE, Ni, GSSi
1041 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
1042 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
1043 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
1046 ident_r2recv(iph1
, msg
)
1047 struct ph1handle
*iph1
;
1050 vchar_t
*pbuf
= NULL
;
1051 struct isakmp_parse_t
*pa
;
1054 vchar_t
*gsstoken
= NULL
;
1057 /* validity check */
1058 if (iph1
->status
!= PHASE1ST_MSG1SENT
) {
1059 plog(LLV_ERROR
, LOCATION
, NULL
,
1060 "status mismatched %d.\n", iph1
->status
);
1064 /* validate the type of next payload */
1065 pbuf
= isakmp_parse(msg
);
1069 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
1070 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1074 case ISAKMP_NPTYPE_KE
:
1075 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0)
1078 case ISAKMP_NPTYPE_NONCE
:
1079 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0)
1082 case ISAKMP_NPTYPE_VID
:
1083 (void)check_vendorid(pa
->ptr
);
1085 case ISAKMP_NPTYPE_CR
:
1086 plog(LLV_WARNING
, LOCATION
, iph1
->remote
,
1087 "CR received, ignore it. "
1088 "It should be in other exchange.\n");
1091 case ISAKMP_NPTYPE_GSS
:
1092 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0)
1094 gssapi_save_received_token(iph1
, gsstoken
);
1097 case ISAKMP_NPTYPE_NATD_RFC
:
1098 case ISAKMP_NPTYPE_NATD_DRAFT
:
1099 case ISAKMP_NPTYPE_NATD_BADDRAFT
:
1104 if (pa
->type
!= iph1
->natd_payload_type
) {
1105 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1106 "ignore the packet, "
1107 "received unexpected natd payload type %d.\n",
1111 match
= natd_matches(iph1
, pa
->ptr
);
1112 iph1
->natt_flags
|= natt_natd_received
;
1113 if ((match
& natd_match_local
) != 0)
1114 iph1
->natt_flags
|= natt_no_local_nat
;
1115 if ((match
& natd_match_remote
) != 0)
1116 iph1
->natt_flags
|= natt_no_remote_nat
;
1121 /* don't send information, see ident_r1recv() */
1122 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1123 "ignore the packet, "
1124 "received unexpecting payload type %d.\n",
1130 /* payload existency check */
1131 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
1132 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1133 "few isakmp message received.\n");
1137 iph1
->status
= PHASE1ST_MSG2RECEIVED
;
1150 VPTRINIT(iph1
->dhpub_p
);
1151 VPTRINIT(iph1
->nonce_p
);
1152 VPTRINIT(iph1
->id_p
);
1161 * sig: HDR, KE, Nr [, CR ]
1162 * gssapi: HDR, KE, Nr, GSSr
1163 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
1164 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
1167 ident_r2send(iph1
, msg
)
1168 struct ph1handle
*iph1
;
1173 /* validity check */
1174 if (iph1
->status
!= PHASE1ST_MSG2RECEIVED
) {
1175 plog(LLV_ERROR
, LOCATION
, NULL
,
1176 "status mismatched %d.\n", iph1
->status
);
1180 /* generate DH public value */
1181 if (oakley_dh_generate(iph1
->approval
->dhgrp
,
1182 &iph1
->dhpub
, &iph1
->dhpriv
) < 0)
1185 /* generate NONCE value */
1186 iph1
->nonce
= eay_set_random(iph1
->rmconf
->nonce_size
);
1187 if (iph1
->nonce
== NULL
)
1191 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
1192 gssapi_get_rtoken(iph1
, NULL
);
1195 /* create HDR;KE;NONCE payload */
1196 iph1
->sendbuf
= ident_ir2mx(iph1
);
1197 if (iph1
->sendbuf
== NULL
)
1200 #ifdef HAVE_PRINT_ISAKMP_C
1201 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
1204 /* send the packet, add to the schedule to resend */
1205 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
1206 if (isakmp_ph1resend(iph1
) == -1)
1209 /* the sending message is added to the received-list. */
1210 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
) == -1) {
1211 plog(LLV_ERROR
, LOCATION
, NULL
,
1212 "failed to add a response packet to the tree.\n");
1216 /* compute sharing secret of DH */
1217 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub
,
1218 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0)
1221 /* generate SKEYIDs & IV & final cipher key */
1222 if (oakley_skeyid(iph1
) < 0)
1224 if (oakley_skeyid_dae(iph1
) < 0)
1226 if (oakley_compute_enckey(iph1
) < 0)
1228 if (oakley_newiv(iph1
) < 0)
1231 iph1
->status
= PHASE1ST_MSG2SENT
;
1240 * receive from initiator
1241 * psk: HDR*, IDi1, HASH_I
1242 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
1243 * gssapi: HDR*, [ IDi1, ] < GSSi(n) | HASH_I >
1248 ident_r3recv(iph1
, msg0
)
1249 struct ph1handle
*iph1
;
1252 vchar_t
*msg
= NULL
;
1253 vchar_t
*pbuf
= NULL
;
1254 struct isakmp_parse_t
*pa
;
1258 vchar_t
*gsstoken
= NULL
;
1261 /* validity check */
1262 if (iph1
->status
!= PHASE1ST_MSG2SENT
) {
1263 plog(LLV_ERROR
, LOCATION
, NULL
,
1264 "status mismatched %d.\n", iph1
->status
);
1269 if (!ISSET(((struct isakmp
*)msg0
->v
)->flags
, ISAKMP_FLAG_E
)) {
1270 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1271 "reject the packet, "
1272 "expecting the packet encrypted.\n");
1275 msg
= oakley_do_decrypt(iph1
, msg0
, iph1
->ivm
->iv
, iph1
->ivm
->ive
);
1279 /* validate the type of next payload */
1280 pbuf
= isakmp_parse(msg
);
1284 iph1
->pl_hash
= NULL
;
1286 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
1287 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1291 case ISAKMP_NPTYPE_ID
:
1292 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0)
1295 case ISAKMP_NPTYPE_HASH
:
1296 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
1298 #ifdef HAVE_SIGNING_C
1299 case ISAKMP_NPTYPE_CR
:
1300 if (oakley_savecr(iph1
, pa
->ptr
) < 0)
1303 case ISAKMP_NPTYPE_CERT
:
1304 if (oakley_savecert(iph1
, pa
->ptr
) < 0)
1307 case ISAKMP_NPTYPE_SIG
:
1308 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0)
1313 case ISAKMP_NPTYPE_GSS
:
1314 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0)
1316 gssapi_save_received_token(iph1
, gsstoken
);
1319 case ISAKMP_NPTYPE_VID
:
1320 (void)check_vendorid(pa
->ptr
);
1322 case ISAKMP_NPTYPE_N
:
1323 isakmp_check_notify(pa
->ptr
, iph1
);
1326 /* don't send information, see ident_r1recv() */
1327 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1328 "ignore the packet, "
1329 "received unexpecting payload type %d.\n",
1335 /* payload existency check */
1336 /* XXX same as ident_i4recv(), should be merged. */
1340 switch (iph1
->approval
->authmethod
) {
1341 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
1342 if (iph1
->id_p
== NULL
|| iph1
->pl_hash
== NULL
)
1345 case OAKLEY_ATTR_AUTH_METHOD_DSSSIG
:
1346 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
1347 if (iph1
->id_p
== NULL
|| iph1
->sig_p
== NULL
)
1350 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
1351 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
1352 if (iph1
->pl_hash
== NULL
)
1356 case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
:
1357 if (gsstoken
== NULL
&& iph1
->pl_hash
== NULL
)
1362 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1363 "invalid authmethod %d why ?\n",
1364 iph1
->approval
->authmethod
);
1368 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1369 "few isakmp message received.\n");
1374 /* see handler.h about IV synchronization. */
1375 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->ive
->l
);
1377 /* verify identifier */
1378 if (ipsecdoi_checkid1(iph1
) != 0) {
1379 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1380 "invalid ID payload.\n");
1384 /* validate authentication value */
1386 if (gsstoken
== NULL
) {
1388 type
= oakley_validate_auth(iph1
);
1391 /* msg printed inner oakley_validate_auth() */
1394 isakmp_info_send_n1(iph1
, type
, NULL
);
1401 #ifdef HAVE_SIGNING_C
1402 if (oakley_checkcr(iph1
) < 0) {
1403 /* Ignore this error in order to be interoperability. */
1409 * XXX: Should we do compare two addresses, ph1handle's and ID
1413 plog(LLV_DEBUG
, LOCATION
, iph1
->remote
, "peer's ID\n");
1414 plogdump(LLV_DEBUG
, iph1
->id_p
->v
, iph1
->id_p
->l
);
1417 iph1
->status
= gsstoken
!= NULL
? PHASE1ST_MSG2RECEIVED
:
1418 PHASE1ST_MSG3RECEIVED
;
1420 iph1
->status
= PHASE1ST_MSG3RECEIVED
;
1436 VPTRINIT(iph1
->id_p
);
1437 oakley_delcert(iph1
->cert_p
);
1438 iph1
->cert_p
= NULL
;
1439 oakley_delcert(iph1
->crl_p
);
1441 VPTRINIT(iph1
->sig_p
);
1442 oakley_delcert(iph1
->cr_p
);
1451 * psk: HDR*, IDr1, HASH_R
1452 * sig: HDR*, IDr1, [ CERT, ] SIG_R
1453 * gssapi: HDR*, IDr1, < GSSr(n) | HASH_R >
1458 ident_r3send(iph1
, msg
)
1459 struct ph1handle
*iph1
;
1468 /* validity check */
1469 if (iph1
->status
!= PHASE1ST_MSG3RECEIVED
) {
1470 plog(LLV_ERROR
, LOCATION
, NULL
,
1471 "status mismatched %d.\n", iph1
->status
);
1475 /* make ID payload into isakmp status */
1476 if (ipsecdoi_setid1(iph1
) < 0)
1480 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
1481 gssapi_more_tokens(iph1
)) {
1482 gssapi_get_rtoken(iph1
, &len
);
1489 /* generate HASH to send */
1490 plog(LLV_DEBUG
, LOCATION
, NULL
, "generate HASH_R\n");
1491 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
1492 if (iph1
->hash
== NULL
)
1497 /* set encryption flag */
1498 iph1
->flags
|= ISAKMP_FLAG_E
;
1500 /* create HDR;ID;HASH payload */
1501 iph1
->sendbuf
= ident_ir3mx(iph1
);
1502 if (iph1
->sendbuf
== NULL
)
1505 /* send HDR;ID;HASH to responder */
1506 if (isakmp_send(iph1
, iph1
->sendbuf
) < 0)
1509 /* the sending message is added to the received-list. */
1510 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
) == -1) {
1511 plog(LLV_ERROR
, LOCATION
, NULL
,
1512 "failed to add a response packet to the tree.\n");
1516 /* see handler.h about IV synchronization. */
1517 memcpy(iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->v
, iph1
->ivm
->iv
->l
);
1519 iph1
->status
= PHASE1ST_ESTABLISHED
;
1529 * This is used in main mode for:
1530 * initiator's 3rd exchange send to responder
1533 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
1534 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
1535 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
1536 * responders 2nd exchnage send to initiator
1538 * sig: HDR, KE, Nr [, CR ]
1539 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
1540 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
1544 struct ph1handle
*iph1
;
1547 struct isakmp_gen
*gen
;
1552 vchar_t
*vid
= NULL
;
1556 vchar_t
*gsstoken
= NULL
;
1560 #ifdef HAVE_SIGNING_C
1561 /* create CR if need */
1562 if (iph1
->side
== RESPONDER
1563 && iph1
->rmconf
->send_cr
1564 && oakley_needcr(iph1
->approval
->authmethod
)
1565 && iph1
->rmconf
->peerscertfile
== NULL
) {
1567 cr
= oakley_getcr(iph1
);
1569 plog(LLV_ERROR
, LOCATION
, NULL
,
1570 "failed to get cr buffer.\n");
1577 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
1578 gssapi_get_token_to_send(iph1
, &gsstoken
);
1582 tlen
= sizeof(struct isakmp
)
1583 + sizeof(*gen
) + iph1
->dhpub
->l
1584 + sizeof(*gen
) + iph1
->nonce
->l
;
1585 if ((vid
= set_vendorid(iph1
->approval
->vendorid
)) != NULL
)
1586 tlen
+= sizeof(*gen
) + vid
->l
;
1588 tlen
+= sizeof(*gen
) + cr
->l
;
1591 tlen
+= sizeof(*gen
) + gsstoken
->l
;
1595 if ((iph1
->natt_flags
& NATT_TYPE_MASK
) != 0) {
1596 natd_type
= iph1
->natd_payload_type
;
1598 if (iph1
->local_natd
)
1599 tlen
+= sizeof(*gen
) + iph1
->local_natd
->l
;
1600 if (iph1
->remote_natd
)
1601 tlen
+= sizeof(*gen
) + iph1
->remote_natd
->l
;
1605 buf
= vmalloc(tlen
);
1607 plog(LLV_ERROR
, LOCATION
, NULL
,
1608 "failed to get buffer to send.\n");
1612 /* set isakmp header */
1613 p
= set_isakmp_header(buf
, iph1
, ISAKMP_NPTYPE_KE
);
1617 /* create isakmp KE payload */
1618 p
= set_isakmp_payload(p
, iph1
->dhpub
, ISAKMP_NPTYPE_NONCE
);
1620 /* create isakmp NONCE payload */
1622 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
1623 nptype
= ISAKMP_NPTYPE_GSS
;
1626 nptype
= vid
? ISAKMP_NPTYPE_VID
:
1627 (need_cr
? ISAKMP_NPTYPE_CR
:
1628 (natd_type
? natd_type
: ISAKMP_NPTYPE_NONE
));
1629 p
= set_isakmp_payload(p
, iph1
->nonce
, nptype
);
1632 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
) {
1633 p
= set_isakmp_payload(p
, gsstoken
,
1634 vid
? ISAKMP_NPTYPE_VID
1635 : (need_cr
? ISAKMP_NPTYPE_CR
1636 : (natd_type
? natd_type
: ISAKMP_NPTYPE_NONE
)));
1640 /* append vendor id, if needed */
1642 p
= set_isakmp_payload(p
, vid
,
1643 need_cr
? ISAKMP_NPTYPE_CR
1644 : (natd_type
? natd_type
: ISAKMP_NPTYPE_NONE
));
1646 /* create isakmp CR payload if needed */
1648 p
= set_isakmp_payload(p
, cr
, natd_type
? natd_type
: ISAKMP_NPTYPE_NONE
);
1652 if ((iph1
->natt_flags
& NATT_TYPE_MASK
) == natt_type_apple
) {
1653 if (iph1
->local_natd
)
1654 p
= set_isakmp_payload(p
, iph1
->local_natd
, natd_type
);
1655 if (iph1
->remote_natd
)
1656 p
= set_isakmp_payload(p
, iph1
->remote_natd
, ISAKMP_NPTYPE_NONE
);
1658 if (iph1
->remote_natd
)
1659 p
= set_isakmp_payload(p
, iph1
->remote_natd
, natd_type
);
1660 if (iph1
->local_natd
)
1661 p
= set_isakmp_payload(p
, iph1
->local_natd
, ISAKMP_NPTYPE_NONE
);
1668 if (error
&& buf
!= NULL
) {
1685 * This is used in main mode for:
1686 * initiator's 4th exchange send to responder
1687 * psk: HDR*, IDi1, HASH_I
1688 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
1689 * gssapi: HDR*, [ IDi1, ] < GSSi(n) | HASH_I >
1692 * responders 3rd exchnage send to initiator
1693 * psk: HDR*, IDr1, HASH_R
1694 * sig: HDR*, IDr1, [ CERT, ] SIG_R
1695 * gssapi: HDR*, [ IDr1, ] < GSSr(n) | HASH_R >
1701 struct ph1handle
*iph1
;
1703 vchar_t
*buf
= NULL
, *new = NULL
;
1706 struct isakmp_gen
*gen
;
1713 vchar_t
*gsstoken
= NULL
;
1714 vchar_t
*gsshash
= NULL
;
1717 tlen
= sizeof(struct isakmp
);
1719 switch (iph1
->approval
->authmethod
) {
1720 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
1721 tlen
+= sizeof(*gen
) + iph1
->id
->l
1722 + sizeof(*gen
) + iph1
->hash
->l
;
1724 buf
= vmalloc(tlen
);
1726 plog(LLV_ERROR
, LOCATION
, NULL
,
1727 "failed to get buffer to send.\n");
1731 /* set isakmp header */
1732 p
= set_isakmp_header(buf
, iph1
, ISAKMP_NPTYPE_ID
);
1736 /* create isakmp ID payload */
1737 p
= set_isakmp_payload(p
, iph1
->id
, ISAKMP_NPTYPE_HASH
);
1739 /* create isakmp HASH payload */
1740 p
= set_isakmp_payload(p
, iph1
->hash
, ISAKMP_NPTYPE_NONE
);
1742 #ifdef HAVE_SIGNING_C
1743 case OAKLEY_ATTR_AUTH_METHOD_DSSSIG
:
1744 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
1745 if (oakley_getmycert(iph1
) < 0)
1748 if (oakley_getsign(iph1
) < 0)
1751 /* create CR if need */
1752 if (iph1
->side
== INITIATOR
1753 && iph1
->rmconf
->send_cr
1754 && oakley_needcr(iph1
->approval
->authmethod
)
1755 && iph1
->rmconf
->peerscertfile
== NULL
) {
1757 cr
= oakley_getcr(iph1
);
1759 plog(LLV_ERROR
, LOCATION
, NULL
,
1760 "failed to get cr buffer.\n");
1765 if (iph1
->cert
!= NULL
&& iph1
->rmconf
->send_cert
)
1768 tlen
+= sizeof(*gen
) + iph1
->id
->l
1769 + sizeof(*gen
) + iph1
->sig
->l
;
1771 tlen
+= sizeof(*gen
) + iph1
->cert
->pl
->l
;
1773 tlen
+= sizeof(*gen
) + cr
->l
;
1775 buf
= vmalloc(tlen
);
1777 plog(LLV_ERROR
, LOCATION
, NULL
,
1778 "failed to get buffer to send.\n");
1782 /* set isakmp header */
1783 p
= set_isakmp_header(buf
, iph1
, ISAKMP_NPTYPE_ID
);
1787 /* add ID payload */
1788 p
= set_isakmp_payload(p
, iph1
->id
, need_cert
1789 ? ISAKMP_NPTYPE_CERT
1790 : ISAKMP_NPTYPE_SIG
);
1792 /* add CERT payload if there */
1794 p
= set_isakmp_payload(p
, iph1
->cert
->pl
, ISAKMP_NPTYPE_SIG
);
1795 /* add SIG payload */
1796 p
= set_isakmp_payload(p
, iph1
->sig
,
1797 need_cr
? ISAKMP_NPTYPE_CR
: ISAKMP_NPTYPE_NONE
);
1799 /* create isakmp CR payload */
1801 p
= set_isakmp_payload(p
, cr
, ISAKMP_NPTYPE_NONE
);
1805 case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
:
1806 if (!gssapi_id_sent(iph1
))
1807 tlen
+= sizeof (*gen
) + iph1
->id
->l
;
1808 if (iph1
->hash
!= NULL
) {
1809 gsshash
= gssapi_wraphash(iph1
);
1810 if (gsshash
== NULL
)
1812 tlen
+= sizeof (*gen
) + gsshash
->l
;
1814 gssapi_get_token_to_send(iph1
, &gsstoken
);
1815 tlen
+= sizeof (*gen
) + gsstoken
->l
;
1818 buf
= vmalloc(tlen
);
1820 plog(LLV_ERROR
, LOCATION
, NULL
,
1821 "failed to get buffer to send.\n");
1825 /* set isakmp header */
1826 if (!gssapi_id_sent(iph1
))
1827 nptype
= ISAKMP_NPTYPE_ID
;
1829 nptype
= iph1
->hash
!= NULL
? ISAKMP_NPTYPE_HASH
:
1831 p
= set_isakmp_header(buf
, iph1
, nptype
);
1835 if (!gssapi_id_sent(iph1
)) {
1836 /* create isakmp ID payload */
1837 nptype
= iph1
->hash
!= NULL
? ISAKMP_NPTYPE_HASH
:
1839 p
= set_isakmp_payload(p
, iph1
->id
, nptype
);
1842 gssapi_set_id_sent(iph1
);
1845 if (iph1
->hash
!= NULL
)
1846 /* create isakmp HASH payload */
1847 p
= set_isakmp_payload(p
, gsshash
,
1848 ISAKMP_NPTYPE_NONE
);
1850 p
= set_isakmp_payload(p
, gsstoken
, ISAKMP_NPTYPE_NONE
);
1853 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
1854 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
1855 plog(LLV_ERROR
, LOCATION
, NULL
,
1856 "not supported authentication type %d\n",
1857 iph1
->approval
->authmethod
);
1860 plog(LLV_ERROR
, LOCATION
, NULL
,
1861 "invalid authentication type %d\n",
1862 iph1
->approval
->authmethod
);
1866 #ifdef HAVE_PRINT_ISAKMP_C
1867 isakmp_printpacket(buf
, iph1
->local
, iph1
->remote
, 1);
1871 new = oakley_do_encrypt(iph1
, buf
, iph1
->ivm
->ive
, iph1
->ivm
->iv
);
1884 if (error
&& buf
!= NULL
) {