diff options
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/common/events/component.py | 7 | ||||
-rw-r--r-- | src/leap/common/keymanager/__init__.py | 2 | ||||
-rw-r--r-- | src/leap/common/keymanager/errors.py | 5 | ||||
-rw-r--r-- | src/leap/common/keymanager/openpgp.py | 19 | ||||
-rw-r--r-- | src/leap/common/tests/test_keymanager.py | 12 |
5 files changed, 28 insertions, 17 deletions
diff --git a/src/leap/common/events/component.py b/src/leap/common/events/component.py index 0cf0e38..98a97bc 100644 --- a/src/leap/common/events/component.py +++ b/src/leap/common/events/component.py @@ -134,9 +134,10 @@ def register(signal, callback, uid=None, replace=False, reqcbk=None, request.mac = "" service = RpcService(proto.EventsServerService_Stub, server.SERVER_PORT, 'localhost') - logger.info("Sending registration request to server on port %s: %s", - server.SERVER_PORT, - str(request)) + logger.info( + "Sending registration request to server on port %s: %s", + server.SERVER_PORT, + str(request)) return service.register(request, callback=reqcbk, timeout=timeout) diff --git a/src/leap/common/keymanager/__init__.py b/src/leap/common/keymanager/__init__.py index d6dbb8a..ab28510 100644 --- a/src/leap/common/keymanager/__init__.py +++ b/src/leap/common/keymanager/__init__.py @@ -116,7 +116,7 @@ class KeyManager(object): leap_assert(response.status_code == 200, 'Invalid response.') leap_assert( response.headers['content-type'].startswith('application/json') - is True, + is True, 'Content-type is not JSON.') return response.json() diff --git a/src/leap/common/keymanager/errors.py b/src/leap/common/keymanager/errors.py index f712975..d6802f0 100644 --- a/src/leap/common/keymanager/errors.py +++ b/src/leap/common/keymanager/errors.py @@ -42,6 +42,7 @@ class KeyAttributesDiffer(Exception): """ pass + class NoPasswordGiven(Exception): """ Raised when trying to perform some action that needs a password without @@ -49,24 +50,28 @@ class NoPasswordGiven(Exception): """ pass + class InvalidSignature(Exception): """ Raised when signature could not be verified. """ pass + class EncryptionFailed(Exception): """ Raised upon failures of encryption. """ pass + class DecryptionFailed(Exception): """ Raised upon failures of decryption. """ pass + class SignFailed(Exception): """ Raised when failed to sign. diff --git a/src/leap/common/keymanager/openpgp.py b/src/leap/common/keymanager/openpgp.py index 0cb1308..d578638 100644 --- a/src/leap/common/keymanager/openpgp.py +++ b/src/leap/common/keymanager/openpgp.py @@ -66,7 +66,7 @@ def encrypt_sym(data, passphrase, sign=None): leap_assert_type(passphrase, str) if sign is not None: leap_assert_type(sign, OpenPGPKey) - leap_assert(sign.private == True) + leap_assert(sign.private is True) def _encrypt_cb(gpg): result = gpg.encrypt( @@ -105,7 +105,7 @@ def decrypt_sym(data, passphrase, verify=None): leap_assert_type(passphrase, str) if verify is not None: leap_assert_type(verify, OpenPGPKey) - leap_assert(verify.private == False) + leap_assert(verify.private is False) def _decrypt_cb(gpg): result = gpg.decrypt(data, passphrase=passphrase) @@ -145,7 +145,7 @@ def encrypt_asym(data, pubkey, sign=None): leap_assert(pubkey.private is False, 'Key is not public.') if sign is not None: leap_assert_type(sign, OpenPGPKey) - leap_assert(sign.private == True) + leap_assert(sign.private is True) def _encrypt_cb(gpg): result = gpg.encrypt( @@ -185,7 +185,7 @@ def decrypt_asym(data, privkey, verify=None): leap_assert(privkey.private is True, 'Key is not private.') if verify is not None: leap_assert_type(verify, OpenPGPKey) - leap_assert(verify.private == False) + leap_assert(verify.private is False) def _decrypt_cb(gpg): result = gpg.decrypt(data) @@ -258,6 +258,7 @@ def is_encrypted_asym(data): return _safe_call(_is_encrypted_cb) + def sign(data, privkey): """ Sign C{data} with C{privkey}. @@ -271,7 +272,7 @@ def sign(data, privkey): @rtype: str """ leap_assert_type(privkey, OpenPGPKey) - leap_assert(privkey.private == True) + leap_assert(privkey.private is True) def _sign_cb(gpg): result = gpg.sign(data, keyid=privkey.key_id) @@ -289,6 +290,7 @@ def sign(data, privkey): return _safe_call(_sign_cb, [privkey]) + def verify(data, pubkey): """ Verify signed C{data} with C{pubkey}. @@ -302,7 +304,7 @@ def verify(data, pubkey): @rtype: str """ leap_assert_type(pubkey, OpenPGPKey) - leap_assert(pubkey.private == False) + leap_assert(pubkey.private is False) def _verify_cb(gpg): result = gpg.verify(data) @@ -314,6 +316,7 @@ def verify(data, pubkey): return _safe_call(_verify_cb, [pubkey]) + # # Helper functions # @@ -358,8 +361,8 @@ def _build_keyring(keys=[]): @return: A GPG wrapper with a unitary keyring. @rtype: gnupg.GPG """ - privkeys = filter(lambda key: key.private == True, keys) - pubkeys = filter(lambda key: key.private == False, keys) + privkeys = filter(lambda key: key.private is True, keys) + pubkeys = filter(lambda key: key.private is False, keys) # here we filter out public keys that have a correspondent private key in # the list because the private key_data by itself is enough to also have # the public key in the keyring, and we want to count the keys afterwards. diff --git a/src/leap/common/tests/test_keymanager.py b/src/leap/common/tests/test_keymanager.py index 68a30e7..d71167c 100644 --- a/src/leap/common/tests/test_keymanager.py +++ b/src/leap/common/tests/test_keymanager.py @@ -366,9 +366,10 @@ class OpenPGPCryptoTestCase(KeyManagerWithSoledadTestCase): pubkey2 = pgp.get_key(ADDRESS_2, private=False) privkey2 = pgp.get_key(ADDRESS_2, private=True) data = 'data' - encrypted_and_signed = openpgp.encrypt_asym(data, pubkey2, sign=privkey) + encrypted_and_signed = openpgp.encrypt_asym( + data, pubkey2, sign=privkey) res = openpgp.decrypt_asym( - encrypted_and_signed, privkey2, verify=pubkey) + encrypted_and_signed, privkey2, verify=pubkey) self.assertTrue(data, res) def test_encrypt_sym_sign_decrypt_verify(self): @@ -379,12 +380,12 @@ class OpenPGPCryptoTestCase(KeyManagerWithSoledadTestCase): pubkey = pgp.get_key(ADDRESS, private=False) encrypted_and_signed = openpgp.encrypt_sym(data, '123', sign=privkey) res = openpgp.decrypt_sym( - encrypted_and_signed, '123', verify=pubkey) + encrypted_and_signed, '123', verify=pubkey) self.assertEqual(data, res) class KeyManagerKeyManagementTestCase( - KeyManagerWithSoledadTestCase): + KeyManagerWithSoledadTestCase): def test_get_all_keys_in_db(self): km = self._key_manager() @@ -473,6 +474,7 @@ class KeyManagerKeyManagementTestCase( class Response(object): status_code = 200 headers = {'content-type': 'application/json'} + def json(self): return {'address': 'anotheruser@leap.se', 'keys': []} @@ -482,7 +484,7 @@ class KeyManagerKeyManagementTestCase( km.fetch_keys_from_server('anotheruser@leap.se') # and verify the call km._fetcher.get.assert_called_once_with( - km._nickserver_url + '/key/' + 'anotheruser@leap.se', + km._nickserver_url + '/key/' + 'anotheruser@leap.se', ) def test_refresh_keys(self): |