Skip to content

Commit

Permalink
Support for CreatedDate and ModifiedDate
Browse files Browse the repository at this point in the history
  • Loading branch information
joergschultzelutter committed Mar 4, 2024
1 parent 45f2156 commit 87d7c8d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ Output should look like this:

```2023-11-27 17:47:04,686 enpasstokeepass -INFO- Saving Keepass database```

Note: unless you see the very last line ("`Saving Keepass database`"), your changes will not be written to the Keepass database.


Note: unless you see the very last line ("`Saving Keepass database`"), your changes will _not_ be written to the Keepass database.


## In Scope
Expand All @@ -63,7 +61,6 @@ Note: unless you see the very last line ("`Saving Keepass database`"), your chan
- The program expects an __existing__ Keepass file. It will __not__ create a new file for you. Additionally, I strongly suggest testing the conversion with an empty target database first.
- First-come-first-serve. Enpass permits e.g. multiple 'password' attributes per entry. For each type in (username, email, password, url), this converter uses the very first instance for creating the native Keepass key value. Occurrence 2..n will end up as regular attributes in the Keepass entry - regardless of whether they are e.g. a URL, email address or not. Note that the entries are copied 'as is' (just their respective field values WITHOUT any read protection). You may be forced to manually protect those additional password entries. Neither the Enpass export file gives any indication about their (previous) visibility protection state nor can that status be set via PyKeePass for the additional attributes.
- This program assumes that there will be 0...1 "totp" entries in the Enpass entry. In case Enpass should ever support more than one TOTP setting per entry (should never happen), only the very last entry survives in the Keepass target file.
- As part of the conversion, all entries will lose their original creation date as it does not seem to be possible to set that value via pykeepass
- The Keepass expiration date cannot be set as there is no distinct Enpass data type for it
- Enpass groups/sections within an enpass entry are NOT transferred to Keepass. Reason: they are exported as "empty" entries and apart from their order enumeration, there is no connection to the fields that are part of Enpass' export.
- The export process will always write NEW entries to Keepass. EXISTING entries will NOT be updated; if a key name conflict is detected (e.g. a key is to be written to Keepass, but it already exists), the code will attach the internal enpass UID to that field name.
Expand Down
19 changes: 18 additions & 1 deletion enpasstokeepass.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/opt/local/bin/python
import datetime

# Enpass-to-Keepass converter
# Author: Joerg Schultze-Lutter, 2021
Expand Down Expand Up @@ -281,6 +282,16 @@ def get_command_line_params():
# we reserve a 2nd dictionary
value_fields = {}

# Get the Unix timestamp for when the entry was last
# updated convert it to a Python DateTime object
updated_at_ux = myitem["updated_at"]
updated_at_dt = datetime.datetime.fromtimestamp(updated_at_ux)

# Get the Unix timestamp for when the entry was
# created and convert it to a Python DateTime object
created_at_ux = myitem["createdAt"]
created_at_dt = datetime.datetime.fromtimestamp(created_at_ux)

# Get the template type (Enpass' product category)
# if the template type ends with '.default', then this is a category
# without a subcategory
Expand Down Expand Up @@ -471,12 +482,18 @@ def get_command_line_params():
notes=mynotes,
tags=tags_to_export,
)

# set the original created_at / updated_at
# values from Enpass for our new entry
newentry.ctime = created_at_dt
newentry.mtime = updated_at_dt

# Add the extra properties (if present)
for value_field in value_fields:
# starting with pykeepass version 4.0.4, several attributes
# need to be handled differently
#
# First check if the key that we are about to write is
# First check if the key that we are about to write is~
# a reserved word. Note that the only remaining
# "reserved" key is an OTP entry - all other entries have
# already been amended by their respective uid's
Expand Down

0 comments on commit 87d7c8d

Please sign in to comment.