Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
replace gnome-keyring with Secret
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Mar 16, 2018
1 parent 3263ebe commit a460e61
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
2 changes: 0 additions & 2 deletions Authenticator/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ def do_startup(self):
"""Startup the application."""
Gtk.Application.do_startup(self)
# Unlock the keyring
if not Keyring.unlock():
self.on_quit()
self.generate_menu()
self.setup_css()

Expand Down
54 changes: 25 additions & 29 deletions Authenticator/models/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,34 @@
along with Authenticator. If not, see <http://www.gnu.org/licenses/>.
"""
from gi import require_version
require_version("GnomeKeyring", "1.0")
from gi.repository import GnomeKeyring as GK
require_version('Secret', '1')
from gi.repository import Secret


class Keyring:
ID = "com.github.bilelmoussaoui.Authenticator"
instance = None


def __init__(self):
self.schema = Secret.Schema.new(Keyring.ID,
Secret.SchemaFlags.NONE,
{
"id": Secret.SchemaAttributeType.STRING
})

@staticmethod
def unlock():
result = GK.unlock_sync(Keyring.ID, None)
return result != GK.Result.CANCELLED
def get_default():
if Keyring.instance is None:
Keyring.instance = Keyring()
return Keyring.instance

@staticmethod
def get_by_id(id_):
"""Return the secret code"""
attr = GK.Attribute.list_new()
GK.Attribute.list_append_string(attr, 'id', id_)
result, value = GK.find_items_sync(GK.ItemType.GENERIC_SECRET,
attr)
if result == GK.Result.OK:
return value[0].secret
return None
schema = Keyring.get_default().schema
password = Secret.password_lookup_sync(schema, { "id": id_ }, None)
return password

@staticmethod
def insert(id_, secret_code):
Expand All @@ -47,12 +53,10 @@ def insert(id_, secret_code):
:param id_: the encrypted id
:param secret_code: the secret code
"""
GK.create_sync(Keyring.ID, None)
attr = GK.Attribute.list_new()
GK.Attribute.list_append_string(attr, 'id', id_)
GK.Attribute.list_append_string(attr, 'secret_code', secret_code)
GK.item_create_sync(Keyring.ID, GK.ItemType.GENERIC_SECRET,
repr(id), attr, secret_code, False)
schema = Keyring.get_default().schema
Secret.password_store_sync(schema, {
"id": id_,
}, Secret.COLLECTION_DEFAULT, "", secret_code, None)

@staticmethod
def remove(id_):
Expand All @@ -61,14 +65,6 @@ def remove(id_):
:param id_: the encrypted secret code.
:return: bool
"""
found = False
(result, ids) = GK.list_item_ids_sync(Keyring.ID)
gid = None
for gid in ids:
(result, item) = GK.item_get_info_sync(Keyring.ID, gid)
if result == GK.Result.OK and \
item.get_display_name().strip("'") == id_:
found = True
break
if found and gid:
GK.item_delete_sync(Keyring.ID, gid)
schema = Keyring.get_default().schema
removed = Secret.password_clear_sync(schema, { "id": id_ }, None)
return removed
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ version](https://img.shields.io/badge/python-3.3%2B-blue.svg)
- `zbarlight` depends on `zbar`
- `libzbar-dev` on Ubuntu
- `zbar` on Arch
- `gnome-keyring`
- `libsecret`
- `gnome-screenshot`

<sub>
Expand Down
3 changes: 1 addition & 2 deletions com.github.bilelmoussaoui.Authenticator.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
"sha256": "92329b5496c7a86f2103f1ee15b1269dcff6011cb096948efafd349473b955a9"
}]
},

{
"name": "gnome-screenshot",
"sources": [{
Expand All @@ -141,7 +140,7 @@
"sources": [{
"type": "git",
"url": "https://github.com/bilelmoussaoui/Authenticator"
}]
- }]
}
]
}

0 comments on commit a460e61

Please sign in to comment.