Browse Source

Minor tweaks for nomenclature consistency of msgbundles and mailboxes

Sajin Sasy 1 year ago
parent
commit
f15b914acd
6 changed files with 33 additions and 30 deletions
  1. 6 5
      App/net.cpp
  2. 1 1
      App/net.hpp
  3. 2 2
      Enclave/Enclave.edl
  4. 1 1
      Enclave/enclave_api.h
  5. 20 18
      Enclave/storage.cpp
  6. 3 3
      Untrusted/Untrusted.cpp

+ 6 - 5
App/net.cpp

@@ -273,6 +273,7 @@ void NetIO::stg_authenticate_new_client(tcp::socket* csocket,
 #ifdef DEBUG_NET_CLIENTS
         printf("Accept handler success\n");
 #endif
+
     unsigned char* auth_message = (unsigned char*) malloc(auth_size);
     boost::asio::async_read(*csocket, boost::asio::buffer(auth_message, auth_size),
         [this, csocket, auth_message]
@@ -342,7 +343,7 @@ void NetIO::send_client_mailbox()
     for(uint32_t lcid = 0; lcid < num_clients_per_stg; lcid++)
     {
         unsigned char *tkn_ptr = epoch_tokens + lcid * token_bundle_size;
-        unsigned char *buf_ptr = epoch_msgbundles + lcid * msgbundle_size;
+        unsigned char *buf_ptr = epoch_mailboxes + lcid * msgbundle_size;
 
         if(client_sockets[lcid]!=nullptr) {
             boost::asio::async_write(*(client_sockets[lcid]),
@@ -462,7 +463,7 @@ NetIO::NetIO(boost::asio::io_context &io_context, const Config &config)
         + (conf.m_priv_out * (conf.msg_size + TOKEN_SIZE))
         + SGX_AESGCM_MAC_SIZE;
     uint16_t priv_out = config.m_priv_out;
-    token_bundle_size = ((priv_out * SGX_AESGCM_KEY_SIZE)
+    token_bundle_size = ((priv_out * TOKEN_SIZE)
         + SGX_AESGCM_IV_SIZE + SGX_AESGCM_MAC_SIZE);
     uint16_t priv_in = conf.m_priv_in;
     mailbox_size = (priv_in * conf.msg_size) + SGX_AESGCM_IV_SIZE
@@ -487,11 +488,11 @@ NetIO::NetIO(boost::asio::io_context &io_context, const Config &config)
             client_sockets.emplace_back(nullptr);
         }
 
-        uint32_t epoch_msgbundles_size = num_clients_per_stg * msgbundle_size;
+        uint32_t epoch_mailboxes_size = num_clients_per_stg * mailbox_size;
         uint32_t epoch_tokens_size = num_clients_per_stg * token_bundle_size;
-        epoch_msgbundles = (unsigned char *) malloc(epoch_msgbundles_size);
+        epoch_mailboxes = (unsigned char *) malloc(epoch_mailboxes_size);
         epoch_tokens = (unsigned char *) malloc (epoch_tokens_size);
-        ecall_supply_storage_buffers(epoch_msgbundles, epoch_msgbundles_size,
+        ecall_supply_storage_buffers(epoch_mailboxes, epoch_mailboxes_size,
             epoch_tokens, epoch_tokens_size);
 
         storage_acceptor = std::shared_ptr<tcp::acceptor>(

+ 1 - 1
App/net.hpp

@@ -143,7 +143,7 @@ class NetIO {
     std::vector<tcp::socket*> client_sockets;
     uint32_t num_clients_per_stg;
     unsigned char *epoch_tokens;
-    unsigned char *epoch_msgbundles;
+    unsigned char *epoch_mailboxes;
     uint16_t num_stg_nodes;
     uint32_t token_bundle_size;
     uint32_t mailbox_size;

+ 2 - 2
Enclave/Enclave.edl

@@ -56,8 +56,8 @@ enclave {
             [user_check] uint8_t *auth_string);
 
         public void ecall_supply_storage_buffers(
-            [user_check] unsigned char *msgbundles,
-            uint32_t msgbundles_size,
+            [user_check] unsigned char *mailboxes,
+            uint32_t mailboxes_size,
             [user_check] unsigned char *tokens,
             uint32_t tokens_size);
     };

+ 1 - 1
Enclave/enclave_api.h

@@ -30,7 +30,7 @@ struct EnclaveAPINodeConfig {
 
 #define SEALED_PRIVKEY_SIZE 610
 
-#define TOKEN_SIZE 16
+#define TOKEN_SIZE SGX_CMAC_MAC_SIZE
 
 // Must be a multiple of 16
 #define FRAME_SIZE (65536+16)

+ 20 - 18
Enclave/storage.cpp

@@ -9,7 +9,7 @@
 
 StgClient *clients;
 uint8_t *epoch_tokens;
-uint8_t *epoch_msgbundles;
+uint8_t *epoch_mailboxes;
 
 static struct {
     uint32_t max_users;
@@ -165,21 +165,20 @@ bool generate_all_tokens()
 /* processMsgs
    - Take all the messages in storage_state.stg_buf
    - Encrypt them all with their corresponding client key and IV and store into
-      epoch_msgbundles
-   - ecall_send_msgbundle();
+      epoch_mailboxes
 */
 bool processMsgs() {
-    unsigned char *epoch_buf_ptr = epoch_msgbundles;
+    unsigned char *epoch_buf_ptr = epoch_mailboxes;
     unsigned char *stg_buf_ptr = storage_state.stg_buf.buf;
-    uint32_t msg_bundle_size = g_teems_config.m_priv_in * g_teems_config.msg_size;
-    uint32_t enc_msg_bundle_size = msg_bundle_size + SGX_AESGCM_IV_SIZE + SGX_AESGCM_MAC_SIZE;
+    uint32_t mailbox_size = g_teems_config.m_priv_in * g_teems_config.msg_size;
+    uint32_t enc_mailbox_size = mailbox_size + SGX_AESGCM_IV_SIZE + SGX_AESGCM_MAC_SIZE;
     sgx_status_t ret = SGX_SUCCESS;
     unsigned char *epoch_buf_ct_ptr = epoch_buf_ptr + SGX_AESGCM_IV_SIZE;
-    unsigned char *epoch_buf_tag_ptr = epoch_buf_ct_ptr + msg_bundle_size;
+    unsigned char *epoch_buf_tag_ptr = epoch_buf_ct_ptr + mailbox_size;
 
     for(uint32_t lcid = 0; lcid <storage_state.max_users; lcid++) {
         memcpy(epoch_buf_ptr, clients[lcid].iv, SGX_AESGCM_IV_SIZE);
-        ret = sgx_rijndael128GCM_encrypt(&(clients[lcid].key), stg_buf_ptr, msg_bundle_size,
+        ret = sgx_rijndael128GCM_encrypt(&(clients[lcid].key), stg_buf_ptr, mailbox_size,
             (uint8_t*) epoch_buf_ct_ptr, epoch_buf_ptr, SGX_AESGCM_IV_SIZE, NULL, 0,
             (sgx_aes_gcm_128bit_tag_t*) epoch_buf_tag_ptr);
         if(ret!=SGX_SUCCESS) {
@@ -198,10 +197,10 @@ bool processMsgs() {
         }
         */
 
-        stg_buf_ptr+=msg_bundle_size;
-        epoch_buf_ptr+=enc_msg_bundle_size;
-        epoch_buf_ct_ptr+=enc_msg_bundle_size;
-        epoch_buf_tag_ptr+=enc_msg_bundle_size;
+        stg_buf_ptr+=mailbox_size;
+        epoch_buf_ptr+=enc_mailbox_size;
+        epoch_buf_ct_ptr+=enc_mailbox_size;
+        epoch_buf_tag_ptr+=enc_mailbox_size;
     }
 
     return true;
@@ -229,9 +228,7 @@ bool storage_init(uint32_t max_users, uint32_t msg_buf_size)
         }
     }
 
-    printf("my_stg_pos = %d\n", my_stg_pos);
     storage_generateClientKeys(max_users, my_stg_pos);
-    // sendClientTokens();
 
     return true;
 }
@@ -379,7 +376,7 @@ void storage_received(MsgBuffer &storage_buf)
     storage_buf.reset();
     pthread_mutex_unlock(&storage_buf.mutex);
 
-    generate_all_tokens();
+    bool ret = generate_all_tokens();
 
     uint32_t num_expected_msgs = g_teems_config.m_priv_in * storage_state.max_users;
     processMsgs();
@@ -395,22 +392,27 @@ void storage_received(MsgBuffer &storage_buf)
 
 bool ecall_storage_authenticate(clientid_t cid, unsigned char *auth_message)
 {
+    printf("In ecall_storage_authenticate!\n");
     bool ret = false;
     uint32_t lcid = cid / g_teems_config.num_storage_nodes;
     const sgx_aes_gcm_128bit_key_t *ckey = &(clients[lcid].key);
 
+    printf("In Enc/Stg::auth: invoked on cid = %d, lcid = %d\n", cid, lcid);
+
     ret = authenticateClient(auth_message, ckey);
+    printf("After authenticateClient, ret = %d\n", ret);
 
     if(!ret) {
         printf("Storage authentication FAIL\n");
     }
+
     return ret;
 }
 
 
-void ecall_supply_storage_buffers(unsigned char *msgbundles,
-    uint32_t msgbundles_size, unsigned char *tokens, uint32_t tokens_size)
+void ecall_supply_storage_buffers(unsigned char *mailboxes,
+    uint32_t mailboxes_size, unsigned char *tokens, uint32_t tokens_size)
 {
-    epoch_msgbundles = msgbundles;
+    epoch_mailboxes = mailboxes;
     epoch_tokens = tokens;
 }

+ 3 - 3
Untrusted/Untrusted.cpp

@@ -327,9 +327,9 @@ bool ecall_storage_authenticate(clientid_t cid, unsigned char *auth_string)
     return ret;
 }
 
-void ecall_supply_storage_buffers(unsigned char *msgbundles,
-    uint32_t msgbundles_size, unsigned char *tokens, uint32_t tokens_size)
+void ecall_supply_storage_buffers(unsigned char *mailboxes,
+    uint32_t mailboxes_size, unsigned char *tokens, uint32_t tokens_size)
 {
-    ecall_supply_storage_buffers(global_eid, msgbundles, msgbundles_size,
+    ecall_supply_storage_buffers(global_eid, mailboxes, mailboxes_size,
         tokens, tokens_size);
 }