Add and use a constant-time memcmp.
[oweals/openssl.git] / ssl / s3_clnt.c
index 0329da2df9545ec30bd51040b21eb97e1f306cc9..61b0cdc204f108ee95f694dd25607b99bd5ae003 100644 (file)
@@ -1225,6 +1225,15 @@ int ssl3_get_server_certificate(SSL *s)
 
        if (need_cert)
                {
+               int exp_idx = ssl_cipher_get_cert_index(s->s3->tmp.new_cipher);
+               if (exp_idx >= 0 && i != exp_idx)
+                       {
+                       x=NULL;
+                       al=SSL_AD_ILLEGAL_PARAMETER;
+                       SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,
+                               SSL_R_WRONG_CERTIFICATE_TYPE);
+                       goto f_err;
+                       }
                sc->peer_cert_type=i;
                CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
                /* Why would the following ever happen?
@@ -1267,7 +1276,6 @@ int ssl3_get_server_certificate(SSL *s)
 
 #endif
        ret=1;
-
        if (0)
                {
 f_err: