PR: 2230
[openssl.git] / ssl / s23_clnt.c
index b21308b6f24268252f5cd4fb46a0eab31ce3ffa7..c6b9142c909cad2174611bee996b1d7ed4e1cd08 100644 (file)
@@ -80,33 +80,15 @@ static SSL_METHOD *ssl23_get_client_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *SSLv23_client_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD SSLv23_client_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-
-               if (init)
-                       {
-                       memcpy((char *)&SSLv23_client_data,
-                               (char *)sslv23_base_method(),sizeof(SSL_METHOD));
-                       SSLv23_client_data.ssl_connect=ssl23_connect;
-                       SSLv23_client_data.get_ssl_method=ssl23_get_client_method;
-                       init=0;
-                       }
-
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&SSLv23_client_data);
-       }
+IMPLEMENT_ssl23_meth_func(SSLv23_client_method,
+                       ssl_undefined_function,
+                       ssl23_connect,
+                       ssl23_get_client_method)
 
 int ssl23_connect(SSL *s)
        {
        BUF_MEM *buf=NULL;
-       unsigned long Time=time(NULL);
+       unsigned long Time=(unsigned long)time(NULL);
        void (*cb)(const SSL *ssl,int type,int val)=NULL;
        int ret= -1;
        int new_state,state;
@@ -220,11 +202,14 @@ static int ssl23_client_hello(SSL *s)
        {
        unsigned char *buf;
        unsigned char *p,*d;
-       int i,j,ch_len;
+       int i,ch_len;
        unsigned long Time,l;
        int ssl2_compat;
        int version = 0, version_major, version_minor;
+#ifndef OPENSSL_NO_COMP
+       int j;
        SSL_COMP *comp;
+#endif
        int ret;
 
        ssl2_compat = (s->options & SSL_OP_NO_SSLv2) ? 0 : 1;
@@ -241,6 +226,17 @@ static int ssl23_client_hello(SSL *s)
                {
                version = SSL2_VERSION;
                }
+#ifndef OPENSSL_NO_TLSEXT 
+       if (version != SSL2_VERSION)
+               {
+               /* have to disable SSL 2.0 compatibility if we need TLS extensions */
+
+               if (s->tlsext_hostname != NULL)
+                       ssl2_compat = 0;
+               if (s->tlsext_status_type != -1)
+                       ssl2_compat = 0;
+               }
+#endif
 
        buf=(unsigned char *)s->init_buf->data;
        if (s->state == SSL23_ST_CW_CLNT_HELLO_A)
@@ -254,7 +250,7 @@ static int ssl23_client_hello(SSL *s)
 #endif
 
                p=s->s3->client_random;
-               Time=time(NULL);                        /* Time */
+               Time=(unsigned long)time(NULL);         /* Time */
                l2n(Time,p);
                if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
                        return -1;
@@ -264,6 +260,14 @@ static int ssl23_client_hello(SSL *s)
                        version_major = TLS1_VERSION_MAJOR;
                        version_minor = TLS1_VERSION_MINOR;
                        }
+#ifdef OPENSSL_FIPS
+               else if(FIPS_mode())
+                       {
+                       SSLerr(SSL_F_SSL23_CLIENT_HELLO,
+                                       SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
+                       return -1;
+                       }
+#endif
                else if (version == SSL3_VERSION)
                        {
                        version_major = SSL3_VERSION_MAJOR;
@@ -365,7 +369,9 @@ static int ssl23_client_hello(SSL *s)
                                }
                        s2n(i,p);
                        p+=i;
-
+#ifdef OPENSSL_NO_COMP
+                       *(p++)=1;
+#else
                        /* COMPRESSION */
                        if (s->ctx->comp_methods == NULL)
                                j=0;
@@ -377,7 +383,15 @@ static int ssl23_client_hello(SSL *s)
                                comp=sk_SSL_COMP_value(s->ctx->comp_methods,i);
                                *(p++)=comp->id;
                                }
+#endif
                        *(p++)=0; /* Add the NULL method */
+#ifndef OPENSSL_NO_TLSEXT
+                       if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL)
+                               {
+                               SSLerr(SSL_F_SSL23_CLIENT_HELLO,ERR_R_INTERNAL_ERROR);
+                               return -1;
+                               }
+#endif
                        
                        l = p-d;
                        *p = 42;
@@ -536,6 +550,14 @@ static int ssl23_get_server_hello(SSL *s)
                if ((p[2] == SSL3_VERSION_MINOR) &&
                        !(s->options & SSL_OP_NO_SSLv3))
                        {
+#ifdef OPENSSL_FIPS
+                       if(FIPS_mode())
+                               {
+                               SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,
+                                       SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
+                               goto err;
+                               }
+#endif
                        s->version=SSL3_VERSION;
                        s->method=SSLv3_client_method();
                        }
@@ -592,7 +614,6 @@ static int ssl23_get_server_hello(SSL *s)
        if (!ssl_get_new_session(s,0))
                goto err;
 
-       s->first_packet=1;
        return(SSL_connect(s));
 err:
        return(-1);