09a618385d47c7f56194615c31761e7dd787f87a
[keymanager.git] / src / leap / keymanager / tests / test_keymanager.py
1 ## -*- coding: utf-8 -*-
2 # test_keymanager.py
3 # Copyright (C) 2013 LEAP
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18
19 """
20 Tests for the Key Manager.
21 """
22
23
24 from mock import Mock
25 from leap.common.testing.basetest import BaseLeapTest
26 from leap.soledad import Soledad
27 from leap.keymanager import (
28     KeyManager,
29     openpgp,
30     KeyNotFound,
31     NoPasswordGiven,
32     errors,
33 )
34 from leap.keymanager.openpgp import OpenPGPKey
35 from leap.keymanager.keys import (
36     is_address,
37     build_key_from_dict,
38 )
39
40
41 ADDRESS = 'leap@leap.se'
42 ADDRESS_2 = 'anotheruser@leap.se'
43
44
45 class KeyManagerUtilTestCase(BaseLeapTest):
46
47     def setUp(self):
48         pass
49
50     def tearDown(self):
51         pass
52
53     def test_is_address(self):
54         self.assertTrue(
55             is_address('user@leap.se'),
56             'Incorrect address detection.')
57         self.assertFalse(
58             is_address('userleap.se'),
59             'Incorrect address detection.')
60         self.assertFalse(
61             is_address('user@'),
62             'Incorrect address detection.')
63         self.assertFalse(
64             is_address('@leap.se'),
65             'Incorrect address detection.')
66
67     def test_build_key_from_dict(self):
68         kdict = {
69             'address': ADDRESS,
70             'key_id': 'key_id',
71             'fingerprint': 'fingerprint',
72             'key_data': 'key_data',
73             'private': 'private',
74             'length': 'length',
75             'expiry_date': 'expiry_date',
76             'first_seen_at': 'first_seen_at',
77             'last_audited_at': 'last_audited_at',
78             'validation': 'validation',
79         }
80         key = build_key_from_dict(OpenPGPKey, ADDRESS, kdict)
81         self.assertEqual(
82             kdict['address'], key.address,
83             'Wrong data in key.')
84         self.assertEqual(
85             kdict['key_id'], key.key_id,
86             'Wrong data in key.')
87         self.assertEqual(
88             kdict['fingerprint'], key.fingerprint,
89             'Wrong data in key.')
90         self.assertEqual(
91             kdict['key_data'], key.key_data,
92             'Wrong data in key.')
93         self.assertEqual(
94             kdict['private'], key.private,
95             'Wrong data in key.')
96         self.assertEqual(
97             kdict['length'], key.length,
98             'Wrong data in key.')
99         self.assertEqual(
100             kdict['expiry_date'], key.expiry_date,
101             'Wrong data in key.')
102         self.assertEqual(
103             kdict['first_seen_at'], key.first_seen_at,
104             'Wrong data in key.')
105         self.assertEqual(
106             kdict['last_audited_at'], key.last_audited_at,
107             'Wrong data in key.')
108         self.assertEqual(
109             kdict['validation'], key.validation,
110             'Wrong data in key.')
111
112
113 class KeyManagerWithSoledadTestCase(BaseLeapTest):
114
115     def setUp(self):
116         # mock key fetching and storing so Soledad doesn't fail when trying to
117         # reach the server.
118         Soledad._get_secrets_from_shared_db = Mock(return_value=None)
119         Soledad._put_secrets_in_shared_db = Mock(return_value=None)
120
121         self._soledad = Soledad(
122             "leap@leap.se",
123             "123456",
124             secrets_path=self.tempdir + "/secret.gpg",
125             local_db_path=self.tempdir + "/soledad.u1db",
126             server_url='',
127             cert_file=None,
128             auth_token=None,
129         )
130
131     def tearDown(self):
132         km = self._key_manager()
133         for key in km.get_all_keys_in_local_db():
134             km._wrapper_map[key.__class__].delete_key(key)
135         for key in km.get_all_keys_in_local_db(private=True):
136             km._wrapper_map[key.__class__].delete_key(key)
137
138     def _key_manager(self, user=ADDRESS, url=''):
139         return KeyManager(user, url, self._soledad)
140
141
142 class OpenPGPCryptoTestCase(KeyManagerWithSoledadTestCase):
143
144     def _test_openpgp_gen_key(self):
145         pgp = openpgp.OpenPGPScheme(self._soledad)
146         self.assertRaises(KeyNotFound, pgp.get_key, 'user@leap.se')
147         key = pgp.gen_key('user@leap.se')
148         self.assertIsInstance(key, openpgp.OpenPGPKey)
149         self.assertEqual(
150             'user@leap.se', key.address, 'Wrong address bound to key.')
151         self.assertEqual(
152             '4096', key.length, 'Wrong key length.')
153
154     def test_openpgp_put_delete_key(self):
155         pgp = openpgp.OpenPGPScheme(self._soledad)
156         self.assertRaises(KeyNotFound, pgp.get_key, ADDRESS)
157         pgp.put_ascii_key(PUBLIC_KEY)
158         key = pgp.get_key(ADDRESS, private=False)
159         pgp.delete_key(key)
160         self.assertRaises(KeyNotFound, pgp.get_key, ADDRESS)
161
162     def test_openpgp_put_ascii_key(self):
163         pgp = openpgp.OpenPGPScheme(self._soledad)
164         self.assertRaises(KeyNotFound, pgp.get_key, ADDRESS)
165         pgp.put_ascii_key(PUBLIC_KEY)
166         key = pgp.get_key(ADDRESS, private=False)
167         self.assertIsInstance(key, openpgp.OpenPGPKey)
168         self.assertEqual(
169             ADDRESS, key.address, 'Wrong address bound to key.')
170         self.assertEqual(
171             '4096', key.length, 'Wrong key length.')
172         pgp.delete_key(key)
173         self.assertRaises(KeyNotFound, pgp.get_key, ADDRESS)
174
175     def test_get_public_key(self):
176         pgp = openpgp.OpenPGPScheme(self._soledad)
177         self.assertRaises(KeyNotFound, pgp.get_key, ADDRESS)
178         pgp.put_ascii_key(PUBLIC_KEY)
179         self.assertRaises(
180             KeyNotFound, pgp.get_key, ADDRESS, private=True)
181         key = pgp.get_key(ADDRESS, private=False)
182         self.assertEqual(ADDRESS, key.address)
183         self.assertFalse(key.private)
184         self.assertEqual(KEY_FINGERPRINT, key.fingerprint)
185         pgp.delete_key(key)
186         self.assertRaises(KeyNotFound, pgp.get_key, ADDRESS)
187
188     def test_openpgp_encrypt_decrypt_asym(self):
189         # encrypt
190         pgp = openpgp.OpenPGPScheme(self._soledad)
191         pgp.put_ascii_key(PUBLIC_KEY)
192         pubkey = pgp.get_key(ADDRESS, private=False)
193         cyphertext = openpgp.encrypt_asym('data', pubkey)
194         # assert
195         self.assertTrue(cyphertext is not None)
196         self.assertTrue(cyphertext != '')
197         self.assertTrue(cyphertext != 'data')
198         self.assertTrue(openpgp.is_encrypted_asym(cyphertext))
199         self.assertTrue(openpgp.is_encrypted(cyphertext))
200         # decrypt
201         self.assertRaises(
202             KeyNotFound, pgp.get_key, ADDRESS, private=True)
203         pgp.put_ascii_key(PRIVATE_KEY)
204         privkey = pgp.get_key(ADDRESS, private=True)
205         plaintext = openpgp.decrypt_asym(cyphertext, privkey)
206         pgp.delete_key(pubkey)
207         pgp.delete_key(privkey)
208         self.assertRaises(
209             KeyNotFound, pgp.get_key, ADDRESS, private=False)
210         self.assertRaises(
211             KeyNotFound, pgp.get_key, ADDRESS, private=True)
212
213     def test_verify_with_private_raises(self):
214         pgp = openpgp.OpenPGPScheme(self._soledad)
215         pgp.put_ascii_key(PRIVATE_KEY)
216         data = 'data'
217         privkey = pgp.get_key(ADDRESS, private=True)
218         signed = openpgp.sign(data, privkey)
219         self.assertRaises(
220             AssertionError,
221             openpgp.verify, signed, privkey)
222
223     def test_sign_with_public_raises(self):
224         pgp = openpgp.OpenPGPScheme(self._soledad)
225         pgp.put_ascii_key(PUBLIC_KEY)
226         data = 'data'
227         pubkey = pgp.get_key(ADDRESS, private=False)
228         self.assertRaises(
229             AssertionError,
230             openpgp.sign, data, pubkey)
231
232     def test_verify_with_wrong_key_raises(self):
233         pgp = openpgp.OpenPGPScheme(self._soledad)
234         pgp.put_ascii_key(PRIVATE_KEY)
235         data = 'data'
236         privkey = pgp.get_key(ADDRESS, private=True)
237         signed = openpgp.sign(data, privkey)
238         pgp.put_ascii_key(PUBLIC_KEY_2)
239         wrongkey = pgp.get_key(ADDRESS_2)
240         self.assertRaises(
241             errors.InvalidSignature,
242             openpgp.verify, signed, wrongkey)
243
244     def test_encrypt_asym_sign_with_public_raises(self):
245         pgp = openpgp.OpenPGPScheme(self._soledad)
246         pgp.put_ascii_key(PRIVATE_KEY)
247         data = 'data'
248         privkey = pgp.get_key(ADDRESS, private=True)
249         pubkey = pgp.get_key(ADDRESS, private=False)
250         self.assertRaises(
251             AssertionError,
252             openpgp.encrypt_asym, data, privkey, sign=pubkey)
253
254     def test_decrypt_asym_verify_with_private_raises(self):
255         pgp = openpgp.OpenPGPScheme(self._soledad)
256         pgp.put_ascii_key(PRIVATE_KEY)
257         data = 'data'
258         privkey = pgp.get_key(ADDRESS, private=True)
259         pubkey = pgp.get_key(ADDRESS, private=False)
260         encrypted_and_signed = openpgp.encrypt_asym(
261             data, pubkey, sign=privkey)
262         self.assertRaises(
263             AssertionError,
264             openpgp.decrypt_asym,
265             encrypted_and_signed, privkey, verify=privkey)
266
267     def test_decrypt_asym_verify_with_wrong_key_raises(self):
268         pgp = openpgp.OpenPGPScheme(self._soledad)
269         pgp.put_ascii_key(PRIVATE_KEY)
270         data = 'data'
271         privkey = pgp.get_key(ADDRESS, private=True)
272         pubkey = pgp.get_key(ADDRESS, private=False)
273         encrypted_and_signed = openpgp.encrypt_asym(data, pubkey, sign=privkey)
274         pgp.put_ascii_key(PUBLIC_KEY_2)
275         wrongkey = pgp.get_key(ADDRESS_2)
276         self.assertRaises(
277             errors.InvalidSignature,
278             openpgp.verify, encrypted_and_signed, wrongkey)
279
280     def test_sign_verify(self):
281         pgp = openpgp.OpenPGPScheme(self._soledad)
282         pgp.put_ascii_key(PRIVATE_KEY)
283         data = 'data'
284         privkey = pgp.get_key(ADDRESS, private=True)
285         signed = openpgp.sign(data, privkey)
286         pubkey = pgp.get_key(ADDRESS, private=False)
287         self.assertTrue(openpgp.verify(signed, pubkey))
288
289     def test_encrypt_asym_sign_decrypt_verify(self):
290         pgp = openpgp.OpenPGPScheme(self._soledad)
291         pgp.put_ascii_key(PRIVATE_KEY)
292         pubkey = pgp.get_key(ADDRESS, private=False)
293         privkey = pgp.get_key(ADDRESS, private=True)
294         pgp.put_ascii_key(PRIVATE_KEY_2)
295         pubkey2 = pgp.get_key(ADDRESS_2, private=False)
296         privkey2 = pgp.get_key(ADDRESS_2, private=True)
297         data = 'data'
298         encrypted_and_signed = openpgp.encrypt_asym(
299             data, pubkey2, sign=privkey)
300         res = openpgp.decrypt_asym(
301             encrypted_and_signed, privkey2, verify=pubkey)
302         self.assertTrue(data, res)
303
304
305 class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase):
306
307     def test_get_all_keys_in_db(self):
308         km = self._key_manager()
309         km._wrapper_map[OpenPGPKey].put_ascii_key(PRIVATE_KEY)
310         # get public keys
311         keys = km.get_all_keys_in_local_db(False)
312         self.assertEqual(len(keys), 1, 'Wrong number of keys')
313         self.assertEqual(ADDRESS, keys[0].address)
314         self.assertFalse(keys[0].private)
315         # get private keys
316         keys = km.get_all_keys_in_local_db(True)
317         self.assertEqual(len(keys), 1, 'Wrong number of keys')
318         self.assertEqual(ADDRESS, keys[0].address)
319         self.assertTrue(keys[0].private)
320
321     def test_get_public_key(self):
322         km = self._key_manager()
323         km._wrapper_map[OpenPGPKey].put_ascii_key(PRIVATE_KEY)
324         # get the key
325         key = km.get_key(ADDRESS, OpenPGPKey, private=False,
326                          fetch_remote=False)
327         self.assertTrue(key is not None)
328         self.assertEqual(key.address, ADDRESS)
329         self.assertEqual(
330             key.fingerprint.lower(), KEY_FINGERPRINT.lower())
331         self.assertFalse(key.private)
332
333     def test_get_private_key(self):
334         km = self._key_manager()
335         km._wrapper_map[OpenPGPKey].put_ascii_key(PRIVATE_KEY)
336         # get the key
337         key = km.get_key(ADDRESS, OpenPGPKey, private=True,
338                          fetch_remote=False)
339         self.assertTrue(key is not None)
340         self.assertEqual(key.address, ADDRESS)
341         self.assertEqual(
342             key.fingerprint.lower(), KEY_FINGERPRINT.lower())
343         self.assertTrue(key.private)
344
345     def test_send_key_raises_key_not_found(self):
346         km = self._key_manager()
347         self.assertRaises(
348             KeyNotFound,
349             km.send_key, OpenPGPKey)
350
351     def test_send_key(self):
352         """
353         Test that request is well formed when sending keys to server.
354         """
355         km = self._key_manager()
356         km._wrapper_map[OpenPGPKey].put_ascii_key(PUBLIC_KEY)
357         km._fetcher.put = Mock()
358         # the following data will be used on the send
359         km.ca_cert_path = 'capath'
360         km.session_id = 'sessionid'
361         km.uid = 'myuid'
362         km.api_uri = 'apiuri'
363         km.api_version = 'apiver'
364         km.send_key(OpenPGPKey)
365         # setup expected args
366         data = {
367             km.PUBKEY_KEY: km.get_key(km._address, OpenPGPKey).key_data,
368         }
369         url = '%s/%s/users/%s.json' % ('apiuri', 'apiver', 'myuid')
370         km._fetcher.put.assert_called_once_with(
371             url, data=data, verify='capath',
372             cookies={'_session_id': 'sessionid'},
373         )
374
375     def test__fetch_keys_from_server(self):
376         """
377         Test that the request is well formed when fetching keys from server.
378         """
379         km = self._key_manager(url='http://nickserver.domain')
380
381         class Response(object):
382             status_code = 200
383             headers = {'content-type': 'application/json'}
384
385             def json(self):
386                 return {'address': ADDRESS_2, 'openpgp': PUBLIC_KEY_2}
387
388             def raise_for_status(self):
389                 pass
390
391         # mock the fetcher so it returns the key for ADDRESS_2
392         km._fetcher.get = Mock(
393             return_value=Response())
394         km.ca_cert_path = 'cacertpath'
395         # do the fetch
396         km._fetch_keys_from_server(ADDRESS_2)
397         # and verify the call
398         km._fetcher.get.assert_called_once_with(
399             'http://nickserver.domain',
400             data={'address': ADDRESS_2},
401             verify='cacertpath',
402         )
403
404     def test_refresh_keys_does_not_refresh_own_key(self):
405         """
406         Test that refreshing keys will not attempt to refresh our own key.
407         """
408         km = self._key_manager()
409         # we add 2 keys but we expect it to only refresh the second one.
410         km._wrapper_map[OpenPGPKey].put_ascii_key(PUBLIC_KEY)
411         km._wrapper_map[OpenPGPKey].put_ascii_key(PUBLIC_KEY_2)
412         # mock the key fetching
413         km._fetch_keys_from_server = Mock(return_value=[])
414         km.ca_cert_path = ''  # some bogus path so the km does not complain.
415         # do the refreshing
416         km.refresh_keys()
417         km._fetch_keys_from_server.assert_called_once_with(
418             ADDRESS_2
419         )
420
421     def test_get_key_fetches_from_server(self):
422         """
423         Test that getting a key successfuly fetches from server.
424         """
425         km = self._key_manager(url='http://nickserver.domain')
426
427         class Response(object):
428             status_code = 200
429             headers = {'content-type': 'application/json'}
430
431             def json(self):
432                 return {'address': ADDRESS_2, 'openpgp': PUBLIC_KEY_2}
433
434             def raise_for_status(self):
435                 pass
436
437         # mock the fetcher so it returns the key for ADDRESS_2
438         km._fetcher.get = Mock(return_value=Response())
439         km.ca_cert_path = 'cacertpath'
440         # try to key get without fetching from server
441         self.assertRaises(
442             KeyNotFound, km.get_key, ADDRESS_2, OpenPGPKey,
443             fetch_remote=False
444         )
445         # try to get key fetching from server.
446         key = km.get_key(ADDRESS_2, OpenPGPKey)
447         self.assertIsInstance(key, OpenPGPKey)
448         self.assertEqual(ADDRESS_2, key.address)
449
450
451 # Key material for testing
452
453 # key 24D18DDF: public key "Leap Test Key <leap@leap.se>"
454 KEY_FINGERPRINT = "E36E738D69173C13D709E44F2F455E2824D18DDF"
455 PUBLIC_KEY = """
456 -----BEGIN PGP PUBLIC KEY BLOCK-----
457 Version: GnuPG v1.4.10 (GNU/Linux)
458
459 mQINBFC9+dkBEADNRfwV23TWEoGc/x0wWH1P7PlXt8MnC2Z1kKaKKmfnglVrpOiz
460 iLWoiU58sfZ0L5vHkzXHXCBf6Eiy/EtUIvdiWAn+yASJ1mk5jZTBKO/WMAHD8wTO
461 zpMsFmWyg3xc4DkmFa9KQ5EVU0o/nqPeyQxNMQN7px5pPwrJtJFmPxnxm+aDkPYx
462 irDmz/4DeDNqXliazGJKw7efqBdlwTHkl9Akw2gwy178pmsKwHHEMOBOFFvX61AT
463 huKqHYmlCGSliwbrJppTG7jc1/ls3itrK+CWTg4txREkSpEVmfcASvw/ZqLbjgfs
464 d/INMwXnR9U81O8+7LT6yw/ca4ppcFoJD7/XJbkRiML6+bJ4Dakiy6i727BzV17g
465 wI1zqNvm5rAhtALKfACha6YO43aJzairO4II1wxVHvRDHZn2IuKDDephQ3Ii7/vb
466 hUOf6XCSmchkAcpKXUOvbxm1yfB1LRa64mMc2RcZxf4mW7KQkulBsdV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cqde3N51
499 XT1jnIAa+NoXUM9uQoGYMiwrL7vNsLlyyiW5ayDyV92H/rIuiqhFgbJsHTlsm7I8
500 oGheR784BagAA1NIKD1qEO9T6Kz9lzlDaeWS5AUKeXrb7ZJLI1TTCIZx5/DxjLqM
501 Tt/RFBpVo9geZQrvLUqLAMwdaUvDXC2c6DaCPXTh65oCZj/hqzlJHH+RoTWWzKI+
502 BjXxgUWF9EmZUBrg68DSmI+9wuDFsjZ51BcqvJwxyfxtTaWhdoYqH/UQS+D1FP3/
503 diZHHlzwVwPICzM9ooNTgbrcDzyxRkIVqsVwBq7EtzcvgYUyX53yG25Giy6YQaQ2
504 ZtQ/VymwFL3XdUWV6B/hU4PVAFvO3qlOtdJ6TpE+nEWgcWjCv5g7RjXX
505 =MuOY
506 -----END PGP PUBLIC KEY BLOCK-----
507 """
508 PRIVATE_KEY = """
509 -----BEGIN PGP PRIVATE KEY BLOCK-----
510 Version: GnuPG v1.4.10 (GNU/Linux)
511
512 lQcYBFC9+dkBEADNRfwV23TWEoGc/x0wWH1P7PlXt8MnC2Z1kKaKKmfnglVrpOiz
513 iLWoiU58sfZ0L5vHkzXHXCBf6Eiy/EtUIvdiWAn+yASJ1mk5jZTBKO/WMAHD8wTO
514 zpMsFmWyg3xc4DkmFa9KQ5EVU0o/nqPeyQxNMQN7px5pPwrJtJFmPxnxm+aDkPYx
515 irDmz/4DeDNqXliazGJKw7efqBdlwTHkl9Akw2gwy178pmsKwHHEMOBOFFvX61AT
516 huKqHYmlCGSliwbrJppTG7jc1/ls3itrK+CWTg4txREkSpEVmfcASvw/ZqLbjgfs
517 d/INMwXnR9U81O8+7LT6yw/ca4ppcFoJD7/XJbkRiML6+bJ4Dakiy6i727BzV17g
518 wI1zqNvm5rAhtALKfACha6YO43aJzairO4II1wxVHvRDHZn2IuKDDephQ3Ii7/vb
519 hUOf6XCSmchkAcpKXUOvbxm1yfB1LRa64mMc2RcZxf4mW7KQkulBsdV5QG2276lv
520 U2UUy2IutXcGP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AEIAAkFAlC9+dkCGwwACgkQL0VeKCTRjd9HCw/+
601 LQSVgLLF4ulYlPCjWIIuQwrPbJfWUVVr2dPUFVM85DCv8gBzk5c121snXh9Swovm
602 laBbw6ate3BmbXLh64jVE9Za5sbTWi7PCcbO/bpRy4d6oLmitmNw6cq0vjTLxUYy
603 bwuiJxWREkfxuU85EKdouN062YDevH+/YResmlJrcCE7LRlJFeRlKsrrwBU3BqYd
604 GgFJjKjQC1peeQ9fj62Y7xfwE9+PXbkiWO5u/Bk8hb1VZH1SoIRU98NHVcp6BVvp
605 VK0jLAXuSauSczULmpRjbyt1lhaAqivDTWEEZXiNNbRyp17c3nVdPWOcgBr42hdQ
606 z25CgZgyLCsvu82wuXLKJblrIPJX3Yf+si6KqEWBsmwdOWybsjygaF5HvzgFqAAD
607 U0goPWoQ71PorP2XOUNp5ZLkBQp5etvtkksjVNMIhnHn8PGMuoxO39EUGlWj2B5l
608 Cu8tSosAzB1pS8NcLZzoNoI9dOHrmgJmP+GrOUkcf5GhNZbMoj4GNfGBRYX0SZlQ
609 GuDrwNKYj73C4MWyNnnUFyq8nDHJ/G1NpaF2hiof9RBL4PUU/f92JkceXPBXA8gL
610 Mz2ig1OButwPPLFGQhWqxXAGrsS3Ny+BhTJfnfIbbkaLLphBpDZm1D9XKbAUvdd1
611 RZXoH+FTg9UAW87eqU610npOkT6cRaBxaMK/mDtGNdc=
612 =JTFu
613 -----END PGP PRIVATE KEY BLOCK-----
614 """
615
616 # key 7FEE575A: public key "anotheruser <anotheruser@leap.se>"
617 PUBLIC_KEY_2 = """
618 -----BEGIN PGP PUBLIC KEY BLOCK-----
619 Version: GnuPG v1.4.10 (GNU/Linux)
620
621 mI0EUYwJXgEEAMbTKHuPJ5/Gk34l9Z06f+0WCXTDXdte1UBoDtZ1erAbudgC4MOR
622 gquKqoj3Hhw0/ILqJ88GcOJmKK/bEoIAuKaqlzDF7UAYpOsPZZYmtRfPC2pTCnXq
623 Z1vdeqLwTbUspqXflkCkFtfhGKMq5rH8GV5a3tXZkRWZhdNwhVXZagC3ABEBAAG0
624 IWFub3RoZXJ1c2VyIDxhbm90aGVydXNlckBsZWFwLnNlPoi4BBMBAgAiBQJRjAle
625 AhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRB/nfpof+5XWotuA/4tLN4E
626 gUr7IfLy2HkHAxzw7A4rqfMN92DIM9mZrDGaWRrOn3aVF7VU1UG7MDkHfPvp/cFw
627 ezoCw4s4IoHVc/pVlOkcHSyt4/Rfh248tYEJmFCJXGHpkK83VIKYJAithNccJ6Q4
628 JE/o06Mtf4uh/cA1HUL4a4ceqUhtpLJULLeKo7iNBFGMCV4BBADsyQI7GR0wSAxz
629 VayLjuPzgT+bjbFeymIhjuxKIEwnIKwYkovztW+4bbOcQs785k3Lp6RzvigTpQQt
630 Z/hwcLOqZbZw8t/24+D+Pq9mMP2uUvCFFqLlVvA6D3vKSQ/XNN+YB919WQ04jh63
631 yuRe94WenT1RJd6xU1aaUff4rKizuQARAQABiJ8EGAECAAkFAlGMCV4CGwwACgkQ
632 f536aH/uV1rPZQQAqCzRysOlu8ez7PuiBD4SebgRqWlxa1TF1ujzfLmuPivROZ2X
633 Kw5aQstxgGSjoB7tac49s0huh4X8XK+BtJBfU84JS8Jc2satlfwoyZ35LH6sDZck
634 I+RS/3we6zpMfHs3vvp9xgca6ZupQxivGtxlJs294TpJorx+mFFqbV17AzQ=
635 =Thdu
636 -----END PGP PUBLIC KEY BLOCK-----
637 """
638
639 PRIVATE_KEY_2 = """
640 -----BEGIN PGP PRIVATE KEY BLOCK-----
641 Version: GnuPG v1.4.10 (GNU/Linux)
642
643 lQHYBFGMCV4BBADG0yh7jyefxpN+JfWdOn/tFgl0w13bXtVAaA7WdXqwG7nYAuDD
644 kYKriqqI9x4cNPyC6ifPBnDiZiiv2xKCALimqpcwxe1AGKTrD2WWJrUXzwtqUwp1
645 6mdb3Xqi8E21LKal35ZApBbX4RijKuax/BleWt7V2ZEVmYXTcIVV2WoAtwARAQAB
646 AAP7BLuSAx7tOohnimEs74ks8l/L6dOcsFQZj2bqs4AoY3jFe7bV0tHr4llypb/8
647 H3/DYvpf6DWnCjyUS1tTnXSW8JXtx01BUKaAufSmMNg9blKV6GGHlT/Whe9uVyks
648 7XHk/+9mebVMNJ/kNlqq2k+uWqJohzC8WWLRK+d1tBeqDsECANZmzltPaqUsGV5X
649 C3zszE3tUBgptV/mKnBtopKi+VH+t7K6fudGcG+bAcZDUoH/QVde52mIIjjIdLje
650 uajJuHUCAO1mqh+vPoGv4eBLV7iBo3XrunyGXiys4a39eomhxTy3YktQanjjx+ty
651 GltAGCs5PbWGO6/IRjjvd46wh53kzvsCAO0J97gsWhzLuFnkxFAJSPk7RRlyl7lI
652 1XS/x0Og6j9XHCyY1OYkfBm0to3UlCfkgirzCYlTYObCofzdKFIPDmSqHbQhYW5v
653 dGhlcnVzZXIgPGFub3RoZXJ1c2VyQGxlYXAuc2U+iLgEEwECACIFAlGMCV4CGwMG
654 CwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEH+d+mh/7ldai24D/i0s3gSBSvsh
655 8vLYeQcDHPDsDiup8w33YMgz2ZmsMZpZGs6fdpUXtVTVQbswOQd8++n9wXB7OgLD
656 izgigdVz+lWU6RwdLK3j9F+Hbjy1gQmYUIlcYemQrzdUgpgkCK2E1xwnpDgkT+jT
657 oy1/i6H9wDUdQvhrhx6pSG2kslQst4qjnQHYBFGMCV4BBADsyQI7GR0wSAxzVayL
658 juPzgT+bjbFeymIhjuxKIEwnIKwYkovztW+4bbOcQs785k3Lp6RzvigTpQQtZ/hw
659 cLOqZbZw8t/24+D+Pq9mMP2uUvCFFqLlVvA6D3vKSQ/XNN+YB919WQ04jh63yuRe
660 94WenT1RJd6xU1aaUff4rKizuQARAQABAAP9EyElqJ3dq3EErXwwT4mMnbd1SrVC
661 rUJrNWQZL59mm5oigS00uIyR0SvusOr+UzTtd8ysRuwHy5d/LAZsbjQStaOMBILx
662 77TJveOel0a1QK0YSMF2ywZMCKvquvjli4hAtWYz/EwfuzQN3t23jc5ny+GqmqD2
663 3FUxLJosFUfLNmECAO9KhVmJi+L9dswIs+2Dkjd1eiRQzNOEVffvYkGYZyKxNiXF
664 UA5kvyZcB4iAN9sWCybE4WHZ9jd4myGB0MPDGxkCAP1RsXJbbuD6zS7BXe5gwunO
665 2q4q7ptdSl/sJYQuTe1KNP5d/uGsvlcFfsYjpsopasPjFBIncc/2QThMKlhoEaEB
666 /0mVAxpT6SrEvUbJ18z7kna24SgMPr3OnPMxPGfvNLJY/Xv/A17YfoqjmByCvsKE
667 JCDjopXtmbcrZyoEZbEht9mko4ifBBgBAgAJBQJRjAleAhsMAAoJEH+d+mh/7lda
668 z2UEAKgs0crDpbvHs+z7ogQ+Enm4EalpcWtUxdbo83y5rj4r0TmdlysOWkLLcYBk
669 o6Ae7WnOPbNIboeF/FyvgbSQX1POCUvCXNrGrZX8KMmd+Sx+rA2XJCPkUv98Hus6
670 THx7N776fcYHGumbqUMYrxrcZSbNveE6SaK8fphRam1dewM0
671 =a5gs
672 -----END PGP PRIVATE KEY BLOCK-----
673 """
674 import unittest
675 if __name__ == "__main__":
676     unittest.main()