Add unittests for multiparty file en/decryption and symmetric en/decryption.
parent
23b3315c45
commit
347cecb9f2
|
@ -624,13 +624,13 @@ class GPGTestCase(unittest.TestCase):
|
||||||
key = self.generate_key("Marten van Dijk", "xorr.ox")
|
key = self.generate_key("Marten van Dijk", "xorr.ox")
|
||||||
dijk = key.fingerprint
|
dijk = key.fingerprint
|
||||||
gpg = self.gpg
|
gpg = self.gpg
|
||||||
message = ("In 2010 Riggio and Sicari presented a practical application"
|
message = """
|
||||||
" of homomorphic encryption to a hybrid wireless sensor/mesh"
|
In 2010 Riggio and Sicari presented a practical application of homomorphic
|
||||||
" network. The system enables transparent multi-hop wireless"
|
encryption to a hybrid wireless sensor/mesh network. The system enables
|
||||||
" backhauls that are able to perform statistical analysis of"
|
transparent multi-hop wireless backhauls that are able to perform statistical
|
||||||
" different kinds of data (temperature, humidity, etc.) "
|
analysis of different kinds of data (temperature, humidity, etc.) coming from
|
||||||
"coming from a WSN while ensuring both end-to-end encryption"
|
a WSN while ensuring both end-to-end encryption and hop-by-hop
|
||||||
"and hop-by-hop authentication.")
|
authentication."""
|
||||||
encrypted = str(gpg.encrypt(message, dijk))
|
encrypted = str(gpg.encrypt(message, dijk))
|
||||||
self.assertNotEqual(message, encrypted, "Data must have changed")
|
self.assertNotEqual(message, encrypted, "Data must have changed")
|
||||||
|
|
||||||
|
@ -659,50 +659,69 @@ class GPGTestCase(unittest.TestCase):
|
||||||
key = self.generate_key("Marten van Dijk", "xorr.ox")
|
key = self.generate_key("Marten van Dijk", "xorr.ox")
|
||||||
dijk = key.fingerprint
|
dijk = key.fingerprint
|
||||||
gpg = self.gpg
|
gpg = self.gpg
|
||||||
message = ("In 2010 Riggio and Sicari presented a practical application"
|
message = """
|
||||||
" of homomorphic encryption to a hybrid wireless sensor/mesh"
|
In 2010 Riggio and Sicari presented a practical application of homomorphic
|
||||||
" network. The system enables transparent multi-hop wireless"
|
encryption to a hybrid wireless sensor/mesh network. The system enables
|
||||||
" backhauls that are able to perform statistical analysis of"
|
transparent multi-hop wireless backhauls that are able to perform statistical
|
||||||
" different kinds of data (temperature, humidity, etc.) "
|
analysis of different kinds of data (temperature, humidity, etc.) coming from
|
||||||
"coming from a WSN while ensuring both end-to-end encryption"
|
a WSN while ensuring both end-to-end encryption and hop-by-hop
|
||||||
"and hop-by-hop authentication.")
|
authentication."""
|
||||||
encrypted2 = str(gpg.encrypt(message, [gentry, dijk]))
|
encrypted2 = str(gpg.encrypt(message, [gentry, dijk]))
|
||||||
self.assertNotEqual(message, encrypted2, "PT and CT should not match")
|
self.assertNotEqual(message, encrypted2, "PT and CT should not match")
|
||||||
|
|
||||||
def test_decryption(self):
|
def test_decryption(self):
|
||||||
"""Test decryption"""
|
"""Test decryption"""
|
||||||
|
key = self.generate_key("Frey", "fr.ey",
|
||||||
|
passphrase="craiggentry")
|
||||||
|
frey = key.fingerprint
|
||||||
|
key = self.generate_key("Rück", "rü.ck",
|
||||||
|
passphrase="ruck")
|
||||||
|
ruck = key.fingerprint
|
||||||
|
gpg = self.gpg
|
||||||
|
message = """
|
||||||
|
In 2010 Riggio and Sicari presented a practical application of homomorphic
|
||||||
|
encryption to a hybrid wireless sensor/mesh network. The system enables
|
||||||
|
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."""
|
||||||
|
encrypted = str(self.gpg.encrypt(message, ruck))
|
||||||
|
decrypted = self.gpg.decrypt(encrypted, passphrase="ruck")
|
||||||
|
if message != decrypted.data:
|
||||||
|
logger.debug("was: %r", message)
|
||||||
|
logger.debug("new: %r", decrypted.data)
|
||||||
|
self.assertEqual(message, decrypted.data)
|
||||||
|
|
||||||
|
def test_decryption_multi_recipient(self):
|
||||||
|
"""Test decryption of an encrypted string for multiple users"""
|
||||||
key = self.generate_key("Craig Gentry", "xorr.ox",
|
key = self.generate_key("Craig Gentry", "xorr.ox",
|
||||||
passphrase="craiggentry")
|
passphrase="craiggentry")
|
||||||
gentry = key.fingerprint
|
gentry = key.fingerprint
|
||||||
key = self.generate_key("Marten van Dijk", "xorr.ox")
|
key = self.generate_key("Marten van Dijk", "xorr.ox")
|
||||||
dijk = key.fingerprint
|
dijk = key.fingerprint
|
||||||
gpg = self.gpg
|
message = """
|
||||||
message = ("In 2010 Riggio and Sicari presented a practical application"
|
In 2010 Riggio and Sicari presented a practical application of homomorphic
|
||||||
" of homomorphic encryption to a hybrid wireless sensor/mesh"
|
encryption to a hybrid wireless sensor/mesh network. The system enables
|
||||||
" network. The system enables transparent multi-hop wireless"
|
transparent multi-hop wireless backhauls that are able to perform statistical
|
||||||
" backhauls that are able to perform statistical analysis of"
|
analysis of different kinds of data (temperature, humidity, etc.) coming from
|
||||||
" different kinds of data (temperature, humidity, etc.) "
|
a WSN while ensuring both end-to-end encryption and hop-by-hop
|
||||||
"coming from a WSN while ensuring both end-to-end encryption"
|
authentication."""
|
||||||
"and hop-by-hop authentication.")
|
encrypted = str(self.gpg.encrypt(message, [gentry, dijk]))
|
||||||
encrypted = str(gpg.encrypt(message, dijk))
|
self.assertNotEqual(message, encrypted, "PT and CT should not match")
|
||||||
decrypted = self.gpg.decrypt(encrypted, passphrase="martenvandijk")
|
decrypted1 = self.gpg.decrypt(encrypted, passphrase="craiggentry")
|
||||||
if message != decrypted.data:
|
self.assertEqual(message, str(decrypted1.data))
|
||||||
logger.debug("was: %r", message)
|
decrypted2 = self.gpg.decrypt(encrypted, passphrase="martenvandijk")
|
||||||
logger.debug("new: %r", decrypted.data)
|
self.assertEqual(message, str(decrypted2.data))
|
||||||
self.assertEqual(message, decrypted.data, "Round-trip must work")
|
|
||||||
|
|
||||||
encrypted2 = str(gpg.encrypt(message, [gentry, dijk]))
|
def test_symmetric_encryption_and_decryption(self):
|
||||||
self.assertNotEqual(message, encrypted2, "PT and CT should not match")
|
"""Test symmetric encryption and decryption"""
|
||||||
decrypted1 = gpg.decrypt(encrypted2, passphrase="craiggentry")
|
msg = """
|
||||||
self.assertEqual(message, decrypted.data, "Round-trip must work")
|
If you have something that you don't want anyone to know, maybe you shouldn't
|
||||||
decrypted2 = gpg.decrypt(encrypted2, passphrase="martenvandijk")
|
be doing it in the first place. - Eric Schmidt, CEO of Google"""
|
||||||
self.assertEqual(message, decrypted.data, "Round-trip must work")
|
encrypted = str(self.gpg.encrypt(msg, None, passphrase='quiscustodiet',
|
||||||
# Test symmetric encryption
|
symmetric=True))
|
||||||
data = "chippy was here"
|
decrypted = self.gpg.decrypt(encrypted, passphrase='quiscustodiet')
|
||||||
edata = str(gpg.encrypt(data, None, passphrase='bbrown',
|
self.assertEqual(msg, str(decrypted.data))
|
||||||
symmetric=True))
|
|
||||||
decrypted = gpg.decrypt(edata, passphrase='bbrown')
|
|
||||||
self.assertEqual(data, str(decrypted))
|
|
||||||
|
|
||||||
def test_file_encryption_and_decryption(self):
|
def test_file_encryption_and_decryption(self):
|
||||||
"""Test that encryption/decryption to/from file works."""
|
"""Test that encryption/decryption to/from file works."""
|
||||||
|
@ -777,6 +796,8 @@ suites = { 'parsers': set(['test_parsers_fix_unsafe',
|
||||||
'test_encryption_alt_encoding',
|
'test_encryption_alt_encoding',
|
||||||
'test_encryption_multi_recipient',
|
'test_encryption_multi_recipient',
|
||||||
'test_decryption',
|
'test_decryption',
|
||||||
|
'test_decryption_multi_recipient',
|
||||||
|
'test_symmetric_encryption_and_decryption',
|
||||||
'test_file_encryption_and_decryption']),
|
'test_file_encryption_and_decryption']),
|
||||||
'listkeys': set(['test_list_keys_after_generation']),
|
'listkeys': set(['test_list_keys_after_generation']),
|
||||||
'keyrings': set(['test_public_keyring',
|
'keyrings': set(['test_public_keyring',
|
||||||
|
|
Loading…
Reference in New Issue