From 3eaaafacb4249220a523669566d49c2d16ee92b0 Mon Sep 17 00:00:00 2001
From: Michele Calgaro <michele.calgaro@yahoo.it>
Date: Wed, 14 Oct 2026 11:50:46 +0900
Subject: Requires openssl 1.1 or greater

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
---
 ConfigureChecks.cmake | 11 +++--------
 src/tls/tqca-tls.cpp  | 49 -------------------------------------------------
 2 files changed, 3 insertions(+), 57 deletions(-)

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 84cbe54..450cdb4 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -36,19 +36,14 @@ endif( BUILD_TQCA )
 
 if( BUILD_TQCA_TLS )
 ##### check for openssl
-
-pkg_search_module( SSL openssl )
+pkg_search_module( SSL openssl>=1.1.0 )
 
 if( NOT SSL_FOUND )
     check_include_file( openssl/ssl.h HAVE_OPENSSL_H )
     check_library_exists( ssl OPENSSL_init_ssl "" HAVE_LIBSSL_11 )
     check_library_exists( crypto EVP_EncryptInit_ex "" HAVE_LIBCRYPTO )
 
-    if( NOT HAVE_LIBSSL_11 )
-        check_library_exists( ssl SSL_library_init "" HAVE_LIBSSL )
-    endif()
-
-    if( HAVE_OPENSSL_H AND HAVE_LIBCRYPTO AND (HAVE_LIBSSL_11 OR HAVE_LIBSSL)  )
+    if( HAVE_OPENSSL_H AND HAVE_LIBCRYPTO AND HAVE_LIBSSL_11 )
         set( SSL_FOUND 1 CACHE INTERNAL "" FORCE )
         find_file( OPENSSLV_H openssl/opensslv.h )
         file( STRINGS "${OPENSSLV_H}" SSL_VERSION REGEX "#[ \t]*define[ \t]*OPENSSL_VERSION_TEXT" )
@@ -59,7 +54,7 @@ if( NOT SSL_FOUND )
 endif( NOT SSL_FOUND )
 
 if( NOT SSL_FOUND )
-    tde_message_fatal( "OpenSSL is required but was not found on your system" )
+    tde_message_fatal( "OpenSSL 1.1 or newer is required but was not found on your system" )
 endif()
 
 
diff --git a/src/tls/tqca-tls.cpp b/src/tls/tqca-tls.cpp
index 2b7ddeb..b703776 100644
--- a/src/tls/tqca-tls.cpp
+++ b/src/tls/tqca-tls.cpp
@@ -34,14 +34,6 @@
 #include <openssl/err.h>
 #include <openssl/rand.h>
 
