def test_failedmac(self): for _ in xrange(self.iterations): encrypted_message = encryption.encrypt_then_mac(self.key, 'user,2000') mac = encrypted_message.rsplit("$", 1)[-1] without_mac = encrypted_message.split("$")[:3] r = random.randint(0, len(mac)-1) mac_modified = mac[:r] + chr(ord(mac[r])+1) + mac[r+1:] msg_modified = "$".join(without_mac + [mac_modified]) try: encryption.decrypt_and_mac(self.key, msg_modified) # Should not reach this assert False except ValueError: pass
def test_failedmac(self): for _ in xrange(self.iterations): encrypted_message = encryption.encrypt_then_mac( self.key, 'user,2000') mac = encrypted_message.rsplit("$", 1)[-1] without_mac = encrypted_message.split("$")[:3] r = random.randint(0, len(mac) - 1) mac_modified = mac[:r] + chr(ord(mac[r]) + 1) + mac[r + 1:] msg_modified = "$".join(without_mac + [mac_modified]) try: encryption.decrypt_and_mac(self.key, msg_modified) # Should not reach this assert False except ValueError: pass
def verify_reproducible(testcase, plaintext_msg, encrypted_msg, key): testcase.assertEquals(encryption.decrypt_and_mac(key, encrypted_msg), plaintext_msg)