From edf47444232c9e3637e2ad71bdd5ffa8cdcc8480 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 17 Dec 2013 15:57:48 -0400 Subject: add repair mailbox utility --- src/leap/bitmask/util/leap_argparse.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/leap/bitmask/util') diff --git a/src/leap/bitmask/util/leap_argparse.py b/src/leap/bitmask/util/leap_argparse.py index e8a9fda9..00192247 100644 --- a/src/leap/bitmask/util/leap_argparse.py +++ b/src/leap/bitmask/util/leap_argparse.py @@ -51,6 +51,12 @@ Launches Bitmask""", epilog=epilog) '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.') # Not in use, we might want to reintroduce them. #parser.add_argument('-i', '--no-provider-checks', -- cgit v1.2.3 From 8ba650488ea1f1a50b4c22758f647c9f2ee7839d Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Fri, 20 Dec 2013 13:44:53 -0400 Subject: mail logs --- src/leap/bitmask/util/leap_argparse.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/leap/bitmask/util') diff --git a/src/leap/bitmask/util/leap_argparse.py b/src/leap/bitmask/util/leap_argparse.py index 00192247..6703b600 100644 --- a/src/leap/bitmask/util/leap_argparse.py +++ b/src/leap/bitmask/util/leap_argparse.py @@ -41,6 +41,11 @@ Launches Bitmask""", epilog=epilog) action="store", dest="log_file", #type=argparse.FileType('w'), 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", -- cgit v1.2.3 From 785380dfa7b3f6205b52be2a90afa9b0afa04c5e Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Thu, 9 Jan 2014 14:24:33 -0300 Subject: Add flag to disable version check. --- src/leap/bitmask/util/leap_argparse.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/leap/bitmask/util') diff --git a/src/leap/bitmask/util/leap_argparse.py b/src/leap/bitmask/util/leap_argparse.py index 6703b600..280573f1 100644 --- a/src/leap/bitmask/util/leap_argparse.py +++ b/src/leap/bitmask/util/leap_argparse.py @@ -62,6 +62,14 @@ Launches Bitmask""", epilog=epilog) help='Repair mailboxes for a given account. ' 'Use when upgrading versions after a schema ' 'change.') + 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 ' + 'the provider.') + parser.add_argument('-M', '--no-api-version-check', default=True, + action="store_false", dest="api_version_check", + help='Skip the api version compatibility check with ' + 'the provider.') # Not in use, we might want to reintroduce them. #parser.add_argument('-i', '--no-provider-checks', -- cgit v1.2.3 From 2bd96c2f0a3c5b6d4a80fe450dfe84bf524ca722 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 9 Jan 2014 19:01:00 -0400 Subject: add --offline flag and tidy up arguments by sections --- src/leap/bitmask/util/leap_argparse.py | 63 ++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 26 deletions(-) (limited to 'src/leap/bitmask/util') 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, -- cgit v1.2.3 From a1db341a39ec336ab62e89280f9bfb315420bfb5 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Sat, 11 Jan 2014 23:10:09 -0400 Subject: offline mode This will skip: * srp authentication with server * remote soledad configuration * keymanager sending key to server * imap fetches. Its main goal is to help us while debugging imap accounts, by cutting almost all communication with server. It will break havoc if you use it without having local keys configured. So, basically, use with care. --- src/leap/bitmask/util/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/leap/bitmask/util') 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) -- cgit v1.2.3 From 5dc5dc816f2ba50920dd3a5908824c244c8d9390 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Sat, 11 Jan 2014 23:10:53 -0400 Subject: workaround for using keyring inside a virtualenv (securestorage backend) This is related to research #4190 and #4083. I didn't resolve them, but I ended understanding a bit more what kind of issues can we be having with those. This workaround is more than anything a cleanup on that for future work, and is making me able to test the client much more nicely inside a virtualenv (where the default keyring selecting was the plaintext one). For this to work inside a virtualenv, one have to install SecureStorage, which in turns depends on python-dbus, which is basically uninstallable using pip inside a venv. So, symlinking to the rescue! it needs gi/repository and pyobject to be symlinked too. but at least you don't have to type the pass every time. I don't know what should be do in the long term with this issue. Some of us were not too fond on using the keyrings at all. We don't have many options among all the keyring backends, and sadly many of them depend on PyCrypto. So probably roll our own backend. Yay. --- src/leap/bitmask/util/keyring_helpers.py | 43 ++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'src/leap/bitmask/util') 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 -- cgit v1.2.3 From 36d634ad980bd260a3d93f8005725bc2dc3527f7 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Sun, 12 Jan 2014 21:28:21 -0400 Subject: rename repair to plumber to suit more generic functionality --- src/leap/bitmask/util/leap_argparse.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/leap/bitmask/util') diff --git a/src/leap/bitmask/util/leap_argparse.py b/src/leap/bitmask/util/leap_argparse.py index fb92f141..dd0f40f7 100644 --- a/src/leap/bitmask/util/leap_argparse.py +++ b/src/leap/bitmask/util/leap_argparse.py @@ -75,6 +75,11 @@ Launches the Bitmask client.""", epilog=epilog) help='Repair mailboxes for a given account. ' 'Use when upgrading versions after a schema ' 'change.') + parser.add_argument('--import-maildir', metavar="/path/to/Maildir", + nargs='?', + action="store", dest="maildir", + help='Import the given maildir. Use with the --mdir ' + 'flag to import to folders other than INBOX.') if not IS_RELEASE_VERSION: help_text = ("Bypasses the certificate check during provider " -- cgit v1.2.3 From 7f9fa030ed44a7db6ced5b359c49dadc0a781b8a Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Sun, 12 Jan 2014 22:56:31 -0400 Subject: able to import maildir --- src/leap/bitmask/util/__init__.py | 27 ++++++++++++++++++++++++--- src/leap/bitmask/util/leap_argparse.py | 17 +++++++++++------ 2 files changed, 35 insertions(+), 9 deletions(-) (limited to 'src/leap/bitmask/util') diff --git a/src/leap/bitmask/util/__init__.py b/src/leap/bitmask/util/__init__.py index 85676d51..c35be99e 100644 --- a/src/leap/bitmask/util/__init__.py +++ b/src/leap/bitmask/util/__init__.py @@ -18,19 +18,23 @@ Some small and handy functions. """ import datetime +import itertools import os from leap.bitmask.config import flags from leap.common.config import get_path_prefix as common_get_path_prefix - -def get_path_prefix(): - return common_get_path_prefix(flags.STANDALONE) +# functional goodies for a healthier life: +# We'll give your money back if it does not alleviate the eye strain, at least. def first(things): """ Return the head of a collection. + + :param things: a sequence to extract the head from. + :type things: sequence + :return: object, or None """ try: return things[0] @@ -38,6 +42,23 @@ def first(things): return None +def flatten(things): + """ + Return a generator iterating through a flattened sequence. + + :param things: a nested sequence, eg, a list of lists. + :type things: sequence + :rtype: generator + """ + return itertools.chain(*things) + + +# leap repetitive chores + +def get_path_prefix(): + return common_get_path_prefix(flags.STANDALONE) + + def get_modification_ts(path): """ Gets modification time of a file. diff --git a/src/leap/bitmask/util/leap_argparse.py b/src/leap/bitmask/util/leap_argparse.py index dd0f40f7..56bf26dc 100644 --- a/src/leap/bitmask/util/leap_argparse.py +++ b/src/leap/bitmask/util/leap_argparse.py @@ -69,17 +69,22 @@ Launches the Bitmask client.""", epilog=epilog) 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", + + parser.add_argument('--acct', metavar="user@provider", nargs='?', - action="store", dest="acct_to_repair", + action="store", dest="acct", + help='Manipulate mailboxes for this account') + parser.add_argument('-r', '--repair-mailboxes', default=False, + action="store_true", dest="repair", help='Repair mailboxes for a given account. ' 'Use when upgrading versions after a schema ' - 'change.') + 'change. Use with --acct') parser.add_argument('--import-maildir', metavar="/path/to/Maildir", nargs='?', - action="store", dest="maildir", - help='Import the given maildir. Use with the --mdir ' - 'flag to import to folders other than INBOX.') + action="store", dest="import_maildir", + help='Import the given maildir. Use with the ' + '--to-mbox flag to import to folders other ' + 'than INBOX. Use with --acct') if not IS_RELEASE_VERSION: help_text = ("Bypasses the certificate check during provider " -- cgit v1.2.3 From 9dbbfeebbb4bb7c445e01f94533e88e514fd6821 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Fri, 17 Jan 2014 11:22:35 -0400 Subject: defend against keyring errors on certain settings, like a virtualenv with symlinks, I'm getting errors after a suspend, related to a error to connect to the dbus socket. wrapping all of it in a conditional we avoid that kind of error. --- src/leap/bitmask/util/keyring_helpers.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/leap/bitmask/util') 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 -- cgit v1.2.3 From 2ea1ffae0423355e626145dcd30d52fdc1b2fee6 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Mon, 3 Feb 2014 12:49:03 -0300 Subject: Use the new log format in the GUI too. - Unify location for log format. --- src/leap/bitmask/util/__init__.py | 5 +++++ src/leap/bitmask/util/leap_log_handler.py | 7 +++---- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src/leap/bitmask/util') diff --git a/src/leap/bitmask/util/__init__.py b/src/leap/bitmask/util/__init__.py index c35be99e..2b2cd874 100644 --- a/src/leap/bitmask/util/__init__.py +++ b/src/leap/bitmask/util/__init__.py @@ -28,6 +28,11 @@ from leap.common.config import get_path_prefix as common_get_path_prefix # We'll give your money back if it does not alleviate the eye strain, at least. +# levelname length == 8, since 'CRITICAL' is the longest +LOG_FORMAT = ('%(asctime)s - %(levelname)-8s - ' + 'L#%(lineno)-4s : %(name)s:%(funcName)s() - %(message)s') + + def first(things): """ Return the head of a collection. diff --git a/src/leap/bitmask/util/leap_log_handler.py b/src/leap/bitmask/util/leap_log_handler.py index 1ab62331..807e53d4 100644 --- a/src/leap/bitmask/util/leap_log_handler.py +++ b/src/leap/bitmask/util/leap_log_handler.py @@ -21,6 +21,8 @@ import logging from PySide import QtCore +from leap.bitmask.util import LOG_FORMAT + class LogHandler(logging.Handler): """ @@ -52,10 +54,7 @@ class LogHandler(logging.Handler): :param logging_level: the debug level to define the color. :type logging_level: str. """ - log_format = ('%(asctime)s - %(name)s:%(funcName)s:L#%(lineno)s ' - '- %(levelname)s - %(message)s') - formatter = logging.Formatter(log_format) - + formatter = logging.Formatter(LOG_FORMAT) return formatter def emit(self, logRecord): -- cgit v1.2.3 From b4b9f10698902005c8d463d4bf3939d40c2a2783 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Mon, 17 Feb 2014 11:13:55 -0400 Subject: silence decorator --- src/leap/bitmask/util/log_silencer.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src/leap/bitmask/util') diff --git a/src/leap/bitmask/util/log_silencer.py b/src/leap/bitmask/util/log_silencer.py index b9f69ad2..56b290e4 100644 --- a/src/leap/bitmask/util/log_silencer.py +++ b/src/leap/bitmask/util/log_silencer.py @@ -46,6 +46,7 @@ class SelectiveSilencerFilter(logging.Filter): # to us. SILENCER_RULES = ( 'leap.common.events', + 'leap.common.decorators', ) def __init__(self): -- cgit v1.2.3 From 306b62e7dcf757c2143d5db4380c0be42fd1e16a Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Mon, 24 Feb 2014 18:37:49 -0300 Subject: Add pastebin api wrapper file. Currently installation through PyPI isn't working so I embedded here. Add reference in license file. --- src/leap/bitmask/util/pastebin.py | 814 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 814 insertions(+) create mode 100755 src/leap/bitmask/util/pastebin.py (limited to 'src/leap/bitmask/util') diff --git a/src/leap/bitmask/util/pastebin.py b/src/leap/bitmask/util/pastebin.py new file mode 100755 index 00000000..21b8a0b7 --- /dev/null +++ b/src/leap/bitmask/util/pastebin.py @@ -0,0 +1,814 @@ +#!/usr/bin/env python + +############################################################################# +# Pastebin.py - Python 3.2 Pastebin API. +# Copyright (C) 2012 Ian Havelock +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +############################################################################# + +# This software is a derivative work of: +# http://winappdbg.sourceforge.net/blog/pastebin.py + +############################################################################# + + +__ALL__ = ['delete_paste', 'user_details', 'trending', 'pastes_by_user', + 'generate_user_key', 'legacy_paste', 'paste', 'Pastebin', + 'PastebinError'] + +import urllib + + +class PastebinError(RuntimeError): + """Pastebin API error. + + The error message returned by the web application is stored as the Python + exception message.""" + + +class PastebinAPI(object): + """Pastebin API interaction object. + + Public functions: + + paste -- Pastes a user-specified file or string using the new API-key POST + method. + + legacy_paste -- Pastes a user-specified file or string using the old + anonymous POST method. + + generate_user_key -- Generates a session-key that is required for other + functions. + + pastes_by_user -- Returns all public pastes submitted by the specified + login credentials. + + trending -- Returns the top trending paste. + + user_details -- Returns details about the user for the specified API user + key. + + delete_paste -- Adds two numbers together and returns the result.""" + + # String to determine bad API requests + _bad_request = 'Bad API request' + + # Base domain name + _base_domain = 'pastebin.com' + + # Valid Pastebin URLs begin with this string (kinda obvious) + _prefix_url = 'http://%s/' % _base_domain + + # Valid Pastebin URLs with a custom subdomain begin with this string + _subdomain_url = 'http://%%s.%s/' % _base_domain + + # URL to the LEGACY POST API + _legacy_api_url = 'http://%s/api_public.php' % _base_domain + + # URL to the POST API + _api_url = 'http://%s/api/api_post.php' % _base_domain + + # URL to the login POST API + _api_login_url = 'http://%s/api/api_login.php' % _base_domain + + # Valid paste_expire_date values: Never, 10 minutes, 1 Hour, 1 Day, 1 Month + paste_expire_date = ('N', '10M', '1H', '1D', '1M') + + # Valid paste_expire_date values (0 = public, 1 = unlisted, 2 = private) + paste_private = ('public', 'unlisted', 'private') + + # Valid parse_format values + paste_format = ( + '4cs', # 4CS + '6502acme', # 6502 ACME Cross Assembler + '6502kickass', # 6502 Kick Assembler + '6502tasm', # 6502 TASM/64TASS + 'abap', # ABAP + 'actionscript', # ActionScript + 'actionscript3', # ActionScript 3 + 'ada', # Ada + 'algol68', # ALGOL 68 + 'apache', # Apache Log + 'applescript', # AppleScript + 'apt_sources', # APT Sources + 'asm', # ASM (NASM) + 'asp', # ASP + 'autoconf', # autoconf + 'autohotkey', # Autohotkey + 'autoit', # AutoIt + 'avisynth', # Avisynth + 'awk', # Awk + 'bascomavr', # BASCOM AVR + 'bash', # Bash + 'basic4gl', # Basic4GL + 'bibtex', # BibTeX + 'blitzbasic', # Blitz Basic + 'bnf', # BNF + 'boo', # BOO + 'bf', # BrainFuck + 'c', # C + 'c_mac', # C for Macs + 'cil', # C Intermediate Language + 'csharp', # C# + 'cpp', # C++ + 'cpp-qt', # C++ (with QT extensions) + 'c_loadrunner', # C: Loadrunner + 'caddcl', # CAD DCL + 'cadlisp', # CAD Lisp + 'cfdg', # CFDG + 'chaiscript', # ChaiScript + 'clojure', # Clojure + 'klonec', # Clone C + 'klonecpp', # Clone C++ + 'cmake', # CMake + 'cobol', # COBOL + 'coffeescript', # CoffeeScript + 'cfm', # ColdFusion + 'css', # CSS + 'cuesheet', # Cuesheet + 'd', # D + 'dcs', # DCS + 'delphi', # Delphi + 'oxygene', # Delphi Prism (Oxygene) + 'diff', # Diff + 'div', # DIV + 'dos', # DOS + 'dot', # DOT + 'e', # E + 'ecmascript', # ECMAScript + 'eiffel', # Eiffel + 'email', # Email + 'epc', # EPC + 'erlang', # Erlang + 'fsharp', # F# + 'falcon', # Falcon + 'fo', # FO Language + 'f1', # Formula One + 'fortran', # Fortran + 'freebasic', # FreeBasic + 'freeswitch', # FreeSWITCH + 'gambas', # GAMBAS + 'gml', # Game Maker + 'gdb', # GDB + 'genero', # Genero + 'genie', # Genie + 'gettext', # GetText + 'go', # Go + 'groovy', # Groovy + 'gwbasic', # GwBasic + 'haskell', # Haskell + 'hicest', # HicEst + 'hq9plus', # HQ9 Plus + 'html4strict', # HTML + 'html5', # HTML 5 + 'icon', # Icon + 'idl', # IDL + 'ini', # INI file + 'inno', # Inno Script + 'intercal', # INTERCAL + 'io', # IO + 'j', # J + 'java', # Java + 'java5', # Java 5 + 'javascript', # JavaScript + 'jquery', # jQuery + 'kixtart', # KiXtart + 'latex', # Latex + 'lb', # Liberty BASIC + 'lsl2', # Linden Scripting + 'lisp', # Lisp + 'llvm', # LLVM + 'locobasic', # Loco Basic + 'logtalk', # Logtalk + 'lolcode', # LOL Code + 'lotusformulas', # Lotus Formulas + 'lotusscript', # Lotus Script + 'lscript', # LScript + 'lua', # Lua + 'm68k', # M68000 Assembler + 'magiksf', # MagikSF + 'make', # Make + 'mapbasic', # MapBasic + 'matlab', # MatLab + 'mirc', # mIRC + 'mmix', # MIX Assembler + 'modula2', # Modula 2 + 'modula3', # Modula 3 + '68000devpac', # Motorola 68000 HiSoft Dev + 'mpasm', # MPASM + 'mxml', # MXML + 'mysql', # MySQL + 'newlisp', # newLISP + 'text', # None + 'nsis', # NullSoft Installer + 'oberon2', # Oberon 2 + 'objeck', # Objeck Programming Langua + 'objc', # Objective C + 'ocaml-brief', # OCalm Brief + 'ocaml', # OCaml + 'pf', # OpenBSD PACKET FILTER + 'glsl', # OpenGL Shading + 'oobas', # Openoffice BASIC + 'oracle11', # Oracle 11 + 'oracle8', # Oracle 8 + 'oz', # Oz + 'pascal', # Pascal + 'pawn', # PAWN + 'pcre', # PCRE + 'per', # Per + 'perl', # Perl + 'perl6', # Perl 6 + 'php', # PHP + 'php-brief', # PHP Brief + 'pic16', # Pic 16 + 'pike', # Pike + 'pixelbender', # Pixel Bender + 'plsql', # PL/SQL + 'postgresql', # PostgreSQL + 'povray', # POV-Ray + 'powershell', # Power Shell + 'powerbuilder', # PowerBuilder + 'proftpd', # ProFTPd + 'progress', # Progress + 'prolog', # Prolog + 'properties', # Properties + 'providex', # ProvideX + 'purebasic', # PureBasic + 'pycon', # PyCon + 'python', # Python + 'q', # q/kdb+ + 'qbasic', # QBasic + 'rsplus', # R + 'rails', # Rails + 'rebol', # REBOL + 'reg', # REG + 'robots', # Robots + 'rpmspec', # RPM Spec + 'ruby', # Ruby + 'gnuplot', # Ruby Gnuplot + 'sas', # SAS + 'scala', # Scala + 'scheme', # Scheme + 'scilab', # Scilab + 'sdlbasic', # SdlBasic + 'smalltalk', # Smalltalk + 'smarty', # Smarty + 'sql', # SQL + 'systemverilog', # SystemVerilog + 'tsql', # T-SQL + 'tcl', # TCL + 'teraterm', # Tera Term + 'thinbasic', # thinBasic + 'typoscript', # TypoScript + 'unicon', # Unicon + 'uscript', # UnrealScript + 'vala', # Vala + 'vbnet', # VB.NET + 'verilog', # VeriLog + 'vhdl', # VHDL + 'vim', # VIM + 'visualprolog', # Visual Pro Log + 'vb', # VisualBasic + 'visualfoxpro', # VisualFoxPro + 'whitespace', # WhiteSpace + 'whois', # WHOIS + 'winbatch', # Winbatch + 'xbasic', # XBasic + 'xml', # XML + 'xorg_conf', # Xorg Config + 'xpp', # XPP + 'yaml', # YAML + 'z80', # Z80 Assembler + 'zxbasic', # ZXBasic + ) + + def __init__(self): + pass + + def delete_paste(self, api_dev_key, api_user_key, api_paste_key): + """Delete the paste specified by the api_paste_key. + + Usage Example:: + from pastebin import PastebinAPI + x = PastebinAPI() + paste_to_delete = x.delete_paste( + '453a994e0e2f1efae07f8759e59e075b', + 'c57a18e6c0ae228cd4bd16fe36da381a', + 'WkgcTFtv') + print paste_to_delete + Paste Removed + + + @type api_dev_key: string + @param api_dev_key: The API Developer Key of a registered + U{http://pastebin.com} account. + + @type api_user_key: string + @param api_user_key: The API User Key of a U{http://pastebin.com} + registered user. + + @type api_paste_key: string + @param api_paste_key: The Paste Key of the paste to be deleted + (string after final / in + U{http://pastebin.com} URL). + + @rtype: string + @returns: A successful deletion returns 'Paste Removed'. + """ + + # Valid api developer key + argv = {'api_dev_key': str(api_dev_key)} + + # Requires pre-registered account + if api_user_key is not None: + argv['api_user_key'] = str(api_user_key) + + # Key of the paste to be deleted. + if api_paste_key is not None: + argv['api_paste_key'] = str(api_paste_key) + + # Valid API option - 'user_details' in this instance + argv['api_option'] = str('delete') + + # lets try to read the URL that we've just built. + request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv)) + response = request_string.read() + + return response + + def user_details(self, api_dev_key, api_user_key): + """Return user details of the user specified by the api_user_key. + + + Usage Example:: + from pastebin import PastebinAPI + x = PastebinAPI() + details = x.user_details('453a994e0e2f1efae07f8759e59e075b', 'c57a18e6c0ae228cd4bd16fe36da381a') + print details + + MonkeyPuzzle + python + N + http://pastebin.com/i/guest.gif + 0 + + user@email.com + + 0 + + + + @type api_dev_key: string + @param api_dev_key: The API Developer Key of a registered + U{http://pastebin.com} account. + + @type api_user_key: string + @param api_user_key: The API User Key of a U{http://pastebin.com} + registered user. + + @rtype: string + @returns: Returns an XML string containing user information. + """ + + # Valid api developer key + argv = {'api_dev_key': str(api_dev_key)} + + # Requires pre-registered account to generate an api_user_key + # (see generate_user_key) + if api_user_key is not None: + argv['api_user_key'] = str(api_user_key) + + # Valid API option - 'user_details' in this instance + argv['api_option'] = str('userdetails') + + # lets try to read the URL that we've just built. + request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv)) + response = request_string.read() + + # do some basic error checking here so we can gracefully handle any + # errors we are likely to encounter + if response.startswith(self._bad_request): + raise PastebinError(response) + + elif not response.startswith(''): + raise PastebinError(response) + + return response + + def trending(self, api_dev_key): + """Returns the top trending paste details. + + + Usage Example:: + from pastebin import PastebinAPI + x = PastebinAPI() + details = x.trending('453a994e0e2f1efae07f8759e59e075b') + print details + + jjMRFDH6 + 1333230838 + + 6416 + 0 + 0 + None + text + http://pastebin.com/jjMRFDH6 + 6384 + + + Note: Returns multiple trending pastes, not just 1. + + + @type api_dev_key: string + @param api_dev_key: The API Developer Key of a registered + U{http://pastebin.com} account. + + + @rtype: string + @return: Returns the string (XML formatted) containing the top + trending pastes. + """ + + # Valid api developer key + argv = {'api_dev_key': str(api_dev_key), 'api_option': str('trends')} + + # Valid API option - 'trends' is returns trending pastes + + # lets try to read the URL that we've just built. + request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv)) + response = request_string.read() + + # do some basic error checking here so we can gracefully handle any + # errors we are likely to encounter + if response.startswith(self._bad_request): + raise PastebinError(response) + + elif not response.startswith(''): + raise PastebinError(response) + + return response + + def pastes_by_user(self, api_dev_key, api_user_key, results_limit=None): + """Returns all pastes for the provided api_user_key. + + + Usage Example:: + from pastebin import PastebinAPI + x = PastebinAPI() + details = x.user_details('453a994e0e2f1efae07f8759e59e075b', + 'c57a18e6c0ae228cd4bd16fe36da381a', + 100) + print details + + DLiSspYT + 1332714730 + Pastebin.py - Python 3.2 Pastebin.com API + 25300 + 0 + 0 + Python + python + http://pastebin.com/DLiSspYT + 70 + + + Note: Returns multiple pastes, not just 1. + + + @type api_dev_key: string + @param api_dev_key: The API Developer Key of a registered + U{http://pastebin.com} account. + + @type api_user_key: string + @param api_user_key: The API User Key of a U{http://pastebin.com} + registered user. + + @type results_limit: number + @param results_limit: The number of pastes to return between 1 - 1000. + + @rtype: string + @returns: Returns an XML string containing number of specified pastes + by user. + """ + + # Valid api developer key + argv = {'api_dev_key': str(api_dev_key)} + + # Requires pre-registered account + if api_user_key is not None: + argv['api_user_key'] = str(api_user_key) + + # Number of results to return - between 1 & 1000, default = 50 + if results_limit is None: + argv['api_results_limit'] = 50 + + if results_limit is not None: + if results_limit < 1: + argv['api_results_limit'] = 50 + elif results_limit > 1000: + argv['api_results_limit'] = 1000 + else: + argv['api_results_limit'] = int(results_limit) + + # Valid API option - 'paste' is default for new paste + argv['api_option'] = str('list') + + # lets try to read the URL that we've just built. + request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv)) + response = request_string.read() + + # do some basic error checking here so we can gracefully handle any + # errors we are likely to encounter + if response.startswith(self._bad_request): + raise PastebinError(response) + + elif not response.startswith(''): + raise PastebinError(response) + + return response + + def generate_user_key(self, api_dev_key, username, password): + """Generate a user session key - needed for other functions. + + + Usage Example:: + from pastebin import PastebinAPI + x = PastebinAPI() + my_key = x.generate_user_key( + '453a994e0e2f1efae07f8759e59e075b', + 'MonkeyPuzzle', + '12345678') + print my_key + c57a18e6c0ae228cd4bd16fe36da381a + + + @type api_dev_key: string + @param api_dev_key: The API Developer Key of a registered + U{http://pastebin.com} account. + + @type username: string + @param username: The username of a registered U{http://pastebin.com} + account. + + @type password: string + @param password: The password of a registered U{http://pastebin.com} + account. + + @rtype: string + @returns: Session key (api_user_key) to allow authenticated + interaction to the API. + + """ + # Valid api developer key + argv = {'api_dev_key': str(api_dev_key)} + + # Requires pre-registered pastebin account + if username is not None: + argv['api_user_name'] = str(username) + + # Requires pre-registered pastebin account + if password is not None: + argv['api_user_password'] = str(password) + + # lets try to read the URL that we've just built. + data = urllib.urlencode(argv) + request_string = urllib.urlopen(self._api_login_url, data) + response = request_string.read() + + # do some basic error checking here so we can gracefully handle + # any errors we are likely to encounter + if response.startswith(self._bad_request): + raise PastebinError(response) + + return response + + def paste(self, api_dev_key, api_paste_code, + api_user_key=None, paste_name=None, paste_format=None, + paste_private=None, paste_expire_date=None): + + """Submit a code snippet to Pastebin using the new API. + + + Usage Example:: + from pastebin import PastebinAPI + x = PastebinAPI() + url = x.paste( + '453a994e0e2f1efae07f8759e59e075b' , + 'Snippet of code to paste goes here', + paste_name = 'title of paste', + api_user_key = 'c57a18e6c0ae228cd4bd16fe36da381a', + paste_format = 'python', + paste_private = 'unlisted', + paste_expire_date = '10M') + print url + http://pastebin.com/tawPUgqY + + + @type api_dev_key: string + @param api_dev_key: The API Developer Key of a registered + U{http://pastebin.com} account. + + @type api_paste_code: string + @param api_paste_code: The file or string to paste to body of the + U{http://pastebin.com} paste. + + @type api_user_key: string + @param api_user_key: The API User Key of a U{http://pastebin.com} + registered user. + If none specified, paste is made as a guest. + + @type paste_name: string + @param paste_name: (Optional) Title of the paste. + Default is to paste anonymously. + + @type paste_format: string + @param paste_format: (Optional) Programming language of the code being + pasted. This enables syntax highlighting when reading the code in + U{http://pastebin.com}. Default is no syntax highlighting (text is + just text and not source code). + + @type paste_private: string + @param paste_private: (Optional) C{'public'} if the paste is public + (visible by everyone), C{'unlisted'} if it's public but not + searchable. C{'private'} if the paste is private and not + searchable or indexed. + The Pastebin FAQ (U{http://pastebin.com/faq}) claims + private pastes are not indexed by search engines (aka Google). + + @type paste_expire_date: str + @param paste_expire_date: (Optional) Expiration date for the paste. + Once past this date the paste is deleted automatically. Valid + values are found in the L{PastebinAPI.paste_expire_date} class + member. + If not provided, the paste never expires. + + @rtype: string + @return: Returns the URL to the newly created paste. + """ + + # Valid api developer key + argv = {'api_dev_key': str(api_dev_key)} + + # Code snippet to submit + if api_paste_code is not None: + argv['api_paste_code'] = str(api_paste_code) + + # Valid API option - 'paste' is default for new paste + argv['api_option'] = str('paste') + + # API User Key + if api_user_key is not None: + argv['api_user_key'] = str(api_user_key) + elif api_user_key is None: + argv['api_user_key'] = str('') + + # Name of the poster + if paste_name is not None: + argv['api_paste_name'] = str(paste_name) + + # Syntax highlighting + if paste_format is not None: + paste_format = str(paste_format).strip().lower() + argv['api_paste_format'] = paste_format + + # Is the snippet private? + if paste_private is not None: + if paste_private == 'public': + argv['api_paste_private'] = int(0) + elif paste_private == 'unlisted': + argv['api_paste_private'] = int(1) + elif paste_private == 'private': + argv['api_paste_private'] = int(2) + + # Expiration for the snippet + if paste_expire_date is not None: + paste_expire_date = str(paste_expire_date).strip().upper() + argv['api_paste_expire_date'] = paste_expire_date + + # lets try to read the URL that we've just built. + request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv)) + response = request_string.read() + + # do some basic error checking here so we can gracefully handle any + # errors we are likely to encounter + if response.startswith(self._bad_request): + raise PastebinError(response) + elif not response.startswith(self._prefix_url): + raise PastebinError(response) + + return response + + def legacy_paste(self, paste_code, + paste_name=None, paste_private=None, + paste_expire_date=None, paste_format=None): + """Unofficial python interface to the Pastebin legacy API. + + Unlike the official API, this one doesn't require an API key, so it's + virtually anonymous. + + + Usage Example:: + from pastebin import PastebinAPI + x = PastebinAPI() + url = x.legacy_paste('Snippet of code to paste goes here', + paste_name = 'title of paste', + paste_private = 'unlisted', + paste_expire_date = '10M', + paste_format = 'python') + print url + http://pastebin.com/tawPUgqY + + + @type paste_code: string + @param paste_code: The file or string to paste to body of the + U{http://pastebin.com} paste. + + @type paste_name: string + @param paste_name: (Optional) Title of the paste. + Default is to paste with no title. + + @type paste_private: string + @param paste_private: (Optional) C{'public'} if the paste is public + (visible by everyone), C{'unlisted'} if it's public but not + searchable. C{'private'} if the paste is private and not + searchable or indexed. + The Pastebin FAQ (U{http://pastebin.com/faq}) claims + private pastes are not indexed by search engines (aka Google). + + @type paste_expire_date: string + @param paste_expire_date: (Optional) Expiration date for the paste. + Once past this date the paste is deleted automatically. Valid + values are found in the L{PastebinAPI.paste_expire_date} class + member. + If not provided, the paste never expires. + + @type paste_format: string + @param paste_format: (Optional) Programming language of the code being + pasted. This enables syntax highlighting when reading the code in + U{http://pastebin.com}. Default is no syntax highlighting (text is + just text and not source code). + + @rtype: string + @return: Returns the URL to the newly created paste. + """ + + # Code snippet to submit + argv = {'paste_code': str(paste_code)} + + # Name of the poster + if paste_name is not None: + argv['paste_name'] = str(paste_name) + + # Is the snippet private? + if paste_private is not None: + argv['paste_private'] = int(bool(int(paste_private))) + + # Expiration for the snippet + if paste_expire_date is not None: + paste_expire_date = str(paste_expire_date).strip().upper() + argv['paste_expire_date'] = paste_expire_date + + # Syntax highlighting + if paste_format is not None: + paste_format = str(paste_format).strip().lower() + argv['paste_format'] = paste_format + + # lets try to read the URL that we've just built. + data = urllib.urlencode(argv) + request_string = urllib.urlopen(self._legacy_api_url, data) + response = request_string.read() + + # do some basic error checking here so we can gracefully handle any + # errors we are likely to encounter + if response.startswith(self._bad_request): + raise PastebinError(response) + elif not response.startswith(self._prefix_url): + raise PastebinError(response) + + return response + + +###################################################### + +delete_paste = PastebinAPI.delete_paste +user_details = PastebinAPI.user_details +trending = PastebinAPI.trending +pastes_by_user = PastebinAPI.pastes_by_user +generate_user_key = PastebinAPI.generate_user_key +legacy_paste = PastebinAPI.legacy_paste +paste = PastebinAPI.paste -- cgit v1.2.3 From 4fddabec963015655a7129f1f95b95412b10ccf6 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Mon, 24 Feb 2014 18:38:39 -0300 Subject: Add pastebin support for upload logs. --- src/leap/bitmask/util/constants.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src/leap/bitmask/util') diff --git a/src/leap/bitmask/util/constants.py b/src/leap/bitmask/util/constants.py index e6a6bdce..e7e72cc4 100644 --- a/src/leap/bitmask/util/constants.py +++ b/src/leap/bitmask/util/constants.py @@ -17,3 +17,4 @@ SIGNUP_TIMEOUT = 5 REQUEST_TIMEOUT = 15 +PASTEBIN_API_DEV_KEY = "09563100642af6085d641f749a1922b4" -- cgit v1.2.3 From cebbb1eaee51ad9a7e57016dfc62d53888bc5bd4 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Tue, 1 Apr 2014 17:03:08 -0300 Subject: Cleanup strings. --- src/leap/bitmask/util/leap_argparse.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/leap/bitmask/util') diff --git a/src/leap/bitmask/util/leap_argparse.py b/src/leap/bitmask/util/leap_argparse.py index 56bf26dc..7f81881d 100644 --- a/src/leap/bitmask/util/leap_argparse.py +++ b/src/leap/bitmask/util/leap_argparse.py @@ -27,9 +27,10 @@ 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-2014 The LEAP Encryption Access Project" - parser = argparse.ArgumentParser(description=""" -Launches the Bitmask client.""", epilog=epilog) + parser = argparse.ArgumentParser( + description="Launches the Bitmask client.", + epilog="Copyright 2012-2014 The LEAP Encryption Access Project") + parser.add_argument('-d', '--debug', action="store_true", help=("Launches Bitmask in debug mode, writing debug " "info to stdout.")) -- cgit v1.2.3 From 5b21dfa2ca18ef4840d908b27228f55b8e65b172 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Tue, 1 Apr 2014 17:03:14 -0300 Subject: Add support for self signed certs. Closes #5391. --- src/leap/bitmask/util/leap_argparse.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/leap/bitmask/util') diff --git a/src/leap/bitmask/util/leap_argparse.py b/src/leap/bitmask/util/leap_argparse.py index 7f81881d..88267ff8 100644 --- a/src/leap/bitmask/util/leap_argparse.py +++ b/src/leap/bitmask/util/leap_argparse.py @@ -93,6 +93,12 @@ def build_parser(): "Use at your own risk!") parser.add_argument('--danger', action="store_true", help=help_text) + # optional cert file used to check domains with self signed certs. + parser.add_argument('--ca-cert-file', metavar="/path/to/cacert.pem", + nargs='?', action="store", dest="ca_cert_file", + help='Uses the given cert file to verify ' + 'against domains.') + # Not in use, we might want to reintroduce them. #parser.add_argument('-i', '--no-provider-checks', #action="store_true", default=False, -- cgit v1.2.3