From 7a8410b375833e9fdaf9b5904aa381be52eca147 Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 1 Apr 2022 14:31:20 -0400 Subject: [PATCH] make more platforms ignore libcrypt --- llarp/CMakeLists.txt | 6 ++++-- llarp/crypto/crypto_libsodium.cpp | 8 +++----- llarp/service/auth.cpp | 2 +- test/crypto/test_llarp_crypto.cpp | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index 33474aca0..5dc983885 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -244,11 +244,13 @@ endif() target_link_libraries(liblokinet PUBLIC cxxopts lokinet-platform lokinet-util lokinet-cryptography sqlite_orm ngtcp2_static) target_link_libraries(liblokinet PRIVATE libunbound) -if(NOT WIN32) - pkg_check_modules(CRYPT libcrypt REQUIRED IMPORTED_TARGET) +pkg_check_modules(CRYPT libcrypt IMPORTED_TARGET) +if(CRYPT_FOUND AND NOT WIN32 AND NOT ANDROID) + add_definitions(-DHAVE_CRYPT) add_library(libcrypt INTERFACE) target_link_libraries(libcrypt INTERFACE PkgConfig::CRYPT) target_link_libraries(liblokinet PRIVATE libcrypt) + message(STATUS "using libcrypt ${CRYPT_VERSION}") endif() diff --git a/llarp/crypto/crypto_libsodium.cpp b/llarp/crypto/crypto_libsodium.cpp index 9c51f8443..60f2e5513 100644 --- a/llarp/crypto/crypto_libsodium.cpp +++ b/llarp/crypto/crypto_libsodium.cpp @@ -13,7 +13,7 @@ #include #include #include -#ifndef _WIN32 +#ifdef HAVE_CRYPT #include #endif @@ -472,12 +472,10 @@ namespace llarp bool CryptoLibSodium::check_passwd_hash(std::string pwhash, std::string challenge) { -#ifdef _WIN32 (void)pwhash; (void)challenge; - return false; -#else bool ret = false; +#ifdef HAVE_CRYPT auto pos = pwhash.find_last_of('$'); auto settings = pwhash.substr(0, pos); crypt_data data{}; @@ -486,8 +484,8 @@ namespace llarp ret = ptr == pwhash; } sodium_memzero(&data, sizeof(data)); - return ret; #endif + return ret; } } // namespace sodium diff --git a/llarp/service/auth.cpp b/llarp/service/auth.cpp index af52361d4..1c6ce91fb 100644 --- a/llarp/service/auth.cpp +++ b/llarp/service/auth.cpp @@ -49,7 +49,7 @@ namespace llarp::service const auto itr = values.find(data); if (itr == values.end()) throw std::invalid_argument("no such auth file type: " + data); -#ifdef _WIN32 +#ifndef HAVE_CRYPT if (itr->second == AuthFileType::eAuthFileHashes) throw std::invalid_argument("unsupported auth file type: " + data); #endif diff --git a/test/crypto/test_llarp_crypto.cpp b/test/crypto/test_llarp_crypto.cpp index 5d9cf707b..13105a87e 100644 --- a/test/crypto/test_llarp_crypto.cpp +++ b/test/crypto/test_llarp_crypto.cpp @@ -48,7 +48,7 @@ TEST_CASE("PQ crypto") REQUIRE(otherShared == shared); } -#ifndef _WIN32 +#ifdef HAVE_CRYPT TEST_CASE("passwd hash valid") {