示例#1
0
    def __init__(self, path, addr, key_controller, db_controller):
        self.addr = addr
        self.path = path
        self.key_controller = key_controller
        self.db = db_controller

        self.cmd_controller = CommandController(self.db)
        self.network = network_interface(self.path, self.addr)
        self.connection_state = 0
        self.client = Client()
        self.banned_clients = {}
示例#2
0
    def __init__(self, own_address, server_addr):
        self.server_addr = server_addr
        self.server_pub_key = self.load_server_public_key()
        self.conn_priv_key = self.generate_connection_keys()
        self.sym_key = b''
        self.own_address = own_address
        self.network_interface = network_interface(self.path, own_address)

        self.password = getpass("Enter your password:"******""
        self.connect_server(server_addr)
        self.wait_time = 0
示例#3
0
    def __init__(self, network_path, own_address):
        self.network_path = network_path
        self.own_address = own_address
        self.networkInterface = network_interface(network_path, own_address)

        self.shared_secret = b'shared_secret_' + own_address.encode(
            'utf-8') + b'_0123456789012345'  # TODO: fájblól beolvasni mint a szervernél...

        #########
        # STATE #
        #########
        self.connected_to_server = False
        self.server_address = ''
        self.session_key = ''
        self.sequence_number_client = -1
        self.sequence_number_server = -1
示例#4
0
    def __init__(self, network_path, own_address):
        self.network_path = network_path
        self.own_address = own_address
        self.networkInterface = network_interface(network_path, own_address)

        self.secret_encryption_key = 'secret_encryption_key'

        #########
        # STATE #
        #########
        self.connected_to_client = False
        self.active_client = ''
        self.session_key = b''
        self.shared_secret = b''
        self.sequence_number_server = -1
        self.sequence_number_client = -1
        self.currentDir = ''
def main(new_user):
    print('Beginning client side routine...')

    net_interface = network_interface(NET_PATH, OWN_ADDR)
    LOGGED_IN, nonce = initialize_login(net_interface, new_user)

    while LOGGED_IN:
        command = input('Enter a command: ')
        valid_command, nonce = send_command(command, nonce, net_interface)
        
        # process and validate server response to command
        if valid_command:
            status, command_response = net_interface.receive_msg(blocking=True)
            
            command_result = AES_decrypt(command_response, nonce)
            if (command[:3] != 'DNL'):
                print(command_result.decode('utf-8'))

            if (command[:3] == 'DNL' and command_result != 'Error: please check arguments and try again'):
                file_name = command.split(' ')[1]
                if decrypt_file(file_name, command_result):
                    print(file_name + ' successfully downloaded')

            nonce = increment_nonce(nonce)
示例#6
0
        NET_PATH = arg
    elif opt == '-a' or opt == '--addr':
        OWN_ADDR = arg

if (NET_PATH[-1] != '/') and (NET_PATH[-1] != '\\'): NET_PATH += '/'

if not os.access(NET_PATH, os.F_OK):
    print('Error: Cannot access path ' + NET_PATH)
    sys.exit(1)

if len(OWN_ADDR) > 1: OWN_ADDR = OWN_ADDR[0]

if OWN_ADDR not in network_interface.addr_space:
    print('Error: Invalid address ' + OWN_ADDR)
    sys.exit(1)

# main loop
netif = network_interface(NET_PATH, OWN_ADDR)
print('Main loop started...')
while True:
    # Calling receive_msg() in non-blocking mode ...
    #	status, msg = netif.receive_msg(blocking=False)
    #	if status: print(msg)      # if status is True, then a message was returned in msg
    #	else: time.sleep(2)        # otherwise msg is empty

    # Calling receive_msg() in blocking mode ...
    status, msg = netif.receive_msg(
        blocking=True
    )  # when returns, status is True and msg contains a message
    print(msg.decode('utf-8'))
示例#7
0
def main():
    print("Beginning server side routine...")

    net_interface = network_interface(NET_PATH, OWN_ADDR)
    nonce = initialize_session(net_interface)

    while True:
        status, msg = net_interface.receive_msg(blocking=True)
        if status:
            client_command = AES_decrypt(msg, nonce).split(' '.encode('utf-8'))
            command_code = client_command[0].decode('utf-8')
            nonce = increment_nonce(nonce)

            global WORKING_DIR

            if command_code == 'MKD':
                print('Making a directory in the server...')
                try:
                    directory_name = client_command[1].decode('utf-8')
                    nonce = make_directory(directory_name, net_interface,
                                           nonce)
                except:
                    error = AES_encrypt(
                        'Error: please check arguments and try again', nonce)
                    net_interface.send_msg(CLIENT_ADDR, error)
                    nonce = increment_nonce(nonce)

            elif command_code == 'RMD':
                print('Removing a directory in the server...')
                try:
                    directory_name = client_command[1].decode('utf-8')
                    nonce = remove_directory(directory_name, net_interface,
                                             nonce)
                except:
                    error = AES_encrypt(
                        'Error: please check arguments and try again', nonce)
                    net_interface.send_msg(CLIENT_ADDR, error)
                    nonce = increment_nonce(nonce)

            elif command_code == 'GWD':
                print('Getting working directory...')
                gwd_response = AES_encrypt(
                    'Current working directory is: ' + WORKING_DIR, nonce)
                net_interface.send_msg(CLIENT_ADDR, gwd_response)
                nonce = increment_nonce(nonce)

            elif command_code == 'CWD':
                print('Changing working directory...')
                try:
                    path_to_dir = client_command[1].decode('utf-8')
                    nonce, NEW_WORKING_DIR = change_working_dir(
                        path_to_dir, net_interface, nonce)
                    WORKING_DIR = NEW_WORKING_DIR
                except:
                    error = AES_encrypt(
                        'Error: please check arguments and try again', nonce)
                    net_interface.send_msg(CLIENT_ADDR, error)
                    nonce = increment_nonce(nonce)

            elif command_code == 'LST':
                print('Listing contents of directory...')
                dir_items = ", ".join(os.listdir(WORKING_DIR))
                lst_response = AES_encrypt(dir_items, nonce)
                net_interface.send_msg(CLIENT_ADDR, lst_response)
                nonce = increment_nonce(nonce)

            elif command_code == 'UPL':
                print('Uploading file to server...')
                file_name = client_command[1].decode('utf-8')
                file_data = client_command[2]
                nonce = upload_file(file_name, file_data, net_interface, nonce)

            elif command_code == 'DNL':
                print('Downloading file from server...')
                try:
                    file_name = client_command[1].decode('utf-8')
                    nonce = download_file(file_name, net_interface, nonce)
                except:
                    error = AES_encrypt(
                        'Error: please check arguments and try again', nonce)
                    net_interface.send_msg(CLIENT_ADDR, error)
                    nonce = increment_nonce(nonce)

            elif command_code == 'RMF':
                print('Removing file from server...')
                try:
                    file_name = client_command[1].decode('utf-8')
                    nonce = remove_file(file_name, net_interface, nonce)
                except:
                    error = AES_encrypt(
                        'Error: please check arguments and try again', nonce)
                    net_interface.send_msg(CLIENT_ADDR, error)
                    nonce = increment_nonce(nonce)
示例#8
0
def init_network(own_addr):
    return network_interface(network_path, own_addr)
示例#9
0
 def checkAndCreateInterface(self):
     if self.netIf is None:
         self.netIf = network_interface("../netsim/files/",
                                        "Z")  # Z is the server's address