Update to allow multiple keys to be shown on list_packets.

Also updated test to ensure only expected keyid has been hidden.
fix/67-hidden-encrypt
Tom Galloway 2014-11-05 12:37:27 +00:00
parent 327d2e5f66
commit f70a7dc4f0
2 changed files with 18 additions and 7 deletions

View File

@ -1394,6 +1394,8 @@ class ListPackets(object):
self.need_passphrase_sym = None
#: The keyid and uid which this data is encrypted to.
self.userid_hint = None
#: A list of keyid's that the message has been encrypted to.
self.key = []
def _handle_status(self, key, value):
"""Parse a status code from the attached GnuPG process.
@ -1403,9 +1405,8 @@ class ListPackets(object):
if key == 'NODATA':
self.status = nodata(value)
elif key == 'ENC_TO':
# This will only capture keys in our keyring. In the future we
# may want to include multiple unknown keys in this list.
self.key, _, _ = value.split()
key_to_add, _, _ = value.split()
self.key.append(key_to_add)
elif key == 'NEED_PASSPHRASE':
self.need_passphrase = True
elif key == 'NEED_PASSPHRASE_SYM':

View File

@ -887,7 +887,7 @@ authentication."""
self.assertEqual(message, decrypted)
def test_encryption_hidden_recipient(self):
def test_encryption_one_hidden_recipient_one_not(self):
"""Test to ensure hidden recipient isn't detailed in packet info"""
alice = open(os.path.join(_files, 'test_key_1.pub'))
@ -896,6 +896,13 @@ authentication."""
res = alice_public.results[-1:][0]
alice_pfpr = str(res['fingerprint'])
alice.close()
bob = open(os.path.join(_files, 'test_key_2.pub'))
bob_pub = bob.read()
bob_public = self.gpg.import_keys(bob_pub)
res = bob_public.results[-1:][0]
bob_pfpr = str(res['fingerprint'])
bob.close()
message = """
In 2010 Riggio and Sicari presented a practical application of homomorphic
@ -904,13 +911,16 @@ transparent multi-hop wireless backhauls that are able to perform statistical
analysis of different kinds of data (temperature, humidity, etc.) coming from
a WSN while ensuring both end-to-end encryption and hop-by-hop
authentication."""
enc = self.gpg.encrypt(message, alice_pfpr, hidden_recipients=[alice_pfpr])
enc = self.gpg.encrypt(message, alice_pfpr, bob_pfpr, hidden_recipients=[alice_pfpr])
encrypted = str(enc)
log.debug("keyid = %s"
% alice_pfpr)
self.assertNotEquals(message, encrypted)
self.assertEquals("0000000000000000", self.gpg.list_packets(encrypted).key)
## We expect Alice's key to be hidden (returned as zero's) and Bob's
## key to be there.
expected_values = ["0000000000000000", "E0ED97345F2973D6"]
self.assertEquals(expected_values, self.gpg.list_packets(encrypted).key)
def test_encryption_decryption_multi_recipient(self):
"""Test decryption of an encrypted string for multiple users"""
@ -1102,7 +1112,7 @@ suites = { 'parsers': set(['test_parsers_fix_unsafe',
'test_encryption_alt_encoding',
'test_encryption_multi_recipient',
'test_encryption_decryption_multi_recipient',
'test_encryption_hidden_recipient',
'test_encryption_one_hidden_recipient_one_not',
'test_decryption',
'test_symmetric_encryption_and_decryption',
'test_file_encryption_and_decryption',