mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-05-17 10:41:49 +02:00
FIXUP: Invalidate downloaded diffoci helper if checksum differs
This commit is contained in:
parent
6cf4c5cc46
commit
c1f25484ff
1 changed files with 17 additions and 5 deletions
|
@ -39,15 +39,27 @@ def git_verify(commit, source):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def diffoci_hash_matches(diffoci):
|
||||||
|
"""Check if the hash of the downloaded diffoci bin matches the expected one."""
|
||||||
|
m = hashlib.sha256()
|
||||||
|
m.update(DIFFOCI_PATH.open().read())
|
||||||
|
diffoci_checksum = m.hexdigest()
|
||||||
|
return diffoci_checksum == DIFFOCI_CHECKSUM
|
||||||
|
|
||||||
|
|
||||||
|
def diffoci_exists():
|
||||||
|
"""Check if the diffoci helper exists, and if the hash matches."""
|
||||||
|
if not DIFFOCI_PATH.exists():
|
||||||
|
return False
|
||||||
|
return diffoci_hash_matches(DIFFOCI_PATH.open().read())
|
||||||
|
|
||||||
|
|
||||||
def diffoci_download():
|
def diffoci_download():
|
||||||
"""Download the diffoci tool, based on a URL and its checksum."""
|
"""Download the diffoci tool, based on a URL and its checksum."""
|
||||||
with urllib.request.urlopen(DIFFOCI_URL) as f:
|
with urllib.request.urlopen(DIFFOCI_URL) as f:
|
||||||
diffoci_bin = f.read()
|
diffoci_bin = f.read()
|
||||||
|
|
||||||
m = hashlib.sha256()
|
if not diffoci_hash_matches(diffoci_bin):
|
||||||
m.update(diffoci_bin)
|
|
||||||
diffoci_checksum = m.hexdigest()
|
|
||||||
if not diffoci_checksum == DIFFOCI_CHECKSUM:
|
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Unexpected checksum for downloaded diffoci binary:"
|
"Unexpected checksum for downloaded diffoci binary:"
|
||||||
f" {diffoci_checksum} !={DIFFOCI_CHECKSUM}"
|
f" {diffoci_checksum} !={DIFFOCI_CHECKSUM}"
|
||||||
|
@ -122,7 +134,7 @@ def main():
|
||||||
commit = git_commit_get()
|
commit = git_commit_get()
|
||||||
git_verify(commit, args.source)
|
git_verify(commit, args.source)
|
||||||
|
|
||||||
if not DIFFOCI_PATH.exists():
|
if diffoci_exists():
|
||||||
logger.info(f"Downloading diffoci helper from {DIFFOCI_URL}")
|
logger.info(f"Downloading diffoci helper from {DIFFOCI_URL}")
|
||||||
diffoci_download()
|
diffoci_download()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue