tobischo / gokeepasslib

A library to read and write keepass 2 files written in go
MIT License
251 stars 30 forks source link

Possibility to change database format #49

Closed korovan-software closed 4 years ago

korovan-software commented 5 years ago

Hello! Would be great to see ability to change encryption algorithm and database format (KDBX3/KDBX4) like in original KeePass application.

tobischo commented 5 years ago

The purpose of the library is to allow reading and writing files so that you may access it as you see fit by writing a program that uses this library.

The original KeePass application has a higher range of responsibility in that regard than this library. Therefore a lot of convenience functions are not part of this library.

In an encrypted KeePass file, you are free to change password, algorithm, etc. as you see fit. This is stored in the file headers, which you can replace. Additionally you would have to adapt all the TimeWrapper values as they also keep the Formatted flag to differentiate between KDBX3 and KDBX4 format.

https://github.com/tobischo/gokeepasslib/blob/ca16913f489fcf3b96cff4b206741a7515042cb2/header.go#L67-L80

I could imagine a convenience function which initializes new headers based on some parameters using the functional option pattern, e.g. by adapting: https://github.com/tobischo/gokeepasslib/blob/ca16913f489fcf3b96cff4b206741a7515042cb2/header.go#L112-L117

I am quite certain that I won't get around to building something like that in the next few weeks. If you do, feel free to contribute it back to this repo.

korovan-software commented 5 years ago

Ok, thanks for clarification. I'll try to extend functional.

tobischo commented 4 years ago

With the recent change to overwrite the format of time wrapper fields this would be partially covered now. The main thing missing should be the possibility to initialize new headers for the format version through a convenience function.

korovan-software commented 4 years ago

Yes, I almost understood how it designed. Unfortunately there is not so much free time now, but I plan some day to make it done.

tobischo commented 4 years ago

I added support for KDBXv4 header initialization now https://github.com/tobischo/gokeepasslib/blob/07e4534c0f4945b84b765ea657995e59f44a0d5b/header.go#L131 This generally a new set of headers would allow migrating from a KDBXv3 file to a KDBXv4 file. Additionally I added support to initialize a new DB directly as KDBXv4. https://github.com/tobischo/gokeepasslib/blob/07e4534c0f4945b84b765ea657995e59f44a0d5b/database_test.go#L76-L96 This is released as v3.1.0. As previously it is possible to just setup the headers as needed and get around those convenience functions.

Please let me know if that fulfill your requirements

korovan-software commented 4 years ago

Thanks a lot, this is great news! I think this is enough for my purposes