From ef483e03e55bee97d6e833aa957187337c0bcf8f Mon Sep 17 00:00:00 2001 From: ro Date: Mon, 27 Sep 2021 17:18:04 -0400 Subject: [PATCH] Include check for pre-4.19 Tails versions in network hook. Attempt to repair auto-updates on those systems. --- .../tails-config/files/securedrop_init.py | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/install_files/ansible-base/roles/tails-config/files/securedrop_init.py b/install_files/ansible-base/roles/tails-config/files/securedrop_init.py index bb930a6837..d8f1955603 100644 --- a/install_files/ansible-base/roles/tails-config/files/securedrop_init.py +++ b/install_files/ansible-base/roles/tails-config/files/securedrop_init.py @@ -7,7 +7,8 @@ import sys import subprocess -from shutil import copyfile +import tempfile +from shutil import copyfile, copyfileobj # check for root @@ -148,3 +149,70 @@ if b'Update needed' in output or os.path.exists(flag_location): # Start the SecureDrop updater GUI. subprocess.Popen(['python3', path_gui_updater], env=env) + +# Check for Tails < 4.19 and apply a fix to the auto-updater. +# See https://tails.boum.org/news/version_4.18/ +# (Suggested removal: 2022/01) +tails_4_min_version = 19 +needs_update = False +tails_current_version = None + +with open('/etc/os-release') as file: + for line in file: + try: + k, v = line.strip().split("=") + if k == "TAILS_VERSION_ID": + tails_current_version = v.strip("\"").split(".") + except ValueError: + continue + +if tails_current_version: + try: + needs_update = (len(tails_current_version) >= 2 and + int(tails_current_version[1]) < tails_4_min_version) + + except (TypeError, ValueError): + sys.exit(0) # Don't break tailsconfig trying to fix this + + if needs_update: + cert_name = 'isrg-root-x1-cross-signed.pem' + pem_file = tempfile.NamedTemporaryFile(delete=True) + + try: + subprocess.call(['torsocks', 'curl', '--silent', + 'https://tails.boum.org/' + cert_name], + stdout=pem_file, env=env) + + # Verify against /etc/ssl/certs/DST_Root_CA_X3.pem, which cross-signs + # the new LetsEncrypt cert but is expiring + verify_proc = subprocess.check_output(['openssl', 'verify', + '-no_check_time', '-no-CApath', + '-CAfile', + '/etc/ssl/certs/DST_Root_CA_X3.pem', + pem_file.name], + universal_newlines=True, env=env) + + if 'OK' in verify_proc: + + # Updating the cert chain requires sudo privileges + os.setresgid(0, 0, -1) + os.setresuid(0, 0, -1) + + with open('/usr/local/etc/ssl/certs/tails.boum.org-CA.pem', 'a') as chain: + pem_file.seek(0) + copyfileobj(pem_file, chain) + + # As amnesia user, start updater GUI + os.setresgid(amnesia_gid, amnesia_gid, -1) + os.setresuid(amnesia_uid, amnesia_uid, -1) + restart_proc = subprocess.call(['systemctl', '--user', 'restart', + 'tails-upgrade-frontend'], env=env) + + except subprocess.CalledProcessError: + sys.exit(0) # Don't break tailsconfig trying to fix this + + except IOError: + sys.exit(0) + + finally: + pem_file.close()