SInPacket now tracks decryption/decompression failure.
Previously there was no way to tell if an incoming packet was incorrectly formatted. The new function SInPacket.isValid() can be called after decryption/decompression to determine if the packet wasn't decrypted and/or decompressed properly. * Added "valid" attribute to SInPacket. * Decryption routine unsets "valid" if input buffer is not divisible by 16. * Decompression routine unsets "valid" on receiving zlib error.
This commit is contained in:
commit
540d682cfc
|
@ -0,0 +1,15 @@
|
|||
# Changelog
|
||||
All notable changes to this project will be documented here. This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## Unreleased
|
||||
- Added attribute to SInPacket to track decryption/decompression failures with incoming packets.
|
||||
|
||||
## 2.1.1 - 2018-03-14
|
||||
- Fixed getPeerCount() returning the maximum number of peers instead of the current peer count.
|
||||
- Fixed clients not sending disconnect message on program exit.
|
||||
- Changed example clients from looping infintely.
|
||||
- Renamed tutorial/examples.
|
||||
- Restructed project directory.
|
||||
|
||||
## 2.1.0 - 2018-03-10
|
||||
Initial commit of original code.
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
An updated version of the [irrNetLite](http://irrlicht.sourceforge.net/forum/viewtopic.php?f=6&t=22658) networking library compiled against recent versions of [enet](https://github.com/lsalzman/enet) and [zlib](https://github.com/madler/zlib).
|
||||
|
||||
Changelog can be viewed [here](https://github.com/rna88/irrnet/blob/master/CHANGELOG.md).
|
||||
|
||||
|
||||
## Compiling for Linux
|
||||
|
||||
|
@ -27,4 +29,4 @@ The compiled binaries will be found in `examples/bin/`.
|
|||
|
||||
## License
|
||||
|
||||
Refer to `source/ReadMe.txt`.
|
||||
Refer to [source/ReadMe.txt](https://github.com/rna88/irrnet/blob/master/source/ReadMe.txt).
|
||||
|
|
|
@ -154,10 +154,14 @@ class SInPacket
|
|||
/// Returns the size in bytes of the packet.
|
||||
u32 getSize();
|
||||
|
||||
/// Returns true if the packet decompresses/decrypts successfully.
|
||||
bool isValid();
|
||||
|
||||
private:
|
||||
u32 pos;
|
||||
core::array<c8> buff;
|
||||
u16 playerid;
|
||||
bool valid;
|
||||
};
|
||||
|
||||
} // Close Net Namespace
|
||||
|
|
|
@ -225,7 +225,7 @@ void SOutPacket::decryptPacket(const c8 key[16])
|
|||
buff = tmpbuff;
|
||||
}
|
||||
|
||||
SInPacket::SInPacket(const c8* buff, const u32 size) : pos(0), playerid(0)
|
||||
SInPacket::SInPacket(const c8* buff, const u32 size) : pos(0), playerid(0), valid(true)
|
||||
{
|
||||
SInPacket::buff.set_used(size);
|
||||
memcpy(SInPacket::buff.pointer(), buff, size);
|
||||
|
@ -435,11 +435,20 @@ void SInPacket::deCompressPacket()
|
|||
newBuff.set_used(newSize);
|
||||
|
||||
uLongf destLen = newSize;
|
||||
uncompress((Bytef*)newBuff.pointer(), &destLen, (Bytef*)buff.pointer() + 4, buff.size() - 4);
|
||||
newBuff.set_used(destLen);
|
||||
int ret = uncompress((Bytef*)newBuff.pointer(), &destLen, (Bytef*)buff.pointer() + 4, buff.size() - 4);
|
||||
|
||||
if (ret != Z_OK)
|
||||
{
|
||||
valid = false;
|
||||
newBuff.set_used(0);
|
||||
newBuff.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
newBuff.set_used(destLen);
|
||||
buff = newBuff;
|
||||
}
|
||||
}
|
||||
|
||||
void SInPacket::encryptPacket(const c8 key[16])
|
||||
{
|
||||
|
@ -457,6 +466,12 @@ void SInPacket::encryptPacket(const c8 key[16])
|
|||
|
||||
void SInPacket::decryptPacket(const c8 key[16])
|
||||
{
|
||||
if (buff.size() % 16 != 0)
|
||||
{
|
||||
valid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
CEncryption::SetEncryptionKey((u8*)&key[0]);
|
||||
const u32 newSize = buff.size();
|
||||
core::array<c8> tmpbuff;
|
||||
|
@ -473,5 +488,10 @@ u32 SInPacket::getSize()
|
|||
return buff.size();
|
||||
}
|
||||
|
||||
bool SInPacket::isValid()
|
||||
{
|
||||
return valid;
|
||||
}
|
||||
|
||||
} // Close Net Namespace
|
||||
} // Close Irr namespace
|
||||
|
|
Loading…
Reference in New Issue