Some more stack stuff.
[openssl.git] / ssl / s3_lib.c
index d7bb6cde35e10eee0549e4b9c213595d0dc27742..c41e2548bdbd89ead141e7da579db38e8ba4d42b 100644 (file)
  */
 
 #include <stdio.h>
-#include "objects.h"
+#include <openssl/md5.h>
+#include <openssl/sha.h>
+#include <openssl/objects.h>
 #include "ssl_locl.h"
 
-char *ssl3_version_str="SSLv3" OPENSSL_VERSION_PTEXT;
+const char *ssl3_version_str="SSLv3" OPENSSL_VERSION_PTEXT;
 
 #define SSL3_NUM_CIPHERS       (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
 
-#ifndef NOPROTO
 static long ssl3_default_timeout(void );
-#else
-static long ssl3_default_timeout();
-#endif
-
 SSL_CIPHER ssl3_ciphers[]={
 /* The RSA ciphers */
 /* Cipher 01 */
@@ -360,8 +357,8 @@ SSL_CIPHER ssl3_ciphers[]={
        /* Cipher 60 */
            {
            1,
-           TLS1_TXT_RSA_EXPORT56_WITH_RC4_56_MD5,
-           TLS1_CK_RSA_EXPORT56_WITH_RC4_56_MD5,
+           TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5,
+           TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5,
            SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_EXP56|SSL_TLSV1,
            0,
            SSL_ALL_CIPHERS
@@ -369,8 +366,8 @@ SSL_CIPHER ssl3_ciphers[]={
        /* Cipher 61 */
            {
            1,
-           TLS1_TXT_RSA_EXPORT56_WITH_RC2_CBC_56_MD5,
-           TLS1_CK_RSA_EXPORT56_WITH_RC2_CBC_56_MD5,
+           TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
+           TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
            SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_EXP56|SSL_TLSV1,
            0,
            SSL_ALL_CIPHERS
@@ -378,12 +375,48 @@ SSL_CIPHER ssl3_ciphers[]={
        /* Cipher 62 */
            {
            1,
-           TLS1_TXT_RSA_EXPORT56_WITH_DES_CBC_SHA,
-           TLS1_CK_RSA_EXPORT56_WITH_DES_CBC_SHA,
+           TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA,
+           TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA,
            SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA|SSL_EXP56|SSL_TLSV1,
            0,
            SSL_ALL_CIPHERS
            },
+       /* Cipher 63 */
+           {
+           1,
+           TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
+           TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
+           SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA|SSL_EXP56|SSL_TLSV1,
+           0,
+           SSL_ALL_CIPHERS
+           },
+       /* Cipher 64 */
+           {
+           1,
+           TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA,
+           TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA,
+           SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_EXP56|SSL_TLSV1,
+           0,
+           SSL_ALL_CIPHERS
+           },
+       /* Cipher 65 */
+           {
+           1,
+           TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
+           TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
+           SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_EXP56|SSL_TLSV1,
+           0,
+           SSL_ALL_CIPHERS
+           },
+       /* Cipher 66 */
+           {
+           1,
+           TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA,
+           TLS1_CK_DHE_DSS_WITH_RC4_128_SHA,
+           SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1,
+           0,
+           SSL_ALL_CIPHERS
+           },
 #endif
 
 /* end of list */
@@ -428,25 +461,24 @@ static SSL_METHOD SSLv3_data= {
        &SSLv3_enc_data,
        };
 
-static long ssl3_default_timeout()
+static long ssl3_default_timeout(void)
        {
        /* 2 hours, the 24 hours mentioned in the SSLv3 spec
         * is way too long for http, the cache would over fill */
        return(60*60*2);
        }
 
-SSL_METHOD *sslv3_base_method()
+SSL_METHOD *sslv3_base_method(void)
        {
        return(&SSLv3_data);
        }
 
-int ssl3_num_ciphers()
+int ssl3_num_ciphers(void)
        {
        return(SSL3_NUM_CIPHERS);
        }
 
-SSL_CIPHER *ssl3_get_cipher(u)
-unsigned int u;
+SSL_CIPHER *ssl3_get_cipher(unsigned int u)
        {
        if (u < SSL3_NUM_CIPHERS)
                return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u]));
@@ -455,14 +487,12 @@ unsigned int u;
        }
 
 /* The problem is that it may not be the correct record type */
-int ssl3_pending(s)
-SSL *s;
+int ssl3_pending(SSL *s)
        {
        return(s->s3->rrec.length);
        }
 
-int ssl3_new(s)
-SSL *s;
+int ssl3_new(SSL *s)
        {
        SSL3_CTX *s3;
 
@@ -484,8 +514,7 @@ err:
        return(0);
        }
 
-void ssl3_free(s)
-SSL *s;
+void ssl3_free(SSL *s)
        {
        if(s == NULL)
            return;
@@ -508,8 +537,7 @@ SSL *s;
        s->s3=NULL;
        }
 
-void ssl3_clear(s)
-SSL *s;
+void ssl3_clear(SSL *s)
        {
        unsigned char *rp,*wp;
 
@@ -540,11 +568,7 @@ SSL *s;
        s->version=SSL3_VERSION;
        }
 
-long ssl3_ctrl(s,cmd,larg,parg)
-SSL *s;
-int cmd;
-long larg;
-char *parg;
+long ssl3_ctrl(SSL *s, int cmd, long larg, char *parg)
        {
        int ret=0;
 
@@ -613,11 +637,7 @@ char *parg;
                }
                break;
        case SSL_CTRL_SET_TMP_RSA_CB:
-#ifndef NOPROTO
                s->cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))parg;
-#else
-               s->cert->rsa_tmp_cb = (RSA *(*)())parg;
-#endif
                break;
 #endif
 #ifndef NO_DH
@@ -644,11 +664,7 @@ char *parg;
                }
                break;
        case SSL_CTRL_SET_TMP_DH_CB:
