diff options
author | Kali Kaneko (leap communications) <kali@leap.se> | 2016-10-27 00:48:54 +0200 |
---|---|---|
committer | Kali Kaneko (leap communications) <kali@leap.se> | 2016-11-03 14:28:04 +0100 |
commit | 3d2d564a966679086156c844d8c58b11751163a3 (patch) | |
tree | 15c6b2cbd4541335c94a7808e0acb19d443b2232 /src/leap | |
parent | 12bbdc84a744aaa2af4130539a2a7188996c7659 (diff) |
[style] pep8 fixes
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/bitmask/core/__init__.py | 21 | ||||
-rw-r--r-- | src/leap/bitmask/core/launcher.py | 1 | ||||
-rw-r--r-- | src/leap/bitmask/core/uuid_map.py | 21 | ||||
-rw-r--r-- | src/leap/bitmask/gui/app.py | 57 | ||||
-rw-r--r-- | src/leap/bitmask/keymanager/__init__.py | 8 | ||||
-rw-r--r-- | src/leap/bitmask/keymanager/openpgp.py | 27 | ||||
-rw-r--r-- | src/leap/bitmask/keymanager/wrapper.py | 18 | ||||
-rw-r--r-- | src/leap/bitmask/util.py | 2 |
8 files changed, 81 insertions, 74 deletions
diff --git a/src/leap/bitmask/core/__init__.py b/src/leap/bitmask/core/__init__.py index 55672e4e..5af0f38f 100644 --- a/src/leap/bitmask/core/__init__.py +++ b/src/leap/bitmask/core/__init__.py @@ -1,15 +1,20 @@ import platform +# FIXME some temporary imports to make the modules +# appear in the coverage report. Remove the imports when +# test code cover them. + + +def dummy_imports(): + import service + import uuid_map + import mail_services + import dispatcher + APPNAME = "bitmask.core" -if platform.system() =='Windows': +if platform.system() == 'Windows': ENDPOINT = "tcp://127.0.0.1:5001" else: ENDPOINT = "ipc:///tmp/%s.sock" % APPNAME -# FIXME some temporary imports to make the modules -# appear in the coverage report. Remove the imports when -# test code cover them. -import service -import uuid_map -import mail_services -import dispatcher +dummy_imports() diff --git a/src/leap/bitmask/core/launcher.py b/src/leap/bitmask/core/launcher.py index 62e8575d..c6a2ab4a 100644 --- a/src/leap/bitmask/core/launcher.py +++ b/src/leap/bitmask/core/launcher.py @@ -32,6 +32,7 @@ pid = abspath(join(get_path_prefix(), 'leap', 'bitmaskd.pid')) STANDALONE = getattr(sys, 'frozen', False) + def here(module=None): if STANDALONE: # we are running in a |PyInstaller| bundle diff --git a/src/leap/bitmask/core/uuid_map.py b/src/leap/bitmask/core/uuid_map.py index b7041aa7..9c13fc57 100644 --- a/src/leap/bitmask/core/uuid_map.py +++ b/src/leap/bitmask/core/uuid_map.py @@ -33,7 +33,8 @@ if IS_WIN: import socket from cryptography.fernet import Fernet from cryptography.hazmat.backends.multibackend import MultiBackend - from cryptography.hazmat.backends.openssl.backend import Backend as OpenSSLBackend + from cryptography.hazmat.backends.openssl.backend \ + import Backend as OpenSSLBackend crypto_backend = MultiBackend([OpenSSLBackend()]) @@ -114,9 +115,9 @@ def _encode_uuid_map(userid, uuid, passwd): # TODO review usage of the raw passwd here if IS_WIN: key = scrypt.hash(passwd, socket.gethostname()) - key = base64.urlsafe_b64encode(key[:32]) - f = Fernet(key, backend=crypto_backend) - encrypted = f.encrypt(data) + key = base64.urlsafe_b64encode(key[:32]) + f = Fernet(key, backend=crypto_backend) + encrypted = f.encrypt(data) else: encrypted = scrypt.encrypt(data, passwd, maxtime=0.05) return base64.urlsafe_b64encode(encrypted) @@ -126,12 +127,12 @@ def _decode_uuid_line(line, passwd): decoded = base64.urlsafe_b64decode(line) if IS_WIN: key = scrypt.hash(passwd, socket.gethostname()) - key = base64.urlsafe_b64encode(key[:32]) - try: - f = Fernet(key, backend=crypto_backend) - maybe_decrypted = f.decrypt(key) - except Exception: - return None + key = base64.urlsafe_b64encode(key[:32]) + try: + f = Fernet(key, backend=crypto_backend) + maybe_decrypted = f.decrypt(key) + except Exception: + return None else: try: maybe_decrypted = scrypt.decrypt(decoded, passwd, maxtime=0.1) diff --git a/src/leap/bitmask/gui/app.py b/src/leap/bitmask/gui/app.py index f812a6b0..d70c238f 100644 --- a/src/leap/bitmask/gui/app.py +++ b/src/leap/bitmask/gui/app.py @@ -27,6 +27,9 @@ import signal import sys from functools import partial +from multiprocessing import Process + +from leap.bitmask.core.launcher import run_bitmaskd, pid if platform.system() == 'Windows': from multiprocessing import freeze_support @@ -43,11 +46,6 @@ else: from PyQt5.QtWidgets import QApplication from PyQt5.QtWebKitWidgets import QWebView -from multiprocessing import Process - -from leap.bitmask.core.launcher import run_bitmaskd, pid - - BITMASK_URI = 'http://localhost:7070' @@ -62,30 +60,31 @@ class BrowserWindow(QDialog): def __init__(self, parent): super(BrowserWindow, self).__init__(parent) - if IS_WIN: - self.view = QWebView(self) - win_size = QSize(1024, 600) - self.setMinimumSize(win_size) - self.view.page().setViewportSize(win_size) - self.view.page().setPreferredContentsSize(win_size) + if IS_WIN: + self.view = QWebView(self) + win_size = QSize(1024, 600) + self.setMinimumSize(win_size) + self.view.page().setViewportSize(win_size) + self.view.page().setPreferredContentsSize(win_size) else: self.view = QWebView(self) - win_size = QSize(800, 600) - self.win_size = win_size - self.resize(win_size) - - if DEBUG: - self.view.settings().setAttribute( - QtWebKit.QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) + win_size = QSize(800, 600) + self.win_size = win_size + self.resize(win_size) + + if DEBUG: + self.view.settings().setAttribute( + QtWebKit.QWebSettings.WebAttribute.DeveloperExtrasEnabled, + True) self.inspector = QtWebKit.QWebInspector(self) - self.inspector.setPage(self.view.page()) - self.inspector.show() - self.splitter = QtGui.QSplitter() - self.splitter.addWidget(self.view) - self.splitter.addWidget(self.inspector) - #TODO add layout also in non-DEBUG mode - layout = QtGui.QVBoxLayout(self) - layout.addWidget(self.splitter) + self.inspector.setPage(self.view.page()) + self.inspector.show() + self.splitter = QtGui.QSplitter() + self.splitter.addWidget(self.view) + self.splitter.addWidget(self.inspector) + # TODO add layout also in non-DEBUG mode + layout = QtGui.QVBoxLayout(self) + layout.addWidget(self.splitter) self.setWindowTitle('Bitmask') self.load_app() @@ -100,7 +99,7 @@ class BrowserWindow(QDialog): self.closing = True global bitmaskd bitmaskd.join() - if os.path.isfile(pid): + if os.path.isfile(pid): with open(pid) as f: pidno = int(f.read()) print('[bitmask] terminating bitmaskd...') @@ -115,7 +114,6 @@ class BrowserWindow(QDialog): sys.exit(1) - def _handle_kill(*args, **kw): win = kw.get('win') if win: @@ -141,7 +139,6 @@ def launch_gui(): signal.SIGINT, partial(_handle_kill, win=browser)) - # Avoid code to get stuck inside c++ loop, returning control # to python land. timer = QtCore.QTimer() @@ -160,7 +157,7 @@ def start_app(): if platform.system() == 'Windows': # In windows, there are some args added to the invocation - # by PyInstaller, I guess... + # by PyInstaller, I guess... MIN_ARGS = 3 else: MIN_ARGS = 1 diff --git a/src/leap/bitmask/keymanager/__init__.py b/src/leap/bitmask/keymanager/__init__.py index 3798ce06..27c9853d 100644 --- a/src/leap/bitmask/keymanager/__init__.py +++ b/src/leap/bitmask/keymanager/__init__.py @@ -98,11 +98,11 @@ class KeyManager(object): self.uid = uid self._openpgp = OpenPGPScheme(soledad, gpgbinary=gpgbinary) create = self._create_combined_bundle_file - try: + try: self._combined_ca_bundle = combined_ca_bundle or create() - except Exception: - logger.warn('error while creating combined ca bundle') - self._combined_ca_bundle = '' + except Exception: + logger.warn('error while creating combined ca bundle') + self._combined_ca_bundle = '' self._async_client = HTTPClient(self._combined_ca_bundle) self._async_client_pinned = HTTPClient(self._ca_cert_path) diff --git a/src/leap/bitmask/keymanager/openpgp.py b/src/leap/bitmask/keymanager/openpgp.py index 5c977946..02b54563 100644 --- a/src/leap/bitmask/keymanager/openpgp.py +++ b/src/leap/bitmask/keymanager/openpgp.py @@ -63,11 +63,14 @@ try: GNUPG_NG = True except ImportError: GNUPG_NG = False + class GPGUtilities(object): + def __init__(self, gpg): - self.gpg = gpg - def is_encrypted_asym(self, raw_data): - result = self._gpg.list_packets(raw_data) + self.gpg = gpg + + def is_encrypted_asym(self, raw_data): + result = self._gpg.list_packets(raw_data) return bool(result.key) @@ -586,10 +589,10 @@ class OpenPGPScheme(object): passphrase=passphrase, symmetric=False, cipher_algo=cipher_algo) if not GNUPG_NG: - kw.pop('cipher_algo') - kw.pop('default_key') - kw.update(passphrase='') - kw.update(always_trust=True) + kw.pop('cipher_algo') + kw.pop('default_key') + kw.update(passphrase='') + kw.update(always_trust=True) result = yield from_thread( gpg.encrypt, data, pubkey.fingerprint, **kw) @@ -692,12 +695,12 @@ class OpenPGPScheme(object): # result.fingerprint - contains the fingerprint of the key used to # sign. with TempGPGWrapper(privkey, self._gpgbinary) as gpg: - kw = dict(default_key=privkey.fingerprint, - digest_algo=digest_algo, clearsign=clearsign, - detach=detach, binary=binary) + kw = dict(default_key=privkey.fingerprint, + digest_algo=digest_algo, clearsign=clearsign, + detach=detach, binary=binary) if not GNUPG_NG: - kw.pop('digest_algo') - kw.pop('default_key') + kw.pop('digest_algo') + kw.pop('default_key') result = gpg.sign(data, **kw) rfprint = privkey.fingerprint privkey = gpg.list_keys(secret=True).pop() diff --git a/src/leap/bitmask/keymanager/wrapper.py b/src/leap/bitmask/keymanager/wrapper.py index 1fd44295..ef8e6640 100644 --- a/src/leap/bitmask/keymanager/wrapper.py +++ b/src/leap/bitmask/keymanager/wrapper.py @@ -105,11 +105,11 @@ class TempGPGWrapper(object): self._gpg = GPG(binary=self._gpgbinary, homedir=tempfile.mkdtemp()) except TypeError: - # compat-mode with python-gnupg until windows - # support is fixed in gnupg-ng + # compat-mode with python-gnupg until windows + # support is fixed in gnupg-ng self._gpg = GPG(gpgbinary=self._gpgbinary, gnupghome=tempfile.mkdtemp(), - options=[]) + options=[]) leap_assert(len(listkeys()) is 0, 'Keyring not empty.') @@ -150,16 +150,16 @@ class TempGPGWrapper(object): raise finally: - try: - homedir = self._gpg.homedir + try: + homedir = self._gpg.homedir except AttributeError: - homedir = self._gpg.gnupghome + homedir = self._gpg.gnupghome leap_assert(homedir != os.path.expanduser('~/.gnupg'), "watch out! Tried to remove default gnupg home!") # TODO some windows debug .... - homedir = os.path.normpath(homedir).replace("\\", "/") - homedir = str(homedir.replace("c:/", "c://")) + homedir = os.path.normpath(homedir).replace("\\", "/") + homedir = str(homedir.replace("c:/", "c://")) if platform.system() == "Windows": - logger.error("BUG! Not erasing folder in Windows") + logger.error("BUG! Not erasing folder in Windows") return shutil.rmtree(homedir) diff --git a/src/leap/bitmask/util.py b/src/leap/bitmask/util.py index 7195b180..0283a032 100644 --- a/src/leap/bitmask/util.py +++ b/src/leap/bitmask/util.py @@ -63,7 +63,7 @@ def get_gpg_bin_path(): elif platform.system() == "Darwin": gpgbin = os.path.abspath( os.path.join(here(), "apps", "mail", "gpg")) - else: + else: gpgbin = os.path.join( get_path_prefix(), "..", "apps", "mail", "gpg") else: |