|
@@ -31,9 +31,9 @@ bool storage_generateClientKeys(uint32_t num_clients, uint32_t my_stg_no) {
|
|
|
for(uint32_t i =0; i < num_clients; i++) {
|
|
|
uint32_t mid = storage_state.my_storage_node_id + i;
|
|
|
clients[i].my_id = mid;
|
|
|
- clients[i].priv_friends = new clientid_t[g_teems_config.m_priv_in];
|
|
|
+ clients[i].priv_friends = new clientid_t[g_teems_config.m_priv_out];
|
|
|
// Initialize this client's private channel friends as themself
|
|
|
- for(int j =0; j <g_teems_config.m_priv_in; j++) {
|
|
|
+ for(int j =0; j <g_teems_config.m_priv_out; j++) {
|
|
|
(clients[i].priv_friends)[j] = mid;
|
|
|
}
|
|
|
}
|
|
@@ -41,7 +41,6 @@ bool storage_generateClientKeys(uint32_t num_clients, uint32_t my_stg_no) {
|
|
|
uint32_t num_stg_nodes = g_teems_config.num_storage_nodes;
|
|
|
uint32_t c_simid = my_stg_no;
|
|
|
|
|
|
- //printf("In Ingestion::genCK, num_clients = %d\n", num_clients);
|
|
|
for (uint32_t i=0; i<num_clients; i++) {
|
|
|
const sgx_aes_gcm_128bit_key_t *pESK = &(g_teems_config.ESK);
|
|
|
unsigned char zeroes[SGX_AESGCM_KEY_SIZE];
|
|
@@ -77,6 +76,162 @@ bool storage_generateClientKeys(uint32_t num_clients, uint32_t my_stg_no) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+bool generate_all_tokens()
|
|
|
+{
|
|
|
+ uint32_t pt_tokens_size = (g_teems_config.m_priv_out * SGX_AESGCM_KEY_SIZE);
|
|
|
+ uint32_t enc_tokens_size = (g_teems_config.m_priv_out * SGX_AESGCM_KEY_SIZE) +
|
|
|
+ SGX_AESGCM_IV_SIZE + SGX_AESGCM_MAC_SIZE;
|
|
|
+ unsigned char token_body[pt_tokens_size];
|
|
|
+
|
|
|
+ const sgx_aes_gcm_128bit_key_t *pTSK = &(g_teems_config.TSK);
|
|
|
+ for(uint32_t lcid=0; lcid<storage_state.max_users; lcid++) {
|
|
|
+
|
|
|
+ unsigned char *tkn_iv_ptr = epoch_tokens + enc_tokens_size * lcid;
|
|
|
+ unsigned char *tkn_ptr = tkn_iv_ptr + SGX_AESGCM_IV_SIZE;
|
|
|
+ unsigned char *tkn_tag = tkn_ptr + pt_tokens_size;
|
|
|
+
|
|
|
+ // We construct the plaintext [S|R|Epoch] underlying the token in
|
|
|
+ // the correct location for this client in the epoch_tokens buffer
|
|
|
+ // The tokens ( i.e., CMAC over S|R|Epoch) is stored in token_body
|
|
|
+ // Then encrypt token_body with the client's storage key and overwrite
|
|
|
+ // the correct location in epoch_tokens
|
|
|
+
|
|
|
+ memset(token_body, 0, pt_tokens_size);
|
|
|
+ memset(tkn_iv_ptr, 0, SGX_AESGCM_IV_SIZE);
|
|
|
+ // IV = epoch_no, for encrypting the token bundle
|
|
|
+ memcpy(tkn_iv_ptr, &storage_epoch, sizeof(storage_epoch));
|
|
|
+
|
|
|
+ unsigned char *ptr = tkn_ptr;
|
|
|
+ for(int i = 0; i<g_teems_config.m_priv_out; i++)
|
|
|
+ {
|
|
|
+ memcpy(ptr, (&(clients[lcid].my_id)), sizeof(clientid_t));
|
|
|
+ memcpy(ptr + sizeof(clientid_t), (&(clients[lcid].priv_friends[i])), sizeof(clientid_t));
|
|
|
+ memcpy(ptr + 2 * sizeof(clientid_t), &storage_epoch, sizeof(storage_epoch));
|
|
|
+ ptr+=SGX_AESGCM_KEY_SIZE;
|
|
|
+ }
|
|
|
+
|
|
|
+ sgx_status_t ret = SGX_SUCCESS;
|
|
|
+ ret = sgx_rijndael128_cmac_msg(pTSK, tkn_ptr, pt_tokens_size,
|
|
|
+ (sgx_cmac_128bit_tag_t*) &token_body);
|
|
|
+ if(ret!=SGX_SUCCESS) {
|
|
|
+ printf("generate_tokens: Creating token FAIL\n");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ if(lcid == 0) {
|
|
|
+ printf("Checking generated token_body:");
|
|
|
+ for(uint32_t i = 0; i < pt_tokens_size; i++) {
|
|
|
+ printf("%x", token_body[i]);
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
+ unsigned char *cl_iv = clients[lcid].iv;
|
|
|
+ ret = (sgx_rijndael128GCM_encrypt(&(clients[lcid].key), token_body, pt_tokens_size,
|
|
|
+ (uint8_t*) tkn_ptr, cl_iv, SGX_AESGCM_IV_SIZE, NULL, 0,
|
|
|
+ (sgx_aes_gcm_128bit_tag_t*) tkn_tag));
|
|
|
+ if(ret!=SGX_SUCCESS) {
|
|
|
+ printf("generate_tokens: Encrypting token FAIL\n");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ memcpy(tkn_iv_ptr, cl_iv, SGX_AESGCM_IV_SIZE);
|
|
|
+ // Update IV
|
|
|
+ uint64_t *iv_ctr = (uint64_t*) cl_iv;
|
|
|
+ (*iv_ctr)+=1;
|
|
|
+
|
|
|
+ /*
|
|
|
+ if(lcid == 0) {
|
|
|
+ printf("Encrypted client token bundle:");
|
|
|
+ for(uint32_t i = 0; i < enc_tokens_size; i++) {
|
|
|
+ printf("%x", tkn_iv_ptr[i]);
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
+ }
|
|
|
+ */
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/* 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();
|
|
|
+*/
|
|
|
+bool processMsgs() {
|
|
|
+ unsigned char *epoch_buf_ptr = epoch_msgbundles;
|
|
|
+ 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;
|
|
|
+ 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;
|
|
|
+
|
|
|
+ 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,
|
|
|
+ (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) {
|
|
|
+ printf("processMsgs: Encrypting msgs FAIL\n");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Update IV
|
|
|
+ uint64_t *iv_ctr = (uint64_t*) clients[lcid].iv;
|
|
|
+ (*iv_ctr)+=1;
|
|
|
+
|
|
|
+ if(lcid==0) {
|
|
|
+ printf("\n\nMessage for lcid 0, S, R = %d, %d\n\n\n", *((uint32_t*) stg_buf_ptr),
|
|
|
+ *((uint32_t*) (stg_buf_ptr + 4)));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool generateDummies() {
|
|
|
+ unsigned char *epoch_buf_ptr = epoch_msgbundles;
|
|
|
+ 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;
|
|
|
+ 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 *zeroes = new unsigned char[msg_bundle_size];
|
|
|
+ memset(zeroes, 0, msg_bundle_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), zeroes, msg_bundle_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) {
|
|
|
+ printf("processMsgs: Encrypting msgs FAIL\n");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Update IV
|
|
|
+ uint64_t *iv_ctr = (uint64_t*) clients[lcid].iv;
|
|
|
+ (*iv_ctr)+=1;
|
|
|
+
|
|
|
+ epoch_buf_ptr+=enc_msg_bundle_size;
|
|
|
+ epoch_buf_ct_ptr+=enc_msg_bundle_size;
|
|
|
+ epoch_buf_tag_ptr+=enc_msg_bundle_size;
|
|
|
+ }
|
|
|
+
|
|
|
+ delete zeroes;
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
// route_init will call this function; no one else should call it
|
|
|
// explicitly. The parameter is the number of messages that can fit in
|
|
|
// the storage-side MsgBuffer. Returns true on success, false on
|
|
@@ -249,21 +404,16 @@ void storage_received(MsgBuffer &storage_buf)
|
|
|
storage_buf.reset();
|
|
|
pthread_mutex_unlock(&storage_buf.mutex);
|
|
|
|
|
|
- // TODO: Send the storage_state.stg_buf to clients
|
|
|
- // Encrypt the storage_state.stg_buf into MSG_BUNDLES
|
|
|
- // encryptMsgBundles(num_clients, num_priv_channels, msg_size);
|
|
|
- // Uses: storage_state.stg_buf, clients, epoch_msgbundles
|
|
|
-
|
|
|
- // generateTokens();
|
|
|
- // Uses: clients, epoch_tokens,
|
|
|
+ generate_all_tokens();
|
|
|
|
|
|
- // ocall_process_msgbundles(epoch_msgbundles, epoch_tokens);
|
|
|
- // sendClientTokens();
|
|
|
- //
|
|
|
+ uint32_t num_expected_msgs = g_teems_config.m_priv_in * storage_state.max_users;
|
|
|
+ if(num_msgs!= 0) {
|
|
|
+ processMsgs();
|
|
|
+ } else {
|
|
|
+ generateDummies();
|
|
|
+ }
|
|
|
|
|
|
- // processStorage(msg_bundles) :
|
|
|
- // a) Send out msg_bundles to clients with open sockets
|
|
|
- // b) Store the other msg_bundles in "backend"
|
|
|
+ storage_epoch++;
|
|
|
|
|
|
storage_state.stg_buf.reset();
|
|
|
|
|
@@ -272,92 +422,6 @@ void storage_received(MsgBuffer &storage_buf)
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-/*
|
|
|
- Given a local client identifier, generate the tokens for this client
|
|
|
- for their priv_friends for the next round.
|
|
|
- Populates the supplied tokens buffer with the correct tokens.
|
|
|
-*/
|
|
|
-bool generate_tokens(clientid_t lcid)
|
|
|
-{
|
|
|
- uint32_t pt_tokens_size = (g_teems_config.m_priv_in * SGX_AESGCM_KEY_SIZE);
|
|
|
- uint32_t enc_tokens_size = (g_teems_config.m_priv_in * SGX_AESGCM_KEY_SIZE) +
|
|
|
- SGX_AESGCM_IV_SIZE + SGX_AESGCM_MAC_SIZE;
|
|
|
-
|
|
|
- const sgx_aes_gcm_128bit_key_t *pTSK = &(g_teems_config.TSK);
|
|
|
- unsigned char *tkn_iv_ptr = epoch_tokens + enc_tokens_size * lcid;
|
|
|
- unsigned char *tkn_ptr = tkn_iv_ptr + SGX_AESGCM_IV_SIZE;
|
|
|
- unsigned char *tkn_tag = tkn_ptr + pt_tokens_size;
|
|
|
-
|
|
|
- // We construct the plaintext underlying the token in the correct location
|
|
|
- // for this client in epoch_tokens
|
|
|
- // The tokens get stored in token_body
|
|
|
- // Later we encrypt token_body with the client's storage key and overwrite
|
|
|
- // the correct location in epoch_tokens
|
|
|
- unsigned char token_body[pt_tokens_size];
|
|
|
-
|
|
|
- memset(token_body, 0, pt_tokens_size);
|
|
|
- memset(tkn_iv_ptr, 0, SGX_AESGCM_IV_SIZE);
|
|
|
- // IV = client_id | epoch_no
|
|
|
- memcpy(tkn_iv_ptr, (uint8_t*) (&(clients[lcid].my_id)), sizeof(clientid_t));
|
|
|
- // TODO: Add epoch to IV
|
|
|
- //memcpy(tkn_iv_ptr + sizeof(clientid_t), epoch_no, sizeof(epoch_no));
|
|
|
-
|
|
|
- unsigned char *ptr = tkn_ptr;
|
|
|
- for(int i = 0; i<g_teems_config.m_priv_in; i++)
|
|
|
- {
|
|
|
- memcpy(ptr, (uint8_t*) (&(clients[lcid].my_id)), sizeof(clientid_t));
|
|
|
- memcpy(ptr + sizeof(clientid_t), (uint8_t*) (&(clients[lcid].priv_friends[i])), sizeof(clientid_t));
|
|
|
- ptr+=SGX_AESGCM_KEY_SIZE;
|
|
|
- }
|
|
|
-
|
|
|
- sgx_status_t ret = SGX_SUCCESS;
|
|
|
- ret = sgx_rijndael128GCM_encrypt(pTSK, tkn_ptr, pt_tokens_size,
|
|
|
- (uint8_t*) token_body, tkn_iv_ptr, SGX_AESGCM_IV_SIZE, NULL, 0,
|
|
|
- (sgx_aes_gcm_128bit_tag_t*) tkn_tag);
|
|
|
- if(ret!=SGX_SUCCESS) {
|
|
|
- printf("generate_tokens: Creating token FAIL\n");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- if(lcid == 0) {
|
|
|
- printf("Checking generated token_body:");
|
|
|
- for(uint32_t i = 0; i < pt_tokens_size; i++) {
|
|
|
- printf("%x", token_body[i]);
|
|
|
- }
|
|
|
- printf("\n");
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
- unsigned char *cl_iv = clients[lcid].iv;
|
|
|
- ret = (sgx_rijndael128GCM_encrypt(&(clients[lcid].key), token_body, pt_tokens_size,
|
|
|
- (uint8_t*) tkn_ptr, cl_iv, SGX_AESGCM_IV_SIZE, NULL, 0,
|
|
|
- (sgx_aes_gcm_128bit_tag_t*) tkn_tag));
|
|
|
- if(ret!=SGX_SUCCESS) {
|
|
|
- printf("generate_tokens: Encrypting token FAIL\n");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- memcpy(tkn_iv_ptr, cl_iv, SGX_AESGCM_IV_SIZE);
|
|
|
- // Update IV
|
|
|
- uint64_t *iv_ctr = (uint64_t*) cl_iv;
|
|
|
- (*iv_ctr)+=1;
|
|
|
-
|
|
|
- /*
|
|
|
- if(lcid == 0) {
|
|
|
- printf("Encrypted client token:");
|
|
|
- for(uint32_t i = 0; i < pt_tokens_size; i++) {
|
|
|
- printf("%x", tkn_ptr[i]);
|
|
|
- }
|
|
|
- printf("\n");
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
bool ecall_storage_authenticate(clientid_t cid, unsigned char *auth_message)
|
|
|
{
|
|
|
bool ret = false;
|
|
@@ -369,26 +433,6 @@ bool ecall_storage_authenticate(clientid_t cid, unsigned char *auth_message)
|
|
|
if(!ret) {
|
|
|
printf("Storage authentication FAIL\n");
|
|
|
}
|
|
|
-
|
|
|
- // When clients authenticate:
|
|
|
- // 1) Send back mailbox archive
|
|
|
- // 2) Send tokens for current epoch
|
|
|
-
|
|
|
- ret &= generate_tokens(lcid);
|
|
|
- /*
|
|
|
- uint32_t enc_token_bundle_size = SGX_AESGCM_KEY_SIZE + SGX_AESGCM_IV_SIZE
|
|
|
- unsigned char *token_ptr = lcid *
|
|
|
- // sendTokens()
|
|
|
-
|
|
|
- */
|
|
|
- /*
|
|
|
- if(ret) {
|
|
|
- printf("ecall_storage_auth : ret = SUCCESS\n");
|
|
|
- }
|
|
|
- else {
|
|
|
- printf("ecall_storage_auth : ret = FAIL\n");
|
|
|
- }
|
|
|
- */
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -398,5 +442,4 @@ void ecall_supply_storage_buffers(unsigned char *msgbundles,
|
|
|
{
|
|
|
epoch_msgbundles = msgbundles;
|
|
|
epoch_tokens = tokens;
|
|
|
- printf("Storage buffers were set");
|
|
|
}
|