This commit is contained in:
2024-12-20 21:19:38 +03:00
parent 33b502fd86
commit 4151e2a546
3 changed files with 18 additions and 2 deletions

View File

@@ -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):
"""