Blame SOURCES/openssl-pkcs11-0.4.10-openssl3.patch

5e8a1a
From 433947efff5712a6a3960c53e8b99e4fe123aace Mon Sep 17 00:00:00 2001
5e8a1a
From: Jakub Jelen <jjelen@redhat.com>
5e8a1a
Date: Wed, 19 May 2021 14:23:27 +0200
5e8a1a
Subject: [PATCH] Do not modify EC/RSA structures after assigning them to
5e8a1a
 EVP_PKEY
5e8a1a
5e8a1a
This was causing OpenSSL 3.0 to fail detect our RSA/EC methods and
5e8a1a
failing the tests ({ec,rsa}-testfork.softhsm).
5e8a1a
5e8a1a
The OpenSSL issue:
5e8a1a
https://github.com/openssl/openssl/issues/15350
5e8a1a
---
5e8a1a
 src/p11_ec.c  | 2 +-
5e8a1a
 src/p11_rsa.c | 4 ++--
5e8a1a
 2 files changed, 3 insertions(+), 3 deletions(-)
5e8a1a
5e8a1a
diff --git a/src/p11_ec.c b/src/p11_ec.c
5e8a1a
index 294cbad..9c5ee0f 100644
5e8a1a
--- a/src/p11_ec.c
5e8a1a
+++ b/src/p11_ec.c
5e8a1a
@@ -365,7 +365,6 @@ static EVP_PKEY *pkcs11_get_evp_key_ec(PKCS11_KEY *key)
5e8a1a
 		EC_KEY_free(ec);
5e8a1a
 		return NULL;
5e8a1a
 	}
5e8a1a
-	EVP_PKEY_set1_EC_KEY(pk, ec); /* Also increments the ec ref count */
5e8a1a
 
5e8a1a
 	if (key->isPrivate) {
5e8a1a
 #if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
5e8a1a
@@ -379,6 +378,7 @@ static EVP_PKEY *pkcs11_get_evp_key_ec(PKCS11_KEY *key)
5e8a1a
 	 * unless the key has the "sensitive" attribute set */
5e8a1a
 
5e8a1a
 	pkcs11_set_ex_data_ec(ec, key);
5e8a1a
+	EVP_PKEY_set1_EC_KEY(pk, ec); /* Also increments the ec ref count */
5e8a1a
 	EC_KEY_free(ec); /* Drops our reference to it */
5e8a1a
 	return pk;
5e8a1a
 }
5e8a1a
diff --git a/src/p11_rsa.c b/src/p11_rsa.c
5e8a1a
index f2f3eb3..183cce2 100644
5e8a1a
--- a/src/p11_rsa.c
5e8a1a
+++ b/src/p11_rsa.c
5e8a1a
@@ -286,8 +286,6 @@ static EVP_PKEY *pkcs11_get_evp_key_rsa(PKCS11_KEY *key)
5e8a1a
 		RSA_free(rsa);
5e8a1a
 		return NULL;
5e8a1a
 	}
5e8a1a
-	EVP_PKEY_set1_RSA(pk, rsa); /* Also increments the rsa ref count */
5e8a1a
-
5e8a1a
 	if (key->isPrivate) {
5e8a1a
 		RSA_set_method(rsa, PKCS11_get_rsa_method());
5e8a1a
 #if OPENSSL_VERSION_NUMBER >= 0x10100005L && !defined(LIBRESSL_VERSION_NUMBER)
5e8a1a
@@ -304,6 +302,8 @@ static EVP_PKEY *pkcs11_get_evp_key_rsa(PKCS11_KEY *key)
5e8a1a
 	rsa->flags |= RSA_FLAG_SIGN_VER;
5e8a1a
 #endif
5e8a1a
 	pkcs11_set_ex_data_rsa(rsa, key);
5e8a1a
+
5e8a1a
+	EVP_PKEY_set1_RSA(pk, rsa); /* Also increments the rsa ref count */
5e8a1a
 	RSA_free(rsa); /* Drops our reference to it */
5e8a1a
 	return pk;
5e8a1a
 }
5e8a1a