1 /* $NetBSD: isakmp_ident.c,v 1.6 2006/10/02 21:41:59 manu Exp $ */
3 /* Id: isakmp_ident.c,v 1.21 2006/04/06 16:46:08 manubsd Exp */
6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 /* Identity Protecion Exchange (Main Mode) */
38 #include <sys/types.h>
39 #include <sys/param.h>
45 #if TIME_WITH_SYS_TIME
46 # include <sys/time.h>
50 # include <sys/time.h>
64 #include "localconf.h"
65 #include "remoteconf.h"
66 #include "isakmp_var.h"
71 #include "ipsec_doi.h"
72 #include "crypto_openssl.h"
74 #include "isakmp_ident.h"
75 #include "isakmp_inf.h"
79 #include "nattraversal.h"
86 #include "isakmp_xauth.h"
87 #include "isakmp_cfg.h"
90 #include "isakmp_frag.h"
93 #include "vpn_control.h"
94 #include "vpn_control_var.h"
95 #include "ipsecSessionTracer.h"
96 #include "ipsecMessageTracer.h"
98 #include <Security/SecDH.h>
101 static vchar_t
*ident_ir2mx
__P((struct ph1handle
*));
102 static vchar_t
*ident_ir3mx
__P((struct ph1handle
*));
105 * begin Identity Protection Mode as initiator.
115 ident_i1send(iph1
, msg
)
116 struct ph1handle
*iph1
;
117 vchar_t
*msg
; /* must be null */
119 struct payload_list
*plist
= NULL
;
122 vchar_t
*vid_natt
[MAX_NATT_VID_COUNT
] = { NULL
};
126 vchar_t
*vid_xauth
= NULL
;
127 vchar_t
*vid_unity
= NULL
;
130 vchar_t
*vid_frag
= NULL
;
133 vchar_t
*vid_dpd
= NULL
;
137 plog(LLV_ERROR
, LOCATION
, NULL
,
138 "msg has to be NULL in this function.\n");
141 if (iph1
->status
!= PHASE1ST_START
) {
142 plog(LLV_ERROR
, LOCATION
, NULL
,
143 "status mismatched %d.\n", iph1
->status
);
147 /* create isakmp index */
148 memset(&iph1
->index
, 0, sizeof(iph1
->index
));
149 isakmp_newcookie((caddr_t
)&iph1
->index
, iph1
->remote
, iph1
->local
);
151 /* create SA payload for my proposal */
152 iph1
->sa
= ipsecdoi_setph1proposal(iph1
->rmconf
->proposal
);
153 if (iph1
->sa
== NULL
) {
154 plog(LLV_ERROR
, LOCATION
, NULL
,
155 "failed to set proposal");
159 /* set SA payload to propose */
160 plist
= isakmp_plist_append(plist
, iph1
->sa
, ISAKMP_NPTYPE_SA
);
163 /* set VID payload for NAT-T if NAT-T support allowed in the config file */
164 if (iph1
->rmconf
->nat_traversal
)
165 plist
= isakmp_plist_append_natt_vids(plist
, vid_natt
);
168 /* Do we need Xauth VID? */
169 switch (RMAUTHMETHOD(iph1
)) {
170 case FICTIVE_AUTH_METHOD_XAUTH_PSKEY_I
:
171 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
172 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I
:
173 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
174 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_I
:
175 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
176 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
177 if ((vid_xauth
= set_vendorid(VENDORID_XAUTH
)) == NULL
)
178 plog(LLV_ERROR
, LOCATION
, NULL
,
179 "Xauth vendor ID generation failed\n");
181 plist
= isakmp_plist_append(plist
,
182 vid_xauth
, ISAKMP_NPTYPE_VID
);
184 if ((vid_unity
= set_vendorid(VENDORID_UNITY
)) == NULL
)
185 plog(LLV_ERROR
, LOCATION
, NULL
,
186 "Unity vendor ID generation failed\n");
188 plist
= isakmp_plist_append(plist
,
189 vid_unity
, ISAKMP_NPTYPE_VID
);
196 if (iph1
->rmconf
->ike_frag
) {
197 if ((vid_frag
= set_vendorid(VENDORID_FRAG
)) == NULL
) {
198 plog(LLV_ERROR
, LOCATION
, NULL
,
199 "Frag vendorID construction failed\n");
201 vid_frag
= isakmp_frag_addcap(vid_frag
,
202 VENDORID_FRAG_IDENT
);
203 plist
= isakmp_plist_append(plist
,
204 vid_frag
, ISAKMP_NPTYPE_VID
);
209 if(iph1
->rmconf
->dpd
){
210 vid_dpd
= set_vendorid(VENDORID_DPD
);
212 plist
= isakmp_plist_append(plist
, vid_dpd
,
217 iph1
->sendbuf
= isakmp_plist_set_all (&plist
, iph1
);
219 #ifdef HAVE_PRINT_ISAKMP_C
220 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
223 /* send the packet, add to the schedule to resend */
224 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
225 if (isakmp_ph1resend(iph1
) == -1) {
226 plog(LLV_ERROR
, LOCATION
, NULL
,
227 "failed to send packet");
231 iph1
->status
= PHASE1ST_MSG1SENT
;
235 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
236 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
237 CONSTSTR("Initiator, Main-Mode message 1"),
242 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
243 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
244 CONSTSTR("Initiator, Main-Mode Message 1"),
245 CONSTSTR("Failed to transmit Main-Mode Message 1"));
252 for (i
= 0; i
< MAX_NATT_VID_COUNT
&& vid_natt
[i
] != NULL
; i
++)
256 if (vid_xauth
!= NULL
)
258 if (vid_unity
!= NULL
)
270 * receive from responder
277 ident_i2recv(iph1
, msg
)
278 struct ph1handle
*iph1
;
281 vchar_t
*pbuf
= NULL
;
282 struct isakmp_parse_t
*pa
;
283 vchar_t
*satmp
= NULL
;
288 if (iph1
->status
!= PHASE1ST_MSG1SENT
) {
289 plog(LLV_ERROR
, LOCATION
, NULL
,
290 "status mismatched %d.\n", iph1
->status
);
294 /* validate the type of next payload */
296 * NOTE: RedCreek(as responder) attaches N[responder-lifetime] here,
297 * if proposal-lifetime > lifetime-redcreek-wants.
299 * => According to the seciton 4.6.3 in RFC 2407, This is illegal.
300 * NOTE: we do not really care about ordering of VID and N.
302 * NOTE: even if there's multiple VID/N, we'll ignore them.
304 pbuf
= isakmp_parse(msg
);
306 plog(LLV_ERROR
, LOCATION
, NULL
,
307 "failed to parse msg");
310 pa
= ALIGNED_CAST(struct isakmp_parse_t
*)pbuf
->v
;
312 /* SA payload is fixed postion */
313 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
314 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
315 "received invalid next payload type %d, "
317 pa
->type
, ISAKMP_NPTYPE_SA
);
320 if (isakmp_p2ph(&satmp
, pa
->ptr
) < 0) {
321 plog(LLV_ERROR
, LOCATION
, NULL
,
322 "failed to process SA payload");
328 pa
->type
!= ISAKMP_NPTYPE_NONE
;
332 case ISAKMP_NPTYPE_VID
:
333 vid_numeric
= check_vendorid(pa
->ptr
);
335 if (iph1
->rmconf
->nat_traversal
&& natt_vendorid(vid_numeric
))
336 natt_handle_vendorid(iph1
, vid_numeric
);
339 switch (vid_numeric
) {
341 iph1
->mode_cfg
->flags
|=
342 ISAKMP_CFG_VENDORID_XAUTH
;
346 iph1
->mode_cfg
->flags
|=
347 ISAKMP_CFG_VENDORID_UNITY
;
355 if (vid_numeric
== VENDORID_DPD
&& iph1
->rmconf
->dpd
)
359 if ((vid_numeric
== VENDORID_FRAG
) &&
360 (vendorid_frag_cap(pa
->ptr
) & VENDORID_FRAG_IDENT
)) {
361 plog(LLV_DEBUG
, LOCATION
, NULL
,
362 "remote supports FRAGMENTATION\n");
368 /* don't send information, see ident_r1recv() */
369 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
370 "ignore the packet, "
371 "received unexpecting payload type %d.\n",
378 if (NATT_AVAILABLE(iph1
)) {
379 plog(LLV_INFO
, LOCATION
, iph1
->remote
,
380 "Selected NAT-T version: %s\n",
381 vid_string_by_id(iph1
->natt_options
->version
));
382 ike_session_update_natt_version(iph1
);
386 /* check SA payload and set approval SA for use */
387 if (ipsecdoi_checkph1proposal(satmp
, iph1
) < 0) {
388 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
389 "failed to get valid proposal.\n");
390 /* XXX send information */
393 VPTRINIT(iph1
->sa_ret
);
395 iph1
->status
= PHASE1ST_MSG2RECEIVED
;
397 #ifdef ENABLE_VPNCONTROL_PORT
398 vpncontrol_notify_phase_change(1, FROM_REMOTE
, iph1
, NULL
);
403 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
404 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
405 CONSTSTR("Initiator, Main-Mode message 2"),
410 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
411 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
412 CONSTSTR("Initiator, Main-Mode Message 2"),
413 CONSTSTR("Failed to process Main-Mode Message 2"));
426 * gssapi: HDR, KE, Ni, GSSi
427 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
428 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
429 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
432 ident_i2send(iph1
, msg
)
433 struct ph1handle
*iph1
;
439 if (iph1
->status
!= PHASE1ST_MSG2RECEIVED
) {
440 plog(LLV_ERROR
, LOCATION
, NULL
,
441 "status mismatched %d.\n", iph1
->status
);
445 /* fix isakmp index */
446 memcpy(&iph1
->index
.r_ck
, &((struct isakmp
*)msg
->v
)->r_ck
,
449 /* generate DH public value */
451 if (oakley_dh_generate(iph1
->approval
->dhgrp
,
452 &iph1
->dhpub
, &iph1
->dhpriv
) < 0) {
454 if (oakley_dh_generate(iph1
->approval
->dhgrp
,
455 &iph1
->dhpub
, &iph1
->publicKeySize
, &iph1
->dhC
) < 0) {
457 plog(LLV_ERROR
, LOCATION
, NULL
,
458 "failed to generate DH");
462 /* generate NONCE value */
463 iph1
->nonce
= eay_set_random(iph1
->rmconf
->nonce_size
);
464 if (iph1
->nonce
== NULL
) {
465 plog(LLV_ERROR
, LOCATION
, NULL
,
466 "failed to generate NONCE");
471 if (AUTHMETHOD(iph1
) == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
472 gssapi_get_itoken(iph1
, NULL
) < 0) {
473 plog(LLV_ERROR
, LOCATION
, NULL
,
474 "failed to get GSS token");
479 /* create buffer to send isakmp payload */
480 iph1
->sendbuf
= ident_ir2mx(iph1
);
481 if (iph1
->sendbuf
== NULL
) {
482 plog(LLV_ERROR
, LOCATION
, NULL
,
483 "failed to create send buffer");
487 #ifdef HAVE_PRINT_ISAKMP_C
488 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
491 /* send the packet, add to the schedule to resend */
492 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
493 if (isakmp_ph1resend(iph1
) == -1) {
494 plog(LLV_ERROR
, LOCATION
, NULL
,
495 "failed to send packet");
499 /* the sending message is added to the received-list. */
500 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
,
501 PH1_NON_ESP_EXTRA_LEN(iph1
), PH1_FRAG_FLAGS(iph1
)) == -1) {
502 plog(LLV_ERROR
, LOCATION
, NULL
,
503 "failed to add a response packet to the tree.\n");
507 iph1
->status
= PHASE1ST_MSG2SENT
;
511 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
512 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
513 CONSTSTR("Initiator, Main-Mode message 3"),
518 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
519 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
520 CONSTSTR("Initiator, Main-Mode Message 3"),
521 CONSTSTR("Failed to transmit Main-Mode Message 3"));
527 * receive from responder
529 * sig: HDR, KE, Nr [, CR ]
530 * gssapi: HDR, KE, Nr, GSSr
531 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
532 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
535 ident_i3recv(iph1
, msg
)
536 struct ph1handle
*iph1
;
539 vchar_t
*pbuf
= NULL
;
540 struct isakmp_parse_t
*pa
;
544 vchar_t
*gsstoken
= NULL
;
547 vchar_t
*natd_received
;
548 int natd_seq
= 0, natd_verified
;
552 if (iph1
->status
!= PHASE1ST_MSG2SENT
) {
553 plog(LLV_ERROR
, LOCATION
, NULL
,
554 "status mismatched %d.\n", iph1
->status
);
558 /* validate the type of next payload */
559 pbuf
= isakmp_parse(msg
);
561 plog(LLV_ERROR
, LOCATION
, NULL
,
562 "failed to parse msg");
566 for (pa
= ALIGNED_CAST(struct isakmp_parse_t
*)pbuf
->v
;
567 pa
->type
!= ISAKMP_NPTYPE_NONE
;
571 case ISAKMP_NPTYPE_KE
:
572 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0) {
573 plog(LLV_ERROR
, LOCATION
, NULL
,
574 "failed to process KE payload");
578 case ISAKMP_NPTYPE_NONCE
:
579 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0) {
580 plog(LLV_ERROR
, LOCATION
, NULL
,
581 "failed to process NONCE payload");
585 case ISAKMP_NPTYPE_VID
:
586 vid_numeric
= check_vendorid(pa
->ptr
);
588 switch (vid_numeric
) {
590 iph1
->mode_cfg
->flags
|=
591 ISAKMP_CFG_VENDORID_XAUTH
;
595 iph1
->mode_cfg
->flags
|=
596 ISAKMP_CFG_VENDORID_UNITY
;
604 if (vid_numeric
== VENDORID_DPD
&& iph1
->rmconf
->dpd
)
609 case ISAKMP_NPTYPE_CR
:
610 if (oakley_savecr(iph1
, pa
->ptr
) < 0) {
611 plog(LLV_ERROR
, LOCATION
, NULL
,
612 "failed to process CR payload");
617 case ISAKMP_NPTYPE_GSS
:
618 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0) {
619 plog(LLV_ERROR
, LOCATION
, NULL
,
620 "failed to process GSS payload");
623 gssapi_save_received_token(iph1
, gsstoken
);
628 case ISAKMP_NPTYPE_NATD_DRAFT
:
629 case ISAKMP_NPTYPE_NATD_RFC
:
630 case ISAKMP_NPTYPE_NATD_BADDRAFT
:
631 if (NATT_AVAILABLE(iph1
) && iph1
->natt_options
!= NULL
&&
632 pa
->type
== iph1
->natt_options
->payload_nat_d
) {
633 natd_received
= NULL
;
634 if (isakmp_p2ph (&natd_received
, pa
->ptr
) < 0) {
635 plog(LLV_ERROR
, LOCATION
, NULL
,
636 "failed to process NATD payload");
640 /* set both bits first so that we can clear them
641 upon verifying hashes */
643 iph1
->natt_flags
|= NAT_DETECTED
;
645 /* this function will clear appropriate bits bits
646 from iph1->natt_flags */
647 natd_verified
= natt_compare_addr_hash (iph1
,
648 natd_received
, natd_seq
++);
650 plog (LLV_INFO
, LOCATION
, NULL
, "NAT-D payload #%d %s\n",
652 natd_verified
? "verified" : "doesn't match");
654 vfree (natd_received
);
657 /* %%%% Be lenient here - some servers send natd payloads */
658 /* when no nat is detected */
663 /* don't send information, see ident_r1recv() */
664 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
665 "ignore the packet, "
666 "received unexpecting payload type %d.\n",
673 if (NATT_AVAILABLE(iph1
)) {
674 plog (LLV_INFO
, LOCATION
, NULL
, "NAT %s %s%s\n",
675 iph1
->natt_flags
& NAT_DETECTED
?
676 "detected:" : "not detected",
677 iph1
->natt_flags
& NAT_DETECTED_ME
? "ME " : "",
678 iph1
->natt_flags
& NAT_DETECTED_PEER
? "PEER" : "");
679 if (iph1
->natt_flags
& NAT_DETECTED
)
680 natt_float_ports (iph1
);
684 /* payload existency check */
685 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
686 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
687 "few isakmp message received.\n");
691 if (oakley_checkcr(iph1
) < 0) {
692 /* Ignore this error in order to be interoperability. */
696 iph1
->status
= PHASE1ST_MSG3RECEIVED
;
700 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
701 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
702 CONSTSTR("Initiator, Main-Mode message 4"),
707 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
708 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
709 CONSTSTR("Initiator, Main-Mode Message 4"),
710 CONSTSTR("Failed to process Main-Mode Message 4"));
719 VPTRINIT(iph1
->dhpub_p
);
720 VPTRINIT(iph1
->nonce_p
);
721 VPTRINIT(iph1
->id_p
);
722 oakley_delcert(iph1
->cr_p
);
731 * psk: HDR*, IDi1, HASH_I
732 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
733 * gssapi: HDR*, IDi1, < Gssi(n) | HASH_I >
738 ident_i3send(iph1
, msg0
)
739 struct ph1handle
*iph1
;
749 if (iph1
->status
!= PHASE1ST_MSG3RECEIVED
) {
750 plog(LLV_ERROR
, LOCATION
, NULL
,
751 "status mismatched %d.\n", iph1
->status
);
755 /* compute sharing secret of DH */
757 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub
,
758 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0) {
760 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub_p
, iph1
->publicKeySize
, &iph1
->dhgxy
, iph1
->dhC
) < 0) {
762 plog(LLV_ERROR
, LOCATION
, NULL
,
763 "failed to compute DH");
767 /* generate SKEYIDs & IV & final cipher key */
768 if (oakley_skeyid(iph1
) < 0) {
769 plog(LLV_ERROR
, LOCATION
, NULL
,
770 "failed to generate SKEYID");
773 if (oakley_skeyid_dae(iph1
) < 0) {
774 plog(LLV_ERROR
, LOCATION
, NULL
,
775 "failed to generate SKEYID-DAE");
778 if (oakley_compute_enckey(iph1
) < 0) {
779 plog(LLV_ERROR
, LOCATION
, NULL
,
780 "failed to generate ENCKEY");
783 if (oakley_newiv(iph1
) < 0) {
784 plog(LLV_ERROR
, LOCATION
, NULL
,
785 "failed to generate IV");
789 /* make ID payload into isakmp status */
790 if (ipsecdoi_setid1(iph1
) < 0) {
791 plog(LLV_ERROR
, LOCATION
, NULL
,
797 if (AUTHMETHOD(iph1
) == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
798 gssapi_more_tokens(iph1
)) {
799 plog(LLV_DEBUG
, LOCATION
, NULL
, "calling get_itoken\n");
800 if (gssapi_get_itoken(iph1
, &len
) < 0) {
801 plog(LLV_ERROR
, LOCATION
, NULL
,
802 "failed to get GSSAPI token");
810 /* generate HASH to send */
812 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
813 if (iph1
->hash
== NULL
) {
814 plog(LLV_ERROR
, LOCATION
, NULL
,
815 "failed to generate HASH");
821 /* set encryption flag */
822 iph1
->flags
|= ISAKMP_FLAG_E
;
824 /* create HDR;ID;HASH payload */
825 iph1
->sendbuf
= ident_ir3mx(iph1
);
826 if (iph1
->sendbuf
== NULL
) {
827 plog(LLV_ERROR
, LOCATION
, NULL
,
828 "failed to allocate send buffer");
832 /* send the packet, add to the schedule to resend */
833 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
834 if (isakmp_ph1resend(iph1
) == -1) {
835 plog(LLV_ERROR
, LOCATION
, NULL
,
836 "failed to send packet");
840 /* the sending message is added to the received-list. */
841 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg0
,
842 PH1_NON_ESP_EXTRA_LEN(iph1
), PH1_FRAG_FLAGS(iph1
)) == -1) {
843 plog(LLV_ERROR
, LOCATION
, NULL
,
844 "failed to add a response packet to the tree.\n");
848 /* see handler.h about IV synchronization. */
849 memcpy(iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->v
, iph1
->ivm
->iv
->l
);
851 iph1
->status
= PHASE1ST_MSG3SENT
;
855 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
856 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
857 CONSTSTR("Initiator, Main-Mode message 5"),
862 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
863 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
864 CONSTSTR("Initiator, Main-Mode Message 5"),
865 CONSTSTR("Failed to transmit Main-Mode Message 5"));
871 * receive from responder
872 * psk: HDR*, IDr1, HASH_R
873 * sig: HDR*, IDr1, [ CERT, ] SIG_R
874 * gssapi: HDR*, IDr1, < GSSr(n) | HASH_R >
879 ident_i4recv(iph1
, msg0
)
880 struct ph1handle
*iph1
;
883 vchar_t
*pbuf
= NULL
;
884 struct isakmp_parse_t
*pa
;
890 vchar_t
*gsstoken
= NULL
;
892 int received_cert
= 0;
895 if (iph1
->status
!= PHASE1ST_MSG3SENT
) {
896 plog(LLV_ERROR
, LOCATION
, NULL
,
897 "status mismatched %d.\n", iph1
->status
);
902 if (!ISSET(((struct isakmp
*)msg0
->v
)->flags
, ISAKMP_FLAG_E
)) {
903 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
904 "ignore the packet, "
905 "expecting the packet encrypted.\n");
908 msg
= oakley_do_decrypt(iph1
, msg0
, iph1
->ivm
->iv
, iph1
->ivm
->ive
);
910 plog(LLV_ERROR
, LOCATION
, NULL
,
911 "failed to decrypt");
915 /* validate the type of next payload */
916 pbuf
= isakmp_parse(msg
);
918 plog(LLV_ERROR
, LOCATION
, NULL
,
919 "failed to parse msg");
923 iph1
->pl_hash
= NULL
;
925 for (pa
= ALIGNED_CAST(struct isakmp_parse_t
*)pbuf
->v
;
926 pa
->type
!= ISAKMP_NPTYPE_NONE
;
930 case ISAKMP_NPTYPE_ID
:
931 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0) {
932 plog(LLV_ERROR
, LOCATION
, NULL
,
933 "failed to process ID payload");
937 case ISAKMP_NPTYPE_HASH
:
938 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
940 case ISAKMP_NPTYPE_CERT
:
941 if (oakley_savecert(iph1
, pa
->ptr
) < 0) {
942 plog(LLV_ERROR
, LOCATION
, NULL
,
943 "failed to process CERT payload");
948 case ISAKMP_NPTYPE_SIG
:
949 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0) {
950 plog(LLV_ERROR
, LOCATION
, NULL
,
951 "failed to process SIG payload");
956 case ISAKMP_NPTYPE_GSS
:
957 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0) {
958 plog(LLV_ERROR
, LOCATION
, NULL
,
959 "failed to process GSS payload");
962 gssapi_save_received_token(iph1
, gsstoken
);
965 case ISAKMP_NPTYPE_VID
:
966 vid_numeric
= check_vendorid(pa
->ptr
);
968 if (vid_numeric
== VENDORID_DPD
&& iph1
->rmconf
->dpd
)
972 case ISAKMP_NPTYPE_N
:
973 isakmp_check_notify(pa
->ptr
, iph1
);
976 /* don't send information, see ident_r1recv() */
977 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
978 "ignore the packet, "
979 "received unexpecting payload type %d.\n",
986 oakley_verify_certid(iph1
);
989 /* payload existency check */
991 /* verify identifier */
992 if (ipsecdoi_checkid1(iph1
) != 0) {
993 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
994 "invalid ID payload.\n");
998 /* validate authentication value */
1000 if (gsstoken
== NULL
) {
1002 type
= oakley_validate_auth(iph1
);
1004 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1005 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_FAIL
,
1006 CONSTSTR("Initiator, Main-Mode Message 6"),
1007 CONSTSTR("Failed to authenticate Main-Mode Message 6"));
1009 /* msg printed inner oakley_validate_auth() */
1012 EVT_PUSH(iph1
->local
, iph1
->remote
,
1013 EVTT_PEERPH1AUTH_FAILED
, NULL
);
1014 isakmp_info_send_n1(iph1
, type
, NULL
);
1017 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1018 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_SUCC
,
1019 CONSTSTR("Initiator, Main-Mode Message 6"),
1026 * XXX: Should we do compare two addresses, ph1handle's and ID
1030 plog(LLV_DEBUG
, LOCATION
, iph1
->remote
, "peer's ID:");
1031 plogdump(LLV_DEBUG
, iph1
->id_p
->v
, iph1
->id_p
->l
);
1033 /* see handler.h about IV synchronization. */
1034 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->ive
->l
);
1037 * If we got a GSS token, we need to this roundtrip again.
1040 iph1
->status
= gsstoken
!= 0 ? PHASE1ST_MSG3RECEIVED
:
1041 PHASE1ST_MSG4RECEIVED
;
1043 iph1
->status
= PHASE1ST_MSG4RECEIVED
;
1048 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1049 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
1050 CONSTSTR("Initiator, Main-Mode message 6"),
1055 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1056 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
1057 CONSTSTR("Initiator, Main-Mode Message 6"),
1058 CONSTSTR("Failed to transmit Main-Mode Message 6"));
1070 VPTRINIT(iph1
->id_p
);
1071 oakley_delcert(iph1
->cert_p
);
1072 iph1
->cert_p
= NULL
;
1073 oakley_delcert(iph1
->crl_p
);
1075 VPTRINIT(iph1
->sig_p
);
1082 * status update and establish isakmp sa.
1085 ident_i4send(iph1
, msg
)
1086 struct ph1handle
*iph1
;
1091 /* validity check */
1092 if (iph1
->status
!= PHASE1ST_MSG4RECEIVED
) {
1093 plog(LLV_ERROR
, LOCATION
, NULL
,
1094 "status mismatched %d.\n", iph1
->status
);
1098 /* see handler.h about IV synchronization. */
1099 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->l
);
1101 iph1
->status
= PHASE1ST_ESTABLISHED
;
1103 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1104 IPSECSESSIONEVENTCODE_IKEV1_PH1_INIT_SUCC
,
1105 CONSTSTR("Initiator, Main-Mode"),
1115 * receive from initiator
1122 ident_r1recv(iph1
, msg
)
1123 struct ph1handle
*iph1
;
1126 vchar_t
*pbuf
= NULL
;
1127 struct isakmp_parse_t
*pa
;
1131 /* validity check */
1132 if (iph1
->status
!= PHASE1ST_START
) {
1133 plog(LLV_ERROR
, LOCATION
, NULL
,
1134 "status mismatched %d.\n", iph1
->status
);
1138 /* validate the type of next payload */
1140 * NOTE: XXX even if multiple VID, we'll silently ignore those.
1142 pbuf
= isakmp_parse(msg
);
1144 plog(LLV_ERROR
, LOCATION
, NULL
,
1145 "failed to parse msg");
1148 pa
= ALIGNED_CAST(struct isakmp_parse_t
*)pbuf
->v
;
1150 /* check the position of SA payload */
1151 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
1152 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1153 "received invalid next payload type %d, "
1155 pa
->type
, ISAKMP_NPTYPE_SA
);
1158 if (isakmp_p2ph(&iph1
->sa
, pa
->ptr
) < 0) {
1159 plog(LLV_ERROR
, LOCATION
, NULL
,
1160 "failed to process SA payload");
1166 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1170 case ISAKMP_NPTYPE_VID
:
1171 vid_numeric
= check_vendorid(pa
->ptr
);
1173 if (iph1
->rmconf
->nat_traversal
&& natt_vendorid(vid_numeric
))
1174 natt_handle_vendorid(iph1
, vid_numeric
);
1176 #ifdef ENABLE_HYBRID
1177 switch (vid_numeric
) {
1178 case VENDORID_XAUTH
:
1179 iph1
->mode_cfg
->flags
|=
1180 ISAKMP_CFG_VENDORID_XAUTH
;
1183 case VENDORID_UNITY
:
1184 iph1
->mode_cfg
->flags
|=
1185 ISAKMP_CFG_VENDORID_UNITY
;
1193 if (vid_numeric
== VENDORID_DPD
&& iph1
->rmconf
->dpd
)
1194 iph1
->dpd_support
=1;
1197 if ((vid_numeric
== VENDORID_FRAG
) &&
1198 (vendorid_frag_cap(pa
->ptr
) & VENDORID_FRAG_IDENT
)) {
1199 plog(LLV_DEBUG
, LOCATION
, NULL
,
1200 "remote supports FRAGMENTATION\n");
1207 * We don't send information to the peer even
1208 * if we received malformed packet. Because we
1209 * can't distinguish the malformed packet and
1210 * the re-sent packet. And we do same behavior
1211 * when we expect encrypted packet.
1213 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1214 "ignore the packet, "
1215 "received unexpecting payload type %d.\n",
1222 if (NATT_AVAILABLE(iph1
)) {
1223 plog(LLV_INFO
, LOCATION
, iph1
->remote
,
1224 "Selected NAT-T version: %s\n",
1225 vid_string_by_id(iph1
->natt_options
->version
));
1226 ike_session_update_natt_version(iph1
);
1230 /* check SA payload and set approval SA for use */
1231 if (ipsecdoi_checkph1proposal(iph1
->sa
, iph1
) < 0) {
1232 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1233 "failed to get valid proposal.\n");
1234 /* XXX send information */
1238 iph1
->status
= PHASE1ST_MSG1RECEIVED
;
1242 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1243 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
1244 CONSTSTR("Responder, Main-Mode message 1"),
1249 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1250 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
1251 CONSTSTR("Responder, Main-Mode Message 1"),
1252 CONSTSTR("Failed to process Main-Mode Message 1"));
1271 ident_r1send(iph1
, msg
)
1272 struct ph1handle
*iph1
;
1275 struct payload_list
*plist
= NULL
;
1277 vchar_t
*gss_sa
= NULL
;
1279 int free_gss_sa
= 0;
1282 vchar_t
*vid_natt
= NULL
;
1284 #ifdef ENABLE_HYBRID
1285 vchar_t
*vid_xauth
= NULL
;
1286 vchar_t
*vid_unity
= NULL
;
1289 vchar_t
*vid_dpd
= NULL
;
1292 vchar_t
*vid_frag
= NULL
;
1295 /* validity check */
1296 if (iph1
->status
!= PHASE1ST_MSG1RECEIVED
) {
1297 plog(LLV_ERROR
, LOCATION
, NULL
,
1298 "status mismatched %d.\n", iph1
->status
);
1302 /* set responder's cookie */
1303 isakmp_newcookie((caddr_t
)&iph1
->index
.r_ck
, iph1
->remote
, iph1
->local
);
1306 if (iph1
->approval
->gssid
!= NULL
) {
1307 gss_sa
= ipsecdoi_setph1proposal(iph1
->approval
);
1308 if (gss_sa
!= iph1
->sa_ret
)
1312 gss_sa
= iph1
->sa_ret
;
1314 /* set SA payload to reply */
1315 plist
= isakmp_plist_append(plist
, gss_sa
, ISAKMP_NPTYPE_SA
);
1317 #ifdef ENABLE_HYBRID
1318 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) {
1319 plog (LLV_INFO
, LOCATION
, NULL
, "Adding xauth VID payload.\n");
1320 if ((vid_xauth
= set_vendorid(VENDORID_XAUTH
)) == NULL
) {
1321 plog(LLV_ERROR
, LOCATION
, NULL
,
1322 "Cannot create Xauth vendor ID\n");
1325 plist
= isakmp_plist_append(plist
,
1326 vid_xauth
, ISAKMP_NPTYPE_VID
);
1329 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_UNITY
) {
1330 if ((vid_unity
= set_vendorid(VENDORID_UNITY
)) == NULL
) {
1331 plog(LLV_ERROR
, LOCATION
, NULL
,
1332 "Cannot create Unity vendor ID\n");
1335 plist
= isakmp_plist_append(plist
,
1336 vid_unity
, ISAKMP_NPTYPE_VID
);
1340 /* Has the peer announced NAT-T? */
1341 if (NATT_AVAILABLE(iph1
))
1342 vid_natt
= set_vendorid(iph1
->natt_options
->version
);
1345 plist
= isakmp_plist_append(plist
, vid_natt
, ISAKMP_NPTYPE_VID
);
1348 /* XXX only send DPD VID if remote sent it ? */
1349 if(iph1
->rmconf
->dpd
){
1350 vid_dpd
= set_vendorid(VENDORID_DPD
);
1351 if (vid_dpd
!= NULL
)
1352 plist
= isakmp_plist_append(plist
, vid_dpd
, ISAKMP_NPTYPE_VID
);
1357 vid_frag
= set_vendorid(VENDORID_FRAG
);
1358 if (vid_frag
!= NULL
)
1359 vid_frag
= isakmp_frag_addcap(vid_frag
,
1360 VENDORID_FRAG_IDENT
);
1361 if (vid_frag
== NULL
)
1362 plog(LLV_ERROR
, LOCATION
, NULL
,
1363 "Frag vendorID construction failed\n");
1365 plist
= isakmp_plist_append(plist
,
1366 vid_frag
, ISAKMP_NPTYPE_VID
);
1370 iph1
->sendbuf
= isakmp_plist_set_all (&plist
, iph1
);
1372 #ifdef HAVE_PRINT_ISAKMP_C
1373 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
1376 /* send the packet, add to the schedule to resend */
1377 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
1378 if (isakmp_ph1resend(iph1
) == -1) {
1379 plog(LLV_ERROR
, LOCATION
, NULL
,
1380 "failed to send packet");
1384 /* the sending message is added to the received-list. */
1385 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
,
1386 PH1_NON_ESP_EXTRA_LEN(iph1
), PH1_FRAG_FLAGS(iph1
)) == -1) {
1387 plog(LLV_ERROR
, LOCATION
, NULL
,
1388 "failed to add a response packet to the tree.\n");
1392 iph1
->status
= PHASE1ST_MSG1SENT
;
1394 #ifdef ENABLE_VPNCONTROL_PORT
1395 vpncontrol_notify_phase_change(1, FROM_LOCAL
, iph1
, NULL
);
1400 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1401 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
1402 CONSTSTR("Responder, Main-Mode message 2"),
1407 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1408 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
1409 CONSTSTR("Responder, Main-Mode Message 2"),
1410 CONSTSTR("Failed to transmit Main-Mode Message 2"));
1420 #ifdef ENABLE_HYBRID
1421 if (vid_xauth
!= NULL
)
1423 if (vid_unity
!= NULL
)
1427 if (vid_dpd
!= NULL
)
1431 if (vid_frag
!= NULL
)
1439 * receive from initiator
1442 * gssapi: HDR, KE, Ni, GSSi
1443 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
1444 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
1445 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
1448 ident_r2recv(iph1
, msg
)
1449 struct ph1handle
*iph1
;
1452 vchar_t
*pbuf
= NULL
;
1453 struct isakmp_parse_t
*pa
;
1456 vchar_t
*gsstoken
= NULL
;
1462 /* validity check */
1463 if (iph1
->status
!= PHASE1ST_MSG1SENT
) {
1464 plog(LLV_ERROR
, LOCATION
, NULL
,
1465 "status mismatched %d.\n", iph1
->status
);
1469 /* validate the type of next payload */
1470 pbuf
= isakmp_parse(msg
);
1472 plog(LLV_ERROR
, LOCATION
, NULL
,
1473 "failed to parse msg");
1477 for (pa
= ALIGNED_CAST(struct isakmp_parse_t
*)pbuf
->v
;
1478 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1481 case ISAKMP_NPTYPE_KE
:
1482 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0) {
1483 plog(LLV_ERROR
, LOCATION
, NULL
,
1484 "failed to process KE payload");
1488 case ISAKMP_NPTYPE_NONCE
:
1489 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0) {
1490 plog(LLV_ERROR
, LOCATION
, NULL
,
1491 "failed to process NONCE payload");
1495 case ISAKMP_NPTYPE_VID
:
1496 (void)check_vendorid(pa
->ptr
);
1498 case ISAKMP_NPTYPE_CR
:
1499 plog(LLV_WARNING
, LOCATION
, iph1
->remote
,
1500 "CR received, ignore it. "
1501 "It should be in other exchange.\n");
1504 case ISAKMP_NPTYPE_GSS
:
1505 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0) {
1506 plog(LLV_ERROR
, LOCATION
, NULL
,
1507 "failed to process GSS payload");
1510 gssapi_save_received_token(iph1
, gsstoken
);
1515 case ISAKMP_NPTYPE_NATD_DRAFT
:
1516 case ISAKMP_NPTYPE_NATD_RFC
:
1517 case ISAKMP_NPTYPE_NATD_BADDRAFT
:
1518 if (NATT_AVAILABLE(iph1
) && iph1
->natt_options
!= NULL
&&
1519 pa
->type
== iph1
->natt_options
->payload_nat_d
)
1521 vchar_t
*natd_received
= NULL
;
1524 if (isakmp_p2ph (&natd_received
, pa
->ptr
) < 0) {
1525 plog(LLV_ERROR
, LOCATION
, NULL
,
1526 "failed to process NATD payload");
1531 iph1
->natt_flags
|= NAT_DETECTED
;
1533 natd_verified
= natt_compare_addr_hash (iph1
,
1534 natd_received
, natd_seq
++);
1536 plog (LLV_INFO
, LOCATION
, NULL
, "NAT-D payload #%d %s\n",
1538 natd_verified
? "verified" : "doesn't match");
1540 vfree (natd_received
);
1543 /* %%%% Be lenient here - some servers send natd payloads */
1544 /* when no nat is detected */
1549 /* don't send information, see ident_r1recv() */
1550 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1551 "ignore the packet, "
1552 "received unexpecting payload type %d.\n",
1559 if (NATT_AVAILABLE(iph1
))
1560 plog (LLV_INFO
, LOCATION
, NULL
, "NAT %s %s%s\n",
1561 iph1
->natt_flags
& NAT_DETECTED
?
1562 "detected:" : "not detected",
1563 iph1
->natt_flags
& NAT_DETECTED_ME
? "ME " : "",
1564 iph1
->natt_flags
& NAT_DETECTED_PEER
? "PEER" : "");
1567 /* payload existency check */
1568 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
1569 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1570 "few isakmp message received.\n");
1574 iph1
->status
= PHASE1ST_MSG2RECEIVED
;
1578 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1579 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
1580 CONSTSTR("Responder, Main-Mode message 3"),
1585 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1586 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
1587 CONSTSTR("Responder, Main-Mode Message 3"),
1588 CONSTSTR("Failed to process Main-Mode Message 3"));
1598 VPTRINIT(iph1
->dhpub_p
);
1599 VPTRINIT(iph1
->nonce_p
);
1600 VPTRINIT(iph1
->id_p
);
1609 * sig: HDR, KE, Nr [, CR ]
1610 * gssapi: HDR, KE, Nr, GSSr
1611 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
1612 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
1615 ident_r2send(iph1
, msg
)
1616 struct ph1handle
*iph1
;
1621 /* validity check */
1622 if (iph1
->status
!= PHASE1ST_MSG2RECEIVED
) {
1623 plog(LLV_ERROR
, LOCATION
, NULL
,
1624 "status mismatched %d.\n", iph1
->status
);
1628 /* generate DH public value */
1630 if (oakley_dh_generate(iph1
->approval
->dhgrp
,
1631 &iph1
->dhpub
, &iph1
->dhpriv
) < 0) {
1633 if (oakley_dh_generate(iph1
->approval
->dhgrp
,
1634 &iph1
->dhpub
, &iph1
->publicKeySize
, &iph1
->dhC
) < 0) {
1636 plog(LLV_ERROR
, LOCATION
, NULL
,
1637 "failed to generate DH");
1641 /* generate NONCE value */
1642 iph1
->nonce
= eay_set_random(iph1
->rmconf
->nonce_size
);
1643 if (iph1
->nonce
== NULL
) {
1644 plog(LLV_ERROR
, LOCATION
, NULL
,
1645 "failed to generate NONCE");
1650 if (AUTHMETHOD(iph1
) == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
1651 gssapi_get_rtoken(iph1
, NULL
);
1654 /* create HDR;KE;NONCE payload */
1655 iph1
->sendbuf
= ident_ir2mx(iph1
);
1656 if (iph1
->sendbuf
== NULL
) {
1657 plog(LLV_ERROR
, LOCATION
, NULL
,
1658 "failed to allocate send buffer");
1662 #ifdef HAVE_PRINT_ISAKMP_C
1663 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
1666 /* send the packet, add to the schedule to resend */
1667 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
1668 if (isakmp_ph1resend(iph1
) == -1) {
1669 plog(LLV_ERROR
, LOCATION
, NULL
,
1670 "failed to send packet");
1674 /* the sending message is added to the received-list. */
1675 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
,
1676 PH1_NON_ESP_EXTRA_LEN(iph1
), PH1_FRAG_FLAGS(iph1
)) == -1) {
1677 plog(LLV_ERROR
, LOCATION
, NULL
,
1678 "failed to add a response packet to the tree.\n");
1682 /* compute sharing secret of DH */
1684 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub
,
1685 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0) {
1687 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub_p
, iph1
->publicKeySize
, &iph1
->dhgxy
, iph1
->dhC
) < 0) {
1689 plog(LLV_ERROR
, LOCATION
, NULL
,
1690 "failed to compute DH");
1694 /* generate SKEYIDs & IV & final cipher key */
1695 if (oakley_skeyid(iph1
) < 0) {
1696 plog(LLV_ERROR
, LOCATION
, NULL
,
1697 "failed to generate SKEYID");
1700 if (oakley_skeyid_dae(iph1
) < 0) {
1701 plog(LLV_ERROR
, LOCATION
, NULL
,
1702 "failed to generate SKEYID-DAE");
1705 if (oakley_compute_enckey(iph1
) < 0) {
1706 plog(LLV_ERROR
, LOCATION
, NULL
,
1707 "failed to generate ENCKEY");
1710 if (oakley_newiv(iph1
) < 0) {
1711 plog(LLV_ERROR
, LOCATION
, NULL
,
1712 "failed to generate IV");
1716 iph1
->status
= PHASE1ST_MSG2SENT
;
1720 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1721 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
1722 CONSTSTR("Responder, Main-Mode message 4"),
1727 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1728 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
1729 CONSTSTR("Responder, Main-Mode Message 4"),
1730 CONSTSTR("Failed to transmit Main-Mode Message 4"));
1736 * receive from initiator
1737 * psk: HDR*, IDi1, HASH_I
1738 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
1739 * gssapi: HDR*, [ IDi1, ] < GSSi(n) | HASH_I >
1744 ident_r3recv(iph1
, msg0
)
1745 struct ph1handle
*iph1
;
1748 vchar_t
*msg
= NULL
;
1749 vchar_t
*pbuf
= NULL
;
1750 struct isakmp_parse_t
*pa
;
1754 vchar_t
*gsstoken
= NULL
;
1756 int received_cert
= 0;
1758 /* validity check */
1759 if (iph1
->status
!= PHASE1ST_MSG2SENT
) {
1760 plog(LLV_ERROR
, LOCATION
, NULL
,
1761 "status mismatched %d.\n", iph1
->status
);
1766 if (!ISSET(((struct isakmp
*)msg0
->v
)->flags
, ISAKMP_FLAG_E
)) {
1767 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1768 "reject the packet, "
1769 "expecting the packet encrypted.\n");
1772 msg
= oakley_do_decrypt(iph1
, msg0
, iph1
->ivm
->iv
, iph1
->ivm
->ive
);
1774 plog(LLV_ERROR
, LOCATION
, NULL
,
1775 "failed to decrypt");
1779 /* validate the type of next payload */
1780 pbuf
= isakmp_parse(msg
);
1782 plog(LLV_ERROR
, LOCATION
, NULL
,
1783 "failed to parse msg");
1787 iph1
->pl_hash
= NULL
;
1789 for (pa
= ALIGNED_CAST(struct isakmp_parse_t
*)pbuf
->v
;
1790 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1794 case ISAKMP_NPTYPE_ID
:
1795 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0) {
1796 plog(LLV_ERROR
, LOCATION
, NULL
,
1797 "failed to process ID payload");
1801 case ISAKMP_NPTYPE_HASH
:
1802 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
1804 case ISAKMP_NPTYPE_CR
:
1805 if (oakley_savecr(iph1
, pa
->ptr
) < 0) {
1806 plog(LLV_ERROR
, LOCATION
, NULL
,
1807 "failed to process CR payload");
1811 case ISAKMP_NPTYPE_CERT
:
1812 if (oakley_savecert(iph1
, pa
->ptr
) < 0) {
1813 plog(LLV_ERROR
, LOCATION
, NULL
,
1814 "failed to process CERT payload");
1819 case ISAKMP_NPTYPE_SIG
:
1820 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0) {
1821 plog(LLV_ERROR
, LOCATION
, NULL
,
1822 "failed to process SIG payload");
1827 case ISAKMP_NPTYPE_GSS
:
1828 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0) {
1829 plog(LLV_ERROR
, LOCATION
, NULL
,
1830 "failed to process GSS payload");
1833 gssapi_save_received_token(iph1
, gsstoken
);
1836 case ISAKMP_NPTYPE_VID
:
1837 (void)check_vendorid(pa
->ptr
);
1839 case ISAKMP_NPTYPE_N
:
1840 isakmp_check_notify(pa
->ptr
, iph1
);
1843 /* don't send information, see ident_r1recv() */
1844 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1845 "ignore the packet, "
1846 "received unexpecting payload type %d.\n",
1852 if (received_cert
) {
1853 oakley_verify_certid(iph1
);
1856 /* payload existency check */
1857 /* XXX same as ident_i4recv(), should be merged. */
1861 switch (AUTHMETHOD(iph1
)) {
1862 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
1863 #ifdef ENABLE_HYBRID
1864 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
:
1865 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
:
1866 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R
:
1868 if (iph1
->id_p
== NULL
|| iph1
->pl_hash
== NULL
)
1871 case OAKLEY_ATTR_AUTH_METHOD_DSSSIG
:
1872 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
1873 #ifdef ENABLE_HYBRID
1874 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
:
1875 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_R
:
1877 if (iph1
->id_p
== NULL
|| iph1
->sig_p
== NULL
)
1880 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
1881 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
1882 #ifdef ENABLE_HYBRID
1883 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_R
:
1884 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_R
:
1886 if (iph1
->pl_hash
== NULL
)
1890 case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
:
1891 if (gsstoken
== NULL
&& iph1
->pl_hash
== NULL
)
1896 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1897 "invalid authmethod %d why ?\n",
1898 iph1
->approval
->authmethod
);
1902 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1903 "few isakmp message received.\n");
1908 /* verify identifier */
1909 if (ipsecdoi_checkid1(iph1
) != 0) {
1910 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1911 "invalid ID payload.\n");
1915 /* validate authentication value */
1917 if (gsstoken
== NULL
) {
1919 type
= oakley_validate_auth(iph1
);
1921 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1922 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_FAIL
,
1923 CONSTSTR("Responder, Main-Mode Message 5"),
1924 CONSTSTR("Failed to authenticate Main-Mode Message 5"));
1926 /* msg printed inner oakley_validate_auth() */
1929 EVT_PUSH(iph1
->local
, iph1
->remote
,
1930 EVTT_PEERPH1AUTH_FAILED
, NULL
);
1931 isakmp_info_send_n1(iph1
, type
, NULL
);
1934 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1935 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_SUCC
,
1936 CONSTSTR("Responder, Main-Mode Message 5"),
1942 if (oakley_checkcr(iph1
) < 0) {
1943 /* Ignore this error in order to be interoperability. */
1948 * XXX: Should we do compare two addresses, ph1handle's and ID
1952 plog(LLV_DEBUG
, LOCATION
, iph1
->remote
, "peer's ID\n");
1953 plogdump(LLV_DEBUG
, iph1
->id_p
->v
, iph1
->id_p
->l
);
1955 /* see handler.h about IV synchronization. */
1956 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->ive
->l
);
1959 iph1
->status
= gsstoken
!= NULL
? PHASE1ST_MSG2RECEIVED
:
1960 PHASE1ST_MSG3RECEIVED
;
1962 iph1
->status
= PHASE1ST_MSG3RECEIVED
;
1967 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1968 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
1969 CONSTSTR("Responder, Main-Mode message 5"),
1974 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1975 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
1976 CONSTSTR("Responder, Main-Mode Message 5"),
1977 CONSTSTR("Failed to process Main-Mode Message 5"));
1989 VPTRINIT(iph1
->id_p
);
1990 oakley_delcert(iph1
->cert_p
);
1991 iph1
->cert_p
= NULL
;
1992 oakley_delcert(iph1
->crl_p
);
1994 VPTRINIT(iph1
->sig_p
);
1995 oakley_delcert(iph1
->cr_p
);
2004 * psk: HDR*, IDr1, HASH_R
2005 * sig: HDR*, IDr1, [ CERT, ] SIG_R
2006 * gssapi: HDR*, IDr1, < GSSr(n) | HASH_R >
2011 ident_r3send(iph1
, msg
)
2012 struct ph1handle
*iph1
;
2021 /* validity check */
2022 if (iph1
->status
!= PHASE1ST_MSG3RECEIVED
) {
2023 plog(LLV_ERROR
, LOCATION
, NULL
,
2024 "status mismatched %d.\n", iph1
->status
);
2028 /* make ID payload into isakmp status */
2029 if (ipsecdoi_setid1(iph1
) < 0) {
2030 plog(LLV_ERROR
, LOCATION
, NULL
,
2031 "failed to set ID");
2036 if (AUTHMETHOD(iph1
) == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
2037 gssapi_more_tokens(iph1
)) {
2038 gssapi_get_rtoken(iph1
, &len
);
2045 /* generate HASH to send */
2046 plog(LLV_DEBUG
, LOCATION
, NULL
, "generate HASH_R\n");
2047 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
2048 if (iph1
->hash
== NULL
) {
2049 plog(LLV_ERROR
, LOCATION
, NULL
,
2050 "failed to generate HASH");
2056 /* set encryption flag */
2057 iph1
->flags
|= ISAKMP_FLAG_E
;
2059 /* create HDR;ID;HASH payload */
2060 iph1
->sendbuf
= ident_ir3mx(iph1
);
2061 if (iph1
->sendbuf
== NULL
) {
2062 plog(LLV_ERROR
, LOCATION
, NULL
,
2063 "failed to create send buffer");
2067 /* send HDR;ID;HASH to responder */
2068 if (isakmp_send(iph1
, iph1
->sendbuf
) < 0) {
2069 plog(LLV_ERROR
, LOCATION
, NULL
,
2070 "failed to send packet");
2074 /* the sending message is added to the received-list. */
2075 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
,
2076 PH1_NON_ESP_EXTRA_LEN(iph1
), PH1_FRAG_FLAGS(iph1
)) == -1) {
2077 plog(LLV_ERROR
, LOCATION
, NULL
,
2078 "failed to add a response packet to the tree.\n");
2082 /* see handler.h about IV synchronization. */
2083 memcpy(iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->v
, iph1
->ivm
->iv
->l
);
2085 iph1
->status
= PHASE1ST_ESTABLISHED
;
2087 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
2088 IPSECSESSIONEVENTCODE_IKEV1_PH1_RESP_SUCC
,
2089 CONSTSTR("Responder, Main-Mode"),
2094 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
2095 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
2096 CONSTSTR("Responder, Main-Mode message 6"),
2101 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
2102 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
2103 CONSTSTR("Responder, Main-Mode Message 6"),
2104 CONSTSTR("Failed to process Main-Mode Message 6"));
2111 * This is used in main mode for:
2112 * initiator's 3rd exchange send to responder
2115 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
2116 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
2117 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
2118 * responders 2nd exchnage send to initiator
2120 * sig: HDR, KE, Nr [, CR ]
2121 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
2122 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
2126 struct ph1handle
*iph1
;
2129 struct payload_list
*plist
= NULL
;
2132 vchar_t
*vid
= NULL
;
2135 vchar_t
*gsstoken
= NULL
;
2138 vchar_t
*natd
[2] = { NULL
, NULL
};
2141 /* create CR if need */
2142 if (iph1
->side
== RESPONDER
2143 && iph1
->rmconf
->send_cr
2144 && oakley_needcr(iph1
->approval
->authmethod
)
2145 && iph1
->rmconf
->peerscertfile
== NULL
) {
2147 cr
= oakley_getcr(iph1
);
2149 plog(LLV_ERROR
, LOCATION
, NULL
,
2150 "failed to get cr buffer.\n");
2156 if (AUTHMETHOD(iph1
) == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
2157 gssapi_get_token_to_send(iph1
, &gsstoken
);
2160 /* create isakmp KE payload */
2161 plist
= isakmp_plist_append(plist
, iph1
->dhpub
, ISAKMP_NPTYPE_KE
);
2163 /* create isakmp NONCE payload */
2164 plist
= isakmp_plist_append(plist
, iph1
->nonce
, ISAKMP_NPTYPE_NONCE
);
2167 if (AUTHMETHOD(iph1
) == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
2168 plist
= isakmp_plist_append(plist
, gsstoken
, ISAKMP_NPTYPE_GSS
);
2171 /* append vendor id, if needed */
2173 plist
= isakmp_plist_append(plist
, vid
, ISAKMP_NPTYPE_VID
);
2175 /* create isakmp CR payload if needed */
2177 plist
= isakmp_plist_append(plist
, cr
, ISAKMP_NPTYPE_CR
);
2180 /* generate and append NAT-D payloads */
2181 if (NATT_AVAILABLE(iph1
) && iph1
->status
== PHASE1ST_MSG2RECEIVED
)
2183 if ((natd
[0] = natt_hash_addr (iph1
, iph1
->remote
)) == NULL
) {
2184 plog(LLV_ERROR
, LOCATION
, NULL
,
2185 "NAT-D hashing failed for %s\n", saddr2str((struct sockaddr
*)iph1
->remote
));
2189 if ((natd
[1] = natt_hash_addr (iph1
, iph1
->local
)) == NULL
) {
2190 plog(LLV_ERROR
, LOCATION
, NULL
,
2191 "NAT-D hashing failed for %s\n", saddr2str((struct sockaddr
*)iph1
->local
));
2195 plog (LLV_INFO
, LOCATION
, NULL
, "Adding remote and local NAT-D payloads.\n");
2196 /* old Apple version sends natd payloads in the wrong order */
2197 if (iph1
->natt_options
->version
== VENDORID_NATT_APPLE
) {
2198 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
2199 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
2202 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
2203 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
2208 buf
= isakmp_plist_set_all (&plist
, iph1
);
2213 if (error
&& buf
!= NULL
) {
2237 * This is used in main mode for:
2238 * initiator's 4th exchange send to responder
2239 * psk: HDR*, IDi1, HASH_I
2240 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
2241 * gssapi: HDR*, [ IDi1, ] < GSSi(n) | HASH_I >
2244 * responders 3rd exchnage send to initiator
2245 * psk: HDR*, IDr1, HASH_R
2246 * sig: HDR*, IDr1, [ CERT, ] SIG_R
2247 * gssapi: HDR*, [ IDr1, ] < GSSr(n) | HASH_R >
2253 struct ph1handle
*iph1
;
2255 struct payload_list
*plist
= NULL
;
2256 vchar_t
*buf
= NULL
, *new = NULL
;
2263 vchar_t
*gsstoken
= NULL
;
2264 vchar_t
*gsshash
= NULL
;
2266 vchar_t
*notp_ini
= NULL
;
2268 switch (AUTHMETHOD(iph1
)) {
2269 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
2270 #ifdef ENABLE_HYBRID
2271 case FICTIVE_AUTH_METHOD_XAUTH_PSKEY_I
:
2272 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
:
2273 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
2274 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I
:
2276 /* create isakmp ID payload */
2277 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
2279 /* create isakmp HASH payload */
2280 plist
= isakmp_plist_append(plist
, iph1
->hash
, ISAKMP_NPTYPE_HASH
);
2282 case OAKLEY_ATTR_AUTH_METHOD_DSSSIG
:
2283 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
2284 #ifdef ENABLE_HYBRID
2285 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
:
2286 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R
:
2287 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
2288 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
:
2289 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_I
:
2290 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_R
:
2292 if (oakley_getmycert(iph1
) < 0) {
2293 plog(LLV_ERROR
, LOCATION
, NULL
,
2294 "failed to get mycert");
2298 if (oakley_getsign(iph1
) < 0) {
2299 plog(LLV_ERROR
, LOCATION
, NULL
,
2300 "failed to get sign");
2304 /* create CR if need */
2305 if (iph1
->side
== INITIATOR
2306 && iph1
->rmconf
->send_cr
2307 && oakley_needcr(iph1
->approval
->authmethod
)
2308 && iph1
->rmconf
->peerscertfile
== NULL
) {
2310 cr
= oakley_getcr(iph1
);
2312 plog(LLV_ERROR
, LOCATION
, NULL
,
2313 "failed to get CR");
2318 if (iph1
->cert
!= NULL
&& iph1
->rmconf
->send_cert
)
2321 /* add ID payload */
2322 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
2324 /* add CERT payload if there */
2325 // we don't support sending of certchains
2327 plist
= isakmp_plist_append(plist
, iph1
->cert
->pl
, ISAKMP_NPTYPE_CERT
);
2328 /* add SIG payload */
2329 plist
= isakmp_plist_append(plist
, iph1
->sig
, ISAKMP_NPTYPE_SIG
);
2331 /* create isakmp CR payload */
2333 plist
= isakmp_plist_append(plist
, cr
, ISAKMP_NPTYPE_CR
);
2336 case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
:
2337 if (iph1
->hash
!= NULL
) {
2338 gsshash
= gssapi_wraphash(iph1
);
2339 if (gsshash
== NULL
) {
2340 plog(LLV_ERROR
, LOCATION
, NULL
,
2341 "failed to generate GSSAPI HASH");
2345 gssapi_get_token_to_send(iph1
, &gsstoken
);
2348 if (!gssapi_id_sent(iph1
)) {
2349 /* create isakmp ID payload */
2350 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
2351 gssapi_set_id_sent(iph1
);
2354 if (iph1
->hash
!= NULL
)
2355 /* create isakmp HASH payload */
2356 plist
= isakmp_plist_append(plist
, gsshash
, ISAKMP_NPTYPE_HASH
);
2358 plist
= isakmp_plist_append(plist
, gsstoken
, ISAKMP_NPTYPE_GSS
);
2361 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
2362 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
2363 #ifdef ENABLE_HYBRID
2364 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
2365 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_R
:
2366 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
2367 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_R
:
2369 plog(LLV_ERROR
, LOCATION
, NULL
,
2370 "not supported authentication type %d\n",
2371 iph1
->approval
->authmethod
);
2374 plog(LLV_ERROR
, LOCATION
, NULL
,
2375 "invalid authentication type %d\n",
2376 iph1
->approval
->authmethod
);
2380 if (iph1
->side
== INITIATOR
) {
2381 notp_ini
= isakmp_plist_append_initial_contact(iph1
, plist
);
2384 buf
= isakmp_plist_set_all (&plist
, iph1
);
2386 #ifdef HAVE_PRINT_ISAKMP_C
2387 isakmp_printpacket(buf
, iph1
->local
, iph1
->remote
, 1);
2391 new = oakley_do_encrypt(iph1
, buf
, iph1
->ivm
->ive
, iph1
->ivm
->iv
);
2393 plog(LLV_ERROR
, LOCATION
, NULL
,
2394 "failed to encrypt");
2411 if (error
&& buf
!= NULL
) {