[elbe-devel] [PATCH 3/8] pkgutils: fix DeprecationWarning: SHA1Hash
Manuel Traut
manut at linutronix.de
Fri Jan 5 22:35:30 CET 2018
The hashlist that is available since python-apt 1.1 should be used
instead. But the hashlist doesn't include a sha1sum. Use sha256sum
instead.
Keep old code cause HashList is not available in Debian/jessie
still used by the initvm.
Signed-off-by: Manuel Traut <manut at linutronix.de>
---
elbepack/pkgutils.py | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/elbepack/pkgutils.py b/elbepack/pkgutils.py
index 47d11cf9..ce5d7493 100644
--- a/elbepack/pkgutils.py
+++ b/elbepack/pkgutils.py
@@ -161,7 +161,12 @@ def get_initrd_uri(prj, defs, arch):
if not x.is_trusted:
return "", uri
- return r.sha1_hash, uri
+ # TODO remove r.sha256_hash path as soon as initvm is stretch or later
+ try:
+ return r.sha256_hash, uri
+ except DeprecationWarning:
+ hashval = r.hashes.find('SHA256')
+ return hashval, uri
else:
return get_initrd_uri_nonvirtapt(apt_sources, target_pkg, arch)
@@ -187,7 +192,7 @@ def get_dsc_size(fname):
def copy_kinitrd(prj, target_dir, defs, arch="default"):
try:
- sha1, uri = get_initrd_uri(prj, defs, arch)
+ sha256, uri = get_initrd_uri(prj, defs, arch)
except KeyError:
raise NoKinitrdException('no elbe-bootstrap package available')
return
@@ -218,15 +223,15 @@ def copy_kinitrd(prj, target_dir, defs, arch="default"):
"couldn't download elbe-bootstrap package")
return
- if len(sha1) > 0:
- m = hashlib.sha1()
+ if len(sha256) > 0:
+ m = hashlib.sha256()
with open(os.path.join(tmpdir, "pkg.deb"), "rb") as f:
buf = f.read(65536)
while len(buf) > 0:
m.update(buf)
buf = f.read(65536)
- if m.hexdigest() != sha1:
+ if m.hexdigest() != sha256:
raise NoKinitrdException('elbe-bootstrap failed to verify !!!')
else:
print("-----------------------------------------------------")
--
2.15.1
More information about the elbe-devel
mailing list