Skip to content

Commit

Permalink
Some changes to crypto code and other things (vmangos#2823)
Browse files Browse the repository at this point in the history
  • Loading branch information
0blu authored Nov 2, 2024
1 parent 83fe148 commit 425fd90
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 233 deletions.
54 changes: 54 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignOperands: false
AlignTrailingComments: false
AlwaysBreakTemplateDeclarations: Yes
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
BeforeWhile: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBraces: Custom
BreakConstructorInitializers: AfterColon
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 999
ConstructorInitializerAllOnOneLineOrOnePerLine: false
IncludeCategories:
- Regex: '^<.*'
Priority: 1
- Regex: '^".*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseBlocks: true
IndentWidth: 4
InsertNewlineAtEOF: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
PointerAlignment: Left
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
TabWidth: 4
...
17 changes: 12 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
root = true

[*]
indent_style = space
indent_size = 2
[{*.h,*.c,*.hpp,*.cpp}]
charset = utf-8
insert_final_newline = true
indent_style = space
indent_size = 4
tab_width = 16 # <-- To instantly see when a TAB was used
trim_trailing_whitespace = true
max_line_length = 999

[*.md]
charset = utf-8
insert_final_newline = true
indent_style = space

[{*.cmake,CMakeLists.txt}]
charset = utf-8
insert_final_newline = true
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
43 changes: 3 additions & 40 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions src/game/Anticheat/WardenAnticheat/WardenScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ WindowsModuleScan::WindowsModuleScan(std::string const& module, bool wanted, std

scan << static_cast<uint8>(winWarden->GetModule()->opcodes[FIND_MODULE_BY_NAME] ^ winWarden->GetXor()) << seed;

HMACSHA1 hash(reinterpret_cast<uint8 const*>(&seed), sizeof(seed));
Crypto::Hash::HMACSHA1::Generator hash(reinterpret_cast<uint8 const*>(&seed), sizeof(seed));
hash.UpdateData(this->m_module);
hash.Finalize();
auto digest = hash.GetDigest();

scan.append(hash.GetDigest(), hash.GetLength());
scan.append(digest.data(), digest.size());
},
// checker
[this](Warden const*, ByteBuffer& buff)
Expand All @@ -174,11 +174,11 @@ WindowsModuleScan::WindowsModuleScan(std::string const& module, CheckT checker,

scan << static_cast<uint8>(winWarden->GetModule()->opcodes[FIND_MODULE_BY_NAME] ^ winWarden->GetXor()) << seed;

HMACSHA1 hash(reinterpret_cast<uint8 const*>(&seed), sizeof(seed));
Crypto::Hash::HMACSHA1::Generator hash(reinterpret_cast<uint8 const*>(&seed), sizeof(seed));
hash.UpdateData(this->m_module);
hash.Finalize();
auto digest = hash.GetDigest();

scan.append(hash.GetDigest(), hash.GetLength());
scan.append(digest.data(), digest.size());
},
checker, sizeof(uint8) + sizeof(uint32) + Crypto::Hash::SHA1::Digest::size(), sizeof(uint8), comment, flags, minBuild, maxBuild)
{
Expand Down Expand Up @@ -303,11 +303,11 @@ WindowsCodeScan::WindowsCodeScan(uint32 offset, std::vector<uint8> const& patter
scan << static_cast<uint8>(winWarden->GetModule()->opcodes[this->m_memImageOnly ? FIND_MEM_IMAGE_CODE_BY_HASH : FIND_CODE_BY_HASH] ^ winWarden->GetXor())
<< seed;

HMACSHA1 hash(reinterpret_cast<uint8 const*>(&seed), sizeof(seed));
Crypto::Hash::HMACSHA1::Generator hash(reinterpret_cast<uint8 const*>(&seed), sizeof(seed));
hash.UpdateData(&this->m_pattern[0], this->m_pattern.size());
hash.Finalize();
scan.append(hash.GetDigest(), hash.GetLength());
auto digest = hash.GetDigest();

scan.append(digest.data(), digest.size());

scan << this->m_offset << static_cast<uint8>(this->m_pattern.size());
},
Expand Down Expand Up @@ -489,11 +489,11 @@ WindowsDriverScan::WindowsDriverScan(std::string const& name, std::string const&

scan << static_cast<uint8>(winWarden->GetModule()->opcodes[FIND_DRIVER_BY_NAME] ^ winWarden->GetXor()) << seed;

HMACSHA1 hash(reinterpret_cast<uint8 const*>(&seed), sizeof(seed));
Crypto::Hash::HMACSHA1::Generator hash(reinterpret_cast<uint8 const*>(&seed), sizeof(seed));
hash.UpdateData(this->m_targetPath);
hash.Finalize();
auto digest = hash.GetDigest();

scan.append(hash.GetDigest(), hash.GetLength());
scan.append(digest.data(), digest.size());
scan << static_cast<uint8>(strings.size());
},
// checker
Expand Down
12 changes: 6 additions & 6 deletions src/game/Anticheat/WardenAnticheat/WardenWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,11 +744,11 @@ void WardenWin::LoadScriptedScans()

scan << opcode << seed;

HMACSHA1 hash(reinterpret_cast<uint8 const*>(&seed), sizeof(seed));
Crypto::Hash::HMACSHA1::Generator hash(reinterpret_cast<uint8 const*>(&seed), sizeof(seed));
hash.UpdateData(hypervisor.DeviceName);
hash.Finalize();
auto digest = hash.GetDigest();

scan.append(hash.GetDigest(), hash.GetLength());
scan.append(digest.data(), digest.size());
scan << static_cast<uint8>(strings.size());
}
},
Expand Down Expand Up @@ -798,11 +798,11 @@ void WardenWin::LoadScriptedScans()

