From 6b20b82dd53f19cf1a32bdd5095dbe4185d3b6f6 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Wed, 19 Oct 2022 11:34:02 -0400 Subject: [PATCH] Allow fallback to standard unlock if quick-unlock fails --- lib/sshyp.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/sshyp.py b/lib/sshyp.py index b25fe8d..da87d6d 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -157,15 +157,20 @@ def decrypt(_entry_dir, _shm_folder, _shm_entry, _gpg_com, _quick_enabled, run(_unlock_method + _output_target, shell=True, stderr=PIPE, check=True, close_fds=True) except CalledProcessError: if _quick_enabled == 'y': - _unlock_method = f"gpg --pinentry-mode loopback --passphrase '{whitelist_verify()}' -qd --output " try: - run(_unlock_method + _output_target, shell=True, stderr=PIPE, check=True, close_fds=True) + run(f"gpg --pinentry-mode loopback --passphrase '{whitelist_verify()}' -qd --output {_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 and that\n" - f"quick-unlock is properly configured on the server\u001b[0m\n") - s_exit(1) + print('\n\u001b[38;5;9merror: quick-unlock failed - falling back to standard unlock\n\nyour sshyp ' + 'server is unreachable or quick-unlock is incorrectly configured\u001b[0m\n') + try: + run(f"{_gpg_com} -qd --output {_output_target}", shell=True, stderr=PIPE, check=True, + close_fds=True) + except CalledProcessError: + print('\n\u001b[38;5;9merror: could not decrypt - ensure the correct gpg key is present\u001b[0m\n') + s_exit(1) else: - print(f"\n\u001b[38;5;9merror: could not decrypt - ensure the correct gpg key is present\u001b[0m\n") + print('\n\u001b[38;5;9merror: could not decrypt - ensure the correct gpg key is present\u001b[0m\n') s_exit(1)