summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/bitmask/util')
-rw-r--r--src/leap/bitmask/util/__init__.py13
-rw-r--r--src/leap/bitmask/util/keyring_helpers.py43
-rw-r--r--src/leap/bitmask/util/leap_argparse.py63
3 files changed, 85 insertions, 34 deletions
diff --git a/src/leap/bitmask/util/__init__.py b/src/leap/bitmask/util/__init__.py
index b58e6e3b..85676d51 100644
--- a/src/leap/bitmask/util/__init__.py
+++ b/src/leap/bitmask/util/__init__.py
@@ -76,3 +76,16 @@ def is_empty_file(path):
Returns True if the file at path is empty.
"""
return os.stat(path).st_size is 0
+
+
+def make_address(user, provider):
+ """
+ Return a full identifier for an user, as a email-like
+ identifier.
+
+ :param user: the username
+ :type user: basestring
+ :param provider: the provider domain
+ :type provider: basestring
+ """
+ return "%s@%s" % (user, provider)
diff --git a/src/leap/bitmask/util/keyring_helpers.py b/src/leap/bitmask/util/keyring_helpers.py
index 4b3eb57f..b202d47e 100644
--- a/src/leap/bitmask/util/keyring_helpers.py
+++ b/src/leap/bitmask/util/keyring_helpers.py
@@ -31,18 +31,45 @@ OBSOLETE_KEYRINGS = [
PlaintextKeyring
]
+canuse = lambda kr: kr is not None and kr.__class__ not in OBSOLETE_KEYRINGS
+
+
+def _get_keyring_with_fallback():
+ """
+ Get the default keyring, and if obsolete try to pick SecretService keyring
+ if available.
+
+ This is a workaround for the cases in which the keyring module chooses
+ an insecure keyring by default (ie, inside a virtualenv).
+ """
+ kr = keyring.get_keyring()
+ if not canuse(kr):
+ try:
+ kr_klass = keyring.backends.SecretService
+ kr = kr_klass.Keyring()
+ except AttributeError:
+ logger.warning("Keyring cannot find SecretService Backend")
+ logger.debug("Selected keyring: %s" % (kr.__class__,))
+ if not canuse(kr):
+ logger.debug("Not using default keyring since it is obsolete")
+ return kr
+
def has_keyring():
"""
- Returns whether we have an useful keyring to use.
+ Return whether we have an useful keyring to use.
:rtype: bool
"""
- kr = keyring.get_keyring()
- klass = kr.__class__
- logger.debug("Selected keyring: %s" % (klass,))
+ kr = _get_keyring_with_fallback()
+ return canuse(kr)
+
- canuse = kr is not None and klass not in OBSOLETE_KEYRINGS
- if not canuse:
- logger.debug("Not using this keyring since it is obsolete")
- return canuse
+def get_keyring():
+ """
+ Return an usable keyring.
+
+ :rtype: keyringBackend or None
+ """
+ kr = _get_keyring_with_fallback()
+ return kr if canuse(kr) else None
diff --git a/src/leap/bitmask/util/leap_argparse.py b/src/leap/bitmask/util/leap_argparse.py
index 280573f1..fb92f141 100644
--- a/src/leap/bitmask/util/leap_argparse.py
+++ b/src/leap/bitmask/util/leap_argparse.py
@@ -27,41 +27,29 @@ def build_parser():
All the options for the leap arg parser
Some of these could be switched on only if debug flag is present!
"""
- epilog = "Copyright 2012-2013 The LEAP Encryption Access Project"
+ epilog = "Copyright 2012-2014 The LEAP Encryption Access Project"
parser = argparse.ArgumentParser(description="""
-Launches Bitmask""", epilog=epilog)
+Launches the Bitmask client.""", epilog=epilog)
parser.add_argument('-d', '--debug', action="store_true",
- help=("Launches Bitmask in debug mode, writing debug"
- "info to stdout"))
- if not IS_RELEASE_VERSION:
- help_text = "Bypasses the certificate check for bootstrap"
- parser.add_argument('--danger', action="store_true", help=help_text)
+ help=("Launches Bitmask in debug mode, writing debug "
+ "info to stdout."))
+ parser.add_argument('-V', '--version', action="store_true",
+ help='Displays Bitmask version and exits.')
+ # files
parser.add_argument('-l', '--logfile', metavar="LOG FILE", nargs='?',
action="store", dest="log_file",
- #type=argparse.FileType('w'),
- help='optional log file')
+ help='Optional log file.')
parser.add_argument('-m', '--mail-logfile',
metavar="MAIL LOG FILE", nargs='?',
action="store", dest="mail_log_file",
- #type=argparse.FileType('w'),
- help='optional log file for email')
- parser.add_argument('--openvpn-verbosity', nargs='?',
- type=int,
- action="store", dest="openvpn_verb",
- help='verbosity level for openvpn logs [1-6]')
+ help='Optional log file for email.')
+
+ # flags
parser.add_argument('-s', '--standalone', action="store_true",
- help='Makes Bitmask use standalone'
- 'directories for configuration and binary'
- 'searching')
- parser.add_argument('-V', '--version', action="store_true",
- help='Displays Bitmask version and exits')
- parser.add_argument('-r', '--repair-mailboxes', metavar="user@provider",
- nargs='?',
- action="store", dest="acct_to_repair",
- help='Repair mailboxes for a given account. '
- 'Use when upgrading versions after a schema '
- 'change.')
+ help='Makes Bitmask use standalone '
+ 'directories for configuration and binary '
+ 'searching.')
parser.add_argument('-N', '--no-app-version-check', default=True,
action="store_false", dest="app_version_check",
help='Skip the app version compatibility check with '
@@ -71,6 +59,29 @@ Launches Bitmask""", epilog=epilog)
help='Skip the api version compatibility check with '
'the provider.')
+ # openvpn options
+ parser.add_argument('--openvpn-verbosity', nargs='?',
+ type=int,
+ action="store", dest="openvpn_verb",
+ help='Verbosity level for openvpn logs [1-6]')
+
+ # mail stuff
+ parser.add_argument('-o', '--offline', action="store_true",
+ help='Starts Bitmask in offline mode: will not '
+ 'try to sync with remote replicas for email.')
+ parser.add_argument('-r', '--repair-mailboxes', metavar="user@provider",
+ nargs='?',
+ action="store", dest="acct_to_repair",
+ help='Repair mailboxes for a given account. '
+ 'Use when upgrading versions after a schema '
+ 'change.')
+
+ if not IS_RELEASE_VERSION:
+ help_text = ("Bypasses the certificate check during provider "
+ "bootstraping, for debugging development servers. "
+ "Use at your own risk!")
+ parser.add_argument('--danger', action="store_true", help=help_text)
+
# Not in use, we might want to reintroduce them.
#parser.add_argument('-i', '--no-provider-checks',
#action="store_true", default=False,