3 /* $KAME: isakmp_newg.c,v 1.10 2002/09/27 05:55:52 itojun 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
36 #include <sys/types.h>
37 #include <sys/param.h>
52 #include "cfparse_proto.h"
53 #include "isakmp_var.h"
55 #include "isakmp_newg.h"
57 #include "ipsec_doi.h"
58 #include "crypto_openssl.h"
66 * New group mode as responder
69 isakmp_newgroup_r(iph1
, msg
)
70 struct ph1handle
*iph1
;
74 struct isakmp
*isakmp
= (struct isakmp
*)msg
->v
;
75 struct isakmp_pl_hash
*hash
= NULL
;
76 struct isakmp_pl_sa
*sa
= NULL
;
79 struct oakley_sa
*osa
;
82 /* validate the type of next payload */
84 * ISAKMP_ETYPE_NEWGRP,
85 * ISAKMP_NPTYPE_HASH, (ISAKMP_NPTYPE_VID), ISAKMP_NPTYPE_SA,
90 struct isakmp_parse_t
*pa
;
92 if ((pbuf
= isakmp_parse(msg
)) == NULL
)
95 for (pa
= (struct isakmp_parse_t
*)pbuf
->v
;
96 pa
->type
!= ISAKMP_NPTYPE_NONE
;
100 case ISAKMP_NPTYPE_HASH
:
102 isakmp_info_send_n1(iph1
, ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE
, NULL
);
103 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
104 "received multiple payload type %d.\n",
109 hash
= (struct isakmp_pl_hash
*)pa
->ptr
;
111 case ISAKMP_NPTYPE_SA
:
113 isakmp_info_send_n1(iph1
, ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE
, NULL
);
114 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
115 "received multiple payload type %d.\n",
120 sa
= (struct isakmp_pl_sa
*)pa
->ptr
;
122 case ISAKMP_NPTYPE_VID
:
123 (void)check_vendorid(pa
->ptr
);
126 isakmp_info_send_n1(iph1
, ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE
, NULL
);
127 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
128 "ignore the packet, "
129 "received unexpecting payload type %d.\n",
138 isakmp_info_send_n1(iph1
, ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE
, NULL
);
139 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
140 "no HASH, or no SA payload.\n");
148 vchar_t
*my_hash
= NULL
;
151 plog(LLV_DEBUG
, LOCATION
, NULL
, "validate HASH\n");
153 len
= sizeof(isakmp
->msgid
) + ntohs(sa
->h
.len
);
156 plog(LLV_ERROR
, LOCATION
, NULL
,
157 "failed to get buffer to send.\n");
160 memcpy(buf
->v
, &isakmp
->msgid
, sizeof(isakmp
->msgid
));
161 memcpy(buf
->v
+ sizeof(isakmp
->msgid
), sa
, ntohs(sa
->h
.len
));
163 plog(LLV_DEBUG
, LOCATION
, NULL
, "hash source\n");
164 plogdump(LLV_DEBUG
, buf
->v
, buf
->l
);
166 my_hash
= isakmp_prf(iph1
->skeyid_a
, buf
, iph1
);
171 plog(LLV_DEBUG
, LOCATION
, NULL
, "hash result\n");
172 plogdump(LLV_DEBUG
, my_hash
->v
, my_hash
->l
);
174 r_hash
= (char *)hash
+ sizeof(*hash
);
176 plog(LLV_DEBUG
, LOCATION
, NULL
, "original hash\n"));
177 plogdump(LLV_DEBUG
, r_hash
, ntohs(hash
->h
.len
) - sizeof(*hash
)));
179 result
= memcmp(my_hash
->v
, r_hash
, my_hash
->l
);
183 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
185 isakmp_info_send_n1(iph1
, ISAKMP_NTYPE_INVALID_HASH_INFORMATION
, NULL
);
190 /* check SA payload and get new one for use */
191 buf
= ipsecdoi_get_proposal((struct ipsecdoi_sa
*)sa
,
192 OAKLEY_NEWGROUP_MODE
);
194 isakmp_info_send_n1(iph1
, ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED
, NULL
);
198 /* save sa parameters */
199 osa
= ipsecdoi_get_oakley(buf
);
201 isakmp_info_send_n1(iph1
, ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED
, NULL
);
206 switch (osa
->dhgrp
) {
207 case OAKLEY_ATTR_GRP_DESC_MODP768
:
208 case OAKLEY_ATTR_GRP_DESC_MODP1024
:
209 case OAKLEY_ATTR_GRP_DESC_MODP1536
:
212 isakmp_info_send_n1(iph1
, ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED
, NULL
);
213 plog(LLV_ERROR
, LOCATION
, NULL
,
214 "dh group %d isn't supported.\n", osa
->dhgrp
);
218 plog(LLV_INFO
, LOCATION
, iph1
->remote
,
219 "got new dh group %s.\n", isakmp_pindex(&iph1
->index
, 0));
226 (void)isakmp_free_ph1(iph1
);