1 /* $NetBSD: isakmp_agg.c,v 1.9 2006/09/30 21:49:37 manu Exp $ */
3 /* Id: isakmp_agg.c,v 1.28 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 /* Aggressive Exchange (Aggressive 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>
69 #include "localconf.h"
70 #include "remoteconf.h"
71 #include "isakmp_var.h"
75 #include "ipsec_doi.h"
76 #include "crypto_openssl.h"
78 #include "isakmp_agg.h"
79 #include "isakmp_inf.h"
81 #include "isakmp_xauth.h"
82 #include "isakmp_cfg.h"
85 #include "isakmp_frag.h"
91 #include "nattraversal.h"
94 #include "vpn_control.h"
95 #include "vpn_control_var.h"
96 #include "ipsecSessionTracer.h"
97 #include "ipsecMessageTracer.h"
99 #include <Security/SecDH.h>
103 * begin Aggressive Mode as initiator.
107 * psk: HDR, SA, KE, Ni, IDi1
108 * sig: HDR, SA, KE, Ni, IDi1 [, CR ]
109 * gssapi: HDR, SA, KE, Ni, IDi1, GSSi
110 * rsa: HDR, SA, [ HASH(1),] KE, <IDi1_b>Pubkey_r, <Ni_b>Pubkey_r
111 * rev: HDR, SA, [ HASH(1),] <Ni_b>Pubkey_r, <KE_b>Ke_i,
112 * <IDii_b>Ke_i [, <Cert-I_b>Ke_i ]
115 agg_i1send(iph1
, msg
)
116 phase1_handle_t
*iph1
;
117 vchar_t
*msg
; /* must be null */
119 struct payload_list
*plist
= NULL
;
124 vchar_t
*vid_natt
[MAX_NATT_VID_COUNT
] = { NULL
};
128 vchar_t
*vid_xauth
= NULL
;
129 vchar_t
*vid_unity
= NULL
;
132 vchar_t
*vid_frag
= NULL
;
135 vchar_t
*vid_dpd
= NULL
;
139 if (iph1
->status
!= IKEV1_STATE_AGG_I_START
) {
141 "status mismatched %d.\n", iph1
->status
);
148 "msg has to be NULL in this function.\n");
152 /* create isakmp index */
153 memset(&iph1
->index
, 0, sizeof(iph1
->index
));
154 isakmp_newcookie((caddr_t
)&iph1
->index
, iph1
->remote
, iph1
->local
);
156 /* make ID payload into isakmp status */
157 if (ipsecdoi_setid1(iph1
) < 0) {
163 /* create SA payload for my proposal */
164 iph1
->sa
= ipsecdoi_setph1proposal(iph1
);
165 if (iph1
->sa
== NULL
) {
167 "failed to set proposal");
171 /* consistency check of proposals */
172 if (iph1
->rmconf
->dhgrp
== NULL
) {
174 "configuration failure about DH group.\n");
178 /* generate DH public value */
180 if (oakley_dh_generate(iph1
->rmconf
->dhgrp
,
181 &iph1
->dhpub
, &iph1
->dhpriv
) < 0) {
183 if (oakley_dh_generate(iph1
->rmconf
->dhgrp
,
184 &iph1
->dhpub
, &iph1
->publicKeySize
, &iph1
->dhC
) < 0) {
187 "failed to generate DH");
191 /* generate NONCE value */
192 iph1
->nonce
= eay_set_random(iph1
->rmconf
->nonce_size
);
193 if (iph1
->nonce
== NULL
) {
195 "failed to generate NONCE");
200 /* Do we need Xauth VID? */
201 switch (RMAUTHMETHOD(iph1
)) {
202 case FICTIVE_AUTH_METHOD_XAUTH_PSKEY_I
:
203 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
204 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
205 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
206 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
207 if ((vid_xauth
= set_vendorid(VENDORID_XAUTH
)) == NULL
)
209 "Xauth vendor ID generation failed\n");
210 if ((vid_unity
= set_vendorid(VENDORID_UNITY
)) == NULL
)
212 "Unity vendor ID generation failed\n");
220 if (iph1
->rmconf
->ike_frag
) {
221 vid_frag
= set_vendorid(VENDORID_FRAG
);
222 if (vid_frag
!= NULL
)
223 vid_frag
= isakmp_frag_addcap(vid_frag
,
225 if (vid_frag
== NULL
)
227 "Frag vendorID construction failed\n");
231 /* create CR if need */
232 if (iph1
->rmconf
->send_cr
233 && oakley_needcr(iph1
->rmconf
->proposal
->authmethod
)) {
235 cr
= oakley_getcr(iph1
);
243 plog(ASL_LEVEL_DEBUG
, "authmethod is %s\n",
244 s_oakley_attr_method(iph1
->rmconf
->proposal
->authmethod
));
246 /* set SA payload to propose */
247 plist
= isakmp_plist_append(plist
, iph1
->sa
, ISAKMP_NPTYPE_SA
);
249 /* create isakmp KE payload */
250 plist
= isakmp_plist_append(plist
, iph1
->dhpub
, ISAKMP_NPTYPE_KE
);
252 /* create isakmp NONCE payload */
253 plist
= isakmp_plist_append(plist
, iph1
->nonce
, ISAKMP_NPTYPE_NONCE
);
255 /* create isakmp ID payload */
256 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
258 /* create isakmp CR payload */
260 plist
= isakmp_plist_append(plist
, cr
, ISAKMP_NPTYPE_CR
);
264 plist
= isakmp_plist_append(plist
, vid_frag
, ISAKMP_NPTYPE_VID
);
268 * set VID payload for NAT-T if NAT-T
269 * support allowed in the config file
271 if (iph1
->rmconf
->nat_traversal
)
272 plist
= isakmp_plist_append_natt_vids(plist
, vid_natt
);
276 plist
= isakmp_plist_append(plist
,
277 vid_xauth
, ISAKMP_NPTYPE_VID
);
279 plist
= isakmp_plist_append(plist
,
280 vid_unity
, ISAKMP_NPTYPE_VID
);
283 if(iph1
->rmconf
->dpd
){
284 vid_dpd
= set_vendorid(VENDORID_DPD
);
286 plist
= isakmp_plist_append(plist
, vid_dpd
, ISAKMP_NPTYPE_VID
);
290 iph1
->sendbuf
= isakmp_plist_set_all (&plist
, iph1
);
292 #ifdef HAVE_PRINT_ISAKMP_C
293 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
296 /* send the packet, add to the schedule to resend */
297 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
298 if (isakmp_ph1resend(iph1
) == -1) {
300 "failed to send packet");
304 fsm_set_state(&iph1
->status
, IKEV1_STATE_AGG_I_MSG1SENT
);
308 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
309 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
310 CONSTSTR("Initiator, Aggressive-Mode message 1"),
315 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
316 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
317 CONSTSTR("Initiator, Aggressive-Mode Message 1"),
318 CONSTSTR("Failed to transmit Aggressive-Mode Message 1"));
327 for (i
= 0; i
< MAX_NATT_VID_COUNT
&& vid_natt
[i
] != NULL
; i
++)
331 if (vid_xauth
!= NULL
)
333 if (vid_unity
!= NULL
)
345 * receive from responder
346 * psk: HDR, SA, KE, Nr, IDr1, HASH_R
347 * sig: HDR, SA, KE, Nr, IDr1, [ CR, ] [ CERT, ] SIG_R
348 * gssapi: HDR, SA, KE, Nr, IDr1, GSSr, HASH_R
349 * rsa: HDR, SA, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i, HASH_R
350 * rev: HDR, SA, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDir_b>Ke_r, HASH_R
353 agg_i2recv(iph1
, msg
)
354 phase1_handle_t
*iph1
;
357 vchar_t
*pbuf
= NULL
;
358 struct isakmp_parse_t
*pa
;
359 vchar_t
*satmp
= NULL
;
363 int received_cert
= 0;
367 struct natd_payload
{
370 TAILQ_ENTRY(natd_payload
) chain
;
372 TAILQ_HEAD(_natd_payload
, natd_payload
) natd_tree
;
373 TAILQ_INIT(&natd_tree
);
377 if (iph1
->status
!= IKEV1_STATE_AGG_I_MSG1SENT
) {
379 "status mismatched %d.\n", iph1
->status
);
383 /* validate the type of next payload */
384 pbuf
= isakmp_parse(msg
);
387 "failed to parse msg");
390 pa
= ALIGNED_CAST(struct isakmp_parse_t
*)pbuf
->v
;
392 iph1
->pl_hash
= NULL
;
394 /* SA payload is fixed postion */
395 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
397 "received invalid next payload type %d, "
399 pa
->type
, ISAKMP_NPTYPE_SA
);
403 if (isakmp_p2ph(&satmp
, pa
->ptr
) < 0) {
405 "failed to process SA payload");
411 pa
->type
!= ISAKMP_NPTYPE_NONE
;
415 case ISAKMP_NPTYPE_KE
:
416 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0) {
418 "failed to process KE payload");
422 case ISAKMP_NPTYPE_NONCE
:
423 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0) {
425 "failed to process NONCE payload");
429 case ISAKMP_NPTYPE_ID
:
430 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0) {
432 "failed to process ID payload");
436 case ISAKMP_NPTYPE_HASH
:
437 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
439 case ISAKMP_NPTYPE_CR
:
440 if (oakley_savecr(iph1
, pa
->ptr
) < 0) {
442 "failed to process CR payload");
446 case ISAKMP_NPTYPE_CERT
:
447 if (oakley_savecert(iph1
, pa
->ptr
) < 0) {
449 "failed to process CERT payload");
454 case ISAKMP_NPTYPE_SIG
:
455 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0) {
457 "failed to process SIG payload");
461 case ISAKMP_NPTYPE_VID
:
462 vid_numeric
= check_vendorid(pa
->ptr
);
464 if (iph1
->rmconf
->nat_traversal
&&
465 natt_vendorid(vid_numeric
))
466 natt_handle_vendorid(iph1
, vid_numeric
);
469 switch (vid_numeric
) {
471 iph1
->mode_cfg
->flags
|=
472 ISAKMP_CFG_VENDORID_XAUTH
;
476 iph1
->mode_cfg
->flags
|=
477 ISAKMP_CFG_VENDORID_UNITY
;
484 if (vid_numeric
== VENDORID_DPD
&& iph1
->rmconf
->dpd
) {
486 plog(ASL_LEVEL_DEBUG
,
487 "remote supports DPD\n");
491 if ((vid_numeric
== VENDORID_FRAG
) &&
492 (vendorid_frag_cap(pa
->ptr
) & VENDORID_FRAG_AGG
)) {
493 plog(ASL_LEVEL_DEBUG
,
494 "remote supports FRAGMENTATION\n");
499 case ISAKMP_NPTYPE_N
:
500 isakmp_check_notify(pa
->ptr
, iph1
);
504 case ISAKMP_NPTYPE_NATD_DRAFT
:
505 case ISAKMP_NPTYPE_NATD_RFC
:
506 case ISAKMP_NPTYPE_NATD_BADDRAFT
:
507 if (NATT_AVAILABLE(iph1
) && iph1
->natt_options
!= NULL
&&
508 pa
->type
== iph1
->natt_options
->payload_nat_d
) {
509 struct natd_payload
*natd
;
510 natd
= (struct natd_payload
*)racoon_malloc(sizeof(*natd
));
513 "failed to pre-process NATD payload");
517 natd
->payload
= NULL
;
519 if (isakmp_p2ph (&natd
->payload
, pa
->ptr
) < 0) {
521 "failed to process NATD payload");
525 natd
->seq
= natd_seq
++;
527 TAILQ_INSERT_TAIL(&natd_tree
, natd
, chain
);
530 /* %%% Be lenient here - some servers send natd payloads */
531 /* when nat not detected */
536 /* don't send information, see isakmp_ident_r1() */
538 "ignore the packet, "
539 "received unexpecting payload type %d.\n",
546 oakley_verify_certid(iph1
);
549 /* payload existency check */
550 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
552 "few isakmp message received.\n");
556 /* verify identifier */
557 if (ipsecdoi_checkid1(iph1
) != 0) {
559 "invalid ID payload.\n");
563 /* check SA payload and set approval SA for use */
564 if (ipsecdoi_checkph1proposal(satmp
, iph1
) < 0) {
566 "failed to get valid proposal.\n");
567 /* XXX send information */
570 VPTRINIT(iph1
->sa_ret
);
572 /* fix isakmp index */
573 memcpy(&iph1
->index
.r_ck
, &((struct isakmp
*)msg
->v
)->r_ck
,
577 if (NATT_AVAILABLE(iph1
)) {
578 struct natd_payload
*natd
= NULL
;
582 "Selected NAT-T version: %s\n",
583 vid_string_by_id(iph1
->natt_options
->version
));
585 /* set both bits first so that we can clear them
586 upon verifying hashes */
587 iph1
->natt_flags
|= NAT_DETECTED
;
589 while ((natd
= TAILQ_FIRST(&natd_tree
)) != NULL
) {
590 /* this function will clear appropriate bits bits
591 from iph1->natt_flags */
592 natd_verified
= natt_compare_addr_hash (iph1
,
593 natd
->payload
, natd
->seq
);
595 plog (ASL_LEVEL_INFO
, "NAT-D payload #%d %s\n",
597 natd_verified
? "verified" : "doesn't match");
599 vfree (natd
->payload
);
601 TAILQ_REMOVE(&natd_tree
, natd
, chain
);
605 plog (ASL_LEVEL_INFO
, "NAT %s %s%s\n",
606 iph1
->natt_flags
& NAT_DETECTED
?
607 "detected:" : "not detected",
608 iph1
->natt_flags
& NAT_DETECTED_ME
? "ME " : "",
609 iph1
->natt_flags
& NAT_DETECTED_PEER
? "PEER" : "");
611 if (iph1
->natt_flags
& NAT_DETECTED
)
612 natt_float_ports (iph1
);
613 ike_session_update_natt_version(iph1
);
617 /* compute sharing secret of DH */
619 if (oakley_dh_compute(iph1
->rmconf
->dhgrp
, iph1
->dhpub
,
620 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0) {
622 if (oakley_dh_compute(iph1
->rmconf
->dhgrp
, iph1
->dhpub_p
, iph1
->publicKeySize
, &iph1
->dhgxy
, &iph1
->dhC
) < 0) {
625 "failed to compute DH");
629 /* generate SKEYIDs & IV & final cipher key */
630 if (oakley_skeyid(iph1
) < 0) {
632 "failed to generate SKEYID");
635 if (oakley_skeyid_dae(iph1
) < 0) {
637 "failed to generate SKEYID-DAE");
640 if (oakley_compute_enckey(iph1
) < 0) {
642 "failed to generate ENCKEY");
645 if (oakley_newiv(iph1
) < 0) {
647 "failed to generate IV");
651 /* validate authentication value */
652 ptype
= oakley_validate_auth(iph1
);
654 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
655 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_FAIL
,
656 CONSTSTR("Initiator, Aggressive-Mode Message 2"),
657 CONSTSTR("Failed to authenticate, Aggressive-Mode Message 2"));
659 /* message printed inner oakley_validate_auth() */
662 isakmp_info_send_n1(iph1
, ptype
, NULL
);
665 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
666 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_SUCC
,
667 CONSTSTR("Initiator, Aggressive-Mode Message 2"),
670 if (oakley_checkcr(iph1
) < 0) {
671 /* Ignore this error in order to be interoperability. */
675 /* change status of isakmp status entry */
676 fsm_set_state(&iph1
->status
, IKEV1_STATE_AGG_I_MSG2RCVD
);
678 #ifdef ENABLE_VPNCONTROL_PORT
679 vpncontrol_notify_phase_change(1, FROM_REMOTE
, iph1
, NULL
);
684 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
685 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
686 CONSTSTR("Initiator, Aggressive-Mode message 2"),
691 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
692 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
693 CONSTSTR("Initiator, Aggressive-Mode Message 2"),
694 CONSTSTR("Failure processing Aggressive-Mode Message 2"));
702 VPTRINIT(iph1
->dhpub_p
);
703 VPTRINIT(iph1
->nonce_p
);
704 VPTRINIT(iph1
->id_p
);
705 oakley_delcert(iph1
->cert_p
);
707 oakley_delcert(iph1
->crl_p
);
709 VPTRINIT(iph1
->sig_p
);
710 oakley_delcert(iph1
->cr_p
);
720 * gssapi: HDR, HASH_I
721 * sig: HDR, [ CERT, ] SIG_I
726 agg_i3send(iph1
, msg
)
727 phase1_handle_t
*iph1
;
730 struct payload_list
*plist
= NULL
;
733 vchar_t
*gsshash
= NULL
;
735 vchar_t
*natd
[2] = { NULL
, NULL
};
737 vchar_t
*notp_unity
= NULL
;
738 vchar_t
*notp_ini
= NULL
;
741 if (iph1
->status
!= IKEV1_STATE_AGG_I_MSG2RCVD
) {
743 "status mismatched %d.\n", iph1
->status
);
747 /* generate HASH to send */
748 plog(ASL_LEVEL_DEBUG
, "generate HASH_I\n");
749 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
750 if (iph1
->hash
== NULL
) {
752 "failed to generate HASH");
756 switch (AUTHMETHOD(iph1
)) {
757 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
759 case FICTIVE_AUTH_METHOD_XAUTH_PSKEY_I
:
760 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
762 /* set HASH payload */
763 plist
= isakmp_plist_append(plist
,
764 iph1
->hash
, ISAKMP_NPTYPE_HASH
);
767 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
769 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
771 /* XXX if there is CR or not ? */
773 if (oakley_getmycert(iph1
) < 0) {
775 "failed to get mycert");
779 if (oakley_getsign(iph1
) < 0) {
781 "failed to get sign");
785 if (iph1
->cert
!= NULL
&& iph1
->rmconf
->send_cert
)
788 /* add CERT payload if there */
789 // we don't support sending of certchains
791 plist
= isakmp_plist_append(plist
, iph1
->cert
->pl
, ISAKMP_NPTYPE_CERT
);
793 /* add SIG payload */
794 plist
= isakmp_plist_append(plist
, iph1
->sig
, ISAKMP_NPTYPE_SIG
);
797 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
798 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
800 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
801 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
807 /* generate NAT-D payloads */
808 if (NATT_AVAILABLE(iph1
)) {
809 plog (ASL_LEVEL_INFO
, "Adding remote and local NAT-D payloads.\n");
810 if ((natd
[0] = natt_hash_addr (iph1
, iph1
->remote
)) == NULL
) {
812 "NAT-D hashing failed for %s\n", saddr2str((struct sockaddr
*)iph1
->remote
));
816 if ((natd
[1] = natt_hash_addr (iph1
, iph1
->local
)) == NULL
) {
818 "NAT-D hashing failed for %s\n", saddr2str((struct sockaddr
*)iph1
->local
));
821 /* old Apple version sends natd payloads in the wrong order */
822 if (iph1
->natt_options
->version
== VENDORID_NATT_APPLE
) {
823 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
824 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
827 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
828 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
834 iph1
->sendbuf
= isakmp_plist_set_all (&plist
, iph1
);
836 #ifdef HAVE_PRINT_ISAKMP_C
837 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
841 /* send to responder */
842 if (isakmp_send(iph1
, iph1
->sendbuf
) < 0) {
844 "failed to send packet");
848 /* the sending message is added to the received-list. */
849 if (ike_session_add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
,
850 PH1_NON_ESP_EXTRA_LEN(iph1
, iph1
->sendbuf
), PH1_FRAG_FLAGS(iph1
)) == -1) {
852 "failed to add a response packet to the tree.\n");
856 /* set encryption flag */
857 iph1
->flags
|= ISAKMP_FLAG_E
;
859 fsm_set_state(&iph1
->status
, IKEV1_STATE_PHASE1_ESTABLISHED
);
861 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
862 IPSECSESSIONEVENTCODE_IKEV1_PH1_INIT_SUCC
,
863 CONSTSTR("Initiator, Aggressive-Mode"),
868 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
869 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
870 CONSTSTR("Initiator, Aggressive-Mode message 3"),
875 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
876 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
877 CONSTSTR("Initiator, Aggressive-Mode Message 3"),
878 CONSTSTR("Failed to transmit Aggressive-Mode Message 3"));
896 * receive from initiator
897 * psk: HDR, SA, KE, Ni, IDi1
898 * sig: HDR, SA, KE, Ni, IDi1 [, CR ]
899 * gssapi: HDR, SA, KE, Ni, IDi1 , GSSi
900 * rsa: HDR, SA, [ HASH(1),] KE, <IDi1_b>Pubkey_r, <Ni_b>Pubkey_r
901 * rev: HDR, SA, [ HASH(1),] <Ni_b>Pubkey_r, <KE_b>Ke_i,
902 * <IDii_b>Ke_i [, <Cert-I_b>Ke_i ]
905 agg_r1recv(iph1
, msg
)
906 phase1_handle_t
*iph1
;
910 vchar_t
*pbuf
= NULL
;
911 struct isakmp_parse_t
*pa
;
915 if (iph1
->status
!= IKEV1_STATE_AGG_R_START
) {
917 "status mismatched %d.\n", iph1
->status
);
921 /* validate the type of next payload */
922 pbuf
= isakmp_parse(msg
);
925 "failed to parse msg");
928 pa
= ALIGNED_CAST(struct isakmp_parse_t
*)pbuf
->v
;
930 /* SA payload is fixed postion */
931 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
933 "received invalid next payload type %d, "
935 pa
->type
, ISAKMP_NPTYPE_SA
);
938 if (isakmp_p2ph(&iph1
->sa
, pa
->ptr
) < 0) {
940 "failed to process SA payload");
946 pa
->type
!= ISAKMP_NPTYPE_NONE
;
949 plog(ASL_LEVEL_DEBUG
,
950 "received payload of type %s\n",
951 s_isakmp_nptype(pa
->type
));
954 case ISAKMP_NPTYPE_KE
:
955 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0) {
957 "failed to process KE payload");
961 case ISAKMP_NPTYPE_NONCE
:
962 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0) {
964 "failed to process NONCE payload");
968 case ISAKMP_NPTYPE_ID
:
969 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0) {
971 "failed to process ID payload");
975 case ISAKMP_NPTYPE_VID
:
976 vid_numeric
= check_vendorid(pa
->ptr
);
979 if (iph1
->rmconf
->nat_traversal
&&
980 natt_vendorid(vid_numeric
)) {
981 natt_handle_vendorid(iph1
, vid_numeric
);
986 switch (vid_numeric
) {
988 iph1
->mode_cfg
->flags
|=
989 ISAKMP_CFG_VENDORID_XAUTH
;
993 iph1
->mode_cfg
->flags
|=
994 ISAKMP_CFG_VENDORID_UNITY
;
1001 if (vid_numeric
== VENDORID_DPD
&& iph1
->rmconf
->dpd
) {
1002 iph1
->dpd_support
=1;
1003 plog(ASL_LEVEL_DEBUG
,
1004 "remote supports DPD\n");
1008 if ((vid_numeric
== VENDORID_FRAG
) &&
1009 (vendorid_frag_cap(pa
->ptr
) & VENDORID_FRAG_AGG
)) {
1010 plog(ASL_LEVEL_DEBUG
,
1011 "remote supports FRAGMENTATION\n");
1017 case ISAKMP_NPTYPE_CR
:
1018 if (oakley_savecr(iph1
, pa
->ptr
) < 0) {
1020 "failed to process CR payload");
1026 /* don't send information, see isakmp_ident_r1() */
1028 "ignore the packet, "
1029 "received unexpecting payload type %d.\n",
1035 /* payload existency check */
1036 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
1038 "few isakmp message received.\n");
1042 /* verify identifier */
1043 if (ipsecdoi_checkid1(iph1
) != 0) {
1045 "invalid ID payload.\n");
1050 if (NATT_AVAILABLE(iph1
)) {
1051 plog(ASL_LEVEL_INFO
,
1052 "Selected NAT-T version: %s\n",
1053 vid_string_by_id(iph1
->natt_options
->version
));
1054 ike_session_update_natt_version(iph1
);
1058 /* check SA payload and set approval SA for use */
1059 if (ipsecdoi_checkph1proposal(iph1
->sa
, iph1
) < 0) {
1061 "failed to get valid proposal.\n");
1062 /* XXX send information */
1066 if (oakley_checkcr(iph1
) < 0) {
1067 /* Ignore this error in order to be interoperability. */
1071 fsm_set_state(&iph1
->status
, IKEV1_STATE_AGG_R_MSG1RCVD
);
1075 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1076 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
1077 CONSTSTR("Responder, Aggressive-Mode message 1"),
1082 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1083 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
1084 CONSTSTR("Responder, Aggressive-Mode Message 1"),
1085 CONSTSTR("Failed to process Aggressive-Mode Message 1"));
1092 VPTRINIT(iph1
->dhpub_p
);
1093 VPTRINIT(iph1
->nonce_p
);
1094 VPTRINIT(iph1
->id_p
);
1095 oakley_delcert(iph1
->cr_p
);
1104 * psk: HDR, SA, KE, Nr, IDr1, HASH_R
1105 * sig: HDR, SA, KE, Nr, IDr1, [ CR, ] [ CERT, ] SIG_R
1106 * gssapi: HDR, SA, KE, Nr, IDr1, GSSr, HASH_R
1107 * rsa: HDR, SA, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i, HASH_R
1108 * rev: HDR, SA, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDir_b>Ke_r, HASH_R
1111 agg_r2send(iph1
, msg
)
1112 phase1_handle_t
*iph1
;
1115 struct payload_list
*plist
= NULL
;
1120 #ifdef ENABLE_HYBRID
1121 vchar_t
*xauth_vid
= NULL
;
1122 vchar_t
*unity_vid
= NULL
;
1125 vchar_t
*vid_natt
= NULL
;
1126 vchar_t
*natd
[2] = { NULL
, NULL
};
1129 vchar_t
*vid_dpd
= NULL
;
1132 vchar_t
*vid_frag
= NULL
;
1135 /* validity check */
1136 if (iph1
->status
!= IKEV1_STATE_AGG_R_MSG1RCVD
) {
1138 "status mismatched %d.\n", iph1
->status
);
1142 /* set responder's cookie */
1143 isakmp_newcookie((caddr_t
)&iph1
->index
.r_ck
, iph1
->remote
, iph1
->local
);
1145 /* make ID payload into isakmp status */
1146 if (ipsecdoi_setid1(iph1
) < 0) {
1148 "failed to set ID");
1152 /* generate DH public value */
1154 if (oakley_dh_generate(iph1
->rmconf
->dhgrp
,
1155 &iph1
->dhpub
, &iph1
->dhpriv
) < 0) {
1157 if (oakley_dh_generate(iph1
->rmconf
->dhgrp
,
1158 &iph1
->dhpub
, &iph1
->publicKeySize
, &iph1
->dhC
) < 0) {
1161 "failed to generate DH");
1165 /* generate NONCE value */
1166 iph1
->nonce
= eay_set_random(iph1
->rmconf
->nonce_size
);
1167 if (iph1
->nonce
== NULL
) {
1169 "failed to generate NONCE");
1173 /* compute sharing secret of DH */
1175 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub
,
1176 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0) {
1178 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub_p
, iph1
->publicKeySize
, &iph1
->dhgxy
, &iph1
->dhC
) < 0) {
1181 "failed to compute DH");
1185 /* generate SKEYIDs & IV & final cipher key */
1186 if (oakley_skeyid(iph1
) < 0) {
1188 "failed to generate SKEYID");
1191 if (oakley_skeyid_dae(iph1
) < 0) {
1193 "failed to generate SKEYID-DAE");
1196 if (oakley_compute_enckey(iph1
) < 0) {
1198 "failed to generate ENCKEY");
1201 if (oakley_newiv(iph1
) < 0) {
1203 "failed to generate IV");
1207 /* generate HASH to send */
1208 plog(ASL_LEVEL_DEBUG
, "generate HASH_R\n");
1209 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
1210 if (iph1
->hash
== NULL
) {
1212 "failed to generate GSS HASH");
1216 /* create CR if need */
1217 if (iph1
->rmconf
->send_cr
1218 && oakley_needcr(iph1
->approval
->authmethod
)) {
1220 cr
= oakley_getcr(iph1
);
1223 "failed to get CR.\n");
1229 /* Has the peer announced NAT-T? */
1230 if (NATT_AVAILABLE(iph1
)) {
1231 /* set chosen VID */
1232 vid_natt
= set_vendorid(iph1
->natt_options
->version
);
1234 /* generate NAT-D payloads */
1235 plog (ASL_LEVEL_INFO
, "Adding remote and local NAT-D payloads.\n");
1236 if ((natd
[0] = natt_hash_addr (iph1
, iph1
->remote
)) == NULL
) {
1238 "NAT-D hashing failed for %s\n", saddr2str((struct sockaddr
*)iph1
->remote
));
1242 if ((natd
[1] = natt_hash_addr (iph1
, iph1
->local
)) == NULL
) {
1244 "NAT-D hashing failed for %s\n", saddr2str((struct sockaddr
*)iph1
->local
));
1250 /* Only send DPD support if remote announced DPD and if DPD support is active */
1251 if (iph1
->dpd_support
&& iph1
->rmconf
->dpd
)
1252 vid_dpd
= set_vendorid(VENDORID_DPD
);
1256 vid_frag
= set_vendorid(VENDORID_FRAG
);
1257 if (vid_frag
!= NULL
)
1258 vid_frag
= isakmp_frag_addcap(vid_frag
,
1260 if (vid_frag
== NULL
)
1262 "Frag vendorID construction failed\n");
1266 switch (AUTHMETHOD(iph1
)) {
1267 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
1268 #ifdef ENABLE_HYBRID
1269 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
:
1271 /* set SA payload to reply */
1272 plist
= isakmp_plist_append(plist
, iph1
->sa_ret
, ISAKMP_NPTYPE_SA
);
1274 /* create isakmp KE payload */
1275 plist
= isakmp_plist_append(plist
, iph1
->dhpub
, ISAKMP_NPTYPE_KE
);
1277 /* create isakmp NONCE payload */
1278 plist
= isakmp_plist_append(plist
, iph1
->nonce
, ISAKMP_NPTYPE_NONCE
);
1280 /* create isakmp ID payload */
1281 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
1283 /* create isakmp HASH payload */
1284 plist
= isakmp_plist_append(plist
,
1285 iph1
->hash
, ISAKMP_NPTYPE_HASH
);
1287 /* create isakmp CR payload if needed */
1289 plist
= isakmp_plist_append(plist
, cr
, ISAKMP_NPTYPE_CR
);
1291 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
1292 #ifdef ENABLE_HYBRID
1293 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
:
1294 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
:
1296 /* XXX if there is CR or not ? */
1298 if (oakley_getmycert(iph1
) < 0) {
1300 "failed to get mycert");
1304 if (oakley_getsign(iph1
) < 0) {
1306 "failed to get sign");
1310 if (iph1
->cert
!= NULL
&& iph1
->rmconf
->send_cert
)
1313 /* set SA payload to reply */
1314 plist
= isakmp_plist_append(plist
, iph1
->sa_ret
, ISAKMP_NPTYPE_SA
);
1316 /* create isakmp KE payload */
1317 plist
= isakmp_plist_append(plist
, iph1
->dhpub
, ISAKMP_NPTYPE_KE
);
1319 /* create isakmp NONCE payload */
1320 plist
= isakmp_plist_append(plist
, iph1
->nonce
, ISAKMP_NPTYPE_NONCE
);
1322 /* add ID payload */
1323 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
1325 /* add CERT payload if there */
1327 plist
= isakmp_plist_append(plist
, iph1
->cert
->pl
, ISAKMP_NPTYPE_CERT
);
1329 /* add SIG payload */
1330 plist
= isakmp_plist_append(plist
, iph1
->sig
, ISAKMP_NPTYPE_SIG
);
1332 /* create isakmp CR payload if needed */
1334 plist
= isakmp_plist_append(plist
,
1335 cr
, ISAKMP_NPTYPE_CR
);
1338 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
1339 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
1340 #ifdef ENABLE_HYBRID
1341 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_R
:
1342 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_R
:
1347 #ifdef ENABLE_HYBRID
1348 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) {
1349 plog (ASL_LEVEL_INFO
, "Adding xauth VID payload.\n");
1350 if ((xauth_vid
= set_vendorid(VENDORID_XAUTH
)) == NULL
) {
1352 "Cannot create Xauth vendor ID\n");
1355 plist
= isakmp_plist_append(plist
,
1356 xauth_vid
, ISAKMP_NPTYPE_VID
);
1359 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_UNITY
) {
1360 if ((unity_vid
= set_vendorid(VENDORID_UNITY
)) == NULL
) {
1362 "Cannot create Unity vendor ID\n");
1365 plist
= isakmp_plist_append(plist
,
1366 unity_vid
, ISAKMP_NPTYPE_VID
);
1371 /* append NAT-T payloads */
1374 plist
= isakmp_plist_append(plist
, vid_natt
, ISAKMP_NPTYPE_VID
);
1376 /* old Apple version sends natd payloads in the wrong order */
1377 if (iph1
->natt_options
->version
== VENDORID_NATT_APPLE
) {
1378 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
1379 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
1382 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
1383 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
1390 plist
= isakmp_plist_append(plist
, vid_frag
, ISAKMP_NPTYPE_VID
);
1395 plist
= isakmp_plist_append(plist
, vid_dpd
, ISAKMP_NPTYPE_VID
);
1398 iph1
->sendbuf
= isakmp_plist_set_all (&plist
, iph1
);
1400 #ifdef HAVE_PRINT_ISAKMP_C
1401 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 1);
1404 /* send the packet, add to the schedule to resend */
1405 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
1406 if (isakmp_ph1resend(iph1
) == -1) {
1407 plog(ASL_LEVEL_ERR
,
1408 "failed to send packet");
1412 /* the sending message is added to the received-list. */
1413 if (ike_session_add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
,
1414 PH1_NON_ESP_EXTRA_LEN(iph1
, iph1
->sendbuf
), PH1_FRAG_FLAGS(iph1
)) == -1) {
1415 plog(ASL_LEVEL_ERR
,
1416 "failed to add a response packet to the tree.\n");
1420 fsm_set_state(&iph1
->status
, IKEV1_STATE_AGG_R_MSG2SENT
);
1422 #ifdef ENABLE_VPNCONTROL_PORT
1423 vpncontrol_notify_phase_change(1, FROM_LOCAL
, iph1
, NULL
);
1428 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1429 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
1430 CONSTSTR("Responder, Aggressive-Mode message 2"),
1435 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1436 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
1437 CONSTSTR("Responder, Aggressive-Mode Message 2"),
1438 CONSTSTR("Failed to process Aggressive-Mode Message 2"));
1442 #ifdef ENABLE_HYBRID
1469 * receive from initiator
1471 * gssapi: HDR, HASH_I
1472 * sig: HDR, [ CERT, ] SIG_I
1477 agg_r3recv(iph1
, msg0
)
1478 phase1_handle_t
*iph1
;
1481 vchar_t
*msg
= NULL
;
1482 vchar_t
*pbuf
= NULL
;
1483 struct isakmp_parse_t
*pa
;
1490 int received_cert
= 0;
1492 /* validity check */
1493 if (iph1
->status
!= IKEV1_STATE_AGG_R_MSG2SENT
) {
1495 "status mismatched %d.\n", iph1
->status
);
1499 /* decrypting if need. */
1500 /* XXX configurable ? */
1501 if (ISSET(((struct isakmp
*)msg0
->v
)->flags
, ISAKMP_FLAG_E
)) {
1502 msg
= oakley_do_decrypt(iph1
, msg0
,
1503 iph1
->ivm
->iv
, iph1
->ivm
->ive
);
1506 "failed to decrypt msg");
1512 /* validate the type of next payload */
1513 pbuf
= isakmp_parse(msg
);
1516 "failed to parse msg");
1520 iph1
->pl_hash
= NULL
;
1522 for (pa
= ALIGNED_CAST(struct isakmp_parse_t
*)pbuf
->v
;
1523 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1527 case ISAKMP_NPTYPE_HASH
:
1528 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
1530 case ISAKMP_NPTYPE_VID
:
1531 (void)check_vendorid(pa
->ptr
);
1533 case ISAKMP_NPTYPE_CERT
:
1534 if (oakley_savecert(iph1
, pa
->ptr
) < 0) {
1536 "failed to process CERT payload");
1541 case ISAKMP_NPTYPE_SIG
:
1542 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0) {
1544 "failed to process SIG payload");
1548 case ISAKMP_NPTYPE_N
:
1549 isakmp_check_notify(pa
->ptr
, iph1
);
1553 case ISAKMP_NPTYPE_NATD_DRAFT
:
1554 case ISAKMP_NPTYPE_NATD_RFC
:
1555 if (NATT_AVAILABLE(iph1
) && iph1
->natt_options
!= NULL
&&
1556 pa
->type
== iph1
->natt_options
->payload_nat_d
)
1558 vchar_t
*natd_received
= NULL
;
1561 if (isakmp_p2ph (&natd_received
, pa
->ptr
) < 0) {
1563 "failed to process NATD payload");
1568 iph1
->natt_flags
|= NAT_DETECTED
;
1570 natd_verified
= natt_compare_addr_hash (iph1
,
1571 natd_received
, natd_seq
++);
1573 plog (ASL_LEVEL_INFO
, "NAT-D payload #%d %s\n",
1575 natd_verified
? "verified" : "doesn't match");
1577 vfree (natd_received
);
1580 /* %%%% Be lenient here - some servers send natd payloads */
1581 /* when no nat is detected */
1586 /* don't send information, see isakmp_ident_r1() */
1588 "ignore the packet, "
1589 "received unexpecting payload type %d.\n",
1596 if (NATT_AVAILABLE(iph1
))
1597 plog (ASL_LEVEL_INFO
, "NAT %s %s%s\n",
1598 iph1
->natt_flags
& NAT_DETECTED
?
1599 "detected:" : "not detected",
1600 iph1
->natt_flags
& NAT_DETECTED_ME
? "ME " : "",
1601 iph1
->natt_flags
& NAT_DETECTED_PEER
? "PEER" : "");
1604 if (received_cert
) {
1605 oakley_verify_certid(iph1
);
1608 /* validate authentication value */
1609 ptype
= oakley_validate_auth(iph1
);
1611 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1612 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_FAIL
,
1613 CONSTSTR("Responder, Aggressive-Mode Message 3"),
1614 CONSTSTR("Failed to authenticate Aggressive-Mode Message 3"));
1616 /* message printed inner oakley_validate_auth() */
1619 isakmp_info_send_n1(iph1
, ptype
, NULL
);
1622 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1623 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_SUCC
,
1624 CONSTSTR("Responder, Aggressive-Mode Message 3"),
1627 fsm_set_state(&iph1
->status
, IKEV1_STATE_AGG_R_MSG3RCVD
);
1631 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1632 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
1633 CONSTSTR("Responder, Aggressive-Mode message 3"),
1638 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1639 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
1640 CONSTSTR("Responder, Aggressive-Mode Message 3"),
1641 CONSTSTR("Failed to process Aggressive-Mode Message 3"));
1648 oakley_delcert(iph1
->cert_p
);
1649 iph1
->cert_p
= NULL
;
1650 oakley_delcert(iph1
->crl_p
);
1652 VPTRINIT(iph1
->sig_p
);
1659 * status update and establish isakmp sa.
1662 agg_rfinalize(iph1
, msg
)
1663 phase1_handle_t
*iph1
;
1668 /* validity check */
1669 if (iph1
->status
!= IKEV1_STATE_AGG_R_MSG3RCVD
) {
1671 "status mismatched %d.\n", iph1
->status
);
1675 /* IV synchronized when packet encrypted. */
1676 /* see handler.h about IV synchronization. */
1677 if (ISSET(((struct isakmp
*)msg
->v
)->flags
, ISAKMP_FLAG_E
))
1678 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->l
);
1680 /* set encryption flag */
1681 iph1
->flags
|= ISAKMP_FLAG_E
;
1683 fsm_set_state(&iph1
->status
, IKEV1_STATE_PHASE1_ESTABLISHED
);
1685 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1686 IPSECSESSIONEVENTCODE_IKEV1_PH1_RESP_SUCC
,
1687 CONSTSTR("Responder, Aggressive-Mode"),