1

I am writing a gnome-shell extension that shows the current balance of prepaid-cards like phones (or electricity). As this needs credentials for the given services, I do not want to store the password in gsettings, but as entry in gnome keyring.

Currently, I use the synchronous way asking the keyring for login and password using

const GnomeKeyring = imports.gi.GnomeKeyring;

GnomeKeyring.unlock_sync(null, null)
// the variable 'id' is a concat of login '@'webservice url
var attrs = GnomeKeyring.Attribute.list_new()
GnomeKeyring.Attribute.list_append_string(attrs, 'id', id)
var result = GnomeKeyring.find_items_sync(
                GnomeKeyring.ItemType.GENERIC_SECRET, 
                attrs
             )
if (result[0] != GnomeKeyring.Result.OK) return
log('  => password '+result[1][0].secret)
log('     keyring id  = '+result[1][0].item_id)
log('     keyring  = '+result[1][0].keyring)

This sync. approachs weak point is, that the keyring needs to already be open or a password dialog is prompted. When starting gnome-shell with auto-login, this synchronous call blocks actually starting the shell at all - so no possibility to enter the keyring password.

The Gnome Developer Wiki names the asynchronous methods

  • GnomeKeyring.unlock
  • GnomeKeyring.find_items

but both are not found in the javascript environment.

Where can I find the GnomeKeyring-Gir file under fedora23 to confirm the lack of the asynch functions missing? How can I achieve an asynchronous keyring-opening and retrieve of the passwords? Does anybody see a completely different, possible approach? Every little helps...

L-Ray
  • 1,637
  • 1
  • 16
  • 29
  • 1
    Have you considered using [libsecret](https://developer.gnome.org/libsecret/0.16/js-examples.html) instead of GnomeKeyring? – JayStrictor Mar 14 '16 at 15:31
  • Hey @JayStrictor, actually I haven't. Wanted to use the standard Gnome environment (as it is for a Gnome shell extension) and didn't look for alternatives instead GnomeKeyring. Do you know if libsecret supports asynchronous calls - with sync. calls my extension blocks the whole gnome shell when starting up. – L-Ray Mar 14 '16 at 18:20
  • 1
    It says "libsecret replaces libgnome-keyring" on the [website](https://wiki.gnome.org/Projects/Libsecret). So I assume that for new projects you should probably use libsecret instead. Furthermore libsecret has an asynchronous [`unlock()` method](https://people.gnome.org/~gcampagna/docs/Secret-1/Secret.Service.unlock.html). Although the doc says that the asynchronous method "may block indefinitely", but that could be a copy&paste error. So I would just try it! – JayStrictor Mar 15 '16 at 19:35
  • 1
    Also note that libsecret uses GnomeKeyring as a backend. – JayStrictor Mar 15 '16 at 19:36
  • Hey @JayStrictor, your solution works great. Do you want to formulate it as an answer, so I can accept and give you the kudos you deserves? :-) – L-Ray Mar 20 '16 at 12:51
  • Thanks :) Will do. – JayStrictor Mar 21 '16 at 18:34

1 Answers1

1

Please consider using libsecret instead of libgnome-keyring. It says "libsecret replaces libgnome-keyring" on the project website of libsecret. So for new projects you should probably use libsecret instead.

Furthermore, libsecret has an asynchronous unlock() method. Although, at the time of writing, the docs say that the asynchronous method "may block indefinitely". But that could be a copy&paste error. So I would just try it!

Also note that libsecret uses GnomeKeyring as a backend, so you would actually use GnomeKeyring, although in conjunction with a more versatile library.

JayStrictor
  • 468
  • 1
  • 4
  • 10