Philipp Hörist pushed to branch master at gajim / gajim


Commits:
f6cfa352 by Philipp Hörist at 2023-11-14T20:44:33+01:00
imprv: Passwords: Use JID as username instead of account

Fixes #11684

- - - - -


1 changed file:

- gajim/common/passwords.py


Changes:

=====================================
gajim/common/passwords.py
=====================================
@@ -77,10 +77,13 @@ def save_password(account_name: str, password: str) -> bool:
         if not is_keyring_available():
             log.warning('No recommended keyring backend available.'
                         'Passwords cannot be stored.')
-            return True
+            return False
+
+        account_jid = app.get_jid_from_account(account_name)
+
         try:
             log.info('Save password to keyring')
-            _interface.backend.set_password('gajim', account_name, password)
+            _interface.backend.set_password('gajim', account_jid, password)
             return True
         except Exception:
             log.exception('Save password failed')
@@ -93,14 +96,33 @@ def get_password(account_name: str) -> str | None:
 
         log.info('Request password from keyring')
 
+        account_jid = app.get_jid_from_account(account_name)
+
         try:
             # For security reasons remove clear-text password
             ConfigPasswordStorage.delete_password(account_name)
-            return _interface.backend.get_password('gajim', account_name)
+            password = _interface.backend.get_password('gajim', account_jid)
+        except Exception:
+            log.exception('Request password failed')
+            return
+
+        if password is not None:
+            return password
+
+        # Migration from account name to account jid
+        try:
+            password = _interface.backend.get_password('gajim', account_name)
         except Exception:
             log.exception('Request password failed')
             return
 
+        if password is not None:
+            result = SecretPasswordStorage.save_password(account_name, 
password)
+            if not result:
+                log.error('Password migration failed')
+
+        return password
+
     @staticmethod
     def delete_password(account_name: str) -> None:
         if not is_keyring_available():
@@ -108,8 +130,11 @@ def delete_password(account_name: str) -> None:
 
         log.info('Remove password from keyring')
 
+        account_jid = app.get_jid_from_account(account_name)
+
         try:
-            return _interface.backend.delete_password('gajim', account_name)
+            _interface.backend.delete_password('gajim', account_name)
+            return _interface.backend.delete_password('gajim', account_jid)
         except keyring.errors.PasswordDeleteError as error:
             log.warning('Removing password failed: %s', error)
         except Exception:



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/f6cfa352d2a32fe2b5311f735a6c836ebe62770c

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/f6cfa352d2a32fe2b5311f735a6c836ebe62770c
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to