chantra / rpms / tpm2-tss

Forked from rpms/tpm2-tss 2 years ago
Clone

Blame SOURCES/0011-Drop-support-for-OpenSSL-1.1.0.patch

a23473
From df8495b73df96f55425970e76c613b8a0950bf0c Mon Sep 17 00:00:00 2001
a23473
From: Petr Gotthard <petr.gotthard@centrum.cz>
a23473
Date: Sun, 18 Jul 2021 20:21:01 +0200
a23473
Subject: Drop support for OpenSSL < 1.1.0
a23473
MIME-Version: 1.0
a23473
Content-Type: text/plain; charset=UTF-8
a23473
Content-Transfer-Encoding: 8bit
a23473
a23473
Delete code written to support OpenSSL < 1.1.0
a23473
a23473
Delete functions that have no effect in OpenSSL >= 1.1.0
a23473
 - ENGINE_load_builtin_engines()
a23473
 - OpenSSL_add_all_algorithms()
a23473
 - ERR_load_crypto_strings()
a23473
 - EC_KEY_set_asn1_flag(ecKey, OPENSSL_EC_NAMED_CURVE)
a23473
a23473
Switch AppVeyor to use pre-built OpenSSL 1.1.0
a23473
a23473
Signed-off-by: Petr Gotthard <petr.gotthard@centrum.cz>
a23473
---
a23473
 src/tss2-esys/esys_crypto_ossl.c | 19 ----------------
a23473
 src/tss2-esys/tss2-esys.vcxproj  | 16 +++++++-------
a23473
 src/tss2-fapi/fapi_crypto.c      | 37 --------------------------------
a23473
 test/helper/tpm_getek.c          | 11 ----------
a23473
 test/helper/tpm_getek_ecc.c      |  9 --------
a23473
 5 files changed, 8 insertions(+), 84 deletions(-)
a23473
a23473
diff --git a/src/tss2-esys/esys_crypto_ossl.c b/src/tss2-esys/esys_crypto_ossl.c
a23473
index 2eb0dfcb..a6259346 100644
a23473
--- a/src/tss2-esys/esys_crypto_ossl.c
a23473
+++ b/src/tss2-esys/esys_crypto_ossl.c
a23473
@@ -525,11 +525,7 @@ iesys_cryptossl_random2b(TPM2B_NONCE * nonce, size_t num_bytes)
a23473
         nonce->size = num_bytes;
a23473
     }
a23473
 
a23473
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
a23473
     RAND_set_rand_method(RAND_OpenSSL());
a23473
-#else
a23473
-    RAND_set_rand_method(RAND_SSLeay());
a23473
-#endif
a23473
     if (1 != RAND_bytes(&nonce->buffer[0], nonce->size)) {
a23473
         RAND_set_rand_method(rand_save);
a23473
         return_error(TSS2_ESYS_RC_GENERAL_FAILURE,
a23473
@@ -563,11 +559,7 @@ iesys_cryptossl_pk_encrypt(TPM2B_PUBLIC * pub_tpm_key,
a23473
                            size_t * out_size, const char *label)
a23473
 {
a23473
     const RAND_METHOD *rand_save = RAND_get_rand_method();
a23473
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
a23473
     RAND_set_rand_method(RAND_OpenSSL());
a23473
-#else
a23473
-    RAND_set_rand_method(RAND_SSLeay());
a23473
-#endif
a23473
 
a23473
     TSS2_RC r = TSS2_RC_SUCCESS;
a23473
     const EVP_MD * hashAlg = NULL;
a23473
@@ -630,14 +622,6 @@ iesys_cryptossl_pk_encrypt(TPM2B_PUBLIC * pub_tpm_key,
a23473
         goto_error(r, TSS2_ESYS_RC_GENERAL_FAILURE,
a23473
                    "Could not create evp key.", cleanup);
a23473
     }
a23473
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
a23473
-    if (!BN_bin2bn(pub_tpm_key->publicArea.unique.rsa.buffer,
a23473
-                           pub_tpm_key->publicArea.unique.rsa.size,
a23473
-                           rsa_key->n)) {
a23473
-        goto_error(r, TSS2_ESYS_RC_GENERAL_FAILURE,
a23473
-                   "Could not create rsa n.", cleanup);
a23473
-    }
a23473
-#else
a23473
     BIGNUM *n = NULL;
a23473
     if (!(n = BN_bin2bn(pub_tpm_key->publicArea.unique.rsa.buffer,
a23473
                         pub_tpm_key->publicArea.unique.rsa.size,
a23473
@@ -650,7 +634,6 @@ iesys_cryptossl_pk_encrypt(TPM2B_PUBLIC * pub_tpm_key,
a23473
         goto_error(r, TSS2_ESYS_RC_GENERAL_FAILURE,
a23473
                    "Could not set rsa n.", cleanup);
a23473
     }
a23473
-#endif
a23473
 
a23473
     if (1 != EVP_PKEY_set1_RSA(evp_rsa_key, rsa_key)) {
a23473
         goto_error(r, TSS2_ESYS_RC_GENERAL_FAILURE,
a23473
@@ -1129,7 +1112,5 @@ iesys_cryptossl_sym_aes_decrypt(uint8_t * key,
a23473
  */
a23473
 TSS2_RC
a23473
 iesys_cryptossl_init() {
a23473
-    ENGINE_load_builtin_engines();
a23473
-    OpenSSL_add_all_algorithms();
a23473
     return TSS2_RC_SUCCESS;
a23473
 }
a23473
diff --git a/src/tss2-esys/tss2-esys.vcxproj b/src/tss2-esys/tss2-esys.vcxproj
a23473
index b75424aa..b2aa67ce 100644
a23473
--- a/src/tss2-esys/tss2-esys.vcxproj
a23473
+++ b/src/tss2-esys/tss2-esys.vcxproj
a23473
@@ -69,13 +69,13 @@
a23473
       <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
a23473
       <WarningLevel>Level3</WarningLevel>
a23473
       <Optimization>Disabled</Optimization>
a23473
-      <AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)\src;$(SolutionDir)\include\tss2;$(SolutionDir)\src\tss2-mu;$(SolutionDir)\src\tss2-sys;$(SolutionDir)\src\tss2-esys;C:\OpenSSL-Win32\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
a23473
+      <AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)\src;$(SolutionDir)\include\tss2;$(SolutionDir)\src\tss2-mu;$(SolutionDir)\src\tss2-sys;$(SolutionDir)\src\tss2-esys;C:\OpenSSL-v11-Win32\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
a23473
     </ClCompile>
a23473
     <Link>
a23473
       <TargetMachine>MachineX86</TargetMachine>
a23473
       <GenerateDebugInformation>true</GenerateDebugInformation>
a23473
       <SubSystem>Windows</SubSystem>
a23473
-      <AdditionalDependencies>$(OutDir)\tss2-mu.lib;$(OutDir)\tss2-sys.lib;$(OutDir)\tss2-tctildr.lib;C:\OpenSSL-Win32\lib\libeay32.lib;C:\OpenSSL-Win32\lib\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
a23473
+      <AdditionalDependencies>$(OutDir)\tss2-mu.lib;$(OutDir)\tss2-sys.lib;$(OutDir)\tss2-tctildr.lib;C:\OpenSSL-v11-Win32\lib\libcrypto.lib;C:\OpenSSL-v11-Win32\lib\libcrypto.lib;%(AdditionalDependencies)</AdditionalDependencies>
a23473
       <ModuleDefinitionFile>$(SolutionDir)\lib\tss2-esys.def</ModuleDefinitionFile>
a23473
     </Link>
a23473
   </ItemDefinitionGroup>
a23473
@@ -84,7 +84,7 @@
a23473
       <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;TSS2ESYS_EXPORTS;MAXLOGLEVEL=6;strtok_r=strtok_s;OSSL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
a23473
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
a23473
       <WarningLevel>Level3</WarningLevel>
a23473
-      <AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)\src;$(SolutionDir)\include\tss2;$(SolutionDir)\src\tss2-mu;$(SolutionDir)\src\tss2-sys;$(SolutionDir)\src\tss2-esys;C:\OpenSSL-Win32\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
a23473
+      <AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)\src;$(SolutionDir)\include\tss2;$(SolutionDir)\src\tss2-mu;$(SolutionDir)\src\tss2-sys;$(SolutionDir)\src\tss2-esys;C:\OpenSSL-v11-Win32\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
a23473
     </ClCompile>
a23473
     <Link>
a23473
       <TargetMachine>MachineX86</TargetMachine>
a23473
@@ -92,27 +92,27 @@
a23473
       <SubSystem>Windows</SubSystem>
a23473
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
a23473
       <OptimizeReferences>true</OptimizeReferences>
a23473
-      <AdditionalDependencies>$(OutDir)\tss2-mu.lib;$(OutDir)\tss2-sys.lib;$(OutDir)\tss2-tctildr.lib;C:\OpenSSL-Win32\lib\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
a23473
+      <AdditionalDependencies>$(OutDir)\tss2-mu.lib;$(OutDir)\tss2-sys.lib;$(OutDir)\tss2-tctildr.lib;C:\OpenSSL-v11-Win32\lib\libcrypto.lib;%(AdditionalDependencies)</AdditionalDependencies>
a23473
       <ModuleDefinitionFile>$(SolutionDir)\lib\tss2-esys.def</ModuleDefinitionFile>
a23473
     </Link>
a23473
   </ItemDefinitionGroup>
a23473
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
a23473
     <ClCompile>
a23473
-      <AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)\src;$(SolutionDir)\include\tss2;$(SolutionDir)\src\tss2-mu;$(SolutionDir)\src\tss2-sys;$(SolutionDir)\src\tss2-esys;C:\OpenSSL-Win64\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
a23473
+      <AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)\src;$(SolutionDir)\include\tss2;$(SolutionDir)\src\tss2-mu;$(SolutionDir)\src\tss2-sys;$(SolutionDir)\src\tss2-esys;C:\OpenSSL-v11-Win64\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
a23473
       <PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;TSS2ESYS_EXPORTS;MAXLOGLEVEL=6;strtok_r=strtok_s;OSSL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
a23473
     </ClCompile>
a23473
     <Link>
a23473
-      <AdditionalDependencies>$(OutDir)\tss2-mu.lib;$(OutDir)\tss2-sys.lib;$(OutDir)\tss2-tctildr.lib;C:\OpenSSL-Win64\lib\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
a23473
+      <AdditionalDependencies>$(OutDir)\tss2-mu.lib;$(OutDir)\tss2-sys.lib;$(OutDir)\tss2-tctildr.lib;C:\OpenSSL-v11-Win64\lib\libcrypto.lib;%(AdditionalDependencies)</AdditionalDependencies>
a23473
       <ModuleDefinitionFile>$(SolutionDir)\lib\tss2-esys.def</ModuleDefinitionFile>
a23473
     </Link>
a23473
   </ItemDefinitionGroup>
a23473
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
a23473
     <ClCompile>
a23473
-      <AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)\src;$(SolutionDir)\include\tss2;$(SolutionDir)\src\tss2-mu;$(SolutionDir)\src\tss2-sys;$(SolutionDir)\src\tss2-esys;C:\OpenSSL-Win64\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
a23473
+      <AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)\src;$(SolutionDir)\include\tss2;$(SolutionDir)\src\tss2-mu;$(SolutionDir)\src\tss2-sys;$(SolutionDir)\src\tss2-esys;C:\OpenSSL-v11-Win64\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
a23473
       <PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;TSS2ESYS_EXPORTS;MAXLOGLEVEL=6;strtok_r=strtok_s;OSSL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
a23473
     </ClCompile>
a23473
     <Link>
a23473
-      <AdditionalDependencies>$(OutDir)\tss2-mu.lib;$(OutDir)\tss2-sys.lib;$(OutDir)\tss2-tctildr.lib;C:\OpenSSL-Win64\lib\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
a23473
+      <AdditionalDependencies>$(OutDir)\tss2-mu.lib;$(OutDir)\tss2-sys.lib;$(OutDir)\tss2-tctildr.lib;C:\OpenSSL-v11-Win64\lib\libcrypto.lib;%(AdditionalDependencies)</AdditionalDependencies>
a23473
       <ModuleDefinitionFile>$(SolutionDir)\lib\tss2-esys.def</ModuleDefinitionFile>
a23473
     </Link>
a23473
   </ItemDefinitionGroup>
a23473
diff --git a/src/tss2-fapi/fapi_crypto.c b/src/tss2-fapi/fapi_crypto.c
a23473
index f5b3d272..c97b0a1d 100644
a23473
--- a/src/tss2-fapi/fapi_crypto.c
a23473
+++ b/src/tss2-fapi/fapi_crypto.c
a23473
@@ -333,12 +333,7 @@ ifapi_tpm_ecc_sig_to_der(
a23473
                     tpmSignature->signature.ecdsa.signatureR.size, NULL);
a23473
     goto_if_null(bnr, "Out of memory", TSS2_FAPI_RC_MEMORY, cleanup);
a23473
 
a23473
-#if OPENSSL_VERSION_NUMBER < 0x10100000
a23473
-    ecdsaSignature->s = bns;
a23473
-    ecdsaSignature->r = bnr;
a23473
-#else /* OPENSSL_VERSION_NUMBER < 0x10100000 */
a23473
     ECDSA_SIG_set0(ecdsaSignature, bnr, bns);
a23473
-#endif /* OPENSSL_VERSION_NUMBER < 0x10100000 */
a23473
 
a23473
     osslRC = i2d_ECDSA_SIG(ecdsaSignature, NULL);
a23473
     if (osslRC == -1) {
a23473
@@ -424,20 +419,9 @@ ossl_rsa_pub_from_tpm(const TPM2B_PUBLIC *tpmPublicKey, EVP_PKEY *evpPublicKey)
a23473
                    "Could not set exponent.", error_cleanup);
a23473
     }
a23473
 
a23473
-#if OPENSSL_VERSION_NUMBER < 0x10100000
a23473
-    rsa->e = e;
a23473
-    rsa->n = n;
a23473
-    rsa->d = d;
a23473
-    rsa->p = p;
a23473
-    rsa->q = q;
a23473
-    rsa->dmp1 = dmp1;
a23473
-    rsa->dmq1 = dmq1;
a23473
-    rsa->iqmp = iqmp;
a23473
-#else /* OPENSSL_VERSION_NUMBER < 0x10100000 */
a23473
     RSA_set0_key(rsa, n, e, d);
a23473
     RSA_set0_factors(rsa, p, q);
a23473
     RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp);
a23473
-#endif /* OPENSSL_VERSION_NUMBER < 0x10100000 */
a23473
 
a23473
     /* Assign the parameters to the key */
a23473
     if (!EVP_PKEY_assign_RSA(evpPublicKey, rsa)) {
a23473
@@ -541,8 +525,6 @@ ossl_ecc_pub_from_tpm(const TPM2B_PUBLIC *tpmPublicKey, EVP_PKEY *evpPublicKey)
a23473
         goto_error(r, TSS2_FAPI_RC_GENERAL_FAILURE, "Assign ecc key",
a23473
                    error_cleanup);
a23473
     }
