示例#1
0
def set_up():
    #mocking the user input
    iou.my_input  = lambda _:'yes'
    iou.my_output = lambda message,_=False: print(message)
    
    path = os.path.dirname(__file__)
    conf_file = os.path.join(path,'data','test_integration.json')
    conf_data = get_configuration(conf_file)
    parameters.set_data(conf_data) 
    du.insert_secret(DOMAIN, ACCESS, UID, PWD, INFO, MEM)
    
    p =Process(target=my_session, args =(MEM, 60, 10))
    p.start()
       
    yield conf_file
            
    iou.my_input = old_input
    iou.my_output = old_output
    iou.my_getpass = old_getpass
    du.delete_secret(DOMAIN,ACCESS)
    parameters.clear()
    set_configuration_data(conf_data, conf_file) 
    
    if is_connected():
        stop_service()
    p.terminate()    
示例#2
0
def get_memorable_password(tested = False):
    """Get the memorable password, either from the live session or from the client prompt.
    input:
    tested    a boolean flag. If true then the password strength is ensured 
              and the password is checked against a second entry
    output:
    return a pair of values (memorable, need_session) where memorable is the
    memorable password and need_session is a flag that tells if a new session needs to be started. 
    """
    memorable = None
    if parameters.is_in_shell(): #in shell mode the password is kept in memory in the parameters 
        memorable = parameters.get_memorable_pwd()
        if memorable is not None:
            return (memorable, False)
        else:
            if tested:
                memorable = get_password("Enter the memorable password", PWD_ATTEMPTS)
            else:
                memorable = get_password_untested("Enter the memorable password")
            parameters.set_memorable_pwd(memorable)
            
            return (memorable, False)                
    elif sc.is_connected(): #in bash shell the password is kept in a separate process
        res = sc.get_session_password()
        if res[0] == 'fresh':
            return (res[1], False)
        else:
            if tested:
                memorable = get_password("Enter the memorable password", PWD_ATTEMPTS)
            else:
                memorable = get_password_untested("Enter the memorable password")
            sc.set_session_password(memorable)
            return (memorable, False)
    else: #session not running
        if tested:
            memorable = get_password("Enter the memorable password", PWD_ATTEMPTS)
        else:
            memorable = get_password_untested("Enter the memorable password")
        return (memorable,True)
示例#3
0
    def client(self):
        """ Client command to invoke the background session. This is for testing only. The action allows to get the session value,
            set the value, stop the background session and test if it is running
        """
        parser = argparse.ArgumentParser(description=self.client.__doc__,
                                         prog='secretwallet client')
        #optional arguments
        parser.add_argument('-a',
                            dest='action',
                            choices=['get', 'set', 'stop', 'test'],
                            help='The client action',
                            default='get')
        parser.add_argument('-v',
                            dest='value',
                            help='The value to store in the session',
                            default='not set')

        args = iou.my_parse(parser, sys.argv[2:])
        if args is None:
            return

        iou.my_output('Starting a secret wallet client with parameters %s' %
                      args)
        try:
            if args.action == 'get':
                iou.my_output((get_session_password()[0], '***'))
            elif args.action == 'set':
                set_session_password(args.value)
            elif args.action == 'stop':
                stop_service()
            elif args.action == 'test':
                if is_connected():
                    iou.my_output('connected')
                else:
                    iou.my_output('not connected')
        except Exception as e:
            iou.my_output(repr(e))
示例#4
0
def test_lifetime(set_up):
    sleep(7)
    assert not is_connected()
示例#5
0
def test_connection_status(set_up):
    sleep(1)
    assert is_connected()
    stop_service()
    sleep(1)
    assert not is_connected()
示例#6
0
    def reconf(self):
        """
           Reconfigures either the memorable or the device password. All secrets will be re-encryted with the changed password.
           It is not possible to change both passwords at the same time. Depending on the size of the wallet, this operation
           might take some time. A backup of the old table is also performed.
        """
        parser = argparse.ArgumentParser(description=self.reconf.__doc__,
                                         prog='secret_wallet reconf')
        #optional arguments
        parser.add_argument(
            '-m',
            '--memorable',
            action='store_true',
            default=False,
            help='Reconfigure secrets because of a change of memorable password'
        )
        parser.add_argument(
            '-d',
            '--device',
            action='store_true',
            default=False,
            help='Reconfigure secrets because of a change of device password')

        args = iou.my_parse(parser, sys.argv[2:])
        if args is None:
            return

        try:
            if args.memorable and args.device:
                print(
                    "You can't reconfigure both memorable and device password at the same time"
                )
            elif args.memorable:
                iou.my_output("You are reconfiguring the memorable password")
                if is_connected():
                    stop_service()
                iou.display_reconfiguration_warning()

                iou.my_output('***Enter the existing memorable password***')
                old_memorable, _ = pm.get_memorable_password(False)
                iou.my_output('***Set the new memorable password***')
                new_memorable, _ = pm.get_memorable_password(True)
                reconf_memorable(list_secrets(None), old_memorable,
                                 new_memorable, True)
            elif args.device:
                iou.my_output("You are reconfiguring the device password")
                if is_connected():
                    stop_service()
                iou.display_reconfiguration_warning()

                iou.my_output('***Enter the existing memorable password***')
                old_memorable, _ = pm.get_memorable_password(False)
                iou.my_output('***Set the new device password***')
                new_device, _ = pm.get_memorable_password(True)
                reconf_salt_key(list_secrets(None), old_memorable, new_device,
                                True)

                #now pass it to the configuration file
                ekey = encrypt_key(new_device)
                cdata = get_configuration()
                cdata['key'] = ekey
                set_configuration_data(cdata)
        except Exception as e:
            iou.my_output(repr(e))