hugosenari / Kupfer-Plugins

My kupfer plugins install with Kupfer
https://github.com/kupferlauncher/kupfer/
11 stars 2 forks source link

Action: Use kupfer_keyring to get secret of an item (object) from seahorse? #12

Closed khurshid-alam closed 6 years ago

khurshid-alam commented 7 years ago

It would be nice if we can search and find (paste secret to clipboard) secret of an item in Seahorse or anything that uses libsecret.

For example:

#!/usr/bin/env python3
import secretstorage

bus = secretstorage.dbus_init()
collection = secretstorage.get_default_collection(bus)
for item in collection.search_items({'rtm': 'rtm_api_key'}):
    print(item.get_secret())
    print(item.get_attributes())

Note: I only want to search those items which was created by me and not by chrome/firefox, .i.e which has 'xdg:schema': 'org.freedesktop.Secret.Generic'

So we use search_items instead of get_all_items in keysource ⟶

bus = secretstorage.dbus_init()
collection = secretstorage.get_default_collection(bus)
for item in collection.search_items({'xdg:schema': 'org.freedesktop.Secret.Generic'}):
    print (item.get_label())

Thoughts?

hugosenari commented 7 years ago

Two options:

Fork creating a kupfer_secretstorage plugin:

Direct use of secretstorage has better performance but restrict your keys to secretstorage, keyring have other backends.

Filter result of get_all_items:

Filter before Leaf creation

for obj in self.resource.get_all_items():
    if obj.get('xdg:schema') == 'org.freedesktop.Secret.Generic'
        yield KeyLeaf(obj)

I'm inclined to implement both and add a setting to filter :smile:

khurshid-alam commented 7 years ago

So we can access secret storage backends with keyring? Can you give an example?

khurshid-alam commented 7 years ago

May be using Using secret from gi would be better (They have asynchronous mode so that it doesn't block gui).

gi.require_version('Secret', '1')
from gi.repository import Secret

#Example using gi
EXAMPLE_SCHEMA = Secret.Schema.new("org.freedesktop.Secret.Generic",
    Secret.SchemaFlags.NONE, {'rtm': Secret.SchemaAttributeType.STRING}
)
password = Secret.password_lookup_sync(EXAMPLE_SCHEMA, {'rtm': 'rtm_token'}, None)
print (password)

I will try and replicate keyring code with it.

khurshid-alam commented 6 years ago

This should be closed.