Ignore zero length constructed segments.
[openssl.git] / ssl / s3_srvr.c
index 18030842b89bf91ef6dc8284dcc6dd72cdb9faf3..44b9c9cdac35d70c84c7f64367db37b0e385fa5b 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -281,6 +281,7 @@ int ssl3_accept(SSL *s)
                        s->shutdown=0;
                        ret=ssl3_get_client_hello(s);
                        if (ret <= 0) goto end;
+                       
                        s->new_session = 2;
                        s->state=SSL3_ST_SW_SRVR_HELLO_A;
                        s->init_num=0;
@@ -895,6 +896,23 @@ int ssl3_get_client_hello(SSL *s)
                goto f_err;
                }
 
+#ifndef OPENSSL_NO_TLSEXT
+       /* TLS extensions*/
+       if (s->version > SSL3_VERSION)
+               {
+               if (!ssl_parse_clienthello_tlsext(s,&p,d,n, &al))
+                       {
+                       /* 'al' set by ssl_parse_clienthello_tlsext */
+                       SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_PARSE_TLS_EXT);
+                       goto f_err;
+                       }
+               }
+               if (ssl_check_tlsext(s,1) <= 0) {
+                       SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_CLIENTHELLO_TLS_EXT);
+                       goto err;
+               }
+#endif
+
        /* Worst case, we will use the NULL compression, but if we have other
         * options, we will now look for them.  We have i-1 compression
         * algorithms from the client, starting at q. */
@@ -926,23 +944,6 @@ int ssl3_get_client_hello(SSL *s)
                }
 #endif
 
-       /* TLS does not mind if there is extra stuff */
-#if 0   /* SSL 3.0 does not mind either, so we should disable this test
-         * (was enabled in 0.9.6d through 0.9.6j and 0.9.7 through 0.9.7b,
-         * in earlier SSLeay/OpenSSL releases this test existed but was buggy) */
-       if (s->version == SSL3_VERSION)
-               {
-               if (p < (d+n))
-                       {
-                       /* wrong number of bytes,
-                        * there could be more to follow */
-                       al=SSL_AD_DECODE_ERROR;
-                       SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
-                       goto f_err;
-                       }
-               }
-#endif
-
        /* Given s->session->ciphers and SSL_get_ciphers, we must
         * pick a cipher */
 
@@ -1086,6 +1087,13 @@ int ssl3_send_server_hello(SSL *s)
                else
                        *(p++)=s->s3->tmp.new_compression->id;
 #endif
+#ifndef OPENSSL_NO_TLSEXT
+               if ((p = ssl_add_serverhello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL)
+                       {
+                       SSLerr(SSL_F_SSL3_SEND_SERVER_HELLO,ERR_R_INTERNAL_ERROR);
+                       return -1;
+                       }
+#endif
 
                /* do the header */
                l=(p-d);
@@ -2102,8 +2110,13 @@ int ssl3_get_client_key_exchange(SSL *s)
                                goto f_err;
                                }
 
-                       EC_POINT_copy(clnt_ecpoint,
-                           EC_KEY_get0_public_key(clnt_pub_pkey->pkey.ec));
+                       if (EC_POINT_copy(clnt_ecpoint,
+                           EC_KEY_get0_public_key(clnt_pub_pkey->pkey.ec)) == 0)
+                               {
+                               SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
+                                       ERR_R_EC_LIB);
+                               goto err;
+                               }
                         ret = 2; /* Skip certificate verify processing */
                         }
                 else