Apr 2002 libsecret

This commit is contained in:
emdee 2022-10-19 18:54:49 +00:00
parent 4c1b226bff
commit cb248a18a3
8 changed files with 86 additions and 17 deletions

View File

@ -3,6 +3,47 @@ MANIFEST.in
README.md
setup.cfg
setup.py
/var/local/src/gajim-1.3.3/build/data/org.gajim.Gajim.appdata.xml
/var/local/src/gajim-1.3.3/build/data/org.gajim.Gajim.desktop
/var/local/src/gajim-1.3.3/build/man/gajim-history-manager.1.gz
/var/local/src/gajim-1.3.3/build/man/gajim-remote.1.gz
/var/local/src/gajim-1.3.3/build/man/gajim.1.gz
/var/local/src/gajim-1.3.3/build/mo/be/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/be@latin/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/bg/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/br/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/ca/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/cs/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/da/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/de/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/el/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/en_GB/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/eo/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/es/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/eu/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/fr/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/gl/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/he/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/hr/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/hu/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/it/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/ja/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/kk/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/lt/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/nb_NO/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/nl/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/pl/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/pt/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/pt_BR/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/ru/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/sk/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/sr/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/sr@Latn/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/sv/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/tr/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/uk/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/zh_CN/LC_MESSAGES/gajim.mo
/var/local/src/gajim-1.3.3/build/mo/zh_TW/LC_MESSAGES/gajim.mo
data/gajim-history-manager.1
data/gajim-remote.1
data/gajim.1

View File

@ -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:
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)
if not KEYRING_AVAILABLE:
for backend in backends:
log.info('Found keyring backend: %s', backend)
keyring_backend = keyring.get_keyring()
log.info('Select %s backend', keyring_backend)
KEYRING_AVAILABLE = any(keyring.core.recommended(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)

View File

@ -17,6 +17,8 @@
import os
os.environ['PYTHON_KEYRING_BACKEND']='keyring.backends.SecretService.Keyring'
import sys
import signal
import platform

View File

@ -1021,7 +1021,8 @@ class LoginDialog(SettingsDialog):
self.connect('destroy', self.on_destroy)
def on_password_change(self, new_password, _data):
passwords.save_password(self.account, new_password)
user = app.get_account_label(account) # guessing
passwords.save_password(self.account, new_password, user=user)
def on_destroy(self, *args):
savepass = app.settings.get_account_setting(self.account, 'savepass')

View File

@ -98,7 +98,7 @@ class ChangePassword(Assistant):
else:
password = self.get_page('password').get_password()
passwords.save_password(self.account, password)
passwords.save_password(self.account, password, user=self.jid)
self.show_page('success')
def _on_destroy(self, *args):

View File

@ -291,7 +291,10 @@ class GenericSetting(Gtk.ListBoxRow):
elif self.type_ == SettingType.ACCOUNT_CONFIG:
if self.value == 'password':
passwords.save_password(self.account, state)
passwords.save_password(self.account, state,
# guessing - for xdg:schema="org.qt.keychain"
user=self.jid,
)
if self.value == 'no_log_for':
self.set_no_log_for(self.account, state)
else:

View File

@ -460,7 +460,7 @@ class Interface:
def on_ok(passphrase, save):
app.settings.set_account_setting(account, 'savepass', save)
passwords.save_password(account, passphrase)
passwords.save_password(account, passphrase, user=obj.jid)
obj.on_password(passphrase)
del self.pass_dialog[account]
@ -1550,7 +1550,7 @@ class Interface:
app.settings.set_account_setting(account, opt, config[opt])
# Password module depends on existing config
passwords.save_password(account, password)
passwords.save_password(account, password, user=account_label)
app.css_config.refresh()

View File

@ -2052,7 +2052,7 @@ class RosterWindow:
# The contact has several resources
if len(contact_instances) > 1:
if contact.resource != '':
if contact.resource:
name += '/' + contact.resource
# Remove resource when going offline