From 8fae83a20504851845eeda5c089f2c53f8678eae Mon Sep 17 00:00:00 2001 From: drebs Date: Thu, 9 May 2013 15:56:04 -0300 Subject: Add sign/verify to keymanager's openpgp. --- src/leap/common/tests/test_keymanager.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/leap/common/tests') diff --git a/src/leap/common/tests/test_keymanager.py b/src/leap/common/tests/test_keymanager.py index 1d7a382..d3dee40 100644 --- a/src/leap/common/tests/test_keymanager.py +++ b/src/leap/common/tests/test_keymanager.py @@ -169,7 +169,7 @@ class KeyManagerWithSoledadTestCase(BaseLeapTest): class OpenPGPCryptoTestCase(KeyManagerWithSoledadTestCase): - def test_openpgp_gen_key(self): + def _test_openpgp_gen_key(self): pgp = openpgp.OpenPGPScheme(self._soledad) self.assertRaises(KeyNotFound, pgp.get_key, 'user@leap.se') key = pgp.gen_key('user@leap.se') @@ -363,6 +363,34 @@ class KeyManagerKeyManagementTestCase( 'leap@leap.se' ) + def test_verify_with_private_raises(self): + km = self._key_manager() + km._wrapper_map[OpenPGPKey].put_key_raw(PRIVATE_KEY) + data = 'data' + privkey = km.get_key(ADDRESS, OpenPGPKey, private=True) + signed = openpgp.sign(data, privkey) + self.assertRaises( + AssertionError, + openpgp.verify, signed, privkey) + + def test_sign_with_public_raises(self): + km = self._key_manager() + km._wrapper_map[OpenPGPKey].put_key_raw(PUBLIC_KEY) + data = 'data' + pubkey = km.get_key(ADDRESS, OpenPGPKey, private=False) + self.assertRaises( + AssertionError, + openpgp.sign, data, pubkey) + + def test_sign_verify(self): + km = self._key_manager() + km._wrapper_map[OpenPGPKey].put_key_raw(PRIVATE_KEY) + data = 'data' + privkey = km.get_key(ADDRESS, OpenPGPKey, private=True) + signed = openpgp.sign(data, privkey) + pubkey = km.get_key(ADDRESS, OpenPGPKey, private=False) + self.assertTrue(openpgp.verify(signed, pubkey)) + # Key material for testing KEY_FINGERPRINT = "E36E738D69173C13D709E44F2F455E2824D18DDF" -- cgit v1.2.3