From 4151e2a546cb3295c179939506970f0948ebf6f1 Mon Sep 17 00:00:00 2001 From: Disledg Date: Fri, 20 Dec 2024 21:19:38 +0300 Subject: [PATCH] Save --- databases/postgresql.py | 2 +- temp_scripts/{ca.crt => ca.pem} | 0 utils/panel.py | 18 +++++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) rename temp_scripts/{ca.crt => ca.pem} (100%) 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): """