|
@@ -118,12 +118,11 @@ void displayEncMessageBundle(unsigned char *bundle, uint16_t priv_out, uint16_t
|
|
|
}
|
|
|
|
|
|
|
|
|
-#define HEADER_SIZE 8
|
|
|
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);
|
|
|
+ return(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));
|
|
|
+ return((priv_out * msg_size));
|
|
|
}
|
|
|
|
|
|
bool config_parse(Config &config, const std::string configstr,
|
|
@@ -329,7 +328,7 @@ void Client::initializeSocket(boost::asio::io_context &ioc,
|
|
|
ing_server.clistenport), err);
|
|
|
if (!err) break;
|
|
|
std::cerr << "Connection to " << ing_server.name <<
|
|
|
- " refused, will retry.\n";
|
|
|
+ " refused, will , epoch_noretry.\n";
|
|
|
sleep(1);
|
|
|
}
|
|
|
}
|
|
@@ -346,11 +345,6 @@ void Client::generateMessageBundle(uint8_t priv_out, uint32_t msg_size,
|
|
|
unsigned char *pt_msgbundle)
|
|
|
{
|
|
|
unsigned char *ptr = pt_msgbundle;
|
|
|
- uint64_t header = (sim_id << 8) + CLIENT_MESSAGE_BUNDLE;
|
|
|
-
|
|
|
- // Setup header
|
|
|
- memcpy(ptr, (uint8_t*) &header, sizeof(header));
|
|
|
- ptr+=sizeof(header);
|
|
|
|
|
|
// Setup message pt_msgbundle
|
|
|
for(uint32_t i = 0; i < priv_out; i++) {
|
|
@@ -370,23 +364,19 @@ void Client::generateMessageBundle(uint8_t priv_out, uint32_t msg_size,
|
|
|
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;
|
|
|
+ // Encrypt the pt_msgbundle
|
|
|
+ unsigned char *pt_msgbundle_start = pt_msgbundle;
|
|
|
+ unsigned char *enc_msgbundle_start = enc_msgbundle + 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;
|
|
|
+ size_t bytes_to_encrypt = enc_bundle_size - SGX_AESGCM_MAC_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);
|
|
|
+ // Copy IV into the bundle
|
|
|
+ memcpy(enc_msgbundle, iv, SGX_AESGCM_IV_SIZE);
|
|
|
|
|
|
// Update IV
|
|
|
uint64_t *iv_ctr = (uint64_t*) iv;
|
|
@@ -412,20 +402,21 @@ void Client::sendMessageBundle(uint16_t priv_out, uint16_t msg_size,
|
|
|
displayPtMessageBundle(pt_msgbundle, priv_out, msg_size);
|
|
|
#endif
|
|
|
|
|
|
- //displayEncMessageBundle(enc_msgbundle, priv_out, msg_size);
|
|
|
-
|
|
|
boost::asio::write(*ingestion_sock,
|
|
|
boost::asio::buffer(enc_msgbundle, enc_bundle_size));
|
|
|
}
|
|
|
|
|
|
-int Client::sendAuthMessage()
|
|
|
+int Client::sendAuthMessage(unsigned long epoch_no)
|
|
|
{
|
|
|
- uint32_t auth_size = sizeof(uint64_t) + SGX_AESGCM_KEY_SIZE;
|
|
|
- unsigned char *auth_string = (unsigned char*) malloc(auth_size);
|
|
|
- unsigned char *as_ptr = auth_string;
|
|
|
- uint64_t header = (sim_id << 8) + CLIENT_AUTHENTICATE;
|
|
|
- memcpy(as_ptr, &header, sizeof(header));
|
|
|
- as_ptr+=sizeof(header);
|
|
|
+ uint32_t auth_size = sizeof(clientid_t) + sizeof(unsigned long) + SGX_AESGCM_KEY_SIZE;
|
|
|
+ unsigned char *auth_message = (unsigned char*) malloc(auth_size);
|
|
|
+ unsigned char *am_ptr = auth_message;
|
|
|
+
|
|
|
+ memcpy(am_ptr, &sim_id, sizeof(sim_id));
|
|
|
+ am_ptr+=sizeof(sim_id);
|
|
|
+
|
|
|
+ memcpy(am_ptr, &epoch_no, sizeof(unsigned long));
|
|
|
+ am_ptr+=sizeof(unsigned long);
|
|
|
|
|
|
unsigned char zeroes[SGX_AESGCM_KEY_SIZE];
|
|
|
unsigned char tag[SGX_AESGCM_MAC_SIZE];
|
|
@@ -434,7 +425,7 @@ int Client::sendAuthMessage()
|
|
|
memset(tag, 0, SGX_AESGCM_KEY_SIZE);
|
|
|
|
|
|
if (sizeof(zeroes) != gcm_encrypt(zeroes, SGX_AESGCM_KEY_SIZE, NULL, 0, key,
|
|
|
- iv, SGX_AESGCM_IV_SIZE, as_ptr, tag)) {
|
|
|
+ (unsigned char*) &epoch_no, sizeof(epoch_no), am_ptr, tag)) {
|
|
|
printf("generateClientEncryptionKey failed\n");
|
|
|
return -1;
|
|
|
}
|
|
@@ -444,15 +435,15 @@ int Client::sendAuthMessage()
|
|
|
(*iv_ctr)+=1;
|
|
|
|
|
|
#ifdef VERBOSE_CLIENT
|
|
|
- printf("Client %d auth_string: \n", id);
|
|
|
+ printf("Client %d auth_message: \n", id);
|
|
|
for(int i=0; i<auth_size; i++) {
|
|
|
- printf("%x", auth_string[i]);
|
|
|
+ printf("%x", auth_message[i]);
|
|
|
}
|
|
|
printf("\n");
|
|
|
#endif
|
|
|
|
|
|
boost::asio::write(*ingestion_sock,
|
|
|
- boost::asio::buffer(auth_string, auth_size));
|
|
|
+ boost::asio::buffer(auth_message, auth_size));
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
@@ -479,7 +470,6 @@ void generateClients(boost::asio::io_context &io_context,
|
|
|
clients[i].initClient(i, client_key, num_stg_nodes, storage_map);
|
|
|
|
|
|
clients[i].initializeSocket(io_context, ingestion_nodes[ing_node_this_client]);
|
|
|
- clients[i].sendAuthMessage();
|
|
|
|
|
|
/*
|
|
|
// Test that the keys generated match those generated within
|
|
@@ -493,6 +483,15 @@ void generateClients(boost::asio::io_context &io_context,
|
|
|
printf("\n\n");
|
|
|
*/
|
|
|
}
|
|
|
+
|
|
|
+ struct timespec ep;
|
|
|
+ clock_gettime(CLOCK_REALTIME_COARSE, &ep);
|
|
|
+ unsigned long ep_time = ep.tv_sec * 1000000 + ep.tv_nsec/1000;
|
|
|
+ unsigned long epoch_no = CEILDIV(ep_time, EPOCH_INTERVAL);
|
|
|
+
|
|
|
+ for(uint32_t i=cstart; i<cstop; i++) {
|
|
|
+ clients[i].sendAuthMessage(epoch_no);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|