Ejemplo n.º 1
0
    def password_loop(self, filename):
        '''Loops until the correct password is entered'''
        attempts = 0
        while attempts < 3:
            password = input('Please enter password to unlock ({0} attempts remaining):  '.format(3-attempts))
            try:
                with open(filename,'rb') as enc_data:
                    encrypted = pickle.load(enc_data)
                    data = self.keyloader.unlock_with_password(password, encrypted)
                    self.crypto.load(data['privateKey'])
                    Display.log('User settings loaded.')
                    return
            except:
                Display.warn('Wrong password')
                attempts += 1

        Display.error('You have exceeded the number of attempts to log in as this user.')
        sys.exit(1)
Ejemplo n.º 2
0
    def send(self, message, target_node, msg_type):
        '''Actually send an encoded json message to the location and port'''
        # Gather the target's location and port
        location, port = target_node.location.split(':')
        #Display.subtle('Sending a {1} to {0} ({2})'.format(target_node.alias, msg_type, target_node.location))

        status = ''
        try:
            headers = {'Accept': 'application/json', 'Content-Type': 'application/json', "Connection": "close"}
            with requests.Session() as s:
                payload = {"message" : message}
                url = 'http://{0}:{1}'.format(location, port)
                r = requests.post(url, json=payload, headers=headers, timeout=1.0)
        except Exception as msg:
            # Flag that we encountered an error
            status = 'Excepted'

        if status == 'Excepted':
            status = self.try_relay(target_node.uid, message)

        if status == 'Failed':
            Display.error('{1} could not be delivered to {0} ({2})'.format(target_node.alias, msg_type, target_node.location))
            if target_node.status != Node.Status.inactive:
                target_node.status = Node.Status.unknown