如何通过秘密存储集合中的标签找到密钥 [英] How to find a key by label from secretstorage collection

查看:91
本文介绍了如何通过秘密存储集合中的标签找到密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python 2.7中使用了来自Gtk3的GnomeKeyring,但几乎所有方法都已弃用[1].所以我尝试使用SecretSecret.Collection [2]

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

我找到了软件包"python-secretstorage" [3],现在可以访问密钥环:

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/
  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 第5章查找属性 在查找过程中,属性名称和值通过区分大小写的字符串相等性进行匹配. ... 为了搜索项目,请使用Service接口的SearchItems()方法. https://specifications.freedesktop.org/secret-service/re01.html#org.freedesktop.Secret.Service.SearchItems

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

推荐答案

我也没有弄清楚如何搜索标签,但是AFAICT,该标签是通过GUI从其中一个属性设置的.这似乎很适合我查找网站凭据:

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()

实际上,打印的标签与我搜索的标签相同,我认为这是使用API​​的预期方式.当然,转折在于找出要搜索的确切属性.对于另一个网站,标识URL存储在"origin_url"下.

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".

这篇关于如何通过秘密存储集合中的标签找到密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