-#ifndef NOPROTO
                s->cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))parg;
-#else
-               s->cert->dh_tmp_cb = (DH *(*)())parg;
-#endif
                break;
 #endif
        default:
@@ -657,11 +673,7 @@ char *parg;
        return(ret);
        }
 
-long ssl3_ctx_ctrl(ctx,cmd,larg,parg)
-SSL_CTX *ctx;
-int cmd;
-long larg;
-char *parg;
+long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, char *parg)
        {
        CERT *cert;
 
@@ -708,11 +720,7 @@ char *parg;
                }
                /* break; */
        case SSL_CTRL_SET_TMP_RSA_CB:
-#ifndef NOPROTO
                cert->rsa_tmp_cb=(RSA *(*)(SSL *, int, int))parg;
-#else
-               cert->rsa_tmp_cb=(RSA *(*)())parg;
-#endif
                break;
 #endif
 #ifndef NO_DH
@@ -739,11 +747,7 @@ char *parg;
                }
                /*break; */
        case SSL_CTRL_SET_TMP_DH_CB:
-#ifndef NOPROTO
                cert->dh_tmp_cb=(DH *(*)(SSL *, int, int))parg;
-#else
-               cert->dh_tmp_cb=(DH *(*)())parg;
-#endif
                break;
 #endif
        /* A Thawte special :-) */
@@ -764,8 +768,7 @@ char *parg;
 
 /* This function needs to check if the ciphers required are actually
  * available */
-SSL_CIPHER *ssl3_get_cipher_by_char(p)
-const unsigned char *p;
+SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p)
        {
        static int init=1;
        static SSL_CIPHER *sorted[SSL3_NUM_CIPHERS];
@@ -775,7 +778,7 @@ const unsigned char *p;
 
        if (init)
                {
-               init=0;
+               CRYPTO_w_lock(CRYPTO_LOCK_SSL);
 
                for (i=0; i<SSL3_NUM_CIPHERS; i++)
                        sorted[i]= &(ssl3_ciphers[i]);
@@ -783,6 +786,10 @@ const unsigned char *p;
                qsort(  (char *)sorted,
                        SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
                        FP_ICC ssl_cipher_ptr_id_cmp);
+
+               CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
+
+               init=0;
                }
 
        id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1];
@@ -797,9 +804,7 @@ const unsigned char *p;
                return(*cpp);
        }
 
-int ssl3_put_cipher_by_char(c,p)
-const SSL_CIPHER *c;
-unsigned char *p;
+int ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
        {
        long l;
 
@@ -813,9 +818,7 @@ unsigned char *p;
        return(2);
        }
 
-int ssl3_part_read(s,i)
-SSL *s;
-int i;
+int ssl3_part_read(SSL *s, int i)
        {
        s->rwstate=SSL_READING;
 
@@ -830,10 +833,8 @@ int i;
                }
        }
 
-SSL_CIPHER *ssl3_choose_cipher(s,have,pref)
-SSL *s;
-STACK_OF(SSL_CIPHER) *have;
-STACK_OF(SSL_CIPHER) *pref;
+SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *have,
+            STACK_OF(SSL_CIPHER) *pref)
        {
        SSL_CIPHER *c,*ret=NULL;
        int i,j,ok;
@@ -895,9 +896,7 @@ STACK_OF(SSL_CIPHER) *pref;
        return(ret);
        }
 
-int ssl3_get_req_cert_type(s,p)
-SSL *s;
-unsigned char *p;
+int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
        {
        int ret=0;
        unsigned long alg;
@@ -934,8 +933,7 @@ unsigned char *p;
        return(ret);
        }
 
-int ssl3_shutdown(s)
-SSL *s;
+int ssl3_shutdown(SSL *s)
        {
 
        /* Don't do anything much if we have not done the handshake or
@@ -975,10 +973,7 @@ SSL *s;
                return(0);
        }
 
-int ssl3_write(s,buf,len)
-SSL *s;
-const char *buf;
-int len;
+int ssl3_write(SSL *s, const void *buf, int len)
        {
        int ret,n;
 
@@ -1003,7 +998,7 @@ int len;
                if (s->s3->delay_buf_pop_ret == 0)
                        {
                        ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
-                               (char *)buf,len);
+                                            buf,len);
                        if (ret <= 0) return(ret);
 
                        s->s3->delay_buf_pop_ret=ret;
@@ -1024,17 +1019,14 @@ int len;
        else
                {
                ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
-                       (char *)buf,len);
+                                    buf,len);
                if (ret <= 0) return(ret);
                }
 
        return(ret);
        }
 
-int ssl3_read(s,buf,len)
-SSL *s;
-char *buf;
-int len;
+int ssl3_read(SSL *s, void *buf, int len)
        {
        int ret;
        
@@ -1056,10 +1048,7 @@ int len;
        return(ret);
        }
 
-int ssl3_peek(s,buf,len)
-SSL *s;
-char *buf;
-int len;
+int ssl3_peek(SSL *s, char *buf, int len)
        {
        SSL3_RECORD *rr;
        int n;
@@ -1081,8 +1070,7 @@ int len;
        return(n);
        }
 
-int ssl3_renegotiate(s)
-SSL *s;
+int ssl3_renegotiate(SSL *s)
        {
        if (s->handshake_func == NULL)
                return(1);
@@ -1094,8 +1082,7 @@ SSL *s;
        return(1);
        }
 
-int ssl3_renegotiate_check(s)
-SSL *s;
+int ssl3_renegotiate_check(SSL *s)
        {
        int ret=0;