From fdb100649b44af1ac7f0a9ec83dc7805430aada8 Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Sun, 31 May 2026 12:28:10 +0900 Subject: [PATCH] fix: invalid type conversion for OpenSSL 4.0.0 Since OpenSSL 4.0.0, X509_get_subject_name returns const X509_NAME pointer, thus X509_NAME_add_entry_by_txt does not accept it anymore. See /usr/include/openssl/x509.h. Instead, explicitly operates it via mutable X509_NAME object. It is safe operation without using X509_get_subject_name() because subject name was not modified after cert = X509_new() assignment. It will fix the following error. error: invalid conversion from 'const X509_name_st*' to 'X509_NAME*' {aka 'X509_name _st*'} [-fpermissive] 87 | X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, reinterpret_cast("Deskflow"), -1, -1, 0); | ^~~~ | | | const X509_name_st* Signed-off-by: Kentaro Hayashi --- src/lib/net/SecureUtils.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/net/SecureUtils.cpp b/src/lib/net/SecureUtils.cpp index f47e4379a..31436d8a0 100644 --- a/src/lib/net/SecureUtils.cpp +++ b/src/lib/net/SecureUtils.cpp @@ -84,9 +84,14 @@ void generatePemSelfSignedCert(const QString &path, int keyLength) X509_gmtime_adj(X509_get_notAfter(cert), expirationDays * 24 * 3600); X509_set_pubkey(cert, privateKey); - auto *name = X509_get_subject_name(cert); + auto *name = X509_NAME_new(); + if (!name) { + throw std::runtime_error("could not allocate subject name"); + } X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, reinterpret_cast("Deskflow"), -1, -1, 0); + X509_set_subject_name(cert, name); X509_set_issuer_name(cert, name); + X509_NAME_free(name); X509_sign(cert, privateKey, EVP_sha256()); const QFile file(path);