Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions src/ground_station/websocket/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ class TornadoWSServer(tornado.websocket.WebSocketHandler, ABC):

clients: set[TornadoWSServer] = set()
last_msg_send: str = ""
pw = "d916d328c73327336b8ccb25a1309a9766df1131f3a5064473933d6aae617442"
sudo_user = None

def open(self, *args: Any, **kwargs: Any) -> None:
TornadoWSServer.clients.add(self)
Expand All @@ -101,29 +99,7 @@ def on_message(self, message: str | bytes) -> None:
message = str(message)
logger.info(f"Received message: {message}")

# When we allow many users to access the front end, only a single user should have access to commands
# To facilitate this, very simple authentication is implemented.

# Once a sudo_user has been authenticated, only messages sent by them should be processed
if self == TornadoWSServer.sudo_user:
if message == "deauth":
TornadoWSServer.sudo_user = None
else:
ws_commands_queue.put(message)
# If no one has been authenticated as the sudo_user, the only messages that should be processed are those
# that try to authenticate
elif TornadoWSServer.sudo_user is None:
parsed_message = message.split(" ")
if len(parsed_message) == 2 and parsed_message[0] == "auth":
h = hashlib.sha256()
h.update(parsed_message[1].encode())
if h.hexdigest() == TornadoWSServer.pw:
TornadoWSServer.sudo_user = self
logger.info("Successfully authenticated")
else:
logger.info("Incorrect password")
else:
logger.info("Insufficient permissions")
ws_commands_queue.put(message)

def check_origin(self, origin: str) -> bool:
"""Authenticates clients from any host origin (_ parameter)."""
Expand Down
Loading