Ejemplo n.º 1
0
    def state_S0(self, connect):
        message = connect.recv(4096)

        protocol_cd = message[:10]
        protocol_data = message[11:]
        self.test.assertEqual(protocol_cd, b'KEYSHARING')
        self.ephecc = ECC(pubkey=protocol_data)
        self.test.assertEqual(protocol_data, self.ephecc.get_pubkey())
 def state_S0(self, connect):
     message = connect.recv(4096)
     
     protocol_cd = message[:10]
     protocol_data = message[11:]
     self.test.assertEqual(protocol_cd, b'KEYSHARING')
     self.ephecc = ECC(pubkey=protocol_data)
     self.test.assertEqual(protocol_data, self.ephecc.get_pubkey())
Ejemplo n.º 3
0
class Test_Server_Client_S0(threading.Thread):
    def __init__(self, host, port, test, number):
        threading.Thread.__init__(self)
        self.host = host
        self.port = port
        self.test = test
        self.number = number

    def connect_to_server(self):
        time.sleep(1)  # Waiting server

        protocol = getattr(ssl, "PROTOCOL_TLSv1_2", False)
        if not protocol: protocol = getattr(ssl, "PROTOCOL_TLSv1_1", False)
        if not protocol: protocol = getattr(ssl, "PROTOCOL_TLSv1", False)
        if not protocol: protocol = getattr(ssl, "PROTOCOL_SSLv23", False)
        context = ssl.SSLContext(protocol)
        context.verify_mode = ssl.CERT_OPTIONAL
        context.check_hostname = False
        context.options |= ssl.OP_NO_SSLv2  # SSL v2 not allowed
        context.options |= ssl.OP_NO_SSLv3  # SSL v3 not allowed
        context.load_verify_locations(cafile=Configuration.certfile)
        connect = context.wrap_socket(
            socket.socket(socket.AF_INET, socket.SOCK_STREAM))
        connect.connect((self.host, self.port))

        self.sockname = connect.getsockname()
        print("Client", self.number, self.sockname,
              ": connection with the server")
        return connect

    def state_S0(self, connect):
        message = connect.recv(4096)

        protocol_cd = message[:10]
        protocol_data = message[11:]
        self.test.assertEqual(protocol_cd, b'KEYSHARING')
        self.ephecc = ECC(pubkey=protocol_data)
        self.test.assertEqual(protocol_data, self.ephecc.get_pubkey())

    def run(self):
        try:
            connect = self.connect_to_server()
            # State 0
            self.state_S0(connect)
        finally:
            connect.close()
            print("Client", self.number, self.sockname,
                  ": disconnection with the server")
class Test_Server_Client_S0(threading.Thread):
    def __init__(self, host, port, test, number):
        threading.Thread.__init__(self)
        self.host = host
        self.port = port
        self.test = test
        self.number = number
        
    def connect_to_server(self):
        time.sleep(1) # Waiting server
        
        protocol = getattr(ssl, "PROTOCOL_TLSv1_2", False)
        if not protocol: protocol = getattr(ssl, "PROTOCOL_TLSv1_1", False)
        if not protocol: protocol = getattr(ssl, "PROTOCOL_TLSv1", False)
        if not protocol: protocol = getattr(ssl, "PROTOCOL_SSLv23", False)
        context = ssl.SSLContext(protocol)
        context.verify_mode = ssl.CERT_OPTIONAL
        context.check_hostname = False
        context.options |= ssl.OP_NO_SSLv2 # SSL v2 not allowed
        context.options |= ssl.OP_NO_SSLv3 # SSL v3 not allowed
        context.load_verify_locations(cafile=Configuration.certfile)
        connect = context.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
        connect.connect((self.host, self.port))
        
        self.sockname = connect.getsockname()
        print("Client", self.number, self.sockname, ": connection with the server")
        return connect
    
    def state_S0(self, connect):
        message = connect.recv(4096)
        
        protocol_cd = message[:10]
        protocol_data = message[11:]
        self.test.assertEqual(protocol_cd, b'KEYSHARING')
        self.ephecc = ECC(pubkey=protocol_data)
        self.test.assertEqual(protocol_data, self.ephecc.get_pubkey())
        
    def run(self):
        try:
            connect = self.connect_to_server()
            # State 0
            self.state_S0(connect)
        finally:
            connect.close()
            print("Client", self.number, self.sockname, ": disconnection with the server")