clients.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 32769
  7. #define PORT_END 60000
  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. struct ip_addr
  21. {
  22. uint8_t ip1;
  23. uint8_t ip2;
  24. uint8_t ip3;
  25. uint8_t ip4;
  26. void increment(int nthreads) {
  27. ip4++;
  28. if(ip4==0) {
  29. ip3++;
  30. if(ip3==0) {
  31. ip2+=nthreads;
  32. }
  33. }
  34. }
  35. std::string ip_str() {
  36. return(std::to_string(ip1) + "." + std::to_string(ip2) + "."
  37. + std::to_string(ip3) + "." + std::to_string(ip4));
  38. }
  39. };
  40. /*
  41. Structure for capture each individual simulated client's state
  42. */
  43. class Client
  44. {
  45. private:
  46. // Clients' have a simulator ID sim_id used for:
  47. // (i) the simulator to divvy up clients across threads
  48. // (ii) the simulator and ingestion servers to align simulated clients
  49. // and their pre-established shared-secrets
  50. clientid_t sim_id;
  51. // The actual client id used by TEEMS is id.
  52. // Format: the first DEST_STORAGE_NODE_BITS bits store the storage node
  53. // number and the userid at that storage node in the last DEST_UID_BITS
  54. clientid_t id;
  55. aes_key ing_key;
  56. aes_key stg_key;
  57. // Clients send encrypted messages to ingestion
  58. // so they set and increment the IV
  59. unsigned char ing_iv[SGX_AESGCM_IV_SIZE] = {0};
  60. token *token_list;
  61. boost::asio::ip::tcp::socket *ingestion_sock = NULL;
  62. boost::asio::ip::tcp::socket *storage_sock = NULL;
  63. void generateAuthenticationMessage();
  64. int sendIngAuthMessage(unsigned long epoch_no);
  65. int sendStgAuthMessage(unsigned long epoch_no);
  66. void generateMessageBundle(uint8_t priv_out, uint32_t msg_size,
  67. unsigned char *pt_msgbundle);
  68. bool encryptMessageBundle(uint32_t bundle_size, unsigned char *pt_msgbundle,
  69. unsigned char* enc_msgbundle);
  70. void sendMessageBundle();
  71. void initializeIngSocket(boost::asio::io_context &ioc, NodeConfig &ing_server,
  72. ip_addr *curr_ip, uint16_t &port_no);
  73. void initializeStgSocket(boost::asio::io_context &ioc, NodeConfig &ing_server,
  74. ip_addr *curr_ip, uint16_t &port_no);
  75. void initClient(clientid_t cid, uint16_t stg_id, aes_key ikey, aes_key skey);
  76. public:
  77. Client() {}
  78. ~Client() {
  79. free(token_list);
  80. delete(ingestion_sock);
  81. delete(storage_sock);
  82. }
  83. void setup_client(boost::asio::io_context &ioc, uint32_t sim_id,
  84. uint16_t ing_node_id, uint16_t stg_node_id,
  85. ip_addr *curr_ip, uint16_t &pno);
  86. void epoch_process();
  87. };