Skip to content

Instantly share code, notes, and snippets.

@rubiojr
Last active Aug 29, 2015
Embed
What would you like to do?
Read-only access to the GNOME keyring
#!/usr/bin/env ruby
require 'gir_ffi-gnome_keyring'
class Keyring
# Return all the keyring items
#
# returns: An Array of Hashes
#
def self.items
items = []
# :generic_secrets isn't making any difference here
code, list = GnomeKeyring.find_items_sync(:generic_secret, [])
list.each do |e|
item = {}
e.attributes.each do |i|
value = (i.type == :string) ? i.get_string : i.get_uint32
item[i.name] = value
end
item['secret'] = e.secret
items << item
end
items
end
# GNOME network passwords
# org.gnome.keyring.NetworkPassword
def self.network_secrets
find_by_schema 'org.gnome.keyring.NetworkPassword'
end
# Generic stuff, like Chrome/Chromium passwords
# org.freedesktop.Secret.Generic
def self.generic_secrets
find_by_schema 'org.freedesktop.Secret.Generic'
end
# NetworkManager stuff
# org.freedesktop.NetworkManager.Connection
def self.connection_secrets
find_by_schema 'org.freedesktop.NetworkManager.Connection'
end
# Secret notes
# org.gnome.keyring.Note
def self.secret_notes
find_by_schema 'org.gnome.keyring.Note'
end
private
def self.find_by_schema(schema)
Keyring.items.find_all do |i|
i['xdg:schema'] == schema
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment