Пример #1
0
def test_update_info_dict_remove_key(set_up):
    m_pwd = u"memorabile"
    domain = u"my_domain"
    access = u"my_access"
    secret_info = {'key1': 'value1', 'key2': 'value2'}
    salt = parameters.get_salt_key()
    try:
        ns = du.count_secrets()
        du.insert_secret(domain, access, None, None, secret_info, m_pwd,
                         parameters.get_salt_key())
        assert ns + 1 == du.count_secrets()
        res = du.get_secret(domain, access, m_pwd, salt,
                            False)  #no decryption of secret
        old_ts = res['timestamp']
        info = res['info']
        assert 2 == len(info)

        del info['key2']  #remove one entry
        du.update_secret_info_dictionary(domain, access, info)
        res = du.get_secret(domain, access, m_pwd, salt)
        ts = res['timestamp']
        info = res['info']
        assert 1 == len(info)
        assert 'value1' == info['key1']
        assert ts != old_ts

    finally:
        du.delete_secret(domain, access)
Пример #2
0
def test_update_missing_secret_no_effect(set_up):
    m_pwd = u"memorabile"
    domain = u"my_domain"
    access = u"my_access"
    access2 = u"my_second access"
    secret_uid = u"me@home"
    secret_pwd = u"ciao mamma"
    secret_pwd2 = u"my second password"
    secret_info = {'message': 'secret'}
    try:
        ns = du.count_secrets()
        du.insert_secret(domain, access, secret_uid, secret_pwd, secret_info,
                         m_pwd, parameters.get_salt_key())
        assert ns + 1 == du.count_secrets()
        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        old_ts = res['timestamp']
        assert 'secret' == res['info']['message']
        assert secret_pwd == res['pwd']
        assert secret_uid == res['uid']

        du.update_secret(domain, access2, None, secret_pwd2, None, None, m_pwd,
                         parameters.get_salt_key())

        assert ns + 1 == du.count_secrets()
        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        assert old_ts == res['timestamp']
    finally:
        du.delete_secret(domain, access)
Пример #3
0
def test_update_secret_info_change_password_and_a_value(set_up):
    m_pwd = u"memorabile"
    domain = u"my_domain"
    access = u"my_access"
    secret_uid = u"me@home"
    secret_pwd = u"ciao mamma"
    secret_pwd2 = u"another password"
    secret_info = {'message': 'secret'}
    info_key = 'message'
    info_val = 'a new secret'
    try:
        du.insert_secret(domain, access, secret_uid, secret_pwd, secret_info,
                         m_pwd, parameters.get_salt_key())
        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        old_ts = res['timestamp']
        assert 'secret' == res['info'][info_key]
        assert secret_pwd == res['pwd']

        du.update_secret(domain, access, None, secret_pwd2, info_key, info_val,
                         m_pwd, parameters.get_salt_key())

        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        assert info_val == res['info'][info_key]
        assert secret_pwd2 == res['pwd']
        assert old_ts < res['timestamp']
    finally:
        du.delete_secret(domain, access)
Пример #4
0
def test_update_secret_login(set_up):
    m_pwd = u"memorabile"
    secret_uid = u"me@home"
    secret_uid2 = u"me@office"
    secret_pwd = u"ciao mamma"
    domain = u"my_domain"
    access = u"my_access"
    try:
        ns = du.count_secrets()
        du.insert_secret(domain, access, secret_uid, secret_pwd, None, m_pwd,
                         parameters.get_salt_key())
        assert ns + 1 == du.count_secrets()
        assert du.has_secret(domain, access)
        old_ts = du.get_secret(domain, access, m_pwd,
                               parameters.get_salt_key())['timestamp']

        du.update_secret(domain, access, secret_uid2, None, None, None, m_pwd,
                         parameters.get_salt_key())

        assert ns + 1 == du.count_secrets(
        )  #no change to the number of secrets
        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        assert secret_uid2 == res['uid']
        assert secret_pwd == res['pwd']
        assert old_ts < res['timestamp']
    finally:
        du.delete_secret(domain, access)
Пример #5
0
def test_wrong_memorable(set_up):
    m_pwd = u"memorabile"
    domain = u"my_domain"
    access = u"my_access"
    secret_uid = u"me@home"
    secret_pwd = u"ciao mamma"
    try:
        du.insert_secret(domain, access, secret_uid, secret_pwd, None, m_pwd)
        with pytest.raises(cryptography.fernet.InvalidToken):
            du.get_secret(domain, access, 'pirillo')
    finally:
        du.delete_secret(domain, access)
