def testMakingEncryptedContactAccept(self): INTRO = "You really shouldn't be able to read this because it should be encrypted and signed" RECPTKEYID = "3B898548F994C536" # id of key2 m = message.ContactResponseMessage(senderId=None, senderName=None, message=INTRO, senderKey=None) output = m.createOutput(RECPTKEYID) print("This should be encrypted:", output) # Check it's really encrypted by looking for the INTRO string for s in range(len(output) - len(INTRO)): x = "" try: x = output[s:s + len(INTRO)].decode("utf-8") print(x) except Exception: pass self.assertNotEqual(x, INTRO, "Message wasn't encrypted properly") # Test decryption bac = message.Message.MessageFromReceivedData(output) self.assertIsNone(bac, "shouldn't be able to decode the data") # Now we can cheat and add the private key2 to the keyring, then we should be able to decode it TestUtils.setupKeyring(["key2_private", "key1_public"]) bac = message.Message.MessageFromReceivedData(output) self.assertIsNotNone(bac, "should be able to decode the data")
def setUp(self): Config.load() CryptoClient.useTestKeyring() self.FRIEND_TORID = "zo7quhgn1nq1uppt" FRIEND_KEYID = "3B898548F994C536" TestUtils.setupOwnProfile("46944E14D24D711B") # id of key1 DbI.updateProfile( self.FRIEND_TORID, { "status": "trusted", "keyid": FRIEND_KEYID, "name": "Norbert Jones", "displayName": "Uncle Norbert" }) TestUtils.setupKeyring(["key1_private", "key2_public"])
def testMakeEncryptedRelayMessage(self): BODY = "Hey dude, have you got any €uros because I heard they were harsh to ünicode? Oh, and &ersands and <tags> too :)" SENDERID = TestUtils._ownTorId RECPTKEYID = "3B898548F994C536" # keyid of eventual target of the message (key2) m = message.RegularMessage(sendTo=RECPTKEYID, messageBody=BODY) relaymsg = message.RelayingMessage(m.createOutput(RECPTKEYID)) output = relaymsg.createOutput(recipientKeyId=None) bac = message.Message.MessageFromReceivedData(output, True) self.assertIsNotNone(bac, "couldn't decode the data") self.assertEqual(bac.encryptionType, message.Message.ENCTYPE_RELAY, "Encryption type not right") self.assertIsNotNone(bac.payload, "Message should have a payload") self.assertEqual(bac.senderId, SENDERID, "Sender id not right") # Now fiddle with keys to let us decode it TestUtils.setupKeyring(["key2_private", "key1_public"]) bac = message.Message.MessageFromReceivedData(output, True) self.assertIsNotNone(bac, "couldn't decode the data") self.assertEqual(bac.sendTo, RECPTKEYID, "Recipient not right") self.assertEqual(bac.messageBody, BODY, "Message not right")
def testMakingEncryptedContactAccept(self): INTRO = "You really shouldn't be able to read this because it should be encrypted and signed" RECPTKEYID = "3B898548F994C536" # id of key2 m = message.ContactResponseMessage(senderId=None, senderName=None, message=INTRO, senderKey=None) output = m.createOutput(RECPTKEYID) print("This should be encrypted:", output) # Check it's really encrypted by looking for the INTRO string for s in range(len(output) - len(INTRO)): x = "" try: x = output[s : s + len(INTRO)].decode("utf-8") print(x) except Exception: pass self.assertNotEqual(x, INTRO, "Message wasn't encrypted properly") # Test decryption bac = message.Message.MessageFromReceivedData(output) self.assertIsNone(bac, "shouldn't be able to decode the data") # Now we can cheat and add the private key2 to the keyring, then we should be able to decode it TestUtils.setupKeyring(["key2_private", "key1_public"]) bac = message.Message.MessageFromReceivedData(output) self.assertIsNotNone(bac, "should be able to decode the data")
def setUp(self): Config.load() DbClient.useTestTables() CryptoClient.useTestKeyring() TestUtils.setupKeyring(["key1_private", "key2_public"]) TestUtils.setupOwnProfile("46944E14D24D711B") # id of key1
def setUp(self): Config.load() CryptoClient.useTestKeyring() TestUtils.setupKeyring(["key1_private", "key2_public"])
def setUp(self): Config.load() CryptoClient.useTestKeyring() TestUtils.setupKeyring(["key1_private", "key2_public"]) TestUtils.setupOwnProfile("46944E14D24D711B") # id of key1
def setUp(self): Config.load() CryptoClient.useTestKeyring() TestUtils.setupKeyring(["key1_private", "key1_public", "key2_public"]) self.KEYID_1 = "46944E14D24D711B" self.KEYID_2 = "3B898548F994C536"