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>
65 #include "localconf.h"
66 #include "remoteconf.h"
67 #include "isakmp_var.h"
71 #include "ipsec_doi.h"
72 #include "crypto_openssl.h"
74 #include "isakmp_agg.h"
75 #include "isakmp_inf.h"
77 #include "isakmp_xauth.h"
78 #include "isakmp_cfg.h"
81 #include "isakmp_frag.h"
87 #include "nattraversal.h"
90 #include "vpn_control.h"
91 #include "vpn_control_var.h"
92 #include "ipsecSessionTracer.h"
93 #include "ipsecMessageTracer.h"
95 #include <Security/SecDH.h>
99 * begin Aggressive Mode as initiator.
103 * psk: HDR, SA, KE, Ni, IDi1
104 * sig: HDR, SA, KE, Ni, IDi1 [, CR ]
105 * gssapi: HDR, SA, KE, Ni, IDi1, GSSi
106 * rsa: HDR, SA, [ HASH(1),] KE, <IDi1_b>Pubkey_r, <Ni_b>Pubkey_r
107 * rev: HDR, SA, [ HASH(1),] <Ni_b>Pubkey_r, <KE_b>Ke_i,
108 * <IDii_b>Ke_i [, <Cert-I_b>Ke_i ]
111 agg_i1send(iph1
, msg
)
112 phase1_handle_t
*iph1
;
113 vchar_t
*msg
; /* must be null */
115 struct payload_list
*plist
= NULL
;
120 vchar_t
*vid_natt
[MAX_NATT_VID_COUNT
] = { NULL
};
124 vchar_t
*vid_xauth
= NULL
;
125 vchar_t
*vid_unity
= NULL
;
128 vchar_t
*vid_frag
= NULL
;
131 vchar_t
*vid_dpd
= NULL
;
135 if (iph1
->status
!= IKEV1_STATE_AGG_I_START
) {
137 "status mismatched %d.\n", iph1
->status
);
144 "msg has to be NULL in this function.\n");
148 /* create isakmp index */
149 memset(&iph1
->index
, 0, sizeof(iph1
->index
));
150 isakmp_newcookie((caddr_t
)&iph1
->index
, iph1
->remote
, iph1
->local
);
152 /* make ID payload into isakmp status */
153 if (ipsecdoi_setid1(iph1
) < 0) {
159 /* create SA payload for my proposal */
160 iph1
->sa
= ipsecdoi_setph1proposal(iph1
);
161 if (iph1
->sa
== NULL
) {
163 "failed to set proposal");
167 /* consistency check of proposals */
168 if (iph1
->rmconf
->dhgrp
== NULL
) {
170 "configuration failure about DH group.\n");
174 /* generate DH public value */
176 if (oakley_dh_generate(iph1
->rmconf
->dhgrp
,
177 &iph1
->dhpub
, &iph1
->dhpriv
) < 0) {
179 if (oakley_dh_generate(iph1
->rmconf
->dhgrp
,
180 &iph1
->dhpub
, &iph1
->publicKeySize
, &iph1
->dhC
) < 0) {
183 "failed to generate DH");
187 /* generate NONCE value */
188 iph1
->nonce
= eay_set_random(iph1
->rmconf
->nonce_size
);
189 if (iph1
->nonce
== NULL
) {
191 "failed to generate NONCE");
196 /* Do we need Xauth VID? */
197 switch (RMAUTHMETHOD(iph1
)) {
198 case FICTIVE_AUTH_METHOD_XAUTH_PSKEY_I
:
199 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
200 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
201 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
202 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
203 if ((vid_xauth
= set_vendorid(VENDORID_XAUTH
)) == NULL
)
205 "Xauth vendor ID generation failed\n");
206 if ((vid_unity
= set_vendorid(VENDORID_UNITY
)) == NULL
)
208 "Unity vendor ID generation failed\n");
216 if (iph1
->rmconf
->ike_frag
) {
217 vid_frag
= set_vendorid(VENDORID_FRAG
);
218 if (vid_frag
!= NULL
)
219 vid_frag
= isakmp_frag_addcap(vid_frag
,
221 if (vid_frag
== NULL
)
223 "Frag vendorID construction failed\n");
227 /* create CR if need */
228 if (iph1
->rmconf
->send_cr
229 && oakley_needcr(iph1
->rmconf
->proposal
->authmethod
)) {
231 cr
= oakley_getcr(iph1
);
239 plog(ASL_LEVEL_DEBUG
, "authmethod is %s\n",
240 s_oakley_attr_method(iph1
->rmconf
->proposal
->authmethod
));
242 /* set SA payload to propose */
243 plist
= isakmp_plist_append(plist
, iph1
->sa
, ISAKMP_NPTYPE_SA
);
245 /* create isakmp KE payload */
246 plist
= isakmp_plist_append(plist
, iph1
->dhpub
, ISAKMP_NPTYPE_KE
);
248 /* create isakmp NONCE payload */
249 plist
= isakmp_plist_append(plist
, iph1
->nonce
, ISAKMP_NPTYPE_NONCE
);
251 /* create isakmp ID payload */
252 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
254 /* create isakmp CR payload */
256 plist
= isakmp_plist_append(plist
, cr
, ISAKMP_NPTYPE_CR
);
260 plist
= isakmp_plist_append(plist
, vid_frag
, ISAKMP_NPTYPE_VID
);
264 * set VID payload for NAT-T if NAT-T
265 * support allowed in the config file
267 if (iph1
->rmconf
->nat_traversal
)
268 plist
= isakmp_plist_append_natt_vids(plist
, vid_natt
);
272 plist
= isakmp_plist_append(plist
,
273 vid_xauth
, ISAKMP_NPTYPE_VID
);
275 plist
= isakmp_plist_append(plist
,
276 vid_unity
, ISAKMP_NPTYPE_VID
);
279 if(iph1
->rmconf
->dpd
){
280 vid_dpd
= set_vendorid(VENDORID_DPD
);
282 plist
= isakmp_plist_append(plist
, vid_dpd
, ISAKMP_NPTYPE_VID
);
286 iph1
->sendbuf
= isakmp_plist_set_all (&plist
, iph1
);
288 #ifdef HAVE_PRINT_ISAKMP_C
289 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
292 /* send the packet, add to the schedule to resend */
293 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
294 if (isakmp_ph1resend(iph1
) == -1) {
296 "failed to send packet");
300 fsm_set_state(&iph1
->status
, IKEV1_STATE_AGG_I_MSG1SENT
);
304 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
305 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
306 CONSTSTR("Initiator, Aggressive-Mode message 1"),
311 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
312 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
313 CONSTSTR("Initiator, Aggressive-Mode Message 1"),
314 CONSTSTR("Failed to transmit Aggressive-Mode Message 1"));
323 for (i
= 0; i
< MAX_NATT_VID_COUNT
&& vid_natt
[i
] != NULL
; i
++)
327 if (vid_xauth
!= NULL
)
329 if (vid_unity
!= NULL
)
341 * receive from responder
342 * psk: HDR, SA, KE, Nr, IDr1, HASH_R
343 * sig: HDR, SA, KE, Nr, IDr1, [ CR, ] [ CERT, ] SIG_R
344 * gssapi: HDR, SA, KE, Nr, IDr1, GSSr, HASH_R
345 * rsa: HDR, SA, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i, HASH_R
346 * rev: HDR, SA, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDir_b>Ke_r, HASH_R
349 agg_i2recv(iph1
, msg
)
350 phase1_handle_t
*iph1
;
353 vchar_t
*pbuf
= NULL
;
354 struct isakmp_parse_t
*pa
;
355 vchar_t
*satmp
= NULL
;
359 int received_cert
= 0;
363 struct natd_payload
{
366 TAILQ_ENTRY(natd_payload
) chain
;
368 TAILQ_HEAD(_natd_payload
, natd_payload
) natd_tree
;
369 TAILQ_INIT(&natd_tree
);
373 if (iph1
->status
!= IKEV1_STATE_AGG_I_MSG1SENT
) {
375 "status mismatched %d.\n", iph1
->status
);
379 /* validate the type of next payload */
380 pbuf
= isakmp_parse(msg
);
383 "failed to parse msg");
386 pa
= ALIGNED_CAST(struct isakmp_parse_t
*)pbuf
->v
;
388 iph1
->pl_hash
= NULL
;
390 /* SA payload is fixed postion */
391 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
393 "received invalid next payload type %d, "
395 pa
->type
, ISAKMP_NPTYPE_SA
);
399 if (isakmp_p2ph(&satmp
, pa
->ptr
) < 0) {
401 "failed to process SA payload");
407 pa
->type
!= ISAKMP_NPTYPE_NONE
;
411 case ISAKMP_NPTYPE_KE
:
412 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0) {
414 "failed to process KE payload");
418 case ISAKMP_NPTYPE_NONCE
:
419 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0) {
421 "failed to process NONCE payload");
425 case ISAKMP_NPTYPE_ID
:
426 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0) {
428 "failed to process ID payload");
432 case ISAKMP_NPTYPE_HASH
:
433 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
435 case ISAKMP_NPTYPE_CR
:
436 if (oakley_savecr(iph1
, pa
->ptr
) < 0) {
438 "failed to process CR payload");
442 case ISAKMP_NPTYPE_CERT
:
443 if (oakley_savecert(iph1
, pa
->ptr
) < 0) {
445 "failed to process CERT payload");
450 case ISAKMP_NPTYPE_SIG
:
451 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0) {
453 "failed to process SIG payload");
457 case ISAKMP_NPTYPE_VID
:
458 vid_numeric
= check_vendorid(pa
->ptr
);
460 if (iph1
->rmconf
->nat_traversal
&&
461 natt_vendorid(vid_numeric
))
462 natt_handle_vendorid(iph1
, vid_numeric
);
465 switch (vid_numeric
) {
467 iph1
->mode_cfg
->flags
|=
468 ISAKMP_CFG_VENDORID_XAUTH
;
472 iph1
->mode_cfg
->flags
|=
473 ISAKMP_CFG_VENDORID_UNITY
;
480 if (vid_numeric
== VENDORID_DPD
&& iph1
->rmconf
->dpd
) {
482 plog(ASL_LEVEL_DEBUG
,
483 "remote supports DPD\n");
487 if ((vid_numeric
== VENDORID_FRAG
) &&
488 (vendorid_frag_cap(pa
->ptr
) & VENDORID_FRAG_AGG
)) {
489 plog(ASL_LEVEL_DEBUG
,
490 "remote supports FRAGMENTATION\n");
495 case ISAKMP_NPTYPE_N
:
496 isakmp_check_notify(pa
->ptr
, iph1
);
500 case ISAKMP_NPTYPE_NATD_DRAFT
:
501 case ISAKMP_NPTYPE_NATD_RFC
:
502 case ISAKMP_NPTYPE_NATD_BADDRAFT
:
503 if (NATT_AVAILABLE(iph1
) && iph1
->natt_options
!= NULL
&&
504 pa
->type
== iph1
->natt_options
->payload_nat_d
) {
505 struct natd_payload
*natd
;
506 natd
= (struct natd_payload
*)racoon_malloc(sizeof(*natd
));
509 "failed to pre-process NATD payload");
513 natd
->payload
= NULL
;
515 if (isakmp_p2ph (&natd
->payload
, pa
->ptr
) < 0) {
517 "failed to process NATD payload");
522 natd
->seq
= natd_seq
++;
524 TAILQ_INSERT_TAIL(&natd_tree
, natd
, chain
);
527 /* %%% Be lenient here - some servers send natd payloads */
528 /* when nat not detected */
533 /* don't send information, see isakmp_ident_r1() */
535 "ignore the packet, "
536 "received unexpecting payload type %d.\n",
543 oakley_verify_certid(iph1
);
546 /* payload existency check */
547 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
549 "few isakmp message received.\n");
553 /* verify identifier */
554 if (ipsecdoi_checkid1(iph1
) != 0) {
556 "invalid ID payload.\n");
560 /* check SA payload and set approval SA for use */
561 if (ipsecdoi_checkph1proposal(satmp
, iph1
) < 0) {
563 "failed to get valid proposal.\n");
564 /* XXX send information */
567 VPTRINIT(iph1
->sa_ret
);
569 /* fix isakmp index */
570 memcpy(&iph1
->index
.r_ck
, &((struct isakmp
*)msg
->v
)->r_ck
,
574 if (NATT_AVAILABLE(iph1
)) {
575 struct natd_payload
*natd
= NULL
;
578 plog(ASL_LEVEL_NOTICE
,
579 "Selected NAT-T version: %s\n",
580 vid_string_by_id(iph1
->natt_options
->version
));
582 /* set both bits first so that we can clear them
583 upon verifying hashes */
584 iph1
->natt_flags
|= NAT_DETECTED
;
586 while ((natd
= TAILQ_FIRST(&natd_tree
)) != NULL
) {
587 /* this function will clear appropriate bits bits
588 from iph1->natt_flags */
589 natd_verified
= natt_compare_addr_hash (iph1
,
590 natd
->payload
, natd
->seq
);
592 plog (ASL_LEVEL_NOTICE
, "NAT-D payload #%d %s\n",
594 natd_verified
? "verified" : "doesn't match");
596 vfree (natd
->payload
);
598 TAILQ_REMOVE(&natd_tree
, natd
, chain
);
602 plog (ASL_LEVEL_NOTICE
, "NAT %s %s%s\n",
603 iph1
->natt_flags
& NAT_DETECTED
?
604 "detected:" : "not detected",
605 iph1
->natt_flags
& NAT_DETECTED_ME
? "ME " : "",
606 iph1
->natt_flags
& NAT_DETECTED_PEER
? "PEER" : "");
608 if (iph1
->natt_flags
& NAT_DETECTED
)
609 natt_float_ports (iph1
);
610 ike_session_update_natt_version(iph1
);
614 /* compute sharing secret of DH */
616 if (oakley_dh_compute(iph1
->rmconf
->dhgrp
, iph1
->dhpub
,
617 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0) {
619 if (oakley_dh_compute(iph1
->rmconf
->dhgrp
, iph1
->dhpub_p
, iph1
->publicKeySize
, &iph1
->dhgxy
, &iph1
->dhC
) < 0) {
622 "failed to compute DH");
626 /* generate SKEYIDs & IV & final cipher key */
627 if (oakley_skeyid(iph1
) < 0) {
629 "failed to generate SKEYID");
632 if (oakley_skeyid_dae(iph1
) < 0) {
634 "failed to generate SKEYID-DAE");
637 if (oakley_compute_enckey(iph1
) < 0) {
639 "failed to generate ENCKEY");
642 if (oakley_newiv(iph1
) < 0) {
644 "failed to generate IV");
648 /* validate authentication value */
649 ptype
= oakley_validate_auth(iph1
);
651 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
652 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_FAIL
,
653 CONSTSTR("Initiator, Aggressive-Mode Message 2"),
654 CONSTSTR("Failed to authenticate, Aggressive-Mode Message 2"));
656 /* message printed inner oakley_validate_auth() */
659 isakmp_info_send_n1(iph1
, ptype
, NULL
);
662 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
663 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_SUCC
,
664 CONSTSTR("Initiator, Aggressive-Mode Message 2"),
667 if (oakley_checkcr(iph1
) < 0) {
668 /* Ignore this error in order to be interoperability. */
672 /* change status of isakmp status entry */
673 fsm_set_state(&iph1
->status
, IKEV1_STATE_AGG_I_MSG2RCVD
);
675 #ifdef ENABLE_VPNCONTROL_PORT
676 vpncontrol_notify_phase_change(1, FROM_REMOTE
, iph1
, NULL
);
681 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
682 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
683 CONSTSTR("Initiator, Aggressive-Mode message 2"),
688 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
689 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
690 CONSTSTR("Initiator, Aggressive-Mode Message 2"),
691 CONSTSTR("Failure processing Aggressive-Mode Message 2"));
699 VPTRINIT(iph1
->dhpub_p
);
700 VPTRINIT(iph1
->nonce_p
);
701 VPTRINIT(iph1
->id_p
);
702 oakley_delcert(iph1
->cert_p
);
704 oakley_delcert(iph1
->crl_p
);
706 VPTRINIT(iph1
->sig_p
);
707 oakley_delcert(iph1
->cr_p
);
717 * gssapi: HDR, HASH_I
718 * sig: HDR, [ CERT, ] SIG_I
723 agg_i3send(iph1
, msg
)
724 phase1_handle_t
*iph1
;
727 struct payload_list
*plist
= NULL
;
730 vchar_t
*gsshash
= NULL
;
732 vchar_t
*natd
[2] = { NULL
, NULL
};
734 vchar_t
*notp_unity
= NULL
;
735 vchar_t
*notp_ini
= NULL
;
738 if (iph1
->status
!= IKEV1_STATE_AGG_I_MSG2RCVD
) {
740 "status mismatched %d.\n", iph1
->status
);
744 /* generate HASH to send */
745 plog(ASL_LEVEL_DEBUG
, "generate HASH_I\n");
746 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
747 if (iph1
->hash
== NULL
) {
749 "failed to generate HASH");
753 switch (AUTHMETHOD(iph1
)) {
754 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
756 case FICTIVE_AUTH_METHOD_XAUTH_PSKEY_I
:
757 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
759 /* set HASH payload */
760 plist
= isakmp_plist_append(plist
,
761 iph1
->hash
, ISAKMP_NPTYPE_HASH
);
764 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
766 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
768 /* XXX if there is CR or not ? */
770 if (oakley_getmycert(iph1
) < 0) {
772 "failed to get mycert");
776 if (oakley_getsign(iph1
) < 0) {
778 "failed to get sign");
782 if (iph1
->cert
!= NULL
&& iph1
->rmconf
->send_cert
)
785 /* add CERT payload if there */
786 // we don't support sending of certchains
788 plist
= isakmp_plist_append(plist
, iph1
->cert
->pl
, ISAKMP_NPTYPE_CERT
);
790 /* add SIG payload */
791 plist
= isakmp_plist_append(plist
, iph1
->sig
, ISAKMP_NPTYPE_SIG
);
794 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
795 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
797 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
798 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
804 /* generate NAT-D payloads */
805 if (NATT_AVAILABLE(iph1
)) {
806 plog (ASL_LEVEL_NOTICE
, "Adding remote and local NAT-D payloads.\n");
807 if ((natd
[0] = natt_hash_addr (iph1
, iph1
->remote
)) == NULL
) {
809 "NAT-D hashing failed for %s\n", saddr2str((struct sockaddr
*)iph1
->remote
));
813 if ((natd
[1] = natt_hash_addr (iph1
, iph1
->local
)) == NULL
) {
815 "NAT-D hashing failed for %s\n", saddr2str((struct sockaddr
*)iph1
->local
));
818 /* old Apple version sends natd payloads in the wrong order */
819 if (iph1
->natt_options
->version
== VENDORID_NATT_APPLE
) {
820 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
821 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
824 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
825 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
831 iph1
->sendbuf
= isakmp_plist_set_all (&plist
, iph1
);
833 #ifdef HAVE_PRINT_ISAKMP_C
834 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
838 /* send to responder */
839 if (isakmp_send(iph1
, iph1
->sendbuf
) < 0) {
841 "failed to send packet");
845 /* the sending message is added to the received-list. */
846 if (ike_session_add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
,
847 PH1_NON_ESP_EXTRA_LEN(iph1
, iph1
->sendbuf
), PH1_FRAG_FLAGS(iph1
)) == -1) {
849 "failed to add a response packet to the tree.\n");
853 /* set encryption flag */
854 iph1
->flags
|= ISAKMP_FLAG_E
;
856 fsm_set_state(&iph1
->status
, IKEV1_STATE_PHASE1_ESTABLISHED
);
858 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
859 IPSECSESSIONEVENTCODE_IKEV1_PH1_INIT_SUCC
,
860 CONSTSTR("Initiator, Aggressive-Mode"),
865 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
866 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
867 CONSTSTR("Initiator, Aggressive-Mode message 3"),
872 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
873 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
874 CONSTSTR("Initiator, Aggressive-Mode Message 3"),
875 CONSTSTR("Failed to transmit Aggressive-Mode Message 3"));
893 * receive from initiator
894 * psk: HDR, SA, KE, Ni, IDi1
895 * sig: HDR, SA, KE, Ni, IDi1 [, CR ]
896 * gssapi: HDR, SA, KE, Ni, IDi1 , GSSi
897 * rsa: HDR, SA, [ HASH(1),] KE, <IDi1_b>Pubkey_r, <Ni_b>Pubkey_r
898 * rev: HDR, SA, [ HASH(1),] <Ni_b>Pubkey_r, <KE_b>Ke_i,
899 * <IDii_b>Ke_i [, <Cert-I_b>Ke_i ]
902 agg_r1recv(iph1
, msg
)
903 phase1_handle_t
*iph1
;
907 vchar_t
*pbuf
= NULL
;
908 struct isakmp_parse_t
*pa
;
912 if (iph1
->status
!= IKEV1_STATE_AGG_R_START
) {
914 "status mismatched %d.\n", iph1
->status
);
918 /* validate the type of next payload */
919 pbuf
= isakmp_parse(msg
);
922 "failed to parse msg");
925 pa
= ALIGNED_CAST(struct isakmp_parse_t
*)pbuf
->v
;
927 /* SA payload is fixed postion */
928 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
930 "received invalid next payload type %d, "
932 pa
->type
, ISAKMP_NPTYPE_SA
);
935 if (isakmp_p2ph(&iph1
->sa
, pa
->ptr
) < 0) {
937 "failed to process SA payload");
943 pa
->type
!= ISAKMP_NPTYPE_NONE
;
946 plog(ASL_LEVEL_DEBUG
,
947 "received payload of type %s\n",
948 s_isakmp_nptype(pa
->type
));
951 case ISAKMP_NPTYPE_KE
:
952 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0) {
954 "failed to process KE payload");
958 case ISAKMP_NPTYPE_NONCE
:
959 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0) {
961 "failed to process NONCE payload");
965 case ISAKMP_NPTYPE_ID
:
966 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0) {
968 "failed to process ID payload");
972 case ISAKMP_NPTYPE_VID
:
973 vid_numeric
= check_vendorid(pa
->ptr
);
976 if (iph1
->rmconf
->nat_traversal
&&
977 natt_vendorid(vid_numeric
)) {
978 natt_handle_vendorid(iph1
, vid_numeric
);
983 switch (vid_numeric
) {
985 iph1
->mode_cfg
->flags
|=
986 ISAKMP_CFG_VENDORID_XAUTH
;
990 iph1
->mode_cfg
->flags
|=
991 ISAKMP_CFG_VENDORID_UNITY
;
998 if (vid_numeric
== VENDORID_DPD
&& iph1
->rmconf
->dpd
) {
1000 plog(ASL_LEVEL_DEBUG
,
1001 "remote supports DPD\n");
1005 if ((vid_numeric
== VENDORID_FRAG
) &&
1006 (vendorid_frag_cap(pa
->ptr
) & VENDORID_FRAG_AGG
)) {
1007 plog(ASL_LEVEL_DEBUG
,
1008 "remote supports FRAGMENTATION\n");
1014 case ISAKMP_NPTYPE_CR
:
1015 if (oakley_savecr(iph1
, pa
->ptr
) < 0) {
1017 "failed to process CR payload");
1023 /* don't send information, see isakmp_ident_r1() */
1025 "ignore the packet, "
1026 "received unexpecting payload type %d.\n",
1032 /* payload existency check */
1033 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
1035 "few isakmp message received.\n");
1039 /* verify identifier */
1040 if (ipsecdoi_checkid1(iph1
) != 0) {
1042 "invalid ID payload.\n");
1047 if (NATT_AVAILABLE(iph1
)) {
1048 plog(ASL_LEVEL_NOTICE
,
1049 "Selected NAT-T version: %s\n",
1050 vid_string_by_id(iph1
->natt_options
->version
));
1051 ike_session_update_natt_version(iph1
);
1055 /* check SA payload and set approval SA for use */
1056 if (ipsecdoi_checkph1proposal(iph1
->sa
, iph1
) < 0) {
1058 "failed to get valid proposal.\n");
1059 /* XXX send information */
1063 if (oakley_checkcr(iph1
) < 0) {
1064 /* Ignore this error in order to be interoperability. */
1068 fsm_set_state(&iph1
->status
, IKEV1_STATE_AGG_R_MSG1RCVD
);
1072 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1073 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
1074 CONSTSTR("Responder, Aggressive-Mode message 1"),
1079 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1080 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
1081 CONSTSTR("Responder, Aggressive-Mode Message 1"),
1082 CONSTSTR("Failed to process Aggressive-Mode Message 1"));
1089 VPTRINIT(iph1
->dhpub_p
);
1090 VPTRINIT(iph1
->nonce_p
);
1091 VPTRINIT(iph1
->id_p
);
1092 oakley_delcert(iph1
->cr_p
);
1101 * psk: HDR, SA, KE, Nr, IDr1, HASH_R
1102 * sig: HDR, SA, KE, Nr, IDr1, [ CR, ] [ CERT, ] SIG_R
1103 * gssapi: HDR, SA, KE, Nr, IDr1, GSSr, HASH_R
1104 * rsa: HDR, SA, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i, HASH_R
1105 * rev: HDR, SA, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDir_b>Ke_r, HASH_R
1108 agg_r2send(iph1
, msg
)
1109 phase1_handle_t
*iph1
;
1112 struct payload_list
*plist
= NULL
;
1117 #ifdef ENABLE_HYBRID
1118 vchar_t
*xauth_vid
= NULL
;
1119 vchar_t
*unity_vid
= NULL
;
1122 vchar_t
*vid_natt
= NULL
;
1123 vchar_t
*natd
[2] = { NULL
, NULL
};
1126 vchar_t
*vid_dpd
= NULL
;
1129 vchar_t
*vid_frag
= NULL
;
1132 /* validity check */
1133 if (iph1
->status
!= IKEV1_STATE_AGG_R_MSG1RCVD
) {
1135 "status mismatched %d.\n", iph1
->status
);
1139 /* set responder's cookie */
1140 isakmp_newcookie((caddr_t
)&iph1
->index
.r_ck
, iph1
->remote
, iph1
->local
);
1142 /* make ID payload into isakmp status */
1143 if (ipsecdoi_setid1(iph1
) < 0) {
1145 "failed to set ID");
1149 /* generate DH public value */
1151 if (oakley_dh_generate(iph1
->rmconf
->dhgrp
,
1152 &iph1
->dhpub
, &iph1
->dhpriv
) < 0) {
1154 if (oakley_dh_generate(iph1
->rmconf
->dhgrp
,
1155 &iph1
->dhpub
, &iph1
->publicKeySize
, &iph1
->dhC
) < 0) {
1158 "failed to generate DH");
1162 /* generate NONCE value */
1163 iph1
->nonce
= eay_set_random(iph1
->rmconf
->nonce_size
);
1164 if (iph1
->nonce
== NULL
) {
1166 "failed to generate NONCE");
1170 /* compute sharing secret of DH */
1172 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub
,
1173 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0) {
1175 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub_p
, iph1
->publicKeySize
, &iph1
->dhgxy
, &iph1
->dhC
) < 0) {
1178 "failed to compute DH");
1182 /* generate SKEYIDs & IV & final cipher key */
1183 if (oakley_skeyid(iph1
) < 0) {
1185 "failed to generate SKEYID");
1188 if (oakley_skeyid_dae(iph1
) < 0) {
1190 "failed to generate SKEYID-DAE");
1193 if (oakley_compute_enckey(iph1
) < 0) {
1195 "failed to generate ENCKEY");
1198 if (oakley_newiv(iph1
) < 0) {
1200 "failed to generate IV");
1204 /* generate HASH to send */
1205 plog(ASL_LEVEL_DEBUG
, "generate HASH_R\n");
1206 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
1207 if (iph1
->hash
== NULL
) {
1209 "failed to generate GSS HASH");
1213 /* create CR if need */
1214 if (iph1
->rmconf
->send_cr
1215 && oakley_needcr(iph1
->approval
->authmethod
)) {
1217 cr
= oakley_getcr(iph1
);
1220 "failed to get CR.\n");
1226 /* Has the peer announced NAT-T? */
1227 if (NATT_AVAILABLE(iph1
)) {
1228 /* set chosen VID */
1229 vid_natt
= set_vendorid(iph1
->natt_options
->version
);
1231 /* generate NAT-D payloads */
1232 plog (ASL_LEVEL_NOTICE
, "Adding remote and local NAT-D payloads.\n");
1233 if ((natd
[0] = natt_hash_addr (iph1
, iph1
->remote
)) == NULL
) {
1235 "NAT-D hashing failed for %s\n", saddr2str((struct sockaddr
*)iph1
->remote
));
1239 if ((natd
[1] = natt_hash_addr (iph1
, iph1
->local
)) == NULL
) {
1241 "NAT-D hashing failed for %s\n", saddr2str((struct sockaddr
*)iph1
->local
));
1247 /* Only send DPD support if remote announced DPD and if DPD support is active */
1248 if (iph1
->dpd_support
&& iph1
->rmconf
->dpd
)
1249 vid_dpd
= set_vendorid(VENDORID_DPD
);
1253 vid_frag
= set_vendorid(VENDORID_FRAG
);
1254 if (vid_frag
!= NULL
)
1255 vid_frag
= isakmp_frag_addcap(vid_frag
,
1257 if (vid_frag
== NULL
)
1259 "Frag vendorID construction failed\n");
1263 switch (AUTHMETHOD(iph1
)) {
1264 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
1265 #ifdef ENABLE_HYBRID
1266 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
:
1268 /* set SA payload to reply */
1269 plist
= isakmp_plist_append(plist
, iph1
->sa_ret
, ISAKMP_NPTYPE_SA
);
1271 /* create isakmp KE payload */
1272 plist
= isakmp_plist_append(plist
, iph1
->dhpub
, ISAKMP_NPTYPE_KE
);
1274 /* create isakmp NONCE payload */
1275 plist
= isakmp_plist_append(plist
, iph1
->nonce
, ISAKMP_NPTYPE_NONCE
);
1277 /* create isakmp ID payload */
1278 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
1280 /* create isakmp HASH payload */
1281 plist
= isakmp_plist_append(plist
,
1282 iph1
->hash
, ISAKMP_NPTYPE_HASH
);
1284 /* create isakmp CR payload if needed */
1286 plist
= isakmp_plist_append(plist
, cr
, ISAKMP_NPTYPE_CR
);
1288 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
1289 #ifdef ENABLE_HYBRID
1290 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
:
1291 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
:
1293 /* XXX if there is CR or not ? */
1295 if (oakley_getmycert(iph1
) < 0) {
1297 "failed to get mycert");
1301 if (oakley_getsign(iph1
) < 0) {
1303 "failed to get sign");
1307 if (iph1
->cert
!= NULL
&& iph1
->rmconf
->send_cert
)
1310 /* set SA payload to reply */
1311 plist
= isakmp_plist_append(plist
, iph1
->sa_ret
, ISAKMP_NPTYPE_SA
);
1313 /* create isakmp KE payload */
1314 plist
= isakmp_plist_append(plist
, iph1
->dhpub
, ISAKMP_NPTYPE_KE
);
1316 /* create isakmp NONCE payload */
1317 plist
= isakmp_plist_append(plist
, iph1
->nonce
, ISAKMP_NPTYPE_NONCE
);
1319 /* add ID payload */
1320 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
1322 /* add CERT payload if there */
1324 plist
= isakmp_plist_append(plist
, iph1
->cert
->pl
, ISAKMP_NPTYPE_CERT
);
1326 /* add SIG payload */
1327 plist
= isakmp_plist_append(plist
, iph1
->sig
, ISAKMP_NPTYPE_SIG
);
1329 /* create isakmp CR payload if needed */
1331 plist
= isakmp_plist_append(plist
,
1332 cr
, ISAKMP_NPTYPE_CR
);
1335 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
1336 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
1337 #ifdef ENABLE_HYBRID
1338 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_R
:
1339 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_R
:
1344 #ifdef ENABLE_HYBRID
1345 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) {
1346 plog (ASL_LEVEL_NOTICE
, "Adding xauth VID payload.\n");
1347 if ((xauth_vid
= set_vendorid(VENDORID_XAUTH
)) == NULL
) {
1349 "Cannot create Xauth vendor ID\n");
1352 plist
= isakmp_plist_append(plist
,
1353 xauth_vid
, ISAKMP_NPTYPE_VID
);
1356 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_UNITY
) {
1357 if ((unity_vid
= set_vendorid(VENDORID_UNITY
)) == NULL
) {
1359 "Cannot create Unity vendor ID\n");
1362 plist
= isakmp_plist_append(plist
,
1363 unity_vid
, ISAKMP_NPTYPE_VID
);
1368 /* append NAT-T payloads */
1371 plist
= isakmp_plist_append(plist
, vid_natt
, ISAKMP_NPTYPE_VID
);
1373 /* old Apple version sends natd payloads in the wrong order */
1374 if (iph1
->natt_options
->version
== VENDORID_NATT_APPLE
) {
1375 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
1376 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
1379 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
1380 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
1387 plist
= isakmp_plist_append(plist
, vid_frag
, ISAKMP_NPTYPE_VID
);
1392 plist
= isakmp_plist_append(plist
, vid_dpd
, ISAKMP_NPTYPE_VID
);
1395 iph1
->sendbuf
= isakmp_plist_set_all (&plist
, iph1
);
1397 #ifdef HAVE_PRINT_ISAKMP_C
1398 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 1);
1401 /* send the packet, add to the schedule to resend */
1402 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
1403 if (isakmp_ph1resend(iph1
) == -1) {
1404 plog(ASL_LEVEL_ERR
,
1405 "failed to send packet");
1409 /* the sending message is added to the received-list. */
1410 if (ike_session_add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
,
1411 PH1_NON_ESP_EXTRA_LEN(iph1
, iph1
->sendbuf
), PH1_FRAG_FLAGS(iph1
)) == -1) {
1412 plog(ASL_LEVEL_ERR
,
1413 "failed to add a response packet to the tree.\n");
1417 fsm_set_state(&iph1
->status
, IKEV1_STATE_AGG_R_MSG2SENT
);
1419 #ifdef ENABLE_VPNCONTROL_PORT
1420 vpncontrol_notify_phase_change(1, FROM_LOCAL
, iph1
, NULL
);
1425 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1426 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
1427 CONSTSTR("Responder, Aggressive-Mode message 2"),
1432 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1433 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
1434 CONSTSTR("Responder, Aggressive-Mode Message 2"),
1435 CONSTSTR("Failed to process Aggressive-Mode Message 2"));
1439 #ifdef ENABLE_HYBRID
1466 * receive from initiator
1468 * gssapi: HDR, HASH_I
1469 * sig: HDR, [ CERT, ] SIG_I
1474 agg_r3recv(iph1
, msg0
)
1475 phase1_handle_t
*iph1
;
1478 vchar_t
*msg
= NULL
;
1479 vchar_t
*pbuf
= NULL
;
1480 struct isakmp_parse_t
*pa
;
1487 int received_cert
= 0;
1489 /* validity check */
1490 if (iph1
->status
!= IKEV1_STATE_AGG_R_MSG2SENT
) {
1492 "status mismatched %d.\n", iph1
->status
);
1496 /* decrypting if need. */
1497 /* XXX configurable ? */
1498 if (ISSET(((struct isakmp
*)msg0
->v
)->flags
, ISAKMP_FLAG_E
)) {
1499 msg
= oakley_do_decrypt(iph1
, msg0
,
1500 iph1
->ivm
->iv
, iph1
->ivm
->ive
);
1503 "failed to decrypt msg");
1509 /* validate the type of next payload */
1510 pbuf
= isakmp_parse(msg
);
1513 "failed to parse msg");
1517 iph1
->pl_hash
= NULL
;
1519 for (pa
= ALIGNED_CAST(struct isakmp_parse_t
*)pbuf
->v
;
1520 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1524 case ISAKMP_NPTYPE_HASH
:
1525 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
1527 case ISAKMP_NPTYPE_VID
:
1528 (void)check_vendorid(pa
->ptr
);
1530 case ISAKMP_NPTYPE_CERT
:
1531 if (oakley_savecert(iph1
, pa
->ptr
) < 0) {
1533 "failed to process CERT payload");
1538 case ISAKMP_NPTYPE_SIG
:
1539 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0) {
1541 "failed to process SIG payload");
1545 case ISAKMP_NPTYPE_N
:
1546 isakmp_check_notify(pa
->ptr
, iph1
);
1550 case ISAKMP_NPTYPE_NATD_DRAFT
:
1551 case ISAKMP_NPTYPE_NATD_RFC
:
1552 if (NATT_AVAILABLE(iph1
) && iph1
->natt_options
!= NULL
&&
1553 pa
->type
== iph1
->natt_options
->payload_nat_d
)
1555 vchar_t
*natd_received
= NULL
;
1558 if (isakmp_p2ph (&natd_received
, pa
->ptr
) < 0) {
1560 "failed to process NATD payload");
1565 iph1
->natt_flags
|= NAT_DETECTED
;
1567 natd_verified
= natt_compare_addr_hash (iph1
,
1568 natd_received
, natd_seq
++);
1570 plog (ASL_LEVEL_NOTICE
, "NAT-D payload #%d %s\n",
1572 natd_verified
? "verified" : "doesn't match");
1574 vfree (natd_received
);
1577 /* %%%% Be lenient here - some servers send natd payloads */
1578 /* when no nat is detected */
1583 /* don't send information, see isakmp_ident_r1() */
1585 "ignore the packet, "
1586 "received unexpecting payload type %d.\n",
1593 if (NATT_AVAILABLE(iph1
))
1594 plog (ASL_LEVEL_NOTICE
, "NAT %s %s%s\n",
1595 iph1
->natt_flags
& NAT_DETECTED
?
1596 "detected:" : "not detected",
1597 iph1
->natt_flags
& NAT_DETECTED_ME
? "ME " : "",
1598 iph1
->natt_flags
& NAT_DETECTED_PEER
? "PEER" : "");
1601 if (received_cert
) {
1602 oakley_verify_certid(iph1
);
1605 /* validate authentication value */
1606 ptype
= oakley_validate_auth(iph1
);
1608 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1609 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_FAIL
,
1610 CONSTSTR("Responder, Aggressive-Mode Message 3"),
1611 CONSTSTR("Failed to authenticate Aggressive-Mode Message 3"));
1613 /* message printed inner oakley_validate_auth() */
1616 isakmp_info_send_n1(iph1
, ptype
, NULL
);
1619 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1620 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_SUCC
,
1621 CONSTSTR("Responder, Aggressive-Mode Message 3"),
1624 fsm_set_state(&iph1
->status
, IKEV1_STATE_AGG_R_MSG3RCVD
);
1628 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1629 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
1630 CONSTSTR("Responder, Aggressive-Mode message 3"),
1635 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1636 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
1637 CONSTSTR("Responder, Aggressive-Mode Message 3"),
1638 CONSTSTR("Failed to process Aggressive-Mode Message 3"));
1645 oakley_delcert(iph1
->cert_p
);
1646 iph1
->cert_p
= NULL
;
1647 oakley_delcert(iph1
->crl_p
);
1649 VPTRINIT(iph1
->sig_p
);
1656 * status update and establish isakmp sa.
1659 agg_rfinalize(iph1
, msg
)
1660 phase1_handle_t
*iph1
;
1665 /* validity check */
1666 if (iph1
->status
!= IKEV1_STATE_AGG_R_MSG3RCVD
) {
1668 "status mismatched %d.\n", iph1
->status
);
1672 /* IV synchronized when packet encrypted. */
1673 /* see handler.h about IV synchronization. */
1674 if (ISSET(((struct isakmp
*)msg
->v
)->flags
, ISAKMP_FLAG_E
))
1675 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->l
);
1677 /* set encryption flag */
1678 iph1
->flags
|= ISAKMP_FLAG_E
;
1680 fsm_set_state(&iph1
->status
, IKEV1_STATE_PHASE1_ESTABLISHED
);
1682 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1683 IPSECSESSIONEVENTCODE_IKEV1_PH1_RESP_SUCC
,
1684 CONSTSTR("Responder, Aggressive-Mode"),