Validate downloaded files

--HG--
branch : feature-streamed-package
hg/feature/streamed-package
kaetemi 10 years ago
parent a7af274ae0
commit 0f59cb4343

@ -27,6 +27,7 @@
#include <nel/misc/streamed_package_manager.h> #include <nel/misc/streamed_package_manager.h>
#include <nel/misc/file.h> #include <nel/misc/file.h>
#include <nel/misc/path.h> #include <nel/misc/path.h>
#include <nel/misc/sha1.h>
namespace NLMISC { namespace NLMISC {
@ -242,6 +243,15 @@ bool CStreamedPackageManager::getFile(std::string &filePath, const std::string &
} }
} }
CHashKey outHash = outBuffer.size() ? getSHA1(&outBuffer[0], outBuffer.size()) : CHashKey();
if (!(outHash == entry->Hash))
{
std::string wantHashS = entry->Hash.toString();
std::string outHashS = outHash.toString();
nlwarning("Invalid SHA1 hash for file '%s', download has hash '%s'", wantHashS.c_str(), outHashS.c_str());
return false;
}
{ {
COFile outStream(unpackPath); COFile outStream(unpackPath);
outStream.serialBuffer(&outBuffer[0], (uint)fileSize); outStream.serialBuffer(&outBuffer[0], (uint)fileSize);

Loading…
Cancel
Save