diff --git a/common_tools.py b/common_tools.py index 224df96..4b429fb 100755 --- a/common_tools.py +++ b/common_tools.py @@ -62,6 +62,7 @@ class Create: text=True, check=False, ) + # Output from Openssl Error if process.stderr: print(process.stderr) diff --git a/org.sslcrypt.policy b/org.sslcrypt.policy index 6a2c47a..d9b5100 100644 --- a/org.sslcrypt.policy +++ b/org.sslcrypt.policy @@ -25,6 +25,7 @@ License along with this library. If not, see auth_admin_keep + auth_admin_keep yes /usr/local/bin/ssl_encrypt.py diff --git a/ssl_decrypt.py b/ssl_decrypt.py index 6d65207..03e4525 100755 --- a/ssl_decrypt.py +++ b/ssl_decrypt.py @@ -7,7 +7,7 @@ from subprocess import CompletedProcess import subprocess from wp_app_config import AppConfig -log_name = AppConfig.USER_FILE.read_text() +log_name = AppConfig.USER_FILE.read_text().strip() keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem") path_of_crypted_tunnel: Path = Path(f"/home/{log_name}/.config/wire_py") @@ -60,7 +60,7 @@ if AppConfig.PUBLICKEY.exists: text=True, check=False, ) - + shutil.chown(f"{AppConfig.TEMP_DIR}/{base_name}.conf", 1000, 1000) print(f"Processing of the file: {tunnel_path}") if process.stdout: diff --git a/ssl_encrypt.py b/ssl_encrypt.py index a92b35c..7147140 100755 --- a/ssl_encrypt.py +++ b/ssl_encrypt.py @@ -1,16 +1,17 @@ #!/usr/bin/python3 """ This Script encrypt Wireguardfiles for Wirepy users for more Security """ - from pathlib import Path import shutil import subprocess from subprocess import CompletedProcess from wp_app_config import AppConfig -log_name = AppConfig.USER_FILE.read_text() +log_name = AppConfig.USER_FILE.read_text().strip() keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem") +target: Path = Path(f"/home/{log_name}/.config/wire_py/") + if not keyfile.is_file(): process: CompletedProcess[str] = subprocess.run( @@ -44,39 +45,37 @@ if not keyfile.is_file(): shutil.chown(keyfile, 1000, 1000) - if AppConfig.TEMP_DIR.exists() and not any(AppConfig.TEMP_DIR.iterdir()): - clear_files = [str(file) for file in path_of_crypted_tunnel.glob()] +# any() get True when directory is not empty +if AppConfig.TEMP_DIR.exists() and any(AppConfig.TEMP_DIR.iterdir()): + clear_files = [str(file) for file in AppConfig.TEMP_DIR.glob("*.conf")] - for config_file in clear_files: - base_name = Path(config_file).stem - process: CompletedProcess[str] = subprocess.run( - [ - "openssl", - "pkeyutl", - "-encrypt", - "-inkey", - keyfile, - "-pubin", - "-in", - config_file, - "-out", - f"{AppConfig.CONFIG_DIR}/{base_name}.dat", - ], - capture_output=True, - text=True, - check=False, - ) + for config_file in clear_files: + base_name = Path(config_file).stem + process: CompletedProcess[str] = subprocess.run( + [ + "openssl", + "pkeyutl", + "-encrypt", + "-inkey", + keyfile, + "-pubin", + "-in", + config_file, + "-out", + f"{target}/{base_name}.dat", + ], + capture_output=True, + text=True, + check=False, + ) - print(f"Processing of the file: {config_file}") + print(f"Processing of the file: {config_file}") - if process.stdout: - print(process.stdout) + # Output from Openssl Error + if process.stderr: + print("(Error):", process.stderr) - # Output from Openssl Error - if process.stderr: - print("(Error):", process.stderr) - - if process.returncode == 0: - print(f"File {base_name}.dat successfully encrypted.") - else: - print(f"Error by {config_file}: Code: {process.returncode}") + if process.returncode == 0: + print(f"File {base_name}.dat successfully encrypted.") + else: + print(f"Error by {config_file}: Code: {process.returncode}") diff --git a/wirepy.py b/wirepy.py index 1e288de..618e57a 100755 --- a/wirepy.py +++ b/wirepy.py @@ -713,6 +713,7 @@ class FrameWidgets(ttk.Frame): ], text=True, ) + Create.encrypt() else: shutil.copy(filepath, f"{AppConfig.TEMP_DIR}/") @@ -735,8 +736,8 @@ class FrameWidgets(ttk.Frame): ], text=True, ) - Create.encrypt() + Create.encrypt() self.str_var.set("") self.a = Tunnel.active() self.l_box.insert(0, self.a) @@ -774,6 +775,7 @@ class FrameWidgets(ttk.Frame): "no", ] ) + elif ("PrivateKey = " in read) and ("Endpoint = " in read): pass else: