From 7488332a25b605b93d7508e2c083f835ed5be329 Mon Sep 17 00:00:00 2001 From: Sandwichs-del <67276741+Sandwichs-del@users.noreply.github.com> Date: Wed, 11 Jan 2023 15:39:08 +0000 Subject: [PATCH 1/3] Log connections dropped due to a security error --- pysyncobj/tcp_connection.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pysyncobj/tcp_connection.py b/pysyncobj/tcp_connection.py index 872a58b..747fd8c 100644 --- a/pysyncobj/tcp_connection.py +++ b/pysyncobj/tcp_connection.py @@ -2,6 +2,7 @@ import socket import zlib import struct +import logging import pysyncobj.pickle as pickle import pysyncobj.win_inet_pton @@ -235,16 +236,18 @@ def __processParseMessage(self): try: if self.encryptor: dataTimestamp = self.encryptor.extract_timestamp(data) - assert dataTimestamp >= self.recvLastTimestamp + assert dataTimestamp >= self.recvLastTimestamp, "Replay - timestamp" self.recvLastTimestamp = dataTimestamp # Unfortunately we can't get a timestamp and data in one go data = self.encryptor.decrypt(data) message = pickle.loads(zlib.decompress(data)) if self.recvRandKey: randKey, message = message - assert randKey == self.recvRandKey - except: - # Why no logging of security errors? + assert randKey == self.recvRandKey, "Replay - recvRandKey" + except Exception as e: + try: peername = self.__socket.getpeername()[0] + except Exception as e2: peername = "(%s)" % repr(e2) + logging.info('Invalid message from %s, connection closing due to %s.' % (peername, repr(e)) self.disconnect() return None self.__readBuffer = self.__readBuffer[4 + l:] From 2d5b7d6bdf43a78806080f07f2090a36273c56e5 Mon Sep 17 00:00:00 2001 From: Sandwichs-del <67276741+Sandwichs-del@users.noreply.github.com> Date: Wed, 11 Jan 2023 17:25:42 +0000 Subject: [PATCH 2/3] Fix missing ' --- pysyncobj/tcp_connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pysyncobj/tcp_connection.py b/pysyncobj/tcp_connection.py index 747fd8c..bb7f99b 100644 --- a/pysyncobj/tcp_connection.py +++ b/pysyncobj/tcp_connection.py @@ -247,7 +247,7 @@ def __processParseMessage(self): except Exception as e: try: peername = self.__socket.getpeername()[0] except Exception as e2: peername = "(%s)" % repr(e2) - logging.info('Invalid message from %s, connection closing due to %s.' % (peername, repr(e)) + logging.info('Invalid message from %s, connection closing due to %s.' % (peername, repr(e))) self.disconnect() return None self.__readBuffer = self.__readBuffer[4 + l:] From 6e487291ad6494eeb3e7e8c5812c5eb1525507c3 Mon Sep 17 00:00:00 2001 From: Sandwichs-del <67276741+Sandwichs-del@users.noreply.github.com> Date: Thu, 2 Feb 2023 09:19:46 +0000 Subject: [PATCH 3/3] fix formatting --- pysyncobj/tcp_connection.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pysyncobj/tcp_connection.py b/pysyncobj/tcp_connection.py index bb7f99b..390fabd 100644 --- a/pysyncobj/tcp_connection.py +++ b/pysyncobj/tcp_connection.py @@ -245,8 +245,10 @@ def __processParseMessage(self): randKey, message = message assert randKey == self.recvRandKey, "Replay - recvRandKey" except Exception as e: - try: peername = self.__socket.getpeername()[0] - except Exception as e2: peername = "(%s)" % repr(e2) + try: + peername = self.__socket.getpeername()[0] + except Exception as e2: + peername = "(%s)" % repr(e2) logging.info('Invalid message from %s, connection closing due to %s.' % (peername, repr(e))) self.disconnect() return None