From fa19ba08e3787b2e5eb0fda2e796578edbcfb852 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Tue, 14 Sep 2021 13:03:27 +0200 Subject: [PATCH] Sentry: Properly store DSN --- include/Common.h | 5 +++++ include/Cryptography.h | 9 +++++---- include/TConsole.h | 1 + src/TSentry.cpp | 11 +++-------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/Common.h b/include/Common.h index dd03108..de7aee1 100644 --- a/include/Common.h +++ b/include/Common.h @@ -87,6 +87,7 @@ void RegisterThread(const std::string& str); #define KB 1024 #define MB (KB * 1024) +#define SSU_UNRAW SECRET_SENTRY_URL #define _file_basename std::filesystem::path(__FILE__).filename().string() #define _line std::to_string(__LINE__) @@ -112,9 +113,11 @@ void RegisterThread(const std::string& str); #else #define _this_location (ThreadName() + _file_basename + ":" + _line + " ") #endif +#define SU_RAW SSU_UNRAW #else // !defined(DEBUG) +#define SU_RAW RAWIFY(SSU_UNRAW) #define _this_location (ThreadName()) #endif // defined(DEBUG) @@ -150,3 +153,5 @@ void LogChatMessage(const std::string& name, int id, const std::string& msg); #define Biggest 30000 std::string Comp(std::string Data); std::string DeComp(std::string Compressed); + +#define S_DSN SU_RAW diff --git a/include/Cryptography.h b/include/Cryptography.h index d1ff235..5d710a0 100644 --- a/include/Cryptography.h +++ b/include/Cryptography.h @@ -49,7 +49,7 @@ struct RandomChar { }; template -struct XorString { +struct MangleString { private: const char _key; std::array _encrypted; @@ -64,7 +64,7 @@ private: public: template - constexpr XorString(const Char* str, std::index_sequence) + constexpr MangleString(const Char* str, std::index_sequence) : _key(RandomChar::value) , _encrypted { enc(str[Is])... } { } @@ -107,7 +107,8 @@ static auto w_sprintf_s_ret = [](char* buf, size_t buf_size, const char* fmt, .. return ret; }; -#define XOR_C(s) [] { constexpr XorCompileTime::XorString< sizeof(s)/sizeof(char) - 1, __COUNTER__, char > expr( s, std::make_index_sequence< sizeof(s)/sizeof(char) - 1>() ); return expr; }().decrypt() -#define XOR_W(s) [] { constexpr XorCompileTime::XorString< sizeof(s)/sizeof(wchar_t) - 1, __COUNTER__, wchar_t > expr( s, std::make_index_sequence< sizeof(s)/sizeof(wchar_t) - 1>() ); return expr; }().decrypt() +#define XOR_C(s) [] { constexpr Crypto::MangleString< sizeof(s)/sizeof(char) - 1, __COUNTER__, char > expr( s, std::make_index_sequence< sizeof(s)/sizeof(char) - 1>() ); return expr; }().decrypt() +#define XOR_W(s) [] { constexpr Crypto::MangleString< sizeof(s)/sizeof(wchar_t) - 1, __COUNTER__, wchar_t > expr( s, std::make_index_sequence< sizeof(s)/sizeof(wchar_t) - 1>() ); return expr; }().decrypt() +#define RAWIFY(s) XOR_C(s) } diff --git a/include/TConsole.h b/include/TConsole.h index fcaca26..7fd3c92 100644 --- a/include/TConsole.h +++ b/include/TConsole.h @@ -2,6 +2,7 @@ #include "commandline/commandline.h" #include "TLuaFile.h" +#include "Cryptography.h" #include #include diff --git a/src/TSentry.cpp b/src/TSentry.cpp index ab20e31..f95911e 100644 --- a/src/TSentry.cpp +++ b/src/TSentry.cpp @@ -1,22 +1,17 @@ #include "TSentry.h" #include "Common.h" +#include #include #include -// compile-time length of a string/array -template -constexpr size_t ConstexprLength(char const (&)[N]) { - return N - 1; -} - TSentry::TSentry() { - if constexpr (ConstexprLength(SECRET_SENTRY_URL) == 0) { + if (std::strlen(S_DSN) == 0) { mValid = false; } else { mValid = true; sentry_options_t* options = sentry_options_new(); - sentry_options_set_dsn(options, SECRET_SENTRY_URL); + sentry_options_set_dsn(options, S_DSN); sentry_options_set_debug(options, false); // needs to always be false sentry_options_set_symbolize_stacktraces(options, true); auto ReleaseString = "BeamMP-Server@" + Application::ServerVersion();