From 17f608f0148c2340a811d6eb85bebd2e612f10be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Fri, 5 Jul 2013 12:50:10 -0300 Subject: Set global request timeout to REQUEST_TIMEOUT (10 secs) --- changes/bug2878-unreachable_provider | 2 ++ src/leap/crypto/constants.py | 18 ------------------ src/leap/crypto/srpauth.py | 10 +++++++--- src/leap/crypto/srpregister.py | 2 +- src/leap/services/eip/eipbootstrapper.py | 7 +++++-- src/leap/services/eip/providerbootstrapper.py | 13 +++++++++---- src/leap/util/constants.py | 19 +++++++++++++++++++ 7 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 changes/bug2878-unreachable_provider delete mode 100644 src/leap/crypto/constants.py create mode 100644 src/leap/util/constants.py diff --git a/changes/bug2878-unreachable_provider b/changes/bug2878-unreachable_provider new file mode 100644 index 00000000..d23e4f8a --- /dev/null +++ b/changes/bug2878-unreachable_provider @@ -0,0 +1,2 @@ + o Set timeout for requests to 10 seconds globally, configurable from + leap.util.constants. Fixes #2878. \ No newline at end of file diff --git a/src/leap/crypto/constants.py b/src/leap/crypto/constants.py deleted file mode 100644 index c5eaef1f..00000000 --- a/src/leap/crypto/constants.py +++ /dev/null @@ -1,18 +0,0 @@ -# -*- coding: utf-8 -*- -# constants.py -# Copyright (C) 2013 LEAP -# -# 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 . - -SIGNUP_TIMEOUT = 5 diff --git a/src/leap/crypto/srpauth.py b/src/leap/crypto/srpauth.py index 0e95ae64..89fee80b 100644 --- a/src/leap/crypto/srpauth.py +++ b/src/leap/crypto/srpauth.py @@ -31,6 +31,7 @@ from twisted.internet import threads from leap.common.check import leap_assert from leap.util.request_helpers import get_content +from leap.util.constants import REQUEST_TIMEOUT from leap.common.events import signal as events_signal from leap.common.events import events_pb2 as proto @@ -155,7 +156,8 @@ class SRPAuth(QtCore.QObject): init_session = self._session.post(sessions_url, data=auth_data, verify=self._provider_config. - get_ca_cert_path()) + get_ca_cert_path(), + timeout=REQUEST_TIMEOUT) except requests.exceptions.ConnectionError as e: logger.error("No connection made (salt): %r" % (e,)) @@ -230,7 +232,8 @@ class SRPAuth(QtCore.QObject): auth_result = self._session.put(auth_url, data=auth_data, verify=self._provider_config. - get_ca_cert_path()) + get_ca_cert_path(), + timeout=REQUEST_TIMEOUT) except requests.exceptions.ConnectionError as e: logger.error("No connection made (HAMK): %r" % (e,)) raise SRPAuthenticationError(self.tr("Could not connect to " @@ -377,7 +380,8 @@ class SRPAuth(QtCore.QObject): self._session.delete(logout_url, data=self.get_session_id(), verify=self._provider_config. - get_ca_cert_path()) + get_ca_cert_path(), + timeout=REQUEST_TIMEOUT) except Exception as e: logger.warning("Something went wrong with the logout: %r" % (e,)) diff --git a/src/leap/crypto/srpregister.py b/src/leap/crypto/srpregister.py index 07b3c917..42a2c4b0 100644 --- a/src/leap/crypto/srpregister.py +++ b/src/leap/crypto/srpregister.py @@ -25,7 +25,7 @@ from PySide import QtCore from urlparse import urlparse from leap.config.providerconfig import ProviderConfig -from leap.crypto.constants import SIGNUP_TIMEOUT +from leap.util.constants import SIGNUP_TIMEOUT from leap.common.check import leap_assert, leap_assert_type logger = logging.getLogger(__name__) diff --git a/src/leap/services/eip/eipbootstrapper.py b/src/leap/services/eip/eipbootstrapper.py index b2af0aea..60270b5b 100644 --- a/src/leap/services/eip/eipbootstrapper.py +++ b/src/leap/services/eip/eipbootstrapper.py @@ -31,6 +31,7 @@ from leap.config.providerconfig import ProviderConfig from leap.crypto.srpauth import SRPAuth from leap.services.eip.eipconfig import EIPConfig from leap.util.request_helpers import get_content +from leap.util.constants import REQUEST_TIMEOUT from leap.services.abstractbootstrapper import AbstractBootstrapper logger = logging.getLogger(__name__) @@ -89,7 +90,8 @@ class EIPBootstrapper(AbstractBootstrapper): res = self._session.get(config_uri, verify=self._provider_config .get_ca_cert_path(), - headers=headers) + headers=headers, + timeout=REQUEST_TIMEOUT) res.raise_for_status() # Not modified @@ -139,7 +141,8 @@ class EIPBootstrapper(AbstractBootstrapper): res = self._session.get(cert_uri, verify=self._provider_config .get_ca_cert_path(), - cookies=cookies) + cookies=cookies, + timeout=REQUEST_TIMEOUT) res.raise_for_status() client_cert = res.content diff --git a/src/leap/services/eip/providerbootstrapper.py b/src/leap/services/eip/providerbootstrapper.py index 754d0643..274fd3bd 100644 --- a/src/leap/services/eip/providerbootstrapper.py +++ b/src/leap/services/eip/providerbootstrapper.py @@ -31,6 +31,7 @@ from leap.common.files import check_and_fix_urw_only, get_mtime, mkdir_p from leap.common.check import leap_assert, leap_assert_type from leap.config.providerconfig import ProviderConfig from leap.util.request_helpers import get_content +from leap.util.constants import REQUEST_TIMEOUT from leap.services.abstractbootstrapper import AbstractBootstrapper from leap.provider.supportedapis import SupportedAPIs @@ -103,7 +104,8 @@ class ProviderBootstrapper(AbstractBootstrapper): try: res = self._session.get("https://%s" % (self._domain,), - verify=not self._bypass_checks) + verify=not self._bypass_checks, + timeout=REQUEST_TIMEOUT) res.raise_for_status() except requests.exceptions.SSLError: self._err_msg = self.tr("Provider certificate could " @@ -135,7 +137,8 @@ class ProviderBootstrapper(AbstractBootstrapper): res = self._session.get("https://%s/%s" % (self._domain, "provider.json"), headers=headers, - verify=not self._bypass_checks) + verify=not self._bypass_checks, + timeout=REQUEST_TIMEOUT) res.raise_for_status() # Not modified @@ -220,7 +223,8 @@ class ProviderBootstrapper(AbstractBootstrapper): return res = self._session.get(self._provider_config.get_ca_cert_uri(), - verify=not self._bypass_checks) + verify=not self._bypass_checks, + timeout=REQUEST_TIMEOUT) res.raise_for_status() cert_path = self._provider_config.get_ca_cert_path( @@ -280,7 +284,8 @@ class ProviderBootstrapper(AbstractBootstrapper): self._provider_config.get_api_version()) res = self._session.get(test_uri, verify=self._provider_config - .get_ca_cert_path()) + .get_ca_cert_path(), + timeout=REQUEST_TIMEOUT) res.raise_for_status() def run_provider_setup_checks(self, diff --git a/src/leap/util/constants.py b/src/leap/util/constants.py new file mode 100644 index 00000000..63f6b1f7 --- /dev/null +++ b/src/leap/util/constants.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# constants.py +# Copyright (C) 2013 LEAP +# +# 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 . + +SIGNUP_TIMEOUT = 5 +REQUEST_TIMEOUT = 10 -- cgit v1.2.3