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

Commits:
9d136317 by Philipp Hörist at 2016-12-11T01:20:16+01:00
Store passwords in Windows Credential Vault

- - - - -
82cfcbff by Philipp Hörist at 2016-12-11T15:37:51+01:00
Merge branch 'keyring' into 'master'

Store passwords in Windows Credential Vault Fixes #8367

See merge request !4
- - - - -


1 changed file:

- src/common/passwords.py


Changes:

=====================================
src/common/passwords.py
=====================================
--- a/src/common/passwords.py
+++ b/src/common/passwords.py
@@ -24,11 +24,21 @@
 ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
 ##
 
+import os
+import logging
+import gi
+from common import gajim
+
 __all__ = ['get_password', 'save_password']
 
-import warnings
-from common import gajim
-import gi
+log = logging.getLogger('gajim.password')
+
+if os.name == 'nt':
+    try:
+        import keyring
+    except ImportError:
+        log.debug('python-keyring missing, falling back to plaintext storage')
+
 
 Secret = None
 
@@ -99,6 +109,32 @@ class SecretPasswordStorage(PasswordStorage):
             gajim.connections[account_name].password = password
 
 
+class SecretWindowsPasswordStorage(PasswordStorage):
+    """ Windows Keyring """
+
+    def __init__(self):
+        self.win_keyring = keyring.get_keyring()
+
+    def save_password(self, account_name, password):
+        self.win_keyring.set_password('gajim', account_name, password)
+        gajim.config.set_per('accounts', account_name, 'password', 'winvault:')
+
+    def get_password(self, account_name):
+        log.debug('getting password')
+        conf = gajim.config.get_per('accounts', account_name, 'password')
+        if conf is None:
+            return None
+        if not conf.startswith('winvault:'):
+            password = conf
+            # migrate the password over to keyring
+            try:
+                self.save_password(account_name, password)
+            except Exception:
+                log.exception('error: ')
+            return password
+        return self.win_keyring.get_password('gajim', account_name)
+
+
 storage = None
 def get_storage():
     global storage
@@ -112,7 +148,10 @@ def get_storage():
         except (ValueError, AttributeError):
             pass
         try:
-            storage = SecretPasswordStorage()
+            if os.name != 'nt':
+                storage = SecretPasswordStorage()
+            else:
+                storage = SecretWindowsPasswordStorage()
         except Exception:
             storage = SimplePasswordStorage()
     return storage
@@ -121,7 +160,6 @@ def set_storage(storage_):
     global storage
     storage = storage_
 
-
 def get_password(account_name):
     return get_storage().get_password(account_name)
 



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/compare/995a154c59b544341bb07073e493827c36244839...82cfcbff8b12758c17fa773eab328b9dd1a5024a
_______________________________________________
Commits mailing list
Commits@gajim.org
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to