Fix cert digest calculation under python3.

Openssl's digest function takes a byte string on python2 and a unicode
string on python3. Use bytes_to_native_str for this conversion.
This commit is contained in:
poljar (Damir Jelić) 2018-02-28 15:53:33 +01:00
parent cd2788553c
commit 8e43fe1533

View file

@ -27,6 +27,7 @@ from itertools import chain
# pylint: disable=redefined-builtin
from builtins import str
from future.utils import bytes_to_native_str as n
# pylint: disable=unused-import
from typing import (List, Set, Dict, Tuple, Text, Optional, AnyStr, Deque, Any)
@ -94,8 +95,8 @@ def print_certificate_info(buff, sock, cert):
key_type = ("RSA" if public_key.type() == crypto.TYPE_RSA else "DSA")
key_size = str(public_key.bits())
sha256_fingerprint = x509.digest(b"SHA256").replace(":", "")
sha1_fingerprint = x509.digest(b"SHA1").replace(":", "")
sha256_fingerprint = x509.digest(n(b"SHA256"))
sha1_fingerprint = x509.digest(n(b"SHA1"))
signature_algorithm = x509.get_signature_algorithm()
key_info = ("key info: {key_type} key {bits} bits, signed using "