コード例 #1
0
 def test_message_sign(self):
     """
     Test if message is signed with sender key.
     """
     # mock the key fetching
     self._km.fetch_keys_from_server = Mock(return_value=[])
     proto = SMTPFactory(
         self._km, self._config).buildProtocol(('127.0.0.1', 0))
     user = User('*****@*****.**', 'relay.leap.se', proto, ADDRESS)
     fromAddr = Address(ADDRESS_2)
     m = EncryptedMessage(fromAddr, user, self._km, self._config)
     for line in self.EMAIL_DATA[4:12]:
         m.lineReceived(line)
     # trigger signing
     m.eomReceived()
     # assert content of message
     self.assertTrue(
         m._message.get_payload().startswith(
             '-----BEGIN PGP SIGNED MESSAGE-----\n' +
             'Hash: SHA1\n\n' + 
             ('\r\n'.join(self.EMAIL_DATA[9:12]) + '\r\n' +
             '-----BEGIN PGP SIGNATURE-----\n')),
         'Message does not start with signature header.')
     self.assertTrue(
         m._message.get_payload().endswith(
             '-----END PGP SIGNATURE-----\n'),
         'Message does not end with signature footer.')
     # assert signature is valid
     pubkey = self._km.get_key(ADDRESS_2, openpgp.OpenPGPKey)
     self.assertTrue(
         self._km.verify(m._message.get_payload(), pubkey),
         'Signature could not be verified.')
コード例 #2
0
 def test_message_sign(self):
     """
     Test if message is signed with sender key.
     """
     # mock the key fetching
     self._km.fetch_keys_from_server = Mock(return_value=[])
     proto = SMTPFactory(
         self._km, self._config).buildProtocol(('127.0.0.1', 0))
     user = User('*****@*****.**', 'relay.leap.se', proto, ADDRESS)
     fromAddr = Address(ADDRESS_2)
     m = EncryptedMessage(fromAddr, user, self._km, self._config)
     for line in self.EMAIL_DATA[4:12]:
         m.lineReceived(line)
     # trigger signing
     m.eomReceived()
     # assert content of message
     self.assertTrue(
         m._message.get_payload().startswith(
             '-----BEGIN PGP SIGNED MESSAGE-----\n' +
             'Hash: SHA1\n\n' + 
             ('\r\n'.join(self.EMAIL_DATA[9:12]) + '\r\n' +
             '-----BEGIN PGP SIGNATURE-----\n')),
         'Message does not start with signature header.')
     self.assertTrue(
         m._message.get_payload().endswith(
             '-----END PGP SIGNATURE-----\n'),
         'Message does not end with signature footer.')
     # assert signature is valid
     pubkey = self._km.get_key(ADDRESS_2, openpgp.OpenPGPKey)
     self.assertTrue(
         openpgp.verify(m._message.get_payload(), pubkey),
         'Signature could not be verified.')
コード例 #3
0
 def test_message_encrypt(self):
     """
     Test if message gets encrypted to destination email.
     """
     proto = SMTPFactory(
         self._km, self._config).buildProtocol(('127.0.0.1', 0))
     fromAddr = Address(ADDRESS_2)
     dest = User(ADDRESS, 'relay.leap.se', proto, ADDRESS)
     m = EncryptedMessage(fromAddr, dest, self._km, self._config)
     for line in self.EMAIL_DATA[4:12]:
         m.lineReceived(line)
     m.eomReceived()
     privkey = self._km.get_key(
         ADDRESS, openpgp.OpenPGPKey, private=True)
     decrypted = self._km.decrypt(m._message.get_payload(), privkey)
     self.assertEqual(
         '\r\n'.join(self.EMAIL_DATA[9:12]) + '\r\n',
         decrypted,
         'Decrypted text differs from plaintext.')
コード例 #4
0
 def test_message_encrypt(self):
     """
     Test if message gets encrypted to destination email.
     """
     proto = SMTPFactory(
         self._km, self._config).buildProtocol(('127.0.0.1', 0))
     fromAddr = Address(ADDRESS_2)
     dest = User(ADDRESS, 'relay.leap.se', proto, ADDRESS)
     m = EncryptedMessage(fromAddr, dest, self._km, self._config)
     for line in self.EMAIL_DATA[4:12]:
         m.lineReceived(line)
     m.eomReceived()
     privkey = self._km.get_key(
         ADDRESS, openpgp.OpenPGPKey, private=True)
     decrypted = openpgp.decrypt_asym(m._message.get_payload(), privkey)
     self.assertEqual(
         '\r\n'.join(self.EMAIL_DATA[9:12]) + '\r\n',
         decrypted,
         'Decrypted text differs from plaintext.')
コード例 #5
0
 def test_message_encrypt_sign(self):
     """
     Test if message gets encrypted to destination email and signed with
     sender key.
     """
     proto = SMTPFactory(
         self._km, self._config).buildProtocol(('127.0.0.1', 0))
     user = User(ADDRESS, 'relay.leap.se', proto, ADDRESS)
     fromAddr = Address(ADDRESS_2)
     m = EncryptedMessage(fromAddr, user, self._km, self._config)
     for line in self.EMAIL_DATA[4:12]:
         m.lineReceived(line)
     # trigger encryption and signing
     m.eomReceived()
     # decrypt and verify
     privkey = self._km.get_key(
         ADDRESS, openpgp.OpenPGPKey, private=True)
     pubkey = self._km.get_key(ADDRESS_2, openpgp.OpenPGPKey)
     decrypted = self._km.decrypt(
         m._message.get_payload(), privkey, verify=pubkey)
     self.assertEqual(
         '\r\n'.join(self.EMAIL_DATA[9:12]) + '\r\n',
         decrypted,
         'Decrypted text differs from plaintext.')
コード例 #6
0
 def test_message_encrypt_sign(self):
     """
     Test if message gets encrypted to destination email and signed with
     sender key.
     """
     proto = SMTPFactory(
         self._km, self._config).buildProtocol(('127.0.0.1', 0))
     user = User(ADDRESS, 'relay.leap.se', proto, ADDRESS)
     fromAddr = Address(ADDRESS_2)
     m = EncryptedMessage(fromAddr, user, self._km, self._config)
     for line in self.EMAIL_DATA[4:12]:
         m.lineReceived(line)
     # trigger encryption and signing
     m.eomReceived()
     # decrypt and verify
     privkey = self._km.get_key(
         ADDRESS, openpgp.OpenPGPKey, private=True)
     pubkey = self._km.get_key(ADDRESS_2, openpgp.OpenPGPKey)
     decrypted = openpgp.decrypt_asym(
         m._message.get_payload(), privkey, verify=pubkey)
     self.assertEqual(
         '\r\n'.join(self.EMAIL_DATA[9:12]) + '\r\n',
         decrypted,
         'Decrypted text differs from plaintext.')