sl@0
|
1 |
/* ssl/d1_clnt.c */
|
sl@0
|
2 |
/*
|
sl@0
|
3 |
* DTLS implementation written by Nagendra Modadugu
|
sl@0
|
4 |
* (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
|
sl@0
|
5 |
*/
|
sl@0
|
6 |
/* ====================================================================
|
sl@0
|
7 |
* Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
10 |
* modification, are permitted provided that the following conditions
|
sl@0
|
11 |
* are met:
|
sl@0
|
12 |
*
|
sl@0
|
13 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
14 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
15 |
*
|
sl@0
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
17 |
* notice, this list of conditions and the following disclaimer in
|
sl@0
|
18 |
* the documentation and/or other materials provided with the
|
sl@0
|
19 |
* distribution.
|
sl@0
|
20 |
*
|
sl@0
|
21 |
* 3. All advertising materials mentioning features or use of this
|
sl@0
|
22 |
* software must display the following acknowledgment:
|
sl@0
|
23 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
24 |
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
sl@0
|
25 |
*
|
sl@0
|
26 |
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
sl@0
|
27 |
* endorse or promote products derived from this software without
|
sl@0
|
28 |
* prior written permission. For written permission, please contact
|
sl@0
|
29 |
* openssl-core@OpenSSL.org.
|
sl@0
|
30 |
*
|
sl@0
|
31 |
* 5. Products derived from this software may not be called "OpenSSL"
|
sl@0
|
32 |
* nor may "OpenSSL" appear in their names without prior written
|
sl@0
|
33 |
* permission of the OpenSSL Project.
|
sl@0
|
34 |
*
|
sl@0
|
35 |
* 6. Redistributions of any form whatsoever must retain the following
|
sl@0
|
36 |
* acknowledgment:
|
sl@0
|
37 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
38 |
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
sl@0
|
39 |
*
|
sl@0
|
40 |
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
sl@0
|
41 |
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
42 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
sl@0
|
43 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
sl@0
|
44 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
sl@0
|
45 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
sl@0
|
46 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
sl@0
|
47 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
48 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
49 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
sl@0
|
50 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
sl@0
|
51 |
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
52 |
* ====================================================================
|
sl@0
|
53 |
*
|
sl@0
|
54 |
* This product includes cryptographic software written by Eric Young
|
sl@0
|
55 |
* (eay@cryptsoft.com). This product includes software written by Tim
|
sl@0
|
56 |
* Hudson (tjh@cryptsoft.com).
|
sl@0
|
57 |
*
|
sl@0
|
58 |
*/
|
sl@0
|
59 |
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
sl@0
|
60 |
* All rights reserved.
|
sl@0
|
61 |
*
|
sl@0
|
62 |
* This package is an SSL implementation written
|
sl@0
|
63 |
* by Eric Young (eay@cryptsoft.com).
|
sl@0
|
64 |
* The implementation was written so as to conform with Netscapes SSL.
|
sl@0
|
65 |
*
|
sl@0
|
66 |
* This library is free for commercial and non-commercial use as long as
|
sl@0
|
67 |
* the following conditions are aheared to. The following conditions
|
sl@0
|
68 |
* apply to all code found in this distribution, be it the RC4, RSA,
|
sl@0
|
69 |
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
sl@0
|
70 |
* included with this distribution is covered by the same copyright terms
|
sl@0
|
71 |
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
sl@0
|
72 |
*
|
sl@0
|
73 |
* Copyright remains Eric Young's, and as such any Copyright notices in
|
sl@0
|
74 |
* the code are not to be removed.
|
sl@0
|
75 |
* If this package is used in a product, Eric Young should be given attribution
|
sl@0
|
76 |
* as the author of the parts of the library used.
|
sl@0
|
77 |
* This can be in the form of a textual message at program startup or
|
sl@0
|
78 |
* in documentation (online or textual) provided with the package.
|
sl@0
|
79 |
*
|
sl@0
|
80 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
81 |
* modification, are permitted provided that the following conditions
|
sl@0
|
82 |
* are met:
|
sl@0
|
83 |
* 1. Redistributions of source code must retain the copyright
|
sl@0
|
84 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
85 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
86 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
87 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
88 |
* 3. All advertising materials mentioning features or use of this software
|
sl@0
|
89 |
* must display the following acknowledgement:
|
sl@0
|
90 |
* "This product includes cryptographic software written by
|
sl@0
|
91 |
* Eric Young (eay@cryptsoft.com)"
|
sl@0
|
92 |
* The word 'cryptographic' can be left out if the rouines from the library
|
sl@0
|
93 |
* being used are not cryptographic related :-).
|
sl@0
|
94 |
* 4. If you include any Windows specific code (or a derivative thereof) from
|
sl@0
|
95 |
* the apps directory (application code) you must include an acknowledgement:
|
sl@0
|
96 |
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
sl@0
|
97 |
*
|
sl@0
|
98 |
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
sl@0
|
99 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
100 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
101 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
sl@0
|
102 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
sl@0
|
103 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
sl@0
|
104 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
105 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
sl@0
|
106 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
sl@0
|
107 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
sl@0
|
108 |
* SUCH DAMAGE.
|
sl@0
|
109 |
*
|
sl@0
|
110 |
* The licence and distribution terms for any publically available version or
|
sl@0
|
111 |
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
sl@0
|
112 |
* copied and put under another distribution licence
|
sl@0
|
113 |
* [including the GNU Public Licence.]
|
sl@0
|
114 |
*/
|
sl@0
|
115 |
/*
|
sl@0
|
116 |
© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
sl@0
|
117 |
*/
|
sl@0
|
118 |
|
sl@0
|
119 |
#include <stdio.h>
|
sl@0
|
120 |
#include "ssl_locl.h"
|
sl@0
|
121 |
#include "kssl_lcl.h"
|
sl@0
|
122 |
#include <openssl/buffer.h>
|
sl@0
|
123 |
#include <openssl/rand.h>
|
sl@0
|
124 |
#include <openssl/objects.h>
|
sl@0
|
125 |
#include <openssl/evp.h>
|
sl@0
|
126 |
#include <openssl/md5.h>
|
sl@0
|
127 |
#ifndef OPENSSL_NO_DH
|
sl@0
|
128 |
#include <openssl/dh.h>
|
sl@0
|
129 |
#endif
|
sl@0
|
130 |
|
sl@0
|
131 |
#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
|
sl@0
|
132 |
#include "libssl_wsd.h"
|
sl@0
|
133 |
#endif
|
sl@0
|
134 |
|
sl@0
|
135 |
#ifdef EMULATOR
|
sl@0
|
136 |
|
sl@0
|
137 |
GET_STATIC_VAR_FROM_TLS(DTLSv1_client_method_data,d1_clnt,SSL_METHOD)
|
sl@0
|
138 |
|
sl@0
|
139 |
#define DTLSv1_client_method_data (*GET_WSD_VAR_NAME(DTLSv1_client_method_data,d1_clnt,s)())
|
sl@0
|
140 |
|
sl@0
|
141 |
#endif
|
sl@0
|
142 |
|
sl@0
|
143 |
static SSL_METHOD *dtls1_get_client_method(int ver);
|
sl@0
|
144 |
static int dtls1_get_hello_verify(SSL *s);
|
sl@0
|
145 |
|
sl@0
|
146 |
static SSL_METHOD *dtls1_get_client_method(int ver)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
if (ver == DTLS1_VERSION)
|
sl@0
|
149 |
return(DTLSv1_client_method());
|
sl@0
|
150 |
else
|
sl@0
|
151 |
return(NULL);
|
sl@0
|
152 |
}
|
sl@0
|
153 |
|
sl@0
|
154 |
EXPORT_C IMPLEMENT_dtls1_meth_func(DTLSv1_client_method,
|
sl@0
|
155 |
ssl_undefined_function,
|
sl@0
|
156 |
dtls1_connect,
|
sl@0
|
157 |
dtls1_get_client_method)
|
sl@0
|
158 |
|
sl@0
|
159 |
int dtls1_connect(SSL *s)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
BUF_MEM *buf=NULL;
|
sl@0
|
162 |
unsigned long Time=(unsigned long)time(NULL),l;
|
sl@0
|
163 |
long num1;
|
sl@0
|
164 |
void (*cb)(const SSL *ssl,int type,int val)=NULL;
|
sl@0
|
165 |
int ret= -1;
|
sl@0
|
166 |
int new_state,state,skip=0;;
|
sl@0
|
167 |
|
sl@0
|
168 |
RAND_add(&Time,sizeof(Time),0);
|
sl@0
|
169 |
ERR_clear_error();
|
sl@0
|
170 |
clear_sys_error();
|
sl@0
|
171 |
|
sl@0
|
172 |
if (s->info_callback != NULL)
|
sl@0
|
173 |
cb=s->info_callback;
|
sl@0
|
174 |
else if (s->ctx->info_callback != NULL)
|
sl@0
|
175 |
cb=s->ctx->info_callback;
|
sl@0
|
176 |
|
sl@0
|
177 |
s->in_handshake++;
|
sl@0
|
178 |
if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
|
sl@0
|
179 |
|
sl@0
|
180 |
for (;;)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
state=s->state;
|
sl@0
|
183 |
|
sl@0
|
184 |
switch(s->state)
|
sl@0
|
185 |
{
|
sl@0
|
186 |
case SSL_ST_RENEGOTIATE:
|
sl@0
|
187 |
s->new_session=1;
|
sl@0
|
188 |
s->state=SSL_ST_CONNECT;
|
sl@0
|
189 |
s->ctx->stats.sess_connect_renegotiate++;
|
sl@0
|
190 |
/* break */
|
sl@0
|
191 |
case SSL_ST_BEFORE:
|
sl@0
|
192 |
case SSL_ST_CONNECT:
|
sl@0
|
193 |
case SSL_ST_BEFORE|SSL_ST_CONNECT:
|
sl@0
|
194 |
case SSL_ST_OK|SSL_ST_CONNECT:
|
sl@0
|
195 |
|
sl@0
|
196 |
s->server=0;
|
sl@0
|
197 |
if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
|
sl@0
|
198 |
|
sl@0
|
199 |
if ((s->version & 0xff00 ) != (DTLS1_VERSION & 0xff00))
|
sl@0
|
200 |
{
|
sl@0
|
201 |
SSLerr(SSL_F_DTLS1_CONNECT, ERR_R_INTERNAL_ERROR);
|
sl@0
|
202 |
ret = -1;
|
sl@0
|
203 |
goto end;
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
/* s->version=SSL3_VERSION; */
|
sl@0
|
207 |
s->type=SSL_ST_CONNECT;
|
sl@0
|
208 |
|
sl@0
|
209 |
if (s->init_buf == NULL)
|
sl@0
|
210 |
{
|
sl@0
|
211 |
if ((buf=BUF_MEM_new()) == NULL)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
ret= -1;
|
sl@0
|
214 |
goto end;
|
sl@0
|
215 |
}
|
sl@0
|
216 |
if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
|
sl@0
|
217 |
{
|
sl@0
|
218 |
ret= -1;
|
sl@0
|
219 |
goto end;
|
sl@0
|
220 |
}
|
sl@0
|
221 |
s->init_buf=buf;
|
sl@0
|
222 |
buf=NULL;
|
sl@0
|
223 |
}
|
sl@0
|
224 |
|
sl@0
|
225 |
if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
|
sl@0
|
226 |
|
sl@0
|
227 |
/* setup buffing BIO */
|
sl@0
|
228 |
if (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; }
|
sl@0
|
229 |
|
sl@0
|
230 |
/* don't push the buffering BIO quite yet */
|
sl@0
|
231 |
|
sl@0
|
232 |
s->state=SSL3_ST_CW_CLNT_HELLO_A;
|
sl@0
|
233 |
s->ctx->stats.sess_connect++;
|
sl@0
|
234 |
s->init_num=0;
|
sl@0
|
235 |
/* mark client_random uninitialized */
|
sl@0
|
236 |
memset(s->s3->client_random,0,sizeof(s->s3->client_random));
|
sl@0
|
237 |
break;
|
sl@0
|
238 |
|
sl@0
|
239 |
case SSL3_ST_CW_CLNT_HELLO_A:
|
sl@0
|
240 |
case SSL3_ST_CW_CLNT_HELLO_B:
|
sl@0
|
241 |
|
sl@0
|
242 |
s->shutdown=0;
|
sl@0
|
243 |
|
sl@0
|
244 |
/* every DTLS ClientHello resets Finished MAC */
|
sl@0
|
245 |
ssl3_init_finished_mac(s);
|
sl@0
|
246 |
|
sl@0
|
247 |
ret=dtls1_client_hello(s);
|
sl@0
|
248 |
if (ret <= 0) goto end;
|
sl@0
|
249 |
|
sl@0
|
250 |
if ( s->d1->send_cookie)
|
sl@0
|
251 |
{
|
sl@0
|
252 |
s->state=SSL3_ST_CW_FLUSH;
|
sl@0
|
253 |
s->s3->tmp.next_state=SSL3_ST_CR_SRVR_HELLO_A;
|
sl@0
|
254 |
}
|
sl@0
|
255 |
else
|
sl@0
|
256 |
s->state=SSL3_ST_CR_SRVR_HELLO_A;
|
sl@0
|
257 |
|
sl@0
|
258 |
s->init_num=0;
|
sl@0
|
259 |
|
sl@0
|
260 |
/* turn on buffering for the next lot of output */
|
sl@0
|
261 |
if (s->bbio != s->wbio)
|
sl@0
|
262 |
s->wbio=BIO_push(s->bbio,s->wbio);
|
sl@0
|
263 |
|
sl@0
|
264 |
break;
|
sl@0
|
265 |
|
sl@0
|
266 |
case SSL3_ST_CR_SRVR_HELLO_A:
|
sl@0
|
267 |
case SSL3_ST_CR_SRVR_HELLO_B:
|
sl@0
|
268 |
ret=ssl3_get_server_hello(s);
|
sl@0
|
269 |
if (ret <= 0) goto end;
|
sl@0
|
270 |
else
|
sl@0
|
271 |
{
|
sl@0
|
272 |
if (s->hit)
|
sl@0
|
273 |
s->state=SSL3_ST_CR_FINISHED_A;
|
sl@0
|
274 |
else
|
sl@0
|
275 |
s->state=DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A;
|
sl@0
|
276 |
}
|
sl@0
|
277 |
s->init_num=0;
|
sl@0
|
278 |
break;
|
sl@0
|
279 |
|
sl@0
|
280 |
case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
|
sl@0
|
281 |
case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
|
sl@0
|
282 |
|
sl@0
|
283 |
ret = dtls1_get_hello_verify(s);
|
sl@0
|
284 |
if ( ret <= 0)
|
sl@0
|
285 |
goto end;
|
sl@0
|
286 |
if ( s->d1->send_cookie) /* start again, with a cookie */
|
sl@0
|
287 |
s->state=SSL3_ST_CW_CLNT_HELLO_A;
|
sl@0
|
288 |
else
|
sl@0
|
289 |
s->state = SSL3_ST_CR_CERT_A;
|
sl@0
|
290 |
s->init_num = 0;
|
sl@0
|
291 |
break;
|
sl@0
|
292 |
|
sl@0
|
293 |
case SSL3_ST_CR_CERT_A:
|
sl@0
|
294 |
case SSL3_ST_CR_CERT_B:
|
sl@0
|
295 |
/* Check if it is anon DH */
|
sl@0
|
296 |
if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
|
sl@0
|
297 |
{
|
sl@0
|
298 |
ret=ssl3_get_server_certificate(s);
|
sl@0
|
299 |
if (ret <= 0) goto end;
|
sl@0
|
300 |
}
|
sl@0
|
301 |
else
|
sl@0
|
302 |
skip=1;
|
sl@0
|
303 |
s->state=SSL3_ST_CR_KEY_EXCH_A;
|
sl@0
|
304 |
s->init_num=0;
|
sl@0
|
305 |
break;
|
sl@0
|
306 |
|
sl@0
|
307 |
case SSL3_ST_CR_KEY_EXCH_A:
|
sl@0
|
308 |
case SSL3_ST_CR_KEY_EXCH_B:
|
sl@0
|
309 |
ret=ssl3_get_key_exchange(s);
|
sl@0
|
310 |
if (ret <= 0) goto end;
|
sl@0
|
311 |
s->state=SSL3_ST_CR_CERT_REQ_A;
|
sl@0
|
312 |
s->init_num=0;
|
sl@0
|
313 |
|
sl@0
|
314 |
/* at this point we check that we have the
|
sl@0
|
315 |
* required stuff from the server */
|
sl@0
|
316 |
if (!ssl3_check_cert_and_algorithm(s))
|
sl@0
|
317 |
{
|
sl@0
|
318 |
ret= -1;
|
sl@0
|
319 |
goto end;
|
sl@0
|
320 |
}
|
sl@0
|
321 |
break;
|
sl@0
|
322 |
|
sl@0
|
323 |
case SSL3_ST_CR_CERT_REQ_A:
|
sl@0
|
324 |
case SSL3_ST_CR_CERT_REQ_B:
|
sl@0
|
325 |
ret=ssl3_get_certificate_request(s);
|
sl@0
|
326 |
if (ret <= 0) goto end;
|
sl@0
|
327 |
s->state=SSL3_ST_CR_SRVR_DONE_A;
|
sl@0
|
328 |
s->init_num=0;
|
sl@0
|
329 |
break;
|
sl@0
|
330 |
|
sl@0
|
331 |
case SSL3_ST_CR_SRVR_DONE_A:
|
sl@0
|
332 |
case SSL3_ST_CR_SRVR_DONE_B:
|
sl@0
|
333 |
ret=ssl3_get_server_done(s);
|
sl@0
|
334 |
if (ret <= 0) goto end;
|
sl@0
|
335 |
if (s->s3->tmp.cert_req)
|
sl@0
|
336 |
s->state=SSL3_ST_CW_CERT_A;
|
sl@0
|
337 |
else
|
sl@0
|
338 |
s->state=SSL3_ST_CW_KEY_EXCH_A;
|
sl@0
|
339 |
s->init_num=0;
|
sl@0
|
340 |
|
sl@0
|
341 |
break;
|
sl@0
|
342 |
|
sl@0
|
343 |
case SSL3_ST_CW_CERT_A:
|
sl@0
|
344 |
case SSL3_ST_CW_CERT_B:
|
sl@0
|
345 |
case SSL3_ST_CW_CERT_C:
|
sl@0
|
346 |
case SSL3_ST_CW_CERT_D:
|
sl@0
|
347 |
ret=dtls1_send_client_certificate(s);
|
sl@0
|
348 |
if (ret <= 0) goto end;
|
sl@0
|
349 |
s->state=SSL3_ST_CW_KEY_EXCH_A;
|
sl@0
|
350 |
s->init_num=0;
|
sl@0
|
351 |
break;
|
sl@0
|
352 |
|
sl@0
|
353 |
case SSL3_ST_CW_KEY_EXCH_A:
|
sl@0
|
354 |
case SSL3_ST_CW_KEY_EXCH_B:
|
sl@0
|
355 |
ret=dtls1_send_client_key_exchange(s);
|
sl@0
|
356 |
if (ret <= 0) goto end;
|
sl@0
|
357 |
l=s->s3->tmp.new_cipher->algorithms;
|
sl@0
|
358 |
/* EAY EAY EAY need to check for DH fix cert
|
sl@0
|
359 |
* sent back */
|
sl@0
|
360 |
/* For TLS, cert_req is set to 2, so a cert chain
|
sl@0
|
361 |
* of nothing is sent, but no verify packet is sent */
|
sl@0
|
362 |
if (s->s3->tmp.cert_req == 1)
|
sl@0
|
363 |
{
|
sl@0
|
364 |
s->state=SSL3_ST_CW_CERT_VRFY_A;
|
sl@0
|
365 |
}
|
sl@0
|
366 |
else
|
sl@0
|
367 |
{
|
sl@0
|
368 |
s->state=SSL3_ST_CW_CHANGE_A;
|
sl@0
|
369 |
s->s3->change_cipher_spec=0;
|
sl@0
|
370 |
}
|
sl@0
|
371 |
|
sl@0
|
372 |
s->init_num=0;
|
sl@0
|
373 |
break;
|
sl@0
|
374 |
|
sl@0
|
375 |
case SSL3_ST_CW_CERT_VRFY_A:
|
sl@0
|
376 |
case SSL3_ST_CW_CERT_VRFY_B:
|
sl@0
|
377 |
ret=dtls1_send_client_verify(s);
|
sl@0
|
378 |
if (ret <= 0) goto end;
|
sl@0
|
379 |
s->state=SSL3_ST_CW_CHANGE_A;
|
sl@0
|
380 |
s->init_num=0;
|
sl@0
|
381 |
s->s3->change_cipher_spec=0;
|
sl@0
|
382 |
break;
|
sl@0
|
383 |
|
sl@0
|
384 |
case SSL3_ST_CW_CHANGE_A:
|
sl@0
|
385 |
case SSL3_ST_CW_CHANGE_B:
|
sl@0
|
386 |
ret=dtls1_send_change_cipher_spec(s,
|
sl@0
|
387 |
SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);
|
sl@0
|
388 |
if (ret <= 0) goto end;
|
sl@0
|
389 |
s->state=SSL3_ST_CW_FINISHED_A;
|
sl@0
|
390 |
s->init_num=0;
|
sl@0
|
391 |
|
sl@0
|
392 |
s->session->cipher=s->s3->tmp.new_cipher;
|
sl@0
|
393 |
#ifdef OPENSSL_NO_COMP
|
sl@0
|
394 |
s->session->compress_meth=0;
|
sl@0
|
395 |
#else
|
sl@0
|
396 |
if (s->s3->tmp.new_compression == NULL)
|
sl@0
|
397 |
s->session->compress_meth=0;
|
sl@0
|
398 |
else
|
sl@0
|
399 |
s->session->compress_meth=
|
sl@0
|
400 |
s->s3->tmp.new_compression->id;
|
sl@0
|
401 |
#endif
|
sl@0
|
402 |
if (!s->method->ssl3_enc->setup_key_block(s))
|
sl@0
|
403 |
{
|
sl@0
|
404 |
ret= -1;
|
sl@0
|
405 |
goto end;
|
sl@0
|
406 |
}
|
sl@0
|
407 |
|
sl@0
|
408 |
if (!s->method->ssl3_enc->change_cipher_state(s,
|
sl@0
|
409 |
SSL3_CHANGE_CIPHER_CLIENT_WRITE))
|
sl@0
|
410 |
{
|
sl@0
|
411 |
ret= -1;
|
sl@0
|
412 |
goto end;
|
sl@0
|
413 |
}
|
sl@0
|
414 |
|
sl@0
|
415 |
dtls1_reset_seq_numbers(s, SSL3_CC_WRITE);
|
sl@0
|
416 |
break;
|
sl@0
|
417 |
|
sl@0
|
418 |
case SSL3_ST_CW_FINISHED_A:
|
sl@0
|
419 |
case SSL3_ST_CW_FINISHED_B:
|
sl@0
|
420 |
ret=dtls1_send_finished(s,
|
sl@0
|
421 |
SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,
|
sl@0
|
422 |
s->method->ssl3_enc->client_finished_label,
|
sl@0
|
423 |
s->method->ssl3_enc->client_finished_label_len);
|
sl@0
|
424 |
if (ret <= 0) goto end;
|
sl@0
|
425 |
s->state=SSL3_ST_CW_FLUSH;
|
sl@0
|
426 |
|
sl@0
|
427 |
/* clear flags */
|
sl@0
|
428 |
s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
|
sl@0
|
429 |
if (s->hit)
|
sl@0
|
430 |
{
|
sl@0
|
431 |
s->s3->tmp.next_state=SSL_ST_OK;
|
sl@0
|
432 |
if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)
|
sl@0
|
433 |
{
|
sl@0
|
434 |
s->state=SSL_ST_OK;
|
sl@0
|
435 |
s->s3->flags|=SSL3_FLAGS_POP_BUFFER;
|
sl@0
|
436 |
s->s3->delay_buf_pop_ret=0;
|
sl@0
|
437 |
}
|
sl@0
|
438 |
}
|
sl@0
|
439 |
else
|
sl@0
|
440 |
{
|
sl@0
|
441 |
s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;
|
sl@0
|
442 |
}
|
sl@0
|
443 |
s->init_num=0;
|
sl@0
|
444 |
/* mark client_random uninitialized */
|
sl@0
|
445 |
memset (s->s3->client_random,0,sizeof(s->s3->client_random));
|
sl@0
|
446 |
|
sl@0
|
447 |
break;
|
sl@0
|
448 |
|
sl@0
|
449 |
case SSL3_ST_CR_FINISHED_A:
|
sl@0
|
450 |
case SSL3_ST_CR_FINISHED_B:
|
sl@0
|
451 |
|
sl@0
|
452 |
ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,
|
sl@0
|
453 |
SSL3_ST_CR_FINISHED_B);
|
sl@0
|
454 |
if (ret <= 0) goto end;
|
sl@0
|
455 |
|
sl@0
|
456 |
if (s->hit)
|
sl@0
|
457 |
s->state=SSL3_ST_CW_CHANGE_A;
|
sl@0
|
458 |
else
|
sl@0
|
459 |
s->state=SSL_ST_OK;
|
sl@0
|
460 |
s->init_num=0;
|
sl@0
|
461 |
break;
|
sl@0
|
462 |
|
sl@0
|
463 |
case SSL3_ST_CW_FLUSH:
|
sl@0
|
464 |
/* number of bytes to be flushed */
|
sl@0
|
465 |
num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);
|
sl@0
|
466 |
if (num1 > 0)
|
sl@0
|
467 |
{
|
sl@0
|
468 |
s->rwstate=SSL_WRITING;
|
sl@0
|
469 |
num1=BIO_flush(s->wbio);
|
sl@0
|
470 |
if (num1 <= 0) { ret= -1; goto end; }
|
sl@0
|
471 |
s->rwstate=SSL_NOTHING;
|
sl@0
|
472 |
}
|
sl@0
|
473 |
|
sl@0
|
474 |
s->state=s->s3->tmp.next_state;
|
sl@0
|
475 |
break;
|
sl@0
|
476 |
|
sl@0
|
477 |
case SSL_ST_OK:
|
sl@0
|
478 |
/* clean a few things up */
|
sl@0
|
479 |
ssl3_cleanup_key_block(s);
|
sl@0
|
480 |
|
sl@0
|
481 |
#if 0
|
sl@0
|
482 |
if (s->init_buf != NULL)
|
sl@0
|
483 |
{
|
sl@0
|
484 |
BUF_MEM_free(s->init_buf);
|
sl@0
|
485 |
s->init_buf=NULL;
|
sl@0
|
486 |
}
|
sl@0
|
487 |
#endif
|
sl@0
|
488 |
|
sl@0
|
489 |
/* If we are not 'joining' the last two packets,
|
sl@0
|
490 |
* remove the buffering now */
|
sl@0
|
491 |
if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))
|
sl@0
|
492 |
ssl_free_wbio_buffer(s);
|
sl@0
|
493 |
/* else do it later in ssl3_write */
|
sl@0
|
494 |
|
sl@0
|
495 |
s->init_num=0;
|
sl@0
|
496 |
s->new_session=0;
|
sl@0
|
497 |
|
sl@0
|
498 |
ssl_update_cache(s,SSL_SESS_CACHE_CLIENT);
|
sl@0
|
499 |
if (s->hit) s->ctx->stats.sess_hit++;
|
sl@0
|
500 |
|
sl@0
|
501 |
ret=1;
|
sl@0
|
502 |
/* s->server=0; */
|
sl@0
|
503 |
s->handshake_func=dtls1_connect;
|
sl@0
|
504 |
s->ctx->stats.sess_connect_good++;
|
sl@0
|
505 |
|
sl@0
|
506 |
if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
|
sl@0
|
507 |
|
sl@0
|
508 |
/* done with handshaking */
|
sl@0
|
509 |
s->d1->handshake_read_seq = 0;
|
sl@0
|
510 |
goto end;
|
sl@0
|
511 |
/* break; */
|
sl@0
|
512 |
|
sl@0
|
513 |
default:
|
sl@0
|
514 |
SSLerr(SSL_F_DTLS1_CONNECT,SSL_R_UNKNOWN_STATE);
|
sl@0
|
515 |
ret= -1;
|
sl@0
|
516 |
goto end;
|
sl@0
|
517 |
/* break; */
|
sl@0
|
518 |
}
|
sl@0
|
519 |
|
sl@0
|
520 |
/* did we do anything */
|
sl@0
|
521 |
if (!s->s3->tmp.reuse_message && !skip)
|
sl@0
|
522 |
{
|
sl@0
|
523 |
if (s->debug)
|
sl@0
|
524 |
{
|
sl@0
|
525 |
if ((ret=BIO_flush(s->wbio)) <= 0)
|
sl@0
|
526 |
goto end;
|
sl@0
|
527 |
}
|
sl@0
|
528 |
|
sl@0
|
529 |
if ((cb != NULL) && (s->state != state))
|
sl@0
|
530 |
{
|
sl@0
|
531 |
new_state=s->state;
|
sl@0
|
532 |
s->state=state;
|
sl@0
|
533 |
cb(s,SSL_CB_CONNECT_LOOP,1);
|
sl@0
|
534 |
s->state=new_state;
|
sl@0
|
535 |
}
|
sl@0
|
536 |
}
|
sl@0
|
537 |
skip=0;
|
sl@0
|
538 |
}
|
sl@0
|
539 |
end:
|
sl@0
|
540 |
s->in_handshake--;
|
sl@0
|
541 |
if (buf != NULL)
|
sl@0
|
542 |
BUF_MEM_free(buf);
|
sl@0
|
543 |
if (cb != NULL)
|
sl@0
|
544 |
cb(s,SSL_CB_CONNECT_EXIT,ret);
|
sl@0
|
545 |
return(ret);
|
sl@0
|
546 |
}
|
sl@0
|
547 |
|
sl@0
|
548 |
int dtls1_client_hello(SSL *s)
|
sl@0
|
549 |
{
|
sl@0
|
550 |
unsigned char *buf;
|
sl@0
|
551 |
unsigned char *p,*d;
|
sl@0
|
552 |
unsigned int i,j;
|
sl@0
|
553 |
unsigned long Time,l;
|
sl@0
|
554 |
SSL_COMP *comp;
|
sl@0
|
555 |
|
sl@0
|
556 |
buf=(unsigned char *)s->init_buf->data;
|
sl@0
|
557 |
if (s->state == SSL3_ST_CW_CLNT_HELLO_A)
|
sl@0
|
558 |
{
|
sl@0
|
559 |
if ((s->session == NULL) ||
|
sl@0
|
560 |
(s->session->ssl_version != s->version) ||
|
sl@0
|
561 |
(s->session->not_resumable))
|
sl@0
|
562 |
{
|
sl@0
|
563 |
if (!ssl_get_new_session(s,0))
|
sl@0
|
564 |
goto err;
|
sl@0
|
565 |
}
|
sl@0
|
566 |
/* else use the pre-loaded session */
|
sl@0
|
567 |
|
sl@0
|
568 |
p=s->s3->client_random;
|
sl@0
|
569 |
/* if client_random is initialized, reuse it, we are
|
sl@0
|
570 |
* required to use same upon reply to HelloVerify */
|
sl@0
|
571 |
for (i=0;p[i]=='\0' && i<sizeof(s->s3->client_random);i++) ;
|
sl@0
|
572 |
if (i==sizeof(s->s3->client_random))
|
sl@0
|
573 |
{
|
sl@0
|
574 |
Time=(unsigned long)time(NULL); /* Time */
|
sl@0
|
575 |
l2n(Time,p);
|
sl@0
|
576 |
RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4);
|
sl@0
|
577 |
}
|
sl@0
|
578 |
|
sl@0
|
579 |
/* Do the message type and length last */
|
sl@0
|
580 |
d=p= &(buf[DTLS1_HM_HEADER_LENGTH]);
|
sl@0
|
581 |
|
sl@0
|
582 |
*(p++)=s->version>>8;
|
sl@0
|
583 |
*(p++)=s->version&0xff;
|
sl@0
|
584 |
s->client_version=s->version;
|
sl@0
|
585 |
|
sl@0
|
586 |
/* Random stuff */
|
sl@0
|
587 |
memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
|
sl@0
|
588 |
p+=SSL3_RANDOM_SIZE;
|
sl@0
|
589 |
|
sl@0
|
590 |
/* Session ID */
|
sl@0
|
591 |
if (s->new_session)
|
sl@0
|
592 |
i=0;
|
sl@0
|
593 |
else
|
sl@0
|
594 |
i=s->session->session_id_length;
|
sl@0
|
595 |
*(p++)=i;
|
sl@0
|
596 |
if (i != 0)
|
sl@0
|
597 |
{
|
sl@0
|
598 |
if (i > sizeof s->session->session_id)
|
sl@0
|
599 |
{
|
sl@0
|
600 |
SSLerr(SSL_F_DTLS1_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
|
sl@0
|
601 |
goto err;
|
sl@0
|
602 |
}
|
sl@0
|
603 |
memcpy(p,s->session->session_id,i);
|
sl@0
|
604 |
p+=i;
|
sl@0
|
605 |
}
|
sl@0
|
606 |
|
sl@0
|
607 |
/* cookie stuff */
|
sl@0
|
608 |
if ( s->d1->cookie_len > sizeof(s->d1->cookie))
|
sl@0
|
609 |
{
|
sl@0
|
610 |
SSLerr(SSL_F_DTLS1_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
|
sl@0
|
611 |
goto err;
|
sl@0
|
612 |
}
|
sl@0
|
613 |
*(p++) = s->d1->cookie_len;
|
sl@0
|
614 |
memcpy(p, s->d1->cookie, s->d1->cookie_len);
|
sl@0
|
615 |
p += s->d1->cookie_len;
|
sl@0
|
616 |
|
sl@0
|
617 |
/* Ciphers supported */
|
sl@0
|
618 |
i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),&(p[2]),0);
|
sl@0
|
619 |
if (i == 0)
|
sl@0
|
620 |
{
|
sl@0
|
621 |
SSLerr(SSL_F_DTLS1_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE);
|
sl@0
|
622 |
goto err;
|
sl@0
|
623 |
}
|
sl@0
|
624 |
s2n(i,p);
|
sl@0
|
625 |
p+=i;
|
sl@0
|
626 |
|
sl@0
|
627 |
/* COMPRESSION */
|
sl@0
|
628 |
if (s->ctx->comp_methods == NULL)
|
sl@0
|
629 |
j=0;
|
sl@0
|
630 |
else
|
sl@0
|
631 |
j=sk_SSL_COMP_num(s->ctx->comp_methods);
|
sl@0
|
632 |
*(p++)=1+j;
|
sl@0
|
633 |
for (i=0; i<j; i++)
|
sl@0
|
634 |
{
|
sl@0
|
635 |
comp=sk_SSL_COMP_value(s->ctx->comp_methods,i);
|
sl@0
|
636 |
*(p++)=comp->id;
|
sl@0
|
637 |
}
|
sl@0
|
638 |
*(p++)=0; /* Add the NULL method */
|
sl@0
|
639 |
|
sl@0
|
640 |
l=(p-d);
|
sl@0
|
641 |
d=buf;
|
sl@0
|
642 |
|
sl@0
|
643 |
d = dtls1_set_message_header(s, d, SSL3_MT_CLIENT_HELLO, l, 0, l);
|
sl@0
|
644 |
|
sl@0
|
645 |
s->state=SSL3_ST_CW_CLNT_HELLO_B;
|
sl@0
|
646 |
/* number of bytes to write */
|
sl@0
|
647 |
s->init_num=p-buf;
|
sl@0
|
648 |
s->init_off=0;
|
sl@0
|
649 |
|
sl@0
|
650 |
/* buffer the message to handle re-xmits */
|
sl@0
|
651 |
dtls1_buffer_message(s, 0);
|
sl@0
|
652 |
}
|
sl@0
|
653 |
|
sl@0
|
654 |
/* SSL3_ST_CW_CLNT_HELLO_B */
|
sl@0
|
655 |
return(dtls1_do_write(s,SSL3_RT_HANDSHAKE));
|
sl@0
|
656 |
err:
|
sl@0
|
657 |
return(-1);
|
sl@0
|
658 |
}
|
sl@0
|
659 |
|
sl@0
|
660 |
static int dtls1_get_hello_verify(SSL *s)
|
sl@0
|
661 |
{
|
sl@0
|
662 |
int n, al, ok = 0;
|
sl@0
|
663 |
unsigned char *data;
|
sl@0
|
664 |
unsigned int cookie_len;
|
sl@0
|
665 |
|
sl@0
|
666 |
n=s->method->ssl_get_message(s,
|
sl@0
|
667 |
DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A,
|
sl@0
|
668 |
DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B,
|
sl@0
|
669 |
-1,
|
sl@0
|
670 |
s->max_cert_list,
|
sl@0
|
671 |
&ok);
|
sl@0
|
672 |
|
sl@0
|
673 |
if (!ok) return((int)n);
|
sl@0
|
674 |
|
sl@0
|
675 |
if (s->s3->tmp.message_type != DTLS1_MT_HELLO_VERIFY_REQUEST)
|
sl@0
|
676 |
{
|
sl@0
|
677 |
s->d1->send_cookie = 0;
|
sl@0
|
678 |
s->s3->tmp.reuse_message=1;
|
sl@0
|
679 |
return(1);
|
sl@0
|
680 |
}
|
sl@0
|
681 |
|
sl@0
|
682 |
data = (unsigned char *)s->init_msg;
|
sl@0
|
683 |
|
sl@0
|
684 |
if ((data[0] != (s->version>>8)) || (data[1] != (s->version&0xff)))
|
sl@0
|
685 |
{
|
sl@0
|
686 |
SSLerr(SSL_F_DTLS1_GET_HELLO_VERIFY,SSL_R_WRONG_SSL_VERSION);
|
sl@0
|
687 |
s->version=(s->version&0xff00)|data[1];
|
sl@0
|
688 |
al = SSL_AD_PROTOCOL_VERSION;
|
sl@0
|
689 |
goto f_err;
|
sl@0
|
690 |
}
|
sl@0
|
691 |
data+=2;
|
sl@0
|
692 |
|
sl@0
|
693 |
cookie_len = *(data++);
|
sl@0
|
694 |
if ( cookie_len > sizeof(s->d1->cookie))
|
sl@0
|
695 |
{
|
sl@0
|
696 |
al=SSL_AD_ILLEGAL_PARAMETER;
|
sl@0
|
697 |
goto f_err;
|
sl@0
|
698 |
}
|
sl@0
|
699 |
|
sl@0
|
700 |
memcpy(s->d1->cookie, data, cookie_len);
|
sl@0
|
701 |
s->d1->cookie_len = cookie_len;
|
sl@0
|
702 |
|
sl@0
|
703 |
s->d1->send_cookie = 1;
|
sl@0
|
704 |
return 1;
|
sl@0
|
705 |
|
sl@0
|
706 |
f_err:
|
sl@0
|
707 |
ssl3_send_alert(s, SSL3_AL_FATAL, al);
|
sl@0
|
708 |
return -1;
|
sl@0
|
709 |
}
|
sl@0
|
710 |
|
sl@0
|
711 |
int dtls1_send_client_key_exchange(SSL *s)
|
sl@0
|
712 |
{
|
sl@0
|
713 |
unsigned char *p,*d;
|
sl@0
|
714 |
int n;
|
sl@0
|
715 |
unsigned long l;
|
sl@0
|
716 |
#ifndef OPENSSL_NO_RSA
|
sl@0
|
717 |
unsigned char *q;
|
sl@0
|
718 |
EVP_PKEY *pkey=NULL;
|
sl@0
|
719 |
#endif
|
sl@0
|
720 |
#ifndef OPENSSL_NO_KRB5
|
sl@0
|
721 |
KSSL_ERR kssl_err;
|
sl@0
|
722 |
#endif /* OPENSSL_NO_KRB5 */
|
sl@0
|
723 |
|
sl@0
|
724 |
if (s->state == SSL3_ST_CW_KEY_EXCH_A)
|
sl@0
|
725 |
{
|
sl@0
|
726 |
d=(unsigned char *)s->init_buf->data;
|
sl@0
|
727 |
p= &(d[DTLS1_HM_HEADER_LENGTH]);
|
sl@0
|
728 |
|
sl@0
|
729 |
l=s->s3->tmp.new_cipher->algorithms;
|
sl@0
|
730 |
|
sl@0
|
731 |
/* Fool emacs indentation */
|
sl@0
|
732 |
if (0) {}
|
sl@0
|
733 |
#ifndef OPENSSL_NO_RSA
|
sl@0
|
734 |
else if (l & SSL_kRSA)
|
sl@0
|
735 |
{
|
sl@0
|
736 |
RSA *rsa;
|
sl@0
|
737 |
unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
|
sl@0
|
738 |
|
sl@0
|
739 |
if (s->session->sess_cert->peer_rsa_tmp != NULL)
|
sl@0
|
740 |
rsa=s->session->sess_cert->peer_rsa_tmp;
|
sl@0
|
741 |
else
|
sl@0
|
742 |
{
|
sl@0
|
743 |
pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
|
sl@0
|
744 |
if ((pkey == NULL) ||
|
sl@0
|
745 |
(pkey->type != EVP_PKEY_RSA) ||
|
sl@0
|
746 |
(pkey->pkey.rsa == NULL))
|
sl@0
|
747 |
{
|
sl@0
|
748 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR);
|
sl@0
|
749 |
goto err;
|
sl@0
|
750 |
}
|
sl@0
|
751 |
rsa=pkey->pkey.rsa;
|
sl@0
|
752 |
EVP_PKEY_free(pkey);
|
sl@0
|
753 |
}
|
sl@0
|
754 |
|
sl@0
|
755 |
tmp_buf[0]=s->client_version>>8;
|
sl@0
|
756 |
tmp_buf[1]=s->client_version&0xff;
|
sl@0
|
757 |
if (RAND_bytes(&(tmp_buf[2]),sizeof tmp_buf-2) <= 0)
|
sl@0
|
758 |
goto err;
|
sl@0
|
759 |
|
sl@0
|
760 |
s->session->master_key_length=sizeof tmp_buf;
|
sl@0
|
761 |
|
sl@0
|
762 |
q=p;
|
sl@0
|
763 |
/* Fix buf for TLS and [incidentally] DTLS */
|
sl@0
|
764 |
if (s->version > SSL3_VERSION)
|
sl@0
|
765 |
p+=2;
|
sl@0
|
766 |
n=RSA_public_encrypt(sizeof tmp_buf,
|
sl@0
|
767 |
tmp_buf,p,rsa,RSA_PKCS1_PADDING);
|
sl@0
|
768 |
#ifdef PKCS1_CHECK
|
sl@0
|
769 |
if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++;
|
sl@0
|
770 |
if (s->options & SSL_OP_PKCS1_CHECK_2) tmp_buf[0]=0x70;
|
sl@0
|
771 |
#endif
|
sl@0
|
772 |
if (n <= 0)
|
sl@0
|
773 |
{
|
sl@0
|
774 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT);
|
sl@0
|
775 |
goto err;
|
sl@0
|
776 |
}
|
sl@0
|
777 |
|
sl@0
|
778 |
/* Fix buf for TLS and [incidentally] DTLS */
|
sl@0
|
779 |
if (s->version > SSL3_VERSION)
|
sl@0
|
780 |
{
|
sl@0
|
781 |
s2n(n,q);
|
sl@0
|
782 |
n+=2;
|
sl@0
|
783 |
}
|
sl@0
|
784 |
|
sl@0
|
785 |
s->session->master_key_length=
|
sl@0
|
786 |
s->method->ssl3_enc->generate_master_secret(s,
|
sl@0
|
787 |
s->session->master_key,
|
sl@0
|
788 |
tmp_buf,sizeof tmp_buf);
|
sl@0
|
789 |
OPENSSL_cleanse(tmp_buf,sizeof tmp_buf);
|
sl@0
|
790 |
}
|
sl@0
|
791 |
#endif
|
sl@0
|
792 |
#ifndef OPENSSL_NO_KRB5
|
sl@0
|
793 |
else if (l & SSL_kKRB5)
|
sl@0
|
794 |
{
|
sl@0
|
795 |
krb5_error_code krb5rc;
|
sl@0
|
796 |
KSSL_CTX *kssl_ctx = s->kssl_ctx;
|
sl@0
|
797 |
/* krb5_data krb5_ap_req; */
|
sl@0
|
798 |
krb5_data *enc_ticket;
|
sl@0
|
799 |
krb5_data authenticator, *authp = NULL;
|
sl@0
|
800 |
EVP_CIPHER_CTX ciph_ctx;
|
sl@0
|
801 |
EVP_CIPHER *enc = NULL;
|
sl@0
|
802 |
unsigned char iv[EVP_MAX_IV_LENGTH];
|
sl@0
|
803 |
unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
|
sl@0
|
804 |
unsigned char epms[SSL_MAX_MASTER_KEY_LENGTH
|
sl@0
|
805 |
+ EVP_MAX_IV_LENGTH];
|
sl@0
|
806 |
int padl, outl = sizeof(epms);
|
sl@0
|
807 |
|
sl@0
|
808 |
EVP_CIPHER_CTX_init(&ciph_ctx);
|
sl@0
|
809 |
|
sl@0
|
810 |
#ifdef KSSL_DEBUG
|
sl@0
|
811 |
printf("ssl3_send_client_key_exchange(%lx & %lx)\n",
|
sl@0
|
812 |
l, SSL_kKRB5);
|
sl@0
|
813 |
#endif /* KSSL_DEBUG */
|
sl@0
|
814 |
|
sl@0
|
815 |
authp = NULL;
|
sl@0
|
816 |
#ifdef KRB5SENDAUTH
|
sl@0
|
817 |
if (KRB5SENDAUTH) authp = &authenticator;
|
sl@0
|
818 |
#endif /* KRB5SENDAUTH */
|
sl@0
|
819 |
|
sl@0
|
820 |
krb5rc = kssl_cget_tkt(kssl_ctx, &enc_ticket, authp,
|
sl@0
|
821 |
&kssl_err);
|
sl@0
|
822 |
enc = kssl_map_enc(kssl_ctx->enctype);
|
sl@0
|
823 |
if (enc == NULL)
|
sl@0
|
824 |
goto err;
|
sl@0
|
825 |
#ifdef KSSL_DEBUG
|
sl@0
|
826 |
{
|
sl@0
|
827 |
printf("kssl_cget_tkt rtn %d\n", krb5rc);
|
sl@0
|
828 |
if (krb5rc && kssl_err.text)
|
sl@0
|
829 |
printf("kssl_cget_tkt kssl_err=%s\n", kssl_err.text);
|
sl@0
|
830 |
}
|
sl@0
|
831 |
#endif /* KSSL_DEBUG */
|
sl@0
|
832 |
|
sl@0
|
833 |
if (krb5rc)
|
sl@0
|
834 |
{
|
sl@0
|
835 |
ssl3_send_alert(s,SSL3_AL_FATAL,
|
sl@0
|
836 |
SSL_AD_HANDSHAKE_FAILURE);
|
sl@0
|
837 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,
|
sl@0
|
838 |
kssl_err.reason);
|
sl@0
|
839 |
goto err;
|
sl@0
|
840 |
}
|
sl@0
|
841 |
|
sl@0
|
842 |
/* 20010406 VRS - Earlier versions used KRB5 AP_REQ
|
sl@0
|
843 |
** in place of RFC 2712 KerberosWrapper, as in:
|
sl@0
|
844 |
**
|
sl@0
|
845 |
** Send ticket (copy to *p, set n = length)
|
sl@0
|
846 |
** n = krb5_ap_req.length;
|
sl@0
|
847 |
** memcpy(p, krb5_ap_req.data, krb5_ap_req.length);
|
sl@0
|
848 |
** if (krb5_ap_req.data)
|
sl@0
|
849 |
** kssl_krb5_free_data_contents(NULL,&krb5_ap_req);
|
sl@0
|
850 |
**
|
sl@0
|
851 |
** Now using real RFC 2712 KerberosWrapper
|
sl@0
|
852 |
** (Thanks to Simon Wilkinson <sxw@sxw.org.uk>)
|
sl@0
|
853 |
** Note: 2712 "opaque" types are here replaced
|
sl@0
|
854 |
** with a 2-byte length followed by the value.
|
sl@0
|
855 |
** Example:
|
sl@0
|
856 |
** KerberosWrapper= xx xx asn1ticket 0 0 xx xx encpms
|
sl@0
|
857 |
** Where "xx xx" = length bytes. Shown here with
|
sl@0
|
858 |
** optional authenticator omitted.
|
sl@0
|
859 |
*/
|
sl@0
|
860 |
|
sl@0
|
861 |
/* KerberosWrapper.Ticket */
|
sl@0
|
862 |
s2n(enc_ticket->length,p);
|
sl@0
|
863 |
memcpy(p, enc_ticket->data, enc_ticket->length);
|
sl@0
|
864 |
p+= enc_ticket->length;
|
sl@0
|
865 |
n = enc_ticket->length + 2;
|
sl@0
|
866 |
|
sl@0
|
867 |
/* KerberosWrapper.Authenticator */
|
sl@0
|
868 |
if (authp && authp->length)
|
sl@0
|
869 |
{
|
sl@0
|
870 |
s2n(authp->length,p);
|
sl@0
|
871 |
memcpy(p, authp->data, authp->length);
|
sl@0
|
872 |
p+= authp->length;
|
sl@0
|
873 |
n+= authp->length + 2;
|
sl@0
|
874 |
|
sl@0
|
875 |
free(authp->data);
|
sl@0
|
876 |
authp->data = NULL;
|
sl@0
|
877 |
authp->length = 0;
|
sl@0
|
878 |
}
|
sl@0
|
879 |
else
|
sl@0
|
880 |
{
|
sl@0
|
881 |
s2n(0,p);/* null authenticator length */
|
sl@0
|
882 |
n+=2;
|
sl@0
|
883 |
}
|
sl@0
|
884 |
|
sl@0
|
885 |
if (RAND_bytes(tmp_buf,sizeof tmp_buf) <= 0)
|
sl@0
|
886 |
goto err;
|
sl@0
|
887 |
|
sl@0
|
888 |
/* 20010420 VRS. Tried it this way; failed.
|
sl@0
|
889 |
** EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,NULL);
|
sl@0
|
890 |
** EVP_CIPHER_CTX_set_key_length(&ciph_ctx,
|
sl@0
|
891 |
** kssl_ctx->length);
|
sl@0
|
892 |
** EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv);
|
sl@0
|
893 |
*/
|
sl@0
|
894 |
|
sl@0
|
895 |
memset(iv, 0, sizeof iv); /* per RFC 1510 */
|
sl@0
|
896 |
EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,
|
sl@0
|
897 |
kssl_ctx->key,iv);
|
sl@0
|
898 |
EVP_EncryptUpdate(&ciph_ctx,epms,&outl,tmp_buf,
|
sl@0
|
899 |
sizeof tmp_buf);
|
sl@0
|
900 |
EVP_EncryptFinal_ex(&ciph_ctx,&(epms[outl]),&padl);
|
sl@0
|
901 |
outl += padl;
|
sl@0
|
902 |
if (outl > sizeof epms)
|
sl@0
|
903 |
{
|
sl@0
|
904 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
|
sl@0
|
905 |
goto err;
|
sl@0
|
906 |
}
|
sl@0
|
907 |
EVP_CIPHER_CTX_cleanup(&ciph_ctx);
|
sl@0
|
908 |
|
sl@0
|
909 |
/* KerberosWrapper.EncryptedPreMasterSecret */
|
sl@0
|
910 |
s2n(outl,p);
|
sl@0
|
911 |
memcpy(p, epms, outl);
|
sl@0
|
912 |
p+=outl;
|
sl@0
|
913 |
n+=outl + 2;
|
sl@0
|
914 |
|
sl@0
|
915 |
s->session->master_key_length=
|
sl@0
|
916 |
s->method->ssl3_enc->generate_master_secret(s,
|
sl@0
|
917 |
s->session->master_key,
|
sl@0
|
918 |
tmp_buf, sizeof tmp_buf);
|
sl@0
|
919 |
|
sl@0
|
920 |
OPENSSL_cleanse(tmp_buf, sizeof tmp_buf);
|
sl@0
|
921 |
OPENSSL_cleanse(epms, outl);
|
sl@0
|
922 |
}
|
sl@0
|
923 |
#endif
|
sl@0
|
924 |
#ifndef OPENSSL_NO_DH
|
sl@0
|
925 |
else if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
|
sl@0
|
926 |
{
|
sl@0
|
927 |
DH *dh_srvr,*dh_clnt;
|
sl@0
|
928 |
|
sl@0
|
929 |
if (s->session->sess_cert->peer_dh_tmp != NULL)
|
sl@0
|
930 |
dh_srvr=s->session->sess_cert->peer_dh_tmp;
|
sl@0
|
931 |
else
|
sl@0
|
932 |
{
|
sl@0
|
933 |
/* we get them from the cert */
|
sl@0
|
934 |
ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
|
sl@0
|
935 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_DH_PARAMETERS);
|
sl@0
|
936 |
goto err;
|
sl@0
|
937 |
}
|
sl@0
|
938 |
|
sl@0
|
939 |
/* generate a new random key */
|
sl@0
|
940 |
if ((dh_clnt=DHparams_dup(dh_srvr)) == NULL)
|
sl@0
|
941 |
{
|
sl@0
|
942 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
|
sl@0
|
943 |
goto err;
|
sl@0
|
944 |
}
|
sl@0
|
945 |
if (!DH_generate_key(dh_clnt))
|
sl@0
|
946 |
{
|
sl@0
|
947 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
|
sl@0
|
948 |
goto err;
|
sl@0
|
949 |
}
|
sl@0
|
950 |
|
sl@0
|
951 |
/* use the 'p' output buffer for the DH key, but
|
sl@0
|
952 |
* make sure to clear it out afterwards */
|
sl@0
|
953 |
|
sl@0
|
954 |
n=DH_compute_key(p,dh_srvr->pub_key,dh_clnt);
|
sl@0
|
955 |
|
sl@0
|
956 |
if (n <= 0)
|
sl@0
|
957 |
{
|
sl@0
|
958 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
|
sl@0
|
959 |
goto err;
|
sl@0
|
960 |
}
|
sl@0
|
961 |
|
sl@0
|
962 |
/* generate master key from the result */
|
sl@0
|
963 |
s->session->master_key_length=
|
sl@0
|
964 |
s->method->ssl3_enc->generate_master_secret(s,
|
sl@0
|
965 |
s->session->master_key,p,n);
|
sl@0
|
966 |
/* clean up */
|
sl@0
|
967 |
memset(p,0,n);
|
sl@0
|
968 |
|
sl@0
|
969 |
/* send off the data */
|
sl@0
|
970 |
n=BN_num_bytes(dh_clnt->pub_key);
|
sl@0
|
971 |
s2n(n,p);
|
sl@0
|
972 |
BN_bn2bin(dh_clnt->pub_key,p);
|
sl@0
|
973 |
n+=2;
|
sl@0
|
974 |
|
sl@0
|
975 |
DH_free(dh_clnt);
|
sl@0
|
976 |
|
sl@0
|
977 |
/* perhaps clean things up a bit EAY EAY EAY EAY*/
|
sl@0
|
978 |
}
|
sl@0
|
979 |
#endif
|
sl@0
|
980 |
else
|
sl@0
|
981 |
{
|
sl@0
|
982 |
ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
|
sl@0
|
983 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR);
|
sl@0
|
984 |
goto err;
|
sl@0
|
985 |
}
|
sl@0
|
986 |
|
sl@0
|
987 |
d = dtls1_set_message_header(s, d,
|
sl@0
|
988 |
SSL3_MT_CLIENT_KEY_EXCHANGE, n, 0, n);
|
sl@0
|
989 |
/*
|
sl@0
|
990 |
*(d++)=SSL3_MT_CLIENT_KEY_EXCHANGE;
|
sl@0
|
991 |
l2n3(n,d);
|
sl@0
|
992 |
l2n(s->d1->handshake_write_seq,d);
|
sl@0
|
993 |
s->d1->handshake_write_seq++;
|
sl@0
|
994 |
*/
|
sl@0
|
995 |
|
sl@0
|
996 |
s->state=SSL3_ST_CW_KEY_EXCH_B;
|
sl@0
|
997 |
/* number of bytes to write */
|
sl@0
|
998 |
s->init_num=n+DTLS1_HM_HEADER_LENGTH;
|
sl@0
|
999 |
s->init_off=0;
|
sl@0
|
1000 |
|
sl@0
|
1001 |
/* buffer the message to handle re-xmits */
|
sl@0
|
1002 |
dtls1_buffer_message(s, 0);
|
sl@0
|
1003 |
}
|
sl@0
|
1004 |
|
sl@0
|
1005 |
/* SSL3_ST_CW_KEY_EXCH_B */
|
sl@0
|
1006 |
return(dtls1_do_write(s,SSL3_RT_HANDSHAKE));
|
sl@0
|
1007 |
err:
|
sl@0
|
1008 |
return(-1);
|
sl@0
|
1009 |
}
|
sl@0
|
1010 |
|
sl@0
|
1011 |
int dtls1_send_client_verify(SSL *s)
|
sl@0
|
1012 |
{
|
sl@0
|
1013 |
unsigned char *p,*d;
|
sl@0
|
1014 |
unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
|
sl@0
|
1015 |
EVP_PKEY *pkey;
|
sl@0
|
1016 |
#ifndef OPENSSL_NO_RSA
|
sl@0
|
1017 |
unsigned u=0;
|
sl@0
|
1018 |
#endif
|
sl@0
|
1019 |
unsigned long n;
|
sl@0
|
1020 |
#ifndef OPENSSL_NO_DSA
|
sl@0
|
1021 |
int j;
|
sl@0
|
1022 |
#endif
|
sl@0
|
1023 |
|
sl@0
|
1024 |
if (s->state == SSL3_ST_CW_CERT_VRFY_A)
|
sl@0
|
1025 |
{
|
sl@0
|
1026 |
d=(unsigned char *)s->init_buf->data;
|
sl@0
|
1027 |
p= &(d[DTLS1_HM_HEADER_LENGTH]);
|
sl@0
|
1028 |
pkey=s->cert->key->privatekey;
|
sl@0
|
1029 |
|
sl@0
|
1030 |
s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2),
|
sl@0
|
1031 |
&(data[MD5_DIGEST_LENGTH]));
|
sl@0
|
1032 |
|
sl@0
|
1033 |
#ifndef OPENSSL_NO_RSA
|
sl@0
|
1034 |
if (pkey->type == EVP_PKEY_RSA)
|
sl@0
|
1035 |
{
|
sl@0
|
1036 |
s->method->ssl3_enc->cert_verify_mac(s,
|
sl@0
|
1037 |
&(s->s3->finish_dgst1),&(data[0]));
|
sl@0
|
1038 |
if (RSA_sign(NID_md5_sha1, data,
|
sl@0
|
1039 |
MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
|
sl@0
|
1040 |
&(p[2]), &u, pkey->pkey.rsa) <= 0 )
|
sl@0
|
1041 |
{
|
sl@0
|
1042 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_VERIFY,ERR_R_RSA_LIB);
|
sl@0
|
1043 |
goto err;
|
sl@0
|
1044 |
}
|
sl@0
|
1045 |
s2n(u,p);
|
sl@0
|
1046 |
n=u+2;
|
sl@0
|
1047 |
}
|
sl@0
|
1048 |
else
|
sl@0
|
1049 |
#endif
|
sl@0
|
1050 |
#ifndef OPENSSL_NO_DSA
|
sl@0
|
1051 |
if (pkey->type == EVP_PKEY_DSA)
|
sl@0
|
1052 |
{
|
sl@0
|
1053 |
if (!DSA_sign(pkey->save_type,
|
sl@0
|
1054 |
&(data[MD5_DIGEST_LENGTH]),
|
sl@0
|
1055 |
SHA_DIGEST_LENGTH,&(p[2]),
|
sl@0
|
1056 |
(unsigned int *)&j,pkey->pkey.dsa))
|
sl@0
|
1057 |
{
|
sl@0
|
1058 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_VERIFY,ERR_R_DSA_LIB);
|
sl@0
|
1059 |
goto err;
|
sl@0
|
1060 |
}
|
sl@0
|
1061 |
s2n(j,p);
|
sl@0
|
1062 |
n=j+2;
|
sl@0
|
1063 |
}
|
sl@0
|
1064 |
else
|
sl@0
|
1065 |
#endif
|
sl@0
|
1066 |
{
|
sl@0
|
1067 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_VERIFY,ERR_R_INTERNAL_ERROR);
|
sl@0
|
1068 |
goto err;
|
sl@0
|
1069 |
}
|
sl@0
|
1070 |
|
sl@0
|
1071 |
d = dtls1_set_message_header(s, d,
|
sl@0
|
1072 |
SSL3_MT_CERTIFICATE_VERIFY, n, 0, n) ;
|
sl@0
|
1073 |
|
sl@0
|
1074 |
s->init_num=(int)n+DTLS1_HM_HEADER_LENGTH;
|
sl@0
|
1075 |
s->init_off=0;
|
sl@0
|
1076 |
|
sl@0
|
1077 |
/* buffer the message to handle re-xmits */
|
sl@0
|
1078 |
dtls1_buffer_message(s, 0);
|
sl@0
|
1079 |
|
sl@0
|
1080 |
s->state = SSL3_ST_CW_CERT_VRFY_B;
|
sl@0
|
1081 |
}
|
sl@0
|
1082 |
|
sl@0
|
1083 |
/* s->state = SSL3_ST_CW_CERT_VRFY_B */
|
sl@0
|
1084 |
return(dtls1_do_write(s,SSL3_RT_HANDSHAKE));
|
sl@0
|
1085 |
err:
|
sl@0
|
1086 |
return(-1);
|
sl@0
|
1087 |
}
|
sl@0
|
1088 |
|
sl@0
|
1089 |
int dtls1_send_client_certificate(SSL *s)
|
sl@0
|
1090 |
{
|
sl@0
|
1091 |
X509 *x509=NULL;
|
sl@0
|
1092 |
EVP_PKEY *pkey=NULL;
|
sl@0
|
1093 |
int i;
|
sl@0
|
1094 |
unsigned long l;
|
sl@0
|
1095 |
|
sl@0
|
1096 |
if (s->state == SSL3_ST_CW_CERT_A)
|
sl@0
|
1097 |
{
|
sl@0
|
1098 |
if ((s->cert == NULL) ||
|
sl@0
|
1099 |
(s->cert->key->x509 == NULL) ||
|
sl@0
|
1100 |
(s->cert->key->privatekey == NULL))
|
sl@0
|
1101 |
s->state=SSL3_ST_CW_CERT_B;
|
sl@0
|
1102 |
else
|
sl@0
|
1103 |
s->state=SSL3_ST_CW_CERT_C;
|
sl@0
|
1104 |
}
|
sl@0
|
1105 |
|
sl@0
|
1106 |
/* We need to get a client cert */
|
sl@0
|
1107 |
if (s->state == SSL3_ST_CW_CERT_B)
|
sl@0
|
1108 |
{
|
sl@0
|
1109 |
/* If we get an error, we need to
|
sl@0
|
1110 |
* ssl->rwstate=SSL_X509_LOOKUP; return(-1);
|
sl@0
|
1111 |
* We then get retied later */
|
sl@0
|
1112 |
i=0;
|
sl@0
|
1113 |
if (s->ctx->client_cert_cb != NULL)
|
sl@0
|
1114 |
i=s->ctx->client_cert_cb(s,&(x509),&(pkey));
|
sl@0
|
1115 |
if (i < 0)
|
sl@0
|
1116 |
{
|
sl@0
|
1117 |
s->rwstate=SSL_X509_LOOKUP;
|
sl@0
|
1118 |
return(-1);
|
sl@0
|
1119 |
}
|
sl@0
|
1120 |
s->rwstate=SSL_NOTHING;
|
sl@0
|
1121 |
if ((i == 1) && (pkey != NULL) && (x509 != NULL))
|
sl@0
|
1122 |
{
|
sl@0
|
1123 |
s->state=SSL3_ST_CW_CERT_B;
|
sl@0
|
1124 |
if ( !SSL_use_certificate(s,x509) ||
|
sl@0
|
1125 |
!SSL_use_PrivateKey(s,pkey))
|
sl@0
|
1126 |
i=0;
|
sl@0
|
1127 |
}
|
sl@0
|
1128 |
else if (i == 1)
|
sl@0
|
1129 |
{
|
sl@0
|
1130 |
i=0;
|
sl@0
|
1131 |
SSLerr(SSL_F_DTLS1_SEND_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);
|
sl@0
|
1132 |
}
|
sl@0
|
1133 |
|
sl@0
|
1134 |
if (x509 != NULL) X509_free(x509);
|
sl@0
|
1135 |
if (pkey != NULL) EVP_PKEY_free(pkey);
|
sl@0
|
1136 |
if (i == 0)
|
sl@0
|
1137 |
{
|
sl@0
|
1138 |
if (s->version == SSL3_VERSION)
|
sl@0
|
1139 |
{
|
sl@0
|
1140 |
s->s3->tmp.cert_req=0;
|
sl@0
|
1141 |
ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_NO_CERTIFICATE);
|
sl@0
|
1142 |
return(1);
|
sl@0
|
1143 |
}
|
sl@0
|
1144 |
else
|
sl@0
|
1145 |
{
|
sl@0
|
1146 |
s->s3->tmp.cert_req=2;
|
sl@0
|
1147 |
}
|
sl@0
|
1148 |
}
|
sl@0
|
1149 |
|
sl@0
|
1150 |
/* Ok, we have a cert */
|
sl@0
|
1151 |
s->state=SSL3_ST_CW_CERT_C;
|
sl@0
|
1152 |
}
|
sl@0
|
1153 |
|
sl@0
|
1154 |
if (s->state == SSL3_ST_CW_CERT_C)
|
sl@0
|
1155 |
{
|
sl@0
|
1156 |
s->state=SSL3_ST_CW_CERT_D;
|
sl@0
|
1157 |
l=dtls1_output_cert_chain(s,
|
sl@0
|
1158 |
(s->s3->tmp.cert_req == 2)?NULL:s->cert->key->x509);
|
sl@0
|
1159 |
s->init_num=(int)l;
|
sl@0
|
1160 |
s->init_off=0;
|
sl@0
|
1161 |
|
sl@0
|
1162 |
/* set header called by dtls1_output_cert_chain() */
|
sl@0
|
1163 |
|
sl@0
|
1164 |
/* buffer the message to handle re-xmits */
|
sl@0
|
1165 |
dtls1_buffer_message(s, 0);
|
sl@0
|
1166 |
}
|
sl@0
|
1167 |
/* SSL3_ST_CW_CERT_D */
|
sl@0
|
1168 |
return(dtls1_do_write(s,SSL3_RT_HANDSHAKE));
|
sl@0
|
1169 |
}
|
sl@0
|
1170 |
|
sl@0
|
1171 |
|