如何从secretstorage集合中按标签查找密钥

2024-05-28 18:08:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python2.7中使用了Gtk3中的GnomeKeyring,但几乎所有的方法都不推荐使用[1]。所以我试着用秘密秘密收藏[2]

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

我找到了包“python secretstorage”[3],现在可以访问keyring了:

^{pr2}$

但是我怎样才能找到我要按标签搜索的键,这样我就不必遍历所有的项呢?在

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"})
  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/

更新

https://specifications.freedesktop.org/secret-service/ch05.html 第五章。查找属性 在查找过程中,属性名和值通过区分大小写的字符串相等进行匹配。 ... 要搜索项目,请使用服务接口的SearchItems()方法。 https://specifications.freedesktop.org/secret-service/re01.html#org.freedesktop.Secret.Service.SearchItems


Tags: 方法httpsioorgimportsecret属性html
1条回答
网友
1楼 · 发布于 2024-05-28 18:08:28

我也不知道如何搜索标签,但实际上,标签是由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”下。在

相关问题 更多 >

    热门问题