From 16506b6d8bd205931b60cded82a13a318c10a30b Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Wed, 25 Oct 2023 17:14:54 -0300 Subject: [PATCH] Default libcrypt to whether or not we find it Also deliberately don't provide the function at all if we aren't compiled with libcrypt so that we can't link if we try to call it when not available. --- external/CMakeLists.txt | 5 ++++- llarp/crypto/crypto.cpp | 6 ++---- llarp/service/auth.cpp | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index f901be4c3..e8eca96e4 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -139,7 +139,10 @@ endif() set(default_libcrypt OFF) if(LINUX AND NOT STATIC_LINK) - set(default_libcrypt ON) + pkg_check_modules(LIBCRYPT libcrypt IMPORTED_TARGET) + if(LIBCRYPTO_FOUND) + set(default_libcrypt ON) + endif() endif() if(MACOS) set(default_libcrypt ON) diff --git a/llarp/crypto/crypto.cpp b/llarp/crypto/crypto.cpp index 81b9cd57d..f8a61535a 100644 --- a/llarp/crypto/crypto.cpp +++ b/llarp/crypto/crypto.cpp @@ -499,13 +499,11 @@ namespace llarp crypto_kem_keypair(d + PQ_SECRETKEYSIZE, d); } +#ifdef HAVE_CRYPT bool crypto::check_passwd_hash(std::string pwhash, std::string challenge) { - (void)pwhash; - (void)challenge; bool ret = false; -#ifdef HAVE_CRYPT auto pos = pwhash.find_last_of('$'); auto settings = pwhash.substr(0, pos); crypt_data data{}; @@ -514,9 +512,9 @@ namespace llarp ret = ptr == pwhash; } sodium_memzero(&data, sizeof(data)); -#endif return ret; } +#endif const byte_t* seckey_topublic(const SecretKey& sec) diff --git a/llarp/service/auth.cpp b/llarp/service/auth.cpp index b5a6c97e8..17fbda0cb 100644 --- a/llarp/service/auth.cpp +++ b/llarp/service/auth.cpp @@ -125,7 +125,9 @@ namespace llarp::service case AuthFileType::eAuthFilePlain: return hash == challenge; case AuthFileType::eAuthFileHashes: +#ifdef HAVE_CRYPT return crypto::check_passwd_hash(std::move(hash), std::move(challenge)); +#endif default: return false; }