static_assert(sizeof(pattern) <= 0xFF, "pattern length must fit into 8 bits");

HMACSHA1 hash(reinterpret_cast<uint8 const*>(&seed), sizeof(seed));
Crypto::Hash::HMACSHA1::Generator hash(reinterpret_cast<uint8 const*>(&seed), sizeof(seed));
hash.UpdateData(&pattern[0], sizeof(pattern));
hash.Finalize();
auto digest = hash.GetDigest();

scan.append(hash.GetDigest(), hash.GetLength());
scan.append(digest.data(), digest.size());

scan << warden->GetModule()->memoryRead << static_cast<uint8>(sizeof(pattern));
},
Expand Down
1 change: 1 addition & 0 deletions src/game/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ class World
};

extern uint32 realmID;
extern std::string realmName;

#define sWorld MaNGOS::Singleton<World>::Instance()
#endif
Expand Down
4 changes: 1 addition & 3 deletions src/mangosd/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ DatabaseType LoginDatabase; // Accessor to the r
DatabaseType LogsDatabase; // Accessor to the logs database

uint32 realmID; // Id of the realm
std::string realmName; // Name of the realm

// Print out the usage string for this program on the console.
void usage(const char *prog)
Expand Down Expand Up @@ -196,9 +197,6 @@ extern int main(int argc, char **argv)
sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "VMaNGOS : https://github.com/vmangos");
sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "Using configuration file %s.", cfg_file);

#define STR(s) #s
#define XSTR(s) STR(s)

sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "Alloc library: " MANGOS_ALLOC_LIB "");
sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "Core Revision: " _FULLVERSION);

Expand Down
16 changes: 14 additions & 2 deletions src/mangosd/Master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ int Master::Run()
return 1;
}

{
std::unique_ptr<QueryResult> result{LoginDatabase.PQuery("SELECT `name` FROM `realmlist` WHERE `id` = %d", realmID)};
if (!result)
{
sLog.Out(LOG_BASIC, LOG_LVL_ERROR, "Config contains invalid realmID %d, make sure its set in the `realmlist` table", realmID);
Log::WaitBeforeContinueIfNeed();
return 1;
}
realmName = (*result)[0].GetCppString();
}

sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "World server is running realm ID: %d Name: \"%s\"", realmID, realmName.c_str());
sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "");

// Initialize the World
sWorld.SetInitialWorldSettings();

Expand Down Expand Up @@ -482,8 +496,6 @@ bool Master::_StartDB()
return false;
}

sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "Realm running as realm ID %d", realmID);

// Clean the database before starting
clearOnlineAccounts();

Expand Down
5 changes: 2 additions & 3 deletions src/realmd/AuthSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

#include "Common.h"
#include "Crypto/Hash/Hmac.h"
#include "Crypto/Hash/HMACSHA1.h"
#include "Auth/base32.h"
#include "Database/DatabaseEnv.h"
#include "Config/Config.h"
Expand Down Expand Up @@ -1275,9 +1275,8 @@ uint32 AuthSocket::GenerateTotpPin(const std::string& secret, int interval) {
uint64 step = static_cast<uint64>((floor(now / 30))) + interval;
EndianConvertReverse(step);

HmacHash hmac(decoded_key.data(), key_size);
Crypto::Hash::HMACSHA1::Generator hmac(decoded_key.data(), key_size);
hmac.UpdateData((uint8*)&step, sizeof(step));
hmac.Finalize();

auto hmac_result = hmac.GetDigest();

Expand Down
10 changes: 0 additions & 10 deletions src/shared/Auth/AuthCrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

#include "AuthCrypt.h"

#include "Crypto/Hash/Hmac.h"

AuthCrypt::AuthCrypt()
{
_initialized = false;
Expand Down Expand Up @@ -88,11 +86,3 @@ void AuthCrypt::SetKey(uint8* key, size_t len)
AuthCrypt::~AuthCrypt()
{
}

void AuthCrypt::GenerateKey(uint8* key, BigNumber* bn)
{
HmacHash hash;
hash.UpdateBigNumber(bn);
hash.Finalize();
memcpy(key, hash.GetDigest(), hash.GetLength());
}
2 changes: 0 additions & 2 deletions src/shared/Auth/AuthCrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ class AuthCrypt

bool IsInitialized() { return _initialized; }

static void GenerateKey(uint8*, BigNumber*);

private:
std::vector<uint8> _key;
uint8 _send_i, _send_j, _recv_i, _recv_j;
Expand Down
2 changes: 0 additions & 2 deletions src/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ set (shared_SRCS
Crypto/Authentication/SRP6.cpp
Crypto/Encryption/RC4.h
Crypto/Encryption/RC4.cpp
Crypto/Hash/Hmac.h
Crypto/Hash/Hmac.cpp
Crypto/Hash/HMACSHA1.h
Crypto/Hash/HMACSHA1.cpp
Crypto/Hash/MD5.h
Expand Down
3 changes: 0 additions & 3 deletions src/shared/Crypto/Authentication/SRP6.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#include "Common.h"
#include "Crypto/BigNumber.h"
#include "Crypto/Hash/SHA1.h"
#include "ByteBuffer.h"

#define HMAC_RES_SIZE 20

/*! Secure Remote Password protocol */
class SRP6
Expand Down
Loading

0 comments on commit 425fd90

Please sign in to comment.