1 /* $NetBSD: isakmp_ident.c,v 1.12 2009/03/12 10:57:26 tteras 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 static vchar_t
*ident_ir2mx
__P((struct ph1handle
*));
94 static vchar_t
*ident_ir3mx
__P((struct ph1handle
*));
95 static int ident_recv_n
__P((struct ph1handle
*, struct isakmp_gen
*));
98 * begin Identity Protection Mode as initiator.
108 ident_i1send(iph1
, msg
)
109 struct ph1handle
*iph1
;
110 vchar_t
*msg
; /* must be null */
112 struct payload_list
*plist
= NULL
;
115 vchar_t
*vid_natt
[MAX_NATT_VID_COUNT
] = { NULL
};
119 vchar_t
*vid_xauth
= NULL
;
120 vchar_t
*vid_unity
= NULL
;
123 vchar_t
*vid_frag
= NULL
;
126 vchar_t
*vid_dpd
= NULL
;
130 plog(LLV_ERROR
, LOCATION
, NULL
,
131 "msg has to be NULL in this function.\n");
134 if (iph1
->status
!= PHASE1ST_START
) {
135 plog(LLV_ERROR
, LOCATION
, NULL
,
136 "status mismatched %d.\n", iph1
->status
);
140 /* create isakmp index */
141 memset(&iph1
->index
, 0, sizeof(iph1
->index
));
142 isakmp_newcookie((caddr_t
)&iph1
->index
, iph1
->remote
, iph1
->local
);
144 /* create SA payload for my proposal */
145 iph1
->sa
= ipsecdoi_setph1proposal(iph1
->rmconf
,
146 iph1
->rmconf
->proposal
);
147 if (iph1
->sa
== NULL
)
150 /* set SA payload to propose */
151 plist
= isakmp_plist_append(plist
, iph1
->sa
, ISAKMP_NPTYPE_SA
);
154 /* set VID payload for NAT-T if NAT-T support allowed in the config file */
155 if (iph1
->rmconf
->nat_traversal
)
156 plist
= isakmp_plist_append_natt_vids(plist
, vid_natt
);
159 /* Do we need Xauth VID? */
160 switch (iph1
->rmconf
->proposal
->authmethod
) {
161 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_I
:
162 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
163 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I
:
164 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
165 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_I
:
166 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
167 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
168 if ((vid_xauth
= set_vendorid(VENDORID_XAUTH
)) == NULL
)
169 plog(LLV_ERROR
, LOCATION
, NULL
,
170 "Xauth vendor ID generation failed\n");
172 plist
= isakmp_plist_append(plist
,
173 vid_xauth
, ISAKMP_NPTYPE_VID
);
175 if ((vid_unity
= set_vendorid(VENDORID_UNITY
)) == NULL
)
176 plog(LLV_ERROR
, LOCATION
, NULL
,
177 "Unity vendor ID generation failed\n");
179 plist
= isakmp_plist_append(plist
,
180 vid_unity
, ISAKMP_NPTYPE_VID
);
187 if (iph1
->rmconf
->ike_frag
) {
188 if ((vid_frag
= set_vendorid(VENDORID_FRAG
)) == NULL
) {
189 plog(LLV_ERROR
, LOCATION
, NULL
,
190 "Frag vendorID construction failed\n");
192 vid_frag
= isakmp_frag_addcap(vid_frag
,
193 VENDORID_FRAG_IDENT
);
194 plist
= isakmp_plist_append(plist
,
195 vid_frag
, ISAKMP_NPTYPE_VID
);
200 if(iph1
->rmconf
->dpd
){
201 vid_dpd
= set_vendorid(VENDORID_DPD
);
203 plist
= isakmp_plist_append(plist
, vid_dpd
,
208 iph1
->sendbuf
= isakmp_plist_set_all (&plist
, iph1
);
210 #ifdef HAVE_PRINT_ISAKMP_C
211 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
214 /* send the packet, add to the schedule to resend */
215 if (isakmp_ph1send(iph1
) == -1)
218 iph1
->status
= PHASE1ST_MSG1SENT
;
228 for (i
= 0; i
< MAX_NATT_VID_COUNT
&& vid_natt
[i
] != NULL
; i
++)
232 if (vid_xauth
!= NULL
)
234 if (vid_unity
!= NULL
)
246 * receive from responder
253 ident_i2recv(iph1
, msg
)
254 struct ph1handle
*iph1
;
257 vchar_t
*pbuf
= NULL
;
258 struct isakmp_parse_t
*pa
;
259 vchar_t
*satmp
= NULL
;
263 if (iph1
->status
!= PHASE1ST_MSG1SENT
) {
264 plog(LLV_ERROR
, LOCATION
, NULL
,
265 "status mismatched %d.\n", iph1
->status
);
269 /* validate the type of next payload */
271 * NOTE: RedCreek(as responder) attaches N[responder-lifetime] here,
272 * if proposal-lifetime > lifetime-redcreek-wants.
274 * => According to the seciton 4.6.3 in RFC 2407, This is illegal.
275 * NOTE: we do not really care about ordering of VID and N.
277 * NOTE: even if there's multiple VID/N, we'll ignore them.
279 pbuf
= isakmp_parse(msg
);
282 pa
= (struct isakmp_parse_t
*)pbuf
->v
;
284 /* SA payload is fixed postion */
285 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
286 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
287 "received invalid next payload type %d, "
289 pa
->type
, ISAKMP_NPTYPE_SA
);
292 if (isakmp_p2ph(&satmp
, pa
->ptr
) < 0)
297 pa
->type
!= ISAKMP_NPTYPE_NONE
;
301 case ISAKMP_NPTYPE_VID
:
302 handle_vendorid(iph1
, pa
->ptr
);
305 /* don't send information, see ident_r1recv() */
306 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
307 "ignore the packet, "
308 "received unexpecting payload type %d.\n",
315 if (NATT_AVAILABLE(iph1
))
316 plog(LLV_INFO
, LOCATION
, iph1
->remote
,
317 "Selected NAT-T version: %s\n",
318 vid_string_by_id(iph1
->natt_options
->version
));
321 /* check SA payload and set approval SA for use */
322 if (ipsecdoi_checkph1proposal(satmp
, iph1
) < 0) {
323 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
324 "failed to get valid proposal.\n");
325 /* XXX send information */
328 VPTRINIT(iph1
->sa_ret
);
330 iph1
->status
= PHASE1ST_MSG2RECEIVED
;
346 * gssapi: HDR, KE, Ni, GSSi
347 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
348 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
349 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
352 ident_i2send(iph1
, msg
)
353 struct ph1handle
*iph1
;
359 if (iph1
->status
!= PHASE1ST_MSG2RECEIVED
) {
360 plog(LLV_ERROR
, LOCATION
, NULL
,
361 "status mismatched %d.\n", iph1
->status
);
365 /* fix isakmp index */
366 memcpy(&iph1
->index
.r_ck
, &((struct isakmp
*)msg
->v
)->r_ck
,
369 /* generate DH public value */
370 if (oakley_dh_generate(iph1
->approval
->dhgrp
,
371 &iph1
->dhpub
, &iph1
->dhpriv
) < 0)
374 /* generate NONCE value */
375 iph1
->nonce
= eay_set_random(iph1
->rmconf
->nonce_size
);
376 if (iph1
->nonce
== NULL
)
380 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
381 gssapi_get_itoken(iph1
, NULL
) < 0)
385 /* create buffer to send isakmp payload */
386 iph1
->sendbuf
= ident_ir2mx(iph1
);
387 if (iph1
->sendbuf
== NULL
)
390 #ifdef HAVE_PRINT_ISAKMP_C
391 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
394 /* send the packet, add to the schedule to resend */
395 if (isakmp_ph1send(iph1
) == -1)
398 /* the sending message is added to the received-list. */
399 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
) == -1) {
400 plog(LLV_ERROR
, LOCATION
, NULL
,
401 "failed to add a response packet to the tree.\n");
405 iph1
->status
= PHASE1ST_MSG2SENT
;
414 * receive from responder
416 * sig: HDR, KE, Nr [, CR ]
417 * gssapi: HDR, KE, Nr, GSSr
418 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
419 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
422 ident_i3recv(iph1
, msg
)
423 struct ph1handle
*iph1
;
426 vchar_t
*pbuf
= NULL
;
427 struct isakmp_parse_t
*pa
;
430 vchar_t
*gsstoken
= NULL
;
433 vchar_t
*natd_received
;
434 int natd_seq
= 0, natd_verified
;
438 if (iph1
->status
!= PHASE1ST_MSG2SENT
) {
439 plog(LLV_ERROR
, LOCATION
, NULL
,
440 "status mismatched %d.\n", iph1
->status
);
444 /* validate the type of next payload */
445 pbuf
= isakmp_parse(msg
);
449 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
450 pa
->type
!= ISAKMP_NPTYPE_NONE
;
454 case ISAKMP_NPTYPE_KE
:
455 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0)
458 case ISAKMP_NPTYPE_NONCE
:
459 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0)
462 case ISAKMP_NPTYPE_VID
:
463 handle_vendorid(iph1
, pa
->ptr
);
465 case ISAKMP_NPTYPE_CR
:
466 if (oakley_savecr(iph1
, pa
->ptr
) < 0)
470 case ISAKMP_NPTYPE_GSS
:
471 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0)
473 gssapi_save_received_token(iph1
, gsstoken
);
478 case ISAKMP_NPTYPE_NATD_DRAFT
:
479 case ISAKMP_NPTYPE_NATD_RFC
:
480 if (NATT_AVAILABLE(iph1
) && iph1
->natt_options
!= NULL
&&
481 pa
->type
== iph1
->natt_options
->payload_nat_d
) {
482 natd_received
= NULL
;
483 if (isakmp_p2ph (&natd_received
, pa
->ptr
) < 0)
486 /* set both bits first so that we can clear them
487 upon verifying hashes */
489 iph1
->natt_flags
|= NAT_DETECTED
;
491 /* this function will clear appropriate bits bits
492 from iph1->natt_flags */
493 natd_verified
= natt_compare_addr_hash (iph1
,
494 natd_received
, natd_seq
++);
496 plog (LLV_INFO
, LOCATION
, NULL
, "NAT-D payload #%d %s\n",
498 natd_verified
? "verified" : "doesn't match");
500 vfree (natd_received
);
503 /* passthrough to default... */
507 /* don't send information, see ident_r1recv() */
508 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
509 "ignore the packet, "
510 "received unexpecting payload type %d.\n",
517 if (NATT_AVAILABLE(iph1
)) {
518 plog (LLV_INFO
, LOCATION
, NULL
, "NAT %s %s%s\n",
519 iph1
->natt_flags
& NAT_DETECTED
?
520 "detected:" : "not detected",
521 iph1
->natt_flags
& NAT_DETECTED_ME
? "ME " : "",
522 iph1
->natt_flags
& NAT_DETECTED_PEER
? "PEER" : "");
523 if (iph1
->natt_flags
& NAT_DETECTED
)
524 natt_float_ports (iph1
);
528 /* payload existency check */
529 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
530 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
531 "few isakmp message received.\n");
535 if (oakley_checkcr(iph1
) < 0) {
536 /* Ignore this error in order to be interoperability. */
540 iph1
->status
= PHASE1ST_MSG3RECEIVED
;
552 VPTRINIT(iph1
->dhpub_p
);
553 VPTRINIT(iph1
->nonce_p
);
554 VPTRINIT(iph1
->id_p
);
555 VPTRINIT(iph1
->cr_p
);
563 * psk: HDR*, IDi1, HASH_I
564 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
565 * gssapi: HDR*, IDi1, < Gssi(n) | HASH_I >
570 ident_i3send(iph1
, msg0
)
571 struct ph1handle
*iph1
;
581 if (iph1
->status
!= PHASE1ST_MSG3RECEIVED
) {
582 plog(LLV_ERROR
, LOCATION
, NULL
,
583 "status mismatched %d.\n", iph1
->status
);
587 /* compute sharing secret of DH */
588 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub
,
589 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0)
592 /* generate SKEYIDs & IV & final cipher key */
593 if (oakley_skeyid(iph1
) < 0)
595 if (oakley_skeyid_dae(iph1
) < 0)
597 if (oakley_compute_enckey(iph1
) < 0)
599 if (oakley_newiv(iph1
) < 0)
602 /* make ID payload into isakmp status */
603 if (ipsecdoi_setid1(iph1
) < 0)
607 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
608 gssapi_more_tokens(iph1
)) {
609 plog(LLV_DEBUG
, LOCATION
, NULL
, "calling get_itoken\n");
610 if (gssapi_get_itoken(iph1
, &len
) < 0)
617 /* generate HASH to send */
619 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
620 if (iph1
->hash
== NULL
)
625 /* set encryption flag */
626 iph1
->flags
|= ISAKMP_FLAG_E
;
628 /* create HDR;ID;HASH payload */
629 iph1
->sendbuf
= ident_ir3mx(iph1
);
630 if (iph1
->sendbuf
== NULL
)
633 /* send the packet, add to the schedule to resend */
634 if (isakmp_ph1send(iph1
) == -1)
637 /* the sending message is added to the received-list. */
638 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg0
) == -1) {
639 plog(LLV_ERROR
, LOCATION
, NULL
,
640 "failed to add a response packet to the tree.\n");
644 /* see handler.h about IV synchronization. */
645 memcpy(iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->v
, iph1
->ivm
->iv
->l
);
647 iph1
->status
= PHASE1ST_MSG3SENT
;
656 * receive from responder
657 * psk: HDR*, IDr1, HASH_R
658 * sig: HDR*, IDr1, [ CERT, ] SIG_R
659 * gssapi: HDR*, IDr1, < GSSr(n) | HASH_R >
664 ident_i4recv(iph1
, msg0
)
665 struct ph1handle
*iph1
;
668 vchar_t
*pbuf
= NULL
;
669 struct isakmp_parse_t
*pa
;
674 vchar_t
*gsstoken
= NULL
;
678 if (iph1
->status
!= PHASE1ST_MSG3SENT
) {
679 plog(LLV_ERROR
, LOCATION
, NULL
,
680 "status mismatched %d.\n", iph1
->status
);
685 if (!ISSET(((struct isakmp
*)msg0
->v
)->flags
, ISAKMP_FLAG_E
)) {
686 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
687 "ignore the packet, "
688 "expecting the packet encrypted.\n");
691 msg
= oakley_do_decrypt(iph1
, msg0
, iph1
->ivm
->iv
, iph1
->ivm
->ive
);
695 /* validate the type of next payload */
696 pbuf
= isakmp_parse(msg
);
700 iph1
->pl_hash
= NULL
;
702 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
703 pa
->type
!= ISAKMP_NPTYPE_NONE
;
707 case ISAKMP_NPTYPE_ID
:
708 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0)
711 case ISAKMP_NPTYPE_HASH
:
712 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
714 case ISAKMP_NPTYPE_CERT
:
715 if (oakley_savecert(iph1
, pa
->ptr
) < 0)
718 case ISAKMP_NPTYPE_SIG
:
719 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0)
723 case ISAKMP_NPTYPE_GSS
:
724 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0)
726 gssapi_save_received_token(iph1
, gsstoken
);
729 case ISAKMP_NPTYPE_VID
:
730 handle_vendorid(iph1
, pa
->ptr
);
732 case ISAKMP_NPTYPE_N
:
733 ident_recv_n(iph1
, pa
->ptr
);
736 /* don't send information, see ident_r1recv() */
737 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
738 "ignore the packet, "
739 "received unexpecting payload type %d.\n",
745 /* payload existency check */
747 /* verify identifier */
748 if (ipsecdoi_checkid1(iph1
) != 0) {
749 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
750 "invalid ID payload.\n");
754 /* validate authentication value */
756 if (gsstoken
== NULL
) {
758 type
= oakley_validate_auth(iph1
);
761 /* msg printed inner oakley_validate_auth() */
764 evt_phase1(iph1
, EVT_PHASE1_AUTH_FAILED
, NULL
);
765 isakmp_info_send_n1(iph1
, type
, NULL
);
773 * XXX: Should we do compare two addresses, ph1handle's and ID
777 plog(LLV_DEBUG
, LOCATION
, iph1
->remote
, "peer's ID:");
778 plogdump(LLV_DEBUG
, iph1
->id_p
->v
, iph1
->id_p
->l
);
780 /* see handler.h about IV synchronization. */
781 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->ive
->l
);
784 * If we got a GSS token, we need to this roundtrip again.
787 iph1
->status
= gsstoken
!= 0 ? PHASE1ST_MSG3RECEIVED
:
788 PHASE1ST_MSG4RECEIVED
;
790 iph1
->status
= PHASE1ST_MSG4RECEIVED
;
806 VPTRINIT(iph1
->id_p
);
807 VPTRINIT(iph1
->cert_p
);
808 VPTRINIT(iph1
->crl_p
);
809 VPTRINIT(iph1
->sig_p
);
816 * status update and establish isakmp sa.
819 ident_i4send(iph1
, msg
)
820 struct ph1handle
*iph1
;
826 if (iph1
->status
!= PHASE1ST_MSG4RECEIVED
) {
827 plog(LLV_ERROR
, LOCATION
, NULL
,
828 "status mismatched %d.\n", iph1
->status
);
832 /* see handler.h about IV synchronization. */
833 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->l
);
835 iph1
->status
= PHASE1ST_ESTABLISHED
;
844 * receive from initiator
851 ident_r1recv(iph1
, msg
)
852 struct ph1handle
*iph1
;
855 vchar_t
*pbuf
= NULL
;
856 struct isakmp_parse_t
*pa
;
861 if (iph1
->status
!= PHASE1ST_START
) {
862 plog(LLV_ERROR
, LOCATION
, NULL
,
863 "status mismatched %d.\n", iph1
->status
);
867 /* validate the type of next payload */
869 * NOTE: XXX even if multiple VID, we'll silently ignore those.
871 pbuf
= isakmp_parse(msg
);
874 pa
= (struct isakmp_parse_t
*)pbuf
->v
;
876 /* check the position of SA payload */
877 if (pa
->type
!= ISAKMP_NPTYPE_SA
) {
878 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
879 "received invalid next payload type %d, "
881 pa
->type
, ISAKMP_NPTYPE_SA
);
884 if (isakmp_p2ph(&iph1
->sa
, pa
->ptr
) < 0)
889 pa
->type
!= ISAKMP_NPTYPE_NONE
;
893 case ISAKMP_NPTYPE_VID
:
894 vid_numeric
= handle_vendorid(iph1
, pa
->ptr
);
896 if ((vid_numeric
== VENDORID_FRAG
) &&
897 (vendorid_frag_cap(pa
->ptr
) & VENDORID_FRAG_IDENT
))
903 * We don't send information to the peer even
904 * if we received malformed packet. Because we
905 * can't distinguish the malformed packet and
906 * the re-sent packet. And we do same behavior
907 * when we expect encrypted packet.
909 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
910 "ignore the packet, "
911 "received unexpecting payload type %d.\n",
918 if (NATT_AVAILABLE(iph1
))
919 plog(LLV_INFO
, LOCATION
, iph1
->remote
,
920 "Selected NAT-T version: %s\n",
921 vid_string_by_id(iph1
->natt_options
->version
));
924 /* check SA payload and set approval SA for use */
925 if (ipsecdoi_checkph1proposal(iph1
->sa
, iph1
) < 0) {
926 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
927 "failed to get valid proposal.\n");
928 /* XXX send information */
932 iph1
->status
= PHASE1ST_MSG1RECEIVED
;
954 ident_r1send(iph1
, msg
)
955 struct ph1handle
*iph1
;
958 struct payload_list
*plist
= NULL
;
960 vchar_t
*gss_sa
= NULL
;
965 vchar_t
*vid_natt
= NULL
;
968 vchar_t
*vid_xauth
= NULL
;
969 vchar_t
*vid_unity
= NULL
;
972 vchar_t
*vid_dpd
= NULL
;
975 vchar_t
*vid_frag
= NULL
;
979 if (iph1
->status
!= PHASE1ST_MSG1RECEIVED
) {
980 plog(LLV_ERROR
, LOCATION
, NULL
,
981 "status mismatched %d.\n", iph1
->status
);
985 /* set responder's cookie */
986 isakmp_newcookie((caddr_t
)&iph1
->index
.r_ck
, iph1
->remote
, iph1
->local
);
989 if (iph1
->approval
->gssid
!= NULL
) {
990 gss_sa
= ipsecdoi_setph1proposal(iph1
->rmconf
, iph1
->approval
);
991 if (gss_sa
!= iph1
->sa_ret
)
995 gss_sa
= iph1
->sa_ret
;
997 /* set SA payload to reply */
998 plist
= isakmp_plist_append(plist
, gss_sa
, ISAKMP_NPTYPE_SA
);
1000 #ifdef ENABLE_HYBRID
1001 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) {
1002 plog (LLV_INFO
, LOCATION
, NULL
, "Adding xauth VID payload.\n");
1003 if ((vid_xauth
= set_vendorid(VENDORID_XAUTH
)) == NULL
) {
1004 plog(LLV_ERROR
, LOCATION
, NULL
,
1005 "Cannot create Xauth vendor ID\n");
1008 plist
= isakmp_plist_append(plist
,
1009 vid_xauth
, ISAKMP_NPTYPE_VID
);
1012 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_UNITY
) {
1013 if ((vid_unity
= set_vendorid(VENDORID_UNITY
)) == NULL
) {
1014 plog(LLV_ERROR
, LOCATION
, NULL
,
1015 "Cannot create Unity vendor ID\n");
1018 plist
= isakmp_plist_append(plist
,
1019 vid_unity
, ISAKMP_NPTYPE_VID
);
1023 /* Has the peer announced NAT-T? */
1024 if (NATT_AVAILABLE(iph1
))
1025 vid_natt
= set_vendorid(iph1
->natt_options
->version
);
1028 plist
= isakmp_plist_append(plist
, vid_natt
, ISAKMP_NPTYPE_VID
);
1031 if (iph1
->dpd_support
) {
1032 vid_dpd
= set_vendorid(VENDORID_DPD
);
1033 if (vid_dpd
!= NULL
)
1034 plist
= isakmp_plist_append(plist
, vid_dpd
, ISAKMP_NPTYPE_VID
);
1039 vid_frag
= set_vendorid(VENDORID_FRAG
);
1040 if (vid_frag
!= NULL
)
1041 vid_frag
= isakmp_frag_addcap(vid_frag
,
1042 VENDORID_FRAG_IDENT
);
1043 if (vid_frag
== NULL
)
1044 plog(LLV_ERROR
, LOCATION
, NULL
,
1045 "Frag vendorID construction failed\n");
1047 plist
= isakmp_plist_append(plist
,
1048 vid_frag
, ISAKMP_NPTYPE_VID
);
1052 iph1
->sendbuf
= isakmp_plist_set_all (&plist
, iph1
);
1054 #ifdef HAVE_PRINT_ISAKMP_C
1055 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
1058 /* send the packet, add to the schedule to resend */
1059 if (isakmp_ph1send(iph1
) == -1)
1062 /* the sending message is added to the received-list. */
1063 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
) == -1) {
1064 plog(LLV_ERROR
, LOCATION
, NULL
,
1065 "failed to add a response packet to the tree.\n");
1069 iph1
->status
= PHASE1ST_MSG1SENT
;
1082 #ifdef ENABLE_HYBRID
1083 if (vid_xauth
!= NULL
)
1085 if (vid_unity
!= NULL
)
1089 if (vid_dpd
!= NULL
)
1093 if (vid_frag
!= NULL
)
1101 * receive from initiator
1104 * gssapi: HDR, KE, Ni, GSSi
1105 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
1106 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
1107 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
1110 ident_r2recv(iph1
, msg
)
1111 struct ph1handle
*iph1
;
1114 vchar_t
*pbuf
= NULL
;
1115 struct isakmp_parse_t
*pa
;
1118 vchar_t
*gsstoken
= NULL
;
1124 /* validity check */
1125 if (iph1
->status
!= PHASE1ST_MSG1SENT
) {
1126 plog(LLV_ERROR
, LOCATION
, NULL
,
1127 "status mismatched %d.\n", iph1
->status
);
1131 /* validate the type of next payload */
1132 pbuf
= isakmp_parse(msg
);
1136 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
1137 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1140 case ISAKMP_NPTYPE_KE
:
1141 if (isakmp_p2ph(&iph1
->dhpub_p
, pa
->ptr
) < 0)
1144 case ISAKMP_NPTYPE_NONCE
:
1145 if (isakmp_p2ph(&iph1
->nonce_p
, pa
->ptr
) < 0)
1148 case ISAKMP_NPTYPE_VID
:
1149 handle_vendorid(iph1
, pa
->ptr
);
1151 case ISAKMP_NPTYPE_CR
:
1152 plog(LLV_WARNING
, LOCATION
, iph1
->remote
,
1153 "CR received, ignore it. "
1154 "It should be in other exchange.\n");
1157 case ISAKMP_NPTYPE_GSS
:
1158 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0)
1160 gssapi_save_received_token(iph1
, gsstoken
);
1165 case ISAKMP_NPTYPE_NATD_DRAFT
:
1166 case ISAKMP_NPTYPE_NATD_RFC
:
1167 if (NATT_AVAILABLE(iph1
) && iph1
->natt_options
!= NULL
&&
1168 pa
->type
== iph1
->natt_options
->payload_nat_d
)
1170 vchar_t
*natd_received
= NULL
;
1173 if (isakmp_p2ph (&natd_received
, pa
->ptr
) < 0)
1177 iph1
->natt_flags
|= NAT_DETECTED
;
1179 natd_verified
= natt_compare_addr_hash (iph1
,
1180 natd_received
, natd_seq
++);
1182 plog (LLV_INFO
, LOCATION
, NULL
, "NAT-D payload #%d %s\n",
1184 natd_verified
? "verified" : "doesn't match");
1186 vfree (natd_received
);
1189 /* passthrough to default... */
1193 /* don't send information, see ident_r1recv() */
1194 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1195 "ignore the packet, "
1196 "received unexpecting payload type %d.\n",
1203 if (NATT_AVAILABLE(iph1
))
1204 plog (LLV_INFO
, LOCATION
, NULL
, "NAT %s %s%s\n",
1205 iph1
->natt_flags
& NAT_DETECTED
?
1206 "detected:" : "not detected",
1207 iph1
->natt_flags
& NAT_DETECTED_ME
? "ME " : "",
1208 iph1
->natt_flags
& NAT_DETECTED_PEER
? "PEER" : "");
1211 /* payload existency check */
1212 if (iph1
->dhpub_p
== NULL
|| iph1
->nonce_p
== NULL
) {
1213 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1214 "few isakmp message received.\n");
1218 iph1
->status
= PHASE1ST_MSG2RECEIVED
;
1231 VPTRINIT(iph1
->dhpub_p
);
1232 VPTRINIT(iph1
->nonce_p
);
1233 VPTRINIT(iph1
->id_p
);
1242 * sig: HDR, KE, Nr [, CR ]
1243 * gssapi: HDR, KE, Nr, GSSr
1244 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
1245 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
1248 ident_r2send(iph1
, msg
)
1249 struct ph1handle
*iph1
;
1254 /* validity check */
1255 if (iph1
->status
!= PHASE1ST_MSG2RECEIVED
) {
1256 plog(LLV_ERROR
, LOCATION
, NULL
,
1257 "status mismatched %d.\n", iph1
->status
);
1261 /* generate DH public value */
1262 if (oakley_dh_generate(iph1
->approval
->dhgrp
,
1263 &iph1
->dhpub
, &iph1
->dhpriv
) < 0)
1266 /* generate NONCE value */
1267 iph1
->nonce
= eay_set_random(RMCONF_NONCE_SIZE(iph1
->rmconf
));
1268 if (iph1
->nonce
== NULL
)
1272 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
1273 gssapi_get_rtoken(iph1
, NULL
);
1276 /* create HDR;KE;NONCE payload */
1277 iph1
->sendbuf
= ident_ir2mx(iph1
);
1278 if (iph1
->sendbuf
== NULL
)
1281 #ifdef HAVE_PRINT_ISAKMP_C
1282 isakmp_printpacket(iph1
->sendbuf
, iph1
->local
, iph1
->remote
, 0);
1285 /* send the packet, add to the schedule to resend */
1286 if (isakmp_ph1send(iph1
) == -1)
1289 /* the sending message is added to the received-list. */
1290 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
) == -1) {
1291 plog(LLV_ERROR
, LOCATION
, NULL
,
1292 "failed to add a response packet to the tree.\n");
1296 /* compute sharing secret of DH */
1297 if (oakley_dh_compute(iph1
->approval
->dhgrp
, iph1
->dhpub
,
1298 iph1
->dhpriv
, iph1
->dhpub_p
, &iph1
->dhgxy
) < 0)
1301 /* generate SKEYIDs & IV & final cipher key */
1302 if (oakley_skeyid(iph1
) < 0)
1304 if (oakley_skeyid_dae(iph1
) < 0)
1306 if (oakley_compute_enckey(iph1
) < 0)
1308 if (oakley_newiv(iph1
) < 0)
1311 iph1
->status
= PHASE1ST_MSG2SENT
;
1320 * receive from initiator
1321 * psk: HDR*, IDi1, HASH_I
1322 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
1323 * gssapi: HDR*, [ IDi1, ] < GSSi(n) | HASH_I >
1328 ident_r3recv(iph1
, msg0
)
1329 struct ph1handle
*iph1
;
1332 vchar_t
*msg
= NULL
;
1333 vchar_t
*pbuf
= NULL
;
1334 struct isakmp_parse_t
*pa
;
1338 vchar_t
*gsstoken
= NULL
;
1341 /* validity check */
1342 if (iph1
->status
!= PHASE1ST_MSG2SENT
) {
1343 plog(LLV_ERROR
, LOCATION
, NULL
,
1344 "status mismatched %d.\n", iph1
->status
);
1349 if (!ISSET(((struct isakmp
*)msg0
->v
)->flags
, ISAKMP_FLAG_E
)) {
1350 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1351 "reject the packet, "
1352 "expecting the packet encrypted.\n");
1355 msg
= oakley_do_decrypt(iph1
, msg0
, iph1
->ivm
->iv
, iph1
->ivm
->ive
);
1359 /* validate the type of next payload */
1360 pbuf
= isakmp_parse(msg
);
1364 iph1
->pl_hash
= NULL
;
1366 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
1367 pa
->type
!= ISAKMP_NPTYPE_NONE
;
1371 case ISAKMP_NPTYPE_ID
:
1372 if (isakmp_p2ph(&iph1
->id_p
, pa
->ptr
) < 0)
1374 if (resolveph1rmconf(iph1
) < 0)
1377 case ISAKMP_NPTYPE_HASH
:
1378 iph1
->pl_hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
1380 case ISAKMP_NPTYPE_CR
:
1381 if (oakley_savecr(iph1
, pa
->ptr
) < 0)
1384 case ISAKMP_NPTYPE_CERT
:
1385 if (oakley_savecert(iph1
, pa
->ptr
) < 0)
1388 case ISAKMP_NPTYPE_SIG
:
1389 if (isakmp_p2ph(&iph1
->sig_p
, pa
->ptr
) < 0)
1393 case ISAKMP_NPTYPE_GSS
:
1394 if (isakmp_p2ph(&gsstoken
, pa
->ptr
) < 0)
1396 gssapi_save_received_token(iph1
, gsstoken
);
1399 case ISAKMP_NPTYPE_VID
:
1400 handle_vendorid(iph1
, pa
->ptr
);
1402 case ISAKMP_NPTYPE_N
:
1403 ident_recv_n(iph1
, pa
->ptr
);
1406 /* don't send information, see ident_r1recv() */
1407 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1408 "ignore the packet, "
1409 "received unexpecting payload type %d.\n",
1415 /* payload existency check */
1416 /* XXX same as ident_i4recv(), should be merged. */
1420 switch (iph1
->approval
->authmethod
) {
1421 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
1422 #ifdef ENABLE_HYBRID
1423 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
:
1424 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
:
1425 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R
:
1427 if (iph1
->id_p
== NULL
|| iph1
->pl_hash
== NULL
)
1430 case OAKLEY_ATTR_AUTH_METHOD_DSSSIG
:
1431 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
1432 #ifdef ENABLE_HYBRID
1433 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
:
1434 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_R
:
1436 if (iph1
->id_p
== NULL
|| iph1
->sig_p
== NULL
)
1439 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
1440 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
1441 #ifdef ENABLE_HYBRID
1442 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_R
:
1443 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_R
:
1445 if (iph1
->pl_hash
== NULL
)
1449 case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
:
1450 if (gsstoken
== NULL
&& iph1
->pl_hash
== NULL
)
1455 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1456 "invalid authmethod %d why ?\n",
1457 iph1
->approval
->authmethod
);
1461 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1462 "few isakmp message received.\n");
1467 /* verify identifier */
1468 if (ipsecdoi_checkid1(iph1
) != 0) {
1469 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1470 "invalid ID payload.\n");
1474 /* validate authentication value */
1476 if (gsstoken
== NULL
) {
1478 type
= oakley_validate_auth(iph1
);
1481 /* msg printed inner oakley_validate_auth() */
1484 evt_phase1(iph1
, EVT_PHASE1_AUTH_FAILED
, NULL
);
1485 isakmp_info_send_n1(iph1
, type
, NULL
);
1492 if (oakley_checkcr(iph1
) < 0) {
1493 /* Ignore this error in order to be interoperability. */
1498 * XXX: Should we do compare two addresses, ph1handle's and ID
1502 plog(LLV_DEBUG
, LOCATION
, iph1
->remote
, "peer's ID\n");
1503 plogdump(LLV_DEBUG
, iph1
->id_p
->v
, iph1
->id_p
->l
);
1505 /* see handler.h about IV synchronization. */
1506 memcpy(iph1
->ivm
->iv
->v
, iph1
->ivm
->ive
->v
, iph1
->ivm
->ive
->l
);
1509 iph1
->status
= gsstoken
!= NULL
? PHASE1ST_MSG2RECEIVED
:
1510 PHASE1ST_MSG3RECEIVED
;
1512 iph1
->status
= PHASE1ST_MSG3RECEIVED
;
1528 VPTRINIT(iph1
->id_p
);
1529 VPTRINIT(iph1
->cert_p
);
1530 VPTRINIT(iph1
->crl_p
);
1531 VPTRINIT(iph1
->sig_p
);
1532 VPTRINIT(iph1
->cr_p
);
1540 * psk: HDR*, IDr1, HASH_R
1541 * sig: HDR*, IDr1, [ CERT, ] SIG_R
1542 * gssapi: HDR*, IDr1, < GSSr(n) | HASH_R >
1547 ident_r3send(iph1
, msg
)
1548 struct ph1handle
*iph1
;
1557 /* validity check */
1558 if (iph1
->status
!= PHASE1ST_MSG3RECEIVED
) {
1559 plog(LLV_ERROR
, LOCATION
, NULL
,
1560 "status mismatched %d.\n", iph1
->status
);
1564 /* make ID payload into isakmp status */
1565 if (ipsecdoi_setid1(iph1
) < 0)
1569 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
&&
1570 gssapi_more_tokens(iph1
)) {
1571 gssapi_get_rtoken(iph1
, &len
);
1578 /* generate HASH to send */
1579 plog(LLV_DEBUG
, LOCATION
, NULL
, "generate HASH_R\n");
1580 iph1
->hash
= oakley_ph1hash_common(iph1
, GENERATE
);
1581 if (iph1
->hash
== NULL
)
1586 /* set encryption flag */
1587 iph1
->flags
|= ISAKMP_FLAG_E
;
1589 /* create HDR;ID;HASH payload */
1590 iph1
->sendbuf
= ident_ir3mx(iph1
);
1591 if (iph1
->sendbuf
== NULL
)
1594 /* send HDR;ID;HASH to responder */
1595 if (isakmp_send(iph1
, iph1
->sendbuf
) < 0)
1598 /* the sending message is added to the received-list. */
1599 if (add_recvdpkt(iph1
->remote
, iph1
->local
, iph1
->sendbuf
, msg
) == -1) {
1600 plog(LLV_ERROR
, LOCATION
, NULL
,
1601 "failed to add a response packet to the tree.\n");
1605 /* see handler.h about IV synchronization. */
1606 memcpy(iph1
->ivm
->ive
->v
, iph1
->ivm
->iv
->v
, iph1
->ivm
->iv
->l
);
1608 iph1
->status
= PHASE1ST_ESTABLISHED
;
1618 * This is used in main mode for:
1619 * initiator's 3rd exchange send to responder
1622 * rsa: HDR, KE, [ HASH(1), ] <IDi1_b>PubKey_r, <Ni_b>PubKey_r
1623 * rev: HDR, [ HASH(1), ] <Ni_b>Pubkey_r, <KE_b>Ke_i,
1624 * <IDi1_b>Ke_i, [<<Cert-I_b>Ke_i]
1625 * responders 2nd exchnage send to initiator
1627 * sig: HDR, KE, Nr [, CR ]
1628 * rsa: HDR, KE, <IDr1_b>PubKey_i, <Nr_b>PubKey_i
1629 * rev: HDR, <Nr_b>PubKey_i, <KE_b>Ke_r, <IDr1_b>Ke_r,
1633 struct ph1handle
*iph1
;
1636 struct payload_list
*plist
= NULL
;
1637 vchar_t
*vid
= NULL
;
1640 vchar_t
*gsstoken
= NULL
;
1643 vchar_t
*natd
[2] = { NULL
, NULL
};
1647 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
) {
1648 if (gssapi_get_token_to_send(iph1
, &gsstoken
) < 0) {
1649 plog(LLV_ERROR
, LOCATION
, NULL
,
1650 "Failed to get gssapi token.\n");
1656 /* create isakmp KE payload */
1657 plist
= isakmp_plist_append(plist
, iph1
->dhpub
, ISAKMP_NPTYPE_KE
);
1659 /* create isakmp NONCE payload */
1660 plist
= isakmp_plist_append(plist
, iph1
->nonce
, ISAKMP_NPTYPE_NONCE
);
1663 if (iph1
->approval
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
)
1664 plist
= isakmp_plist_append(plist
, gsstoken
, ISAKMP_NPTYPE_GSS
);
1667 /* append vendor id, if needed */
1669 plist
= isakmp_plist_append(plist
, vid
, ISAKMP_NPTYPE_VID
);
1671 /* create CR if need */
1672 if (iph1
->side
== RESPONDER
&&
1673 oakley_needcr(iph1
->approval
->authmethod
))
1674 plist
= oakley_append_cr(plist
, iph1
);
1677 /* generate and append NAT-D payloads */
1678 if (NATT_AVAILABLE(iph1
) && iph1
->status
== PHASE1ST_MSG2RECEIVED
)
1680 if ((natd
[0] = natt_hash_addr (iph1
, iph1
->remote
)) == NULL
) {
1681 plog(LLV_ERROR
, LOCATION
, NULL
,
1682 "NAT-D hashing failed for %s\n", saddr2str(iph1
->remote
));
1686 if ((natd
[1] = natt_hash_addr (iph1
, iph1
->local
)) == NULL
) {
1687 plog(LLV_ERROR
, LOCATION
, NULL
,
1688 "NAT-D hashing failed for %s\n", saddr2str(iph1
->local
));
1692 plog (LLV_INFO
, LOCATION
, NULL
, "Adding remote and local NAT-D payloads.\n");
1693 plist
= isakmp_plist_append(plist
, natd
[0], iph1
->natt_options
->payload_nat_d
);
1694 plist
= isakmp_plist_append(plist
, natd
[1], iph1
->natt_options
->payload_nat_d
);
1698 buf
= isakmp_plist_set_all (&plist
, iph1
);
1703 if (error
&& buf
!= NULL
) {
1725 * This is used in main mode for:
1726 * initiator's 4th exchange send to responder
1727 * psk: HDR*, IDi1, HASH_I
1728 * sig: HDR*, IDi1, [ CR, ] [ CERT, ] SIG_I
1729 * gssapi: HDR*, [ IDi1, ] < GSSi(n) | HASH_I >
1732 * responders 3rd exchnage send to initiator
1733 * psk: HDR*, IDr1, HASH_R
1734 * sig: HDR*, IDr1, [ CERT, ] SIG_R
1735 * gssapi: HDR*, [ IDr1, ] < GSSr(n) | HASH_R >
1741 struct ph1handle
*iph1
;
1743 struct payload_list
*plist
= NULL
;
1744 vchar_t
*buf
= NULL
, *new = NULL
;
1749 vchar_t
*gsstoken
= NULL
;
1750 vchar_t
*gsshash
= NULL
;
1753 switch (iph1
->approval
->authmethod
) {
1754 case OAKLEY_ATTR_AUTH_METHOD_PSKEY
:
1755 #ifdef ENABLE_HYBRID
1756 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_I
:
1757 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
:
1758 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
1759 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I
:
1761 /* create isakmp ID payload */
1762 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
1764 /* create isakmp HASH payload */
1765 plist
= isakmp_plist_append(plist
, iph1
->hash
, ISAKMP_NPTYPE_HASH
);
1767 case OAKLEY_ATTR_AUTH_METHOD_DSSSIG
:
1768 case OAKLEY_ATTR_AUTH_METHOD_RSASIG
:
1769 #ifdef ENABLE_HYBRID
1770 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
:
1771 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R
:
1772 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
1773 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
:
1774 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_I
:
1775 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_R
:
1777 if (oakley_getmycert(iph1
) < 0)
1780 if (oakley_getsign(iph1
) < 0)
1783 if (iph1
->cert
!= NULL
&& iph1
->rmconf
->send_cert
)
1786 /* add ID payload */
1787 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
1789 /* add CERT payload if there */
1791 plist
= isakmp_plist_append(plist
, iph1
->cert
,
1792 ISAKMP_NPTYPE_CERT
);
1793 /* add SIG payload */
1794 plist
= isakmp_plist_append(plist
, iph1
->sig
, ISAKMP_NPTYPE_SIG
);
1796 /* create isakmp CR payload */
1797 if (iph1
->side
== INITIATOR
&&
1798 oakley_needcr(iph1
->approval
->authmethod
))
1799 plist
= oakley_append_cr(plist
, iph1
);
1802 case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
:
1803 if (iph1
->hash
!= NULL
) {
1804 gsshash
= gssapi_wraphash(iph1
);
1805 if (gsshash
== NULL
)
1808 if (gssapi_get_token_to_send(iph1
, &gsstoken
) < 0) {
1809 plog(LLV_ERROR
, LOCATION
, NULL
,
1810 "Failed to get gssapi token.\n");
1815 if (!gssapi_id_sent(iph1
)) {
1816 /* create isakmp ID payload */
1817 plist
= isakmp_plist_append(plist
, iph1
->id
, ISAKMP_NPTYPE_ID
);
1818 gssapi_set_id_sent(iph1
);
1821 if (iph1
->hash
!= NULL
)
1822 /* create isakmp HASH payload */
1823 plist
= isakmp_plist_append(plist
, gsshash
, ISAKMP_NPTYPE_HASH
);
1825 plist
= isakmp_plist_append(plist
, gsstoken
, ISAKMP_NPTYPE_GSS
);
1828 case OAKLEY_ATTR_AUTH_METHOD_RSAENC
:
1829 case OAKLEY_ATTR_AUTH_METHOD_RSAREV
:
1830 #ifdef ENABLE_HYBRID
1831 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
1832 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_R
:
1833 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
1834 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_R
:
1836 plog(LLV_ERROR
, LOCATION
, NULL
,
1837 "not supported authentication type %d\n",
1838 iph1
->approval
->authmethod
);
1841 plog(LLV_ERROR
, LOCATION
, NULL
,
1842 "invalid authentication type %d\n",
1843 iph1
->approval
->authmethod
);
1847 buf
= isakmp_plist_set_all (&plist
, iph1
);
1849 #ifdef HAVE_PRINT_ISAKMP_C
1850 isakmp_printpacket(buf
, iph1
->local
, iph1
->remote
, 1);
1854 new = oakley_do_encrypt(iph1
, buf
, iph1
->ivm
->ive
, iph1
->ivm
->iv
);
1869 if (error
&& buf
!= NULL
) {
1878 * handle a notification payload inside identity exchange.
1879 * called only when the packet has been verified to be encrypted.
1882 ident_recv_n(iph1
, gen
)
1883 struct ph1handle
*iph1
;
1884 struct isakmp_gen
*gen
;
1886 struct isakmp_pl_n
*notify
= (struct isakmp_pl_n
*) gen
;
1889 type
= ntohs(notify
->type
);
1891 case ISAKMP_NTYPE_INITIAL_CONTACT
:
1892 iph1
->initial_contact_received
= TRUE
;
1895 isakmp_log_notify(iph1
, notify
, "identity exchange");