SSL_R_UNSUPPORTED_PROTOCOL (as in s23_clnt.c) for SSL 2 when
[openssl.git] / ssl / s23_srvr.c
index 8a3bc2ea1f0de2d0cf0a910847b43fa396255cb0..7fe8027daa1833a5cc803bac4977c0d02f9c349f 100644 (file)
@@ -67,8 +67,10 @@ static SSL_METHOD *ssl23_get_server_method(int ver);
 int ssl23_get_client_hello(SSL *s);
 static SSL_METHOD *ssl23_get_server_method(int ver)
        {
+#ifndef NO_SSL2
        if (ver == SSL2_VERSION)
                return(SSLv2_server_method());
+#endif
        if (ver == SSL3_VERSION)
                return(SSLv3_server_method());
        else if (ver == TLS1_VERSION)
@@ -101,7 +103,7 @@ int ssl23_accept(SSL *s)
        int ret= -1;
        int new_state,state;
 
-       RAND_seed(&Time,sizeof(Time));
+       RAND_add(&Time,sizeof(Time),0);
        ERR_clear_error();
        clear_sys_error();
 
@@ -186,7 +188,18 @@ end:
 
 int ssl23_get_client_hello(SSL *s)
        {
-       char buf_space[11]; /* request this many bytes in initial read */
+       char buf_space[11]; /* Request this many bytes in initial read.
+                            * We can detect SSL 3.0/TLS 1.0 Client Hellos only
+                            * when the following is in a single record
+                            * (not guaranteed by protocol specs):
+                            * Byte  Content
+                            *  0     type            \
+                            *  1/2   version          > record header
+                            *  3/4   length          /
+                            *  5     msg_type        \
+                            *  6-8   length           > Client Hello message
+                            *  9/10  client_version  /
+                            */
        char *buf= &(buf_space[0]);
        unsigned char *p,*d,*dd;
        unsigned int i;
@@ -341,7 +354,10 @@ int ssl23_get_client_hello(SSL *s)
                                        }
                                }
                        else if (!(s->options & SSL_OP_NO_SSLv3))
+                               {
+                               s->version=SSL3_VERSION;
                                type=3;
+                               }
                        }
                else if ((strncmp("GET ", (char *)p,4) == 0) ||
                         (strncmp("POST ",(char *)p,5) == 0) ||
@@ -436,6 +452,10 @@ next_bit:
 
        if (type == 1)
                {
+#ifdef NO_SSL2
+               SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
+               goto err;
+#else
                /* we are talking sslv2 */
                /* we need to clean up the SSLv3/TLSv1 setup and put in the
                 * sslv2 stuff. */
@@ -474,6 +494,7 @@ next_bit:
 
                s->method=SSLv2_server_method();
                s->handshake_func=s->method->ssl_accept;
+#endif
                }
 
        if ((type == 2) || (type == 3))