main_42.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. def test_depseudonymize(self):
  2. ip = os.urandom(16)
  3. # manually compute investigator-local pseudonym
  4. pseudonym_secrets = {}
  5. for peer_secrets in self.secrets.peers.values():
  6. for shard, shard_secrets in peer_secrets.by_shard.items():
  7. pseudonym_secrets[shard] \
  8. = shard_secrets.pseudonym_component_secret
  9. s = 1
  10. e = ed25519.scalar_unpack(common.sha256(b"PEP3 investigator"))
  11. for secret in pseudonym_secrets.values():
  12. s *= pow(ed25519.scalar_unpack(secret), e, ed25519.l)
  13. s %= ed25519.l
  14. investigator_local_ip = (ed25519.Point.lizard(ip) * s).pack()
  15. # manually create warrant
  16. warrant = pep3_pb2.DepseudonymizationRequest.Warrant()
  17. warrant.act.actor = b"PEP3 investigator"
  18. warrant.act.name.state = pep3_pb2.Pseudonymizable.UNENCRYPTED_PSEUDONYM
  19. warrant.act.name.data = investigator_local_ip
  20. self.investigator.encrypt([warrant.act.name],
  21. self.investigator.public_keys['pseudonym'])
  22. warrant.signature = crypto.sign(
  23. crypto.load_privatekey(crypto.FILETYPE_PEM,
  24. self.secrets.root_certificate_keys.warrants),
  25. warrant.act.SerializeToString(), 'sha256')
  26. result = self.investigator.connect_to("investigator") \
  27. .Depseudonymize(warrant)
  28. self.assertEqual(result.data, ip)