summaryrefslogtreecommitdiff
path: root/protocol.py
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2020-12-19 17:16:12 -0300
committerJesusaves <cpntb1@ymail.com>2020-12-19 17:16:12 -0300
commit2cef216419817217ec2780f23166e6af84a078eb (patch)
tree351c156bd2ed1c56a4c39611d8ec8970d463782b /protocol.py
parent4835dc8a7792e135719558a1982354d9eb213a42 (diff)
downloadserver-2cef216419817217ec2780f23166e6af84a078eb.tar.gz
server-2cef216419817217ec2780f23166e6af84a078eb.tar.bz2
server-2cef216419817217ec2780f23166e6af84a078eb.tar.xz
server-2cef216419817217ec2780f23166e6af84a078eb.zip
Token validation - ensure each connection can only handle its own token
Diffstat (limited to 'protocol.py')
-rw-r--r--protocol.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/protocol.py b/protocol.py
index 33ff203..5401e1c 100644
--- a/protocol.py
+++ b/protocol.py
@@ -26,18 +26,23 @@ from consts import ERR_BAD, ERR_DONE, PACKET_NACK, PACKET_ACK
# self.data structure: <Token> ; <Message> ; <JSON Arguments>
def parse(packet, conn):
##########################################################################
- # Maybe it is a RAW packet
+ # Maybe it is a DEBUG packet
if (packet.lower() == "ping"):
return [PACKET_ACK, "PONG"]
##########################################################################
- # Not a raw packet, so it must adhere to the convention
+ # Not a debug packet, so it must adhere to the convention
data=packet.split(';')
if (len(data) != 3):
return [PACKET_NACK, "Invalid packet (RAW)"]
t=data[0]
##########################################################################
+ # Maybe it is a raw packet which doesn't requires auth
+ if (data[1] == "PING"):
+ return [PACKET_ACK, "PONG"]
+
+ ##########################################################################
# Maybe it is an honest login attempt, or a registration attempt
if data[1] == "login":
# TODO: Create a token
@@ -63,6 +68,8 @@ def parse(packet, conn):
return [PACKET_NACK, "Invalid packet (TOKENF)"]
# TODO: Now validate the token itself
+ if data[0] != conn.token:
+ return [PACKET_NACK, "Invalid packet (TOKENC)"]
##########################################################################
# Top level protocols