Skip to content

Commit

Permalink
Have securedrop-admin emit distinct error messages
Browse files Browse the repository at this point in the history
Don't emit "Signature verification failed" for multiple different error
branches, which makes it far more difficult to diagnose exactly what
step failed.

Fixes freedomofpress#7200.
  • Loading branch information
timini authored and legoktm committed Dec 20, 2024
1 parent 4ae955e commit 4acc8bb
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions admin/securedrop_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,31 +1066,24 @@ def update(args: argparse.Namespace) -> int:
and len(good_sig_matches) == 1
and bad_sig_text not in sig_result
):
# Finally, we check that there is no branch of the same name
# prior to reporting success.
# Check for duplicate branch name
cmd = ["git", "show-ref", "--heads", "--verify", f"refs/heads/{latest_tag}"]
try:
# We expect this to produce a non-zero exit code, which
# will produce a subprocess.CalledProcessError
subprocess.check_output(cmd, stderr=subprocess.STDOUT, cwd=args.root)
sdlog.info("Signature verification failed.")
sdlog.error("Update failed: Branch name collision detected")
return 1
except subprocess.CalledProcessError as e:
if "not a valid ref" in e.output.decode("utf-8"):
# Then there is no duplicate branch.
sdlog.info("Signature verification successful.")
else: # If any other exception occurs, we bail.
sdlog.info("Signature verification failed.")
else:
sdlog.error("Update failed: Git command error")
return 1
else: # If anything else happens, fail and exit 1
sdlog.info("Signature verification failed.")
else:
sdlog.error("Update failed: Invalid signature format")
return 1

except subprocess.CalledProcessError:
# If there is no signature, or if the signature does not verify,
# then git tag -v exits subprocess.check_output will exit 1
# and subprocess.check_output will throw a CalledProcessError
sdlog.info("Signature verification failed.")
sdlog.error("Update failed: Missing or invalid signature")
return 1

# Only if the proper signature verifies do we check out the latest
Expand Down Expand Up @@ -1256,3 +1249,4 @@ def main(argv: List[str]) -> None:

if __name__ == "__main__":
main(sys.argv[1:])

0 comments on commit 4acc8bb

Please sign in to comment.