From 3bd34db2d6748cd1feab7ef46d5658c14798793a Mon Sep 17 00:00:00 2001
From: Andreas Karlsson <andreas.karlsson@percona.com>
Date: Wed, 25 Nov 2026 03:18:01 +0100
Subject: [PATCH v2] Remove backwards compatibility ifdef for
 SSL_AD_NO_APPLICATION_PROTOCOL

As our minimum supported OpenSSL version is 1.1.1 we can now rely on
that SSL_AD_NO_APPLICATION_PROTOCOL will always be defined so this ifdef
can be removed. And the same is also true for LibreSSL as this define
was actually introduced in 3.4.0, and not in 3.4.3 as the comment
implies and 3.4.0 happens to be our oldest supported version.

When already touching the comment we also add information about in which
library versions the bug the error message was fixed in so we in the
future can remove this workaround.
---
 src/interfaces/libpq/fe-secure-openssl.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c
index 243ed240087..8031fc4f6a3 100644
--- a/src/interfaces/libpq/fe-secure-openssl.c
+++ b/src/interfaces/libpq/fe-secure-openssl.c
@@ -1642,20 +1642,16 @@ SSLerrmessage(unsigned long ecode)
 
 	/*
 	 * Server aborted the connection with TLS "no_application_protocol" alert.
-	 * The ERR_reason_error_string() function doesn't give any error string
-	 * for that for some reason, so do it ourselves.  See
-	 * https://github.com/openssl/openssl/issues/24300.  This is available in
-	 * OpenSSL 1.1.0 and later, as well as in LibreSSL 3.4.3 (OpenBSD 7.0) and
-	 * later.
+	 * Older OpenSSL and LibreSSL versions don't give any error string for
+	 * that, so do it ourselves.  This was fixed in OpenSSL 3.4 and in LibreSSL
+	 * 4.1.0.  See https://github.com/openssl/openssl/issues/24300.
 	 */
-#ifdef SSL_AD_NO_APPLICATION_PROTOCOL
 	if (ERR_GET_LIB(ecode) == ERR_LIB_SSL &&
 		ERR_GET_REASON(ecode) == SSL_AD_REASON_OFFSET + SSL_AD_NO_APPLICATION_PROTOCOL)
 	{
 		snprintf(errbuf, SSL_ERR_LEN, "no application protocol");
 		return errbuf;
 	}
-#endif
 
 	/*
 	 * In OpenSSL 3.0.0 and later, ERR_reason_error_string does not map system
-- 
2.43.0

