From 6b8e24b0b2d1cf7c7d1c2ef6270ff1ec7d71c67a Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Wed, 19 Oct 2022 09:33:38 -0400 Subject: [PATCH] Optimized decrypt() Former-commit-id: 8ad01f00ecf678ea8716507745791818343eaf66 [formerly 2b98562dcaea641d3775e883301b61901d75b4ed] Former-commit-id: fdc02b6db471b98fbbdf55ddc381a25b68477f0b --- lib/sshyp.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/sshyp.py b/lib/sshyp.py index 5b6cf4d..0b53d72 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -144,20 +144,16 @@ def encrypt(_entry_dir, _shm_folder, _shm_entry, _gpg_com, _gpg_id, _tmp_dir=pat def decrypt(_entry_dir, _shm_folder, _shm_entry, _gpg_com, _tmp_dir=path.expanduser('~/.config/sshyp/tmp/')): - # decrypts an entry to a temporary directory - if _shm_folder == 0 and _shm_entry == 0: - if quick_unlock_enabled == 'y': - _command = f"gpg --pinentry-mode loopback --passphrase '{whitelist_verify()}' -qd --output /dev/null " \ - f"{path.expanduser('~/.config/sshyp/lock.gpg')}" - else: - _command = f"{_gpg_com} -qd --output /dev/null {path.expanduser('~/.config/sshyp/lock.gpg')}" - elif quick_unlock_enabled == 'y': - _command = f"gpg --pinentry-mode loopback --passphrase '{whitelist_verify()}' -qd --output " \ - f"{_tmp_dir}{_shm_folder}/{_shm_entry} '{_entry_dir}.gpg'" + if quick_unlock_enabled == 'y': + _unlock_method = f"gpg --pinentry-mode loopback --passphrase '{whitelist_verify()}' -qd --output " else: - _command = f"{_gpg_com} -qd --output {_tmp_dir}{_shm_folder}/{_shm_entry} '{_entry_dir}.gpg'" + _unlock_method = f"{_gpg_com} -qd --output " + if _shm_folder == 0 and _shm_entry == 0: # quick lock file decryption + _output_target = f"/dev/null {path.expanduser('~/.config/sshyp/lock.gpg')}" + else: + _output_target = f"{_tmp_dir}{_shm_folder}/{_shm_entry} '{_entry_dir}.gpg'" try: - run(_command, shell=True, stderr=PIPE, check=True, close_fds=True) + run(_unlock_method + _output_target, shell=True, stderr=PIPE, check=True, close_fds=True) except CalledProcessError: print(f"\n\u001b[38;5;9merror: could not decrypt - ensure the correct gpg key is present\u001b[0m\n") if quick_unlock_enabled == 'y':