summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.rst3
-rw-r--r--changes/feature_save-token1
-rw-r--r--changes/feature_support-requests1
-rw-r--r--src/leap/crypto/srpauth.py37
-rw-r--r--src/leap/gui/mainwindow.py3
-rw-r--r--src/leap/gui/wizard.py6
-rw-r--r--src/leap/platform_init/locks.py8
7 files changed, 42 insertions, 17 deletions
diff --git a/README.rst b/README.rst
index 63dfd83a..887552b3 100644
--- a/README.rst
+++ b/README.rst
@@ -28,8 +28,7 @@ Installing
After getting the source and installing all the dependencies, proceed to install ``leap-client`` package::
$ make
- $ export LEAP_VENV_SKIP_PYSIDE=1 # This will avoid building PySide from source
- $ sudo python setup.py install
+ $ sudo LEAP_VENV_SKIP_PYSIDE=1 python setup.py install
Running
-------
diff --git a/changes/feature_save-token b/changes/feature_save-token
new file mode 100644
index 00000000..dc347310
--- /dev/null
+++ b/changes/feature_save-token
@@ -0,0 +1 @@
+ o Saves the token to allow token authenticated queries. \ No newline at end of file
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 9446cee8..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
@@ -82,6 +84,8 @@ class SRPAuth(QtCore.QObject):
self._session_id_lock = QtCore.QMutex()
self._uid = None
self._uid_lock = QtCore.QMutex()
+ self._token = None
+ self._token_lock = QtCore.QMutex()
self._srp_user = None
self._srp_a = None
@@ -157,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")
@@ -224,30 +232,35 @@ 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)
self.set_uid(uid)
+ self.set_token(token)
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"))
@@ -356,6 +369,14 @@ class SRPAuth(QtCore.QObject):
QtCore.QMutexLocker(self._uid_lock)
return self._uid
+ def set_token(self, token):
+ QtCore.QMutexLocker(self._token_lock)
+ self._token = token
+
+ def get_token(self, token):
+ QtCore.QMutexLocker(self._token_lock)
+ return self._token
+
__instance = None
authentication_finished = QtCore.Signal(bool, str)
diff --git a/src/leap/gui/mainwindow.py b/src/leap/gui/mainwindow.py
index ccf97672..b3ab56d3 100644
--- a/src/leap/gui/mainwindow.py
+++ b/src/leap/gui/mainwindow.py
@@ -47,6 +47,9 @@ from leap.services.eip.vpnlaunchers import (VPNLauncherException,
from leap.util import __version__ as VERSION
from leap.util.checkerthread import CheckerThread
+if IS_WIN:
+ from leap.platform_init.locks import WindowsLock
+
from ui_mainwindow import Ui_MainWindow
logger = logging.getLogger(__name__)
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)
diff --git a/src/leap/platform_init/locks.py b/src/leap/platform_init/locks.py
index e5b392a3..fefc209b 100644
--- a/src/leap/platform_init/locks.py
+++ b/src/leap/platform_init/locks.py
@@ -17,7 +17,6 @@
"""
Utilities for handling multi-platform file locking mechanisms
"""
-import commands
import logging
import errno
import os
@@ -30,10 +29,8 @@ from leap import platform_init
if platform_init.IS_UNIX:
from fcntl import flock, LOCK_EX, LOCK_NB
else:
- import errno
import glob
import shutil
- import socket
from tempfile import gettempdir
@@ -177,7 +174,7 @@ if platform_init.IS_WIN:
"""
try:
self._fd = os.makedirs(self.name)
- except WindowsError as exc:
+ except OSError as exc:
# could not create the dir
if exc.args[0] == 183:
logger.debug('cannot create dir')
@@ -218,8 +215,7 @@ if platform_init.IS_WIN:
try:
shutil.rmtree(self.name)
return True
-
- except WindowsError as exc:
+ except shutil.WindowsError as exc:
if exc.errno in (errno.EPIPE, errno.ENOENT,
errno.ESRCH, errno.EACCES):
logger.warning(