diff --git a/databases/postgresql.py b/databases/postgresql.py index 8b01a04..bde8e2e 100644 --- a/databases/postgresql.py +++ b/databases/postgresql.py @@ -175,7 +175,7 @@ class DatabaseManager: 'password': server_info['password'], } - panel = PanelInteraction(url_base, login_data, self.logger,) + panel = PanelInteraction(url_base, login_data, self.logger,server_info['certificate']['data']) expiry_date_iso = new_subscription.expiry_date.isoformat() # Добавляем на сервер diff --git a/temp_scripts/ca.crt b/temp_scripts/ca.pem similarity index 100% rename from temp_scripts/ca.crt rename to temp_scripts/ca.pem diff --git a/utils/panel.py b/utils/panel.py index 51b59c2..96a3f08 100644 --- a/utils/panel.py +++ b/utils/panel.py @@ -2,6 +2,7 @@ import aiohttp import uuid import json import base64 +import ssl from datetime import datetime from dateutil.relativedelta import relativedelta @@ -35,11 +36,26 @@ class PanelInteraction: :param is_encoded: Indicates whether the certificate is Base64-encoded. :return: Decoded certificate content as bytes. """ + if not certificate: self.logger.error("No certificate provided.") raise ValueError("Certificate is required.") + try: + # Создаем SSLContext + ssl_context = ssl.create_default_context() - return base64.b64decode(certificate) if is_encoded else certificate.encode() + # Декодируем, если нужно + if is_encoded: + certificate = base64.b64decode(certificate).decode() + + # Загружаем сертификат в SSLContext + ssl_context.load_verify_locations(cadata=certificate) + return ssl_context + + except Exception as e: + self.logger.error(f"Error while decoding certificate: {e}") + raise ValueError("Invalid certificate format or content.") from e + async def _ensure_logged_in(self): """