ddnet/src/engine/shared/map.cpp
heinrich5991 ca8fcc823c Use more secure hash function for map downloads
SHA256 was chosen because it is reasonably standard, the file names
don't explode in length (this rules out SHA512) and it is supported by
basically all versions of OpenSSL (this rules out SHA512/256 and SHA3).

The protocol is changed in a backward compatible way: The supporting
server sends the SHA256 corresponding to the map in the `MAP_DETAILS`
message prior to sending the `MAP_CHANGE` message. The client saves the
SHA256 obtained from the `MAP_DETAILS` message until the next
`MAP_CHANGE` message.

For servers not supporting this protocol, the client falls back to
simply opening maps like in the previous scheme.

Remove the `map_version` tool, it is not being used and would have been
a little bit effort to update.

Use the OpenSSL implementation of SHA256 if it is supported, otherwise
fall back to a public domain one.

Fix #1127.
2018-06-24 17:04:50 +02:00

64 lines
1.7 KiB
C++

/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/system.h>
#include <engine/map.h>
#include <engine/storage.h>
#include "datafile.h"
class CMap : public IEngineMap
{
CDataFileReader m_DataFile;
public:
CMap() {}
virtual void *GetData(int Index) { return m_DataFile.GetData(Index); }
virtual int GetDataSize(int Index) { return m_DataFile.GetDataSize(Index); }
virtual void *GetDataSwapped(int Index) { return m_DataFile.GetDataSwapped(Index); }
virtual void UnloadData(int Index) { m_DataFile.UnloadData(Index); }
virtual void *GetItem(int Index, int *pType, int *pID) { return m_DataFile.GetItem(Index, pType, pID); }
virtual int GetItemSize(int Index) { return m_DataFile.GetItemSize(Index); }
virtual void GetType(int Type, int *pStart, int *pNum) { m_DataFile.GetType(Type, pStart, pNum); }
virtual void *FindItem(int Type, int ID) { return m_DataFile.FindItem(Type, ID); }
virtual int NumItems() { return m_DataFile.NumItems(); }
virtual void Unload()
{
m_DataFile.Close();
}
virtual bool Load(const char *pMapName)
{
IStorage *pStorage = Kernel()->RequestInterface<IStorage>();
if(!pStorage)
return false;
return m_DataFile.Open(pStorage, pMapName, IStorage::TYPE_ALL);
}
virtual bool IsLoaded()
{
return m_DataFile.IsOpen();
}
virtual SHA256_DIGEST Sha256()
{
return m_DataFile.Sha256();
}
virtual unsigned Crc()
{
return m_DataFile.Crc();
}
virtual int MapSize()
{
return m_DataFile.MapSize();
}
virtual IOHANDLE File()
{
return m_DataFile.File();
}
};
extern IEngineMap *CreateEngineMap() { return new CMap; }