pkglistgen: handle published repos using sha512 nistead of sha256

Fixes https://github.com/openSUSE/openSUSE-release-tools/issues/2938
This commit is contained in:
Dominique Leuenberger 2023-03-15 11:42:28 +01:00
parent 143a171253
commit f2b7fb69e4
Signed by untrusted user: dimstar
GPG Key ID: 14C1CBBAC1E4B014

View File

@ -74,7 +74,13 @@ def parse_repomd(repo, baseurl):
root = ET.fromstring(repomd.content) root = ET.fromstring(repomd.content)
primary_element = root.find('.//r:data[@type="primary"]', ns) primary_element = root.find('.//r:data[@type="primary"]', ns)
location = primary_element.find('r:location', ns).get('href') 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 = tempfile.TemporaryFile()
f.write(repomd.content) f.write(repomd.content)
@ -85,9 +91,13 @@ def parse_repomd(repo, baseurl):
with requests.get(url, stream=True) as primary: with requests.get(url, stream=True) as primary:
if primary.status_code != requests.codes.ok: if primary.status_code != requests.codes.ok:
raise Exception(url + ' does not exist') raise Exception(url + ' does not exist')
sha256 = hashlib.sha256(primary.content).hexdigest() if sha256_or_512 == 512:
if sha256 != sha256_expected: sha = hashlib.sha512(primary.content).hexdigest()
raise Exception('checksums do not match {} != {}'.format(sha256, sha256_expected)) 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)) content = gzip.GzipFile(fileobj=io.BytesIO(primary.content))
os.lseek(f.fileno(), 0, os.SEEK_SET) os.lseek(f.fileno(), 0, os.SEEK_SET)