def _get_server_cert(response):
    """
    Get the certificate at the request_url and return it as a SHA256 hash. Will get the raw socket from the
    original response from the server. This socket is then checked if it is an SSL socket and then used to
    get the hash of the certificate. The certificate hash is then used with NTLMv2 authentication for
    Channel Binding Tokens support. If the raw object is not a urllib3 HTTPReponse (default with requests)
    then no certificate will be returned.

    :param response: The original 401 response from the server
    :return: SHA256 hash of the DER encoded certificate at the request_url or None if not a HTTPS endpoint
    """
    certificate_hash = None
    raw_response = response.raw

    if isinstance(raw_response, HTTPResponse):
        if sys.version_info > (3, 0):
            socket = raw_response._fp.fp.raw._sock
        else:
            socket = raw_response._fp.fp._sock

        try:
            server_certificate = socket.getpeercert(True)
        except AttributeError:
            pass
        else:
            hash_object = hashlib.sha256(server_certificate)
            certificate_hash = hash_object.hexdigest().upper()
    else:
        warnings.warn("Requests is running with a non urllib3 backend, cannot retrieve server certificate for CBT", NoCertificateRetrievedWarning)

    return certificate_hash
Get the certificate at the request_url and return it as a SHA256 hash. Will get the raw socket from the
    original response from the server. This socket is then checked if it is an SSL socket and then used to
    get the hash of the certificate. The certificate hash is then used with NTLMv2 authentication for
    Channel Binding Tokens support. If the raw object is not a urllib3 HTTPReponse (default with requests)
    then no certificate will be returned.

    :param response: The original 401 response from the server
    :return: SHA256 hash of the DER encoded certificate at the request_url or None if not a HTTPS endpoint