Check hashes after downloading

This commit is contained in:
Tixx
2025-07-25 23:50:16 +02:00
parent c0ed056440
commit b9cc025083
5 changed files with 65 additions and 12 deletions

View File

@@ -127,7 +127,7 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
return Ret;
}
bool HTTP::Download(const std::string& IP, const beammp_fs_string& Path) {
bool HTTP::Download(const std::string& IP, const beammp_fs_string& Path, const std::string& Hash) {
static std::mutex Lock;
std::scoped_lock Guard(Lock);
@@ -139,6 +139,16 @@ bool HTTP::Download(const std::string& IP, const beammp_fs_string& Path) {
return false;
}
std::string RetHash = Utils::GetSha256HashReallyFast(Ret, Path);
debug("Return hash: " + RetHash);
debug("Expected hash: " + Hash);
if (RetHash != Hash) {
error("Downloaded file hash does not match expected hash");
return false;
}
std::ofstream File(Path, std::ios::binary);
if (File.is_open()) {
File << Ret;