smorks / keepassnatmsg

KeePass plugin to expose credentials securely to a browser using Native Messaging
GNU General Public License v3.0
271 stars 26 forks source link

Debugging lost connection #87

Open xasbo opened 2 years ago

xasbo commented 2 years ago

Hi, I'm using the following stack:

KeePass 2.49 KeePassNatMsg 2.0.14.0 Chrome 96.0.4664.45 KeePassXC-Browser 1.7.10.1 Windows 10 Enterprise 20H2

I have Native Messaging Host installed for Chrome and Chromium (though I only use Chrome). Interesting, the plugin falsely detects Firefox and Thunderbird as being installed. I haven't changed any of the settings on the Advanced tab.

The setup does work, but periodically I find that the browser extension periodically reports "Cannot connect to KeePassXC. Check that browser integration is enabled in KeePassXC settings." This is typical on browser launch, but also recurs after reloading the extension, reconnecting to the database, unlocking the database, using the database, etc. I haven't yet been able to establish an obvious pattern of when this happens. It always seems to correct itself immediately when I reload the plugin, but it's not clear what makes it break in the first place.

I'm willing to do some legwork here to root cause this behavior, but I don't have any idea where to start. I would suspect either the KeePassXC-Browser or KeePassNatMsg, but am not sure what steps to take to debug or rule out either. Any suggestions?

edit: I noticed that issue #85 mentions behavior like this, but I can confirm that my keys are already saved and present on a fresh launch of KeePass. I'm not prompting about add a new key at any point, and after needing to click Reload on the browser extension, the correlating key does not change. These don't seem to be related to me.

smorks commented 2 years ago

Here are some steps that may give some more information:

  1. go to the menu in Chrome, then More tools -> Extensions.
  2. Turn on Developer mode in the top right hand corner
  3. Under KeePassXC-Browser, click on the "background page" link where it says "Inspect views background page"
  4. That should open a new window, or a new pane.
  5. At the top, you should see a tab called "Console". Some error messages should appear in there after you've got the "Cannot connect to KeePassXC" error, that may help in figuring out what the issue might be.
xasbo commented 2 years ago

Unfortunately, the extension log isn't any more helpful:

Error 5: Cannot connect to KeePassXC. Check that browser integration is enabled in KeePassXC settings. keepass.js:1187

The referenced line in keepass.js is the error handler, and there's a number of places that error 5, TIMEOUT_OR_NOT_CONNECTED, might fire from. There's no backtrace, so do I have unpack extension and put more logging in or what?

smorks commented 2 years ago

i don't think the unpack extension thing will help at all. i'm not sure what else to try, especially if there's nothing you can think of that is causing this to happen.

have you tried disabling all other extensions to see if that helps at all? i believe that if keepass is closed & re-opened while the browser thinks it's connected, it can cause weird issues.

i'll try and think of some other ways we can get to the root of this problem, and i'll let you know.

xasbo commented 2 years ago

i don't think the unpack extension thing will help at all. i'm not sure what else to try, especially if there's nothing you can think of that is causing this to happen.

My line of thinking was that I could try to expand the error handling in the extension. "Not connected" and "timed out" are lumped into a single error state, and I think it would be useful to understand if it was an active communication failure or if the pipe broken in the background. That was only from a brief foray into the extension JavaScript, though, so I could still be off-base. Is there any additional debug I can get out of KeePassNatMsg itself?

have you tried disabling all other extensions to see if that helps at all? i believe that if keepass is closed & re-opened while the browser thinks it's connected, it can cause weird issues.

I'll give that a shot. Generally, KeePass is running 100% of the time, I never intentionally close it. That said, since you mentioned it, I have noticed occasionally that it's not running when I expect it to be. Do you have any insight as to whether KeePass could be terminating silently for any reason? (exception, error occurred, whatever)

floviolleau commented 2 years ago

Hi,

Thanks for your work on making working the keepass stack with browsers!

I was using keepasshttp before but I faced to a blocking issue: https://github.com/pfn/keepasshttp/issues/371 keepasshttp recommends to use Firefox addon passifox but it is now not on the store. Same issue for Google Chrome addon

I was using as well https://addons.mozilla.org/en-US/firefox/addon/keepasshttp-connector/ which has been deprecated.

So I changed completely my stack and it looks like this now:

I face to the same issue mentioned

Thanks for helping here

xasbo commented 2 years ago

Just an update from my side - I paid extra attention for about a week after my last post while using both of the machines I have (matching configurations) and noticed that indeed every once in a while KeePass was either silently dying in the background, or possibly I inadvertently quit in the background. This seemed to account for that majority of the cases I ran into an issue with the extension, because I don't see it as often anymore. It still happens from time-to-time, but it's livable and digging around in the extension again I didn't find any great opportunity to extracting more information on the recurrances.

@floviolleau, I noticed you're running an older version of KeePass - I don't remember if anything specifically in change notes, but I haven't noticed the problem as much any more and - if there were silent crashes - upgrading may help.

floviolleau commented 2 years ago

@xasbo I'm taking keepass from Ubuntu depots so I cannot use a newer version.