Apr 2002 libsecret
This commit is contained in:
parent
4c1b226bff
commit
cb248a18a3
8 changed files with 86 additions and 17 deletions
|
@ -22,6 +22,7 @@
|
|||
|
||||
import logging
|
||||
import keyring
|
||||
import os
|
||||
|
||||
from gajim.common import app
|
||||
|
||||
|
@ -29,17 +30,30 @@ __all__ = ['get_password', 'save_password']
|
|||
|
||||
log = logging.getLogger('gajim.password')
|
||||
|
||||
from keyring.backends.SecretService import Keyring
|
||||
|
||||
KEYRING_AVAILABLE = None
|
||||
backends = keyring.backend.get_all_keyring()
|
||||
for backend in backends:
|
||||
log.info('Found keyring backend: %s', backend)
|
||||
if 'PYTHON_KEYRING_BACKEND' in os.environ and os.environ['PYTHON_KEYRING_BACKEND']:
|
||||
k_name=os.environ['PYTHON_KEYRING_BACKEND']
|
||||
# 'keyring.backends.SecretService.Keyring'
|
||||
k_list = list(filter(lambda elt: repr(elt.__class__) == "<class '" +k_name +"'>",
|
||||
backends))
|
||||
if k_list:
|
||||
keyring_backend = k_list[0]
|
||||
KEYRING_AVAILABLE = True
|
||||
log.info('Select PYTHON_KEYRING_BACKEND %s backend', keyring_backend)
|
||||
else:
|
||||
log.warn('Select PYTHON_KEYRING_BACKEND %s not found', k_name)
|
||||
|
||||
keyring_backend = keyring.get_keyring()
|
||||
log.info('Select %s backend', keyring_backend)
|
||||
|
||||
KEYRING_AVAILABLE = any(keyring.core.recommended(backend)
|
||||
for backend in backends)
|
||||
if not KEYRING_AVAILABLE:
|
||||
for backend in backends:
|
||||
log.info('Found keyring backend: %s', backend)
|
||||
|
||||
keyring_backend = keyring.get_keyring()
|
||||
KEYRING_AVAILABLE = any(keyring.core.recommended(backend)
|
||||
for backend in backends)
|
||||
log.info('Select %s backend', keyring_backend)
|
||||
|
||||
class SecretPasswordStorage:
|
||||
"""
|
||||
|
@ -47,14 +61,21 @@ class SecretPasswordStorage:
|
|||
"""
|
||||
|
||||
@staticmethod
|
||||
def save_password(account_name, password):
|
||||
def save_password(account_name, password, **kwargs):
|
||||
if not KEYRING_AVAILABLE:
|
||||
log.warning('No recommended keyring backend available.'
|
||||
'Passwords cannot be stored.')
|
||||
return True
|
||||
if kwargs is None: kwargs = dict()
|
||||
kwargs["server"] = "xmpp"
|
||||
kwargs["type"] = "plaintext"
|
||||
kwargs["xdg:schema"] = "org.qt.keychain"
|
||||
try:
|
||||
log.info('Save password to keyring')
|
||||
keyring_backend.set_password('gajim', account_name, password)
|
||||
keyring_backend.set_password('gajim', account_name, password,
|
||||
# these are added for qt compatability
|
||||
**kwargs
|
||||
)
|
||||
return True
|
||||
except Exception:
|
||||
log.exception('Save password failed')
|
||||
|
@ -96,7 +117,7 @@ class ConfigPasswordStorage:
|
|||
return app.settings.get_account_setting(account_name, 'password')
|
||||
|
||||
@staticmethod
|
||||
def save_password(account_name, password):
|
||||
def save_password(account_name, password, **kwargs):
|
||||
app.settings.set_account_setting(account_name, 'password', password)
|
||||
return True
|
||||
|
||||
|
@ -120,7 +141,8 @@ def save_password(account_name, password):
|
|||
return True
|
||||
|
||||
if app.settings.get('use_keyring'):
|
||||
return SecretPasswordStorage.save_password(account_name, password)
|
||||
user = app.get_account_label(account) # guessing
|
||||
return SecretPasswordStorage.save_password(account_name, password, user=user)
|
||||
return ConfigPasswordStorage.save_password(account_name, password)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue