Blame SOURCES/0005-openssl-Remove-support-for-OpenSSL-1.1.0.patch

05e1a9
From 61989b4c0a2da337a5c8df56e68c83e73259ed75 Mon Sep 17 00:00:00 2001
05e1a9
From: Petr Gotthard <petr.gotthard@centrum.cz>
05e1a9
Date: Sat, 7 Aug 2021 11:39:52 +0200
05e1a9
Subject: [PATCH 04/17] openssl: Remove support for OpenSSL < 1.1.0
05e1a9
05e1a9
The OpenSSL 1.0.2 is no longer maintained. Supporting an EOL crypto
05e1a9
library is not a good idea.
05e1a9
05e1a9
 - Compared to the upstream commit 1e439d85 changes related to functions
05e1a9
   and features not previously backported were ommited.
05e1a9
05e1a9
Signed-off-by: Petr Gotthard <petr.gotthard@centrum.cz>
05e1a9
---
05e1a9
 configure.ac       |  2 +-
05e1a9
 doc/CHANGELOG.md   |  5 +++
05e1a9
 doc/INSTALL.md     |  2 +-
05e1a9
 doc/RELEASE.md     |  7 ----
05e1a9
 lib/tpm2_openssl.c | 87 ----------------------------------------------
05e1a9
 lib/tpm2_openssl.h | 10 ------
05e1a9
 6 files changed, 7 insertions(+), 106 deletions(-)
05e1a9
05e1a9
diff --git a/configure.ac b/configure.ac
05e1a9
index a3988e15..9561fa86 100644
05e1a9
--- a/configure.ac
05e1a9
+++ b/configure.ac
05e1a9
@@ -58,7 +58,7 @@ PKG_CHECK_MODULES([TSS2_TCTILDR], [tss2-tctildr])
05e1a9
 PKG_CHECK_MODULES([TSS2_MU], [tss2-mu])
05e1a9
 PKG_CHECK_MODULES([TSS2_RC], [tss2-rc])
05e1a9
 PKG_CHECK_MODULES([TSS2_SYS], [tss2-sys])
05e1a9
-PKG_CHECK_MODULES([CRYPTO], [libcrypto >= 1.0.2g])
05e1a9
+PKG_CHECK_MODULES([CRYPTO], [libcrypto >= 1.1.0])
05e1a9
 PKG_CHECK_MODULES([CURL], [libcurl])
05e1a9
 PKG_CHECK_MODULES([UUID], [uuid])
05e1a9
 
05e1a9
diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md
05e1a9
index 87573fd7..b244dfee 100644
05e1a9
--- a/doc/CHANGELOG.md
05e1a9
+++ b/doc/CHANGELOG.md
05e1a9
@@ -1,5 +1,10 @@
05e1a9
 ## Changelog
05e1a9
 
05e1a9
+### next
05e1a9
+
05e1a9
+  * openssl:
05e1a9
+      - Dropped support for OpenSSL < 1.1.0
05e1a9
+
05e1a9
 ### 5.0 - 2020-11-16
05e1a9
 
05e1a9
 #### Non Backwards Compatible Changes
05e1a9
diff --git a/doc/INSTALL.md b/doc/INSTALL.md
05e1a9
index b23b8d61..ab160581 100644
05e1a9
--- a/doc/INSTALL.md
05e1a9
+++ b/doc/INSTALL.md
05e1a9
@@ -19,7 +19,7 @@ To build and install the tpm2-tools software the following software is required:
05e1a9
   * C compiler
05e1a9
   * C Library Development Libraries and Header Files (for pthreads headers)
05e1a9
   * ESAPI - TPM2.0 TSS ESAPI library (tss2-esys) and header files
05e1a9
-  * OpenSSL libcrypto library and header files
05e1a9
+  * OpenSSL libcrypto library and header files (version >= 1.1.0)
05e1a9
   * Curl library and header files
05e1a9
   * Universally Unique ID library (UUID)
05e1a9
 
