#!/usr/bin/python3 """ This Script encrypt Wireguardfiles for Wirepy users for more Security """ import os import shutil from pathlib import Path from subprocess import check_call from common_tools import LxTools from wp_app_config import AppConfig keyfile: Path = Path( f"/home/{AppConfig.USER_FILE.read_text(encoding="utf-8")}/.config/wire_py/pbwgk.pem" ) if not keyfile.is_file(): check_call( [ "openssl", "rsa", "-in", AppConfig.SYSTEM_PATHS["pkey_path"], "-out", keyfile, "-outform", "PEM", "-pubout", ] ) shutil.chown(keyfile, 1000, 1000) if AppConfig.TEMP_DIR.exists(): tl = LxTools.get_file_name(AppConfig.TEMP_DIR) CPTH: str = f"{keyfile}" CRYPTFILES: str = CPTH[:-9] if keyfile.exists() and len(tl) != 0: for tunnels in tl: sourcetl: str = f"{AppConfig.TEMP_DIR}/{tunnels}" tlname: str = f"{CRYPTFILES}{tunnels[:-5]}.dat" check_call( [ "openssl", "pkeyutl", "-encrypt", "-inkey", keyfile, "-pubin", "-in", sourcetl, "-out", tlname, ] ) else: if AppConfig.TEMP_DIR.exists(): tl: list[str] = os.listdir(f"{AppConfig.TEMP_DIR}") CPTH: str = f"{keyfile}" CRYPTFILES: str = CPTH[:-9] if keyfile.exists() and len(tl) != 0: for tunnels in tl: sourcetl: str = f"{AppConfig.TEMP_DIR}/{tunnels}" tlname: str = f"{CRYPTFILES}{tunnels[:-5]}.dat" check_call( [ "openssl", "pkeyutl", "-encrypt", "-inkey", keyfile, "-pubin", "-in", sourcetl, "-out", tlname, ] )