Пример #1
0
def build_client_hello(tls_version, cipher_suites, session_ticket=None):
    """
    Build a ClientHello with the given TLS version, cipher suite, and optional
    session ticket.
    """

    client_hello_record = None

    # Build TLS ClientHello
    if tls_version > 0x0002:
        extensions = None
        if session_ticket:
            extensions = [TLS_Ext_SessionTicket(ticket=session_ticket)]
        tls_client_hello = TLSClientHello(version=tls_version,
                                          gmt_unix_time=int(time.time()),
                                          random_bytes=randstring(28),
                                          sidlen=0,
                                          ciphers=cipher_suites,
                                          complen=1,
                                          ext=extensions)
        client_hello_record = TLS(msg=[tls_client_hello])
    else:
        # SSLv2 ClientHello
        sslv2_client_hello = SSLv2ClientHello(version=tls_version,
                                              sidlen=0,
                                              ciphers=cipher_suites)
        client_hello_record = SSLv2(msg=[sslv2_client_hello])

    return client_hello_record
Пример #2
0
 def add_record(self, is_sslv2=None, is_tls13=None):
     """
     Add a new TLS or SSLv2 or TLS 1.3 record to the packets buffered out.
     """
     if is_sslv2 is None and is_tls13 is None:
         v = (self.cur_session.tls_version
              or self.cur_session.advertised_tls_version)
         if v in [0x0200, 0x0002]:
             is_sslv2 = True
         elif v >= 0x0304:
             is_tls13 = True
     if is_sslv2:
         self.buffer_out.append(SSLv2(tls_session=self.cur_session))
     elif is_tls13:
         self.buffer_out.append(TLS13(tls_session=self.cur_session))
     else:
         self.buffer_out.append(TLS(tls_session=self.cur_session))