diff options
| -rw-r--r-- | changes/feature_support-requests | 1 | ||||
| -rw-r--r-- | src/leap/crypto/srpauth.py | 25 | ||||
| -rw-r--r-- | src/leap/gui/wizard.py | 6 | 
3 files changed, 23 insertions, 9 deletions
diff --git a/changes/feature_support-requests b/changes/feature_support-requests new file mode 100644 index 00000000..38b9ece5 --- /dev/null +++ b/changes/feature_support-requests @@ -0,0 +1 @@ +  o Add support for requests < 1.0.0
\ No newline at end of file diff --git a/src/leap/crypto/srpauth.py b/src/leap/crypto/srpauth.py index 26bd0295..dbaac01b 100644 --- a/src/leap/crypto/srpauth.py +++ b/src/leap/crypto/srpauth.py @@ -20,12 +20,14 @@ import logging  import requests  import srp +import json  from PySide import QtCore, QtGui  from leap.common.check import leap_assert  from leap.config.providerconfig import ProviderConfig  from leap.util.checkerthread import CheckerThread +from leap.util.request_helpers import get_content  from leap.common.events import signal as events_signal  from leap.common.events import events_pb2 as proto @@ -159,14 +161,18 @@ class SRPAuth(QtCore.QObject):                  raise SRPAuthenticationError("Unknown error: %r" %                                               (e,)) +            content, mtime = get_content(init_session) +              if init_session.status_code not in (200,):                  logger.error("No valid response (salt): "                               "Status code = %r. Content: %r" % -                             (init_session.status_code, init_session.content)) +                             (init_session.status_code, content))                  if init_session.status_code == 422:                      raise SRPAuthenticationError(self.tr("Unknown user")) -            salt = init_session.json().get("salt", None) -            B = init_session.json().get("B", None) + +            json_content = json.loads(content) +            salt = json_content.get("salt", None) +            B = json_content.get("B", None)              if salt is None:                  logger.error("No salt parameter sent") @@ -226,22 +232,25 @@ class SRPAuth(QtCore.QObject):                  raise SRPAuthenticationError(self.tr("Could not connect to "                                                       "the server")) +            content, mtime = get_content(auth_result) +              if auth_result.status_code == 422:                  logger.error("[%s] Wrong password (HAMK): [%s]" %                               (auth_result.status_code, -                              auth_result.json(). +                              content.                                get("errors", "")))                  raise SRPAuthenticationError(self.tr("Wrong password"))              if auth_result.status_code not in (200,):                  logger.error("No valid response (HAMK): "                               "Status code = %s. Content = %r" % -                             (auth_result.status_code, auth_result.content)) +                             (auth_result.status_code, content))                  raise SRPAuthenticationError(self.tr("Unknown error (%s)") %                                               (auth_result.status_code,)) -            M2 = auth_result.json().get("M2", None) -            uid = auth_result.json().get("id", None) +            json_content = json.loads(content) +            M2 = json_content.get("M2", None) +            uid = json_content.get("id", None)              token = auth_result.json().get("token", None)              events_signal(proto.CLIENT_UID, content=uid) @@ -251,7 +260,7 @@ class SRPAuth(QtCore.QObject):              if M2 is None or self.get_uid() is None:                  logger.error("Something went wrong. Content = %r" % -                             (auth_result.content,)) +                             (content,))                  raise SRPAuthenticationError(self.tr("Problem getting data "                                                       "from server")) diff --git a/src/leap/gui/wizard.py b/src/leap/gui/wizard.py index ad45dd8c..713383a6 100644 --- a/src/leap/gui/wizard.py +++ b/src/leap/gui/wizard.py @@ -20,6 +20,7 @@ First run wizard  """  import os  import logging +import json  from PySide import QtCore, QtGui  from functools import partial @@ -28,6 +29,7 @@ from ui_wizard import Ui_Wizard  from leap.config.providerconfig import ProviderConfig  from leap.crypto.srpregister import SRPRegister  from leap.util.privilege_policies import is_missing_policy_permissions +from leap.util.request_helpers import get_content  from leap.services.eip.providerbootstrapper import ProviderBootstrapper  logger = logging.getLogger(__name__) @@ -254,7 +256,9 @@ class Wizard(QtGui.QWizard):              self._password = None              error_msg = self.tr("Unknown error")              try: -                error_msg = req.json().get("errors").get("login")[0] +                content, _ = get_content(req) +                json_content = json.loads(content) +                error_msg = json_content.get("errors").get("login")[0]                  if not error_msg.istitle():                      error_msg = "%s %s" % (old_username, error_msg)                  self._set_register_status(error_msg, error=True)  | 
