How to use pykeepass - 10 common examples

To help you get started, we’ve selected a few pykeepass examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libkeepass / pykeepass / pykeepass / kdbx_parsing / kdbx4.py View on Github external
if context._._.transformed_key is not None:
        transformed_key = context._._.transformed_key
    elif kdf_parameters['$UUID'].value == kdf_uuids['argon2']:
        transformed_key = argon2.low_level.hash_secret_raw(
            secret=key_composite,
            salt=kdf_parameters['S'].value,
            hash_len=32,
            type=argon2.low_level.Type.D,
            time_cost=kdf_parameters['I'].value,
            memory_cost=kdf_parameters['M'].value // 1024,
            parallelism=kdf_parameters['P'].value,
            version=kdf_parameters['V'].value
        )
    elif kdf_parameters['$UUID'].value == kdf_uuids['aeskdf']:
        key_composite = compute_key_composite(
            password=context._._.password,
            keyfile=context._._.keyfile
        )
        transformed_key = aes_kdf(
            kdf_parameters['S'].value,
            kdf_parameters['R'].value,
            key_composite
        )
    else:
        raise Exception('Unsupported key derivation method')

    return transformed_key
github libkeepass / pykeepass / pykeepass / kdbx_parsing / kdbx4.py View on Github external
def compute_transformed(context):
    """Compute transformed key for opening database"""

    key_composite = compute_key_composite(
        password=context._._.password,
        keyfile=context._._.keyfile
    )
    kdf_parameters = context._.header.value.dynamic_header.kdf_parameters.data.dict

    if context._._.transformed_key is not None:
        transformed_key = context._._.transformed_key
    elif kdf_parameters['$UUID'].value == kdf_uuids['argon2']:
        transformed_key = argon2.low_level.hash_secret_raw(
            secret=key_composite,
            salt=kdf_parameters['S'].value,
            hash_len=32,
            type=argon2.low_level.Type.D,
            time_cost=kdf_parameters['I'].value,
            memory_cost=kdf_parameters['M'].value // 1024,
            parallelism=kdf_parameters['P'].value,
github libkeepass / pykeepass / tests / tests.py View on Github external
def open(self):
        self.kp = PyKeePass(
            os.path.join(base_dir, 'test_attachment.kdbx'),
            password=self.password,
            keyfile=os.path.join(base_dir, self.keyfile)
        )
github libkeepass / pykeepass / tests / tests.py View on Github external
def test_ctx_manager(self):
        with PyKeePass(os.path.join(base_dir, 'test4.kdbx'), password='password', keyfile=base_dir + '/test4.key') as kp:
            results = kp.find_entries_by_username('foobar_user', first=True)
            self.assertEqual('foobar_user', results.username)
github libkeepass / pykeepass / tests / tests.py View on Github external
def setUp(self):
        self.kp = PyKeePass(
            os.path.join(base_dir, self.database),
            password=self.password,
            keyfile=os.path.join(base_dir, self.keyfile)
        )
github libkeepass / pykeepass / tests / tests.py View on Github external
def test_open_error(self):
        with self.assertRaises(CredentialsIntegrityError):
            database = 'test4.kdbx'
            invalid_password = 'foobar'
            keyfile = os.path.join(base_dir, 'test4.key')
            PyKeePass(
                os.path.join(base_dir, database),
                password=invalid_password,
                keyfile=keyfile
            )
        with self.assertRaises(CredentialsIntegrityError):
            database = 'test4.kdbx'
            password = 'password'
            invalid_keyfile = os.path.join(base_dir, 'test3.key')
            PyKeePass(
                os.path.join(base_dir, database),
                password=password,
                keyfile=invalid_keyfile
            )
github libkeepass / pykeepass / tests / tests.py View on Github external
def setUp(self):
        shutil.copy(
            os.path.join(base_dir, self.database),
            os.path.join(base_dir, 'change_creds.kdbx')
        )
        self.kp = PyKeePass(
            os.path.join(base_dir, self.database),
            password=self.password,
            keyfile=os.path.join(base_dir, self.keyfile)
        )
        self.kp_tmp = PyKeePass(
            os.path.join(base_dir, 'change_creds.kdbx'),
            password=self.password,
            keyfile=os.path.join(base_dir, self.keyfile)
        )
github libkeepass / pykeepass / tests / tests.py View on Github external
def test_set_and_get_fields(self):
        time = datetime.now().replace(microsecond=0)
        changed_time = time + timedelta(hours=9)
        changed_string = 'changed_'
        entry = Entry(
            'title',
            'username',
            'password',
            url='url',
            notes='notes',
            tags='tags',
            expires=True,
            expiry_time=time,
            icon=icons.KEY,
            kp=self.kp
        )
        entry.title = changed_string + 'title'
        entry.username = changed_string + 'username'
        entry.password = changed_string + 'password'
        entry.url = changed_string + 'url'
        entry.notes = changed_string + 'notes'
github libkeepass / pykeepass / tests / tests.py View on Github external
def test_find_entries_by_uuid(self):
        uu = uuid.UUID('cc5f7ecd-2a00-48ca-9621-c222a347b0bb')
        results = self.kp.find_entries_by_uuid(uu)[0]
        self.assertIsInstance(results, Entry)
        self.assertEqual(uu, results.uuid)
        self.assertEqual('foobar_user', results.username)
github libkeepass / pykeepass / tests / tests.py View on Github external
def test_expired_datetime_offset(self):
        """Test for https://github.com/pschmitt/pykeepass/issues/115"""
        future_time = datetime.now() + timedelta(days=1)
        past_time = datetime.now() - timedelta(days=1)
        entry = Entry(
            'title',
            'username',
            'password',
            expires=True,
            expiry_time=future_time,
            kp=self.kp
        )
        self.assertFalse(entry.expired)

        entry.expiry_time = past_time
        self.assertTrue(entry.expired)