diff options
author | Ruben Pollan <meskio@sindominio.net> | 2014-08-01 10:20:27 -0500 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2014-10-09 12:40:56 -0500 |
commit | 2c8cfffad0cf214951628b771db2322533a8fe50 (patch) | |
tree | 1a34002312d466b84ae99bc9dd130570141005e0 /src/leap/keymanager/__init__.py | |
parent | 2c7c18b04d0435de65b58d57f22e229577189ca2 (diff) |
Implement 'fetch_key' for ascii keys
binary keys support is still missing
Diffstat (limited to 'src/leap/keymanager/__init__.py')
-rw-r--r-- | src/leap/keymanager/__init__.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/leap/keymanager/__init__.py b/src/leap/keymanager/__init__.py index da679acb..c3423d9b 100644 --- a/src/leap/keymanager/__init__.py +++ b/src/leap/keymanager/__init__.py @@ -48,7 +48,7 @@ from leap.common.events import signal from leap.common.events import events_pb2 as proto from leap.common.decorators import memoized_method -from leap.keymanager.errors import KeyNotFound +from leap.keymanager.errors import KeyNotFound, KeyAttributesDiffer from leap.keymanager.keys import ( EncryptionKey, @@ -526,6 +526,35 @@ class KeyManager(object): except IndexError as e: leap_assert(False, "Unsupported key type. Error {0!r}".format(e)) + def fetch_key(self, address, uri, ktype): + """ + Fetch a public key for C{address} from the network and put it in + local storage. + + Raises C{openpgp.errors.KeyNotFound} if not valid key on C{uri}. + Raises C{openpgp.errors.KeyAttributesDiffer} if address don't match + any uid on the key. + + :param address: The email address of the key. + :type address: str + :param uri: The URI of the key. + :type uri: str + :param ktype: The type of the key. + :type ktype: KeyType + """ + res = self._get(uri) + if not res.ok: + raise KeyNotFound(uri) + + # XXX parse binary keys + pubkey, _ = self._wrapper_map[ktype].parse_ascii_key(res.content) + if pubkey is None: + raise KeyNotFound(uri) + if pubkey.address != address: + raise KeyAttributesDiffer("UID %s found, but expected %s" + % (pubkey.address, address)) + self.put_key(pubkey) + from ._version import get_versions __version__ = get_versions()['version'] del get_versions |