diff options
author | Tomás Touceda <chiiph@leap.se> | 2014-01-17 12:49:38 -0300 |
---|---|---|
committer | Tomás Touceda <chiiph@leap.se> | 2014-01-17 12:49:38 -0300 |
commit | 9d7152f7f7e81cf1c8838ad2cbeba3ff6fac41a7 (patch) | |
tree | 3957db7bc593a4cfb4ac61141d6dd44012935ba3 | |
parent | 9400d166db96fdcb2927245f5163ced0e29f2e07 (diff) | |
parent | 9dbbfeebbb4bb7c445e01f94533e88e514fd6821 (diff) |
Merge remote-tracking branch 'refs/remotes/kali/bug/capture-keyring-errors' into develop
-rw-r--r-- | changes/bug_capture-keyring-errors | 2 | ||||
-rw-r--r-- | src/leap/bitmask/util/keyring_helpers.py | 30 |
2 files changed, 22 insertions, 10 deletions
diff --git a/changes/bug_capture-keyring-errors b/changes/bug_capture-keyring-errors new file mode 100644 index 00000000..a4b7046b --- /dev/null +++ b/changes/bug_capture-keyring-errors @@ -0,0 +1,2 @@ +- Fail gracefully against keyring import errors. + diff --git a/src/leap/bitmask/util/keyring_helpers.py b/src/leap/bitmask/util/keyring_helpers.py index b202d47e..ee2d7a1c 100644 --- a/src/leap/bitmask/util/keyring_helpers.py +++ b/src/leap/bitmask/util/keyring_helpers.py @@ -19,19 +19,23 @@ Keyring helpers. """ import logging -import keyring +try: + import keyring + from keyring.backends.file import EncryptedKeyring, PlaintextKeyring + OBSOLETE_KEYRINGS = [ + EncryptedKeyring, + PlaintextKeyring + ] + canuse = lambda kr: (kr is not None + and kr.__class__ not in OBSOLETE_KEYRINGS) -from keyring.backends.file import EncryptedKeyring, PlaintextKeyring - -logger = logging.getLogger(__name__) +except Exception: + # Problems when importing keyring! It might be a problem binding to the + # dbus socket, or stuff like that. + keyring = None -OBSOLETE_KEYRINGS = [ - EncryptedKeyring, - PlaintextKeyring -] - -canuse = lambda kr: kr is not None and kr.__class__ not in OBSOLETE_KEYRINGS +logger = logging.getLogger(__name__) def _get_keyring_with_fallback(): @@ -42,6 +46,8 @@ def _get_keyring_with_fallback(): This is a workaround for the cases in which the keyring module chooses an insecure keyring by default (ie, inside a virtualenv). """ + if not keyring: + return None kr = keyring.get_keyring() if not canuse(kr): try: @@ -61,6 +67,8 @@ def has_keyring(): :rtype: bool """ + if not keyring: + return False kr = _get_keyring_with_fallback() return canuse(kr) @@ -71,5 +79,7 @@ def get_keyring(): :rtype: keyringBackend or None """ + if not keyring: + return False kr = _get_keyring_with_fallback() return kr if canuse(kr) else None |