Some more prototype fixes.
[openssl.git] / ssl / s23_srvr.c
index 8c41e1ff01f822160020ccb86e892a1143807d97..9e89cc7f9a24bacbe61834fff9aa86bb2b5dad01 100644 (file)
@@ -152,7 +152,7 @@ int ssl23_accept(SSL *s)
        {
        BUF_MEM *buf;
        unsigned long Time=time(NULL);
-       void (*cb)()=NULL;
+       void (*cb)(const SSL *ssl,int type,int val)=NULL;
        int ret= -1;
        int new_state,state;
 
@@ -165,8 +165,8 @@ int ssl23_accept(SSL *s)
        else if (s->ctx->info_callback != NULL)
                cb=s->ctx->info_callback;
        
-       if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); 
        s->in_handshake++;
+       if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); 
 
        for (;;)
                {
@@ -232,9 +232,9 @@ int ssl23_accept(SSL *s)
                        }
                }
 end:
+       s->in_handshake--;
        if (cb != NULL)
                cb(s,SSL_CB_ACCEPT_EXIT,ret);
-       s->in_handshake--;
        return(ret);
        }
 
@@ -339,17 +339,22 @@ int ssl23_get_client_hello(SSL *s)
                        /* We must look at client_version inside the Client Hello message
                         * to get the correct minor version.
                         * However if we have only a pathologically small fragment of the
-                        * Client Hello message, this would be difficult, we'd have
-                        * to read at least one additional record to find out.
-                        * This doesn't usually happen in real life, so we just complain
-                        * for now.
-                        */
+                        * Client Hello message, this would be difficult, and we'd have
+                        * to read more records to find out.
+                        * No known SSL 3.0 client fragments ClientHello like this,
+                        * so we simply assume TLS 1.0 to avoid protocol version downgrade
+                        * attacks. */
                        if (p[3] == 0 && p[4] < 6)
                                {
+#if 0
                                SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_SMALL);
                                goto err;
+#else
+                               v[1] = TLS1_VERSION_MINOR;
+#endif
                                }
-                       v[1]=p[10]; /* minor version according to client_version */
+                       else
+                               v[1]=p[10]; /* minor version according to client_version */
                        if (v[1] >= TLS1_VERSION_MINOR)
                                {
                                if (!(s->options & SSL_OP_NO_TLSv1))
@@ -415,7 +420,9 @@ int ssl23_get_client_hello(SSL *s)
                j=ssl23_read_bytes(s,n+2);
                if (j <= 0) return(j);
 
-               ssl3_finish_mac(s,&(s->packet[2]),s->packet_length-2);
+               ssl3_finish_mac(s, s->packet+2, s->packet_length-2);
+               if (s->msg_callback)
+                       s->msg_callback(0, SSL2_VERSION, 0, s->packet+2, s->packet_length-2, s, s->msg_callback_arg); /* CLIENT-HELLO */
 
                p=s->packet;
                p+=5;
@@ -466,7 +473,7 @@ int ssl23_get_client_hello(SSL *s)
                *(d++)=1;
                *(d++)=0;
                
-               i=(d-(unsigned char *)s->init_buf->data);
+               i = (d-(unsigned char *)s->init_buf->data) - 4;
                l2n3((long)i, d_len);
 
                /* get the data reused from the init_buf */