From 8e43fe1533edc9044ad787643e9ffcd932823330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Wed, 28 Feb 2018 15:53:33 +0100 Subject: [PATCH] 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. --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 9d11248..d409905 100644 --- a/main.py +++ b/main.py @@ -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 "