diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/keymanager/common.py | 64 | ||||
-rw-r--r-- | tests/integration/keymanager/test_keymanager.py | 63 |
2 files changed, 125 insertions, 2 deletions
diff --git a/tests/integration/keymanager/common.py b/tests/integration/keymanager/common.py index 9e4b9ee1..c2fd77be 100644 --- a/tests/integration/keymanager/common.py +++ b/tests/integration/keymanager/common.py @@ -195,6 +195,70 @@ RZXoH+FTg9UAW87eqU610npOkT6cRaBxaMK/mDtGNdc= -----END PGP PRIVATE KEY BLOCK----- """ +# different private key to the same address +# A4337956D27DC89C Leap Test Key <leap@leap.se> +# no expiry date +DIFFERENT_KEY_FPR = "EFA5842560D6462AD9CCE7A2A4337956D27DC89C" +DIFFERENT_PRIVATE_KEY = """ +-----BEGIN PGP PRIVATE KEY BLOCK----- +Version: GnuPG v1 + +lQOYBFg3mmIBCAD1W0VwNfGm7hMDzqd/AX8xJcLw3WyAABpOOusEzcZLmMu8Lc6U +37LK7aJi0UQ/gHjS3Wakxt98dzDGcjIcrNh0u3Ldo776cfXGkyAcqj+dZP7xdPLc +x+WIIhZahzIL59isncT0Ou0yXpl7GpBnByXEr5oO21cKZdkD5QN5WmHcUlkNRcTx +CG7jLHhGcY00GdDXhrC7/+OaNdgceHcn2698YIzPXSVrP7oCjb25fYMZ4zZQpgsL +1Wbdr+enSzIRYAJu7pwNjwvnILergqs21SlVOJugd4PKvFZ5+IM0pJqhDwnErrQt +7syAr4B6bF99Hxze9QXiP7PbPhmYqNLNUwfFABEBAAEAB/4s9Q7pqzC+xiPc0Dp3 +tqYAMuuf5+qwH5SyXfBfXncltfcq4XfXZo/jyBw3oCGxwxAgjyn2Kmyb6VkaG6Wc +BH3bEdfPzee6CzSeMKozJmzmobFnO+ceVlB0G87dwqUEcnSM2JHUsJFy58uWt3zb +K/+bJRQFAeLWiGf14zo6O7nvvRkyTg2mteG86vZ/btTbf9AEX1v6d9NRUscckuv9 +eeLAI3+I8W6ZrFVIlwd7hEijP49o5GM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GRS8E2EBnpXWkxu3DGBwZARwl39AlZrcIwP8DiPp +H6g2OhZK+IpnKa0OsglZrGa8rK8XTjGYO7U8PVm7xn6vwLbZ/RQ2VedebD5jHeDC +kDqCzE/321iAFD4P/FSFjTUkf/BtSIDlMX48eyIBxfOb6D2QfKiTy3XA0qeS8IZI +qJ+oeYtcI35wL+z87y6AiAUfeGSlGt1iDQZAmGw/w4kBHwQYAQIACQUCWDeaYgIb +DAAKCRCkM3lW0n3InNkRCACE5++Zjc2GQSrOPZ4q8sI24FDRQr24zwQr3VX0GiQ6 +wi2rJkTRG+Wmxl27OG5A72pYBUpGgcudPi5sAzR62P2SP4K/ZK4aS0tk3uTN4xiY +LGkK8esj6Yi/ZpB1YN8LVJFobOjE2fIs6JOM6ntmP/8Y/9ocD6fYJyrT016U1bwW +rLSfncpUZYCgkVsCHl9IYZ3ZNqp1xjdvDWOQCdpFbxaN9dFoqfpOuwupoV1/WkWK +e3xEcIGgfXWW+h4aZLlmMEJJebt+UOiSsawPTsLQNJAs4JWAyE3w3GKS7JYVRnSK +p/c59ceStlbqgYybVHhnFtse0d/dpl7rTi0JO9sph/Mg +=3mjv +-----END PGP PRIVATE KEY BLOCK----- +""" + # key 7FEE575A: public key "anotheruser <anotheruser@leap.se>" KEY_FINGERPRINT_2 = "F6E2B572ADB84EA58BD2E9A57F9DFA687FEE575A" PUBLIC_KEY_2 = """ diff --git a/tests/integration/keymanager/test_keymanager.py b/tests/integration/keymanager/test_keymanager.py index e11e19b8..7bacd050 100644 --- a/tests/integration/keymanager/test_keymanager.py +++ b/tests/integration/keymanager/test_keymanager.py @@ -52,8 +52,8 @@ from common import ( KEY_EXPIRING_CREATION_DATE, PRIVATE_EXPIRING_KEY, NEW_PUB_KEY, - OLD_AND_NEW_KEY_ADDRESS -) + OLD_AND_NEW_KEY_ADDRESS, + DIFFERENT_PRIVATE_KEY, DIFFERENT_KEY_FPR) NICKSERVER_URI = "http://leap.se/" REMOTE_KEY_URL = "http://site.domain/key" @@ -195,6 +195,25 @@ class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase): self.assertTrue(key.private) @defer.inlineCallbacks + def test_create_and_get_two_private_keys_sets_first_key_inactive(self): + km = self._key_manager() + yield km._openpgp.put_raw_key(PRIVATE_KEY, ADDRESS) + yield km._openpgp.put_raw_key(DIFFERENT_PRIVATE_KEY, ADDRESS) + # get the key + inactive_key = yield km.get_key(ADDRESS, private=True, + active=False, fetch_remote=False) + active_key = yield km.get_key(ADDRESS, private=True, + active=True, fetch_remote=False) + self.assertEqual( + inactive_key.fingerprint.lower(), KEY_FINGERPRINT.lower()) + self.assertEqual( + active_key.fingerprint.lower(), DIFFERENT_KEY_FPR.lower()) + self.assertTrue(inactive_key.private) + self.assertTrue(active_key.private) + self.assertFalse(inactive_key.is_active()) + self.assertTrue(active_key.is_active()) + + @defer.inlineCallbacks def test_send_key(self): """ Test that request is well formed when sending keys to server. @@ -577,6 +596,25 @@ class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase): self.assertIn(old_key.fingerprint[-16:], renewed_public_key.signatures) @defer.inlineCallbacks + def test_key_regenerate_deactivate_the_old_private_key(self): + km = self._key_manager(user=ADDRESS_EXPIRING) + + yield km._openpgp.put_raw_key(PRIVATE_EXPIRING_KEY, ADDRESS_EXPIRING) + old_key = yield km.get_key(ADDRESS_EXPIRING) + + new_key = yield km.regenerate_key() + retrieved_old_key = yield km.get_key(ADDRESS_EXPIRING, + private=True, active=False) + renewed_public_key = yield km.get_key(ADDRESS_EXPIRING, private=False) + + self.assertEqual(old_key.fingerprint, + retrieved_old_key.fingerprint) + self.assertNotEqual(old_key.fingerprint, + new_key.fingerprint) + self.assertEqual(new_key.fingerprint, renewed_public_key.fingerprint) + self.assertIn(old_key.fingerprint[-16:], renewed_public_key.signatures) + + @defer.inlineCallbacks def test_key_regenerate_resets_all_public_key_sign_used(self): km = self._key_manager(user=ADDRESS_EXPIRING) @@ -630,6 +668,27 @@ class KeyManagerCryptoTestCase(KeyManagerWithSoledadTestCase): self.assertEqual(signingkey.fingerprint, key.fingerprint) @defer.inlineCallbacks + def test_keymanager_openpgp_decryption_tries_inactive_valid_key(self): + km = self._key_manager() + # put raw private key + yield km._openpgp.put_raw_key(PRIVATE_KEY, ADDRESS) + yield km._openpgp.put_raw_key(PRIVATE_KEY_2, ADDRESS_2) + # encrypt + encdata = yield km.encrypt(self.RAW_DATA, ADDRESS, sign=ADDRESS_2, + fetch_remote=False) + self.assertNotEqual(self.RAW_DATA, encdata) + + # renew key + new_key = yield km.regenerate_key() + + # decrypt + rawdata, signingkey = yield km.decrypt( + encdata, ADDRESS, verify=ADDRESS_2, fetch_remote=False) + self.assertEqual(self.RAW_DATA, rawdata) + key = yield km.get_key(ADDRESS_2, private=False, fetch_remote=False) + self.assertEqual(signingkey.fingerprint, key.fingerprint) + + @defer.inlineCallbacks def test_keymanager_openpgp_encrypt_decrypt_wrong_sign(self): km = self._key_manager() # put raw keys |