(certificate_der)
return certificate_hash
Get's the server's certificate hash for the tls-server-end-point
        channel binding.

        According to https://tools.ietf.org/html/rfc5929#section-4.1, this is
        calculated by
            Using the SHA256 is the signatureAlgorithm is MD5 or SHA1
            The signatureAlgorithm if the hash function is neither MD5 or SHA1

        :param certificate_der: The byte string of the server's certificate
        :return: The byte string containing the hash of the server's
            certificate
Get's the server's certificate hash for the tls-server-end-point
        channel binding.
Get s the server s certificate hash for the tls - server - end - point channel binding .
def _get_certificate_hash(certificate_der):
        """
        Get's the server's certificate hash for the tls-server-end-point
        channel binding.

        According to https://tools.ietf.org/html/rfc5929#section-4.1, this is
        calculated by
            Using the SHA256 is the signatureAlgorithm is MD5 or SHA1
            The signatureAlgorithm if the hash function is neither MD5 or SHA1

        :param certificate_der: The byte string of the server's certificate
        :return: The byte string containing the hash of the server's
            certificate
        """
        backend = default_backend()

        cert = x509.load_der_x509_certificate(certificate_der, backend)

        hash_algorithm = None
        try:
            hash_algorithm = cert.signature_hash_algorithm
        except UnsupportedAlgorithm as ex:
            warnings.warn("Failed to get the signature algorithm from the certificate due to: %s" % str(ex),
                          UnknownSignatureAlgorithmOID)

        # If the cert signature algorithm is unknown, md5, or sha1 then use sha256 otherwise use the signature
        # algorithm of the cert itself.
        if not hash_algorithm or hash_algorithm.name in ['md5', 'sha1']:
            digest = hashes.Hash(hashes.SHA256(), backend)
        else:
            digest = hashes.Hash(hash_algorithm, backend)

        digest.update(certificate_der)
        certificate_hash = digest.finalize()

        return certificate_hash
def _get_certificate_hash ( certificate_der ) : backend = default_backend ( ) cert = x509 . load_der_x509_certificate ( certificate_der , backend ) hash_algorithm = None try : hash_algorithm = cert . signature_hash_algorithm except UnsupportedAlgorithm as ex : warnings . warn ( "Failed to get the signature algorithm from the certificate due to: %s" % str ( ex ) , UnknownSignatureAlgorithmOID ) # If the cert signature algorithm is unknown, md5, or sha1 then use sha256 otherwise use the signature # algorithm of the cert itself. if not hash_algorithm or hash_algorithm . name in [ 'md5' , 'sha1' ] : digest = hashes . Hash ( hashes . SHA256 ( ) , backend ) else : digest = hashes . Hash ( hash_algorithm , backend ) digest . update ( certificate_der ) certificate_hash = digest . finalize ( ) return certificate_hash