sl@0: /* ssl/s3_both.c */ sl@0: /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) sl@0: * All rights reserved. sl@0: * sl@0: * This package is an SSL implementation written sl@0: * by Eric Young (eay@cryptsoft.com). sl@0: * The implementation was written so as to conform with Netscapes SSL. sl@0: * sl@0: * This library is free for commercial and non-commercial use as long as sl@0: * the following conditions are aheared to. The following conditions sl@0: * apply to all code found in this distribution, be it the RC4, RSA, sl@0: * lhash, DES, etc., code; not just the SSL code. The SSL documentation sl@0: * included with this distribution is covered by the same copyright terms sl@0: * except that the holder is Tim Hudson (tjh@cryptsoft.com). sl@0: * sl@0: * Copyright remains Eric Young's, and as such any Copyright notices in sl@0: * the code are not to be removed. sl@0: * If this package is used in a product, Eric Young should be given attribution sl@0: * as the author of the parts of the library used. sl@0: * This can be in the form of a textual message at program startup or sl@0: * in documentation (online or textual) provided with the package. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * 3. All advertising materials mentioning features or use of this software sl@0: * must display the following acknowledgement: sl@0: * "This product includes cryptographic software written by sl@0: * Eric Young (eay@cryptsoft.com)" sl@0: * The word 'cryptographic' can be left out if the rouines from the library sl@0: * being used are not cryptographic related :-). sl@0: * 4. If you include any Windows specific code (or a derivative thereof) from sl@0: * the apps directory (application code) you must include an acknowledgement: sl@0: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND sl@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE sl@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE sl@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL sl@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS sl@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT sl@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY sl@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF sl@0: * SUCH DAMAGE. sl@0: * sl@0: * The licence and distribution terms for any publically available version or sl@0: * derivative of this code cannot be changed. i.e. this code cannot simply be sl@0: * copied and put under another distribution licence sl@0: * [including the GNU Public Licence.] sl@0: */ sl@0: /* ==================================================================== sl@0: * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * sl@0: * 1. Redistributions of source code must retain the above copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in sl@0: * the documentation and/or other materials provided with the sl@0: * distribution. sl@0: * sl@0: * 3. All advertising materials mentioning features or use of this sl@0: * software must display the following acknowledgment: sl@0: * "This product includes software developed by the OpenSSL Project sl@0: * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" sl@0: * sl@0: * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to sl@0: * endorse or promote products derived from this software without sl@0: * prior written permission. For written permission, please contact sl@0: * openssl-core@openssl.org. sl@0: * sl@0: * 5. Products derived from this software may not be called "OpenSSL" sl@0: * nor may "OpenSSL" appear in their names without prior written sl@0: * permission of the OpenSSL Project. sl@0: * sl@0: * 6. Redistributions of any form whatsoever must retain the following sl@0: * acknowledgment: sl@0: * "This product includes software developed by the OpenSSL Project sl@0: * for use in the OpenSSL Toolkit (http://www.openssl.org/)" sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY sl@0: * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE sl@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR sl@0: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR sl@0: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, sl@0: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT sl@0: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; sl@0: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, sl@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) sl@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED sl@0: * OF THE POSSIBILITY OF SUCH DAMAGE. sl@0: * ==================================================================== sl@0: * sl@0: * This product includes cryptographic software written by Eric Young sl@0: * (eay@cryptsoft.com). This product includes software written by Tim sl@0: * Hudson (tjh@cryptsoft.com). sl@0: * sl@0: */ sl@0: /* ==================================================================== sl@0: * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. sl@0: * ECC cipher suite support in OpenSSL originally developed by sl@0: * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "ssl_locl.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: /* send s->init_buf in records of type 'type' (SSL3_RT_HANDSHAKE or SSL3_RT_CHANGE_CIPHER_SPEC) */ sl@0: int ssl3_do_write(SSL *s, int type) sl@0: { sl@0: int ret; sl@0: sl@0: ret=ssl3_write_bytes(s,type,&s->init_buf->data[s->init_off], sl@0: s->init_num); sl@0: if (ret < 0) return(-1); sl@0: if (type == SSL3_RT_HANDSHAKE) sl@0: /* should not be done for 'Hello Request's, but in that case sl@0: * we'll ignore the result anyway */ sl@0: ssl3_finish_mac(s,(unsigned char *)&s->init_buf->data[s->init_off],ret); sl@0: sl@0: if (ret == s->init_num) sl@0: { sl@0: if (s->msg_callback) sl@0: s->msg_callback(1, s->version, type, s->init_buf->data, (size_t)(s->init_off + s->init_num), s, s->msg_callback_arg); sl@0: return(1); sl@0: } sl@0: s->init_off+=ret; sl@0: s->init_num-=ret; sl@0: return(0); sl@0: } sl@0: sl@0: int ssl3_send_finished(SSL *s, int a, int b, const char *sender, int slen) sl@0: { sl@0: unsigned char *p,*d; sl@0: int i; sl@0: unsigned long l; sl@0: sl@0: if (s->state == a) sl@0: { sl@0: d=(unsigned char *)s->init_buf->data; sl@0: p= &(d[4]); sl@0: sl@0: i=s->method->ssl3_enc->final_finish_mac(s, sl@0: &(s->s3->finish_dgst1), sl@0: &(s->s3->finish_dgst2), sl@0: sender,slen,s->s3->tmp.finish_md); sl@0: s->s3->tmp.finish_md_len = i; sl@0: memcpy(p, s->s3->tmp.finish_md, i); sl@0: p+=i; sl@0: l=i; sl@0: sl@0: #ifdef OPENSSL_SYS_WIN16 sl@0: /* MSVC 1.5 does not clear the top bytes of the word unless sl@0: * I do this. sl@0: */ sl@0: l&=0xffff; sl@0: #endif sl@0: sl@0: *(d++)=SSL3_MT_FINISHED; sl@0: l2n3(l,d); sl@0: s->init_num=(int)l+4; sl@0: s->init_off=0; sl@0: sl@0: s->state=b; sl@0: } sl@0: sl@0: /* SSL3_ST_SEND_xxxxxx_HELLO_B */ sl@0: return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); sl@0: } sl@0: sl@0: int ssl3_get_finished(SSL *s, int a, int b) sl@0: { sl@0: int al,i,ok; sl@0: long n; sl@0: unsigned char *p; sl@0: sl@0: /* the mac has already been generated when we received the sl@0: * change cipher spec message and is in s->s3->tmp.peer_finish_md sl@0: */ sl@0: sl@0: n=s->method->ssl_get_message(s, sl@0: a, sl@0: b, sl@0: SSL3_MT_FINISHED, sl@0: 64, /* should actually be 36+4 :-) */ sl@0: &ok); sl@0: sl@0: if (!ok) return((int)n); sl@0: sl@0: /* If this occurs, we have missed a message */ sl@0: if (!s->s3->change_cipher_spec) sl@0: { sl@0: al=SSL_AD_UNEXPECTED_MESSAGE; sl@0: SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_GOT_A_FIN_BEFORE_A_CCS); sl@0: goto f_err; sl@0: } sl@0: s->s3->change_cipher_spec=0; sl@0: sl@0: p = (unsigned char *)s->init_msg; sl@0: i = s->s3->tmp.peer_finish_md_len; sl@0: sl@0: if (i != n) sl@0: { sl@0: al=SSL_AD_DECODE_ERROR; sl@0: SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_BAD_DIGEST_LENGTH); sl@0: goto f_err; sl@0: } sl@0: sl@0: if (memcmp(p, s->s3->tmp.peer_finish_md, i) != 0) sl@0: { sl@0: al=SSL_AD_DECRYPT_ERROR; sl@0: SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_DIGEST_CHECK_FAILED); sl@0: goto f_err; sl@0: } sl@0: sl@0: return(1); sl@0: f_err: sl@0: ssl3_send_alert(s,SSL3_AL_FATAL,al); sl@0: return(0); sl@0: } sl@0: sl@0: /* for these 2 messages, we need to sl@0: * ssl->enc_read_ctx re-init sl@0: * ssl->s3->read_sequence zero sl@0: * ssl->s3->read_mac_secret re-init sl@0: * ssl->session->read_sym_enc assign sl@0: * ssl->session->read_compression assign sl@0: * ssl->session->read_hash assign sl@0: */ sl@0: int ssl3_send_change_cipher_spec(SSL *s, int a, int b) sl@0: { sl@0: unsigned char *p; sl@0: sl@0: if (s->state == a) sl@0: { sl@0: p=(unsigned char *)s->init_buf->data; sl@0: *p=SSL3_MT_CCS; sl@0: s->init_num=1; sl@0: s->init_off=0; sl@0: sl@0: s->state=b; sl@0: } sl@0: sl@0: /* SSL3_ST_CW_CHANGE_B */ sl@0: return(ssl3_do_write(s,SSL3_RT_CHANGE_CIPHER_SPEC)); sl@0: } sl@0: sl@0: unsigned long ssl3_output_cert_chain(SSL *s, X509 *x) sl@0: { sl@0: unsigned char *p; sl@0: int n,i; sl@0: unsigned long l=7; sl@0: BUF_MEM *buf; sl@0: X509_STORE_CTX xs_ctx; sl@0: X509_OBJECT obj; sl@0: sl@0: int no_chain; sl@0: sl@0: if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || s->ctx->extra_certs) sl@0: no_chain = 1; sl@0: else sl@0: no_chain = 0; sl@0: sl@0: /* TLSv1 sends a chain with nothing in it, instead of an alert */ sl@0: buf=s->init_buf; sl@0: if (!BUF_MEM_grow_clean(buf,10)) sl@0: { sl@0: SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); sl@0: return(0); sl@0: } sl@0: if (x != NULL) sl@0: { sl@0: if(!no_chain && !X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL)) sl@0: { sl@0: SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_X509_LIB); sl@0: return(0); sl@0: } sl@0: sl@0: for (;;) sl@0: { sl@0: n=i2d_X509(x,NULL); sl@0: if (!BUF_MEM_grow_clean(buf,(int)(n+l+3))) sl@0: { sl@0: SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); sl@0: return(0); sl@0: } sl@0: p=(unsigned char *)&(buf->data[l]); sl@0: l2n3(n,p); sl@0: i2d_X509(x,&p); sl@0: l+=n+3; sl@0: sl@0: if (no_chain) sl@0: break; sl@0: sl@0: if (X509_NAME_cmp(X509_get_subject_name(x), sl@0: X509_get_issuer_name(x)) == 0) break; sl@0: sl@0: i=X509_STORE_get_by_subject(&xs_ctx,X509_LU_X509, sl@0: X509_get_issuer_name(x),&obj); sl@0: if (i <= 0) break; sl@0: x=obj.data.x509; sl@0: /* Count is one too high since the X509_STORE_get uped the sl@0: * ref count */ sl@0: X509_free(x); sl@0: } sl@0: if (!no_chain) sl@0: X509_STORE_CTX_cleanup(&xs_ctx); sl@0: } sl@0: sl@0: /* Thawte special :-) */ sl@0: if (s->ctx->extra_certs != NULL) sl@0: for (i=0; ictx->extra_certs); i++) sl@0: { sl@0: x=sk_X509_value(s->ctx->extra_certs,i); sl@0: n=i2d_X509(x,NULL); sl@0: if (!BUF_MEM_grow_clean(buf,(int)(n+l+3))) sl@0: { sl@0: SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); sl@0: return(0); sl@0: } sl@0: p=(unsigned char *)&(buf->data[l]); sl@0: l2n3(n,p); sl@0: i2d_X509(x,&p); sl@0: l+=n+3; sl@0: } sl@0: sl@0: l-=7; sl@0: p=(unsigned char *)&(buf->data[4]); sl@0: l2n3(l,p); sl@0: l+=3; sl@0: p=(unsigned char *)&(buf->data[0]); sl@0: *(p++)=SSL3_MT_CERTIFICATE; sl@0: l2n3(l,p); sl@0: l+=4; sl@0: return(l); sl@0: } sl@0: sl@0: /* Obtain handshake message of message type 'mt' (any if mt == -1), sl@0: * maximum acceptable body length 'max'. sl@0: * The first four bytes (msg_type and length) are read in state 'st1', sl@0: * the body is read in state 'stn'. sl@0: */ sl@0: long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) sl@0: { sl@0: unsigned char *p; sl@0: unsigned long l; sl@0: long n; sl@0: int i,al; sl@0: sl@0: if (s->s3->tmp.reuse_message) sl@0: { sl@0: s->s3->tmp.reuse_message=0; sl@0: if ((mt >= 0) && (s->s3->tmp.message_type != mt)) sl@0: { sl@0: al=SSL_AD_UNEXPECTED_MESSAGE; sl@0: SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE); sl@0: goto f_err; sl@0: } sl@0: *ok=1; sl@0: s->init_msg = s->init_buf->data + 4; sl@0: s->init_num = (int)s->s3->tmp.message_size; sl@0: return s->init_num; sl@0: } sl@0: sl@0: p=(unsigned char *)s->init_buf->data; sl@0: sl@0: if (s->state == st1) /* s->init_num < 4 */ sl@0: { sl@0: int skip_message; sl@0: sl@0: do sl@0: { sl@0: while (s->init_num < 4) sl@0: { sl@0: i=s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE, sl@0: &p[s->init_num],4 - s->init_num, 0); sl@0: if (i <= 0) sl@0: { sl@0: s->rwstate=SSL_READING; sl@0: *ok = 0; sl@0: return i; sl@0: } sl@0: s->init_num+=i; sl@0: } sl@0: sl@0: skip_message = 0; sl@0: if (!s->server) sl@0: if (p[0] == SSL3_MT_HELLO_REQUEST) sl@0: /* The server may always send 'Hello Request' messages -- sl@0: * we are doing a handshake anyway now, so ignore them sl@0: * if their format is correct. Does not count for sl@0: * 'Finished' MAC. */ sl@0: if (p[1] == 0 && p[2] == 0 &&p[3] == 0) sl@0: { sl@0: s->init_num = 0; sl@0: skip_message = 1; sl@0: sl@0: if (s->msg_callback) sl@0: s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, p, 4, s, s->msg_callback_arg); sl@0: } sl@0: } sl@0: while (skip_message); sl@0: sl@0: /* s->init_num == 4 */ sl@0: sl@0: if ((mt >= 0) && (*p != mt)) sl@0: { sl@0: al=SSL_AD_UNEXPECTED_MESSAGE; sl@0: SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE); sl@0: goto f_err; sl@0: } sl@0: if ((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) && sl@0: (st1 == SSL3_ST_SR_CERT_A) && sl@0: (stn == SSL3_ST_SR_CERT_B)) sl@0: { sl@0: /* At this point we have got an MS SGC second client sl@0: * hello (maybe we should always allow the client to sl@0: * start a new handshake?). We need to restart the mac. sl@0: * Don't increment {num,total}_renegotiations because sl@0: * we have not completed the handshake. */ sl@0: ssl3_init_finished_mac(s); sl@0: } sl@0: sl@0: s->s3->tmp.message_type= *(p++); sl@0: sl@0: n2l3(p,l); sl@0: if (l > (unsigned long)max) sl@0: { sl@0: al=SSL_AD_ILLEGAL_PARAMETER; sl@0: SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE); sl@0: goto f_err; sl@0: } sl@0: if (l > (INT_MAX-4)) /* BUF_MEM_grow takes an 'int' parameter */ sl@0: { sl@0: al=SSL_AD_ILLEGAL_PARAMETER; sl@0: SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE); sl@0: goto f_err; sl@0: } sl@0: if (l && !BUF_MEM_grow_clean(s->init_buf,(int)l+4)) sl@0: { sl@0: SSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB); sl@0: goto err; sl@0: } sl@0: s->s3->tmp.message_size=l; sl@0: s->state=stn; sl@0: sl@0: s->init_msg = s->init_buf->data + 4; sl@0: s->init_num = 0; sl@0: } sl@0: sl@0: /* next state (stn) */ sl@0: p = s->init_msg; sl@0: n = s->s3->tmp.message_size - s->init_num; sl@0: while (n > 0) sl@0: { sl@0: i=s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n,0); sl@0: if (i <= 0) sl@0: { sl@0: s->rwstate=SSL_READING; sl@0: *ok = 0; sl@0: return i; sl@0: } sl@0: s->init_num += i; sl@0: n -= i; sl@0: } sl@0: ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, s->init_num + 4); sl@0: if (s->msg_callback) sl@0: s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, s->init_buf->data, (size_t)s->init_num + 4, s, s->msg_callback_arg); sl@0: *ok=1; sl@0: return s->init_num; sl@0: f_err: sl@0: ssl3_send_alert(s,SSL3_AL_FATAL,al); sl@0: err: sl@0: *ok=0; sl@0: return(-1); sl@0: } sl@0: sl@0: int ssl_cert_type(X509 *x, EVP_PKEY *pkey) sl@0: { sl@0: EVP_PKEY *pk; sl@0: int ret= -1,i; sl@0: sl@0: if (pkey == NULL) sl@0: pk=X509_get_pubkey(x); sl@0: else sl@0: pk=pkey; sl@0: if (pk == NULL) goto err; sl@0: sl@0: i=pk->type; sl@0: if (i == EVP_PKEY_RSA) sl@0: { sl@0: ret=SSL_PKEY_RSA_ENC; sl@0: } sl@0: else if (i == EVP_PKEY_DSA) sl@0: { sl@0: ret=SSL_PKEY_DSA_SIGN; sl@0: } sl@0: #ifndef OPENSSL_NO_EC sl@0: else if (i == EVP_PKEY_EC) sl@0: { sl@0: ret = SSL_PKEY_ECC; sl@0: } sl@0: #endif sl@0: sl@0: err: sl@0: if(!pkey) EVP_PKEY_free(pk); sl@0: return(ret); sl@0: } sl@0: sl@0: int ssl_verify_alarm_type(long type) sl@0: { sl@0: int al; sl@0: sl@0: switch(type) sl@0: { sl@0: case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: sl@0: case X509_V_ERR_UNABLE_TO_GET_CRL: sl@0: case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER: sl@0: al=SSL_AD_UNKNOWN_CA; sl@0: break; sl@0: case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: sl@0: case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: sl@0: case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: sl@0: case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: sl@0: case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: sl@0: case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: sl@0: case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: sl@0: case X509_V_ERR_CERT_NOT_YET_VALID: sl@0: case X509_V_ERR_CRL_NOT_YET_VALID: sl@0: case X509_V_ERR_CERT_UNTRUSTED: sl@0: case X509_V_ERR_CERT_REJECTED: sl@0: al=SSL_AD_BAD_CERTIFICATE; sl@0: break; sl@0: case X509_V_ERR_CERT_SIGNATURE_FAILURE: sl@0: case X509_V_ERR_CRL_SIGNATURE_FAILURE: sl@0: al=SSL_AD_DECRYPT_ERROR; sl@0: break; sl@0: case X509_V_ERR_CERT_HAS_EXPIRED: sl@0: case X509_V_ERR_CRL_HAS_EXPIRED: sl@0: al=SSL_AD_CERTIFICATE_EXPIRED; sl@0: break; sl@0: case X509_V_ERR_CERT_REVOKED: sl@0: al=SSL_AD_CERTIFICATE_REVOKED; sl@0: break; sl@0: case X509_V_ERR_OUT_OF_MEM: sl@0: al=SSL_AD_INTERNAL_ERROR; sl@0: break; sl@0: case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: sl@0: case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: sl@0: case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: sl@0: case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: sl@0: case X509_V_ERR_CERT_CHAIN_TOO_LONG: sl@0: case X509_V_ERR_PATH_LENGTH_EXCEEDED: sl@0: case X509_V_ERR_INVALID_CA: sl@0: al=SSL_AD_UNKNOWN_CA; sl@0: break; sl@0: case X509_V_ERR_APPLICATION_VERIFICATION: sl@0: al=SSL_AD_HANDSHAKE_FAILURE; sl@0: break; sl@0: case X509_V_ERR_INVALID_PURPOSE: sl@0: al=SSL_AD_UNSUPPORTED_CERTIFICATE; sl@0: break; sl@0: default: sl@0: al=SSL_AD_CERTIFICATE_UNKNOWN; sl@0: break; sl@0: } sl@0: return(al); sl@0: } sl@0: sl@0: int ssl3_setup_buffers(SSL *s) sl@0: { sl@0: unsigned char *p; sl@0: unsigned int extra; sl@0: size_t len; sl@0: sl@0: if (s->s3->rbuf.buf == NULL) sl@0: { sl@0: if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER) sl@0: extra=SSL3_RT_MAX_EXTRA; sl@0: else sl@0: extra=0; sl@0: len = SSL3_RT_MAX_PACKET_SIZE + extra; sl@0: if ((p=OPENSSL_malloc(len)) == NULL) sl@0: goto err; sl@0: s->s3->rbuf.buf = p; sl@0: s->s3->rbuf.len = len; sl@0: } sl@0: sl@0: if (s->s3->wbuf.buf == NULL) sl@0: { sl@0: len = SSL3_RT_MAX_PACKET_SIZE; sl@0: len += SSL3_RT_HEADER_LENGTH + 256; /* extra space for empty fragment */ sl@0: if ((p=OPENSSL_malloc(len)) == NULL) sl@0: goto err; sl@0: s->s3->wbuf.buf = p; sl@0: s->s3->wbuf.len = len; sl@0: } sl@0: s->packet= &(s->s3->rbuf.buf[0]); sl@0: return(1); sl@0: err: sl@0: SSLerr(SSL_F_SSL3_SETUP_BUFFERS,ERR_R_MALLOC_FAILURE); sl@0: return(0); sl@0: }