[elbe-devel] [PATCH 3/8] pkgutils: fix DeprecationWarning: SHA1Hash

Torben Hohn torben.hohn at linutronix.de
Mon Jan 8 15:12:25 CET 2018


On Fri, Jan 05, 2018 at 10:35:30PM +0100, Manuel Traut wrote:
> 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>

Reviewed-by: Torben Hohn <torben.hohn 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
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel

-- 
Mit freundlichen Grüßen
Torben Hohn

Linutronix GmbH

Standort: Bremen

Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Firmensitz / Registered Office: D-88690 Uhldingen, Bahnhofstr. 3
Registergericht / Local District Court: Amtsgericht Freiburg i. Br.; HRB
Nr. / Trade register no.: 700 806

Geschäftsführer / Managing Directors: Heinz Egger, Thomas Gleixner

Eine Bitte von uns: Sollten Sie diese E-Mail irrtümlich erhalten haben,
benachrichtigen Sie uns in diesem Falle bitte sobald wie es Ihnen
möglich ist, durch Antwort-Mail. Vielen Dank!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.linutronix.de/pipermail/elbe-devel/attachments/20180108/52eca490/attachment.sig>


More information about the elbe-devel mailing list