From 8022339834dabf5d2817157b25a2b65997989474 Mon Sep 17 00:00:00 2001 From: Folker Bernitt Date: Thu, 12 Mar 2015 16:17:12 +0100 Subject: Added missing file for previous commit. - Issue #313 --- .../pixelated/support/ext_keymanager_fetch_key.py | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 service/pixelated/support/ext_keymanager_fetch_key.py (limited to 'service/pixelated/support') diff --git a/service/pixelated/support/ext_keymanager_fetch_key.py b/service/pixelated/support/ext_keymanager_fetch_key.py new file mode 100644 index 00000000..a9478a43 --- /dev/null +++ b/service/pixelated/support/ext_keymanager_fetch_key.py @@ -0,0 +1,53 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . +import leap.keymanager + + +def patched_fetch_keys_from_server(self, address): + """ + Fetch keys bound to C{address} from nickserver and insert them in + local database. + + Instead of raising a KeyNotFound only for 404 responses, this implementation + raises a KeyNotFound exception for all problems. + + For original see: https://github.com/leapcode/keymanager/blob/develop/src/leap/keymanager/__init__.py + + :param address: The address bound to the keys. + :type address: str + + :raise KeyNotFound: If the key was not found on nickserver. + """ + # request keys from the nickserver + res = None + try: + res = self._get(self._nickserver_uri, {'address': address}) + res.raise_for_status() + server_keys = res.json() + # insert keys in local database + if self.OPENPGP_KEY in server_keys: + self._wrapper_map[OpenPGPKey].put_ascii_key( + server_keys['openpgp']) + except requests.exceptions.HTTPError as e: + logger.warning("HTTP error retrieving key: %r" % (e,)) + logger.warning("%s" % (res.content,)) + raise KeyNotFound(address) + except Exception as e: + logger.warning("Error retrieving key: %r" % (e,)) + raise KeyNotFound(address) + + +leap.keymanager.KeyManager._fetch_keys_from_server = patched_fetch_keys_from_server -- cgit v1.2.3