First attempt at adding the possibility to set the pointer size for the builds on...
[openssl.git] / ssl / s3_lib.c
index f09238f187425b4920b2468ff06ab14aa4b9a8c2..53bf4c23aa704099ec24c6a4b0fbc068563e4450 100644 (file)
@@ -2077,7 +2077,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
 
 SSL3_ENC_METHOD SSLv3_enc_data={
        ssl3_enc,
-       ssl3_mac,
+       n_ssl3_mac,
        ssl3_setup_key_block,
        ssl3_generate_master_secret,
        ssl3_change_cipher_state,
@@ -2101,7 +2101,7 @@ int ssl3_num_ciphers(void)
        return(SSL3_NUM_CIPHERS);
        }
 
-SSL_CIPHER *ssl3_get_cipher(unsigned int u)
+const SSL_CIPHER *ssl3_get_cipher(unsigned int u)
        {
        if (u < SSL3_NUM_CIPHERS)
                return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u]));
@@ -2211,6 +2211,7 @@ void ssl3_clear(SSL *s)
        wlen = s->s3->wbuf.len;
        if (s->s3->handshake_buffer) {
                BIO_free(s->s3->handshake_buffer);
+               s->s3->handshake_buffer = NULL;
        }
        if (s->s3->handshake_dgst) {
                ssl3_free_digest_list(s);
@@ -2229,6 +2230,15 @@ void ssl3_clear(SSL *s)
        s->s3->num_renegotiations=0;
        s->s3->in_read_app_data=0;
        s->version=SSL3_VERSION;
+
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
+       if (s->next_proto_negotiated)
+               {
+               OPENSSL_free(s->next_proto_negotiated);
+               s->next_proto_negotiated = NULL;
+               s->next_proto_negotiated_len = 0;
+               }
+#endif
        }
 
 long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
@@ -2534,6 +2544,11 @@ long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)(void))
                                        unsigned char *, int, void *))fp;
                break;
 #endif
+       case SSL_CTRL_SET_NOT_RESUMABLE_SESS_CB:
+               {
+               s->not_resumable_session_cb = (int (*)(SSL *, int))fp;
+               }
+               break;
        default:
                break;
                }
@@ -2778,6 +2793,11 @@ long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
                break;
 
 #endif
+       case SSL_CTRL_SET_NOT_RESUMABLE_SESS_CB:
+               {
+               ctx->not_resumable_session_cb = (int (*)(SSL *, int))fp;
+               }
+               break;
        default:
                return(0);
                }
@@ -2786,17 +2806,15 @@ long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
 
 /* This function needs to check if the ciphers required are actually
  * available */
-SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p)
+const SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p)
        {
-       SSL_CIPHER c,*cp;
+       SSL_CIPHER c;
+       const SSL_CIPHER *cp;
        unsigned long id;
 
        id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1];
        c.id=id;
-       cp = (SSL_CIPHER *)OBJ_bsearch((char *)&c,
-               (char *)ssl3_ciphers,
-               SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER),
-               FP_ICC ssl_cipher_id_cmp);
+       cp = OBJ_bsearch_ssl_cipher_id(&c, ssl3_ciphers, SSL3_NUM_CIPHERS);
        if (cp == NULL || cp->valid == 0)
                return NULL;
        else
@@ -2823,13 +2841,11 @@ SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
        SSL_CIPHER *c,*ret=NULL;
        STACK_OF(SSL_CIPHER) *prio, *allow;
        int i,ii,ok;
-#ifndef OPENSSL_NO_TLSEXT
+#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_EC)
        unsigned int j;
-#ifndef OPENSSL_NO_EC
        int ec_ok, ec_nid;
        unsigned char ec_search1 = 0, ec_search2 = 0;
-#endif /* OPENSSL_NO_EC */
-#endif /* OPENSSL_NO_TLSEXT */
+#endif
        CERT *cert;
        unsigned long alg_k,alg_a,mask_k,mask_a,emask_k,emask_a;
 
@@ -3091,6 +3107,18 @@ int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
 
        alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
 
+#ifndef OPENSSL_NO_GOST
+       if (s->version >= TLS1_VERSION)
+               {
+               if (alg_k & SSL_kGOST)
+                       {
+                       p[ret++]=TLS_CT_GOST94_SIGN;
+                       p[ret++]=TLS_CT_GOST01_SIGN;
+                       return(ret);
+                       }
+               }
+#endif
+
 #ifndef OPENSSL_NO_DH
        if (alg_k & (SSL_kDHr|SSL_kEDH))
                {
@@ -3140,6 +3168,7 @@ int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
 
 int ssl3_shutdown(SSL *s)
        {
+       int ret;
 
        /* Don't do anything much if we have not done the handshake or
         * we don't want to send messages :-) */
@@ -3157,18 +3186,32 @@ int ssl3_shutdown(SSL *s)
 #endif
                /* our shutdown alert has been sent now, and if it still needs
                 * to be written, s->s3->alert_dispatch will be true */
+               if (s->s3->alert_dispatch)
+                       return(-1);     /* return WANT_WRITE */
                }
        else if (s->s3->alert_dispatch)
                {
                /* resend it if not sent */
 #if 1
-               s->method->ssl_dispatch_alert(s);
+               ret=s->method->ssl_dispatch_alert(s);
+               if(ret == -1)
+                       {
+                       /* we only get to return -1 here the 2nd/Nth
+                        * invocation, we must  have already signalled
+                        * return 0 upon a previous invoation,
+                        * return WANT_WRITE */
+                       return(ret);
+                       }
 #endif
                }
        else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN))
                {
                /* If we are waiting for a close from our peer, we are closed */
                s->method->ssl_read_bytes(s,0,NULL,0,0);
+               if(!(s->shutdown & SSL_RECEIVED_SHUTDOWN))
+                       {
+                       return(-1);     /* return WANT_READ */
+                       }
                }
 
        if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) &&
@@ -3302,4 +3345,3 @@ need to go to SSL_ST_ACCEPT.
                }
        return(ret);
        }
-