libkeepass / pykeepass

Python library to interact with keepass databases (supports KDBX3 and KDBX4)
https://pypi.org/project/pykeepass/
GNU General Public License v3.0
411 stars 96 forks source link

Change master seed on each save #366

Open A6GibKm opened 11 months ago

A6GibKm commented 11 months ago

Fixes: https://github.com/libkeepass/pykeepass/issues/219

A6GibKm commented 11 months ago

12 tests fail, with error

ERROR: test_set_credentials (__main__.PyKeePassTests4.test_set_credentials)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/home/deathwish/Projects/pykeepass/tests/tests.py", line 827, in test_set_credentials
    self.kp_tmp.save()
  File "/var/home/deathwish/Projects/pykeepass/pykeepass/pykeepass.py", line 179, in save
    raise e
  File "/var/home/deathwish/Projects/pykeepass/pykeepass/pykeepass.py", line 169, in save
    KDBX.build_file(
  File "/var/home/deathwish/.local/share/pyenv/versions/3.11.2/lib/python3.11/site-packages/construct/core.py", line 451, in build_file
    self.build_stream(obj, f, **contextkw)
  File "/var/home/deathwish/.local/share/pyenv/versions/3.11.2/lib/python3.11/site-packages/construct/core.py", line 441, in build_stream
    self._build(obj, stream, context, "(building)")
  File "/var/home/deathwish/.local/share/pyenv/versions/3.11.2/lib/python3.11/site-packages/construct/core.py", line 2229, in _build
    buildret = sc._build(subobj, stream, context, path)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/deathwish/.local/share/pyenv/versions/3.11.2/lib/python3.11/site-packages/construct/core.py", line 2742, in _build
    return self.subcon._build(obj, stream, context, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/deathwish/.local/share/pyenv/versions/3.11.2/lib/python3.11/site-packages/construct/core.py", line 4007, in _build
    keyfunc = evaluate(self.keyfunc, context)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/deathwish/.local/share/pyenv/versions/3.11.2/lib/python3.11/site-packages/construct/core.py", line 291, in evaluate
    return param(context) if callable(param) else param
           ^^^^^^^^^^^^^^
  File "/var/home/deathwish/.local/share/pyenv/versions/3.11.2/lib/python3.11/site-packages/construct/expr.py", line 188, in __call__
    return self.__parent(obj)[self.__field]
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

I suspect those are the ones that save.

A6GibKm commented 11 months ago

When saving, the newer value for the master seed is not taken into account by compute_header_hmac_hash