clients.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. typedef uint8_t token[SGX_AESGCM_MAC_SIZE];
  2. typedef uint8_t aes_key[SGX_AESGCM_KEY_SIZE];
  3. // #define VERBOSE_CLIENT
  4. // #define RANDOMIZE_CLIENT_RETRY_SLEEP_TIME
  5. #define CLIENT_UNIQUE_IP
  6. #define PORT_START 32768
  7. #define PORT_END 65534
  8. /*
  9. Client -> Ingestion Server (C->I) communication protocols:
  10. 1) Authentication
  11. Format: Client sim_id, Epoch number, Authentication token
  12. 2) Messages
  13. Format: IV, AESGCM([CM_1], [CM_2], ..., [CM_k]), TAG
  14. - each CM = Client Message for private channel has the format :
  15. 4-byte Sender ID, 4-byte Recipient ID, 16-byte Token,
  16. <Upto msg_size - 24> - bytes of message data
  17. where the Sender ID and Recipient ID are the TEEMS client id
  18. (and not sim_id)
  19. */
  20. /*
  21. Structure for capture each individual simulated client's state
  22. */
  23. class Client
  24. {
  25. private:
  26. // Clients' have a simulator ID sim_id used for:
  27. // (i) the simulator to divvy up clients across threads
  28. // (ii) the simulator and ingestion servers to align simulated clients
  29. // and their pre-established shared-secrets
  30. clientid_t sim_id;
  31. // The actual client id used by TEEMS is id.
  32. // Format: the first DEST_STORAGE_NODE_BITS bits store the storage node
  33. // number and the userid at that storage node in the last DEST_UID_BITS
  34. clientid_t id;
  35. aes_key ing_key;
  36. aes_key stg_key;
  37. // Clients send encrypted messages to ingestion
  38. // so they set and increment the IV
  39. unsigned char ing_iv[SGX_AESGCM_IV_SIZE] = {0};
  40. token *token_list;
  41. boost::asio::ip::tcp::socket *ingestion_sock = NULL;
  42. boost::asio::ip::tcp::socket *storage_sock = NULL;
  43. void generateAuthenticationMessage();
  44. int sendIngAuthMessage(unsigned long epoch_no);
  45. int sendStgAuthMessage(unsigned long epoch_no);
  46. void generateMessageBundle(uint8_t priv_out, uint32_t msg_size,
  47. unsigned char *pt_msgbundle);
  48. bool encryptMessageBundle(uint32_t bundle_size, unsigned char *pt_msgbundle,
  49. unsigned char* enc_msgbundle);
  50. void sendMessageBundle();
  51. void initializeIngSocket(boost::asio::io_context &ioc, NodeConfig &ing_server,
  52. std::string raw_ip_addr, uint16_t &port_no);
  53. void initializeStgSocket(boost::asio::io_context &ioc, NodeConfig &ing_server,
  54. std::string raw_ip_addr, uint16_t &port_no);
  55. void initClient(clientid_t cid, uint16_t stg_id, aes_key ikey, aes_key skey);
  56. public:
  57. Client() {}
  58. ~Client() {
  59. free(token_list);
  60. delete(ingestion_sock);
  61. delete(storage_sock);
  62. }
  63. void setup_client(boost::asio::io_context &ioc, uint32_t sim_id,
  64. uint16_t ing_node_id, uint16_t stg_node_id, std::string, uint16_t pno);
  65. void epoch_process();
  66. };