s23_clnt.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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. #include <stdio.h>
  59. #include "ssl_locl.h"
  60. #include <openssl/buffer.h>
  61. #include <openssl/rand.h>
  62. #include <openssl/objects.h>
  63. #include <openssl/evp.h>
  64. static SSL_METHOD *ssl23_get_client_method(int ver);
  65. static int ssl23_client_hello(SSL *s);
  66. static int ssl23_get_server_hello(SSL *s);
  67. static SSL_METHOD *ssl23_get_client_method(int ver)
  68. {
  69. #ifndef OPENSSL_NO_SSL2
  70. if (ver == SSL2_VERSION)
  71. return (SSLv2_client_method());
  72. #endif
  73. #ifndef OPENSSL_NO_SSL3
  74. if (ver == SSL3_VERSION)
  75. return (SSLv3_client_method());
  76. #endif
  77. if (ver == TLS1_VERSION)
  78. return (TLSv1_client_method());
  79. else
  80. return (NULL);
  81. }
  82. IMPLEMENT_ssl23_meth_func(SSLv23_client_method,
  83. ssl_undefined_function,
  84. ssl23_connect, ssl23_get_client_method)
  85. int ssl23_connect(SSL *s)
  86. {
  87. BUF_MEM *buf = NULL;
  88. unsigned long Time = (unsigned long)time(NULL);
  89. void (*cb) (const SSL *ssl, int type, int val) = NULL;
  90. int ret = -1;
  91. int new_state, state;
  92. RAND_add(&Time, sizeof(Time), 0);
  93. ERR_clear_error();
  94. clear_sys_error();
  95. if (s->info_callback != NULL)
  96. cb = s->info_callback;
  97. else if (s->ctx->info_callback != NULL)
  98. cb = s->ctx->info_callback;
  99. s->in_handshake++;
  100. if (!SSL_in_init(s) || SSL_in_before(s))
  101. SSL_clear(s);
  102. for (;;) {
  103. state = s->state;
  104. switch (s->state) {
  105. case SSL_ST_BEFORE:
  106. case SSL_ST_CONNECT:
  107. case SSL_ST_BEFORE | SSL_ST_CONNECT:
  108. case SSL_ST_OK | SSL_ST_CONNECT:
  109. if (s->session != NULL) {
  110. SSLerr(SSL_F_SSL23_CONNECT,
  111. SSL_R_SSL23_DOING_SESSION_ID_REUSE);
  112. ret = -1;
  113. goto end;
  114. }
  115. s->server = 0;
  116. if (cb != NULL)
  117. cb(s, SSL_CB_HANDSHAKE_START, 1);
  118. /* s->version=TLS1_VERSION; */
  119. s->type = SSL_ST_CONNECT;
  120. if (s->init_buf == NULL) {
  121. if ((buf = BUF_MEM_new()) == NULL) {
  122. ret = -1;
  123. goto end;
  124. }
  125. if (!BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {
  126. ret = -1;
  127. goto end;
  128. }
  129. s->init_buf = buf;
  130. buf = NULL;
  131. }
  132. if (!ssl3_setup_buffers(s)) {
  133. ret = -1;
  134. goto end;
  135. }
  136. ssl3_init_finished_mac(s);
  137. s->state = SSL23_ST_CW_CLNT_HELLO_A;
  138. s->ctx->stats.sess_connect++;
  139. s->init_num = 0;
  140. break;
  141. case SSL23_ST_CW_CLNT_HELLO_A:
  142. case SSL23_ST_CW_CLNT_HELLO_B:
  143. s->shutdown = 0;
  144. ret = ssl23_client_hello(s);
  145. if (ret <= 0)
  146. goto end;
  147. s->state = SSL23_ST_CR_SRVR_HELLO_A;
  148. s->init_num = 0;
  149. break;
  150. case SSL23_ST_CR_SRVR_HELLO_A:
  151. case SSL23_ST_CR_SRVR_HELLO_B:
  152. ret = ssl23_get_server_hello(s);
  153. if (ret >= 0)
  154. cb = NULL;
  155. goto end;
  156. /* break; */
  157. default:
  158. SSLerr(SSL_F_SSL23_CONNECT, SSL_R_UNKNOWN_STATE);
  159. ret = -1;
  160. goto end;
  161. /* break; */
  162. }
  163. if (s->debug) {
  164. (void)BIO_flush(s->wbio);
  165. }
  166. if ((cb != NULL) && (s->state != state)) {
  167. new_state = s->state;
  168. s->state = state;
  169. cb(s, SSL_CB_CONNECT_LOOP, 1);
  170. s->state = new_state;
  171. }
  172. }
  173. end:
  174. s->in_handshake--;
  175. if (buf != NULL)
  176. BUF_MEM_free(buf);
  177. if (cb != NULL)
  178. cb(s, SSL_CB_CONNECT_EXIT, ret);
  179. return (ret);
  180. }
  181. static int ssl23_client_hello(SSL *s)
  182. {
  183. unsigned char *buf;
  184. unsigned char *p, *d;
  185. int i, ch_len;
  186. unsigned long Time, l;
  187. int ssl2_compat;
  188. int version = 0, version_major, version_minor;
  189. #ifndef OPENSSL_NO_COMP
  190. int j;
  191. SSL_COMP *comp;
  192. #endif
  193. int ret;
  194. ssl2_compat = (s->options & SSL_OP_NO_SSLv2) ? 0 : 1;
  195. if (!(s->options & SSL_OP_NO_TLSv1)) {
  196. version = TLS1_VERSION;
  197. } else if (!(s->options & SSL_OP_NO_SSLv3)) {
  198. version = SSL3_VERSION;
  199. } else if (!(s->options & SSL_OP_NO_SSLv2)) {
  200. version = SSL2_VERSION;
  201. }
  202. #ifndef OPENSSL_NO_TLSEXT
  203. if (version != SSL2_VERSION) {
  204. /*
  205. * have to disable SSL 2.0 compatibility if we need TLS extensions
  206. */
  207. if (s->tlsext_hostname != NULL)
  208. ssl2_compat = 0;
  209. if (s->tlsext_status_type != -1)
  210. ssl2_compat = 0;
  211. }
  212. #endif
  213. buf = (unsigned char *)s->init_buf->data;
  214. if (s->state == SSL23_ST_CW_CLNT_HELLO_A) {
  215. #if 0
  216. /* don't reuse session-id's */
  217. if (!ssl_get_new_session(s, 0)) {
  218. return (-1);
  219. }
  220. #endif
  221. p = s->s3->client_random;
  222. Time = (unsigned long)time(NULL); /* Time */
  223. l2n(Time, p);
  224. if (RAND_pseudo_bytes(p, SSL3_RANDOM_SIZE - 4) <= 0)
  225. return -1;
  226. if (version == TLS1_VERSION) {
  227. version_major = TLS1_VERSION_MAJOR;
  228. version_minor = TLS1_VERSION_MINOR;
  229. }
  230. #ifdef OPENSSL_FIPS
  231. else if (FIPS_mode()) {
  232. SSLerr(SSL_F_SSL23_CLIENT_HELLO,
  233. SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
  234. return -1;
  235. }
  236. #endif
  237. else if (version == SSL3_VERSION) {
  238. version_major = SSL3_VERSION_MAJOR;
  239. version_minor = SSL3_VERSION_MINOR;
  240. } else if (version == SSL2_VERSION) {
  241. version_major = SSL2_VERSION_MAJOR;
  242. version_minor = SSL2_VERSION_MINOR;
  243. } else {
  244. SSLerr(SSL_F_SSL23_CLIENT_HELLO, SSL_R_NO_PROTOCOLS_AVAILABLE);
  245. return (-1);
  246. }
  247. s->client_version = version;
  248. if (ssl2_compat) {
  249. /* create SSL 2.0 compatible Client Hello */
  250. /* two byte record header will be written last */
  251. d = &(buf[2]);
  252. p = d + 9; /* leave space for message type, version,
  253. * individual length fields */
  254. *(d++) = SSL2_MT_CLIENT_HELLO;
  255. *(d++) = version_major;
  256. *(d++) = version_minor;
  257. /* Ciphers supported */
  258. i = ssl_cipher_list_to_bytes(s, SSL_get_ciphers(s), p, 0);
  259. if (i == 0) {
  260. /* no ciphers */
  261. SSLerr(SSL_F_SSL23_CLIENT_HELLO, SSL_R_NO_CIPHERS_AVAILABLE);
  262. return -1;
  263. }
  264. s2n(i, d);
  265. p += i;
  266. /*
  267. * put in the session-id length (zero since there is no reuse)
  268. */
  269. #if 0
  270. s->session->session_id_length = 0;
  271. #endif
  272. s2n(0, d);
  273. if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG)
  274. ch_len = SSL2_CHALLENGE_LENGTH;
  275. else
  276. ch_len = SSL2_MAX_CHALLENGE_LENGTH;
  277. /* write out sslv2 challenge */
  278. if (SSL3_RANDOM_SIZE < ch_len)
  279. i = SSL3_RANDOM_SIZE;
  280. else
  281. i = ch_len;
  282. s2n(i, d);
  283. memset(&(s->s3->client_random[0]), 0, SSL3_RANDOM_SIZE);
  284. if (RAND_pseudo_bytes
  285. (&(s->s3->client_random[SSL3_RANDOM_SIZE - i]), i) <= 0)
  286. return -1;
  287. memcpy(p, &(s->s3->client_random[SSL3_RANDOM_SIZE - i]), i);
  288. p += i;
  289. i = p - &(buf[2]);
  290. buf[0] = ((i >> 8) & 0xff) | 0x80;
  291. buf[1] = (i & 0xff);
  292. /* number of bytes to write */
  293. s->init_num = i + 2;
  294. s->init_off = 0;
  295. ssl3_finish_mac(s, &(buf[2]), i);
  296. } else {
  297. /* create Client Hello in SSL 3.0/TLS 1.0 format */
  298. /*
  299. * do the record header (5 bytes) and handshake message header (4
  300. * bytes) last
  301. */
  302. d = p = &(buf[9]);
  303. *(p++) = version_major;
  304. *(p++) = version_minor;
  305. /* Random stuff */
  306. memcpy(p, s->s3->client_random, SSL3_RANDOM_SIZE);
  307. p += SSL3_RANDOM_SIZE;
  308. /* Session ID (zero since there is no reuse) */
  309. *(p++) = 0;
  310. /* Ciphers supported (using SSL 3.0/TLS 1.0 format) */
  311. i = ssl_cipher_list_to_bytes(s, SSL_get_ciphers(s), &(p[2]),
  312. ssl3_put_cipher_by_char);
  313. if (i == 0) {
  314. SSLerr(SSL_F_SSL23_CLIENT_HELLO, SSL_R_NO_CIPHERS_AVAILABLE);
  315. return -1;
  316. }
  317. s2n(i, p);
  318. p += i;
  319. #ifdef OPENSSL_NO_COMP
  320. *(p++) = 1;
  321. #else
  322. /* COMPRESSION */
  323. if (s->ctx->comp_methods == NULL)
  324. j = 0;
  325. else
  326. j = sk_SSL_COMP_num(s->ctx->comp_methods);
  327. *(p++) = 1 + j;
  328. for (i = 0; i < j; i++) {
  329. comp = sk_SSL_COMP_value(s->ctx->comp_methods, i);
  330. *(p++) = comp->id;
  331. }
  332. #endif
  333. *(p++) = 0; /* Add the NULL method */
  334. #ifndef OPENSSL_NO_TLSEXT
  335. if ((p =
  336. ssl_add_clienthello_tlsext(s, p,
  337. buf +
  338. SSL3_RT_MAX_PLAIN_LENGTH)) ==
  339. NULL) {
  340. SSLerr(SSL_F_SSL23_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
  341. return -1;
  342. }
  343. #endif
  344. l = p - d;
  345. *p = 42;
  346. /* fill in 4-byte handshake header */
  347. d = &(buf[5]);
  348. *(d++) = SSL3_MT_CLIENT_HELLO;
  349. l2n3(l, d);
  350. l += 4;
  351. if (l > SSL3_RT_MAX_PLAIN_LENGTH) {
  352. SSLerr(SSL_F_SSL23_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
  353. return -1;
  354. }
  355. /* fill in 5-byte record header */
  356. d = buf;
  357. *(d++) = SSL3_RT_HANDSHAKE;
  358. *(d++) = version_major;
  359. *(d++) = version_minor; /* arguably we should send the *lowest*
  360. * suported version here (indicating,
  361. * e.g., TLS 1.0 in "SSL 3.0 format") */
  362. s2n((int)l, d);
  363. /* number of bytes to write */
  364. s->init_num = p - buf;
  365. s->init_off = 0;
  366. ssl3_finish_mac(s, &(buf[5]), s->init_num - 5);
  367. }
  368. s->state = SSL23_ST_CW_CLNT_HELLO_B;
  369. s->init_off = 0;
  370. }
  371. /* SSL3_ST_CW_CLNT_HELLO_B */
  372. ret = ssl23_write_bytes(s);
  373. if ((ret >= 2) && s->msg_callback) {
  374. /* Client Hello has been sent; tell msg_callback */
  375. if (ssl2_compat)
  376. s->msg_callback(1, SSL2_VERSION, 0, s->init_buf->data + 2,
  377. ret - 2, s, s->msg_callback_arg);
  378. else
  379. s->msg_callback(1, version, SSL3_RT_HANDSHAKE,
  380. s->init_buf->data + 5, ret - 5, s,
  381. s->msg_callback_arg);
  382. }
  383. return ret;
  384. }
  385. static int ssl23_get_server_hello(SSL *s)
  386. {
  387. char buf[8];
  388. unsigned char *p;
  389. int i;
  390. int n;
  391. n = ssl23_read_bytes(s, 7);
  392. if (n != 7)
  393. return (n);
  394. p = s->packet;
  395. memcpy(buf, p, n);
  396. if ((p[0] & 0x80) && (p[2] == SSL2_MT_SERVER_HELLO) &&
  397. (p[5] == 0x00) && (p[6] == 0x02)) {
  398. #ifdef OPENSSL_NO_SSL2
  399. SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, SSL_R_UNSUPPORTED_PROTOCOL);
  400. goto err;
  401. #else
  402. /* we are talking sslv2 */
  403. /*
  404. * we need to clean up the SSLv3 setup and put in the sslv2 stuff.
  405. */
  406. int ch_len;
  407. if (s->options & SSL_OP_NO_SSLv2) {
  408. SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, SSL_R_UNSUPPORTED_PROTOCOL);
  409. goto err;
  410. }
  411. if (s->s2 == NULL) {
  412. if (!ssl2_new(s))
  413. goto err;
  414. } else
  415. ssl2_clear(s);
  416. if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG)
  417. ch_len = SSL2_CHALLENGE_LENGTH;
  418. else
  419. ch_len = SSL2_MAX_CHALLENGE_LENGTH;
  420. /* write out sslv2 challenge */
  421. i = (SSL3_RANDOM_SIZE < ch_len)
  422. ? SSL3_RANDOM_SIZE : ch_len;
  423. s->s2->challenge_length = i;
  424. memcpy(s->s2->challenge,
  425. &(s->s3->client_random[SSL3_RANDOM_SIZE - i]), i);
  426. if (s->s3 != NULL)
  427. ssl3_free(s);
  428. if (!BUF_MEM_grow_clean(s->init_buf,
  429. SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) {
  430. SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, ERR_R_BUF_LIB);
  431. goto err;
  432. }
  433. s->state = SSL2_ST_GET_SERVER_HELLO_A;
  434. if (!(s->client_version == SSL2_VERSION))
  435. /*
  436. * use special padding (SSL 3.0 draft/RFC 2246, App. E.2)
  437. */
  438. s->s2->ssl2_rollback = 1;
  439. /*
  440. * setup the 7 bytes we have read so we get them from the sslv2
  441. * buffer
  442. */
  443. s->rstate = SSL_ST_READ_HEADER;
  444. s->packet_length = n;
  445. s->packet = &(s->s2->rbuf[0]);
  446. memcpy(s->packet, buf, n);
  447. s->s2->rbuf_left = n;
  448. s->s2->rbuf_offs = 0;
  449. /* we have already written one */
  450. s->s2->write_sequence = 1;
  451. s->method = SSLv2_client_method();
  452. s->handshake_func = s->method->ssl_connect;
  453. #endif
  454. } else if (p[1] == SSL3_VERSION_MAJOR &&
  455. ((p[2] == SSL3_VERSION_MINOR) ||
  456. (p[2] == TLS1_VERSION_MINOR)) &&
  457. ((p[0] == SSL3_RT_HANDSHAKE && p[5] == SSL3_MT_SERVER_HELLO) ||
  458. (p[0] == SSL3_RT_ALERT && p[3] == 0 && p[4] == 2))) {
  459. /* we have sslv3 or tls1 (server hello or alert) */
  460. #ifndef OPENSSL_NO_SSL3
  461. if ((p[2] == SSL3_VERSION_MINOR) && !(s->options & SSL_OP_NO_SSLv3)) {
  462. # ifdef OPENSSL_FIPS
  463. if (FIPS_mode()) {
  464. SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,
  465. SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
  466. goto err;
  467. }
  468. # endif
  469. s->version = SSL3_VERSION;
  470. s->method = SSLv3_client_method();
  471. } else
  472. #endif
  473. if ((p[2] == TLS1_VERSION_MINOR) && !(s->options & SSL_OP_NO_TLSv1)) {
  474. s->version = TLS1_VERSION;
  475. s->method = TLSv1_client_method();
  476. } else {
  477. SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, SSL_R_UNSUPPORTED_PROTOCOL);
  478. goto err;
  479. }
  480. /* ensure that TLS_MAX_VERSION is up-to-date */
  481. OPENSSL_assert(s->version <= TLS_MAX_VERSION);
  482. if (p[0] == SSL3_RT_ALERT && p[5] != SSL3_AL_WARNING) {
  483. /* fatal alert */
  484. void (*cb) (const SSL *ssl, int type, int val) = NULL;
  485. int j;
  486. if (s->info_callback != NULL)
  487. cb = s->info_callback;
  488. else if (s->ctx->info_callback != NULL)
  489. cb = s->ctx->info_callback;
  490. i = p[5];
  491. if (cb != NULL) {
  492. j = (i << 8) | p[6];
  493. cb(s, SSL_CB_READ_ALERT, j);
  494. }
  495. if (s->msg_callback)
  496. s->msg_callback(0, s->version, SSL3_RT_ALERT, p + 5, 2, s,
  497. s->msg_callback_arg);
  498. s->rwstate = SSL_NOTHING;
  499. SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, SSL_AD_REASON_OFFSET + p[6]);
  500. goto err;
  501. }
  502. if (!ssl_init_wbio_buffer(s, 1))
  503. goto err;
  504. /* we are in this state */
  505. s->state = SSL3_ST_CR_SRVR_HELLO_A;
  506. /*
  507. * put the 7 bytes we have read into the input buffer for SSLv3
  508. */
  509. s->rstate = SSL_ST_READ_HEADER;
  510. s->packet_length = n;
  511. if (s->s3->rbuf.buf == NULL)
  512. if (!ssl3_setup_buffers(s))
  513. goto err;
  514. s->packet = &(s->s3->rbuf.buf[0]);
  515. memcpy(s->packet, buf, n);
  516. s->s3->rbuf.left = n;
  517. s->s3->rbuf.offset = 0;
  518. s->handshake_func = s->method->ssl_connect;
  519. } else {
  520. SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, SSL_R_UNKNOWN_PROTOCOL);
  521. goto err;
  522. }
  523. s->init_num = 0;
  524. /*
  525. * Since, if we are sending a ssl23 client hello, we are not reusing a
  526. * session-id
  527. */
  528. if (!ssl_get_new_session(s, 0))
  529. goto err;
  530. return (SSL_connect(s));
  531. err:
  532. return (-1);
  533. }