Fall back to DB-based password storage when Gnome-Keyring is missing. Fixes #235

This commit is contained in:
Manu 2019-03-24 17:21:12 +08:00
parent e40f571b5e
commit 414de1d36b
4 changed files with 10 additions and 3 deletions

View File

@ -12,12 +12,13 @@ class VortaKeyring:
if sys.platform == 'darwin': # Use Keychain on macOS
from .darwin import VortaDarwinKeyring
return VortaDarwinKeyring()
else: # Try to use DBus (available on Linux and *BSD)
else: # Try to use DBus and Gnome-Keyring (available on Linux and *BSD)
import secretstorage
from .secretstorage import VortaSecretStorageKeyring
try:
return VortaSecretStorageKeyring()
except secretstorage.SecretServiceNotAvailableException: # Save passwords in DB, if all else fails.
# Save passwords in DB, if all else fails.
except secretstorage.SecretServiceNotAvailableException:
from .db import VortaDBKeyring
return VortaDBKeyring()

View File

@ -7,7 +7,6 @@ objc modules.
Adapted from https://gist.github.com/apettinen/5dc7bf1f6a07d148b2075725db6b1950
"""
from .abc import VortaKeyring

View File

@ -8,7 +8,12 @@ class VortaSecretStorageKeyring(VortaKeyring):
"""A wrapper for the secretstorage package to support the custom keyring backend"""
def __init__(self):
"""
Test whether DBus and Gnome-Keyring are available.
"""
self.connection = secretstorage.dbus_init()
asyncio.set_event_loop(asyncio.new_event_loop())
secretstorage.get_default_collection(self.connection)
def set_password(self, service, repo_url, password):
asyncio.set_event_loop(asyncio.new_event_loop())

View File

@ -21,8 +21,10 @@ from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtGui import QIcon
from PyQt5 import QtCore
from vorta.keyring.abc import VortaKeyring
from vorta.log import logger
keyring = VortaKeyring.get_keyring()
logger.info('Using %s Keyring implementation.', keyring.__class__.__name__)
def nested_dict():