dlech / KeeAgent

ssh agent plugin for KeePass 2.x
http://lechnology.com/software/keeagent
Other
522 stars 35 forks source link

Error loading key from attachment, "Attachment does not exist" and NullReferenceException #325

Closed nicoell closed 2 years ago

nicoell commented 2 years ago

Up front

My conclusion while investigating this issue is that "something" corrupted a specific entry in my KeyPass Database. Apparently, the file-content of the attachments (private and public key) of this entry got replaced with the contents of another entry in the same group. What followed is that KeeAgent seemingly behaved odd, as detailed below.

While it would be nice to find the core issue of what corrupted my entry, I don't know how I could track that down. I see many potential reasons, e.g. old KeePass version on another device, outdated plugins, synchronization with cloud.

So, I don't want to blame KeeAgent here, I rather thought telling this "story" could still be interesting. Even if it's just the insight that there is a case where GetSshKey can be called with getPrivateKeyStream returning null.

Manifestation of the issue

This error started to appear recently without any prior changes to entries with Keys. Since then it appears every time I load my KeyAgent database. image

Looking at the code, the function seems to expect the PrivateKeyStream to never be null, but it is: https://github.com/dlech/KeeAgent/blob/3caecd7ff40a3a282e51a61f4e8fdbbf7f093be2/KeeAgent/ExtensionMethods.cs#L206-L222

PrivateKey is null because "Attachment does not exist"

First, after pressing OK on above error, a dialogue pops up: image No further error appears on loading additional keys, but according to the Key Info Comment of entries with Keys, all of them fail to load with the reason: \<Error loading key from attachment>

For all my entries, the Private Key File Location is set to an attachment file (filenames pixelated in image below): I can open and view all File attachments without any problems: image

But, on pressing OK during "Edit Entry", a popup tells me "Attachment does not exist". image

This dialogue also prevents me from changing anything from the entry.

A new error appears

After disabling and enabling the flag for KeeAgent to use this Entry, the Key Info Comment still says \<Error loading key from attachment>, but I can change the entry without the "Attachment does not exist" popup.

But, on reopening the database, I now get a different error dialogue: image

The culprit of all this

After taking a closer look at the private key in the attachments, I noticed that it is not the correct private key. It is exactly the same private key as another entry within the same Group: My GitHub private key has become my GitLab private key. Same for the public key that I also saved in the attachments. I don't know how or when this happened and there is no valid previous version in the Entry History that I could restore, just one very old and outdated one without keys.

dlech commented 2 years ago

Is it possible you have two entries with the same UUID?

image

nicoell commented 2 years ago

No, all UUIDs are unique.

I have three more entries with scrambled attachments. They got randomized... Private Keys became KeeAgent settings, Public keys of one entry became the private key of another entries.

I did some more research and my best guess is that this was caused by KeyPassDX on Android. There were related issues reported: https://github.com/Kunzisoft/KeePassDX/issues/726

dlech commented 2 years ago

Thanks for the follow up. I'll go ahead and close since this doesn't seem like a KeeAgent issue.