From 3d280f9439a61c0c8bc68208e816f77372601987 Mon Sep 17 00:00:00 2001
From: Michele Calgaro <michele.calgaro@yahoo.it>
Date: Wed, 14 Oct 2026 12:15:53 +0900
Subject: Add support for openssl 4

Co-authored-by: Opencode/Big Pickle
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
---
 src/tls/tqca-tls.cpp | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/src/tls/tqca-tls.cpp b/src/tls/tqca-tls.cpp
index b703776..059a01e 100644
--- a/src/tls/tqca-tls.cpp
+++ b/src/tls/tqca-tls.cpp
@@ -53,18 +53,16 @@ static bool lib_generateKeyIV(const EVP_CIPHER *_type, const TQByteArray &data,
 	TQByteArray k, i;
 	unsigned char *kp = nullptr;
 	unsigned char *ip = nullptr;
-	EVP_CIPHER *loctype = EVP_CIPHER_meth_dup(_type);
 	Q_UNUSED(keysize)
 	if(key) {
-		k.resize(EVP_CIPHER_key_length(loctype));
+		k.resize(EVP_CIPHER_key_length(_type));
 		kp = (unsigned char *)k.data();
 	}
 	if(iv) {
-		i.resize(EVP_CIPHER_iv_length(loctype));
+		i.resize(EVP_CIPHER_iv_length(_type));
 		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);
-	EVP_CIPHER_meth_free(loctype);
+	int res = EVP_BytesToKey(_type, EVP_sha1(), (unsigned char *)salt.data(), (unsigned char *)data.data(), data.size(), 1, kp, ip);
 	if (!res)
 		return false;
 	if(key)
@@ -612,24 +610,26 @@ public:
 	RSA *pub, *sec;
 };
 
-static TQValueList<TQCA_CertProperty> nameToProperties(struct X509_name_st *name)
+static TQValueList<TQCA_CertProperty> nameToProperties(const X509_NAME *name)
 {
 	TQValueList<TQCA_CertProperty> list;
 
 	for(int n = 0; n < X509_NAME_entry_count(name); ++n) {
-		X509_NAME_ENTRY *ne = X509_NAME_get_entry(name, n);
+		const X509_NAME_ENTRY *ne = X509_NAME_get_entry(name, n);
 		TQCA_CertProperty p;
 
-		ASN1_OBJECT *ao = X509_NAME_ENTRY_get_object(ne);
+		const ASN1_OBJECT *ao = X509_NAME_ENTRY_get_object(ne);
 		int nid = OBJ_obj2nid(ao);
 		if(nid == NID_undef)
 			continue;
 		p.var = OBJ_nid2sn(nid);
 
-		ASN1_STRING *as = X509_NAME_ENTRY_get_data(ne);
+		const ASN1_STRING *as = X509_NAME_ENTRY_get_data(ne);
+		int len = ASN1_STRING_length(as);
+		const unsigned char *data = ASN1_STRING_get0_data(as);
 		TQCString c;
-		c.resize(as->length+1);
-		strncpy(c.data(), (char *)as->data, as->length);
+		c.resize(len+1);
+		memcpy(c.data(), data, len);
 		p.val = TQString::fromLatin1(c);
 		list += p;
 	}
@@ -641,18 +641,16 @@ static TQValueList<TQCA_CertProperty> nameToProperties(struct X509_name_st *name
 //
 // This code is mostly taken from OpenSSL v0.9.5a
 // by Eric Young
-TQDateTime ASN1_UTCTIME_TQDateTime(ASN1_UTCTIME *tm, int *isGmt)
+TQDateTime ASN1_UTCTIME_TQDateTime(const ASN1_UTCTIME *tm, int *isGmt)
 {
 	TQDateTime qdt;
-	char *v;
 	int gmt=0;
-	int i;
 	int y=0,M=0,d=0,h=0,m=0,s=0;
 	TQDate qdate;
 	TQTime qtime;
 
-	i = tm->length;
-	v = (char *)tm->data;
+	int i = ASN1_STRING_length(tm);
+	const unsigned char *v = ASN1_STRING_get0_data(tm);
 
 	if (i < 10) goto auq_err;
 	if (v[i-1] == 'Z') gmt=1;
@@ -843,8 +841,8 @@ public:
 		na = ASN1_UTCTIME_TQDateTime(X509_get_notAfter(x), nullptr);
 
 		// extract the subject/issuer strings
-		struct X509_name_st *sn = X509_get_subject_name(x);
-		struct X509_name_st *in = X509_get_issuer_name(x);
+		const X509_NAME *sn = X509_get_subject_name(x);
+		const X509_NAME *in = X509_get_issuer_name(x);
 		char buf[1024];
 		X509_NAME_oneline(sn, buf, 1024);
 		v_subject = buf;
-- 
cgit v1.2.3

