如何从 secretstorage 集合中按标签查找密钥
How to find a key by label from secretstorage collection
我在 Python 2.7 中使用 Gtk3 的 GnomeKeyring,但几乎所有方法都已弃用 [1]。所以我尝试使用 SecretSecret.Collection [2]
import gi
gi.require_version('Secret', '1.0')
from gi.repository import Secret
>> ValueError: Namespace Secret not available
我找到了包 "python-secretstorage" [3],现在可以访问密钥环了:
import secretstorage
bus = secretstorage.dbus_init()
collection = secretstorage.get_default_collection(bus) ## login keyring
但是我怎样才能通过标签找到我正在搜索的键,这样我就不必遍历所有项目了?
items = collection.get_all_items()
for item in items:
if item.get_label() == "most_wanted_key":
return item
这是我试过的方法,但它不适用于标签,仅适用于属性。
found_items = collection.search_items({"label": "most_wanted_key"})
- https://lazka.github.io/pgi-docs/GnomeKeyring-1.0/functions.html
- https://lazka.github.io/pgi-docs/Secret-1/classes/Collection.html
- https://secretstorage.readthedocs.io/en/latest/
更新
https://specifications.freedesktop.org/secret-service/ch05.html
第 5 章查找属性
在查找期间,属性名称和值通过区分大小写的字符串相等性进行匹配。
...
要搜索项目,请使用服务接口的 SearchItems() 方法。
https://specifications.freedesktop.org/secret-service/re01.html#org.freedesktop.Secret.Service.SearchItems
我也不知道如何搜索标签,但是 AFAICT,标签是由 GUI 从其中一个属性设置的。这似乎对我查找网站凭据有用:
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()
打印的标签实际上与我搜索的相同,我认为这是使用 API 的预期方式。当然,关键在于找出要搜索的确切属性;对于另一个网站,标识 URL 存储在 "origin_url".
下
我在 Python 2.7 中使用 Gtk3 的 GnomeKeyring,但几乎所有方法都已弃用 [1]。所以我尝试使用 SecretSecret.Collection [2]
import gi
gi.require_version('Secret', '1.0')
from gi.repository import Secret
>> ValueError: Namespace Secret not available
我找到了包 "python-secretstorage" [3],现在可以访问密钥环了:
import secretstorage
bus = secretstorage.dbus_init()
collection = secretstorage.get_default_collection(bus) ## login keyring
但是我怎样才能通过标签找到我正在搜索的键,这样我就不必遍历所有项目了?
items = collection.get_all_items()
for item in items:
if item.get_label() == "most_wanted_key":
return item
这是我试过的方法,但它不适用于标签,仅适用于属性。
found_items = collection.search_items({"label": "most_wanted_key"})
- https://lazka.github.io/pgi-docs/GnomeKeyring-1.0/functions.html
- https://lazka.github.io/pgi-docs/Secret-1/classes/Collection.html
- https://secretstorage.readthedocs.io/en/latest/
更新
https://specifications.freedesktop.org/secret-service/ch05.html 第 5 章查找属性 在查找期间,属性名称和值通过区分大小写的字符串相等性进行匹配。 ... 要搜索项目,请使用服务接口的 SearchItems() 方法。 https://specifications.freedesktop.org/secret-service/re01.html#org.freedesktop.Secret.Service.SearchItems
我也不知道如何搜索标签,但是 AFAICT,标签是由 GUI 从其中一个属性设置的。这似乎对我查找网站凭据有用:
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()
打印的标签实际上与我搜索的相同,我认为这是使用 API 的预期方式。当然,关键在于找出要搜索的确切属性;对于另一个网站,标识 URL 存储在 "origin_url".
下