a23473
-    /* Needed for older OSSL versions. */
a23473
-    EC_KEY_set_asn1_flag(ecKey, OPENSSL_EC_NAMED_CURVE);
a23473
     OSSL_FREE(y, BN);
a23473
     OSSL_FREE(x, BN);
a23473
     return TSS2_RC_SUCCESS;
a23473
@@ -654,24 +636,14 @@ ifapi_ecc_der_sig_to_tpm(
a23473
 
a23473
     /* Initialize the ECDSA signature components */
a23473
     ECDSA_SIG *ecdsaSignature = NULL;
a23473
-#if OPENSSL_VERSION_NUMBER < 0x10100000
a23473
-    BIGNUM *bnr;
a23473
-    BIGNUM *bns;
a23473
-#else /* OPENSSL_VERSION_NUMBER < 0x10100000 */
a23473
     const BIGNUM *bnr;
a23473
     const BIGNUM *bns;
a23473
-#endif /* OPENSSL_VERSION_NUMBER < 0x10100000 */
a23473
 
a23473
     d2i_ECDSA_SIG(&ecdsaSignature, &signature, signatureSize);
a23473
     return_if_null(ecdsaSignature, "Invalid DER signature",
a23473
                    TSS2_FAPI_RC_GENERAL_FAILURE);
a23473
 
a23473
-#if OPENSSL_VERSION_NUMBER < 0x10100000
a23473
-    bns = ecdsaSignature->s;
a23473
-    bnr = ecdsaSignature->r;
a23473
-#else /* OPENSSL_VERSION_NUMBER < 0x10100000 */
a23473
     ECDSA_SIG_get0(ecdsaSignature, &bnr, &bns;;
a23473
-#endif /* OPENSSL_VERSION_NUMBER < 0x10100000 */
a23473
 
a23473
     /* Writing them to the TPM format signature */
a23473
     tpmSignature->signature.ecdsa.hash = hashAlgorithm;
a23473
@@ -933,12 +905,7 @@ get_rsa_tpm2b_public_from_evp(
a23473
     const BIGNUM *e = NULL, *n = NULL;
a23473
     int rsaKeySize = RSA_size(rsaKey);
a23473
 
a23473
-#if OPENSSL_VERSION_NUMBER < 0x10100000
a23473
-    e = rsaKey->e;
a23473
-    n = rsaKey->n;
a23473
-#else /* OPENSSL_VERSION_NUMBER < 0x10100000 */
a23473
     RSA_get0_key(rsaKey, &n, &e, NULL);
a23473
-#endif /* OPENSSL_VERSION_NUMBER < 0x10100000 */
a23473
     tpmPublic->publicArea.unique.rsa.size = rsaKeySize;
a23473
     if (1 != ifapi_bn2binpad(n, &tpmPublic->publicArea.unique.rsa.buffer[0],
a23473
                              rsaKeySize)) {
a23473
@@ -1650,8 +1617,6 @@ get_crl_from_cert(X509 *cert, X509_CRL **crl)
a23473
         goto_error(r, TSS2_FAPI_RC_NO_CERT, "Get crl.", cleanup);
a23473
     }
a23473
 
a23473
-    OpenSSL_add_all_algorithms();
a23473
-
a23473
     unsigned const char* tmp_ptr1 = crl_buffer;
a23473
     unsigned const char** tmp_ptr2 = &tmp_ptr1;
a23473
 
a23473
@@ -1935,7 +1900,6 @@ ifapi_verify_ek_cert(
a23473
                       r, TSS2_FAPI_RC_BAD_VALUE, cleanup);
a23473
     } else {
a23473
         /* Get uri for ek intermediate certificate. */
a23473
-        OpenSSL_add_all_algorithms();
a23473
         info = X509_get_ext_d2i(ek_cert, NID_info_access, NULL, NULL);
a23473
 
a23473
         for (i = 0; i < sk_ACCESS_DESCRIPTION_num(info); i++) {
a23473
@@ -1955,7 +1919,6 @@ ifapi_verify_ek_cert(
a23473
         goto_if_null2(cert_buffer, "No certificate downloaded", r,
a23473
                       TSS2_FAPI_RC_NO_CERT, cleanup);
a23473
 
a23473
-        OpenSSL_add_all_algorithms();
a23473
         intermed_cert = get_cert_from_buffer(cert_buffer, cert_buffer_size);
a23473
 
a23473
         SAFE_FREE(cert_buffer);
a23473
diff --git a/test/helper/tpm_getek.c b/test/helper/tpm_getek.c
a23473
index 21be0f46..c6a8e906 100644
a23473
--- a/test/helper/tpm_getek.c
a23473
+++ b/test/helper/tpm_getek.c
a23473
@@ -147,20 +147,9 @@ main (int argc, char *argv[])
a23473
         exp = out_public.publicArea.parameters.rsaDetail.exponent;
a23473
     BN_set_word(e, exp);
a23473
 
a23473
-#if OPENSSL_VERSION_NUMBER < 0x10100000
a23473
-    rsa->e = e;
a23473
-    rsa->n = n;
a23473
-    rsa->d = d;
a23473
-    rsa->p = p;
a23473
-    rsa->q = q;
a23473
-    rsa->dmp1 = dmp1;
a23473
-    rsa->dmq1 = dmq1;
a23473
-    rsa->iqmp = iqmp;
a23473
-#else /* OPENSSL_VERSION_NUMBER < 0x10100000 */
a23473
     RSA_set0_key(rsa, n, e, d);
a23473
     RSA_set0_factors(rsa, p, q);
a23473
     RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp);
a23473
-#endif /* OPENSSL_VERSION_NUMBER < 0x10100000 */
a23473
 
a23473
     EVP_PKEY_assign_RSA(evp, rsa);
a23473
 
a23473
diff --git a/test/helper/tpm_getek_ecc.c b/test/helper/tpm_getek_ecc.c
a23473
index 0419f47a..75165fdd 100644
a23473
--- a/test/helper/tpm_getek_ecc.c
a23473
+++ b/test/helper/tpm_getek_ecc.c
a23473
@@ -128,14 +128,6 @@ main (int argc, char *argv[])
a23473
     /* Convert the key from out_public to PEM */
a23473
 
a23473
     EVP_PKEY *evp = EVP_PKEY_new();
a23473
-
a23473
-    OpenSSL_add_all_algorithms();
a23473
-
a23473
-    OpenSSL_add_all_algorithms();
a23473
-
a23473
-    ERR_load_crypto_strings();
a23473
-
a23473
-
a23473
     EC_KEY *ecc_key = EC_KEY_new();
a23473
     BIGNUM *x = NULL, *y = NULL;
a23473
     BIO *bio;
a23473
@@ -159,7 +151,6 @@ main (int argc, char *argv[])
a23473
     if (!EC_KEY_set_group(ecc_key, ecgroup))
a23473
         exit(1);
a23473
 
a23473
-    EC_KEY_set_asn1_flag(ecc_key, OPENSSL_EC_NAMED_CURVE);
a23473
     EC_GROUP_free(ecgroup);
a23473
 
a23473
     /* Set the ECC parameters in the OpenSSL key */
a23473
-- 
a23473
2.26.3
a23473