From 7aadb14a45aba2f55d1c27c6854a03a88c194271 Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Thu, 4 Dec 2025 15:14:04 -0600 Subject: [PATCH] Fix basic auth --- CMakeLists.txt | 3 +++ src/Crypto/MbedTLS/Crypto.cpp | 7 ++++--- src/Http/BasicAuthServer.cpp | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a356fe..5ff7c62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -343,6 +343,9 @@ if(TESSESFRAMEWORK_ENABLE_EXAMPLES) add_executable(runevent examples/runevent.cpp) target_link_libraries(runevent PUBLIC tessesframework) + + add_executable(tests examples/tests.cpp) + target_link_libraries(tests PUBLIC tessesframework) endif() if(TESSESFRAMEWORK_ENABLE_APPS) diff --git a/src/Crypto/MbedTLS/Crypto.cpp b/src/Crypto/MbedTLS/Crypto.cpp index 5b7f493..aa52a35 100644 --- a/src/Crypto/MbedTLS/Crypto.cpp +++ b/src/Crypto/MbedTLS/Crypto.cpp @@ -10,6 +10,7 @@ #include #include #endif +#include namespace Tesses::Framework::Crypto { bool HaveCrypto() @@ -40,14 +41,14 @@ namespace Tesses::Framework::Crypto std::vector Base64_Decode(std::string str) { #if defined(TESSESFRAMEWORK_ENABLE_MBED) - size_t olen; + size_t olen=0; std::vector data; - mbedtls_base64_decode(data.data(), 0, &olen, (const uint8_t*)str.data(),str.size()); + data.resize(olen); - + if(mbedtls_base64_decode(data.data(), olen, &olen, (const uint8_t*)str.data(),str.size())==0) { diff --git a/src/Http/BasicAuthServer.cpp b/src/Http/BasicAuthServer.cpp index 44fa6b3..eeae1df 100644 --- a/src/Http/BasicAuthServer.cpp +++ b/src/Http/BasicAuthServer.cpp @@ -1,5 +1,6 @@ #include "TessesFramework/Http/BasicAuthServer.hpp" #include "TessesFramework/Crypto/Crypto.hpp" +#include namespace Tesses::Framework::Http { BasicAuthServer::BasicAuthServer() @@ -39,7 +40,9 @@ namespace Tesses::Framework::Http { auto security = HttpUtils::SplitString(auth," ",2); if(security.size() < 2) return false; if(security[0] != "Basic") return false; - auto decoded = Crypto::Base64_Decode(security[0]); + + auto decoded = Crypto::Base64_Decode(security[1]); + std::string decoded_str(decoded.begin(),decoded.end()); security = HttpUtils::SplitString(decoded_str,":",2); if(security.size() < 2) return false;