|
@@ -78,7 +78,7 @@ void displayMessage(unsigned char *msg, uint16_t msg_size) {
|
|
|
printf("\n");
|
|
|
}
|
|
|
|
|
|
-void displayMessageBundle(unsigned char *bundle, uint16_t priv_out, uint16_t msg_size) {
|
|
|
+void displayPtMessageBundle(unsigned char *bundle, uint16_t priv_out, uint16_t msg_size) {
|
|
|
unsigned char *ptr = bundle;
|
|
|
uint64_t header = *((uint64_t*) ptr);
|
|
|
ptr+=sizeof(uint64_t);
|
|
@@ -88,12 +88,40 @@ void displayMessageBundle(unsigned char *bundle, uint16_t priv_out, uint16_t msg
|
|
|
printf("\n");
|
|
|
ptr+=msg_size;
|
|
|
}
|
|
|
+ printf("\n");
|
|
|
+}
|
|
|
+
|
|
|
+void displayEncMessageBundle(unsigned char *bundle, uint16_t priv_out, uint16_t msg_size) {
|
|
|
+ unsigned char *ptr = bundle;
|
|
|
+ uint64_t header = *((uint64_t*) ptr);
|
|
|
+ ptr+=sizeof(uint64_t);
|
|
|
+
|
|
|
+ printf("IV: ");
|
|
|
+ for(int i=0; i<SGX_AESGCM_IV_SIZE; i++) {
|
|
|
+ printf("%x", ptr[i]);
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
+ ptr+= SGX_AESGCM_IV_SIZE;
|
|
|
+
|
|
|
+ for(int i=0; i<priv_out; i++) {
|
|
|
+ displayMessage(ptr, msg_size);
|
|
|
+ ptr+=msg_size;
|
|
|
+ }
|
|
|
|
|
|
+ printf("MAC: ");
|
|
|
+ for(int i=0; i<SGX_AESGCM_MAC_SIZE; i++) {
|
|
|
+ printf("%x", ptr[i]);
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
#define HEADER_SIZE 8
|
|
|
-static inline uint32_t messageBundleSize(uint16_t priv_out, uint16_t msg_size) {
|
|
|
- return(HEADER_SIZE + (priv_out * msg_size) + SGX_AESGCM_MAC_SIZE);
|
|
|
+static inline uint32_t encMsgBundleSize(uint16_t priv_out, uint16_t msg_size) {
|
|
|
+ return(HEADER_SIZE + SGX_AESGCM_IV_SIZE + (priv_out * msg_size) + SGX_AESGCM_MAC_SIZE);
|
|
|
+}
|
|
|
+static inline uint32_t ptMsgBundleSize(uint16_t priv_out, uint16_t msg_size) {
|
|
|
+ return(HEADER_SIZE + (priv_out * msg_size));
|
|
|
}
|
|
|
|
|
|
bool config_parse(Config &config, const std::string configstr,
|
|
@@ -249,12 +277,13 @@ int generateClientEncryptionKey(clientid_t client_number, aes_key &EMK, aes_key
|
|
|
memset(tag, 0, SGX_AESGCM_KEY_SIZE);
|
|
|
memcpy(iv, &client_number, sizeof(client_number));
|
|
|
|
|
|
+ /*
|
|
|
printf("Client Key: (before Gen) ");
|
|
|
for(int i=0;i<SGX_AESGCM_KEY_SIZE;i++) {
|
|
|
printf("%x", client_key[i]);
|
|
|
}
|
|
|
printf("\n");
|
|
|
-
|
|
|
+ */
|
|
|
|
|
|
if (sizeof(zeroes) != gcm_encrypt(zeroes, SGX_AESGCM_KEY_SIZE, NULL, 0, EMK,
|
|
|
iv, SGX_AESGCM_IV_SIZE, client_key, tag)) {
|
|
@@ -262,12 +291,13 @@ int generateClientEncryptionKey(clientid_t client_number, aes_key &EMK, aes_key
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /*
|
|
|
printf("Client Key: (after Gen) ");
|
|
|
for(int i=0;i<SGX_AESGCM_KEY_SIZE;i++) {
|
|
|
printf("%x", client_key[i]);
|
|
|
}
|
|
|
printf("\n");
|
|
|
+ */
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
@@ -305,23 +335,23 @@ void Client::initializeSocket(boost::asio::io_context &ioc,
|
|
|
|
|
|
/*
|
|
|
|
|
|
- Populates the buffer payload with a valid message payload.
|
|
|
- Assumes that it is supplied with a payload buffer of the correct length
|
|
|
+ Populates the buffer pt_msgbundle with a valid message pt_msgbundle.
|
|
|
+ Assumes that it is supplied with a pt_msgbundle buffer of the correct length
|
|
|
|
|
|
- Correct length for payload = 8 + (priv_out)*(msg_size) + 16 bytes
|
|
|
+ Correct length for pt_msgbundle = 8 + (priv_out)*(msg_size) + 16 bytes
|
|
|
|
|
|
*/
|
|
|
void Client::generateMessageBundle(uint8_t priv_out, uint32_t msg_size,
|
|
|
- unsigned char *payload)
|
|
|
+ unsigned char *pt_msgbundle)
|
|
|
{
|
|
|
- unsigned char *ptr = payload;
|
|
|
+ unsigned char *ptr = pt_msgbundle;
|
|
|
uint64_t header = (id << 8) + CLIENT_MESSAGE_BUNDLE;
|
|
|
|
|
|
// Setup header
|
|
|
memcpy(ptr, (uint8_t*) &header, sizeof(header));
|
|
|
ptr+=sizeof(header);
|
|
|
|
|
|
- // Setup message payload
|
|
|
+ // Setup message pt_msgbundle
|
|
|
for(uint32_t i = 0; i < priv_out; i++) {
|
|
|
memcpy(ptr, &id, sizeof(id));
|
|
|
ptr+=(sizeof(id));
|
|
@@ -332,36 +362,56 @@ void Client::generateMessageBundle(uint8_t priv_out, uint32_t msg_size,
|
|
|
memset(ptr, 0, remaining_message_size);
|
|
|
ptr+=(remaining_message_size);
|
|
|
}
|
|
|
-
|
|
|
- memset(ptr, 0, SGX_AESGCM_MAC_SIZE);
|
|
|
}
|
|
|
|
|
|
|
|
|
-void Client::encryptMessageBundle(uint32_t bundle_size, unsigned char *payload)
|
|
|
+bool Client::encryptMessageBundle(uint32_t enc_bundle_size, unsigned char *pt_msgbundle,
|
|
|
+ unsigned char *enc_msgbundle)
|
|
|
{
|
|
|
+ // Copy the header
|
|
|
+ memcpy(enc_msgbundle, pt_msgbundle, HEADER_SIZE);
|
|
|
+
|
|
|
+ // Encrypt the rest of the pt_msgbundle
|
|
|
+ unsigned char *pt_msgbundle_start = pt_msgbundle + HEADER_SIZE;
|
|
|
+ unsigned char *enc_msgbundle_start = enc_msgbundle + HEADER_SIZE + SGX_AESGCM_IV_SIZE;
|
|
|
+ unsigned char *enc_tag = enc_msgbundle + enc_bundle_size - SGX_AESGCM_MAC_SIZE;
|
|
|
+ size_t bytes_to_encrypt = enc_bundle_size - SGX_AESGCM_MAC_SIZE - HEADER_SIZE - SGX_AESGCM_IV_SIZE;
|
|
|
+ if (bytes_to_encrypt != gcm_encrypt(pt_msgbundle_start, bytes_to_encrypt,
|
|
|
+ NULL, 0, key, iv, SGX_AESGCM_IV_SIZE, enc_msgbundle_start, enc_tag)) {
|
|
|
+ printf("Client: encryptMessageBundle FAIL\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
+ // Copy the IV into the bundle
|
|
|
+ unsigned char *enc_msgbundle_iv = enc_msgbundle + HEADER_SIZE;
|
|
|
+ memcpy(enc_msgbundle_iv, iv, SGX_AESGCM_IV_SIZE);
|
|
|
+
|
|
|
+ // Update IV
|
|
|
+ uint64_t *iv_ctr = (uint64_t*) iv;
|
|
|
+ (*iv_ctr)+=1;
|
|
|
+ return 1;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
- Assumes payload is a buffer of size messageBundleSize(priv_out, msg_size)
|
|
|
+ Assumes pt_msgbundle is a buffer of size messageBundleSize(priv_out, msg_size)
|
|
|
*/
|
|
|
|
|
|
void Client::sendMessageBundle(uint16_t priv_out, uint16_t msg_size,
|
|
|
- unsigned char *payload)
|
|
|
+ unsigned char *pt_msgbundle, unsigned char *enc_msgbundle)
|
|
|
{
|
|
|
- uint32_t bundle_size = messageBundleSize(priv_out, msg_size);
|
|
|
+ uint32_t enc_bundle_size = encMsgBundleSize(priv_out, msg_size);
|
|
|
|
|
|
- generateMessageBundle(priv_out, msg_size, payload);
|
|
|
+ generateMessageBundle(priv_out, msg_size, pt_msgbundle);
|
|
|
|
|
|
- //encryptMessageBundle(bundle_size, payload);
|
|
|
+ encryptMessageBundle(enc_bundle_size, pt_msgbundle, enc_msgbundle);
|
|
|
|
|
|
- displayMessageBundle(payload, priv_out, msg_size);
|
|
|
- //Send over the ingestion_sock
|
|
|
+ //displayPtMessageBundle(pt_msgbundle, priv_out, msg_size);
|
|
|
|
|
|
- boost::asio::write(*ingestion_sock,
|
|
|
- boost::asio::buffer(payload, bundle_size));
|
|
|
+ //displayEncMessageBundle(enc_msgbundle, priv_out, msg_size);
|
|
|
|
|
|
+ boost::asio::write(*ingestion_sock,
|
|
|
+ boost::asio::buffer(enc_msgbundle, enc_bundle_size));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -425,12 +475,13 @@ int main(int argc, char **argv)
|
|
|
uint16_t priv_out = config.m_priv_out;
|
|
|
uint16_t msg_size = config.msg_size;
|
|
|
|
|
|
- uint32_t bundle_size = messageBundleSize(priv_out, msg_size);
|
|
|
- unsigned char *payload = (unsigned char*) malloc (bundle_size);
|
|
|
-
|
|
|
+ uint32_t pt_bundle_size = ptMsgBundleSize(priv_out, msg_size);
|
|
|
+ uint32_t enc_bundle_size = encMsgBundleSize(priv_out, msg_size);
|
|
|
+ unsigned char *pt_msgbundle = (unsigned char*) malloc (pt_bundle_size);
|
|
|
+ unsigned char *enc_msgbundle = (unsigned char*) malloc (enc_bundle_size);
|
|
|
|
|
|
uint64_t epoch = 1;
|
|
|
- while(epoch<3) {
|
|
|
+ while(epoch<2) {
|
|
|
|
|
|
for(uint32_t i=0; i<num_clients_total; i++) {
|
|
|
if(epoch==1) {
|
|
@@ -446,7 +497,6 @@ int main(int argc, char **argv)
|
|
|
clients[i].initializeSocket(io_context, ingestion_nodes[ing_node_this_client]);
|
|
|
//clients[i].sendAuthMessage();
|
|
|
|
|
|
-
|
|
|
/*
|
|
|
// Test that the keys generated match those generated within
|
|
|
// enclave config
|
|
@@ -460,12 +510,12 @@ int main(int argc, char **argv)
|
|
|
*/
|
|
|
}
|
|
|
|
|
|
- clients[i].sendMessageBundle(priv_out, msg_size, payload);
|
|
|
+ clients[i].sendMessageBundle(priv_out, msg_size, pt_msgbundle, enc_msgbundle);
|
|
|
}
|
|
|
epoch++;
|
|
|
sleep(1);
|
|
|
}
|
|
|
|
|
|
- free(payload);
|
|
|
+ free(pt_msgbundle);
|
|
|
delete [] clients;
|
|
|
}
|