Пример #6
0
def test_wrong_salt_key(set_up):
    c_pwd = 'pirillo'
    wrong_key = cu.encrypt_key(c_pwd)
    m_pwd = u"memorabile"
    domain = u"my_domain"
    access = u"my_access"
    secret_uid = u"me@home"
    secret_pwd = u"ciao mamma"
    try:
        du.insert_secret(domain, access, secret_uid, secret_pwd, None, m_pwd,
                         wrong_key)
        with pytest.raises(cryptography.fernet.InvalidToken):
            du.get_secret(domain, access, m_pwd)
    finally:
        du.delete_secret(domain, access)
Пример #7
0
    def get(self):
        """
            Retrieves the information stored inside a secret, as identified by the domain, access pair. These two fields need
            to be passed by using the -d and -a options
        """
        parser = argparse.ArgumentParser(description=self.get.__doc__,
                                         prog='secret_wallet get')
        #required arguments
        parser.add_argument('-d',
                            dest='domain',
                            required=True,
                            help='The domain (category) of the secret')
        parser.add_argument(
            '-a',
            dest='access',
            required=True,
            help='The sub=domain (sub-category or access) of the secret')

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

        iou.my_output('Running get with arguments %s' % args)
        try:
            memorable, need_session = pm.get_memorable_password(False)
            iou.display_secret(get_secret(args.domain, args.access, memorable))
            if need_session:
                start_my_session(memorable, parameters.get_session_lifetime(),
                                 parameters.get_session_timeout())
        except Exception as e:
            iou.my_output(repr(e))
Пример #8
0
def test_rename_secret(set_up):
    m_pwd = u"memorabile"
    domain = u"my_domain"
    access = u"my_access"
    new_domain = u"new_domain"
    new_access = u"new_access"
    info = {'message': 'secret'}
    try:
        #before
        assert not du.has_secret(domain, access)
        assert not du.has_secret(new_domain, new_access)
        #after insertion
        du.insert_secret(domain, access, None, None, info, m_pwd,
                         parameters.get_salt_key())
        assert du.has_secret(domain, access)
        assert not du.has_secret(new_domain, new_access)
        #after rename
        du.rename_secret(domain, access, new_domain, new_access)
        assert not du.has_secret(domain, access)
        assert du.has_secret(new_domain, new_access)
        res = du.get_secret(new_domain, new_access, m_pwd,
                            parameters.get_salt_key())
        assert info['message'] == res['info']['message']
    finally:
        du.delete_secret(domain, access)
        du.delete_secret(new_domain, new_access)
Пример #9
0
def test_reconf_memorable(set_up, insert_records):
    old_mem = "memorable"
    new_mem = 'another'
    secrets = du.list_secrets("d1") + du.list_secrets("d2")
    assert 3 == len(secrets)
    sec = du.get_secret('d1', 'a1', old_mem)
    assert "v1" == sec['info']['k1']

    du.reconf_memorable(secrets, old_mem, new_mem)
    secrets = du.list_secrets("d1") + du.list_secrets("d2")
    assert 3 == len(secrets)
    secrets = du.list_secrets("I") + du.list_secrets("D")
    assert 0 == len(secrets)
    sec = du.get_secret('d1', 'a1', new_mem)
    assert "v1" == sec['info']['k1']

    with pytest.raises(cryptography.fernet.InvalidToken):
        du.get_secret('d1', 'a1', old_mem)
Пример #10
0
def test_reconf_salt_key(set_up, insert_records):
    old_mem = "memorable"
    c_pwd = 'carpiato'
    new_salt_key = cu.encrypt_key(c_pwd)
    secrets = du.list_secrets("d1") + du.list_secrets("d2")
    assert 3 == len(secrets)
    sec = du.get_secret('d1', 'a1', old_mem)
    assert "v1" == sec['info']['k1']

    du.reconf_salt_key(secrets, old_mem, c_pwd, False)
    secrets = du.list_secrets("d1") + du.list_secrets("d2")
    assert 3 == len(secrets)
    secrets = du.list_secrets("I") + du.list_secrets("D")
    assert 0 == len(secrets)
    sec = du.get_secret('d1', 'a1', old_mem, new_salt_key)
    assert "v1" == sec['info']['k1']

    with pytest.raises(cryptography.fernet.InvalidToken):
        du.get_secret('d1', 'a1', old_mem)
Пример #11
0
def test_update_info(set_up):
    sleep(1)
    sys.argv=['secret_wallet','set','-d',DOMAIN, '-a', ACCESS, '-ik','first_key','-iv','first_value']
    Parser()
    sys.argv=['secret_wallet','set','-d',DOMAIN, '-a', ACCESS, '-ik','second_key','-iv','second_value']
    Parser()
    res = du.get_secret(DOMAIN, ACCESS, 'memorable', parameters.get_salt_key())
    assert 3 == len(res['info'])
    assert 'value' == res['info']['key']
    assert 'first_value' == res['info']['first_key']
    assert 'second_value' == res['info']['second_key']
