bearer.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import os
  2. import socket
  3. import time
  4. import threading
  5. import config as cfg
  6. from connection.socket import SocketClient
  7. from Crypto.Util.number import long_to_bytes, bytes_to_long
  8. from Utils import *
  9. class Bearer:
  10. def __init__(self, parser):
  11. self.parser = parser
  12. self.connector = None
  13. self.data = None
  14. gBackPrint("BEARER", "")
  15. def oracleInitial(self, data):
  16. try:
  17. time.sleep(3)
  18. self.connector = SocketClient(
  19. data["connector"][0], data["connector"][1], self.parser, "Bearer"
  20. )
  21. self.data = bytes.fromhex(data["data"])
  22. self.dataLen = len(self.data)
  23. bPrint("len", self.dataLen)
  24. if not self.dataLen % 16 == 0:
  25. bPrint("00", b"\x00" * (16 - self.dataLen % 16))
  26. self.data = self.data + b"\x00" * (16 - self.dataLen % 16)
  27. bPrint("len", self.dataLen)
  28. except Exception as e:
  29. rBackPrint("An exception occurred oracleInitial", e)
  30. def MPC(self, json):
  31. try:
  32. n = int(json["data"])
  33. bPrint("MPC Input", self.data[4 * n : 4 * (1 + n)].hex())
  34. bPrint(
  35. "MPC Input int", str(bytes_to_long((self.data[4 * n : 4 * (1 + n)])))
  36. )
  37. s = (
  38. "echo "
  39. + str(bytes_to_long((self.data[4 * n : 4 * (1 + n)])))
  40. + " > ./Player-Data/Input-P1-0"
  41. )
  42. os.system(s)
  43. os.system(
  44. "./MP-SPDZ/mascot-party.x 1 xor -pn 12023 -h 127.0.0.1 -N 3"
  45. )
  46. except Exception as e:
  47. rBackPrint("An exception occurred MPC", e)