Description: Build without mbed TLS
 mbed TLS is going away from Debian (#1154999), so do not fall back to the
 embedded copy when no system mbedtls is found, and use GnuTLS for TLS.
 Look up GnuTLS with plain pkg-config, Debian links it dynamically.
Author: Nico Della Torre <nicoz91@ubuntu.com>
Bug-Debian: https://bugs.debian.org/1155219
Forwarded: not-needed
Last-Update: 2026-11-27
---
Index: ncbi-blastplus/c++/src/build-system/configure
===================================================================
--- ncbi-blastplus.orig/c++/src/build-system/configure
+++ ncbi-blastplus/c++/src/build-system/configure
@@ -19102,14 +19102,6 @@ $as_echo "#define HAVE_LIBMBEDTLS 1" >>c
       MBEDTLS_LIBS="-L$MBEDTLS_PATH/lib -lmbedtls-static -lmbedx509-static -lmbedcrypto-static $Z_LIBS"
    fi
 fi
-if test -z "$MBEDTLS_LIBS"; then
-   mbedtls_local=connect/mbedtls
-   { $as_echo "$as_me:${as_lineno-$LINENO}: using local mbedTLS copy in $mbedtls_local" >&5
-$as_echo "$as_me: using local mbedTLS copy in $mbedtls_local" >&6;}
-   MBEDTLS_INCLUDE=""
-   MBEDTLS_LIBS="$Z_LIBS"
-             WithPackages="$WithPackages${WithPackagesSep}MBEDTLS"; WithPackagesSep=" "
-fi
 
 if test "x$with_gmp" != xno; then
    case "$with_gmp" in
@@ -19833,7 +19825,7 @@ if test "x$with_gnutls" != xno; then
          test "x$p" = "x/usr"  ||  GNUTLS_PATH=$p
       fi
    else
-      LIBGNUTLS_CONFIG="eval PKG_CONFIG_PATH=\"$GNUTLS_PATH/lib$bit64_sfx/pkgconfig:$GNUTLS_PATH/lib/pkgconfig\" pkg-config gnutls --static"
+      LIBGNUTLS_CONFIG="eval PKG_CONFIG_PATH=\"$GNUTLS_PATH/lib$bit64_sfx/pkgconfig:$GNUTLS_PATH/lib/pkgconfig\" pkg-config gnutls"
       $LIBGNUTLS_CONFIG --exists >/dev/null 2>&1 ||  LIBGNUTLS_CONFIG=no
    fi
    case "$LIBGNUTLS_CONFIG" in
Index: ncbi-blastplus/c++/src/build-system/configure.ac
===================================================================
--- ncbi-blastplus.orig/c++/src/build-system/configure.ac
+++ ncbi-blastplus/c++/src/build-system/configure.ac
@@ -4980,13 +4980,6 @@ if test "x${with_mbedtls-no}" != xno; th
       MBEDTLS_LIBS="-L$MBEDTLS_PATH/lib -lmbedtls-static -lmbedx509-static -lmbedcrypto-static $Z_LIBS"
    fi
 fi
-if test -z "$MBEDTLS_LIBS"; then
-   mbedtls_local=connect/mbedtls
-   AC_MSG_NOTICE([using local mbedTLS copy in $mbedtls_local])
-   MBEDTLS_INCLUDE=""
-   MBEDTLS_LIBS="$Z_LIBS"
-   NCBI_PACKAGE(MBEDTLS)
-fi
 
 if test "x$with_gmp" != xno; then
    case "$with_gmp" in
@@ -5106,7 +5099,7 @@ if test "x$with_gnutls" != xno; then
          test "x$p" = "x/usr"  ||  GNUTLS_PATH=$p
       fi
    else
-      LIBGNUTLS_CONFIG="eval PKG_CONFIG_PATH=\"$GNUTLS_PATH/lib$bit64_sfx/pkgconfig:$GNUTLS_PATH/lib/pkgconfig\" pkg-config gnutls --static"
+      LIBGNUTLS_CONFIG="eval PKG_CONFIG_PATH=\"$GNUTLS_PATH/lib$bit64_sfx/pkgconfig:$GNUTLS_PATH/lib/pkgconfig\" pkg-config gnutls"
       $LIBGNUTLS_CONFIG --exists >/dev/null 2>&1 ||  LIBGNUTLS_CONFIG=no
    fi
    case "$LIBGNUTLS_CONFIG" in
Index: ncbi-blastplus/c++/src/connect/connect_misc.cpp
===================================================================
--- ncbi-blastplus.orig/c++/src/connect/connect_misc.cpp
+++ ncbi-blastplus/c++/src/connect/connect_misc.cpp
@@ -323,6 +323,7 @@ void CLogLatencyReport::Start(EWhich whi
     _VERIFY(NcbiSys_close(saved_stderr) >= 0);
 }
 
+#ifdef HAVE_LIBMBEDTLS
 NCBI_EXPORT_FUNC_DEFINE(XCONNECT, mbedtls_ctr_drbg_free);
 NCBI_EXPORT_FUNC_DEFINE(XCONNECT, mbedtls_ctr_drbg_init);
 NCBI_EXPORT_FUNC_DEFINE(XCONNECT, mbedtls_ctr_drbg_random);
@@ -356,5 +357,6 @@ NCBI_EXPORT_FUNC_DEFINE(XCONNECT, mbedtl
 NCBI_EXPORT_FUNC_DEFINE(XCONNECT, mbedtls_x509_crt_init);
 NCBI_EXPORT_FUNC_DEFINE(XCONNECT, mbedtls_x509_crt_parse);
 NCBI_EXPORT_FUNC_DEFINE(XCONNECT, psa_crypto_init);
+#endif
 
 END_NCBI_SCOPE
Index: ncbi-blastplus/c++/src/connect/connect_misc_impl.hpp
===================================================================
--- ncbi-blastplus.orig/c++/src/connect/connect_misc_impl.hpp
+++ ncbi-blastplus/c++/src/connect/connect_misc_impl.hpp
@@ -30,17 +30,20 @@
  *
  */
 
+#include <corelib/ncbimisc.hpp>
+
+#ifdef HAVE_LIBMBEDTLS
 #include <mbedtls/error.h>
 #include <mbedtls/ctr_drbg.h>
 #include <mbedtls/entropy.h>
 #include <mbedtls/ssl.h>
-
-#include <corelib/ncbimisc.hpp>
+#endif
 
 #include <connect/connect_export.h>
 
 BEGIN_NCBI_SCOPE
 
+#ifdef HAVE_LIBMBEDTLS
 NCBI_EXPORT_FUNC_DECLARE(XCONNECT, mbedtls_ctr_drbg_free);
 NCBI_EXPORT_FUNC_DECLARE(XCONNECT, mbedtls_ctr_drbg_init);
 NCBI_EXPORT_FUNC_DECLARE(XCONNECT, mbedtls_ctr_drbg_random);
@@ -74,6 +77,7 @@ NCBI_EXPORT_FUNC_DECLARE(XCONNECT, mbedt
 NCBI_EXPORT_FUNC_DECLARE(XCONNECT, mbedtls_x509_crt_init);
 NCBI_EXPORT_FUNC_DECLARE(XCONNECT, mbedtls_x509_crt_parse);
 NCBI_EXPORT_FUNC_DECLARE(XCONNECT, psa_crypto_init);
+#endif
 
 END_NCBI_SCOPE
 
Index: ncbi-blastplus/c++/src/connect/ncbi_connssl.h
===================================================================
--- ncbi-blastplus.orig/c++/src/connect/ncbi_connssl.h
+++ ncbi-blastplus/c++/src/connect/ncbi_connssl.h
@@ -135,7 +135,7 @@ struct SOCKSSL_struct {
 
 /* Internal certificate credentials management routines */
 
-#if defined(HAVE_LIBMBEDTLS)  ||  defined(NCBI_CXX_TOOLKIT)
+#if defined(HAVE_LIBMBEDTLS)
 
 NCBI_CRED NcbiCreateMbedTlsCertCredentials(const void* cert,
                                            size_t      certsz,
@@ -144,7 +144,7 @@ NCBI_CRED NcbiCreateMbedTlsCertCredentia
 
 void NcbiDeleteMbedTlsCertCredentials(NCBI_CRED cred);
 
-#endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
+#endif /*HAVE_LIBMBEDTLS*/
 
 
 #ifdef HAVE_LIBGNUTLS
Index: ncbi-blastplus/c++/src/connect/ncbi_mbedtls.c
===================================================================
--- ncbi-blastplus.orig/c++/src/connect/ncbi_mbedtls.c
+++ ncbi-blastplus/c++/src/connect/ncbi_mbedtls.c
@@ -41,7 +41,7 @@
 #define NCBI_USE_ERRCODE_X   Connect_TLS
 
 
-#if defined(HAVE_LIBMBEDTLS)  ||  defined(NCBI_CXX_TOOLKIT)
+#if defined(HAVE_LIBMBEDTLS)
 
 #  include <mbedtls/ctr_drbg.h>
 #  include <mbedtls/debug.h>
@@ -69,7 +69,7 @@
 #  define mbedtls_x509_crt    void
 #  define mbedtls_pk_context  void
 
-#endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
+#endif /*HAVE_LIBMBEDTLS*/
 
 
 struct SNcbiMbedTlsCred {
@@ -78,7 +78,7 @@ struct SNcbiMbedTlsCred {
 };
 
 
-#if defined(HAVE_LIBMBEDTLS)  ||  defined(NCBI_CXX_TOOLKIT)
+#if defined(HAVE_LIBMBEDTLS)
 
 #  if defined(MBEDTLS_THREADING_ALT)  &&  defined(NCBI_THREADS)
 #    ifdef MBEDTLS_THREADING_PTHREAD
@@ -894,7 +894,7 @@ static EIO_Status s_MbedTlsInit(FSSLPull
     return eIO_NotSupported;
 }
 
-#endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
+#endif /*HAVE_LIBMBEDTLS*/
 
 
 extern SOCKSSL NcbiSetupMbedTls(void)
@@ -902,7 +902,7 @@ extern SOCKSSL NcbiSetupMbedTls(void)
     static const struct SOCKSSL_struct kMbedTlsOps = {
         "MBEDTLS"
         , s_MbedTlsInit
-#if defined(HAVE_LIBMBEDTLS)  ||  defined(NCBI_CXX_TOOLKIT)
+#if defined(HAVE_LIBMBEDTLS)
         , s_MbedTlsCreate
         , s_MbedTlsOpen
         , s_MbedTlsRead
@@ -911,11 +911,11 @@ extern SOCKSSL NcbiSetupMbedTls(void)
         , s_MbedTlsDelete
         , s_MbedTlsExit
         , s_MbedTlsError
-#endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
+#endif /*HAVE_LIBMBEDTLS*/
     };
-#if !defined(HAVE_LIBMBEDTLS)  &&  !defined(NCBI_CXX_TOOLKIT)
+#if !defined(HAVE_LIBMBEDTLS)
     CORE_LOG_X(8, eLOG_Warning, "Unavailable feature MBEDTLS");
-#endif /*!HAVE_LIBMBEDTLS && !NCBI_CXX_TOOLKIT*/
+#endif /*!HAVE_LIBMBEDTLS*/
     return &kMbedTlsOps;
 }
 
@@ -948,7 +948,7 @@ extern NCBI_CRED NcbiCredMbedTls(void* x
 }
 
 
-#if defined(HAVE_LIBMBEDTLS)  ||  defined(NCBI_CXX_TOOLKIT)
+#if defined(HAVE_LIBMBEDTLS)
 
 void NcbiDeleteMbedTlsCertCredentials(NCBI_CRED cred)
 {
@@ -1054,4 +1054,4 @@ NCBI_CRED NcbiCreateMbedTlsCertCredentia
     return 0;
 }
 
-#endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
+#endif /*HAVE_LIBMBEDTLS*/
Index: ncbi-blastplus/c++/src/connect/ncbi_tls.c
===================================================================
--- ncbi-blastplus.orig/c++/src/connect/ncbi_tls.c
+++ ncbi-blastplus/c++/src/connect/ncbi_tls.c
@@ -43,7 +43,7 @@
 
 
 /* Establish default here! */
-#if   defined(HAVE_LIBMBEDTLS)  ||  defined(NCBI_CXX_TOOLKIT)
+#if   defined(HAVE_LIBMBEDTLS)
 #  define NcbiSetupDefaultTls  NcbiSetupMbedTls
 #elif defined(HAVE_LIBGNUTLS)
 #  define NcbiSetupDefaultTls  NcbiSetupGnuTls
@@ -135,34 +135,34 @@ extern NCBI_CRED NcbiCreateTlsCertCreden
     sslname = SOCK_SSLName();
     if (!sslname  ||  !*sslname) {
         FSSLSetup setup = x_NcbiSetupTls();
-#if defined(HAVE_LIBMBEDTLS)  ||  defined(NCBI_CXX_TOOLKIT)
+#if defined(HAVE_LIBMBEDTLS)
         if (setup == NcbiSetupMbedTls) {
             ssltype = eNcbiCred_MbedTls;
             CORE_LOG_X(48, eLOG_Warning,
                        "Building MBEDTLS certificate credentials may not"
                        " work correctly prior to proper SSL setup/init");
         }
-#endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
+#endif /*HAVE_LIBMBEDTLS*/
 #ifdef HAVE_LIBGNUTLS
         if (setup == NcbiSetupGnuTls)
             ssltype = eNcbiCred_GnuTls;
 #endif /*HAVE_LIBGNUTLS*/
         (void) setup;
     } else {
-#if defined(HAVE_LIBMBEDTLS)  ||  defined(NCBI_CXX_TOOLKIT)
+#if defined(HAVE_LIBMBEDTLS)
         if (strcmp(sslname, "MBEDTLS") == 0)
             ssltype = eNcbiCred_MbedTls;
-#endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
+#endif /*HAVE_LIBMBEDTLS*/
 #ifdef HAVE_LIBGNUTLS
         if (strcmp(sslname, "GNUTLS") == 0)
             ssltype = eNcbiCred_GnuTls;
 #endif /*HAVE_LIBGNUTLS*/
     }
     switch (ssltype) {
-#if defined(HAVE_LIBMBEDTLS)  ||  defined(NCBI_CXX_TOOLKIT)
+#if defined(HAVE_LIBMBEDTLS)
     case eNcbiCred_MbedTls:
         return NcbiCreateMbedTlsCertCredentials(cert, certsz, pkey, pkeysz);
-#endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
+#endif /*HAVE_LIBMBEDTLS*/
 #ifdef HAVE_LIBGNUTLS
     case eNcbiCred_GnuTls:
         return NcbiCreateGnuTlsCertCredentials (cert, certsz, pkey, pkeysz);
@@ -183,11 +183,11 @@ extern void NcbiDeleteTlsCertCredentials
 {
     char who[40];
     switch (cred->type / 100) {
-#if defined(HAVE_LIBMBEDTLS)  ||  defined(NCBI_CXX_TOOLKIT)
+#if defined(HAVE_LIBMBEDTLS)
     case eNcbiCred_MbedTls / 100:
         NcbiDeleteMbedTlsCertCredentials(cred);
         return;
-#endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
+#endif /*HAVE_LIBMBEDTLS*/
 #ifdef HAVE_LIBGNUTLS
     case eNcbiCred_GnuTls / 100:
         NcbiDeleteGnuTlsCertCredentials (cred);
@@ -202,11 +202,11 @@ extern void NcbiDeleteTlsCertCredentials
         strcpy(who, "GNUTLS");
         break;
 #endif /*!HAVE_LIBGNUTLS*/
-#if !defined(HAVE_LIBMBEDTLS)  &&  !defined(NCBI_CXX_TOOLKIT)
+#if !defined(HAVE_LIBMBEDTLS)
     case eNcbiCred_MbedTls / 100:
         strcpy(who, "MBEDTLS");
         break;
-#endif /*!HAVE_LIBMBEDTLS && !NCBI_CXX_TOOLKIT*/
+#endif /*!HAVE_LIBMBEDTLS*/
     default:
         sprintf(who, "TLS 0x%08X", cred->type);
         break;
