|
@@ -23,6 +23,7 @@ std::vector<uint16_t> storage_map;
|
|
std::vector<uint16_t> ingestion_map;
|
|
std::vector<uint16_t> ingestion_map;
|
|
unsigned long setup_time;
|
|
unsigned long setup_time;
|
|
uint16_t nthreads = 1;
|
|
uint16_t nthreads = 1;
|
|
|
|
+bool private_routing;
|
|
|
|
|
|
// Split a hostport string like "127.0.0.1:12000" at the rightmost colon
|
|
// Split a hostport string like "127.0.0.1:12000" at the rightmost colon
|
|
// into a host part "127.0.0.1" and a port part "12000".
|
|
// into a host part "127.0.0.1" and a port part "12000".
|
|
@@ -130,6 +131,15 @@ void displayEncMessageBundle(unsigned char *bundle, uint16_t priv_out,
|
|
printf("\n");
|
|
printf("\n");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static inline uint32_t encPubMsgBundleSize(uint16_t pub_out, uint16_t msg_size)
|
|
|
|
+{
|
|
|
|
+ return(SGX_AESGCM_IV_SIZE + (pub_out * msg_size) + SGX_AESGCM_MAC_SIZE);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static inline uint32_t ptPubMsgBundleSize(uint16_t pub_out, uint16_t msg_size)
|
|
|
|
+{
|
|
|
|
+ return(pub_out * msg_size);
|
|
|
|
+}
|
|
|
|
|
|
static inline uint32_t encMsgBundleSize(uint16_t priv_out, uint16_t msg_size)
|
|
static inline uint32_t encMsgBundleSize(uint16_t priv_out, uint16_t msg_size)
|
|
{
|
|
{
|
|
@@ -185,7 +195,8 @@ bool config_parse(Config &config, const std::string configstr,
|
|
} else if (!pentry.first.compare("master_secret")) {
|
|
} else if (!pentry.first.compare("master_secret")) {
|
|
std::string hex_key = pentry.second.data();
|
|
std::string hex_key = pentry.second.data();
|
|
memcpy(config.master_secret, hex_key.c_str(), SGX_AESGCM_KEY_SIZE);
|
|
memcpy(config.master_secret, hex_key.c_str(), SGX_AESGCM_KEY_SIZE);
|
|
-
|
|
|
|
|
|
+ } else if (!pentry.first.compare("private_routing")) {
|
|
|
|
+ config.private_routing = pentry.second.get_value<bool>();
|
|
} else {
|
|
} else {
|
|
std::cerr << "Unknown field in params: " <<
|
|
std::cerr << "Unknown field in params: " <<
|
|
pentry.first << "\n";
|
|
pentry.first << "\n";
|
|
@@ -519,8 +530,10 @@ void Client::generateMessageBundle(uint8_t priv_out, uint32_t msg_size,
|
|
ptr+=(remaining_message_size);
|
|
ptr+=(remaining_message_size);
|
|
}
|
|
}
|
|
|
|
|
|
- // Add the tokens for this msgbundle
|
|
|
|
- memcpy(ptr, token_list, config.m_priv_out * TOKEN_SIZE);
|
|
|
|
|
|
+ if(private_routing) {
|
|
|
|
+ // Add the tokens for this msgbundle
|
|
|
|
+ memcpy(ptr, token_list, config.m_priv_out * TOKEN_SIZE);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -550,16 +563,26 @@ bool Client::encryptMessageBundle(uint32_t enc_bundle_size, unsigned char *pt_ms
|
|
|
|
|
|
void Client::sendMessageBundle()
|
|
void Client::sendMessageBundle()
|
|
{
|
|
{
|
|
-
|
|
|
|
uint16_t priv_out = config.m_priv_out;
|
|
uint16_t priv_out = config.m_priv_out;
|
|
|
|
+ uint16_t pub_out = config.m_pub_out;
|
|
uint16_t msg_size = config.msg_size;
|
|
uint16_t msg_size = config.msg_size;
|
|
- uint32_t send_pt_msgbundle_size = ptMsgBundleSize(priv_out, msg_size);
|
|
|
|
- uint32_t send_enc_msgbundle_size = encMsgBundleSize(priv_out, msg_size);
|
|
|
|
- unsigned char *send_pt_msgbundle = (unsigned char*) malloc (send_pt_msgbundle_size);
|
|
|
|
- unsigned char *send_enc_msgbundle = (unsigned char*) malloc (send_enc_msgbundle_size);
|
|
|
|
|
|
+ uint32_t send_pt_msgbundle_size, send_enc_msgbundle_size;
|
|
|
|
|
|
- generateMessageBundle(priv_out, msg_size, send_pt_msgbundle);
|
|
|
|
|
|
+ if(private_routing) {
|
|
|
|
+ send_pt_msgbundle_size = ptMsgBundleSize(priv_out, msg_size);
|
|
|
|
+ send_enc_msgbundle_size = encMsgBundleSize(priv_out, msg_size);
|
|
|
|
+ } else {
|
|
|
|
+ send_pt_msgbundle_size = ptPubMsgBundleSize(pub_out, msg_size);
|
|
|
|
+ send_enc_msgbundle_size = encPubMsgBundleSize(pub_out, msg_size);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ unsigned char *send_pt_msgbundle = (unsigned char*) malloc (send_pt_msgbundle_size);
|
|
|
|
+ unsigned char *send_enc_msgbundle = (unsigned char*) malloc (send_enc_msgbundle_size);
|
|
|
|
+ if(private_routing) {
|
|
|
|
+ generateMessageBundle(priv_out, msg_size, send_pt_msgbundle);
|
|
|
|
+ } else {
|
|
|
|
+ generateMessageBundle(pub_out, msg_size, send_pt_msgbundle);
|
|
|
|
+ }
|
|
encryptMessageBundle(send_enc_msgbundle_size, send_pt_msgbundle, send_enc_msgbundle);
|
|
encryptMessageBundle(send_enc_msgbundle_size, send_pt_msgbundle, send_enc_msgbundle);
|
|
|
|
|
|
#ifdef VERBOSE_CLIENT
|
|
#ifdef VERBOSE_CLIENT
|
|
@@ -777,64 +800,105 @@ void Client::epoch_process() {
|
|
+ SGX_AESGCM_MAC_SIZE;
|
|
+ SGX_AESGCM_MAC_SIZE;
|
|
unsigned char *enc_tokens = (unsigned char*) malloc (token_bundle_size);
|
|
unsigned char *enc_tokens = (unsigned char*) malloc (token_bundle_size);
|
|
|
|
|
|
- //Async read the encrypted tokens for this epoch
|
|
|
|
- boost::asio::async_read(*storage_sock, boost::asio::buffer(enc_tokens, token_bundle_size),
|
|
|
|
- [this, enc_tokens, token_bundle_size, pt_token_size]
|
|
|
|
- (boost::system::error_code ec, std::size_t) {
|
|
|
|
|
|
+ if(private_routing) {
|
|
|
|
+ //Async read the encrypted tokens for this epoch
|
|
|
|
+ boost::asio::async_read(*storage_sock, boost::asio::buffer(enc_tokens, token_bundle_size),
|
|
|
|
+ [this, enc_tokens, token_bundle_size, pt_token_size]
|
|
|
|
+ (boost::system::error_code ec, std::size_t) {
|
|
|
|
|
|
- if (ec) {
|
|
|
|
- if(ec == boost::asio::error::eof) {
|
|
|
|
- delete(storage_sock);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- printf("Error %s\n", ec.message().c_str());
|
|
|
|
- printf("Client::epoch_process boost async_read_tokens failed\n");
|
|
|
|
|
|
+ if (ec) {
|
|
|
|
+ if(ec == boost::asio::error::eof) {
|
|
|
|
+ delete(storage_sock);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ printf("Error %s\n", ec.message().c_str());
|
|
|
|
+ printf("Client::epoch_process boost async_read_tokens failed\n");
|
|
|
|
+ }
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
|
|
-#ifdef VERBOSE_CLIENT
|
|
|
|
- if(sim_id == 0) {
|
|
|
|
- printf("TEST: Client 0: Encrypted token bundle received:\n");
|
|
|
|
- for(uint32_t i = 0; i < token_bundle_size; i++) {
|
|
|
|
- printf("%x", enc_tokens[i]);
|
|
|
|
|
|
+ #ifdef VERBOSE_CLIENT
|
|
|
|
+ if(sim_id == 0) {
|
|
|
|
+ printf("TEST: Client 0: Encrypted token bundle received:\n");
|
|
|
|
+ for(uint32_t i = 0; i < token_bundle_size; i++) {
|
|
|
|
+ printf("%x", enc_tokens[i]);
|
|
|
|
+ }
|
|
|
|
+ printf("\n");
|
|
}
|
|
}
|
|
- printf("\n");
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
|
|
+ #endif
|
|
|
|
|
|
|
|
|
|
- // Decrypt the token bundle
|
|
|
|
- unsigned char *enc_tkn_ptr = enc_tokens + SGX_AESGCM_IV_SIZE;
|
|
|
|
- unsigned char *enc_tkn_tag = enc_tokens + SGX_AESGCM_IV_SIZE + pt_token_size;
|
|
|
|
|
|
+ // Decrypt the token bundle
|
|
|
|
+ unsigned char *enc_tkn_ptr = enc_tokens + SGX_AESGCM_IV_SIZE;
|
|
|
|
+ unsigned char *enc_tkn_tag = enc_tokens + SGX_AESGCM_IV_SIZE + pt_token_size;
|
|
|
|
|
|
|
|
|
|
- int decrypted_bytes = gcm_decrypt(enc_tkn_ptr, pt_token_size,
|
|
|
|
- NULL, 0, enc_tkn_tag, (unsigned char*) &(this->stg_key),
|
|
|
|
- enc_tokens, SGX_AESGCM_IV_SIZE, (unsigned char*) (this->token_list));
|
|
|
|
|
|
+ int decrypted_bytes = gcm_decrypt(enc_tkn_ptr, pt_token_size,
|
|
|
|
+ NULL, 0, enc_tkn_tag, (unsigned char*) &(this->stg_key),
|
|
|
|
+ enc_tokens, SGX_AESGCM_IV_SIZE, (unsigned char*) (this->token_list));
|
|
|
|
|
|
- if(decrypted_bytes != pt_token_size) {
|
|
|
|
- printf("Client::epoch_process gcm_decrypt tokens failed. decrypted_bytes = %d \n", decrypted_bytes);
|
|
|
|
- }
|
|
|
|
|
|
+ if(decrypted_bytes != pt_token_size) {
|
|
|
|
+ printf("Client::epoch_process gcm_decrypt tokens failed. decrypted_bytes = %d \n", decrypted_bytes);
|
|
|
|
+ }
|
|
|
|
|
|
- free(enc_tokens);
|
|
|
|
|
|
+ free(enc_tokens);
|
|
|
|
|
|
- /*
|
|
|
|
- unsigned char *tkn_ptr = (unsigned char*) this->token_list;
|
|
|
|
- if(sim_id==0) {
|
|
|
|
- printf("TEST: Client 0: Decrypted client tokens:\n");
|
|
|
|
- for(int i = 0; i < 2 * SGX_AESGCM_KEY_SIZE; i++) {
|
|
|
|
- printf("%x", tkn_ptr[i]);
|
|
|
|
|
|
+ /*
|
|
|
|
+ unsigned char *tkn_ptr = (unsigned char*) this->token_list;
|
|
|
|
+ if(sim_id==0) {
|
|
|
|
+ printf("TEST: Client 0: Decrypted client tokens:\n");
|
|
|
|
+ for(int i = 0; i < 2 * SGX_AESGCM_KEY_SIZE; i++) {
|
|
|
|
+ printf("%x", tkn_ptr[i]);
|
|
|
|
+ }
|
|
|
|
+ printf("\n");
|
|
}
|
|
}
|
|
- printf("\n");
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ // Async read the messages recieved in the last epoch
|
|
|
|
+ uint16_t priv_in = config.m_priv_in;
|
|
|
|
+ uint16_t msg_size = config.msg_size;
|
|
|
|
+ uint32_t recv_pt_mailbox_size = ptMailboxSize(priv_in, msg_size);
|
|
|
|
+ uint32_t recv_enc_mailbox_size = encMailboxSize(priv_in, msg_size);
|
|
|
|
+ unsigned char *recv_pt_mailbox = (unsigned char*) malloc (recv_pt_mailbox_size);
|
|
|
|
+ unsigned char *recv_enc_mailbox = (unsigned char*) malloc (recv_enc_mailbox_size);
|
|
|
|
+
|
|
|
|
+ boost::asio::async_read(*storage_sock,
|
|
|
|
+ boost::asio::buffer(recv_enc_mailbox, recv_enc_mailbox_size),
|
|
|
|
+ [this, recv_pt_mailbox, recv_enc_mailbox]
|
|
|
|
+ (boost::system::error_code ecc, std::size_t) {
|
|
|
|
+
|
|
|
|
+ if (ecc) {
|
|
|
|
+ if(ecc == boost::asio::error::eof) {
|
|
|
|
+ delete(storage_sock);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ printf("Error %s\n", ecc.message().c_str());
|
|
|
|
+ }
|
|
|
|
+ printf("Client: boost async_read failed for recieving msg_bundle\n");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #ifdef VERBOSE_CLIENT
|
|
|
|
+ if(sim_id == 0) {
|
|
|
|
+ printf("TEST: Client 0: Encrypted msgbundle received\n");
|
|
|
|
+ }
|
|
|
|
+ #endif
|
|
|
|
+
|
|
|
|
+ // Do whatever processing with the received messages here
|
|
|
|
+ free(recv_enc_mailbox);
|
|
|
|
+ free(recv_pt_mailbox);
|
|
|
|
|
|
|
|
+ // Send this epoch's message bundle
|
|
|
|
+ sendMessageBundle();
|
|
|
|
+ epoch_process();
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
// Async read the messages recieved in the last epoch
|
|
// Async read the messages recieved in the last epoch
|
|
- uint16_t priv_in = config.m_priv_in;
|
|
|
|
|
|
+ uint16_t pub_in = config.m_pub_in;
|
|
uint16_t msg_size = config.msg_size;
|
|
uint16_t msg_size = config.msg_size;
|
|
- uint32_t recv_pt_mailbox_size = ptMailboxSize(priv_in, msg_size);
|
|
|
|
- uint32_t recv_enc_mailbox_size = encMailboxSize(priv_in, msg_size);
|
|
|
|
|
|
+ uint32_t recv_pt_mailbox_size = ptMailboxSize(pub_in, msg_size);
|
|
|
|
+ uint32_t recv_enc_mailbox_size = encMailboxSize(pub_in, msg_size);
|
|
unsigned char *recv_pt_mailbox = (unsigned char*) malloc (recv_pt_mailbox_size);
|
|
unsigned char *recv_pt_mailbox = (unsigned char*) malloc (recv_pt_mailbox_size);
|
|
unsigned char *recv_enc_mailbox = (unsigned char*) malloc (recv_enc_mailbox_size);
|
|
unsigned char *recv_enc_mailbox = (unsigned char*) malloc (recv_enc_mailbox_size);
|
|
|
|
|
|
@@ -854,12 +918,6 @@ void Client::epoch_process() {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
-#ifdef VERBOSE_CLIENT
|
|
|
|
- if(sim_id == 0) {
|
|
|
|
- printf("TEST: Client 0: Encrypted msgbundle received\n");
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
// Do whatever processing with the received messages here
|
|
// Do whatever processing with the received messages here
|
|
free(recv_enc_mailbox);
|
|
free(recv_enc_mailbox);
|
|
free(recv_pt_mailbox);
|
|
free(recv_pt_mailbox);
|
|
@@ -868,8 +926,7 @@ void Client::epoch_process() {
|
|
sendMessageBundle();
|
|
sendMessageBundle();
|
|
epoch_process();
|
|
epoch_process();
|
|
});
|
|
});
|
|
- });
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
void client_epoch_process(uint32_t cstart, uint32_t cstop)
|
|
void client_epoch_process(uint32_t cstart, uint32_t cstop)
|
|
@@ -955,6 +1012,7 @@ int main(int argc, char **argv)
|
|
exit(1);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private_routing = config.private_routing;
|
|
clients = new Client[config.user_count];
|
|
clients = new Client[config.user_count];
|
|
#ifdef VERBOSE_CLIENT
|
|
#ifdef VERBOSE_CLIENT
|
|
printf("Number of ingestion_nodes = %ld, Number of storage_node = %ld\n",
|
|
printf("Number of ingestion_nodes = %ld, Number of storage_node = %ld\n",
|
|
@@ -974,20 +1032,24 @@ int main(int argc, char **argv)
|
|
// Start background threads; one will perform the work and the other
|
|
// Start background threads; one will perform the work and the other
|
|
// will execute the async_write handlers
|
|
// will execute the async_write handlers
|
|
// TODO: Cleanup and distribute this based on nthreads.
|
|
// TODO: Cleanup and distribute this based on nthreads.
|
|
- // Currently assumes 8 threads are available for client simulator.
|
|
|
|
|
|
+ // Currently assumes 4 threads are available for client simulator on chime.
|
|
boost::thread t([&]{io_context.run();});
|
|
boost::thread t([&]{io_context.run();});
|
|
boost::thread t2([&]{io_context.run();});
|
|
boost::thread t2([&]{io_context.run();});
|
|
boost::thread t3([&]{io_context.run();});
|
|
boost::thread t3([&]{io_context.run();});
|
|
|
|
+ /*
|
|
boost::thread t4([&]{io_context.run();});
|
|
boost::thread t4([&]{io_context.run();});
|
|
boost::thread t5([&]{io_context.run();});
|
|
boost::thread t5([&]{io_context.run();});
|
|
boost::thread t6([&]{io_context.run();});
|
|
boost::thread t6([&]{io_context.run();});
|
|
|
|
+ */
|
|
io_context.run();
|
|
io_context.run();
|
|
t.join();
|
|
t.join();
|
|
t2.join();
|
|
t2.join();
|
|
t3.join();
|
|
t3.join();
|
|
|
|
+ /*
|
|
t4.join();
|
|
t4.join();
|
|
t5.join();
|
|
t5.join();
|
|
t6.join();
|
|
t6.join();
|
|
|
|
+ */
|
|
|
|
|
|
delete [] clients;
|
|
delete [] clients;
|
|
}
|
|
}
|