05e1a9
diff --git a/doc/RELEASE.md b/doc/RELEASE.md
05e1a9
index e2c72a67..8769b57d 100644
05e1a9
--- a/doc/RELEASE.md
05e1a9
+++ b/doc/RELEASE.md
05e1a9
@@ -23,13 +23,6 @@ the next release.
05e1a9
 - [3.0.X](https://github.com/tpm2-software/tpm2-tools/tree/3.0.X): EOL after
05e1a9
 3.2.1 release.
05e1a9
 
05e1a9
-## OpenSSL
05e1a9
-
05e1a9
-tpm2-tools relies heavily on OpenSSL. OpenSSL will be EOL'ing 1.0.2 at the end
05e1a9
-of 2019, see: https://www.openssl.org/blog/blog/2018/05/18/new-lts/. When this
05e1a9
-occurs, we will remove OSSL 1.0.2 support from the tpm2-tools repository as
05e1a9
-supporting an EOL crypto library is not a good idea.
05e1a9
-
05e1a9
 # Release Information
05e1a9
 
05e1a9
 Releases shall be tagged following semantic version guidelines found at:
05e1a9
diff --git a/lib/tpm2_openssl.c b/lib/tpm2_openssl.c
05e1a9
index e769d6df..877d2764 100644
05e1a9
--- a/lib/tpm2_openssl.c
05e1a9
+++ b/lib/tpm2_openssl.c
05e1a9
@@ -72,58 +72,6 @@ const EVP_MD *tpm2_openssl_halg_from_tpmhalg(TPMI_ALG_HASH algorithm) {
05e1a9
     /* no return, not possible */
05e1a9
 }
05e1a9
 
05e1a9
-#if defined(LIB_TPM2_OPENSSL_OPENSSL_PRE11)
05e1a9
-int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) {
05e1a9
-
05e1a9
-    if ((r->n == NULL && n == NULL) || (r->e == NULL && e == NULL)) {
05e1a9
-        return 0;
05e1a9
-    }
05e1a9
-
05e1a9
-    if (n != NULL) {
05e1a9
-        BN_free(r->n);
05e1a9
-        r->n = n;
05e1a9
-    }
05e1a9
-
05e1a9
-    if (e != NULL) {
05e1a9
-        BN_free(r->e);
05e1a9
-        r->e = e;
05e1a9
-    }
05e1a9
-
05e1a9
-    if (d != NULL) {
05e1a9
-        BN_free(r->d);
05e1a9
-        r->d = d;
05e1a9
-    }
05e1a9
-
05e1a9
-    return 1;
05e1a9
-}
05e1a9
-
05e1a9
-void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q) {
05e1a9
-    if(p) {
05e1a9
-        *p = r->p;
05e1a9
-    }
05e1a9
-
05e1a9
-    if (q) {
05e1a9
-        *q = r->q;
05e1a9
-    }
05e1a9
-}
05e1a9
-
05e1a9
-int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s) {
05e1a9
-
05e1a9
-    if (!r || !s) {
05e1a9
-        return 0;
05e1a9
-    }
05e1a9
-
05e1a9
-    BN_clear_free(sig->r);
05e1a9
-    BN_clear_free(sig->s);
05e1a9
-
05e1a9
-    sig->r = r;
05e1a9
-    sig->s = s;
05e1a9
-
05e1a9
-    return 1;
05e1a9
-}
05e1a9
-
05e1a9
-#endif
05e1a9
-
05e1a9
 bool tpm2_openssl_hash_compute_data(TPMI_ALG_HASH halg, BYTE *buffer,
05e1a9
         UINT16 length, TPM2B_DIGEST *digest) {
05e1a9
 
05e1a9
@@ -422,54 +370,28 @@ out:
05e1a9
 
05e1a9
 HMAC_CTX *tpm2_openssl_hmac_new() {
05e1a9
     HMAC_CTX *ctx;
05e1a9
-#if defined(LIB_TPM2_OPENSSL_OPENSSL_PRE11)
05e1a9
-    ctx = malloc(sizeof(*ctx));
05e1a9
-#else
05e1a9
     ctx = HMAC_CTX_new();
05e1a9
-#endif
05e1a9
     if (!ctx)
05e1a9
         return NULL;
05e1a9
 
05e1a9
-#if defined(LIB_TPM2_OPENSSL_OPENSSL_PRE11)
05e1a9
-    HMAC_CTX_init(ctx);
05e1a9
-#endif
05e1a9
-
05e1a9
     return ctx;
05e1a9
 }
05e1a9
 
05e1a9
 void tpm2_openssl_hmac_free(HMAC_CTX *ctx) {
05e1a9
-#if defined(LIB_TPM2_OPENSSL_OPENSSL_PRE11)
05e1a9
-    HMAC_CTX_cleanup(ctx);
05e1a9
-    free(ctx);
05e1a9
-#else
05e1a9
     HMAC_CTX_free(ctx);
05e1a9
-#endif
05e1a9
 }
05e1a9
 
05e1a9
 EVP_CIPHER_CTX *tpm2_openssl_cipher_new(void) {
05e1a9
     EVP_CIPHER_CTX *ctx;
05e1a9
-#if defined(LIB_TPM2_OPENSSL_OPENSSL_PRE11)
05e1a9
-    ctx = malloc(sizeof(*ctx));
05e1a9
-#else
05e1a9
     ctx = EVP_CIPHER_CTX_new();
05e1a9
-#endif
05e1a9
     if (!ctx)
05e1a9
         return NULL;
05e1a9
 
05e1a9
-#if defined(LIB_TPM2_OPENSSL_OPENSSL_PRE11)
05e1a9
-    EVP_CIPHER_CTX_init(ctx);
05e1a9
-#endif
05e1a9
-
05e1a9
     return ctx;
05e1a9
 }
05e1a9
 
05e1a9
 void tpm2_openssl_cipher_free(EVP_CIPHER_CTX *ctx) {
05e1a9
-#if defined(LIB_TPM2_OPENSSL_OPENSSL_PRE11)
05e1a9
-    EVP_CIPHER_CTX_cleanup(ctx);
05e1a9
-    free(ctx);
05e1a9
-#else
05e1a9
     EVP_CIPHER_CTX_free(ctx);
05e1a9
-#endif
05e1a9
 }
05e1a9
 
05e1a9
 digester tpm2_openssl_halg_to_digester(TPMI_ALG_HASH halg) {
05e1a9
@@ -680,12 +602,7 @@ static bool load_public_RSA_from_key(RSA *k, TPM2B_PUBLIC *pub) {
05e1a9
     const BIGNUM *n; /* modulus */
05e1a9
     const BIGNUM *e; /* public key exponent */
05e1a9
 
05e1a9
-#if defined(LIB_TPM2_OPENSSL_OPENSSL_PRE11)
05e1a9
-    n = k->n;
05e1a9
-    e = k->e;
05e1a9
-#else
05e1a9
     RSA_get0_key(k, &n, &e, NULL);
05e1a9
-#endif
05e1a9
 
05e1a9
     /*
05e1a9
      * The size of the modulus is the key size in RSA, store this as the
05e1a9
@@ -1006,11 +923,7 @@ static bool load_private_RSA_from_key(RSA *k, TPM2B_SENSITIVE *priv) {
05e1a9
 
05e1a9
     const BIGNUM *p; /* the private key exponent */
05e1a9
 
05e1a9
-#if defined(LIB_TPM2_OPENSSL_OPENSSL_PRE11)
05e1a9
-    p = k->p;
05e1a9
-#else
05e1a9
     RSA_get0_factors(k, &p, NULL);
05e1a9
-#endif
05e1a9
 
05e1a9
     TPMT_SENSITIVE *sa = &priv->sensitiveArea;
05e1a9
 
05e1a9
diff --git a/lib/tpm2_openssl.h b/lib/tpm2_openssl.h
05e1a9
index 46c8f9c0..8e3e0c17 100644
05e1a9
--- a/lib/tpm2_openssl.h
05e1a9
+++ b/lib/tpm2_openssl.h
05e1a9
@@ -13,10 +13,6 @@
05e1a9
 
05e1a9
 #include "pcr.h"
05e1a9
 
05e1a9
-#if (OPENSSL_VERSION_NUMBER < 0x1010000fL && !defined(LIBRESSL_VERSION_NUMBER)) || (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) /* OpenSSL 1.1.0 */
05e1a9
-#define LIB_TPM2_OPENSSL_OPENSSL_PRE11
05e1a9
-#endif
05e1a9
-
05e1a9
 #if OPENSSL_VERSION_NUMBER >= 0x10101000L
05e1a9
 #define EC_POINT_set_affine_coordinates_tss(group, tpm_pub_key, bn_x, bn_y, dmy) \
05e1a9
         EC_POINT_set_affine_coordinates(group, tpm_pub_key, bn_x, bn_y, dmy)
05e1a9
@@ -32,12 +28,6 @@
05e1a9
         EC_POINT_get_affine_coordinates_GFp(group, tpm_pub_key, bn_x, bn_y, dmy)
05e1a9
 #endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
05e1a9
 
05e1a9
-#if defined(LIB_TPM2_OPENSSL_OPENSSL_PRE11)
05e1a9
-int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
05e1a9
-void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
05e1a9
-int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
05e1a9
-#endif
05e1a9
-
05e1a9
 /**
05e1a9
  * Function prototype for a hashing routine.
05e1a9
  *
05e1a9
-- 
05e1a9
2.31.1
05e1a9