3

How can I query whether the GNOME keyring is unlocked or not from the terminal? I looked at this question which asks how to lock the keyring and one of the answers shows how to do this using DBus. My question is now if something similar can be done but for just querying the status.

I'm asking this in order to have a small status icon showing if the keyring is unlocked or not.

1 Answer 1

3

Each secret collection (i.e. keyring) has a "Locked" property. You can retrieve object properties by calling Get() on the org.freedesktop.DBus.Properties interface:

$ busctl --user introspect org.freedesktop.secrets \
                           /org/freedesktop/secrets/collection/login
NAME                                TYPE      SIGNATURE      RESULT/VALUE
org.freedesktop.DBus.Properties     interface -              -
.Get                                method    ss             v
org.freedesktop.Secret.Collection   interface -              -
.Label                              property  s              "Login"
.Locked                             property  b              false

$ busctl --user get-property org.freedesktop.secrets \
                             /org/freedesktop/secrets/collection/login \
                             org.freedesktop.Secret.Collection Locked
b false
$ gdbus introspect -e -d org.freedesktop.secrets \
                      -o /org/freedesktop/secrets/collection/login
node /org/freedesktop/secrets/collection/login {
  interface org.freedesktop.DBus.Properties {
    methods:
      Get(in  s interface_name,
          in  s property_name,
          out v value);
  };
  interface org.freedesktop.Secret.Collection {
    properties:
      readonly b Locked = false;
  };
};

$ gdbus call -e -d org.freedesktop.secrets \
                -o /org/freedesktop/secrets/collection/login \
                -m org.freedesktop.DBus.Properties.Get \
                   org.freedesktop.Secret.Collection Locked
(<false>,)

You can also receive property change notifications through the PropertiesChanged signal (depending on programming language, your D-Bus library might provide a wrapper for this).

2
  • Thanks you for your reply @user1686! When I run the first command there are no entries. Any idea why that could be? Jan 20, 2021 at 11:37
  • 1
    The keyring (collection) might be named differently, see busctl --user tree org.freedesktop.secrets or the somewhat more verbose gdbus introspect -e -d org.freedesktop.secrets -o / -r -p for a list of all objects provided by that service. Jan 20, 2021 at 11:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .