1

I used GnomeKeyring from Gtk3 with Python 2.7 but almost all methodes are deprecated [1]. So I tried to use SecretSecret.Collection [2]

import gi
gi.require_version('Secret', '1.0')
from gi.repository import Secret
>> ValueError: Namespace Secret not available

I found the package "python-secretstorage" [3] and can access the keyring now:

import secretstorage
bus = secretstorage.dbus_init()
collection = secretstorage.get_default_collection(bus)  ## login keyring

But how can I find the key I am searching for by label so I dont have to iterate over all item?

items = collection.get_all_items()
for item in items:
    if item.get_label() == "most_wanted_key":
        return item

Here is what I tried, but it don't works with the label, only with attribute(s).

found_items = collection.search_items({"label": "most_wanted_key"})
  1. https://lazka.github.io/pgi-docs/GnomeKeyring-1.0/functions.html
  2. https://lazka.github.io/pgi-docs/Secret-1/classes/Collection.html
  3. https://secretstorage.readthedocs.io/en/latest/

Update

https://specifications.freedesktop.org/secret-service/ch05.html Chapter 5. Lookup Attributes During a lookup, attribute names and values are matched via case-sensitive string equality. ... In order to search for items, use the SearchItems() method of the Service interface. https://specifications.freedesktop.org/secret-service/re01.html#org.freedesktop.Secret.Service.SearchItems

oxidworks
  • 1,563
  • 1
  • 14
  • 37

1 Answers1

1

I haven't figured out how to search for the label either, but AFAICT, the label is set from one of the attributes by the GUI. This seems to work for me to find website credentials:

import secretstorage
bus = secretstorage.dbus_init()
collection = secretstorage.get_default_collection(bus)  ## login keyring
search={u'action_url': u'https://testapp.example.com:8443/login'}
items = collection.search_items(search)
for item in items:
  print item.get_label()
  print item.get_secret()

The printed label is, in fact, identical to what I searched for, and I think this is the intended way to use the API. Of course, the twist is in figuring out the exact attribute to search for; for another website the identifying URL is stored under "origin_url".

BertD
  • 618
  • 8
  • 11
  • Thank you. Why do you think the label is set from an attribute? I set label with collection.create_item('LabelName', attributes, password'). But nevertheless I use now search_items with label in attributes, but I have to create item with extra attribute "key_label" by myself so I can search for. – oxidworks May 09 '18 at 12:30