Browse Source

Minor touchups to Enclave/config.{cpp,hpp}

Ian Goldberg 11 months ago
parent
commit
971f4eacbd
2 changed files with 19 additions and 13 deletions
  1. 14 11
      Enclave/config.cpp
  2. 5 2
      Enclave/config.hpp

+ 14 - 11
Enclave/config.cpp

@@ -12,7 +12,7 @@ unsigned long storage_epoch;
 
 Config g_teems_config;
 
-int generateMasterKeys(sgx_aes_gcm_128bit_key_t master_secret,
+static int generateMasterKeys(sgx_aes_gcm_128bit_key_t master_secret,
     sgx_aes_gcm_128bit_key_t &ESK, sgx_aes_gcm_128bit_key_t &TSK)
 {
     unsigned char zeroes[SGX_AESGCM_KEY_SIZE];
@@ -24,7 +24,7 @@ int generateMasterKeys(sgx_aes_gcm_128bit_key_t master_secret,
     sgx_status_t ret = SGX_SUCCESS;
 
     ret = sgx_rijndael128GCM_encrypt((const sgx_aes_gcm_128bit_key_t *)
-        (master_secret), zeroes, SGX_AESGCM_KEY_SIZE,
+        master_secret, zeroes, SGX_AESGCM_KEY_SIZE,
         (uint8_t*) ESK, iv, SGX_AESGCM_IV_SIZE, NULL, 0, &mac);
     if(ret!=SGX_SUCCESS) {
         return -1;
@@ -32,14 +32,14 @@ int generateMasterKeys(sgx_aes_gcm_128bit_key_t master_secret,
 
     printf("Encryption Master Key: ");
     for(int i=0;i<SGX_AESGCM_KEY_SIZE;i++) {
-        printf("%x", ESK[i]);
+        printf("%02x", ESK[i]);
     }
-    printf("\n\n");
+    printf("\n");
 
     memset(iv, 0, SGX_AESGCM_IV_SIZE);
     memcpy(iv, "Token", sizeof("Token"));
     ret = sgx_rijndael128GCM_encrypt((const sgx_aes_gcm_128bit_key_t *)
-        (master_secret), zeroes, SGX_AESGCM_KEY_SIZE,
+        master_secret, zeroes, SGX_AESGCM_KEY_SIZE,
         (uint8_t*) TSK, iv, SGX_AESGCM_IV_SIZE, NULL, 0, &mac);
     if(ret!=SGX_SUCCESS) {
         return -1;
@@ -47,7 +47,7 @@ int generateMasterKeys(sgx_aes_gcm_128bit_key_t master_secret,
 
     printf("Token Master Key: ");
     for(int i=0;i<SGX_AESGCM_KEY_SIZE;i++) {
-        printf("%x", TSK[i]);
+        printf("%02x", TSK[i]);
     }
     printf("\n");
 
@@ -72,7 +72,8 @@ bool ecall_config_load(threadid_t nthreads,
     g_teems_config.m_priv_in = apiparams->m_priv_in;
     g_teems_config.m_pub_out = apiparams->m_pub_out;
     g_teems_config.m_pub_in = apiparams->m_pub_in;
-    memcpy(g_teems_config.master_secret, apiparams->master_secret, SGX_AESGCM_KEY_SIZE);
+    memcpy(g_teems_config.master_secret, apiparams->master_secret,
+        SGX_AESGCM_KEY_SIZE);
     g_teems_config.private_routing = apiparams->private_routing;
     // Temporary vectors to store node numbers for nodes of different
     // types, where the node numbers are smaller than our own node
@@ -150,18 +151,20 @@ bool ecall_config_load(threadid_t nthreads,
     threadpool_init(nthreads);
 
     uint8_t my_role = apinodeconfigs[my_node_num].roles;
-    if( (my_role & ROLE_INGESTION) || (my_role & ROLE_STORAGE) ) {
+    if ( (my_role & ROLE_INGESTION) || (my_role & ROLE_STORAGE) ) {
         generateMasterKeys(g_teems_config.master_secret,
             g_teems_config.ESK, g_teems_config.TSK);
 
         uint32_t num_clients_total = g_teems_config.user_count;
 
-        if(my_role & ROLE_INGESTION) {
+        if (my_role & ROLE_INGESTION) {
             uint32_t num_ing_nodes = g_teems_config.num_ingestion_nodes;
-            uint32_t clients_per_server = CEILDIV(num_clients_total, num_ing_nodes);
+            uint32_t clients_per_server =
+                CEILDIV(num_clients_total, num_ing_nodes);
             uint32_t num_clients_this_ing = clients_per_server;
             uint32_t client_start = ing_smaller.size();
-            g_ing.initialize(num_clients_this_ing, client_start, g_teems_config.ESK);
+            g_ing.initialize(num_clients_this_ing, client_start,
+                g_teems_config.ESK);
         }
     }
 

+ 5 - 2
Enclave/config.hpp

@@ -35,10 +35,14 @@ struct Config {
     std::vector<nodenum_t> ingestion_nodes;
     std::vector<nodenum_t> routing_nodes;
     std::vector<nodenum_t> storage_nodes;
-    sgx_aes_gcm_128bit_key_t master_secret;
     // storage_map[i] is the node number of the storage node responsible
     // for the destination adddresses with storage node field i.
     std::vector<nodenum_t> storage_map;
+
+    // A stub hardcoded shared secret to derive the below keys for
+    // client <-> server communications (ESK) and tokens (TSK).  In
+    // reality, this would be a key exchange.
+    sgx_aes_gcm_128bit_key_t master_secret;
     sgx_aes_gcm_128bit_key_t ESK;
     sgx_aes_gcm_128bit_key_t TSK;
 };
@@ -48,5 +52,4 @@ extern Config g_teems_config;
 extern unsigned long ingestion_epoch;
 extern unsigned long storage_epoch;
 
-
 #endif