From 8c4ae2253a3c1cd217e20ccce0031d0840aaad34 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 2 Jun 2023 20:20:31 +0200 Subject: [PATCH] Try OpenSSL 3.0 --- src/core/libs/CMakeLists.txt | 42 +++++++++++++++++----- src/core/libs/osnma_msg_receiver.cc | 33 +++++++++++++++-- src/core/system_parameters/Galileo_OSNMA.h | 1 + 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/core/libs/CMakeLists.txt b/src/core/libs/CMakeLists.txt index 02d6e31de..5757a2ddd 100644 --- a/src/core/libs/CMakeLists.txt +++ b/src/core/libs/CMakeLists.txt @@ -102,16 +102,40 @@ target_link_libraries(core_libs Pugixml::pugixml ) -target_link_libraries(core_libs - PRIVATE - ${GNUTLS_LIBRARIES} - ${GNUTLS_OPENSSL_LIBRARY} -) - -target_include_directories(core_libs - PRIVATE +if(OPENSSL_FOUND) + if(TARGET OpenSSL::SSL) + target_link_libraries(core_libs + PRIVATE + OpenSSL::SSL + ) + else() + target_link_libraries(core_libs + PRIVATE + ${OPENSSL_LIBRARIES} + ) + target_include_directories(core_libs + PRIVATE + ${OPENSSL_INCLUDE_DIR} + ) + endif() + if(OPENSSL_VERSION) + if(OPENSSL_VERSION VERSION_GREATER "3.0.0") + target_compile_definitions(core_libs PRIVATE -DUSE_OPENSSL_3=1) + endif() + endif() +else() + target_link_libraries(core_libs + PRIVATE + ${GNUTLS_LIBRARIES} + ${GNUTLS_OPENSSL_LIBRARY} + ) + target_include_directories(core_libs + PRIVATE ${GNUTLS_INCLUDE_DIR} -) + ) +endif() + + if(OPENSSL_FOUND) target_compile_definitions(core_libs PRIVATE -DUSE_OPENSSL_FALLBACK=1) diff --git a/src/core/libs/osnma_msg_receiver.cc b/src/core/libs/osnma_msg_receiver.cc index a1583195d..e771d7de8 100644 --- a/src/core/libs/osnma_msg_receiver.cc +++ b/src/core/libs/osnma_msg_receiver.cc @@ -108,7 +108,7 @@ void osnma_msg_receiver::msg_handler_osnma(const pmt::pmt_t& msg) auto osnma_data_ptr = std::make_shared(d_osnma_data); this->message_port_pub(pmt::mp("OSNMA_to_PVT"), pmt::make_any(osnma_data_ptr)); d_new_data = false; - d_osnma_data = OSNMA_data(); + // d_osnma_data = OSNMA_data(); DLOG(INFO) << "NMA info sent to the PVT block through the OSNMA_to_PVT async message port"; } } @@ -382,7 +382,7 @@ void osnma_msg_receiver::process_dsm_message(const std::vector& dsm_msg { // Reserved message? LOG(WARNING) << "OSNMA Reserved message received"; - d_osnma_data = OSNMA_data(); + // d_osnma_data = OSNMA_data(); } d_number_of_blocks[d_osnma_data.d_dsm_header.dsm_id] = 0; } @@ -441,10 +441,37 @@ std::vector osnma_msg_receiver::computeSHA256(const std::vector output(32); // SHA256 hash size #if USE_OPENSSL_FALLBACK +#if USE_OPENSSL_3 + // unsigned char mdVal[EVP_MAX_MD_SIZE]; + // unsigned char* md; + unsigned int mdLen; + EVP_MD_CTX* mdCtx = EVP_MD_CTX_new(); + if (!EVP_DigestInit_ex(mdCtx, EVP_sha256(), OPENSSL_ENGINE)) + { + // printf("Message digest initialization failed.\n"); + // EVP_MD_CTX_free(mdCtx); + // exit(EXIT_FAILURE); + } + if (!EVP_DigestUpdate(mdCtx, input.data(), input.size())) + { + // printf("Message digest update failed.\n"); + // EVP_MD_CTX_free(mdCtx); + // exit(EXIT_FAILURE); + } + if (!EVP_DigestFinal_ex(mdCtx, output.data(), &mdLen)) + { + printf("Message digest finalization failed.\n"); + EVP_MD_CTX_free(mdCtx); + exit(EXIT_FAILURE); + } + EVP_MD_CTX_free(mdCtx); + // md = mdVal; +#else SHA256_CTX sha256Context; SHA256_Init(&sha256Context); SHA256_Update(&sha256Context, input.data(), input.size()); SHA256_Final(output.data(), &sha256Context); +#endif #else gnutls_hash_hd_t hashHandle; gnutls_hash_init(&hashHandle, GNUTLS_DIG_SHA256); @@ -455,7 +482,7 @@ std::vector osnma_msg_receiver::computeSHA256(const std::vector& publicKey, const std::vector& publicKey) +// bool signature(const std::vector& publicKey, const std::vector& digest, const std::vector& signature) // { // bool success = false; // #if USE_OPENSSL_FALLBACK diff --git a/src/core/system_parameters/Galileo_OSNMA.h b/src/core/system_parameters/Galileo_OSNMA.h index 39f32752e..62df5ccb1 100644 --- a/src/core/system_parameters/Galileo_OSNMA.h +++ b/src/core/system_parameters/Galileo_OSNMA.h @@ -22,6 +22,7 @@ #include #include #include +#include /** \addtogroup Core * \{ */