-#if OPENSSL_VERSION_NUMBER >= 0x00907000
-#define OSSL_097
-#endif
-
-#ifndef OSSL_097
-#define NO_AES
-#endif
-
 static TQByteArray lib_randomArray(int size)
 {
 	if(RAND_status() == 0) {
@@ -61,15 +53,8 @@ static bool lib_generateKeyIV(const EVP_CIPHER *_type, const TQByteArray &data,
 	TQByteArray k, i;
 	unsigned char *kp = nullptr;
 	unsigned char *ip = nullptr;
-#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
-	EVP_CIPHER type = *_type;
-	EVP_CIPHER *loctype = &type;
-	if(keysize != -1)
-		type.key_len = keysize;
-#else
 	EVP_CIPHER *loctype = EVP_CIPHER_meth_dup(_type);
 	Q_UNUSED(keysize)
-#endif
 	if(key) {
 		k.resize(EVP_CIPHER_key_length(loctype));
 		kp = (unsigned char *)k.data();
@@ -79,9 +64,7 @@ static bool lib_generateKeyIV(const EVP_CIPHER *_type, const TQByteArray &data,
 		ip = (unsigned char *)i.data();
 	}
 	int res = EVP_BytesToKey(loctype, EVP_sha1(), (unsigned char *)salt.data(), (unsigned char *)data.data(), data.size(), 1, kp, ip);
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
 	EVP_CIPHER_meth_free(loctype);
-#endif
 	if (!res)
 		return false;
 	if(key)
@@ -191,12 +174,7 @@ public:
 	virtual ~EVPCipherContext()
 	{
 		if(type) {
-#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
-			EVP_CIPHER_CTX_cleanup(c);
-			OPENSSL_free(c);
-#else
 			EVP_CIPHER_CTX_free(c);
-#endif
 			type = nullptr;
 		}
 	}
@@ -238,12 +216,7 @@ public:
 		pad = _pad;
 		type = getType(mode);
 		r.resize(0);
-#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
-		c = (EVP_CIPHER_CTX*)OPENSSL_malloc(sizeof(EVP_CIPHER_CTX));
-		EVP_CIPHER_CTX_init(c);
-#else
 		c = EVP_CIPHER_CTX_new();
-#endif
 
 		if(dir == TQCA::Encrypt) {
 			if(!EVP_EncryptInit(c, type, nullptr, nullptr))
@@ -340,7 +313,6 @@ public:
 	}
 };
 
-#ifndef NO_AES
 class AES128Context : public EVPCipherContext
 {
 public:
@@ -370,7 +342,6 @@ public:
 			return nullptr;
 	}
 };
-#endif
 
 class RSAKeyContext : public TQCA_RSAKeyContext
 {
@@ -408,11 +379,7 @@ public:
 			p = buf;
 			i2d_RSAPublicKey(r, &p);
 			p = buf;
-#ifdef OSSL_097
 			*_pub = d2i_RSAPublicKey(nullptr, (const unsigned char **)&p, len);
-#else
-			*_pub = d2i_RSAPublicKey(nullptr, (unsigned char **)&p, len);
-#endif
 			free(buf);
 		}
 
@@ -422,11 +389,7 @@ public:
 			p = buf;
 			i2d_RSAPrivateKey(r, &p);
 			p = buf;
-#ifdef OSSL_097
 			*_sec = d2i_RSAPrivateKey(nullptr, (const unsigned char **)&p, len);
-#else
-			*_sec = d2i_RSAPrivateKey(nullptr, (unsigned char **)&p, len);
-#endif
 			free(buf);
 		}
 	}
@@ -455,11 +418,7 @@ public:
 
 		// private?
 		p = (void *)in;
-#ifdef OSSL_097
 		r = d2i_RSAPrivateKey(nullptr, (const unsigned char **)&p, len);
-#else
-		r = d2i_RSAPrivateKey(nullptr, (unsigned char **)&p, len);
-#endif
 		if(r) {
 			reset();
 
@@ -470,11 +429,7 @@ public:
 		else {
 			// public?
 			p = (void *)in;
-#ifdef OSSL_097
 			r = d2i_RSAPublicKey(nullptr, (const unsigned char **)&p, len);
-#else
-			r = d2i_RSAPublicKey(nullptr, (unsigned char **)&p, len);
-#endif
 			if(!r) {
 				// try this other public function, for whatever reason
 				p = (void *)in;
@@ -1468,10 +1423,8 @@ public:
 			TQCA::CAP_MD5 |
 			TQCA::CAP_BlowFish |
 			TQCA::CAP_TripleDES |
-#ifndef NO_AES
 			TQCA::CAP_AES128 |
 			TQCA::CAP_AES256 |
-#endif
 			TQCA::CAP_RSA |
 			TQCA::CAP_X509 |
 			TQCA::CAP_TLS;
@@ -1488,12 +1441,10 @@ public:
 			return new BlowFishContext;
 		else if(cap == TQCA::CAP_TripleDES)
 			return new TripleDESContext;
-#ifndef NO_AES
 		else if(cap == TQCA::CAP_AES128)
 			return new AES128Context;
 		else if(cap == TQCA::CAP_AES256)
 			return new AES256Context;
-#endif
 		else if(cap == TQCA::CAP_RSA)
 			return new RSAKeyContext;
 		else if(cap == TQCA::CAP_X509)
-- 
cgit v1.2.3

