Skip to content

Commit

Permalink
pkglistgen: handle published repos using sha512 nistead of sha256
Browse files Browse the repository at this point in the history
Fixes #2938
  • Loading branch information
DimStar77 committed Mar 15, 2023
1 parent 143a171 commit f2b7fb6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkglistgen/update_repo_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ def parse_repomd(repo, baseurl):
root = ET.fromstring(repomd.content)
primary_element = root.find('.//r:data[@type="primary"]', ns)
location = primary_element.find('r:location', ns).get('href')
sha256_expected = primary_element.find('r:checksum[@type="sha256"]', ns).text
sha256_or_512 = 0
try:
sha_expected = primary_element.find('r:checksum[@type="sha512"]', ns).text
sha256_or_512 = 512
except AttributeError:
sha_expected = primary_element.find('r:checksum[@type="sha256"]', ns).text
sha256_or_512 = 256

f = tempfile.TemporaryFile()
f.write(repomd.content)
Expand All @@ -85,9 +91,13 @@ def parse_repomd(repo, baseurl):
with requests.get(url, stream=True) as primary:
if primary.status_code != requests.codes.ok:
raise Exception(url + ' does not exist')
sha256 = hashlib.sha256(primary.content).hexdigest()
if sha256 != sha256_expected:
raise Exception('checksums do not match {} != {}'.format(sha256, sha256_expected))
if sha256_or_512 == 512:
sha = hashlib.sha512(primary.content).hexdigest()
else:
sha = hashlib.sha256(primary.content).hexdigest()

if sha != sha_expected:
raise Exception('checksums do not match {} != {}'.format(sha, sha_expected))

content = gzip.GzipFile(fileobj=io.BytesIO(primary.content))
os.lseek(f.fileno(), 0, os.SEEK_SET)
Expand Down

0 comments on commit f2b7fb6

Please sign in to comment.