File openssl-CVE-2015-3197.patch of Package openssl

commit 38015f7f9bb5cc3e8bcaf4a091082e5540af858d
Author: Viktor Dukhovni <openssl-users@dukhovni.org>
Date:   Wed Dec 30 22:44:51 2015 -0500

    Better SSLv2 cipher-suite enforcement
    
    Based on patch by: Nimrod Aviram <nimrod.aviram@gmail.com>
    
    Reviewed-by: Tim Hudson <tjh@openssl.org>

Index: openssl-1.0.1k/ssl/s2_srvr.c
===================================================================
--- openssl-1.0.1k.orig/ssl/s2_srvr.c	2016-01-28 15:29:26.391648704 +0100
+++ openssl-1.0.1k/ssl/s2_srvr.c	2016-01-28 15:38:15.819172856 +0100
@@ -400,7 +400,7 @@ static int get_client_master_key(SSL *s)
 			}
 
 		cp=ssl2_get_cipher_by_char(p);
-		if (cp == NULL)
+		if (cp == NULL || sk_SSL_CIPHER_find(s->session->ciphers, cp) < 0)
 			{
 			ssl2_return_error(s,SSL2_PE_NO_CIPHER);
 			SSLerr(SSL_F_GET_CLIENT_MASTER_KEY, SSL_R_NO_CIPHER_MATCH);
@@ -698,9 +698,13 @@ static int get_client_hello(SSL *s)
 		    prio = cs;
 		    allow = cl;
 		    }
+
+		/* Generate list of SSLv2 ciphers shared between client and server */
 		for (z=0; z<sk_SSL_CIPHER_num(prio); z++)
 			{
-			if (sk_SSL_CIPHER_find(allow,sk_SSL_CIPHER_value(prio,z)) < 0)
+			const SSL_CIPHER *cp = sk_SSL_CIPHER_value(prio, z);
+			if ((cp->algorithm_ssl & SSL_SSLV2) == 0 ||
+			     sk_SSL_CIPHER_find(allow, cp) < 0)
 				{
 				(void)sk_SSL_CIPHER_delete(prio,z);
 				z--;
@@ -711,6 +715,14 @@ static int get_client_hello(SSL *s)
 		    sk_SSL_CIPHER_free(s->session->ciphers);
 		    s->session->ciphers = prio;
 		    }
+
+        /* Make sure we have at least one cipher in common */
+        if (sk_SSL_CIPHER_num(s->session->ciphers) == 0) {
+            ssl2_return_error(s, SSL2_PE_NO_CIPHER);
+            SSLerr(SSL_F_GET_CLIENT_HELLO, SSL_R_NO_CIPHER_MATCH);
+            return -1;
+        }
+
 		/* s->session->ciphers should now have a list of
 		 * ciphers that are on both the client and server.
 		 * This list is ordered by the order the client sent