s3_both.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /* ssl/s3_both.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-2002 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. #include <string.h>
  112. #include <stdio.h>
  113. #include <openssl/buffer.h>
  114. #include <openssl/rand.h>
  115. #include <openssl/objects.h>
  116. #include <openssl/evp.h>
  117. #include <openssl/x509.h>
  118. #include "ssl_locl.h"
  119. /* send s->init_buf in records of type 'type' */
  120. int ssl3_do_write(SSL *s, int type)
  121. {
  122. int ret;
  123. ret=ssl3_write_bytes(s,type,&s->init_buf->data[s->init_off],
  124. s->init_num);
  125. if (ret < 0) return(-1);
  126. if (type == SSL3_RT_HANDSHAKE)
  127. /* should not be done for 'Hello Request's, but in that case
  128. * we'll ignore the result anyway */
  129. ssl3_finish_mac(s,(unsigned char *)&s->init_buf->data[s->init_off],ret);
  130. if (ret == s->init_num)
  131. return(1);
  132. s->init_off+=ret;
  133. s->init_num-=ret;
  134. return(0);
  135. }
  136. int ssl3_send_finished(SSL *s, int a, int b, const char *sender, int slen)
  137. {
  138. unsigned char *p,*d;
  139. int i;
  140. unsigned long l;
  141. if (s->state == a)
  142. {
  143. d=(unsigned char *)s->init_buf->data;
  144. p= &(d[4]);
  145. i=s->method->ssl3_enc->final_finish_mac(s,
  146. &(s->s3->finish_dgst1),
  147. &(s->s3->finish_dgst2),
  148. sender,slen,s->s3->tmp.finish_md);
  149. s->s3->tmp.finish_md_len = i;
  150. memcpy(p, s->s3->tmp.finish_md, i);
  151. p+=i;
  152. l=i;
  153. #ifdef WIN16
  154. /* MSVC 1.5 does not clear the top bytes of the word unless
  155. * I do this.
  156. */
  157. l&=0xffff;
  158. #endif
  159. *(d++)=SSL3_MT_FINISHED;
  160. l2n3(l,d);
  161. s->init_num=(int)l+4;
  162. s->init_off=0;
  163. s->state=b;
  164. }
  165. /* SSL3_ST_SEND_xxxxxx_HELLO_B */
  166. return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
  167. }
  168. int ssl3_get_finished(SSL *s, int a, int b)
  169. {
  170. int al,i,ok;
  171. long n;
  172. unsigned char *p;
  173. /* the mac has already been generated when we received the
  174. * change cipher spec message and is in s->s3->tmp.peer_finish_md
  175. */
  176. n=ssl3_get_message(s,
  177. a,
  178. b,
  179. SSL3_MT_FINISHED,
  180. 64, /* should actually be 36+4 :-) */
  181. &ok);
  182. if (!ok) return((int)n);
  183. /* If this occurs, we have missed a message */
  184. if (!s->s3->change_cipher_spec)
  185. {
  186. al=SSL_AD_UNEXPECTED_MESSAGE;
  187. SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_GOT_A_FIN_BEFORE_A_CCS);
  188. goto f_err;
  189. }
  190. s->s3->change_cipher_spec=0;
  191. p = (unsigned char *)s->init_buf->data;
  192. i = s->s3->tmp.peer_finish_md_len;
  193. if (i != n)
  194. {
  195. al=SSL_AD_DECODE_ERROR;
  196. SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_BAD_DIGEST_LENGTH);
  197. goto f_err;
  198. }
  199. if (memcmp(p, s->s3->tmp.peer_finish_md, i) != 0)
  200. {
  201. al=SSL_AD_DECRYPT_ERROR;
  202. SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_DIGEST_CHECK_FAILED);
  203. goto f_err;
  204. }
  205. return(1);
  206. f_err:
  207. ssl3_send_alert(s,SSL3_AL_FATAL,al);
  208. return(0);
  209. }
  210. /* for these 2 messages, we need to
  211. * ssl->enc_read_ctx re-init
  212. * ssl->s3->read_sequence zero
  213. * ssl->s3->read_mac_secret re-init
  214. * ssl->session->read_sym_enc assign
  215. * ssl->session->read_compression assign
  216. * ssl->session->read_hash assign
  217. */
  218. int ssl3_send_change_cipher_spec(SSL *s, int a, int b)
  219. {
  220. unsigned char *p;
  221. if (s->state == a)
  222. {
  223. p=(unsigned char *)s->init_buf->data;
  224. *p=SSL3_MT_CCS;
  225. s->init_num=1;
  226. s->init_off=0;
  227. s->state=b;
  228. }
  229. /* SSL3_ST_CW_CHANGE_B */
  230. return(ssl3_do_write(s,SSL3_RT_CHANGE_CIPHER_SPEC));
  231. }
  232. unsigned long ssl3_output_cert_chain(SSL *s, X509 *x)
  233. {
  234. unsigned char *p;
  235. int n,i;
  236. unsigned long l=7;
  237. BUF_MEM *buf;
  238. X509_STORE_CTX xs_ctx;
  239. X509_OBJECT obj;
  240. /* TLSv1 sends a chain with nothing in it, instead of an alert */
  241. buf=s->init_buf;
  242. if (!BUF_MEM_grow(buf,(int)(10)))
  243. {
  244. SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
  245. return(0);
  246. }
  247. if (x != NULL)
  248. {
  249. X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL);
  250. for (;;)
  251. {
  252. n=i2d_X509(x,NULL);
  253. if (!BUF_MEM_grow(buf,(int)(n+l+3)))
  254. {
  255. SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
  256. return(0);
  257. }
  258. p=(unsigned char *)&(buf->data[l]);
  259. l2n3(n,p);
  260. i2d_X509(x,&p);
  261. l+=n+3;
  262. if (X509_NAME_cmp(X509_get_subject_name(x),
  263. X509_get_issuer_name(x)) == 0) break;
  264. i=X509_STORE_get_by_subject(&xs_ctx,X509_LU_X509,
  265. X509_get_issuer_name(x),&obj);
  266. if (i <= 0) break;
  267. x=obj.data.x509;
  268. /* Count is one too high since the X509_STORE_get uped the
  269. * ref count */
  270. X509_free(x);
  271. }
  272. X509_STORE_CTX_cleanup(&xs_ctx);
  273. }
  274. /* Thawte special :-) */
  275. if (s->ctx->extra_certs != NULL)
  276. for (i=0; i<sk_X509_num(s->ctx->extra_certs); i++)
  277. {
  278. x=sk_X509_value(s->ctx->extra_certs,i);
  279. n=i2d_X509(x,NULL);
  280. if (!BUF_MEM_grow(buf,(int)(n+l+3)))
  281. {
  282. SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
  283. return(0);
  284. }
  285. p=(unsigned char *)&(buf->data[l]);
  286. l2n3(n,p);
  287. i2d_X509(x,&p);
  288. l+=n+3;
  289. }
  290. l-=7;
  291. p=(unsigned char *)&(buf->data[4]);
  292. l2n3(l,p);
  293. l+=3;
  294. p=(unsigned char *)&(buf->data[0]);
  295. *(p++)=SSL3_MT_CERTIFICATE;
  296. l2n3(l,p);
  297. l+=4;
  298. return(l);
  299. }
  300. /* Obtain handshake message of message type 'mt' (any if mt == -1),
  301. * maximum acceptable body length 'max'.
  302. * The first four bytes (msg_type and length) are read in state 'st1',
  303. * the body is read in state 'stn'.
  304. */
  305. long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)
  306. {
  307. unsigned char *p;
  308. unsigned long l;
  309. long n;
  310. int i,al;
  311. if (s->s3->tmp.reuse_message)
  312. {
  313. s->s3->tmp.reuse_message=0;
  314. if ((mt >= 0) && (s->s3->tmp.message_type != mt))
  315. {
  316. al=SSL_AD_UNEXPECTED_MESSAGE;
  317. SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);
  318. goto f_err;
  319. }
  320. *ok=1;
  321. return((int)s->s3->tmp.message_size);
  322. }
  323. p=(unsigned char *)s->init_buf->data;
  324. if (s->state == st1) /* s->init_num < 4 */
  325. {
  326. int skip_message;
  327. do
  328. {
  329. while (s->init_num < 4)
  330. {
  331. i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],
  332. 4 - s->init_num, 0);
  333. if (i <= 0)
  334. {
  335. s->rwstate=SSL_READING;
  336. *ok = 0;
  337. return i;
  338. }
  339. s->init_num+=i;
  340. }
  341. skip_message = 0;
  342. if (!s->server)
  343. if (p[0] == SSL3_MT_HELLO_REQUEST)
  344. /* The server may always send 'Hello Request' messages --
  345. * we are doing a handshake anyway now, so ignore them
  346. * if their format is correct. Does not count for
  347. * 'Finished' MAC. */
  348. if (p[1] == 0 && p[2] == 0 &&p[3] == 0)
  349. {
  350. s->init_num = 0;
  351. skip_message = 1;
  352. }
  353. }
  354. while (skip_message);
  355. /* s->init_num == 4 */
  356. if ((mt >= 0) && (*p != mt))
  357. {
  358. al=SSL_AD_UNEXPECTED_MESSAGE;
  359. SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);
  360. goto f_err;
  361. }
  362. if ((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) &&
  363. (st1 == SSL3_ST_SR_CERT_A) &&
  364. (stn == SSL3_ST_SR_CERT_B))
  365. {
  366. /* At this point we have got an MS SGC second client
  367. * hello (maybe we should always allow the client to
  368. * start a new handshake?). We need to restart the mac.
  369. * Don't increment {num,total}_renegotiations because
  370. * we have not completed the handshake. */
  371. ssl3_init_finished_mac(s);
  372. }
  373. ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, 4);
  374. s->s3->tmp.message_type= *(p++);
  375. n2l3(p,l);
  376. if (l > (unsigned long)max)
  377. {
  378. al=SSL_AD_ILLEGAL_PARAMETER;
  379. SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);
  380. goto f_err;
  381. }
  382. if (l && !BUF_MEM_grow(s->init_buf,(int)l))
  383. {
  384. SSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);
  385. goto err;
  386. }
  387. s->s3->tmp.message_size=l;
  388. s->state=stn;
  389. s->init_num=0;
  390. }
  391. /* next state (stn) */
  392. p=(unsigned char *)s->init_buf->data;
  393. n=s->s3->tmp.message_size;
  394. n -= s->init_num;
  395. while (n > 0)
  396. {
  397. i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n,0);
  398. if (i <= 0)
  399. {
  400. s->rwstate=SSL_READING;
  401. *ok = 0;
  402. return i;
  403. }
  404. s->init_num += i;
  405. n -= i;
  406. }
  407. ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, s->init_num);
  408. *ok=1;
  409. return s->init_num;
  410. f_err:
  411. ssl3_send_alert(s,SSL3_AL_FATAL,al);
  412. err:
  413. *ok=0;
  414. return(-1);
  415. }
  416. int ssl_cert_type(X509 *x, EVP_PKEY *pkey)
  417. {
  418. EVP_PKEY *pk;
  419. int ret= -1,i,j;
  420. if (pkey == NULL)
  421. pk=X509_get_pubkey(x);
  422. else
  423. pk=pkey;
  424. if (pk == NULL) goto err;
  425. i=pk->type;
  426. if (i == EVP_PKEY_RSA)
  427. {
  428. ret=SSL_PKEY_RSA_ENC;
  429. if (x != NULL)
  430. {
  431. j=X509_get_ext_count(x);
  432. /* check to see if this is a signing only certificate */
  433. /* EAY EAY EAY EAY */
  434. }
  435. }
  436. else if (i == EVP_PKEY_DSA)
  437. {
  438. ret=SSL_PKEY_DSA_SIGN;
  439. }
  440. else if (i == EVP_PKEY_DH)
  441. {
  442. /* if we just have a key, we needs to be guess */
  443. if (x == NULL)
  444. ret=SSL_PKEY_DH_DSA;
  445. else
  446. {
  447. j=X509_get_signature_type(x);
  448. if (j == EVP_PKEY_RSA)
  449. ret=SSL_PKEY_DH_RSA;
  450. else if (j== EVP_PKEY_DSA)
  451. ret=SSL_PKEY_DH_DSA;
  452. else ret= -1;
  453. }
  454. }
  455. else
  456. ret= -1;
  457. err:
  458. if(!pkey) EVP_PKEY_free(pk);
  459. return(ret);
  460. }
  461. int ssl_verify_alarm_type(long type)
  462. {
  463. int al;
  464. switch(type)
  465. {
  466. case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
  467. case X509_V_ERR_UNABLE_TO_GET_CRL:
  468. al=SSL_AD_UNKNOWN_CA;
  469. break;
  470. case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
  471. case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
  472. case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
  473. case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
  474. case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
  475. case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
  476. case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
  477. case X509_V_ERR_CERT_NOT_YET_VALID:
  478. case X509_V_ERR_CRL_NOT_YET_VALID:
  479. case X509_V_ERR_CERT_UNTRUSTED:
  480. case X509_V_ERR_CERT_REJECTED:
  481. al=SSL_AD_BAD_CERTIFICATE;
  482. break;
  483. case X509_V_ERR_CERT_SIGNATURE_FAILURE:
  484. case X509_V_ERR_CRL_SIGNATURE_FAILURE:
  485. al=SSL_AD_DECRYPT_ERROR;
  486. break;
  487. case X509_V_ERR_CERT_HAS_EXPIRED:
  488. case X509_V_ERR_CRL_HAS_EXPIRED:
  489. al=SSL_AD_CERTIFICATE_EXPIRED;
  490. break;
  491. case X509_V_ERR_CERT_REVOKED:
  492. al=SSL_AD_CERTIFICATE_REVOKED;
  493. break;
  494. case X509_V_ERR_OUT_OF_MEM:
  495. al=SSL_AD_INTERNAL_ERROR;
  496. break;
  497. case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
  498. case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
  499. case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
  500. case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
  501. case X509_V_ERR_CERT_CHAIN_TOO_LONG:
  502. case X509_V_ERR_PATH_LENGTH_EXCEEDED:
  503. case X509_V_ERR_INVALID_CA:
  504. al=SSL_AD_UNKNOWN_CA;
  505. break;
  506. case X509_V_ERR_APPLICATION_VERIFICATION:
  507. al=SSL_AD_HANDSHAKE_FAILURE;
  508. break;
  509. case X509_V_ERR_INVALID_PURPOSE:
  510. al=SSL_AD_UNSUPPORTED_CERTIFICATE;
  511. break;
  512. default:
  513. al=SSL_AD_CERTIFICATE_UNKNOWN;
  514. break;
  515. }
  516. return(al);
  517. }
  518. int ssl3_setup_buffers(SSL *s)
  519. {
  520. unsigned char *p;
  521. unsigned int extra;
  522. size_t len;
  523. if (s->s3->rbuf.buf == NULL)
  524. {
  525. if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
  526. extra=SSL3_RT_MAX_EXTRA;
  527. else
  528. extra=0;
  529. len = SSL3_RT_MAX_PACKET_SIZE + extra;
  530. if ((p=OPENSSL_malloc(len)) == NULL)
  531. goto err;
  532. s->s3->rbuf.buf = p;
  533. s->s3->rbuf_len = len;
  534. }
  535. if (s->s3->wbuf.buf == NULL)
  536. {
  537. len = SSL3_RT_MAX_PACKET_SIZE;
  538. len += SSL3_RT_HEADER_LENGTH + 256; /* extra space for empty fragment */
  539. if ((p=OPENSSL_malloc(len)) == NULL)
  540. goto err;
  541. s->s3->wbuf.buf = p;
  542. s->s3->wbuf_len = len;
  543. }
  544. s->packet= &(s->s3->rbuf.buf[0]);
  545. return(1);
  546. err:
  547. SSLerr(SSL_F_SSL3_SETUP_BUFFERS,ERR_R_MALLOC_FAILURE);
  548. return(0);
  549. }