Beispiel #1
0
            permission[0] = random.randint(0, 1)
            mb = {'middlebox_id': mbid, 'middlebox_permission': permission}
            settings.s_to_c_mb_list.append(mb)

        time1 = time.time()
        for i in range(number_of_connections):
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((server_ip, server_port))

            # now use sock to establish TLS 1.3 connection with the remote server
            connection = TLSConnection(sock)
            connection.handshakeClientCert(settings=settings)
            # send page request to server
            #request = bytearray()
            #request.append((amt >> 16) & 0xff)
            #request.append((amt >> 8) & 0xff)
            #request.append(amt & 0xff)
            #connection.sendall(request)
            while amt > blocksize:
                data = connection.recv(blocksize)
                amt = amt - blocksize
            if amt > 0:
                data = connection.recv(amt)
            # read page from server
            #response = connection.recv(amt)
            connection.close()

        time2 = time.time()
        page_load_time = (time2 - time1) / number_of_connections
        print 'page load time is ' + str(page_load_time) + ' second'
Beispiel #2
0
        settings.s_to_c_mb_list = []

        # client introduce server to client middleboxes
        for i in range(number_of_middleboxes):
            mbid = bytearray(os.urandom(64))
            permission = bytearray(1)
            permission[0] = random.randint(0, 1)
            mb = {'middlebox_id': mbid, 'middlebox_permission': permission}
            settings.s_to_c_mb_list.append(mb)

        time1 = time.time()
        for i in range(number_of_connections):
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((server_ip, server_port))

            # now use sock to establish TLS 1.3 connection with the remote server
            connection = TLSConnection(sock)
            connection.handshakeClientCert(settings=settings)
            # send page request to server
            request = bytearray()
            request.append((amt >> 16) & 0xff)
            request.append((amt >> 8) & 0xff)
            request.append(amt & 0xff)
            connection.sendall(request)
            # read page from server
            response = connection.recv(amt)
            connection.close()

        time2 = time.time()
        page_load_time = (time2 - time1) / number_of_connections
        print 'page load time is ' + str(page_load_time) + ' second'
Beispiel #3
0
        sock.sendall(request)

        # receive reply from socke 5 proxy
        failed_reply = b''
        failed_reply = failed_reply + b'\x05'  # version number
        failed_reply = failed_reply + b'\x01'  # general SOCKS server failure
        failed_reply = failed_reply + b'\x00'  # reserved
        failed_reply = failed_reply + b'\x01' + b'\x00' * 6

        reply = sock.recv(10)
        if len(reply) != 10:
            print 'reply length is not 10'
            print 'this should not happen'
        elif reply == failed_reply:
            print 'received failed reply'
        else:
            print 'received succeeded reply, socks 5 proxy established connection with the remote server'
            # now use sock to establish TLS 1.3 connection with the remote server
            connection = TLSConnection(sock)
            mb_utils.fake_handshakeClientCert(connection)
            # 2 \r\n
            connection.send("GET / HTTP/1.0\r\n\r\n")
            r = connection.recv(10240)
            if r in (0, 1):
                print 'received 0 or 1'
            elif isinstance(r, str):
                print 'received from server:'
                print r
            else:
                print 'f**k'
            #connection.close()
        settings.csibekey = bytearray(32)
        settings.c_to_s_mb_list = []
        settings.s_to_c_mb_list = []

        # client introduce server to client middleboxes
        for i in range(number_of_middleboxes):
            mbid = bytearray(os.urandom(64))
            permission = bytearray(1)
            permission[0] = random.randint(0, 1)
            mb = {'middlebox_id': mbid, 'middlebox_permission': permission}
            settings.s_to_c_mb_list.append(mb)

        #print settings
        print len(settings.c_to_s_mb_list)
        print len(settings.s_to_c_mb_list)

        connection.handshakeClientCert(settings=settings)

        handshake_msg_size = connection._recordLayer._recordSocket.data_sent + connection._recordLayer._recordSocket.data_received
        print 'handshake message size is: ' + str(
            handshake_msg_size) + ' bytes'
        # test data transfer
        # s = 'hello world ' * 100000
        # connection.sendall(s)

        count = 0
        for i in range(10):
            connection.sendall('hello world' * 1000)
            data = connection.recv(20000)
            count += len(data)
            print 'received ' + str(count) + ' bytes data'
Beispiel #5
0
        settings.keyShares = [curve_name]

        settings.maxVersion = (3, 3)  # tls 1.2
        settings.versions = [(3, 3)]
        #settings.number_of_middleboxes = number_of_middleboxes
        settings.print_debug_info = True

        cert_file = "tests/serverX509Cert.pem"
        s = open(cert_file, "rb").read()
        if sys.version_info[0] >= 3:
            s = str(s, 'utf-8')
        x509 = X509()
        x509.parse(s)
        cert_chain = X509CertChain([x509])
        middlebox_public_key = cert_chain.getEndEntityPublicKey()
        settings.middlebox_public_key = middlebox_public_key
        connection.middlebox_public_key = middlebox_public_key
        #connection.number_of_middleboxes = number_of_middleboxes

        connection.handshakeClientCert(settings=settings)

        amout = 1024 * 1024 * 5
        count = 0
        time1 = time.time()
        while count < amout:
            data = connection.recv(4096)
            count += len(data)
        time2 = time.time()
        result = 5 / (time2 - time1)
        print 'throughput is ' + str(result) + ' MB/s'
        connection.close()