From f2b7fb69e493a02810016dec41e2ff44f7262d37 Mon Sep 17 00:00:00 2001 From: Dominique Leuenberger Date: Wed, 15 Mar 2023 11:42:28 +0100 Subject: [PATCH] pkglistgen: handle published repos using sha512 nistead of sha256 Fixes https://github.com/openSUSE/openSUSE-release-tools/issues/2938 --- pkglistgen/update_repo_handler.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkglistgen/update_repo_handler.py b/pkglistgen/update_repo_handler.py index 21e6db87..2d803da2 100644 --- a/pkglistgen/update_repo_handler.py +++ b/pkglistgen/update_repo_handler.py @@ -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) @@ -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)