]> git.ipfire.org Git - thirdparty/openssl.git/blob - ssl/s23_clnt.c
Run util/openssl-format-source -v -c .
[thirdparty/openssl.git] / ssl / s23_clnt.c
1 /* ssl/s23_clnt.c */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58 /* ====================================================================
59 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112 #include <stdio.h>
113 #include "ssl_locl.h"
114 #include <openssl/buffer.h>
115 #include <openssl/rand.h>
116 #include <openssl/objects.h>
117 #include <openssl/evp.h>
118
119 static const SSL_METHOD *ssl23_get_client_method(int ver);
120 static int ssl23_client_hello(SSL *s);
121 static int ssl23_get_server_hello(SSL *s);
122 static const SSL_METHOD *ssl23_get_client_method(int ver)
123 {
124 #ifndef OPENSSL_NO_SSL3
125 if (ver == SSL3_VERSION)
126 return (SSLv3_client_method());
127 #endif
128 if (ver == TLS1_VERSION)
129 return (TLSv1_client_method());
130 else if (ver == TLS1_1_VERSION)
131 return (TLSv1_1_client_method());
132 else if (ver == TLS1_2_VERSION)
133 return (TLSv1_2_client_method());
134 else
135 return (NULL);
136 }
137
138 IMPLEMENT_ssl23_meth_func(SSLv23_client_method,
139 ssl_undefined_function,
140 ssl23_connect, ssl23_get_client_method)
141
142 int ssl23_connect(SSL *s)
143 {
144 BUF_MEM *buf = NULL;
145 unsigned long Time = (unsigned long)time(NULL);
146 void (*cb) (const SSL *ssl, int type, int val) = NULL;
147 int ret = -1;
148 int new_state, state;
149
150 RAND_add(&Time, sizeof(Time), 0);
151 ERR_clear_error();
152 clear_sys_error();
153
154 if (s->info_callback != NULL)
155 cb = s->info_callback;
156 else if (s->ctx->info_callback != NULL)
157 cb = s->ctx->info_callback;
158
159 s->in_handshake++;
160 if (!SSL_in_init(s) || SSL_in_before(s))
161 SSL_clear(s);
162
163 for (;;) {
164 state = s->state;
165
166 switch (s->state) {
167 case SSL_ST_BEFORE:
168 case SSL_ST_CONNECT:
169 case SSL_ST_BEFORE | SSL_ST_CONNECT:
170 case SSL_ST_OK | SSL_ST_CONNECT:
171
172 if (s->session != NULL) {
173 SSLerr(SSL_F_SSL23_CONNECT,
174 SSL_R_SSL23_DOING_SESSION_ID_REUSE);
175 ret = -1;
176 goto end;
177 }
178 s->server = 0;
179 if (cb != NULL)
180 cb(s, SSL_CB_HANDSHAKE_START, 1);
181
182 /* s->version=TLS1_VERSION; */
183 s->type = SSL_ST_CONNECT;
184
185 if (s->init_buf == NULL) {
186 if ((buf = BUF_MEM_new()) == NULL) {
187 ret = -1;
188 goto end;
189 }
190 if (!BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {
191 ret = -1;
192 goto end;
193 }
194 s->init_buf = buf;
195 buf = NULL;
196 }
197
198 if (!ssl3_setup_buffers(s)) {
199 ret = -1;
200 goto end;
201 }
202
203 ssl3_init_finished_mac(s);
204
205 s->state = SSL23_ST_CW_CLNT_HELLO_A;
206 s->ctx->stats.sess_connect++;
207 s->init_num = 0;
208 break;
209
210 case SSL23_ST_CW_CLNT_HELLO_A:
211 case SSL23_ST_CW_CLNT_HELLO_B:
212
213 s->shutdown = 0;
214 ret = ssl23_client_hello(s);
215 if (ret <= 0)
216 goto end;
217 s->state = SSL23_ST_CR_SRVR_HELLO_A;
218 s->init_num = 0;
219
220 break;
221
222 case SSL23_ST_CR_SRVR_HELLO_A:
223 case SSL23_ST_CR_SRVR_HELLO_B:
224 ret = ssl23_get_server_hello(s);
225 if (ret >= 0)
226 cb = NULL;
227 goto end;
228 /* break; */
229
230 default:
231 SSLerr(SSL_F_SSL23_CONNECT, SSL_R_UNKNOWN_STATE);
232 ret = -1;
233 goto end;
234 /* break; */
235 }
236
237 if (s->debug) {
238 (void)BIO_flush(s->wbio);
239 }
240
241 if ((cb != NULL) && (s->state != state)) {
242 new_state = s->state;
243 s->state = state;
244 cb(s, SSL_CB_CONNECT_LOOP, 1);
245 s->state = new_state;
246 }
247 }
248 end:
249 s->in_handshake--;
250 if (buf != NULL)
251 BUF_MEM_free(buf);
252 if (cb != NULL)
253 cb(s, SSL_CB_CONNECT_EXIT, ret);
254 return (ret);
255 }
256
257 /*
258 * Fill a ClientRandom or ServerRandom field of length len. Returns <= 0 on
259 * failure, 1 on success.
260 */
261 int ssl_fill_hello_random(SSL *s, int server, unsigned char *result, int len)
262 {
263 int send_time = 0;
264 if (len < 4)
265 return 0;
266 if (server)
267 send_time = (s->mode & SSL_MODE_SEND_SERVERHELLO_TIME) != 0;
268 else
269 send_time = (s->mode & SSL_MODE_SEND_CLIENTHELLO_TIME) != 0;
270 if (send_time) {
271 unsigned long Time = (unsigned long)time(NULL);
272 unsigned char *p = result;
273 l2n(Time, p);
274 return RAND_pseudo_bytes(p, len - 4);
275 } else
276 return RAND_pseudo_bytes(result, len);
277 }
278
279 static int ssl23_client_hello(SSL *s)
280 {
281 unsigned char *buf;
282 unsigned char *p, *d;
283 int i;
284 unsigned long l;
285 int version = 0, version_major, version_minor;
286 int al = 0;
287 #ifndef OPENSSL_NO_COMP
288 int j;
289 SSL_COMP *comp;
290 #endif
291 int ret;
292 unsigned long mask, options = s->options;
293
294 /*
295 * SSL_OP_NO_X disables all protocols above X *if* there are
296 * some protocols below X enabled. This is required in order
297 * to maintain "version capability" vector contiguous. So
298 * that if application wants to disable TLS1.0 in favour of
299 * TLS1>=1, it would be insufficient to pass SSL_NO_TLSv1, the
300 * answer is SSL_OP_NO_TLSv1|SSL_OP_NO_SSLv3|SSL_OP_NO_SSLv2.
301 */
302 mask = SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1
303 #if !defined(OPENSSL_NO_SSL3)
304 | SSL_OP_NO_SSLv3
305 #endif
306 ;
307 #if !defined(OPENSSL_NO_TLS1_2_CLIENT)
308 version = TLS1_2_VERSION;
309
310 if ((options & SSL_OP_NO_TLSv1_2) && (options & mask) != mask)
311 version = TLS1_1_VERSION;
312 #else
313 version = TLS1_1_VERSION;
314 #endif
315 mask &= ~SSL_OP_NO_TLSv1_1;
316 if ((options & SSL_OP_NO_TLSv1_1) && (options & mask) != mask)
317 version = TLS1_VERSION;
318 mask &= ~SSL_OP_NO_TLSv1;
319 #if !defined(OPENSSL_NO_SSL3)
320 if ((options & SSL_OP_NO_TLSv1) && (options & mask) != mask)
321 version = SSL3_VERSION;
322 mask &= ~SSL_OP_NO_SSLv3;
323 #endif
324
325 buf = (unsigned char *)s->init_buf->data;
326 if (s->state == SSL23_ST_CW_CLNT_HELLO_A) {
327 #if 0
328 /* don't reuse session-id's */
329 if (!ssl_get_new_session(s, 0)) {
330 return (-1);
331 }
332 #endif
333
334 p = s->s3->client_random;
335 if (ssl_fill_hello_random(s, 0, p, SSL3_RANDOM_SIZE) <= 0)
336 return -1;
337
338 if (version == TLS1_2_VERSION) {
339 version_major = TLS1_2_VERSION_MAJOR;
340 version_minor = TLS1_2_VERSION_MINOR;
341 } else if (tls1_suiteb(s)) {
342 SSLerr(SSL_F_SSL23_CLIENT_HELLO,
343 SSL_R_ONLY_TLS_1_2_ALLOWED_IN_SUITEB_MODE);
344 return -1;
345 } else if (version == TLS1_1_VERSION) {
346 version_major = TLS1_1_VERSION_MAJOR;
347 version_minor = TLS1_1_VERSION_MINOR;
348 } else if (version == TLS1_VERSION) {
349 version_major = TLS1_VERSION_MAJOR;
350 version_minor = TLS1_VERSION_MINOR;
351 } else if (FIPS_mode()) {
352 SSLerr(SSL_F_SSL23_CLIENT_HELLO,
353 SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
354 return -1;
355 } else if (version == SSL3_VERSION) {
356 version_major = SSL3_VERSION_MAJOR;
357 version_minor = SSL3_VERSION_MINOR;
358 } else {
359 SSLerr(SSL_F_SSL23_CLIENT_HELLO, SSL_R_NO_PROTOCOLS_AVAILABLE);
360 return (-1);
361 }
362
363 s->client_version = version;
364
365 /* create Client Hello in SSL 3.0/TLS 1.0 format */
366
367 /*
368 * do the record header (5 bytes) and handshake message header (4
369 * bytes) last
370 */
371 d = p = &(buf[9]);
372
373 *(p++) = version_major;
374 *(p++) = version_minor;
375
376 /* Random stuff */
377 memcpy(p, s->s3->client_random, SSL3_RANDOM_SIZE);
378 p += SSL3_RANDOM_SIZE;
379
380 /* Session ID (zero since there is no reuse) */
381 *(p++) = 0;
382
383 /* Ciphers supported (using SSL 3.0/TLS 1.0 format) */
384 i = ssl_cipher_list_to_bytes(s, SSL_get_ciphers(s), &(p[2]),
385 ssl3_put_cipher_by_char);
386 if (i == 0) {
387 SSLerr(SSL_F_SSL23_CLIENT_HELLO, SSL_R_NO_CIPHERS_AVAILABLE);
388 return -1;
389 }
390 #ifdef OPENSSL_MAX_TLS1_2_CIPHER_LENGTH
391 /*
392 * Some servers hang if client hello > 256 bytes as hack workaround
393 * chop number of supported ciphers to keep it well below this if we
394 * use TLS v1.2
395 */
396 if (TLS1_get_version(s) >= TLS1_2_VERSION
397 && i > OPENSSL_MAX_TLS1_2_CIPHER_LENGTH)
398 i = OPENSSL_MAX_TLS1_2_CIPHER_LENGTH & ~1;
399 #endif
400 s2n(i, p);
401 p += i;
402
403 /* COMPRESSION */
404 #ifdef OPENSSL_NO_COMP
405 *(p++) = 1;
406 #else
407 if (!ssl_allow_compression(s) || !s->ctx->comp_methods)
408 j = 0;
409 else
410 j = sk_SSL_COMP_num(s->ctx->comp_methods);
411 *(p++) = 1 + j;
412 for (i = 0; i < j; i++) {
413 comp = sk_SSL_COMP_value(s->ctx->comp_methods, i);
414 *(p++) = comp->id;
415 }
416 #endif
417 *(p++) = 0; /* Add the NULL method */
418
419 #ifndef OPENSSL_NO_TLSEXT
420 /* TLS extensions */
421 if (ssl_prepare_clienthello_tlsext(s) <= 0) {
422 SSLerr(SSL_F_SSL23_CLIENT_HELLO, SSL_R_CLIENTHELLO_TLSEXT);
423 return -1;
424 }
425 if ((p =
426 ssl_add_clienthello_tlsext(s, p, buf + SSL3_RT_MAX_PLAIN_LENGTH,
427 &al)) == NULL) {
428 ssl3_send_alert(s, SSL3_AL_FATAL, al);
429 SSLerr(SSL_F_SSL23_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
430 return -1;
431 }
432 #endif
433
434 l = p - d;
435
436 /* fill in 4-byte handshake header */
437 d = &(buf[5]);
438 *(d++) = SSL3_MT_CLIENT_HELLO;
439 l2n3(l, d);
440
441 l += 4;
442
443 if (l > SSL3_RT_MAX_PLAIN_LENGTH) {
444 SSLerr(SSL_F_SSL23_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
445 return -1;
446 }
447
448 /* fill in 5-byte record header */
449 d = buf;
450 *(d++) = SSL3_RT_HANDSHAKE;
451 *(d++) = version_major;
452 /*
453 * Some servers hang if we use long client hellos and a record number
454 * > TLS 1.0.
455 */
456 if (TLS1_get_client_version(s) > TLS1_VERSION)
457 *(d++) = 1;
458 else
459 *(d++) = version_minor;
460 s2n((int)l, d);
461
462 /* number of bytes to write */
463 s->init_num = p - buf;
464 s->init_off = 0;
465
466 ssl3_finish_mac(s, &(buf[5]), s->init_num - 5);
467
468 s->state = SSL23_ST_CW_CLNT_HELLO_B;
469 s->init_off = 0;
470 }
471
472 /* SSL3_ST_CW_CLNT_HELLO_B */
473 ret = ssl23_write_bytes(s);
474
475 if ((ret >= 2) && s->msg_callback) {
476 /* Client Hello has been sent; tell msg_callback */
477 s->msg_callback(1, version, SSL3_RT_HEADER, s->init_buf->data, 5, s,
478 s->msg_callback_arg);
479 s->msg_callback(1, version, SSL3_RT_HANDSHAKE, s->init_buf->data + 5,
480 ret - 5, s, s->msg_callback_arg);
481 }
482
483 return ret;
484 }
485
486 static int ssl23_get_server_hello(SSL *s)
487 {
488 char buf[8];
489 unsigned char *p;
490 int i;
491 int n;
492
493 n = ssl23_read_bytes(s, 7);
494
495 if (n != 7)
496 return (n);
497 p = s->packet;
498
499 memcpy(buf, p, n);
500
501 if (p[1] == SSL3_VERSION_MAJOR &&
502 p[2] <= TLS1_2_VERSION_MINOR &&
503 ((p[0] == SSL3_RT_HANDSHAKE && p[5] == SSL3_MT_SERVER_HELLO) ||
504 (p[0] == SSL3_RT_ALERT && p[3] == 0 && p[4] == 2))) {
505 /* we have sslv3 or tls1 (server hello or alert) */
506
507 #ifndef OPENSSL_NO_SSL3
508 if ((p[2] == SSL3_VERSION_MINOR) && !(s->options & SSL_OP_NO_SSLv3)) {
509 if (FIPS_mode()) {
510 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,
511 SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
512 goto err;
513 }
514 s->version = SSL3_VERSION;
515 s->method = SSLv3_client_method();
516 } else
517 #endif
518 if ((p[2] == TLS1_VERSION_MINOR) && !(s->options & SSL_OP_NO_TLSv1)) {
519 s->version = TLS1_VERSION;
520 s->method = TLSv1_client_method();
521 } else if ((p[2] == TLS1_1_VERSION_MINOR) &&
522 !(s->options & SSL_OP_NO_TLSv1_1)) {
523 s->version = TLS1_1_VERSION;
524 s->method = TLSv1_1_client_method();
525 } else if ((p[2] == TLS1_2_VERSION_MINOR) &&
526 !(s->options & SSL_OP_NO_TLSv1_2)) {
527 s->version = TLS1_2_VERSION;
528 s->method = TLSv1_2_client_method();
529 } else {
530 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, SSL_R_UNSUPPORTED_PROTOCOL);
531 goto err;
532 }
533
534 /* ensure that TLS_MAX_VERSION is up-to-date */
535 OPENSSL_assert(s->version <= TLS_MAX_VERSION);
536
537 if (!ssl_security(s, SSL_SECOP_VERSION, 0, s->version, NULL)) {
538 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, SSL_R_VERSION_TOO_LOW);
539 goto err;
540 }
541
542 if (p[0] == SSL3_RT_ALERT && p[5] != SSL3_AL_WARNING) {
543 /* fatal alert */
544
545 void (*cb) (const SSL *ssl, int type, int val) = NULL;
546 int j;
547
548 if (s->info_callback != NULL)
549 cb = s->info_callback;
550 else if (s->ctx->info_callback != NULL)
551 cb = s->ctx->info_callback;
552
553 i = p[5];
554 if (cb != NULL) {
555 j = (i << 8) | p[6];
556 cb(s, SSL_CB_READ_ALERT, j);
557 }
558
559 if (s->msg_callback) {
560 s->msg_callback(0, s->version, SSL3_RT_HEADER, p, 5, s,
561 s->msg_callback_arg);
562 s->msg_callback(0, s->version, SSL3_RT_ALERT, p + 5, 2, s,
563 s->msg_callback_arg);
564 }
565
566 s->rwstate = SSL_NOTHING;
567 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, SSL_AD_REASON_OFFSET + p[6]);
568 goto err;
569 }
570
571 if (!ssl_init_wbio_buffer(s, 1))
572 goto err;
573
574 /* we are in this state */
575 s->state = SSL3_ST_CR_SRVR_HELLO_A;
576
577 /*
578 * put the 7 bytes we have read into the input buffer for SSLv3
579 */
580 s->rstate = SSL_ST_READ_HEADER;
581 s->packet_length = n;
582 if (s->s3->rbuf.buf == NULL)
583 if (!ssl3_setup_read_buffer(s))
584 goto err;
585 s->packet = &(s->s3->rbuf.buf[0]);
586 memcpy(s->packet, buf, n);
587 s->s3->rbuf.left = n;
588 s->s3->rbuf.offset = 0;
589
590 s->handshake_func = s->method->ssl_connect;
591 } else {
592 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, SSL_R_UNKNOWN_PROTOCOL);
593 goto err;
594 }
595 s->init_num = 0;
596
597 /*
598 * Since, if we are sending a ssl23 client hello, we are not reusing a
599 * session-id
600 */
601 if (!ssl_get_new_session(s, 0))
602 goto err;
603
604 return (SSL_connect(s));
605 err:
606 return (-1);
607 }