From 30c922e03f61d9c588d4d4eca5edcdf2a5c4056c Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 23 Oct 2013 16:20:58 -0300 Subject: Use unicode values and encode them out. --- src/leap/bitmask/provider/providerbootstrapper.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/leap') diff --git a/src/leap/bitmask/provider/providerbootstrapper.py b/src/leap/bitmask/provider/providerbootstrapper.py index 1b5947e1..2adf8aa8 100644 --- a/src/leap/bitmask/provider/providerbootstrapper.py +++ b/src/leap/bitmask/provider/providerbootstrapper.py @@ -20,6 +20,7 @@ Provider bootstrapping import logging import socket import os +import sys import requests @@ -125,9 +126,13 @@ class ProviderBootstrapper(AbstractBootstrapper): # err --- but we can do it after a failure, to diagnose what went # wrong. Right now we're just adding connection overhead. -- kali + verify = self.verify + if verify: + verify = self.verify.encode(sys.getfilesystemencoding()) + try: res = self._session.get("https://%s" % (self._domain,), - verify=self.verify, + verify=verify, timeout=REQUEST_TIMEOUT) res.raise_for_status() except requests.exceptions.SSLError as exc: @@ -180,6 +185,8 @@ class ProviderBootstrapper(AbstractBootstrapper): # no ca? then download from main domain again. pass + if verify: + verify = verify.encode(sys.getfilesystemencoding()) logger.debug("Requesting for provider.json... " "uri: {0}, verify: {1}, headers: {2}".format( uri, verify, headers)) @@ -336,9 +343,9 @@ class ProviderBootstrapper(AbstractBootstrapper): test_uri = "%s/%s/cert" % (self._provider_config.get_api_uri(), self._provider_config.get_api_version()) - res = self._session.get(test_uri, - verify=self._provider_config - .get_ca_cert_path(), + ca_cert_path = self._provider_config.get_ca_cert_path() + ca_cert_path = ca_cert_path.encode(sys.getfilesystemencoding()) + res = self._session.get(test_uri, verify=ca_cert_path, timeout=REQUEST_TIMEOUT) res.raise_for_status() -- cgit v1.2.3 From d3ca8c456c7220a65ef0f88042fe49fb438eddc9 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 23 Oct 2013 17:34:11 -0300 Subject: Encode cert path before send it. --- src/leap/bitmask/crypto/srpauth.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/leap') diff --git a/src/leap/bitmask/crypto/srpauth.py b/src/leap/bitmask/crypto/srpauth.py index 47ed21b0..31316f17 100644 --- a/src/leap/bitmask/crypto/srpauth.py +++ b/src/leap/bitmask/crypto/srpauth.py @@ -17,6 +17,7 @@ import binascii import logging +import sys import requests import srp @@ -249,10 +250,13 @@ class SRPAuth(QtCore.QObject): (self._provider_config.get_api_uri(), self._provider_config.get_api_version(), "sessions") + + ca_cert_path = self._provider_config.get_ca_cert_path() + ca_cert_path = ca_cert_path.encode(sys.getfilesystemencoding()) + init_session = self._session.post(sessions_url, data=auth_data, - verify=self._provider_config. - get_ca_cert_path(), + verify=ca_cert_path, timeout=REQUEST_TIMEOUT) # Clean up A value, we don't need it anymore self._srp_a = None -- cgit v1.2.3 From aa9b0460a9320a0ec12e45e75011fce6b102ac58 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Thu, 24 Oct 2013 17:19:30 -0300 Subject: Encode paths before use them. --- src/leap/bitmask/services/__init__.py | 7 ++++++- src/leap/bitmask/services/soledad/soledadbootstrapper.py | 10 ++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src/leap') diff --git a/src/leap/bitmask/services/__init__.py b/src/leap/bitmask/services/__init__.py index f9456159..e62277b6 100644 --- a/src/leap/bitmask/services/__init__.py +++ b/src/leap/bitmask/services/__init__.py @@ -19,6 +19,7 @@ Services module. """ import logging import os +import sys from PySide import QtCore @@ -135,8 +136,12 @@ def download_service_config(provider_config, service_config, if token is not None: headers["Authorization"] = 'Token token="{0}"'.format(token) + verify = provider_config.get_ca_cert_path() + if verify: + verify = verify.encode(sys.getfilesystemencoding()) + res = session.get(config_uri, - verify=provider_config.get_ca_cert_path(), + verify=verify, headers=headers, timeout=REQUEST_TIMEOUT, cookies=cookies) diff --git a/src/leap/bitmask/services/soledad/soledadbootstrapper.py b/src/leap/bitmask/services/soledad/soledadbootstrapper.py index 4619ba80..3bb5fd84 100644 --- a/src/leap/bitmask/services/soledad/soledadbootstrapper.py +++ b/src/leap/bitmask/services/soledad/soledadbootstrapper.py @@ -20,6 +20,7 @@ Soledad bootstrapping import logging import os import socket +import sys from ssl import SSLError @@ -239,14 +240,15 @@ class SoledadBootstrapper(AbstractBootstrapper): """ # TODO: If selected server fails, retry with another host # (issue #3309) + encoding = sys.getfilesystemencoding() try: self._soledad = Soledad( uuid, - self._password.encode("utf-8"), - secrets_path=secrets_path, - local_db_path=local_db_path, + self._password.encode('utf-8'), + secrets_path=secrets_path.encode(encoding), + local_db_path=local_db_path.encode(encoding), server_url=server_url, - cert_file=cert_file, + cert_file=cert_file.encode(encoding), auth_token=auth_token) # XXX All these errors should be handled by soledad itself, -- cgit v1.2.3 From d6a40020d89a1dfab6c49aa710b6e84bc91140b6 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Fri, 25 Oct 2013 17:32:31 -0300 Subject: Handle encoding problems in the vpn connection. --- src/leap/bitmask/services/eip/darwinvpnlauncher.py | 5 ++++- src/leap/bitmask/services/eip/linuxvpnlauncher.py | 5 ++++- src/leap/bitmask/services/eip/vpnlauncher.py | 3 --- src/leap/bitmask/services/eip/vpnprocess.py | 18 +++++++++++++++--- 4 files changed, 23 insertions(+), 8 deletions(-) (limited to 'src/leap') diff --git a/src/leap/bitmask/services/eip/darwinvpnlauncher.py b/src/leap/bitmask/services/eip/darwinvpnlauncher.py index f3b6bfc8..fe3fe4c1 100644 --- a/src/leap/bitmask/services/eip/darwinvpnlauncher.py +++ b/src/leap/bitmask/services/eip/darwinvpnlauncher.py @@ -21,6 +21,7 @@ import commands import getpass import logging import os +import sys from leap.bitmask.services.eip.vpnlauncher import VPNLauncher from leap.bitmask.services.eip.vpnlauncher import VPNLauncherException @@ -185,6 +186,8 @@ class DarwinVPNLauncher(VPNLauncher): :rtype: dict """ + ld_library_path = os.path.join(get_path_prefix(), "..", "lib") + ld_library_path.encode(sys.getfilesystemencoding()) return { - "DYLD_LIBRARY_PATH": os.path.join(get_path_prefix(), "..", "lib") + "DYLD_LIBRARY_PATH": ld_library_path } diff --git a/src/leap/bitmask/services/eip/linuxvpnlauncher.py b/src/leap/bitmask/services/eip/linuxvpnlauncher.py index efb23285..d02f6f96 100644 --- a/src/leap/bitmask/services/eip/linuxvpnlauncher.py +++ b/src/leap/bitmask/services/eip/linuxvpnlauncher.py @@ -21,6 +21,7 @@ import commands import logging import os import subprocess +import sys import time from leap.bitmask.config import flags @@ -231,6 +232,8 @@ class LinuxVPNLauncher(VPNLauncher): :rtype: dict """ + ld_library_path = os.path.join(get_path_prefix(), "..", "lib") + ld_library_path.encode(sys.getfilesystemencoding()) return { - "LD_LIBRARY_PATH": os.path.join(get_path_prefix(), "..", "lib") + "LD_LIBRARY_PATH": ld_library_path } diff --git a/src/leap/bitmask/services/eip/vpnlauncher.py b/src/leap/bitmask/services/eip/vpnlauncher.py index bce3599b..07497814 100644 --- a/src/leap/bitmask/services/eip/vpnlauncher.py +++ b/src/leap/bitmask/services/eip/vpnlauncher.py @@ -250,9 +250,6 @@ class VPNLauncher(object): '--ping-restart', '30'] command_and_args = [openvpn] + args - logger.debug("Running VPN with command:") - logger.debug(" ".join(command_and_args)) - return command_and_args @classmethod diff --git a/src/leap/bitmask/services/eip/vpnprocess.py b/src/leap/bitmask/services/eip/vpnprocess.py index 19e1aa7b..51f0f738 100644 --- a/src/leap/bitmask/services/eip/vpnprocess.py +++ b/src/leap/bitmask/services/eip/vpnprocess.py @@ -23,6 +23,7 @@ import psutil import psutil.error import shutil import socket +import sys from itertools import chain, repeat @@ -864,15 +865,26 @@ class VPNProcess(protocol.ProcessProtocol, VPNManager): """ Gets the vpn command from the aproppriate launcher. - Might throw: VPNLauncherException, OpenVPNNotFoundException. + Might throw: + VPNLauncherException, + OpenVPNNotFoundException. + + :rtype: list of str """ - cmd = self._launcher.get_vpn_command( + command = self._launcher.get_vpn_command( eipconfig=self._eipconfig, providerconfig=self._providerconfig, socket_host=self._socket_host, socket_port=self._socket_port, openvpn_verb=self._openvpn_verb) - return map(str, cmd) + + encoding = sys.getfilesystemencoding() + for i, c in enumerate(command): + if not isinstance(c, str): + command[i] = c.encode(encoding) + + logger.debug("Running VPN with command: {0}".format(command)) + return command # shutdown -- cgit v1.2.3 From c90be9157d5423d055984b354c5712f6873336b8 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Tue, 29 Oct 2013 12:24:45 -0300 Subject: Update docstrings to unicode types. --- src/leap/bitmask/config/providerconfig.py | 5 +++-- src/leap/bitmask/gui/login.py | 4 ++-- src/leap/bitmask/services/soledad/soledadbootstrapper.py | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/leap') diff --git a/src/leap/bitmask/config/providerconfig.py b/src/leap/bitmask/config/providerconfig.py index 44698d83..e80b2337 100644 --- a/src/leap/bitmask/config/providerconfig.py +++ b/src/leap/bitmask/config/providerconfig.py @@ -169,11 +169,12 @@ class ProviderConfig(BaseConfig): checking if the cert exists because we are about to write it. :type about_to_download: bool + + :rtype: unicode """ cert_path = os.path.join(get_path_prefix(), "leap", "providers", - self.get_domain(), - "keys", "ca", "cacert.pem") + self.get_domain(), "keys", "ca", "cacert.pem") if not about_to_download: cert_exists = os.path.exists(cert_path) diff --git a/src/leap/bitmask/gui/login.py b/src/leap/bitmask/gui/login.py index ac34fe23..255a06d3 100644 --- a/src/leap/bitmask/gui/login.py +++ b/src/leap/bitmask/gui/login.py @@ -168,7 +168,7 @@ class LoginWidget(QtGui.QWidget): """ Returns the user that appears in the widget. - :rtype: str + :rtype: unicode """ return self.ui.lnUser.text() @@ -185,7 +185,7 @@ class LoginWidget(QtGui.QWidget): """ Returns the password that appears in the widget - :rtype: str + :rtype: unicode """ return self.ui.lnPassword.text() diff --git a/src/leap/bitmask/services/soledad/soledadbootstrapper.py b/src/leap/bitmask/services/soledad/soledadbootstrapper.py index 3bb5fd84..c673ea61 100644 --- a/src/leap/bitmask/services/soledad/soledadbootstrapper.py +++ b/src/leap/bitmask/services/soledad/soledadbootstrapper.py @@ -414,9 +414,9 @@ class SoledadBootstrapper(AbstractBootstrapper): :param provider_config: Provider configuration :type provider_config: ProviderConfig :param user: User's login - :type user: str + :type user: unicode :param password: User's password - :type password: str + :type password: unicode :param download_if_needed: If True, it will only download files if the have changed since the time it was previously downloaded. -- cgit v1.2.3