diff --git a/encryption.py b/encryption.py index 9fa5cc6..52514fd 100644 --- a/encryption.py +++ b/encryption.py @@ -6,7 +6,6 @@ from utils import generate_hash - def decrypt_packet(mp, key): """Decrypt the encrypted message payload and return the decoded data.""" try: @@ -52,4 +51,4 @@ def encrypt_packet(channel, key, mp, encoded_message): except Exception as e: logging.error(f"Failed to encrypt: {e}") - return None + return None \ No newline at end of file diff --git a/load_config.py b/load_config.py index 8a5e357..255fb21 100644 --- a/load_config.py +++ b/load_config.py @@ -25,4 +25,4 @@ HOP_MODIFIER = config['hop_modifier'] # Get the full default key -EXPANDED_KEY = "1PG7OiApB1nwvP+rz05pAQ==" if KEY == "AQ==" else KEY +KEY = "1PG7OiApB1nwvP+rz05pAQ==" if KEY == "AQ==" else KEY \ No newline at end of file diff --git a/logger.py b/logger.py index 53edf26..fce89bf 100644 --- a/logger.py +++ b/logger.py @@ -1,6 +1,5 @@ import logging -# Enable logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s %(message)s', @@ -27,4 +26,4 @@ def log_skipped_message(from_topic, portnum, action) -> None: f"Portnum : {portnum}\n" f"Action : {action}\n" f"{DIVIDER}" - ) + ) \ No newline at end of file diff --git a/main.py b/main.py index db91e03..0ff8e8b 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ - import logging import sys diff --git a/message_handler.py b/message_handler.py index 4b15aab..c6d8c64 100644 --- a/message_handler.py +++ b/message_handler.py @@ -38,7 +38,7 @@ def on_message(client, userdata, msg) -> None: # Decrypt the payload if necessary if original_mp.HasField("encrypted") and not original_mp.HasField("decoded"): - decoded_data = decrypt_packet(original_mp, load_config.EXPANDED_KEY) + decoded_data = decrypt_packet(original_mp, load_config.KEY) if decoded_data is None: # Check if decryption failed logging.error("Decryption failed; skipping message") return # Skip processing this message if decryption failed @@ -81,16 +81,16 @@ def on_message(client, userdata, msg) -> None: forward_to_preset = target_topic.split("/")[-1] target_topic =f"{target_topic}/{gateway_node_id}" - new_channel = generate_hash(forward_to_preset, load_config.EXPANDED_KEY) + new_channel = generate_hash(forward_to_preset, load_config.KEY) modified_mp.channel = new_channel original_channel = msg.topic original_channel = original_channel.split("/")[-2] - original_channel = generate_hash(original_channel, load_config.EXPANDED_KEY) + original_channel = generate_hash(original_channel, load_config.KEY) - if load_config.EXPANDED_KEY == "": + if load_config.KEY == "": modified_mp.decoded.CopyFrom(original_mp.decoded) else: - modified_mp.encrypted = encrypt_packet(forward_to_preset, load_config.EXPANDED_KEY, modified_mp, original_mp.decoded) + modified_mp.encrypted = encrypt_packet(forward_to_preset, load_config.KEY, modified_mp, original_mp.decoded) # Package the modified packet for publishing diff --git a/mqtt.py b/mqtt.py index 02a1403..7432921 100644 --- a/mqtt.py +++ b/mqtt.py @@ -12,7 +12,7 @@ def on_connect(client, userdata, flags, reason_code, properties=None): logging.error(f"Failed to connect with reason code {reason_code}") def create_mqtt_client(): - client = mqtt.Client() + client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) client.username_pw_set(load_config.USER, load_config.PASSWORD) client.on_connect = on_connect return client \ No newline at end of file