clients.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. typedef uint8_t token[SGX_AESGCM_MAC_SIZE];
  2. typedef uint8_t aes_key[SGX_AESGCM_KEY_SIZE];
  3. // #define VERBOSE_CLIENT
  4. /*
  5. Client -> Ingestion Server (C->I) communication protocols:
  6. 1) Authentication
  7. Format: Client sim_id, Epoch number, Authentication token
  8. 2) Messages
  9. Format: IV, AESGCM([CM_1], [CM_2], ..., [CM_k]), TAG
  10. - each CM = Client Message for private channel has the format :
  11. 4-byte Sender ID, 4-byte Recipient ID, 16-byte Token,
  12. <Upto msg_size - 24> - bytes of message data
  13. where the Sender ID and Recipient ID are the TEEMS client id
  14. (and not sim_id)
  15. */
  16. /*
  17. Structure for capture each individual simulated client's state
  18. */
  19. class Client
  20. {
  21. private:
  22. // Clients' have a simulator ID sim_id used for:
  23. // (i) the simulator to divvy up clients across threads
  24. // (ii) the simulator and ingestion servers to align simulated clients
  25. // and their pre-established shared-secrets
  26. clientid_t sim_id;
  27. // The actual client id used by TEEMS is id.
  28. // Format: the first DEST_STORAGE_NODE_BITS bits store the storage node
  29. // number and the userid at that storage node in the last DEST_UID_BITS
  30. clientid_t id;
  31. aes_key key;
  32. unsigned char iv[SGX_AESGCM_IV_SIZE];
  33. boost::asio::ip::tcp::socket *ingestion_sock = NULL;
  34. void generateAuthenticationMessage();
  35. void generateMessageBundle(uint8_t priv_out, uint32_t msg_size,
  36. unsigned char *pt_msgbundle);
  37. bool encryptMessageBundle(uint32_t bundle_size, unsigned char *pt_msgbundle,
  38. unsigned char* enc_msgbundle);
  39. public:
  40. Client () {
  41. memset(key, 0, SGX_AESGCM_KEY_SIZE);
  42. memset(iv, 0, SGX_AESGCM_IV_SIZE);
  43. }
  44. void initClient(clientid_t cid, aes_key ckey, uint16_t num_storage_nodes,
  45. std::vector<uint16_t> &storage_map) {
  46. sim_id = cid;
  47. uint16_t stg_no = cid % num_storage_nodes;
  48. uint16_t stg_id = storage_map[stg_no];
  49. id = stg_id << DEST_UID_BITS;
  50. id += (cid/num_storage_nodes);
  51. //printf("Client sim_id = %d, stg_id = %d, cid = %d\n", sim_id, stg_id, id);
  52. memcpy(key, ckey, SGX_AESGCM_KEY_SIZE);
  53. }
  54. bool socketReady(){
  55. return(ingestion_sock!=NULL);
  56. }
  57. clientid_t getid(){
  58. return id;
  59. }
  60. unsigned char* getKey(){
  61. return ((unsigned char*) key);
  62. }
  63. void initializeSocket(boost::asio::io_context &ioc, NodeConfig &ing_server);
  64. int sendAuthMessage(unsigned long epoch_no);
  65. void sendMessageBundle(uint16_t priv_out, uint16_t msg_size,
  66. unsigned char *pt_msgbundle, unsigned char *enc_msgbundle);
  67. };