|
@@ -13,6 +13,7 @@ void displayMessage(unsigned char *msg, uint16_t msg_size) {
|
|
|
sid = *((clientid_t*) ptr);
|
|
|
ptr+=sizeof(sid);
|
|
|
rid = *((clientid_t*) ptr);
|
|
|
+ ptr+=sizeof(rid);
|
|
|
printf("Sender ID: %d, Receiver ID: %d, Token: N/A\n", sid, rid );
|
|
|
printf("Message: ");
|
|
|
for(int j = 0; j<msg_size - sizeof(sid)*2; j++) {
|
|
@@ -59,11 +60,11 @@ bool ecall_authenticate(clientid_t cid, unsigned char *auth_message)
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-void Ingestion::initialize(uint32_t cnum, uint32_t cstart, sgx_aes_gcm_128bit_key_t &ESK) {
|
|
|
- clients.num = cnum;
|
|
|
- clients.start = cstart;
|
|
|
- clients.end = cnum + cstart;
|
|
|
- clients.keys = new sgx_aes_gcm_128bit_key_t[cnum];
|
|
|
+void Ingestion::initialize(uint32_t num, uint32_t start, sgx_aes_gcm_128bit_key_t &ESK) {
|
|
|
+ cnum = num;
|
|
|
+ cstart = start;
|
|
|
+ clients = new IngClient[cnum];
|
|
|
+
|
|
|
generateClientKeys(ESK);
|
|
|
|
|
|
max_buffer_size = g_teems_config.m_priv_out * cnum;
|
|
@@ -72,54 +73,26 @@ void Ingestion::initialize(uint32_t cnum, uint32_t cstart, sgx_aes_gcm_128bit_ke
|
|
|
|
|
|
bool Ingestion::authenticate(clientid_t cid, unsigned char *auth_message)
|
|
|
{
|
|
|
- int auth_success = 0;
|
|
|
- unsigned long epoch_no = *((unsigned long*) auth_message);
|
|
|
- auth_message+=(sizeof(unsigned long));
|
|
|
- // Fetch corresponding client key
|
|
|
- clientid_t lcid = cid - g_ing.clients.start;
|
|
|
- sgx_aes_gcm_128bit_key_t &ckey = (g_ing.clients).keys[lcid];
|
|
|
-
|
|
|
- unsigned char computed_auth[SGX_AESGCM_KEY_SIZE];
|
|
|
- unsigned char zeroes[SGX_AESGCM_KEY_SIZE];
|
|
|
- unsigned char iv[SGX_AESGCM_IV_SIZE];
|
|
|
- sgx_aes_gcm_128bit_tag_t mac;
|
|
|
- memset(zeroes, 0, SGX_AESGCM_KEY_SIZE);
|
|
|
- memset(iv, 0, SGX_AESGCM_IV_SIZE);
|
|
|
- sgx_status_t ret = SGX_SUCCESS;
|
|
|
-
|
|
|
- ret = sgx_rijndael128GCM_encrypt(&ckey, zeroes, SGX_AESGCM_KEY_SIZE,
|
|
|
- computed_auth, (unsigned char*) (&epoch_no), sizeof(epoch_no), NULL, 0, &mac);
|
|
|
- if(ret!=SGX_SUCCESS) {
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- auth_success = memcmp(auth_message, computed_auth, SGX_AESGCM_KEY_SIZE);
|
|
|
-
|
|
|
- if(auth_success == 0) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- printf("authentication FAIL\n");
|
|
|
- return false;
|
|
|
- }
|
|
|
+ uint32_t lcid = cid-cstart;
|
|
|
+ const sgx_aes_gcm_128bit_key_t *ckey = &(clients[lcid].key);
|
|
|
+ return(authenticateClient(auth_message, ckey));
|
|
|
}
|
|
|
|
|
|
bool Ingestion::processMsgBundle(clientid_t cid, unsigned char *msgbundle,
|
|
|
uint32_t num_msgs) {
|
|
|
|
|
|
// Fetch corresponding client key
|
|
|
- clientid_t lcid = cid - g_ing.clients.start;
|
|
|
- sgx_aes_gcm_128bit_key_t &ckey = (g_ing.clients).keys[lcid];
|
|
|
+ clientid_t lcid = cid - g_ing.cstart;
|
|
|
+ sgx_aes_gcm_128bit_key_t *ckey = &(clients[lcid].key);
|
|
|
unsigned char *iv = msgbundle;
|
|
|
msgbundle += SGX_AESGCM_IV_SIZE;
|
|
|
|
|
|
uint16_t msg_size = g_teems_config.msg_size;
|
|
|
uint32_t msgbundle_size = num_msgs * msg_size;
|
|
|
unsigned char *dec_msgbundle = (unsigned char *) malloc (msgbundle_size);
|
|
|
- //sgx_aes_gcm_128bit_tag_t tag;
|
|
|
- //memcpy(tag, msgbundle + msgbundle_size, SGX_AESGCM_MAC_SIZE);
|
|
|
sgx_aes_gcm_128bit_tag_t *tag = (sgx_aes_gcm_128bit_tag_t*) (msgbundle + msgbundle_size);
|
|
|
|
|
|
- sgx_status_t ret = sgx_rijndael128GCM_decrypt(&ckey, msgbundle, msgbundle_size,
|
|
|
+ sgx_status_t ret = sgx_rijndael128GCM_decrypt(ckey, msgbundle, msgbundle_size,
|
|
|
dec_msgbundle, iv, SGX_AESGCM_IV_SIZE, NULL, 0, tag);
|
|
|
if(ret!=SGX_SUCCESS) {
|
|
|
printf("Ingestion::processMsgBundle FAIL\n");
|
|
@@ -154,8 +127,8 @@ bool Ingestion::processMsgBundle(clientid_t cid, unsigned char *msgbundle,
|
|
|
void Ingestion::generateClientKeys(sgx_aes_gcm_128bit_key_t &ESK)
|
|
|
{
|
|
|
printf("In Ingestion::genCK, num_clients = %d, client_start = %d, client_end = %d\n",
|
|
|
- clients.num, clients.start, clients.end);
|
|
|
- for(uint32_t i=0; i<clients.num; i++)
|
|
|
+ cnum, cstart, cnum + cstart);
|
|
|
+ for(uint32_t i=0; i<cnum; i++)
|
|
|
{
|
|
|
unsigned char zeroes[SGX_AESGCM_KEY_SIZE];
|
|
|
unsigned char iv[SGX_AESGCM_IV_SIZE];
|
|
@@ -163,12 +136,12 @@ void Ingestion::generateClientKeys(sgx_aes_gcm_128bit_key_t &ESK)
|
|
|
memset(zeroes, 0, SGX_AESGCM_KEY_SIZE);
|
|
|
memset(iv, 0, SGX_AESGCM_IV_SIZE);
|
|
|
|
|
|
- uint32_t client_num = clients.start + i;
|
|
|
+ uint32_t client_num = cstart + i;
|
|
|
memcpy(iv, (uint8_t*) (&client_num), sizeof(client_num));
|
|
|
|
|
|
sgx_status_t ret = SGX_SUCCESS;
|
|
|
ret = sgx_rijndael128GCM_encrypt((const sgx_aes_gcm_128bit_key_t *) (ESK),
|
|
|
- zeroes, SGX_AESGCM_KEY_SIZE, (uint8_t*) (clients.keys[i]), iv,
|
|
|
+ zeroes, SGX_AESGCM_KEY_SIZE, (uint8_t*) (clients[i].key), iv,
|
|
|
SGX_AESGCM_IV_SIZE, NULL, 0, &tag);
|
|
|
if(ret!=SGX_SUCCESS) {
|
|
|
printf("Ingestion::GCK FAIL\n");
|
|
@@ -176,3 +149,8 @@ void Ingestion::generateClientKeys(sgx_aes_gcm_128bit_key_t &ESK)
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+sgx_aes_gcm_128bit_key_t* Ingestion::getClientKey(uint32_t lcid)
|
|
|
+{
|
|
|
+ return(&(clients[lcid].key));
|
|
|
+}
|