Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 def test_reproducible(self):
     for _ in xrange(self.iterations):
         encrypted_message = encryption.encrypt_then_mac(self.key, 'user,2000')
         verify_reproducible(self, 'user,2000', encrypted_message, self.key)
Exemplo n.º 4
0
 def test_well_formed(self):
     for _ in xrange(self.iterations):
         verify_format(self, encryption.encrypt_then_mac(self.key, "State secret"))
Exemplo n.º 5
0
 def test_reproducible(self):
     for _ in xrange(self.iterations):
         encrypted_message = encryption.encrypt_then_mac(
             self.key, 'user,2000')
         verify_reproducible(self, 'user,2000', encrypted_message, self.key)
Exemplo n.º 6
0
 def test_well_formed(self):
     for _ in xrange(self.iterations):
         verify_format(
             self, encryption.encrypt_then_mac(self.key, "State secret"))