clients.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. Each client has a 4-byte Client ID (id). Client(C) and ingestion servers(I)
  7. are bootstrapped with a shared secret key (K). Clients messages to the
  8. ingestion server have an 8-byte header followed by some data. There are
  9. two types of client messages for C->I communications:
  10. 1) CLIENT_AUTHENTICATE:
  11. Header: (0x00 + 4-byte Client ID)
  12. Body: HMAC(K, epoch_number)
  13. - where MAC is a Keyed MAC with the shared secret key K
  14. over the epoch number.
  15. 2) CLIENT_MESSAGE_BUNDLE:
  16. Header: (0x01 + 4-byte Client ID)
  17. Body: CMP
  18. - where CMP = Client Message Payload is
  19. IV, AESGCM([CM_1], [CM_2], ..., [CM_k]), TAG
  20. with k being the maximum number of messages a client can send in an
  21. epoch, and IV and TAG are the AESGCM IV and TAG for that CMP.
  22. - each CM = Client Message, has the format:
  23. 4-byte Sender ID , 4-byte Recipient ID, 16-byte Token,
  24. <Upto msg_size - 24> - bytes of message data
  25. -NOTE: This will eventually expand to accomodate Token manipulation
  26. component of clients' messages as well.
  27. Headers are stored as the low 5 bytes of a uint64_t.
  28. */
  29. /*
  30. Structure for capture each individual simulated client's state
  31. */
  32. class Client
  33. {
  34. private:
  35. // Clients' have a simulator ID sim_id used for:
  36. // (i) the simulator to divvy up clients across threads
  37. // (ii) the simulator and ingestion servers to align simulated clients
  38. // and their pre-established shared-secrets
  39. clientid_t sim_id;
  40. // The actual client id used by TEEMS is id.
  41. // Format: the first DEST_STORAGE_NODE_BITS bits store the storage node
  42. // number and the userid at that storage node in the last DEST_UID_BITS
  43. clientid_t id;
  44. aes_key key;
  45. unsigned char iv[SGX_AESGCM_IV_SIZE];
  46. boost::asio::ip::tcp::socket *ingestion_sock = NULL;
  47. void generateAuthenticationMessage();
  48. void generateMessageBundle(uint8_t priv_out, uint32_t msg_size,
  49. unsigned char *pt_msgbundle);
  50. bool encryptMessageBundle(uint32_t bundle_size, unsigned char *pt_msgbundle,
  51. unsigned char* enc_msgbundle);
  52. public:
  53. Client () {
  54. memset(key, 0, SGX_AESGCM_KEY_SIZE);
  55. memset(iv, 0, SGX_AESGCM_IV_SIZE);
  56. }
  57. void initClient(clientid_t cid, aes_key ckey, uint16_t num_storage_nodes,
  58. std::vector<uint16_t> &storage_map) {
  59. sim_id = cid;
  60. uint16_t stg_no = cid % num_storage_nodes;
  61. uint16_t stg_id = storage_map[stg_no];
  62. id = stg_id << DEST_UID_BITS;
  63. id += (cid/num_storage_nodes);
  64. printf("Client sim_id = %d, stg_id = %d, cid = %d\n", sim_id, stg_id, id);
  65. memcpy(key, ckey, SGX_AESGCM_KEY_SIZE);
  66. }
  67. bool socketReady(){
  68. return(ingestion_sock!=NULL);
  69. }
  70. clientid_t getid(){
  71. return id;
  72. }
  73. unsigned char* getKey(){
  74. return ((unsigned char*) key);
  75. }
  76. void initializeSocket(boost::asio::io_context &ioc, NodeConfig &ing_server);
  77. int sendAuthMessage();
  78. void sendMessageBundle(uint16_t priv_out, uint16_t msg_size,
  79. unsigned char *pt_msgbundle, unsigned char *enc_msgbundle);
  80. };