<commit_before># -*- coding: utf-8 -*-
"""Main classes for performing all the SSL connections within the plugins.
"""
from __future__ import absolute_import
from __future__ import unicode_literals

import random
import socket
from typing import Text
from typing import Optional
import struct
import time
from base64 import b64encode

from sslyze.ssl_settings import ClientAuthenticationCredentials

try:
    # Python 3
    # noinspection PyCompatibility
    from urllib.parse import quote
except ImportError:
    # Python 2
    # noinspection PyCompatibility
    from urllib import quote

from nassl import _nassl
from nassl.ssl_client import SslClient
from nassl.legacy_ssl_client import LegacySslClient
from nassl.ssl_client import ClientCertificateRequested, OpenSslVerifyEnum, OpenSslVersionEnum
from sslyze.utils.http_request_generator import HttpRequestGenerator

from sslyze.utils.http_response_parser import HttpResponseParser


class SSLHandshakeRejected(IOError):
    """The server explicitly rejected the SSL handshake.
    """
    pass


class StartTLSError(IOError):
    """The server rejected the StartTLS negotiation.
    """
    pass


class ProxyError(IOError):
    """The proxy was offline or did not return HTTP 200 to our CONNECT request.
    """
    pass


class SSLConnection(object):
    """Base SSL connection class which leverages an nassl.SslClient for performing the SSL handshake.
    """

    # The following errors mean that the server explicitly rejected the handshake. The goal to differentiate rejected
    # handshakes from random network errors such as the server going offline, etc.
    HANDSHAKE_REJECTED_SOCKET_ERRORS = {'was forcibly closed': 'Received FIN',
                                        'reset by peer': 'Received RST'}

    HANDSHAKE_REJECTED_SSL_ERRORS = {
        'sslv3 alert handshake failure': 'Alert handshake failure',
        'excessive message size': 'Excessive message size',
        'bad mac decode': 'Bad mac decode',
        'wrong version number': 'Wrong version number',
        'no cipher match': 'No cipher match',
        'bad decompression': 'Bad decompression',
        'peer error no cipher': 'Peer error no cipher',
        'no cipher list': 'No ciphers list',
        'insufficient security': 'Insufficient security',
        'block type is not 01': 'block type is not 01',  # Actually an RSA error
        'tlsv1 alert protocol version': 'Alert: protocol version ',
        'wrong ssl version' : 'Wrong SSL version',
        'tlsv1 alert decrypt error': 'Decrypt error',
<commit_msg>Tweak style<commit_after># -*- coding: utf-8 -*-
"""Main classes for performing all the SSL connections within the plugins.
"""
from __future__ import absolute_import
from __future__ import unicode_literals

import random
import socket
from typing import Text
from typing import Optional
import struct
import time
from base64 import b64encode

from sslyze.ssl_settings import ClientAuthenticationCredentials

try:
    # Python 3
    # noinspection PyCompatibility
    from urllib.parse import quote
except ImportError:
    # Python 2
    # noinspection PyCompatibility
    from urllib import quote

from nassl import _nassl
from nassl.ssl_client import SslClient
from nassl.legacy_ssl_client import LegacySslClient
from nassl.ssl_client import ClientCertificateRequested, OpenSslVerifyEnum, OpenSslVersionEnum
from sslyze.utils.http_request_generator import HttpRequestGenerator

from sslyze.utils.http_response_parser import HttpResponseParser


class SSLHandshakeRejected(IOError):
    """The server explicitly rejected the SSL handshake.
    """
    pass


class StartTLSError(IOError):
    """The server rejected the StartTLS negotiation.
    """
    pass


class ProxyError(IOError):
    """The proxy was offline or did not return HTTP 200 to our CONNECT request.
    """
    pass


class SSLConnection(object):
    """Base SSL connection class which leverages an nassl.SslClient for performing the SSL handshake.
    """

    # The following errors mean that the server explicitly rejected the handshake. The goal to differentiate rejected
    # handshakes from random network errors such as the server going offline, etc.
    HANDSHAKE_REJECTED_SOCKET_ERRORS = {
        'was forcibly closed': 'Received FIN',
        'reset by peer': 'Received RST'
    }

    HANDSHAKE_REJECTED_SSL_ERRORS = {
        'sslv3 alert handshake failure': 'Alert handshake failure',
        'excessive message size': 'Excessive message size',
        'bad mac decode': 'Bad mac decode',
        'wrong version number': 'Wrong version number',
        'no cipher match': 'No cipher match',
        'bad decompression': 'Bad decompression',
        'peer error no cipher': 'Peer error no cipher',
        'no cipher list': 'No ciphers list',
        'insufficient security': 'Insufficient security',
        'block type is not 01': 'block type is not 01',  # Actually an RSA error
        'tlsv1 alert protocol version': 'Alert: protocol version ',
        'wrong ssl version' : 'Wrong SSL version',
        'tlsv1 alert decrypt error': 'Decrypt error',

{'fraction_non_alphanumeric': 0.06983130639466457, 'fraction_numerical': 0.006669282071400549, 'mean_word_length': 3.6779816513761467, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1054295', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1343, 'n_words': 537}