Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion wadas/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Date: 2024-08-14
# Description: module to keep track of WADAS version

__version__ = "v1.0.0.a4"
__version__ = "v1.0.0.a5"
__dbversion__ = __version__
36 changes: 36 additions & 0 deletions wadas/domain/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
import uuid
from logging.handlers import RotatingFileHandler

from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization


def get_timestamp():
"""Method to prepare timestamp string to apply to images naming"""
Expand Down Expand Up @@ -120,3 +124,35 @@ def send_data_on_local_socket(port, command):
return data
finally:
client_socket.close()


def is_pem_key(
pem_key_file: str,
password: bytes | None = None,
) -> bool:
"""Method to validate pem key file content."""

try:
with open(pem_key_file, "rb") as f:
serialization.load_pem_private_key(
f.read(),
password=password,
backend=default_backend(),
)
return True
except Exception:
return False


def is_pem_certificate(pem_certificate_file) -> bool:
"""Method to validate pem certificate file content."""

try:
with open(pem_certificate_file, "rb") as f:
x509.load_pem_x509_certificate(
f.read(),
backend=default_backend(),
)
return True
except Exception:
return False
Binary file modified wadas/icons/icon-actuator-24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified wadas/icons/icon-ai-24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions wadas/ui/configure_actuators_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from wadas.domain.fastapi_actuator_server import FastAPIActuatorServer, initialize_fastapi_logger
from wadas.domain.feeder_actuator import FeederActuator
from wadas.domain.roadsign_actuator import RoadSignActuator
from wadas.domain.utils import is_pem_certificate, is_pem_key
from wadas.ui.error_message_dialog import WADASErrorMessage
from wadas.ui.qt.ui_configure_actuators import Ui_DialogConfigureActuators
from wadas.ui.qtextedit_logger import QTextEditLogger

Expand Down Expand Up @@ -254,6 +256,12 @@ def select_key_file(self):
self, "Open SSL key file", os.getcwd(), "Pem File (*.pem)"
)
self.ui.label_key_file.setText(str(file_name[0]))

# Verify key file
if not is_pem_key(file_name[0]):
WADASErrorMessage("Invalid key file provided",
f"Error while loading key file. Please make sure selected file is a valid one.").exec()

self.validate()

def select_certificate_file(self):
Expand All @@ -263,6 +271,11 @@ def select_certificate_file(self):
self, "Open SSL certificate file", os.getcwd(), "Pem File (*.pem)"
)
self.ui.label_cert_file.setText(str(file_name[0]))

if not is_pem_certificate(file_name[0]):
WADASErrorMessage("Invalid certificate file provided",
f"Error while loading certificate file. Please make sure selected file is a valid one").exec()

self.validate()

def get_actuator_id(self, row):
Expand Down
4 changes: 4 additions & 0 deletions wadas/ui/configure_camera_actuator_associations_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def __init__(self):
# Set the model to the QTreeView
self.ui.treeView.setModel(self.model)

# Expand all items by default
self.ui.treeView.expandAll()

# Signal
self.ui.treeView.doubleClicked.connect(self.handle_double_click)
self.ui.pushButton_close.clicked.connect(self.accept_and_close)
Expand All @@ -72,6 +75,7 @@ def handle_double_click(self, index):
dialog.exec()
# Refresh the camera item in the tree view after editing actuators
self.populate_model()
self.ui.treeView.expandAll()

def populate_model(self):

Expand Down
13 changes: 13 additions & 0 deletions wadas/ui/configure_ftp_cameras_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
from wadas.domain.database import DataBase
from wadas.domain.ftp_camera import FTPCamera
from wadas.domain.ftps_server import FTPsServer
from wadas.domain.utils import is_pem_certificate, is_pem_key
from wadas.ui.error_message_dialog import WADASErrorMessage
from wadas.ui.qt.ui_configure_ftp_cameras import Ui_DialogFTPCameras
from wadas.ui.qtextedit_logger import QTextEditLogger

Expand Down Expand Up @@ -328,6 +330,12 @@ def select_key_file(self):
self, "Open SSL key file", os.getcwd(), "Pem File (*.pem)"
)
self.ui.label_key_file_path.setText(str(file_name[0]))

# Verify key file
if not is_pem_key(file_name[0]):
WADASErrorMessage("Invalid key file provided",
f"Error while loading key file. Please make sure selected file is a valid one.").exec()

self.validate()

def select_certificate_file(self):
Expand All @@ -337,6 +345,11 @@ def select_certificate_file(self):
self, "Open SSL certificate file", os.getcwd(), "Pem File (*.pem)"
)
self.ui.label_certificate_file_path.setText(str(file_name[0]))

if not is_pem_certificate(file_name[0]):
WADASErrorMessage("Invalid certificate file provided",
f"Error while loading certificate file. Please make sure selected file is a valid one").exec()

self.validate()

def select_ftp_folder(self):
Expand Down
2 changes: 0 additions & 2 deletions wadas/ui/configure_web_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ def initialize_dialog(self):
role_cb = self.findChild(QComboBox, f"comboBox_role_{i}")
role_txt = role if role in self.roles else "Viewer"
role_cb.setCurrentText(role_txt)

self.validate()
else:
self.findChild(QLineEdit, "lineEdit_user_0").setEnabled(False)
self.findChild(QLineEdit, "lineEdit_password_0").setEnabled(False)
Expand Down