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 static vchar_t
*ident_ir2mx
__P((struct ph1handle
*));
99 static vchar_t
*ident_ir3mx
__P((struct ph1handle
*));
102 * begin Identity Protection Mode as initiator.
112 ident_i1send(iph1
, msg
)
113 struct ph1handle
*iph1
;
114 vchar_t
*msg
; /* must be null */
116 struct payload_list
*plist
= NULL
;
119 vchar_t
*vid_natt
[MAX_NATT_VID_COUNT
] = { NULL
};
123 vchar_t
*vid_xauth
= NULL
;
124 vchar_t
*vid_unity
= NULL
;
127 vchar_t
*vid_frag
= NULL
;
130 vchar_t
*vid_dpd
= NULL
;
134 plog(LLV_ERROR
, LOCATION
, NULL
,
135 "msg has to be NULL in this function.\n");
138 if (iph1
->status
!= PHASE1ST_START
) {
139 plog(LLV_ERROR
, LOCATION
, NULL
,
140 "status mismatched %d.\n", iph1
->status
);
144 /* create isakmp index */
145 memset(&iph1
->index
, 0, sizeof(iph1
->index
));
146 isakmp_newcookie((caddr_t
)&iph1
->index
, iph1
->remote
, iph1
->local
);
148 /* create SA payload for my proposal */
149 iph1
->sa
= ipsecdoi_setph1proposal(iph1
->rmconf
->proposal
);
150 if (iph1
->sa
== NULL
) {
151 plog(LLV_ERROR
, LOCATION
, NULL
,
152 "failed to set proposal");
156 /* set SA payload to propose */
157 plist
= isakmp_plist_append(plist
, iph1
->sa
, ISAKMP_NPTYPE_SA
);
160 /* set VID payload for NAT-T if NAT-T support allowed in the config file */
161 if (iph1
->rmconf
->nat_traversal
)
162 plist
= isakmp_plist_append_natt_vids(plist
, vid_natt
);
165 /* Do we need Xauth VID? */
166 switch (RMAUTHMETHOD(iph1
)) {
167 case FICTIVE_AUTH_METHOD_XAUTH_PSKEY_I
:
168 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
169 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I
:
170 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
171 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_I
:
172 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
173 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
174 if ((vid_xauth
= set_vendorid(VENDORID_XAUTH
)) == NULL
)
175 plog(LLV_ERROR
, LOCATION
, NULL
,
176 "Xauth vendor ID generation failed\n");
178 plist
= isakmp_plist_append(plist
,
179 vid_xauth
, ISAKMP_NPTYPE_VID
);
181 if ((vid_unity
= set_vendorid(VENDORID_UNITY
)) == NULL
)
182 plog(LLV_ERROR
, LOCATION
, NULL
,
183 "Unity vendor ID generation failed\n");
185 plist
= isakmp_plist_append(plist
,
186 vid_unity
, ISAKMP_NPTYPE_VID
);
193 if (iph1
->rmconf
->ike_frag
) {
194 if ((vid_frag
= set_vendorid(VENDORID_FRAG
)) == NULL
) {
195 plog(LLV_ERROR
, LOCATION
, NULL
,
196 "Frag vendorID construction failed\n");
198 vid_frag
= isakmp_frag_addcap(vid_frag
,
199 VENDORID_FRAG_IDENT
);
200 plist
= isakmp_plist_append(plist
,
201 vid_frag
, ISAKMP_NPTYPE_VID
);
206 if(iph1
->rmconf
->dpd
){
207 vid_dpd
= set_vendorid(VENDORID_DPD
);
209 plist
= isakmp_plist_append(plist
, vid_dpd
,
214 iph1
->sendbuf
= isakmp_plist_set_all (&plist
, iph1
);
216 #ifdef HAVE_PRINT_ISAKMP_C
217 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
220 /* send the packet, add to the schedule to resend */
221 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
222 if (isakmp_ph1resend(iph1
) == -1) {
223 plog(LLV_ERROR
, LOCATION
, NULL
,
224 "failed to send packet");
228 iph1
->status
= PHASE1ST_MSG1SENT
;
232 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
233 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
234 CONSTSTR("Initiator, Main-Mode message 1"),
239 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
240 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
241 CONSTSTR("Initiator, Main-Mode Message 1"),
242 CONSTSTR("Failed to transmit Main-Mode Message 1"));
249 for (i
= 0; i
< MAX_NATT_VID_COUNT
&& vid_natt
[i
] != NULL
; i
++)
253 if (vid_xauth
!= NULL
)
255 if (vid_unity
!= NULL
)
267 * receive from responder
274 ident_i2recv(iph1
, msg
)
275 struct ph1handle
*iph1
;
278 vchar_t
*pbuf
= NULL
;
279 struct isakmp_parse_t
*pa
;
280 vchar_t
*satmp
= NULL
;
285 if (iph1
->status
!= PHASE1ST_MSG1SENT
) {
286 plog(LLV_ERROR
, LOCATION
, NULL
,
287 "status mismatched %d.\n", iph1
->status
);
291 /* validate the type of next payload */
293 * NOTE: RedCreek(as responder) attaches N[responder-lifetime] here,
294 * if proposal-lifetime > lifetime-redcreek-wants.
296 * => According to the seciton 4.6.3 in RFC 2407, This is illegal.
297 * NOTE: we do not really care about ordering of VID and N.
299 * NOTE: even if there's multiple VID/N, we'll ignore them.
301 pbuf
= isakmp_parse(msg
);
303 plog(LLV_ERROR
, LOCATION
, NULL
,
304 "failed to parse msg");
307 pa
= (struct isakmp_parse_t
*)pbuf
->v
;
309 /* SA payload is fixed postion */
310 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
311 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
312 "received invalid next payload type %d, "
314 pa
->type
, ISAKMP_NPTYPE_SA
);
317 if (isakmp_p2ph(&satmp
, pa
->ptr
) < 0) {
318 plog(LLV_ERROR
, LOCATION
, NULL
,
319 "failed to process SA payload");
325 pa
->type
!= ISAKMP_NPTYPE_NONE
;
329 case ISAKMP_NPTYPE_VID
:
330 vid_numeric
= check_vendorid(pa
->ptr
);
332 if (iph1
->rmconf
->nat_traversal
&& natt_vendorid(vid_numeric
))
333 natt_handle_vendorid(iph1
, vid_numeric
);
336 switch (vid_numeric
) {
338 iph1
->mode_cfg
->flags
|=
339 ISAKMP_CFG_VENDORID_XAUTH
;
343 iph1
->mode_cfg
->flags
|=
344 ISAKMP_CFG_VENDORID_UNITY
;
352 if (vid_numeric
== VENDORID_DPD
&& iph1
->rmconf
->dpd
)
357 /* don't send information, see ident_r1recv() */
358 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
359 "ignore the packet, "
360 "received unexpecting payload type %d.\n",
367 if (NATT_AVAILABLE(iph1
)) {
368 plog(LLV_INFO
, LOCATION
, iph1
->remote
,
369 "Selected NAT-T version: %s\n",
370 vid_string_by_id(iph1
->natt_options
->version
));
371 ike_session_update_natt_version(iph1
);
375 /* check SA payload and set approval SA for use */
376 if (ipsecdoi_checkph1proposal(satmp
, iph1
) < 0) {
377 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
378 "failed to get valid proposal.\n");
379 /* XXX send information */
382 VPTRINIT(iph1
->sa_ret
);
384 iph1
->status
= PHASE1ST_MSG2RECEIVED
;
386 #ifdef ENABLE_VPNCONTROL_PORT
387 vpncontrol_notify_phase_change(1, FROM_REMOTE
, iph1
, NULL
);
392 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
393 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
394 CONSTSTR("Initiator, Main-Mode message 2"),
399 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
400 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
401 CONSTSTR("Initiator, Main-Mode Message 2"),
402 CONSTSTR("Failed to process Main-Mode Message 2"));
415 * gssapi: HDR, KE, Ni, GSSi
416 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
417 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
418 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
421 ident_i2send(iph1
, msg
)
422 struct ph1handle
*iph1
;
428 if (iph1
->status
!= PHASE1ST_MSG2RECEIVED
) {
429 plog(LLV_ERROR
, LOCATION
, NULL
,
430 "status mismatched %d.\n", iph1
->status
);
434 /* fix isakmp index */
435 memcpy(&iph1
->index
.r_ck
, &((struct isakmp
*)msg
->v
)->r_ck
,
438 /* generate DH public value */
439 if (oakley_dh_generate(iph1
->approval
->dhgrp
,
440 &iph1
->dhpub
, &iph1
->dhpriv
) < 0) {
441 plog(LLV_ERROR
, LOCATION
, NULL
,
442 "failed to generate DH");
446 /* generate NONCE value */
447 iph1
->nonce
= eay_set_random(iph1
->rmconf
->nonce_size
);
448 if (iph1
->nonce
== NULL
) {
449 plog(LLV_ERROR
, LOCATION
, NULL
,
450 "failed to generate NONCE");
455 if (AUTHMETHOD(iph1
) == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
456 gssapi_get_itoken(iph1
, NULL
) < 0) {
457 plog(LLV_ERROR
, LOCATION
, NULL
,
458 "failed to get GSS token");
463 /* create buffer to send isakmp payload */
464 iph1
->sendbuf
= ident_ir2mx(iph1
);
465 if (iph1
->sendbuf
== NULL
) {
466 plog(LLV_ERROR
, LOCATION
, NULL
,
467 "failed to create send buffer");
471 #ifdef HAVE_PRINT_ISAKMP_C
472 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
475 /* send the packet, add to the schedule to resend */
476 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
477 if (isakmp_ph1resend(iph1
) == -1) {
478 plog(LLV_ERROR
, LOCATION
, NULL
,
479 "failed to send packet");
483 /* the sending message is added to the received-list. */
484 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
,
485 PH1_NON_ESP_EXTRA_LEN(iph1
)) == -1) {
486 plog(LLV_ERROR
, LOCATION
, NULL
,
487 "failed to add a response packet to the tree.\n");
491 iph1
->status
= PHASE1ST_MSG2SENT
;
495 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
496 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
497 CONSTSTR("Initiator, Main-Mode message 3"),
502 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
503 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
504 CONSTSTR("Initiator, Main-Mode Message 3"),
505 CONSTSTR("Failed to transmit Main-Mode Message 3"));
511 * receive from responder
513 * sig: HDR, KE, Nr [, CR ]
514 * gssapi: HDR, KE, Nr, GSSr
515 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
516 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
519 ident_i3recv(iph1
, msg
)
520 struct ph1handle
*iph1
;
523 vchar_t
*pbuf
= NULL
;
524 struct isakmp_parse_t
*pa
;
528 vchar_t
*gsstoken
= NULL
;
531 vchar_t
*natd_received
;
532 int natd_seq
= 0, natd_verified
;
536 if (iph1
->status
!= PHASE1ST_MSG2SENT
) {
537 plog(LLV_ERROR
, LOCATION
, NULL
,
538 "status mismatched %d.\n", iph1
->status
);
542 /* validate the type of next payload */
543 pbuf
= isakmp_parse(msg
);
545 plog(LLV_ERROR
, LOCATION
, NULL
,
546 "failed to parse msg");
550 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
551 pa
->type
!= ISAKMP_NPTYPE_NONE
;
555 case ISAKMP_NPTYPE_KE
:
556 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0) {
557 plog(LLV_ERROR
, LOCATION
, NULL
,
558 "failed to process KE payload");
562 case ISAKMP_NPTYPE_NONCE
:
563 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0) {
564 plog(LLV_ERROR
, LOCATION
, NULL
,
565 "failed to process NONCE payload");
569 case ISAKMP_NPTYPE_VID
:
570 vid_numeric
= check_vendorid(pa
->ptr
);
572 switch (vid_numeric
) {
574 iph1
->mode_cfg
->flags
|=
575 ISAKMP_CFG_VENDORID_XAUTH
;
579 iph1
->mode_cfg
->flags
|=
580 ISAKMP_CFG_VENDORID_UNITY
;
588 if (vid_numeric
== VENDORID_DPD
&& iph1
->rmconf
->dpd
)
593 case ISAKMP_NPTYPE_CR
:
594 if (oakley_savecr(iph1
, pa
->ptr
) < 0) {
595 plog(LLV_ERROR
, LOCATION
, NULL
,
596 "failed to process CR payload");
601 case ISAKMP_NPTYPE_GSS
:
602 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0) {
603 plog(LLV_ERROR
, LOCATION
, NULL
,
604 "failed to process GSS payload");
607 gssapi_save_received_token(iph1
, gsstoken
);
612 case ISAKMP_NPTYPE_NATD_DRAFT
:
613 case ISAKMP_NPTYPE_NATD_RFC
:
615 case ISAKMP_NPTYPE_NATD_BADDRAFT
:
617 if (NATT_AVAILABLE(iph1
) && iph1
->natt_options
!= NULL
&&
618 pa
->type
== iph1
->natt_options
->payload_nat_d
) {
619 natd_received
= NULL
;
620 if (isakmp_p2ph (&natd_received
, pa
->ptr
) < 0) {
621 plog(LLV_ERROR
, LOCATION
, NULL
,
622 "failed to process NATD payload");
626 /* set both bits first so that we can clear them
627 upon verifying hashes */
629 iph1
->natt_flags
|= NAT_DETECTED
;
631 /* this function will clear appropriate bits bits
632 from iph1->natt_flags */
633 natd_verified
= natt_compare_addr_hash (iph1
,
634 natd_received
, natd_seq
++);
636 plog (LLV_INFO
, LOCATION
, NULL
, "NAT-D payload #%d %s\n",
638 natd_verified
? "verified" : "doesn't match");
640 vfree (natd_received
);
643 /* %%%% Be lenient here - some servers send natd payloads */
644 /* when no nat is detected */
649 /* don't send information, see ident_r1recv() */
650 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
651 "ignore the packet, "
652 "received unexpecting payload type %d.\n",
659 if (NATT_AVAILABLE(iph1
)) {
660 plog (LLV_INFO
, LOCATION
, NULL
, "NAT %s %s%s\n",
661 iph1
->natt_flags
& NAT_DETECTED
?
662 "detected:" : "not detected",
663 iph1
->natt_flags
& NAT_DETECTED_ME
? "ME " : "",
664 iph1
->natt_flags
& NAT_DETECTED_PEER
? "PEER" : "");
665 if (iph1
->natt_flags
& NAT_DETECTED
)
666 natt_float_ports (iph1
);
670 /* payload existency check */
671 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
672 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
673 "few isakmp message received.\n");
677 if (oakley_checkcr(iph1
) < 0) {
678 /* Ignore this error in order to be interoperability. */
682 iph1
->status
= PHASE1ST_MSG3RECEIVED
;
686 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
687 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
688 CONSTSTR("Initiator, Main-Mode message 4"),
693 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
694 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
695 CONSTSTR("Initiator, Main-Mode Message 4"),
696 CONSTSTR("Failed to process Main-Mode Message 4"));
705 VPTRINIT(iph1
->dhpub_p
);
706 VPTRINIT(iph1
->nonce_p
);
707 VPTRINIT(iph1
->id_p
);
708 oakley_delcert(iph1
->cr_p
);
717 * psk: HDR*, IDi1, HASH_I
718 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
719 * gssapi: HDR*, IDi1, < Gssi(n) | HASH_I >
724 ident_i3send(iph1
, msg0
)
725 struct ph1handle
*iph1
;
735 if (iph1
->status
!= PHASE1ST_MSG3RECEIVED
) {
736 plog(LLV_ERROR
, LOCATION
, NULL
,
737 "status mismatched %d.\n", iph1
->status
);
741 /* compute sharing secret of DH */
742 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub
,
743 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0) {
744 plog(LLV_ERROR
, LOCATION
, NULL
,
745 "failed to compute DH");
749 /* generate SKEYIDs & IV & final cipher key */
750 if (oakley_skeyid(iph1
) < 0) {
751 plog(LLV_ERROR
, LOCATION
, NULL
,
752 "failed to generate SKEYID");
755 if (oakley_skeyid_dae(iph1
) < 0) {
756 plog(LLV_ERROR
, LOCATION
, NULL
,
757 "failed to generate SKEYID-DAE");
760 if (oakley_compute_enckey(iph1
) < 0) {
761 plog(LLV_ERROR
, LOCATION
, NULL
,
762 "failed to generate ENCKEY");
765 if (oakley_newiv(iph1
) < 0) {
766 plog(LLV_ERROR
, LOCATION
, NULL
,
767 "failed to generate IV");
771 /* make ID payload into isakmp status */
772 if (ipsecdoi_setid1(iph1
) < 0) {
773 plog(LLV_ERROR
, LOCATION
, NULL
,
779 if (AUTHMETHOD(iph1
) == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
780 gssapi_more_tokens(iph1
)) {
781 plog(LLV_DEBUG
, LOCATION
, NULL
, "calling get_itoken\n");
782 if (gssapi_get_itoken(iph1
, &len
) < 0) {
783 plog(LLV_ERROR
, LOCATION
, NULL
,
784 "failed to get GSSAPI token");
792 /* generate HASH to send */
794 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
795 if (iph1
->hash
== NULL
) {
796 plog(LLV_ERROR
, LOCATION
, NULL
,
797 "failed to generate HASH");
803 /* set encryption flag */
804 iph1
->flags
|= ISAKMP_FLAG_E
;
806 /* create HDR;ID;HASH payload */
807 iph1
->sendbuf
= ident_ir3mx(iph1
);
808 if (iph1
->sendbuf
== NULL
) {
809 plog(LLV_ERROR
, LOCATION
, NULL
,
810 "failed to allocate send buffer");
814 /* send the packet, add to the schedule to resend */
815 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
816 if (isakmp_ph1resend(iph1
) == -1) {
817 plog(LLV_ERROR
, LOCATION
, NULL
,
818 "failed to send packet");
822 /* the sending message is added to the received-list. */
823 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg0
,
824 PH1_NON_ESP_EXTRA_LEN(iph1
)) == -1) {
825 plog(LLV_ERROR
, LOCATION
, NULL
,
826 "failed to add a response packet to the tree.\n");
830 /* see handler.h about IV synchronization. */
831 memcpy(iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->v
, iph1
->ivm
->iv
->l
);
833 iph1
->status
= PHASE1ST_MSG3SENT
;
837 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
838 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
839 CONSTSTR("Initiator, Main-Mode message 5"),
844 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
845 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
846 CONSTSTR("Initiator, Main-Mode Message 5"),
847 CONSTSTR("Failed to transmit Main-Mode Message 5"));
853 * receive from responder
854 * psk: HDR*, IDr1, HASH_R
855 * sig: HDR*, IDr1, [ CERT, ] SIG_R
856 * gssapi: HDR*, IDr1, < GSSr(n) | HASH_R >
861 ident_i4recv(iph1
, msg0
)
862 struct ph1handle
*iph1
;
865 vchar_t
*pbuf
= NULL
;
866 struct isakmp_parse_t
*pa
;
872 vchar_t
*gsstoken
= NULL
;
876 if (iph1
->status
!= PHASE1ST_MSG3SENT
) {
877 plog(LLV_ERROR
, LOCATION
, NULL
,
878 "status mismatched %d.\n", iph1
->status
);
883 if (!ISSET(((struct isakmp
*)msg0
->v
)->flags
, ISAKMP_FLAG_E
)) {
884 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
885 "ignore the packet, "
886 "expecting the packet encrypted.\n");
889 msg
= oakley_do_decrypt(iph1
, msg0
, iph1
->ivm
->iv
, iph1
->ivm
->ive
);
891 plog(LLV_ERROR
, LOCATION
, NULL
,
892 "failed to decrypt");
896 /* validate the type of next payload */
897 pbuf
= isakmp_parse(msg
);
899 plog(LLV_ERROR
, LOCATION
, NULL
,
900 "failed to parse msg");
904 iph1
->pl_hash
= NULL
;
906 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
907 pa
->type
!= ISAKMP_NPTYPE_NONE
;
911 case ISAKMP_NPTYPE_ID
:
912 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0) {
913 plog(LLV_ERROR
, LOCATION
, NULL
,
914 "failed to process ID payload");
918 case ISAKMP_NPTYPE_HASH
:
919 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
921 case ISAKMP_NPTYPE_CERT
:
922 if (oakley_savecert(iph1
, pa
->ptr
) < 0) {
923 plog(LLV_ERROR
, LOCATION
, NULL
,
924 "failed to process CERT payload");
928 case ISAKMP_NPTYPE_SIG
:
929 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0) {
930 plog(LLV_ERROR
, LOCATION
, NULL
,
931 "failed to process SIG payload");
936 case ISAKMP_NPTYPE_GSS
:
937 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0) {
938 plog(LLV_ERROR
, LOCATION
, NULL
,
939 "failed to process GSS payload");
942 gssapi_save_received_token(iph1
, gsstoken
);
945 case ISAKMP_NPTYPE_VID
:
946 vid_numeric
= check_vendorid(pa
->ptr
);
948 if (vid_numeric
== VENDORID_DPD
&& iph1
->rmconf
->dpd
)
952 case ISAKMP_NPTYPE_N
:
953 isakmp_check_notify(pa
->ptr
, iph1
);
956 /* don't send information, see ident_r1recv() */
957 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
958 "ignore the packet, "
959 "received unexpecting payload type %d.\n",
965 /* payload existency check */
967 /* verify identifier */
968 if (ipsecdoi_checkid1(iph1
) != 0) {
969 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
970 "invalid ID payload.\n");
974 /* validate authentication value */
976 if (gsstoken
== NULL
) {
978 type
= oakley_validate_auth(iph1
);
980 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
981 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_FAIL
,
982 CONSTSTR("Initiator, Main-Mode Message 6"),
983 CONSTSTR("Failed to authenticate Main-Mode Message 6"));
985 /* msg printed inner oakley_validate_auth() */
988 EVT_PUSH(iph1
->local
, iph1
->remote
,
989 EVTT_PEERPH1AUTH_FAILED
, NULL
);
990 isakmp_info_send_n1(iph1
, type
, NULL
);
993 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
994 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_SUCC
,
995 CONSTSTR("Initiator, Main-Mode Message 6"),
1002 * XXX: Should we do compare two addresses, ph1handle's and ID
1006 plog(LLV_DEBUG
, LOCATION
, iph1
->remote
, "peer's ID:");
1007 plogdump(LLV_DEBUG
, iph1
->id_p
->v
, iph1
->id_p
->l
);
1009 /* see handler.h about IV synchronization. */
1010 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->ive
->l
);
1013 * If we got a GSS token, we need to this roundtrip again.
1016 iph1
->status
= gsstoken
!= 0 ? PHASE1ST_MSG3RECEIVED
:
1017 PHASE1ST_MSG4RECEIVED
;
1019 iph1
->status
= PHASE1ST_MSG4RECEIVED
;
1024 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1025 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
1026 CONSTSTR("Initiator, Main-Mode message 6"),
1031 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1032 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
1033 CONSTSTR("Initiator, Main-Mode Message 6"),
1034 CONSTSTR("Failed to transmit Main-Mode Message 6"));
1046 VPTRINIT(iph1
->id_p
);
1047 oakley_delcert(iph1
->cert_p
);
1048 iph1
->cert_p
= NULL
;
1049 oakley_delcert(iph1
->crl_p
);
1051 VPTRINIT(iph1
->sig_p
);
1058 * status update and establish isakmp sa.
1061 ident_i4send(iph1
, msg
)
1062 struct ph1handle
*iph1
;
1067 /* validity check */
1068 if (iph1
->status
!= PHASE1ST_MSG4RECEIVED
) {
1069 plog(LLV_ERROR
, LOCATION
, NULL
,
1070 "status mismatched %d.\n", iph1
->status
);
1074 /* see handler.h about IV synchronization. */
1075 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->l
);
1077 iph1
->status
= PHASE1ST_ESTABLISHED
;
1079 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1080 IPSECSESSIONEVENTCODE_IKEV1_PH1_INIT_SUCC
,
1081 CONSTSTR("Initiator, Main-Mode"),
1091 * receive from initiator
1098 ident_r1recv(iph1
, msg
)
1099 struct ph1handle
*iph1
;
1102 vchar_t
*pbuf
= NULL
;
1103 struct isakmp_parse_t
*pa
;
1107 /* validity check */
1108 if (iph1
->status
!= PHASE1ST_START
) {
1109 plog(LLV_ERROR
, LOCATION
, NULL
,
1110 "status mismatched %d.\n", iph1
->status
);
1114 /* validate the type of next payload */
1116 * NOTE: XXX even if multiple VID, we'll silently ignore those.
1118 pbuf
= isakmp_parse(msg
);
1120 plog(LLV_ERROR
, LOCATION
, NULL
,
1121 "failed to parse msg");
1124 pa
= (struct isakmp_parse_t
*)pbuf
->v
;
1126 /* check the position of SA payload */
1127 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
1128 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1129 "received invalid next payload type %d, "
1131 pa
->type
, ISAKMP_NPTYPE_SA
);
1134 if (isakmp_p2ph(&iph1
->sa
, pa
->ptr
) < 0) {
1135 plog(LLV_ERROR
, LOCATION
, NULL
,
1136 "failed to process SA payload");
1142 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1146 case ISAKMP_NPTYPE_VID
:
1147 vid_numeric
= check_vendorid(pa
->ptr
);
1149 if (iph1
->rmconf
->nat_traversal
&& natt_vendorid(vid_numeric
))
1150 natt_handle_vendorid(iph1
, vid_numeric
);
1153 if ((vid_numeric
== VENDORID_FRAG
) &&
1154 (vendorid_frag_cap(pa
->ptr
) & VENDORID_FRAG_IDENT
))
1157 #ifdef ENABLE_HYBRID
1158 switch (vid_numeric
) {
1159 case VENDORID_XAUTH
:
1160 iph1
->mode_cfg
->flags
|=
1161 ISAKMP_CFG_VENDORID_XAUTH
;
1164 case VENDORID_UNITY
:
1165 iph1
->mode_cfg
->flags
|=
1166 ISAKMP_CFG_VENDORID_UNITY
;
1174 if (vid_numeric
== VENDORID_DPD
&& iph1
->rmconf
->dpd
)
1175 iph1
->dpd_support
=1;
1180 * We don't send information to the peer even
1181 * if we received malformed packet. Because we
1182 * can't distinguish the malformed packet and
1183 * the re-sent packet. And we do same behavior
1184 * when we expect encrypted packet.
1186 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1187 "ignore the packet, "
1188 "received unexpecting payload type %d.\n",
1195 if (NATT_AVAILABLE(iph1
)) {
1196 plog(LLV_INFO
, LOCATION
, iph1
->remote
,
1197 "Selected NAT-T version: %s\n",
1198 vid_string_by_id(iph1
->natt_options
->version
));
1199 ike_session_update_natt_version(iph1
);
1203 /* check SA payload and set approval SA for use */
1204 if (ipsecdoi_checkph1proposal(iph1
->sa
, iph1
) < 0) {
1205 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1206 "failed to get valid proposal.\n");
1207 /* XXX send information */
1211 iph1
->status
= PHASE1ST_MSG1RECEIVED
;
1215 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1216 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
1217 CONSTSTR("Responder, Main-Mode message 1"),
1222 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1223 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
1224 CONSTSTR("Responder, Main-Mode Message 1"),
1225 CONSTSTR("Failed to process Main-Mode Message 1"));
1244 ident_r1send(iph1
, msg
)
1245 struct ph1handle
*iph1
;
1248 struct payload_list
*plist
= NULL
;
1250 vchar_t
*gss_sa
= NULL
;
1252 int free_gss_sa
= 0;
1255 vchar_t
*vid_natt
= NULL
;
1257 #ifdef ENABLE_HYBRID
1258 vchar_t
*vid_xauth
= NULL
;
1259 vchar_t
*vid_unity
= NULL
;
1262 vchar_t
*vid_dpd
= NULL
;
1265 vchar_t
*vid_frag
= NULL
;
1268 /* validity check */
1269 if (iph1
->status
!= PHASE1ST_MSG1RECEIVED
) {
1270 plog(LLV_ERROR
, LOCATION
, NULL
,
1271 "status mismatched %d.\n", iph1
->status
);
1275 /* set responder's cookie */
1276 isakmp_newcookie((caddr_t
)&iph1
->index
.r_ck
, iph1
->remote
, iph1
->local
);
1279 if (iph1
->approval
->gssid
!= NULL
) {
1280 gss_sa
= ipsecdoi_setph1proposal(iph1
->approval
);
1281 if (gss_sa
!= iph1
->sa_ret
)
1285 gss_sa
= iph1
->sa_ret
;
1287 /* set SA payload to reply */
1288 plist
= isakmp_plist_append(plist
, gss_sa
, ISAKMP_NPTYPE_SA
);
1290 #ifdef ENABLE_HYBRID
1291 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) {
1292 plog (LLV_INFO
, LOCATION
, NULL
, "Adding xauth VID payload.\n");
1293 if ((vid_xauth
= set_vendorid(VENDORID_XAUTH
)) == NULL
) {
1294 plog(LLV_ERROR
, LOCATION
, NULL
,
1295 "Cannot create Xauth vendor ID\n");
1298 plist
= isakmp_plist_append(plist
,
1299 vid_xauth
, ISAKMP_NPTYPE_VID
);
1302 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_UNITY
) {
1303 if ((vid_unity
= set_vendorid(VENDORID_UNITY
)) == NULL
) {
1304 plog(LLV_ERROR
, LOCATION
, NULL
,
1305 "Cannot create Unity vendor ID\n");
1308 plist
= isakmp_plist_append(plist
,
1309 vid_unity
, ISAKMP_NPTYPE_VID
);
1313 /* Has the peer announced NAT-T? */
1314 if (NATT_AVAILABLE(iph1
))
1315 vid_natt
= set_vendorid(iph1
->natt_options
->version
);
1318 plist
= isakmp_plist_append(plist
, vid_natt
, ISAKMP_NPTYPE_VID
);
1321 /* XXX only send DPD VID if remote sent it ? */
1322 if(iph1
->rmconf
->dpd
){
1323 vid_dpd
= set_vendorid(VENDORID_DPD
);
1324 if (vid_dpd
!= NULL
)
1325 plist
= isakmp_plist_append(plist
, vid_dpd
, ISAKMP_NPTYPE_VID
);
1330 vid_frag
= set_vendorid(VENDORID_FRAG
);
1331 if (vid_frag
!= NULL
)
1332 vid_frag
= isakmp_frag_addcap(vid_frag
,
1333 VENDORID_FRAG_IDENT
);
1334 if (vid_frag
== NULL
)
1335 plog(LLV_ERROR
, LOCATION
, NULL
,
1336 "Frag vendorID construction failed\n");
1338 plist
= isakmp_plist_append(plist
,
1339 vid_frag
, ISAKMP_NPTYPE_VID
);
1343 iph1
->sendbuf
= isakmp_plist_set_all (&plist
, iph1
);
1345 #ifdef HAVE_PRINT_ISAKMP_C
1346 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
1349 /* send the packet, add to the schedule to resend */
1350 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
1351 if (isakmp_ph1resend(iph1
) == -1) {
1352 plog(LLV_ERROR
, LOCATION
, NULL
,
1353 "failed to send packet");
1357 /* the sending message is added to the received-list. */
1358 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
,
1359 PH1_NON_ESP_EXTRA_LEN(iph1
)) == -1) {
1360 plog(LLV_ERROR
, LOCATION
, NULL
,
1361 "failed to add a response packet to the tree.\n");
1365 iph1
->status
= PHASE1ST_MSG1SENT
;
1367 #ifdef ENABLE_VPNCONTROL_PORT
1368 vpncontrol_notify_phase_change(1, FROM_LOCAL
, iph1
, NULL
);
1373 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1374 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
1375 CONSTSTR("Responder, Main-Mode message 2"),
1380 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1381 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
1382 CONSTSTR("Responder, Main-Mode Message 2"),
1383 CONSTSTR("Failed to transmit Main-Mode Message 2"));
1393 #ifdef ENABLE_HYBRID
1394 if (vid_xauth
!= NULL
)
1396 if (vid_unity
!= NULL
)
1400 if (vid_dpd
!= NULL
)
1404 if (vid_frag
!= NULL
)
1412 * receive from initiator
1415 * gssapi: HDR, KE, Ni, GSSi
1416 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
1417 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
1418 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
1421 ident_r2recv(iph1
, msg
)
1422 struct ph1handle
*iph1
;
1425 vchar_t
*pbuf
= NULL
;
1426 struct isakmp_parse_t
*pa
;
1429 vchar_t
*gsstoken
= NULL
;
1435 /* validity check */
1436 if (iph1
->status
!= PHASE1ST_MSG1SENT
) {
1437 plog(LLV_ERROR
, LOCATION
, NULL
,
1438 "status mismatched %d.\n", iph1
->status
);
1442 /* validate the type of next payload */
1443 pbuf
= isakmp_parse(msg
);
1445 plog(LLV_ERROR
, LOCATION
, NULL
,
1446 "failed to parse msg");
1450 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
1451 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1454 case ISAKMP_NPTYPE_KE
:
1455 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0) {
1456 plog(LLV_ERROR
, LOCATION
, NULL
,
1457 "failed to process KE payload");
1461 case ISAKMP_NPTYPE_NONCE
:
1462 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0) {
1463 plog(LLV_ERROR
, LOCATION
, NULL
,
1464 "failed to process NONCE payload");
1468 case ISAKMP_NPTYPE_VID
:
1469 (void)check_vendorid(pa
->ptr
);
1471 case ISAKMP_NPTYPE_CR
:
1472 plog(LLV_WARNING
, LOCATION
, iph1
->remote
,
1473 "CR received, ignore it. "
1474 "It should be in other exchange.\n");
1477 case ISAKMP_NPTYPE_GSS
:
1478 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0) {
1479 plog(LLV_ERROR
, LOCATION
, NULL
,
1480 "failed to process GSS payload");
1483 gssapi_save_received_token(iph1
, gsstoken
);
1488 case ISAKMP_NPTYPE_NATD_DRAFT
:
1489 case ISAKMP_NPTYPE_NATD_RFC
:
1491 case ISAKMP_NPTYPE_NATD_BADDRAFT
:
1493 if (NATT_AVAILABLE(iph1
) && iph1
->natt_options
!= NULL
&&
1494 pa
->type
== iph1
->natt_options
->payload_nat_d
)
1496 vchar_t
*natd_received
= NULL
;
1499 if (isakmp_p2ph (&natd_received
, pa
->ptr
) < 0) {
1500 plog(LLV_ERROR
, LOCATION
, NULL
,
1501 "failed to process NATD payload");
1506 iph1
->natt_flags
|= NAT_DETECTED
;
1508 natd_verified
= natt_compare_addr_hash (iph1
,
1509 natd_received
, natd_seq
++);
1511 plog (LLV_INFO
, LOCATION
, NULL
, "NAT-D payload #%d %s\n",
1513 natd_verified
? "verified" : "doesn't match");
1515 vfree (natd_received
);
1518 /* %%%% Be lenient here - some servers send natd payloads */
1519 /* when no nat is detected */
1524 /* don't send information, see ident_r1recv() */
1525 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1526 "ignore the packet, "
1527 "received unexpecting payload type %d.\n",
1534 if (NATT_AVAILABLE(iph1
))
1535 plog (LLV_INFO
, LOCATION
, NULL
, "NAT %s %s%s\n",
1536 iph1
->natt_flags
& NAT_DETECTED
?
1537 "detected:" : "not detected",
1538 iph1
->natt_flags
& NAT_DETECTED_ME
? "ME " : "",
1539 iph1
->natt_flags
& NAT_DETECTED_PEER
? "PEER" : "");
1542 /* payload existency check */
1543 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
1544 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1545 "few isakmp message received.\n");
1549 iph1
->status
= PHASE1ST_MSG2RECEIVED
;
1553 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1554 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
1555 CONSTSTR("Responder, Main-Mode message 3"),
1560 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1561 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
1562 CONSTSTR("Responder, Main-Mode Message 3"),
1563 CONSTSTR("Failed to process Main-Mode Message 3"));
1573 VPTRINIT(iph1
->dhpub_p
);
1574 VPTRINIT(iph1
->nonce_p
);
1575 VPTRINIT(iph1
->id_p
);
1584 * sig: HDR, KE, Nr [, CR ]
1585 * gssapi: HDR, KE, Nr, GSSr
1586 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
1587 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
1590 ident_r2send(iph1
, msg
)
1591 struct ph1handle
*iph1
;
1596 /* validity check */
1597 if (iph1
->status
!= PHASE1ST_MSG2RECEIVED
) {
1598 plog(LLV_ERROR
, LOCATION
, NULL
,
1599 "status mismatched %d.\n", iph1
->status
);
1603 /* generate DH public value */
1604 if (oakley_dh_generate(iph1
->approval
->dhgrp
,
1605 &iph1
->dhpub
, &iph1
->dhpriv
) < 0) {
1606 plog(LLV_ERROR
, LOCATION
, NULL
,
1607 "failed to generate DH");
1611 /* generate NONCE value */
1612 iph1
->nonce
= eay_set_random(iph1
->rmconf
->nonce_size
);
1613 if (iph1
->nonce
== NULL
) {
1614 plog(LLV_ERROR
, LOCATION
, NULL
,
1615 "failed to generate NONCE");
1620 if (AUTHMETHOD(iph1
) == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
1621 gssapi_get_rtoken(iph1
, NULL
);
1624 /* create HDR;KE;NONCE payload */
1625 iph1
->sendbuf
= ident_ir2mx(iph1
);
1626 if (iph1
->sendbuf
== NULL
) {
1627 plog(LLV_ERROR
, LOCATION
, NULL
,
1628 "failed to allocate send buffer");
1632 #ifdef HAVE_PRINT_ISAKMP_C
1633 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
1636 /* send the packet, add to the schedule to resend */
1637 iph1
->retry_counter
= iph1
->rmconf
->retry_counter
;
1638 if (isakmp_ph1resend(iph1
) == -1) {
1639 plog(LLV_ERROR
, LOCATION
, NULL
,
1640 "failed to send packet");
1644 /* the sending message is added to the received-list. */
1645 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
,
1646 PH1_NON_ESP_EXTRA_LEN(iph1
)) == -1) {
1647 plog(LLV_ERROR
, LOCATION
, NULL
,
1648 "failed to add a response packet to the tree.\n");
1652 /* compute sharing secret of DH */
1653 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub
,
1654 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0) {
1655 plog(LLV_ERROR
, LOCATION
, NULL
,
1656 "failed to compute DH");
1660 /* generate SKEYIDs & IV & final cipher key */
1661 if (oakley_skeyid(iph1
) < 0) {
1662 plog(LLV_ERROR
, LOCATION
, NULL
,
1663 "failed to generate SKEYID");
1666 if (oakley_skeyid_dae(iph1
) < 0) {
1667 plog(LLV_ERROR
, LOCATION
, NULL
,
1668 "failed to generate SKEYID-DAE");
1671 if (oakley_compute_enckey(iph1
) < 0) {
1672 plog(LLV_ERROR
, LOCATION
, NULL
,
1673 "failed to generate ENCKEY");
1676 if (oakley_newiv(iph1
) < 0) {
1677 plog(LLV_ERROR
, LOCATION
, NULL
,
1678 "failed to generate IV");
1682 iph1
->status
= PHASE1ST_MSG2SENT
;
1686 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1687 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
1688 CONSTSTR("Responder, Main-Mode message 4"),
1693 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1694 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
1695 CONSTSTR("Responder, Main-Mode Message 4"),
1696 CONSTSTR("Failed to transmit Main-Mode Message 4"));
1702 * receive from initiator
1703 * psk: HDR*, IDi1, HASH_I
1704 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
1705 * gssapi: HDR*, [ IDi1, ] < GSSi(n) | HASH_I >
1710 ident_r3recv(iph1
, msg0
)
1711 struct ph1handle
*iph1
;
1714 vchar_t
*msg
= NULL
;
1715 vchar_t
*pbuf
= NULL
;
1716 struct isakmp_parse_t
*pa
;
1720 vchar_t
*gsstoken
= NULL
;
1723 /* validity check */
1724 if (iph1
->status
!= PHASE1ST_MSG2SENT
) {
1725 plog(LLV_ERROR
, LOCATION
, NULL
,
1726 "status mismatched %d.\n", iph1
->status
);
1731 if (!ISSET(((struct isakmp
*)msg0
->v
)->flags
, ISAKMP_FLAG_E
)) {
1732 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1733 "reject the packet, "
1734 "expecting the packet encrypted.\n");
1737 msg
= oakley_do_decrypt(iph1
, msg0
, iph1
->ivm
->iv
, iph1
->ivm
->ive
);
1739 plog(LLV_ERROR
, LOCATION
, NULL
,
1740 "failed to decrypt");
1744 /* validate the type of next payload */
1745 pbuf
= isakmp_parse(msg
);
1747 plog(LLV_ERROR
, LOCATION
, NULL
,
1748 "failed to parse msg");
1752 iph1
->pl_hash
= NULL
;
1754 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
1755 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1759 case ISAKMP_NPTYPE_ID
:
1760 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0) {
1761 plog(LLV_ERROR
, LOCATION
, NULL
,
1762 "failed to process ID payload");
1766 case ISAKMP_NPTYPE_HASH
:
1767 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
1769 case ISAKMP_NPTYPE_CR
:
1770 if (oakley_savecr(iph1
, pa
->ptr
) < 0) {
1771 plog(LLV_ERROR
, LOCATION
, NULL
,
1772 "failed to process CR payload");
1776 case ISAKMP_NPTYPE_CERT
:
1777 if (oakley_savecert(iph1
, pa
->ptr
) < 0) {
1778 plog(LLV_ERROR
, LOCATION
, NULL
,
1779 "failed to process CERT payload");
1783 case ISAKMP_NPTYPE_SIG
:
1784 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0) {
1785 plog(LLV_ERROR
, LOCATION
, NULL
,
1786 "failed to process SIG payload");
1791 case ISAKMP_NPTYPE_GSS
:
1792 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0) {
1793 plog(LLV_ERROR
, LOCATION
, NULL
,
1794 "failed to process GSS payload");
1797 gssapi_save_received_token(iph1
, gsstoken
);
1800 case ISAKMP_NPTYPE_VID
:
1801 (void)check_vendorid(pa
->ptr
);
1803 case ISAKMP_NPTYPE_N
:
1804 isakmp_check_notify(pa
->ptr
, iph1
);
1807 /* don't send information, see ident_r1recv() */
1808 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1809 "ignore the packet, "
1810 "received unexpecting payload type %d.\n",
1816 /* payload existency check */
1817 /* XXX same as ident_i4recv(), should be merged. */
1821 switch (AUTHMETHOD(iph1
)) {
1822 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
1823 #ifdef ENABLE_HYBRID
1824 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
:
1825 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
:
1826 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R
:
1828 if (iph1
->id_p
== NULL
|| iph1
->pl_hash
== NULL
)
1831 case OAKLEY_ATTR_AUTH_METHOD_DSSSIG
:
1832 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
1833 #ifdef ENABLE_HYBRID
1834 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
:
1835 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_R
:
1837 if (iph1
->id_p
== NULL
|| iph1
->sig_p
== NULL
)
1840 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
1841 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
1842 #ifdef ENABLE_HYBRID
1843 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_R
:
1844 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_R
:
1846 if (iph1
->pl_hash
== NULL
)
1850 case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
:
1851 if (gsstoken
== NULL
&& iph1
->pl_hash
== NULL
)
1856 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1857 "invalid authmethod %d why ?\n",
1858 iph1
->approval
->authmethod
);
1862 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1863 "few isakmp message received.\n");
1868 /* verify identifier */
1869 if (ipsecdoi_checkid1(iph1
) != 0) {
1870 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1871 "invalid ID payload.\n");
1875 /* validate authentication value */
1877 if (gsstoken
== NULL
) {
1879 type
= oakley_validate_auth(iph1
);
1881 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1882 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_FAIL
,
1883 CONSTSTR("Responder, Main-Mode Message 5"),
1884 CONSTSTR("Failed to authenticate Main-Mode Message 5"));
1886 /* msg printed inner oakley_validate_auth() */
1889 EVT_PUSH(iph1
->local
, iph1
->remote
,
1890 EVTT_PEERPH1AUTH_FAILED
, NULL
);
1891 isakmp_info_send_n1(iph1
, type
, NULL
);
1894 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1895 IPSECSESSIONEVENTCODE_IKEV1_PH1_AUTH_SUCC
,
1896 CONSTSTR("Responder, Main-Mode Message 5"),
1902 if (oakley_checkcr(iph1
) < 0) {
1903 /* Ignore this error in order to be interoperability. */
1908 * XXX: Should we do compare two addresses, ph1handle's and ID
1912 plog(LLV_DEBUG
, LOCATION
, iph1
->remote
, "peer's ID\n");
1913 plogdump(LLV_DEBUG
, iph1
->id_p
->v
, iph1
->id_p
->l
);
1915 /* see handler.h about IV synchronization. */
1916 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->ive
->l
);
1919 iph1
->status
= gsstoken
!= NULL
? PHASE1ST_MSG2RECEIVED
:
1920 PHASE1ST_MSG3RECEIVED
;
1922 iph1
->status
= PHASE1ST_MSG3RECEIVED
;
1927 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1928 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
1929 CONSTSTR("Responder, Main-Mode message 5"),
1934 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1935 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
1936 CONSTSTR("Responder, Main-Mode Message 5"),
1937 CONSTSTR("Failed to process Main-Mode Message 5"));
1949 VPTRINIT(iph1
->id_p
);
1950 oakley_delcert(iph1
->cert_p
);
1951 iph1
->cert_p
= NULL
;
1952 oakley_delcert(iph1
->crl_p
);
1954 VPTRINIT(iph1
->sig_p
);
1955 oakley_delcert(iph1
->cr_p
);
1964 * psk: HDR*, IDr1, HASH_R
1965 * sig: HDR*, IDr1, [ CERT, ] SIG_R
1966 * gssapi: HDR*, IDr1, < GSSr(n) | HASH_R >
1971 ident_r3send(iph1
, msg
)
1972 struct ph1handle
*iph1
;
1981 /* validity check */
1982 if (iph1
->status
!= PHASE1ST_MSG3RECEIVED
) {
1983 plog(LLV_ERROR
, LOCATION
, NULL
,
1984 "status mismatched %d.\n", iph1
->status
);
1988 /* make ID payload into isakmp status */
1989 if (ipsecdoi_setid1(iph1
) < 0) {
1990 plog(LLV_ERROR
, LOCATION
, NULL
,
1991 "failed to set ID");
1996 if (AUTHMETHOD(iph1
) == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
1997 gssapi_more_tokens(iph1
)) {
1998 gssapi_get_rtoken(iph1
, &len
);
2005 /* generate HASH to send */
2006 plog(LLV_DEBUG
, LOCATION
, NULL
, "generate HASH_R\n");
2007 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
2008 if (iph1
->hash
== NULL
) {
2009 plog(LLV_ERROR
, LOCATION
, NULL
,
2010 "failed to generate HASH");
2016 /* set encryption flag */
2017 iph1
->flags
|= ISAKMP_FLAG_E
;
2019 /* create HDR;ID;HASH payload */
2020 iph1
->sendbuf
= ident_ir3mx(iph1
);
2021 if (iph1
->sendbuf
== NULL
) {
2022 plog(LLV_ERROR
, LOCATION
, NULL
,
2023 "failed to create send buffer");
2027 /* send HDR;ID;HASH to responder */
2028 if (isakmp_send(iph1
, iph1
->sendbuf
) < 0) {
2029 plog(LLV_ERROR
, LOCATION
, NULL
,
2030 "failed to send packet");
2034 /* the sending message is added to the received-list. */
2035 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
,
2036 PH1_NON_ESP_EXTRA_LEN(iph1
)) == -1) {
2037 plog(LLV_ERROR
, LOCATION
, NULL
,
2038 "failed to add a response packet to the tree.\n");
2042 /* see handler.h about IV synchronization. */
2043 memcpy(iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->v
, iph1
->ivm
->iv
->l
);
2045 iph1
->status
= PHASE1ST_ESTABLISHED
;
2047 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
2048 IPSECSESSIONEVENTCODE_IKEV1_PH1_RESP_SUCC
,
2049 CONSTSTR("Responder, Main-Mode"),
2054 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
2055 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
2056 CONSTSTR("Responder, Main-Mode message 6"),
2061 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
2062 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
2063 CONSTSTR("Responder, Main-Mode Message 6"),
2064 CONSTSTR("Failed to process Main-Mode Message 6"));
2071 * This is used in main mode for:
2072 * initiator's 3rd exchange send to responder
2075 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
2076 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
2077 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
2078 * responders 2nd exchnage send to initiator
2080 * sig: HDR, KE, Nr [, CR ]
2081 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
2082 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
2086 struct ph1handle
*iph1
;
2089 struct payload_list
*plist
= NULL
;
2092 vchar_t
*vid
= NULL
;
2095 vchar_t
*gsstoken
= NULL
;
2098 vchar_t
*natd
[2] = { NULL
, NULL
};
2101 /* create CR if need */
2102 if (iph1
->side
== RESPONDER
2103 && iph1
->rmconf
->send_cr
2104 && oakley_needcr(iph1
->approval
->authmethod
)
2105 && iph1
->rmconf
->peerscertfile
== NULL
) {
2107 cr
= oakley_getcr(iph1
);
2109 plog(LLV_ERROR
, LOCATION
, NULL
,
2110 "failed to get cr buffer.\n");
2116 if (AUTHMETHOD(iph1
) == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
2117 gssapi_get_token_to_send(iph1
, &gsstoken
);
2120 /* create isakmp KE payload */
2121 plist
= isakmp_plist_append(plist
, iph1
->dhpub
, ISAKMP_NPTYPE_KE
);
2123 /* create isakmp NONCE payload */
2124 plist
= isakmp_plist_append(plist
, iph1
->nonce
, ISAKMP_NPTYPE_NONCE
);
2127 if (AUTHMETHOD(iph1
) == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
2128 plist
= isakmp_plist_append(plist
, gsstoken
, ISAKMP_NPTYPE_GSS
);
2131 /* append vendor id, if needed */
2133 plist
= isakmp_plist_append(plist
, vid
, ISAKMP_NPTYPE_VID
);
2135 /* create isakmp CR payload if needed */
2137 plist
= isakmp_plist_append(plist
, cr
, ISAKMP_NPTYPE_CR
);
2140 /* generate and append NAT-D payloads */
2141 if (NATT_AVAILABLE(iph1
) && iph1
->status
== PHASE1ST_MSG2RECEIVED
)
2143 if ((natd
[0] = natt_hash_addr (iph1
, iph1
->remote
)) == NULL
) {
2144 plog(LLV_ERROR
, LOCATION
, NULL
,
2145 "NAT-D hashing failed for %s\n", saddr2str(iph1
->remote
));
2149 if ((natd
[1] = natt_hash_addr (iph1
, iph1
->local
)) == NULL
) {
2150 plog(LLV_ERROR
, LOCATION
, NULL
,
2151 "NAT-D hashing failed for %s\n", saddr2str(iph1
->local
));
2155 plog (LLV_INFO
, LOCATION
, NULL
, "Adding remote and local NAT-D payloads.\n");
2157 /* old Apple version sends natd payloads in the wrong order */
2158 if (iph1
->natt_options
->version
== VENDORID_NATT_APPLE
) {
2159 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
2160 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
2164 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
2165 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
2170 buf
= isakmp_plist_set_all (&plist
, iph1
);
2175 if (error
&& buf
!= NULL
) {
2199 * This is used in main mode for:
2200 * initiator's 4th exchange send to responder
2201 * psk: HDR*, IDi1, HASH_I
2202 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
2203 * gssapi: HDR*, [ IDi1, ] < GSSi(n) | HASH_I >
2206 * responders 3rd exchnage send to initiator
2207 * psk: HDR*, IDr1, HASH_R
2208 * sig: HDR*, IDr1, [ CERT, ] SIG_R
2209 * gssapi: HDR*, [ IDr1, ] < GSSr(n) | HASH_R >
2215 struct ph1handle
*iph1
;
2217 struct payload_list
*plist
= NULL
;
2218 vchar_t
*buf
= NULL
, *new = NULL
;
2225 vchar_t
*gsstoken
= NULL
;
2226 vchar_t
*gsshash
= NULL
;
2229 switch (AUTHMETHOD(iph1
)) {
2230 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
2231 #ifdef ENABLE_HYBRID
2232 case FICTIVE_AUTH_METHOD_XAUTH_PSKEY_I
:
2233 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
:
2234 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
2235 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I
:
2237 /* create isakmp ID payload */
2238 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
2240 /* create isakmp HASH payload */
2241 plist
= isakmp_plist_append(plist
, iph1
->hash
, ISAKMP_NPTYPE_HASH
);
2243 case OAKLEY_ATTR_AUTH_METHOD_DSSSIG
:
2244 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
2245 #ifdef ENABLE_HYBRID
2246 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
:
2247 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R
:
2248 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
2249 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
:
2250 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_I
:
2251 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_R
:
2253 if (oakley_getmycert(iph1
) < 0) {
2254 plog(LLV_ERROR
, LOCATION
, NULL
,
2255 "failed to get mycert");
2259 if (oakley_getsign(iph1
) < 0) {
2260 plog(LLV_ERROR
, LOCATION
, NULL
,
2261 "failed to get sign");
2265 /* create CR if need */
2266 if (iph1
->side
== INITIATOR
2267 && iph1
->rmconf
->send_cr
2268 && oakley_needcr(iph1
->approval
->authmethod
)
2269 && iph1
->rmconf
->peerscertfile
== NULL
) {
2271 cr
= oakley_getcr(iph1
);
2273 plog(LLV_ERROR
, LOCATION
, NULL
,
2274 "failed to get CR");
2279 if (iph1
->cert
!= NULL
&& iph1
->rmconf
->send_cert
)
2282 /* add ID payload */
2283 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
2285 /* add CERT payload if there */
2287 plist
= isakmp_plist_append(plist
, iph1
->cert
->pl
, ISAKMP_NPTYPE_CERT
);
2288 /* add SIG payload */
2289 plist
= isakmp_plist_append(plist
, iph1
->sig
, ISAKMP_NPTYPE_SIG
);
2291 /* create isakmp CR payload */
2293 plist
= isakmp_plist_append(plist
, cr
, ISAKMP_NPTYPE_CR
);
2296 case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
:
2297 if (iph1
->hash
!= NULL
) {
2298 gsshash
= gssapi_wraphash(iph1
);
2299 if (gsshash
== NULL
) {
2300 plog(LLV_ERROR
, LOCATION
, NULL
,
2301 "failed to generate GSSAPI HASH");
2305 gssapi_get_token_to_send(iph1
, &gsstoken
);
2308 if (!gssapi_id_sent(iph1
)) {
2309 /* create isakmp ID payload */
2310 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
2311 gssapi_set_id_sent(iph1
);
2314 if (iph1
->hash
!= NULL
)
2315 /* create isakmp HASH payload */
2316 plist
= isakmp_plist_append(plist
, gsshash
, ISAKMP_NPTYPE_HASH
);
2318 plist
= isakmp_plist_append(plist
, gsstoken
, ISAKMP_NPTYPE_GSS
);
2321 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
2322 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
2323 #ifdef ENABLE_HYBRID
2324 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
2325 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_R
:
2326 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
2327 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_R
:
2329 plog(LLV_ERROR
, LOCATION
, NULL
,
2330 "not supported authentication type %d\n",
2331 iph1
->approval
->authmethod
);
2334 plog(LLV_ERROR
, LOCATION
, NULL
,
2335 "invalid authentication type %d\n",
2336 iph1
->approval
->authmethod
);
2340 buf
= isakmp_plist_set_all (&plist
, iph1
);
2342 #ifdef HAVE_PRINT_ISAKMP_C
2343 isakmp_printpacket(buf
, iph1
->local
, iph1
->remote
, 1);
2347 new = oakley_do_encrypt(iph1
, buf
, iph1
->ivm
->ive
, iph1
->ivm
->iv
);
2349 plog(LLV_ERROR
, LOCATION
, NULL
,
2350 "failed to encrypt");
2367 if (error
&& buf
!= NULL
) {