Fixed tiny bugs with authentication, added more unit tests

This commit is contained in:
Lonami
2016-09-04 21:07:09 +02:00
parent 7c8c65560e
commit b027dd2c8f
11 changed files with 98 additions and 32 deletions

View File

@@ -1,7 +1,7 @@
# This file is based on TLSharp
# https://github.com/sochix/TLSharp/blob/master/TLSharp.Core/Network/TcpTransport.cs
from zlib import crc32
from network import TcpMessage, TcpClient
from binascii import crc32
class TcpTransport:
@@ -35,12 +35,11 @@ class TcpTransport:
body = self._tcp_client.read(packet_length - 12)
checksum = int.from_bytes(self._tcp_client.read(4), byteorder='little')
checksum = int.from_bytes(self._tcp_client.read(4), byteorder='little', signed=False)
# Then perform the checks
rv = packet_length_bytes + seq_bytes + body
# Ensure it's unsigned (http://stackoverflow.com/a/30092291/4759433)
valid_checksum = crc32(rv) & 0xFFFFFFFF
valid_checksum = crc32(rv)
if checksum != valid_checksum:
raise ValueError('Invalid checksum, skip')