Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements MasterKeyChangeForce Meta key #279

Closed
wants to merge 1 commit into from

Conversation

KeyWeeUsr
Copy link
Contributor

This PR implements the forceful password change trigger which happens once a person opens the DB in a KDBX-compatible UI tool.

Closes #269

@KeyWeeUsr
Copy link
Contributor Author

Simple example:

from pykeepass import create_database

db = create_database("db.kdbx")
assert db.password_change_force_days == -1
assert not db.needs_password_change
print(db.xml())

# open with the password for blank DB (embedded in the codebase) via UI tool
# no effect, close

# enforce password change
db.password_change_force_days = 0  # immediately
assert db.password_change_force_days == 0
assert db.needs_password_change
db.save()
print(db.xml())

# open with the password for blank DB (embedded in the codebase) via UI tool
# UI needs to enforce master password change immediately

@pschmitt
Copy link
Member

pschmitt commented Oct 6, 2021

lgtm

@KeyWeeUsr
Copy link
Contributor Author

@pschmitt Please approve it via Review changes if it's okay or add hacktoberfest-accepted label for it. Thanks! :)

@Evidlo
Copy link
Member

Evidlo commented Dec 15, 2021

We need to check when the masterkey was set for this to make sense. I don't see any datetime parsing happening here, so I don't understand how this is supposed to work.

These are the fields we need to read/set:

    <MasterKeyChanged>2017-06-17T00:38:50Z</MasterKeyChanged>
    <MasterKeyChangeRec>-1</MasterKeyChangeRec>
    <MasterKeyChangeForce>100</MasterKeyChangeForce>

So something like:

@property
def masterkey_change_required(self):
    change_date = self._decode_time(self._xpath('/KeePassFile/Meta/MasterKeyChanged'))
    max_days = self._xpath('/KeePassFile/Meta/MasterKeyChangeForce')
    return (datetime.now() - change_date).days > max_days

@property
def masterkey_change_recommended(self):
    change_date = self._decode_time(self._xpath('/KeePassFile/Meta/MasterKeyChanged'))
    max_days = self._xpath('/KeePassFile/Meta/MasterKeyChangeRec')
    return (datetime.now() - change_date).days > max_days

Also _decode_time should be moved out of BaseElement into PyKeePass.

And tests.

@Evidlo
Copy link
Member

Evidlo commented Dec 16, 2021

Looking at the keepass2 code linked above, I think the booleans bChangeRec and bChangeForce are just to determine whether the checkboxes in the settings menu are ticked or not when a database is loaded:

out

@Evidlo
Copy link
Member

Evidlo commented Jul 15, 2022

This was implemented in 9811ac0

@Evidlo Evidlo closed this Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for "Force master key change on next open"
3 participants