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
:
445 if (pa
->type
== iph1
->natd_payload_type
) {
446 natd_match_t match
= natd_matches(iph1
, pa
->ptr
);
447 iph1
->natt_flags
|= natt_natd_received
;
448 if ((match
& natd_match_local
) != 0)
449 iph1
->natt_flags
|= natt_no_local_nat
;
450 if ((match
& natd_match_remote
) != 0)
451 iph1
->natt_flags
|= natt_no_remote_nat
;
456 /* don't send information, see ident_r1recv() */
457 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
458 "ignore the packet, "
459 "received unexpecting payload type %d.\n",
466 /* Determine if we need to switch to port 4500 */
467 if (natd_hasnat(iph1
))
469 /* There is a NAT between us! Switch to port 4500. */
470 if (iph1
->remote
->sa_family
== AF_INET
)
472 struct sockaddr_in
*sin
= (struct sockaddr_in
*)iph1
->remote
;
473 plog(LLV_INFO
, LOCATION
, NULL
,
474 "detected NAT, switching to port %d for %s",
475 PORT_ISAKMP_NATT
, saddr2str(iph1
->remote
));
476 sin
->sin_port
= htons(PORT_ISAKMP_NATT
);
477 sin
= (struct sockaddr_in
*)iph1
->local
;
478 sin
->sin_port
= htons(PORT_ISAKMP_NATT
);
483 /* payload existency check */
484 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
485 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
486 "few isakmp message received.\n");
490 #ifdef HAVE_SIGNING_C
491 if (oakley_checkcr(iph1
) < 0) {
492 /* Ignore this error in order to be interoperability. */
497 iph1
->status
= PHASE1ST_MSG3RECEIVED
;
505 VPTRINIT(iph1
->dhpub_p
);
506 VPTRINIT(iph1
->nonce_p
);
507 VPTRINIT(iph1
->id_p
);
508 oakley_delcert(iph1
->cr_p
);
517 * psk: HDR*, IDi1, HASH_I
518 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
519 * gssapi: HDR*, IDi1, < Gssi(n) | HASH_I >
524 ident_i3send(iph1
, msg0
)
525 struct ph1handle
*iph1
;
535 if (iph1
->status
!= PHASE1ST_MSG3RECEIVED
) {
536 plog(LLV_ERROR
, LOCATION
, NULL
,
537 "status mismatched %d.\n", iph1
->status
);
541 /* compute sharing secret of DH */
542 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub
,
543 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0)
546 /* generate SKEYIDs & IV & final cipher key */
547 if (oakley_skeyid(iph1
) < 0)
549 if (oakley_skeyid_dae(iph1
) < 0)
551 if (oakley_compute_enckey(iph1
) < 0)
553 if (oakley_newiv(iph1
) < 0)
556 /* make ID payload into isakmp status */
557 if (ipsecdoi_setid1(iph1
) < 0)
561 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
562 gssapi_more_tokens(iph1
)) {
563 plog(LLV_DEBUG
, LOCATION
, NULL
, "calling get_itoken\n");
564 if (gssapi_get_itoken(iph1
, &len
) < 0)
571 /* generate HASH to send */
573 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
574 if (iph1
->hash
== NULL
)
579 /* set encryption flag */
580 iph1
->flags
|= ISAKMP_FLAG_E
;
582 /* create HDR;ID;HASH payload */
583 iph1
->sendbuf
= ident_ir3mx(iph1
);
584 if (iph1
->sendbuf
== NULL
)
587 /* send the packet, add to the schedule to resend */
588 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
589 if (isakmp_ph1resend(iph1
) == -1)
592 /* the sending message is added to the received-list. */
593 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg0
) == -1) {
594 plog(LLV_ERROR
, LOCATION
, NULL
,
595 "failed to add a response packet to the tree.\n");
599 /* see handler.h about IV synchronization. */
600 memcpy(iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->v
, iph1
->ivm
->iv
->l
);
602 iph1
->status
= PHASE1ST_MSG3SENT
;
611 * receive from responder
612 * psk: HDR*, IDr1, HASH_R
613 * sig: HDR*, IDr1, [ CERT, ] SIG_R
614 * gssapi: HDR*, IDr1, < GSSr(n) | HASH_R >
619 ident_i4recv(iph1
, msg0
)
620 struct ph1handle
*iph1
;
623 vchar_t
*pbuf
= NULL
;
624 struct isakmp_parse_t
*pa
;
629 vchar_t
*gsstoken
= NULL
;
633 if (iph1
->status
!= PHASE1ST_MSG3SENT
) {
634 plog(LLV_ERROR
, LOCATION
, NULL
,
635 "status mismatched %d.\n", iph1
->status
);
640 if (!ISSET(((struct isakmp
*)msg0
->v
)->flags
, ISAKMP_FLAG_E
)) {
641 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
642 "ignore the packet, "
643 "expecting the packet encrypted.\n");
646 msg
= oakley_do_decrypt(iph1
, msg0
, iph1
->ivm
->iv
, iph1
->ivm
->ive
);
650 /* validate the type of next payload */
651 pbuf
= isakmp_parse(msg
);
655 iph1
->pl_hash
= NULL
;
657 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
658 pa
->type
!= ISAKMP_NPTYPE_NONE
;
662 case ISAKMP_NPTYPE_ID
:
663 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0)
666 case ISAKMP_NPTYPE_HASH
:
667 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
669 #ifdef HAVE_SIGNING_C
670 case ISAKMP_NPTYPE_CERT
:
671 if (oakley_savecert(iph1
, pa
->ptr
) < 0)
674 case ISAKMP_NPTYPE_SIG
:
675 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0)
680 case ISAKMP_NPTYPE_GSS
:
681 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0)
683 gssapi_save_received_token(iph1
, gsstoken
);
686 case ISAKMP_NPTYPE_VID
:
687 (void)check_vendorid(pa
->ptr
);
689 case ISAKMP_NPTYPE_N
:
690 isakmp_check_notify(pa
->ptr
, iph1
);
693 /* don't send information, see ident_r1recv() */
694 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
695 "ignore the packet, "
696 "received unexpecting payload type %d.\n",
702 /* payload existency check */
704 /* see handler.h about IV synchronization. */
705 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->ive
->l
);
707 /* verify identifier */
708 if (ipsecdoi_checkid1(iph1
) != 0) {
709 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
710 "invalid ID payload.\n");
714 /* validate authentication value */
716 if (gsstoken
== NULL
) {
718 type
= oakley_validate_auth(iph1
);
721 /* msg printed inner oakley_validate_auth() */
724 isakmp_info_send_n1(iph1
, type
, NULL
);
732 * XXX: Should we do compare two addresses, ph1handle's and ID
736 plog(LLV_DEBUG
, LOCATION
, iph1
->remote
, "peer's ID:");
737 plogdump(LLV_DEBUG
, iph1
->id_p
->v
, iph1
->id_p
->l
);
740 * If we got a GSS token, we need to this roundtrip again.
743 iph1
->status
= gsstoken
!= 0 ? PHASE1ST_MSG3RECEIVED
:
744 PHASE1ST_MSG4RECEIVED
;
746 iph1
->status
= PHASE1ST_MSG4RECEIVED
;
762 VPTRINIT(iph1
->id_p
);
763 oakley_delcert(iph1
->cert_p
);
765 oakley_delcert(iph1
->crl_p
);
767 VPTRINIT(iph1
->sig_p
);
774 * status update and establish isakmp sa.
777 ident_i4send(iph1
, msg
)
778 struct ph1handle
*iph1
;
784 if (iph1
->status
!= PHASE1ST_MSG4RECEIVED
) {
785 plog(LLV_ERROR
, LOCATION
, NULL
,
786 "status mismatched %d.\n", iph1
->status
);
790 /* see handler.h about IV synchronization. */
791 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->l
);
793 iph1
->status
= PHASE1ST_ESTABLISHED
;
802 * receive from initiator
809 ident_r1recv(iph1
, msg
)
810 struct ph1handle
*iph1
;
813 vchar_t
*pbuf
= NULL
;
814 struct isakmp_parse_t
*pa
;
818 if (iph1
->status
!= PHASE1ST_START
) {
819 plog(LLV_ERROR
, LOCATION
, NULL
,
820 "status mismatched %d.\n", iph1
->status
);
824 /* validate the type of next payload */
826 * NOTE: XXX even if multiple VID, we'll silently ignore those.
828 pbuf
= isakmp_parse(msg
);
831 pa
= (struct isakmp_parse_t
*)pbuf
->v
;
833 /* check the position of SA payload */
834 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
835 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
836 "received invalid next payload type %d, "
838 pa
->type
, ISAKMP_NPTYPE_SA
);
841 if (isakmp_p2ph(&iph1
->sa
, pa
->ptr
) < 0)
846 pa
->type
!= ISAKMP_NPTYPE_NONE
;
850 case ISAKMP_NPTYPE_VID
:
852 int vid
= check_vendorid(pa
->ptr
);
854 if (vid
== VENDORID_NATT_RFC
)
855 iph1
->natt_flags
|= natt_type_rfc
;
856 else if (vid
== VENDORID_NATT_APPLE
)
857 iph1
->natt_flags
|= natt_type_apple
;
858 else if (vid
== VENDORID_NATT_02
)
859 iph1
->natt_flags
|= natt_type_02
;
861 iph1
->natt_flags
|= natt_type_02N
;
867 * We don't send information to the peer even
868 * if we received malformed packet. Because we
869 * can't distinguish the malformed packet and
870 * the re-sent packet. And we do same behavior
871 * when we expect encrypted packet.
873 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
874 "ignore the packet, "
875 "received unexpecting payload type %d.\n",
881 /* if natt vid(s) received - select type to use */
882 natt_select_type(iph1
);
884 /* check SA payload and set approval SA for use */
885 if (ipsecdoi_checkph1proposal(iph1
->sa
, iph1
) < 0) {
886 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
887 "failed to get valid proposal.\n");
888 /* XXX send information */
892 iph1
->status
= PHASE1ST_MSG1RECEIVED
;
914 ident_r1send(iph1
, msg
)
915 struct ph1handle
*iph1
;
918 struct isakmp_gen
*gen
;
922 vchar_t
*gss_sa
= NULL
;
925 vchar_t
*nattvid
= NULL
;
929 if (iph1
->status
!= PHASE1ST_MSG1RECEIVED
) {
930 plog(LLV_ERROR
, LOCATION
, NULL
,
931 "status mismatched %d.\n", iph1
->status
);
935 /* set responder's cookie */
936 isakmp_newcookie((caddr_t
)&iph1
->index
.r_ck
, iph1
->remote
, iph1
->local
);
939 if (iph1
->approval
->gssid
!= NULL
)
940 gss_sa
= ipsecdoi_setph1proposal(iph1
->approval
);
943 gss_sa
= iph1
->sa_ret
;
945 /* create buffer to send isakmp payload */
946 tlen
= sizeof(struct isakmp
)
947 + sizeof(*gen
) + gss_sa
->l
;
949 if ((vid
= set_vendorid(iph1
->approval
->vendorid
)) != NULL
)
950 tlen
+= sizeof(*gen
) + vid
->l
;
954 int natt_type
= iph1
->natt_flags
& NATT_TYPE_MASK
;
956 if (natt_type
!= 0) {
957 if (natt_type
== natt_type_rfc
)
958 nattvid
= set_vendorid(VENDORID_NATT_RFC
);
959 else if (natt_type
== natt_type_apple
)
960 nattvid
= set_vendorid(VENDORID_NATT_APPLE
);
961 else if (natt_type
== natt_type_02
)
962 nattvid
= set_vendorid(VENDORID_NATT_02
);
963 else if (natt_type
== natt_type_02N
)
964 nattvid
= set_vendorid(VENDORID_NATT_02N
);
967 tlen
+= sizeof(*gen
) + nattvid
->l
;
972 iph1
->sendbuf
= vmalloc(tlen
);
973 if (iph1
->sendbuf
== NULL
) {
974 plog(LLV_ERROR
, LOCATION
, NULL
,
975 "failed to get buffer to send.\n");
979 /* set isakmp header */
980 p
= set_isakmp_header(iph1
->sendbuf
, iph1
, ISAKMP_NPTYPE_SA
);
984 /* set SA payload to reply */
985 p
= set_isakmp_payload(p
, gss_sa
,
986 (vid
|| nattvid
) ? ISAKMP_NPTYPE_VID
987 : ISAKMP_NPTYPE_NONE
);
989 /* Set Vendor ID, if necessary. */
991 p
= set_isakmp_payload(p
, vid
, nattvid
? ISAKMP_NPTYPE_VID
: ISAKMP_NPTYPE_NONE
);
994 p
= set_isakmp_payload(p
, nattvid
, ISAKMP_NPTYPE_NONE
);
996 #ifdef HAVE_PRINT_ISAKMP_C
997 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
1000 /* send the packet, add to the schedule to resend */
1001 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
1002 if (isakmp_ph1resend(iph1
) == -1)
1005 /* the sending message is added to the received-list. */
1006 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
) == -1) {
1007 plog(LLV_ERROR
, LOCATION
, NULL
,
1008 "failed to add a response packet to the tree.\n");
1012 iph1
->status
= PHASE1ST_MSG1SENT
;
1018 if (gss_sa
!= iph1
->sa_ret
)
1029 * receive from initiator
1032 * gssapi: HDR, KE, Ni, GSSi
1033 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
1034 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
1035 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
1038 ident_r2recv(iph1
, msg
)
1039 struct ph1handle
*iph1
;
1042 vchar_t
*pbuf
= NULL
;
1043 struct isakmp_parse_t
*pa
;
1046 vchar_t
*gsstoken
= NULL
;
1049 /* validity check */
1050 if (iph1
->status
!= PHASE1ST_MSG1SENT
) {
1051 plog(LLV_ERROR
, LOCATION
, NULL
,
1052 "status mismatched %d.\n", iph1
->status
);
1056 /* validate the type of next payload */
1057 pbuf
= isakmp_parse(msg
);
1061 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
1062 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1066 case ISAKMP_NPTYPE_KE
:
1067 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0)
1070 case ISAKMP_NPTYPE_NONCE
:
1071 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0)
1074 case ISAKMP_NPTYPE_VID
:
1075 (void)check_vendorid(pa
->ptr
);
1077 case ISAKMP_NPTYPE_CR
:
1078 plog(LLV_WARNING
, LOCATION
, iph1
->remote
,
1079 "CR received, ignore it. "
1080 "It should be in other exchange.\n");
1083 case ISAKMP_NPTYPE_GSS
:
1084 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0)
1086 gssapi_save_received_token(iph1
, gsstoken
);
1089 case ISAKMP_NPTYPE_NATD_RFC
:
1090 case ISAKMP_NPTYPE_NATD_DRAFT
:
1091 case ISAKMP_NPTYPE_NATD_BADDRAFT
:
1093 if (pa
->type
== iph1
->natd_payload_type
) {
1094 natd_match_t match
= natd_matches(iph1
, pa
->ptr
);
1095 iph1
->natt_flags
|= natt_natd_received
;
1096 if ((match
& natd_match_local
) != 0)
1097 iph1
->natt_flags
|= natt_no_local_nat
;
1098 if ((match
& natd_match_remote
) != 0)
1099 iph1
->natt_flags
|= natt_no_remote_nat
;
1104 /* don't send information, see ident_r1recv() */
1105 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1106 "ignore the packet, "
1107 "received unexpecting payload type %d.\n",
1113 /* payload existency check */
1114 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
1115 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1116 "few isakmp message received.\n");
1120 iph1
->status
= PHASE1ST_MSG2RECEIVED
;
1133 VPTRINIT(iph1
->dhpub_p
);
1134 VPTRINIT(iph1
->nonce_p
);
1135 VPTRINIT(iph1
->id_p
);
1144 * sig: HDR, KE, Nr [, CR ]
1145 * gssapi: HDR, KE, Nr, GSSr
1146 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
1147 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
1150 ident_r2send(iph1
, msg
)
1151 struct ph1handle
*iph1
;
1156 /* validity check */
1157 if (iph1
->status
!= PHASE1ST_MSG2RECEIVED
) {
1158 plog(LLV_ERROR
, LOCATION
, NULL
,
1159 "status mismatched %d.\n", iph1
->status
);
1163 /* generate DH public value */
1164 if (oakley_dh_generate(iph1
->approval
->dhgrp
,
1165 &iph1
->dhpub
, &iph1
->dhpriv
) < 0)
1168 /* generate NONCE value */
1169 iph1
->nonce
= eay_set_random(iph1
->rmconf
->nonce_size
);
1170 if (iph1
->nonce
== NULL
)
1174 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
1175 gssapi_get_rtoken(iph1
, NULL
);
1178 /* create HDR;KE;NONCE payload */
1179 iph1
->sendbuf
= ident_ir2mx(iph1
);
1180 if (iph1
->sendbuf
== NULL
)
1183 #ifdef HAVE_PRINT_ISAKMP_C
1184 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
1187 /* send the packet, add to the schedule to resend */
1188 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
1189 if (isakmp_ph1resend(iph1
) == -1)
1192 /* the sending message is added to the received-list. */
1193 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
) == -1) {
1194 plog(LLV_ERROR
, LOCATION
, NULL
,
1195 "failed to add a response packet to the tree.\n");
1199 /* compute sharing secret of DH */
1200 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub
,
1201 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0)
1204 /* generate SKEYIDs & IV & final cipher key */
1205 if (oakley_skeyid(iph1
) < 0)
1207 if (oakley_skeyid_dae(iph1
) < 0)
1209 if (oakley_compute_enckey(iph1
) < 0)
1211 if (oakley_newiv(iph1
) < 0)
1214 iph1
->status
= PHASE1ST_MSG2SENT
;
1223 * receive from initiator
1224 * psk: HDR*, IDi1, HASH_I
1225 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
1226 * gssapi: HDR*, [ IDi1, ] < GSSi(n) | HASH_I >
1231 ident_r3recv(iph1
, msg0
)
1232 struct ph1handle
*iph1
;
1235 vchar_t
*msg
= NULL
;
1236 vchar_t
*pbuf
= NULL
;
1237 struct isakmp_parse_t
*pa
;
1241 vchar_t
*gsstoken
= NULL
;
1244 /* validity check */
1245 if (iph1
->status
!= PHASE1ST_MSG2SENT
) {
1246 plog(LLV_ERROR
, LOCATION
, NULL
,
1247 "status mismatched %d.\n", iph1
->status
);
1252 if (!ISSET(((struct isakmp
*)msg0
->v
)->flags
, ISAKMP_FLAG_E
)) {
1253 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1254 "reject the packet, "
1255 "expecting the packet encrypted.\n");
1258 msg
= oakley_do_decrypt(iph1
, msg0
, iph1
->ivm
->iv
, iph1
->ivm
->ive
);
1262 /* validate the type of next payload */
1263 pbuf
= isakmp_parse(msg
);
1267 iph1
->pl_hash
= NULL
;
1269 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
1270 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1274 case ISAKMP_NPTYPE_ID
:
1275 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0)
1278 case ISAKMP_NPTYPE_HASH
:
1279 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
1281 #ifdef HAVE_SIGNING_C
1282 case ISAKMP_NPTYPE_CR
:
1283 if (oakley_savecr(iph1
, pa
->ptr
) < 0)
1286 case ISAKMP_NPTYPE_CERT
:
1287 if (oakley_savecert(iph1
, pa
->ptr
) < 0)
1290 case ISAKMP_NPTYPE_SIG
:
1291 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0)
1296 case ISAKMP_NPTYPE_GSS
:
1297 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0)
1299 gssapi_save_received_token(iph1
, gsstoken
);
1302 case ISAKMP_NPTYPE_VID
:
1303 (void)check_vendorid(pa
->ptr
);
1305 case ISAKMP_NPTYPE_N
:
1306 isakmp_check_notify(pa
->ptr
, iph1
);
1309 /* don't send information, see ident_r1recv() */
1310 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1311 "ignore the packet, "
1312 "received unexpecting payload type %d.\n",
1318 /* payload existency check */
1319 /* XXX same as ident_i4recv(), should be merged. */
1323 switch (iph1
->approval
->authmethod
) {
1324 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
1325 if (iph1
->id_p
== NULL
|| iph1
->pl_hash
== NULL
)
1328 case OAKLEY_ATTR_AUTH_METHOD_DSSSIG
:
1329 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
1330 if (iph1
->id_p
== NULL
|| iph1
->sig_p
== NULL
)
1333 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
1334 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
1335 if (iph1
->pl_hash
== NULL
)
1339 case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
:
1340 if (gsstoken
== NULL
&& iph1
->pl_hash
== NULL
)
1345 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1346 "invalid authmethod %d why ?\n",
1347 iph1
->approval
->authmethod
);
1351 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1352 "few isakmp message received.\n");
1357 /* see handler.h about IV synchronization. */
1358 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->ive
->l
);
1360 /* verify identifier */
1361 if (ipsecdoi_checkid1(iph1
) != 0) {
1362 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1363 "invalid ID payload.\n");
1367 /* validate authentication value */
1369 if (gsstoken
== NULL
) {
1371 type
= oakley_validate_auth(iph1
);
1374 /* msg printed inner oakley_validate_auth() */
1377 isakmp_info_send_n1(iph1
, type
, NULL
);
1384 #ifdef HAVE_SIGNING_C
1385 if (oakley_checkcr(iph1
) < 0) {
1386 /* Ignore this error in order to be interoperability. */
1392 * XXX: Should we do compare two addresses, ph1handle's and ID
1396 plog(LLV_DEBUG
, LOCATION
, iph1
->remote
, "peer's ID\n");
1397 plogdump(LLV_DEBUG
, iph1
->id_p
->v
, iph1
->id_p
->l
);
1400 iph1
->status
= gsstoken
!= NULL
? PHASE1ST_MSG2RECEIVED
:
1401 PHASE1ST_MSG3RECEIVED
;
1403 iph1
->status
= PHASE1ST_MSG3RECEIVED
;
1419 VPTRINIT(iph1
->id_p
);
1420 oakley_delcert(iph1
->cert_p
);
1421 iph1
->cert_p
= NULL
;
1422 oakley_delcert(iph1
->crl_p
);
1424 VPTRINIT(iph1
->sig_p
);
1425 oakley_delcert(iph1
->cr_p
);
1434 * psk: HDR*, IDr1, HASH_R
1435 * sig: HDR*, IDr1, [ CERT, ] SIG_R
1436 * gssapi: HDR*, IDr1, < GSSr(n) | HASH_R >
1441 ident_r3send(iph1
, msg
)
1442 struct ph1handle
*iph1
;
1451 /* validity check */
1452 if (iph1
->status
!= PHASE1ST_MSG3RECEIVED
) {
1453 plog(LLV_ERROR
, LOCATION
, NULL
,
1454 "status mismatched %d.\n", iph1
->status
);
1458 /* make ID payload into isakmp status */
1459 if (ipsecdoi_setid1(iph1
) < 0)
1463 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
1464 gssapi_more_tokens(iph1
)) {
1465 gssapi_get_rtoken(iph1
, &len
);
1472 /* generate HASH to send */
1473 plog(LLV_DEBUG
, LOCATION
, NULL
, "generate HASH_R\n");
1474 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
1475 if (iph1
->hash
== NULL
)
1480 /* set encryption flag */
1481 iph1
->flags
|= ISAKMP_FLAG_E
;
1483 /* create HDR;ID;HASH payload */
1484 iph1
->sendbuf
= ident_ir3mx(iph1
);
1485 if (iph1
->sendbuf
== NULL
)
1488 /* send HDR;ID;HASH to responder */
1489 if (isakmp_send(iph1
, iph1
->sendbuf
) < 0)
1492 /* the sending message is added to the received-list. */
1493 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
) == -1) {
1494 plog(LLV_ERROR
, LOCATION
, NULL
,
1495 "failed to add a response packet to the tree.\n");
1499 /* see handler.h about IV synchronization. */
1500 memcpy(iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->v
, iph1
->ivm
->iv
->l
);
1502 iph1
->status
= PHASE1ST_ESTABLISHED
;
1512 * This is used in main mode for:
1513 * initiator's 3rd exchange send to responder
1516 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
1517 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
1518 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
1519 * responders 2nd exchnage send to initiator
1521 * sig: HDR, KE, Nr [, CR ]
1522 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
1523 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
1527 struct ph1handle
*iph1
;
1530 struct isakmp_gen
*gen
;
1535 vchar_t
*vid
= NULL
;
1539 vchar_t
*gsstoken
= NULL
;
1543 #ifdef HAVE_SIGNING_C
1544 /* create CR if need */
1545 if (iph1
->side
== RESPONDER
1546 && iph1
->rmconf
->send_cr
1547 && oakley_needcr(iph1
->approval
->authmethod
)
1548 && iph1
->rmconf
->peerscertfile
== NULL
) {
1550 cr
= oakley_getcr(iph1
);
1552 plog(LLV_ERROR
, LOCATION
, NULL
,
1553 "failed to get cr buffer.\n");
1560 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
1561 gssapi_get_token_to_send(iph1
, &gsstoken
);
1565 tlen
= sizeof(struct isakmp
)
1566 + sizeof(*gen
) + iph1
->dhpub
->l
1567 + sizeof(*gen
) + iph1
->nonce
->l
;
1568 if ((vid
= set_vendorid(iph1
->approval
->vendorid
)) != NULL
)
1569 tlen
+= sizeof(*gen
) + vid
->l
;
1571 tlen
+= sizeof(*gen
) + cr
->l
;
1574 tlen
+= sizeof(*gen
) + gsstoken
->l
;
1578 if ((iph1
->natt_flags
& NATT_TYPE_MASK
) != 0) {
1579 natd_type
= iph1
->natd_payload_type
;
1581 if (iph1
->local_natd
)
1582 tlen
+= sizeof(*gen
) + iph1
->local_natd
->l
;
1583 if (iph1
->remote_natd
)
1584 tlen
+= sizeof(*gen
) + iph1
->remote_natd
->l
;
1588 buf
= vmalloc(tlen
);
1590 plog(LLV_ERROR
, LOCATION
, NULL
,
1591 "failed to get buffer to send.\n");
1595 /* set isakmp header */
1596 p
= set_isakmp_header(buf
, iph1
, ISAKMP_NPTYPE_KE
);
1600 /* create isakmp KE payload */
1601 p
= set_isakmp_payload(p
, iph1
->dhpub
, ISAKMP_NPTYPE_NONCE
);
1603 /* create isakmp NONCE payload */
1605 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
1606 nptype
= ISAKMP_NPTYPE_GSS
;
1609 nptype
= vid
? ISAKMP_NPTYPE_VID
:
1610 (need_cr
? ISAKMP_NPTYPE_CR
:
1611 (natd_type
? natd_type
: ISAKMP_NPTYPE_NONE
));
1612 p
= set_isakmp_payload(p
, iph1
->nonce
, nptype
);
1615 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
) {
1616 p
= set_isakmp_payload(p
, gsstoken
,
1617 vid
? ISAKMP_NPTYPE_VID
1618 : (need_cr
? ISAKMP_NPTYPE_CR
1619 : (natd_type
? natd_type
: ISAKMP_NPTYPE_NONE
)));
1623 /* append vendor id, if needed */
1625 p
= set_isakmp_payload(p
, vid
,
1626 need_cr
? ISAKMP_NPTYPE_CR
1627 : (natd_type
? natd_type
: ISAKMP_NPTYPE_NONE
));
1629 /* create isakmp CR payload if needed */
1631 p
= set_isakmp_payload(p
, cr
, natd_type
? natd_type
: ISAKMP_NPTYPE_NONE
);
1635 if ((iph1
->natt_flags
& NATT_TYPE_MASK
) == natt_type_apple
) {
1636 if (iph1
->local_natd
)
1637 p
= set_isakmp_payload(p
, iph1
->local_natd
, natd_type
);
1638 if (iph1
->remote_natd
)
1639 p
= set_isakmp_payload(p
, iph1
->remote_natd
, ISAKMP_NPTYPE_NONE
);
1641 if (iph1
->remote_natd
)
1642 p
= set_isakmp_payload(p
, iph1
->remote_natd
, natd_type
);
1643 if (iph1
->local_natd
)
1644 p
= set_isakmp_payload(p
, iph1
->local_natd
, ISAKMP_NPTYPE_NONE
);
1651 if (error
&& buf
!= NULL
) {
1668 * This is used in main mode for:
1669 * initiator's 4th exchange send to responder
1670 * psk: HDR*, IDi1, HASH_I
1671 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
1672 * gssapi: HDR*, [ IDi1, ] < GSSi(n) | HASH_I >
1675 * responders 3rd exchnage send to initiator
1676 * psk: HDR*, IDr1, HASH_R
1677 * sig: HDR*, IDr1, [ CERT, ] SIG_R
1678 * gssapi: HDR*, [ IDr1, ] < GSSr(n) | HASH_R >
1684 struct ph1handle
*iph1
;
1686 vchar_t
*buf
= NULL
, *new = NULL
;
1689 struct isakmp_gen
*gen
;
1696 vchar_t
*gsstoken
= NULL
;
1697 vchar_t
*gsshash
= NULL
;
1700 tlen
= sizeof(struct isakmp
);
1702 switch (iph1
->approval
->authmethod
) {
1703 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
1704 tlen
+= sizeof(*gen
) + iph1
->id
->l
1705 + sizeof(*gen
) + iph1
->hash
->l
;
1707 buf
= vmalloc(tlen
);
1709 plog(LLV_ERROR
, LOCATION
, NULL
,
1710 "failed to get buffer to send.\n");
1714 /* set isakmp header */
1715 p
= set_isakmp_header(buf
, iph1
, ISAKMP_NPTYPE_ID
);
1719 /* create isakmp ID payload */
1720 p
= set_isakmp_payload(p
, iph1
->id
, ISAKMP_NPTYPE_HASH
);
1722 /* create isakmp HASH payload */
1723 p
= set_isakmp_payload(p
, iph1
->hash
, ISAKMP_NPTYPE_NONE
);
1725 #ifdef HAVE_SIGNING_C
1726 case OAKLEY_ATTR_AUTH_METHOD_DSSSIG
:
1727 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
1728 if (oakley_getmycert(iph1
) < 0)
1731 if (oakley_getsign(iph1
) < 0)
1734 /* create CR if need */
1735 if (iph1
->side
== INITIATOR
1736 && iph1
->rmconf
->send_cr
1737 && oakley_needcr(iph1
->approval
->authmethod
)
1738 && iph1
->rmconf
->peerscertfile
== NULL
) {
1740 cr
= oakley_getcr(iph1
);
1742 plog(LLV_ERROR
, LOCATION
, NULL
,
1743 "failed to get cr buffer.\n");
1748 if (iph1
->cert
!= NULL
&& iph1
->rmconf
->send_cert
)
1751 tlen
+= sizeof(*gen
) + iph1
->id
->l
1752 + sizeof(*gen
) + iph1
->sig
->l
;
1754 tlen
+= sizeof(*gen
) + iph1
->cert
->pl
->l
;
1756 tlen
+= sizeof(*gen
) + cr
->l
;
1758 buf
= vmalloc(tlen
);
1760 plog(LLV_ERROR
, LOCATION
, NULL
,
1761 "failed to get buffer to send.\n");
1765 /* set isakmp header */
1766 p
= set_isakmp_header(buf
, iph1
, ISAKMP_NPTYPE_ID
);
1770 /* add ID payload */
1771 p
= set_isakmp_payload(p
, iph1
->id
, need_cert
1772 ? ISAKMP_NPTYPE_CERT
1773 : ISAKMP_NPTYPE_SIG
);
1775 /* add CERT payload if there */
1777 p
= set_isakmp_payload(p
, iph1
->cert
->pl
, ISAKMP_NPTYPE_SIG
);
1778 /* add SIG payload */
1779 p
= set_isakmp_payload(p
, iph1
->sig
,
1780 need_cr
? ISAKMP_NPTYPE_CR
: ISAKMP_NPTYPE_NONE
);
1782 /* create isakmp CR payload */
1784 p
= set_isakmp_payload(p
, cr
, ISAKMP_NPTYPE_NONE
);
1788 case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
:
1789 if (!gssapi_id_sent(iph1
))
1790 tlen
+= sizeof (*gen
) + iph1
->id
->l
;
1791 if (iph1
->hash
!= NULL
) {
1792 gsshash
= gssapi_wraphash(iph1
);
1793 if (gsshash
== NULL
)
1795 tlen
+= sizeof (*gen
) + gsshash
->l
;
1797 gssapi_get_token_to_send(iph1
, &gsstoken
);
1798 tlen
+= sizeof (*gen
) + gsstoken
->l
;
1801 buf
= vmalloc(tlen
);
1803 plog(LLV_ERROR
, LOCATION
, NULL
,
1804 "failed to get buffer to send.\n");
1808 /* set isakmp header */
1809 if (!gssapi_id_sent(iph1
))
1810 nptype
= ISAKMP_NPTYPE_ID
;
1812 nptype
= iph1
->hash
!= NULL
? ISAKMP_NPTYPE_HASH
:
1814 p
= set_isakmp_header(buf
, iph1
, nptype
);
1818 if (!gssapi_id_sent(iph1
)) {
1819 /* create isakmp ID payload */
1820 nptype
= iph1
->hash
!= NULL
? ISAKMP_NPTYPE_HASH
:
1822 p
= set_isakmp_payload(p
, iph1
->id
, nptype
);
1825 gssapi_set_id_sent(iph1
);
1828 if (iph1
->hash
!= NULL
)
1829 /* create isakmp HASH payload */
1830 p
= set_isakmp_payload(p
, gsshash
,
1831 ISAKMP_NPTYPE_NONE
);
1833 p
= set_isakmp_payload(p
, gsstoken
, ISAKMP_NPTYPE_NONE
);
1836 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
1837 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
1838 plog(LLV_ERROR
, LOCATION
, NULL
,
1839 "not supported authentication type %d\n",
1840 iph1
->approval
->authmethod
);
1843 plog(LLV_ERROR
, LOCATION
, NULL
,
1844 "invalid authentication type %d\n",
1845 iph1
->approval
->authmethod
);
1849 #ifdef HAVE_PRINT_ISAKMP_C
1850 isakmp_printpacket(buf
, iph1
->local
, iph1
->remote
, 1);
1854 new = oakley_do_encrypt(iph1
, buf
, iph1
->ivm
->ive
, iph1
->ivm
->iv
);
1867 if (error
&& buf
!= NULL
) {