Esempio n. 1
0
    def list_users(client_socket, parts):
        username = parts[1]
        signature = base64.b64decode(parts[2])

        user = User.load_user(username)
        client = ClientsStore.get_client(username)

        valid_signature = Cryptography.verify_signature(
            base64.b64decode(client['cert']).decode(), username, signature)

        if valid_signature:
            user_list = ClientsStore.list_users(username,
                                                user.get_clearance_level())
            encoded_list = pickle.dumps(user_list)
            client_socket.send(encoded_list)

        else:
            client_socket.send('UNAUTHORIZED'.encode())
Esempio n. 2
0
    def list_users(username, clearance_level):
        """
        Method to list the User's that are online and which clearance level is compatible with the asking user

        :param username: Username of the user that is asking for the list
        :param clearance_level: Clearance level of the user that is asking for the list
        :return: List of online users that the user can see
        """

        user_list = []
        for user in ClientsStore.__online:
            if user != username:
                if ClientsStore.is_online(username):
                    saved_user = User.load_user(user)
                    if saved_user.get_clearance_level() <= clearance_level:
                        user_entry = ClientsStore.get_client(user)
                        user_entry['username'] = user
                        user_list.append(user_entry)
        return user_list
Esempio n. 3
0
    def perform_operations(client_socket, parts):
        """
        Method to execute the privileged operations

        :param client_socket: Socket where a connection with a client is happening
        :param parts: Parts of the message that was sent by the client
        """

        username = parts[1]
        signature = base64.b64decode(parts[2])
        n = int(parts[3])
        number = int(parts[4])
        user = User.load_user(username)
        client = ClientsStore.get_client(username)

        valid_signature = Cryptography.verify_signature(
            base64.b64decode(client['cert']).decode(), username, signature)
        if n <= 0.0:
            client_socket.send('INVALID'.encode())
            return

        if valid_signature:
            clearance = user.get_clearance_level()
            if clearance == 1 and n > 2:
                client_socket.send('UNAUTHORIZED'.encode())
                return
            if clearance == 2 and n > 3:
                client_socket.send('UNAUTHORIZED'.encode())
                return
            if n == 2:
                result = Functions.square_root(number)
            elif n == 3:
                result = Functions.cubic_root(number)
            else:
                result = Functions.n_root(number, n)

            client_socket.send(str(result).encode())
        else:
            client_socket.send('UNAUTHORIZED'.encode())