From 179743461f150f7fda1f5f6672a153fa11ab18a9 Mon Sep 17 00:00:00 2001 From: Whyverum Date: Mon, 1 Dec 2025 18:17:14 +0700 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=B0=D1=80=D1=85=D0=B8=D0=B2=D0=B0=20=D0=BB?= =?UTF-8?q?=D0=B8=D1=86=D0=B5=D0=BD=D0=B7=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/services/license_service.py | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 backend/services/license_service.py diff --git a/backend/services/license_service.py b/backend/services/license_service.py new file mode 100644 index 0000000..ff6bd4d --- /dev/null +++ b/backend/services/license_service.py @@ -0,0 +1,43 @@ +import tempfile +from zipfile import ZipFile +from pathlib import Path +from ..utils.encoding import variant_base64_encode +from ..utils.crypto import encrypt_bytes + +class LicenseType: + Professional: int = 1 + Educational: int = 3 + Personal: int = 4 + +def generate_license_file( + user_name: str, + version: str, + lic_type: int = LicenseType.Professional, + count: int = 1 +) -> tuple[str, tempfile.TemporaryDirectory]: + """ + Генерация временного ZIP-файла с лицензией Custom.mxtpro. + Возвращает путь к файлу и объект временной директории для cleanup. + """ + # Разбор версии + try: + major_str, minor_str = version.split(".") + major_version: int = int(major_str) + minor_version: int = int(minor_str) + except Exception as e: + raise ValueError(f"Неверный формат версии: {version}") from e + # Формирование строки лицензии (исправлено: убрали лишний #, интегрировали цифры в один блок) + license_str: str = ( + f"{lic_type}#{user_name}|{major_version}{minor_version}" + f"#{count}#{major_version}3{minor_version}6{minor_version}#0#0#0#" + ) + # Шифрование и кодирование + encrypted: bytes = encrypt_bytes(0x0787, license_str.encode("utf-8")) + encoded: str = variant_base64_encode(encrypted).decode("ascii") + + # Создание временной директории и файла с фиксированным именем + temp_dir = tempfile.TemporaryDirectory() + filepath = Path(temp_dir.name) / "Custom.mxtpro" + with ZipFile(filepath, "w") as zf: + zf.writestr("Pro.key", encoded) + return str(filepath), temp_dir \ No newline at end of file