Пример #12
0
def test_insert_select_compare_info(set_up):
    m_pwd = u"memorabile"
    secret_info = {'message': 'secret'}
    domain = u"my_domain"
    access = u"my_access"
    try:
        du.insert_secret(domain, access, None, None, secret_info, m_pwd,
                         parameters.get_salt_key())
        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        assert secret_info['message'] == res['info']['message']
    finally:
        du.delete_secret(domain, access)
Пример #13
0
def test_update_secret_info_change_value(set_up):
    m_pwd = u"memorabile"
    domain = u"my_domain"
    access = u"my_access"
    secret_info = {'message': 'secret'}
    info_key = 'message'
    info_val = 'a new secret'
    try:
        du.insert_secret(domain, access, None, None, secret_info, m_pwd,
                         parameters.get_salt_key())
        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        old_ts = res['timestamp']
        assert 'secret' == res['info'][info_key]

        du.update_secret(domain, access, None, None, info_key, info_val, m_pwd,
                         parameters.get_salt_key())

        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        assert info_val == res['info'][info_key]
        assert old_ts < res['timestamp']
    finally:
        du.delete_secret(domain, access)
Пример #14
0
def test_insert_select_compare_login(set_up):
    m_pwd = u"memorabile"
    secret_uid = u"me@home"
    secret_pwd = u"ciao mamma"
    domain = u"my_domain"
    access = u"my_access"
    try:
        du.insert_secret(domain, access, secret_uid, secret_pwd, None, m_pwd,
                         parameters.get_salt_key())
        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        assert secret_uid == res['uid']
        assert secret_pwd == res['pwd']
    finally:
        du.delete_secret(domain, access)
Пример #15
0
    def delete(self):
        """
            Deletes an existing secret, as identified by the domain, access pair. These two fields can
            be passed by using the -d and -a options. If only the domain is given, all secrets for that domain
            are deleted. When the -ik option is given with a key name, the corresponding entry
            in the info dictionary is removed, only if both domain and access are given and they identify an existing secret
        """
        parser = argparse.ArgumentParser(description=self.delete.__doc__,
                                         prog='secret_wallet delete')
        #required arguments
        parser.add_argument('-d',
                            dest='domain',
                            required=True,
                            help='The domain (category) of the secret')
        parser.add_argument(
            '-a',
            dest='access',
            help='The sub=domain (sub-category or access) of the secret')
        parser.add_argument('-ik',
                            '--info_key',
                            help='The key in an information map')

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

        iou.my_output('Running delete with arguments %s' % args)
        try:
            if args.domain is not None and args.access is not None and args.info_key is not None:
                iou.confirm_delete_key(args.domain, args.access, args.info_key)
                sec = get_secret(args.domain, args.access, None, None,
                                 False)  #no decryption
                info = sec['info']
                del info[args.info_key]
                update_secret_info_dictionary(args.domain, args.access, info)
            elif args.domain is not None and args.access is not None:
                iou.confirm_delete([(args.domain, args.access)])
                delete_secret(args.domain, args.access)
            else:
                secrets = list_secrets(args.domain)
                iou.confirm_delete(secrets)
                delete_secrets(secrets)
        except Exception as e:
            iou.my_output(repr(e))
Пример #16
0
    def qget(self):
        """
           Searches for secrets containig a given subtext in their domain or access names. Once a list of secrets
           that match the given pattern is found, thre secrets are tagged with a progressive number and the user can
           select the one to retrieve and display.
        """
        parser = argparse.ArgumentParser(description=self.qget.__doc__,
                                         prog='secret_wallet qget')

        parser.add_argument(
            'pattern',
            default=None,
            help=
            'A pattern that is searched both in the domain and the access field'
        )

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

        iou.my_output('Query secrets with arguments %s' % args)
        try:
            if (args.pattern is not None):
                secrets = query_secrets_by_pattern(args.pattern)
            sec = iou.get_secret_by_idx("List of secrets", secrets)
            if sec is None:
                return
            try:
                memorable, need_session = pm.get_memorable_password(False)
                iou.display_secret(get_secret(sec[0], sec[1], memorable))
                if need_session:
                    start_my_session(memorable,
                                     parameters.get_session_lifetime(),
                                     parameters.get_session_timeout())
            except Exception as e:
                iou.my_output(repr(e))

        except Exception as e:
            iou.my_output(repr(e))