keepassxreboot / keepassxc

KeePassXC is a cross-platform community-driven port of the Windows application “Keepass Password Safe”.
https://keepassxc.org/
Other
21.22k stars 1.47k forks source link

Event notification service for autostart #4561

Open alaricljs opened 4 years ago

alaricljs commented 4 years ago

I have a set of apps/tools that start automatically with my window manager session in X. Some of these rely on KeepassXC via either SSH Agent, or Secret Service Integration. This doesn't work if the database isn't open so I'd like some way to have the auto-start process wait until the DB is open and then continue starting those apps.

Desired Behavior

Maybe this is covered by AutoOpen but I can't find complete documentation on that feature. Basically I'd like to have KeepassXC fire off a command when a DB is opened.

Context

During my X session startup I fire off a few things that behave poorly if my DB is not open: Nextcloud (relies on SSI integration and merrily fires off a re-auth if not there) SSH sessions (relies on SSH Agent)

These are use cases that I transitioned off of other tools like gnome-keyring that would already be live immediately post-auth to the X session manager.

droidmonkey commented 4 years ago

This seems like a niche edge use case to me. We have a dbus interface but only listen for commands, we don't post information or events. I suppose we could extend that.

alaricljs commented 4 years ago

Yes it's niche. I've worked around it by using --pw-stdin and a pipe script that throws keepassxc into the background after auth completes (enter is pressed). Breaks if you typo the password though.

Appreciate that you'll look into it.

rigrig commented 4 years ago

You can also use secret-tool (from libsecret-tools) to add a test entry to the secret service:

echo ok | secret-tool store --label="Unlock test entry" service keepassxc-unlock-test

and then use something like this to wait for KeepassXC to become unlocked

#!/bin/sh
echo -n "Waiting for KeepassXC to be unlocked..."
while [ "`secret-tool lookup service keepassxc-unlock-test 2>/dev/null`" != "ok" ]; do echo -n .; sleep 1;done
echo OK
rigrig commented 4 years ago

You can also use secret-tool (from libsecret-tools) to add a test entry to the secret service:

echo ok | secret-tool store --label="Unlock test entry" service keepassxc-unlock-test

and then wait for it to become available: ~/bin/wait-for-keepass:

#!/bin/sh
echo -n "Waiting for KeepassXC to be unlocked..."
while [ "`secret-tool lookup service keepassxc-unlock-test 2>/dev/null`" != "ok" ]; do echo -n .; sleep 1;done
echo OK

Startup entry for Nextcloud: sh -c "wait-for-keepass && exec nextcloud"

jpathy commented 3 years ago

You can monitor for broadcast signal NameOwnerChanged from org.freedesktop.DBus:

> dbus-monitor --session \
"type=signal,sender=org.freedesktop.DBus,path=/org/freedesktop/DBus,interface=org.freedesktop.DBus,member=NameOwnerChanged,arg0=org.keepassxc.KeePassXC.MainWindow" 2>/dev/null

[....]
signal time=1625831031.357444 sender=org.freedesktop.DBus -> destination=(null destination) serial=1004 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameOwnerChanged
   string "org.keepassxc.KeePassXC.MainWindow"
   string ":1.278"
   string ""
[...]

You can then pipe this to awk/while loop to do your thing.