diff options
author | kali <kali@leap.se> | 2012-09-18 22:55:45 +0900 |
---|---|---|
committer | kali <kali@leap.se> | 2012-09-18 22:55:45 +0900 |
commit | 89735a5fd3c81e8aba3cb7b1d4836c1bf1e8c098 (patch) | |
tree | a8a00856a7ee856cb08f263d613ac038f82043fd /src/leap/base | |
parent | 0d35f2a82bf15504ace2135af3e0c66ae1c16874 (diff) |
cert verification and malformed json checks
Diffstat (limited to 'src/leap/base')
-rw-r--r-- | src/leap/base/config.py | 20 | ||||
-rw-r--r-- | src/leap/base/constants.py | 2 | ||||
-rw-r--r-- | src/leap/base/exceptions.py | 2 |
3 files changed, 19 insertions, 5 deletions
diff --git a/src/leap/base/config.py b/src/leap/base/config.py index e896ffd2..eb9bf88a 100644 --- a/src/leap/base/config.py +++ b/src/leap/base/config.py @@ -18,6 +18,9 @@ from leap.base import exceptions from leap.base import constants from leap.util.fileutil import (mkdir_p) +# move to base! +from leap.eip import exceptions as eipexceptions + class BaseLeapConfig(object): slug = None @@ -145,9 +148,9 @@ class JSONLeapConfig(BaseLeapConfig): config[k] = v() self._config.serialize(to) - def load(self, fromfile=None, from_uri=None, fetcher=None): + def load(self, fromfile=None, from_uri=None, fetcher=None, verify=False): if from_uri is not None: - fetched = self.fetch(from_uri, fetcher=fetcher) + fetched = self.fetch(from_uri, fetcher=fetcher, verify=verify) if fetched: return if fromfile is None: @@ -156,12 +159,21 @@ class JSONLeapConfig(BaseLeapConfig): # XXX check for no errors, etc self._config.config = newconfig - def fetch(self, uri, fetcher=None): + def fetch(self, uri, fetcher=None, verify=True): if not fetcher: fetcher = self.fetcher - request = fetcher.get(uri) + logger.debug('verify: %s', verify) + request = fetcher.get(uri, verify=verify) + + # XXX get 404, ... + # and raise a UnableToFetch... request.raise_for_status() fd, fname = tempfile.mkstemp(suffix=".json") + if not request.json: + try: + json.loads(request.content) + except ValueError: + raise eipexceptions.LeapBadConfigFetchedError with open(fname, 'w') as tmp: tmp.write(json.dumps(request.json)) self._loadtemp(fname) diff --git a/src/leap/base/constants.py b/src/leap/base/constants.py index f3e24715..7a1415fb 100644 --- a/src/leap/base/constants.py +++ b/src/leap/base/constants.py @@ -11,7 +11,7 @@ DEFAULT_PROVIDER = __branding.get( "provider_domain", "testprovider.example.org") -DEFINITION_EXPECTED_PATH = "definition.json" +DEFINITION_EXPECTED_PATH = "provider.json" DEFAULT_PROVIDER_DEFINITION = { u'api_uri': u'https://api.%s/' % DEFAULT_PROVIDER, diff --git a/src/leap/base/exceptions.py b/src/leap/base/exceptions.py index 9c4aa77b..caaa3be6 100644 --- a/src/leap/base/exceptions.py +++ b/src/leap/base/exceptions.py @@ -4,3 +4,5 @@ class MissingConfigFileError(Exception): class ImproperlyConfigured(Exception): pass + + |