|
@@ -75,59 +75,86 @@ static bool hextobuf(unsigned char *buf, const char *str, size_t len)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-void displayMessage(unsigned char *msg, uint16_t msg_size)
|
|
|
+void displayMessage(unsigned char *msg, uint16_t msg_size,
|
|
|
+ uint32_t client)
|
|
|
{
|
|
|
+ std::stringstream outbuf;
|
|
|
clientid_t sid, rid;
|
|
|
+ uint32_t prio;
|
|
|
unsigned char *ptr = msg;
|
|
|
- sid = *((clientid_t*) ptr);
|
|
|
- ptr+=sizeof(sid);
|
|
|
rid = *((clientid_t*) ptr);
|
|
|
+ ptr+=sizeof(rid);
|
|
|
+ if (!private_routing) {
|
|
|
+ prio = *((uint32_t*) ptr);
|
|
|
+ ptr+=sizeof(prio);
|
|
|
+ }
|
|
|
+ sid = *((clientid_t*) ptr);
|
|
|
ptr+=sizeof(sid);
|
|
|
- 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++) {
|
|
|
- printf("%02x", (*ptr));
|
|
|
- ptr++;
|
|
|
+ if (private_routing) {
|
|
|
+ outbuf << std::hex
|
|
|
+ << "Cli: "
|
|
|
+ << std::setfill('0') << std::setw(8) << client
|
|
|
+ << ", Recv: "
|
|
|
+ << std::setfill('0') << std::setw(8) << rid
|
|
|
+ << ", Send: "
|
|
|
+ << std::setfill('0') << std::setw(8) << sid
|
|
|
+ << "\n";
|
|
|
+ } else {
|
|
|
+ outbuf << std::hex
|
|
|
+ << "Cli: "
|
|
|
+ << std::setfill('0') << std::setw(8) << client
|
|
|
+ << ", Recv: "
|
|
|
+ << std::setfill('0') << std::setw(8) << rid
|
|
|
+ << ", Prio: "
|
|
|
+ << std::setfill('0') << std::setw(8) << prio
|
|
|
+ << ", Send: "
|
|
|
+ << std::setfill('0') << std::setw(8) << sid
|
|
|
+ << "\n";
|
|
|
}
|
|
|
- printf("\n");
|
|
|
-}
|
|
|
-
|
|
|
-void displayPtMessageBundle(unsigned char *bundle, uint16_t priv_out,
|
|
|
- uint16_t msg_size)
|
|
|
-{
|
|
|
- unsigned char *ptr = bundle;
|
|
|
-
|
|
|
- for(int i=0; i<priv_out; i++) {
|
|
|
- displayMessage(ptr, msg_size);
|
|
|
- printf("\n");
|
|
|
- ptr+=msg_size;
|
|
|
+ unsigned char *end = msg + msg_size;
|
|
|
+ while (ptr < end) {
|
|
|
+ size_t remain = end-ptr;
|
|
|
+ if (remain > 16) {
|
|
|
+ remain = 16;
|
|
|
+ }
|
|
|
+ char row[34 + 17 + 2];
|
|
|
+ memset(row, ' ', sizeof(row)-1);
|
|
|
+ row[sizeof(row)-2] = '\n';
|
|
|
+ row[sizeof(row)-1] = '\0';
|
|
|
+ size_t hexoffset = 0;
|
|
|
+ size_t charoffset = 34;
|
|
|
+ for (size_t i=0; i<remain; ++i) {
|
|
|
+ char hex[3];
|
|
|
+ sprintf(hex, "%02x", ptr[i]);
|
|
|
+ memcpy(row+hexoffset, hex, 2);
|
|
|
+ if (ptr[i] >= ' ' && ptr[i] <= '~') {
|
|
|
+ row[charoffset] = ptr[i];
|
|
|
+ } else {
|
|
|
+ row[charoffset] = '.';
|
|
|
+ }
|
|
|
+ hexoffset += 2;
|
|
|
+ charoffset += 1;
|
|
|
+ if (i == 7) {
|
|
|
+ hexoffset += 1;
|
|
|
+ charoffset += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ outbuf << row;
|
|
|
+ ptr += remain;
|
|
|
}
|
|
|
- printf("\n");
|
|
|
+ outbuf << "\n";
|
|
|
+ std::cout << outbuf.str();
|
|
|
}
|
|
|
|
|
|
-void displayEncMessageBundle(unsigned char *bundle, uint16_t priv_out,
|
|
|
- uint16_t msg_size)
|
|
|
+void displayPtMessageBundle(unsigned char *bundle, uint16_t num_out,
|
|
|
+ uint16_t msg_size, uint32_t client)
|
|
|
{
|
|
|
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);
|
|
|
+ for(int i=0; i<num_out; i++) {
|
|
|
+ displayMessage(ptr, msg_size, client);
|
|
|
ptr+=msg_size;
|
|
|
}
|
|
|
-
|
|
|
- printf("MAC: ");
|
|
|
- for(int i=0; i<SGX_AESGCM_MAC_SIZE; i++) {
|
|
|
- printf("%x", ptr[i]);
|
|
|
- }
|
|
|
printf("\n");
|
|
|
}
|
|
|
|
|
@@ -542,23 +569,46 @@ void Client::generateMessageBundle(uint8_t num_out, uint32_t msg_size,
|
|
|
// For benchmarking, each client just sends messages to
|
|
|
// themselves, so the destination and source ids are the same.
|
|
|
|
|
|
- // Destination id
|
|
|
+ // Receiver id
|
|
|
+ uint32_t rid = id;
|
|
|
+#if 0
|
|
|
+ uint32_t dest_uid_mask = (1 << DEST_UID_BITS) - 1;
|
|
|
+ if (!private_routing) {
|
|
|
+ // If we're testing public routing, have each user send a
|
|
|
+ // message to the user with the same local id, but on
|
|
|
+ // storage server 0.
|
|
|
+ rid &= dest_uid_mask;
|
|
|
+ }
|
|
|
+#endif
|
|
|
unsigned char *start_ptr = ptr;
|
|
|
- memcpy(ptr, &id, sizeof(id));
|
|
|
- ptr+=(sizeof(id));
|
|
|
+ memcpy(ptr, &rid, sizeof(rid));
|
|
|
+ ptr += sizeof(rid);
|
|
|
|
|
|
// Priority (for public routing only)
|
|
|
if (!private_routing) {
|
|
|
- memset(ptr, 0, sizeof(uint32_t));
|
|
|
- ptr+=sizeof(uint32_t);
|
|
|
+ uint32_t priority = 0;
|
|
|
+#ifdef SHOW_RECEIVED_MESSAGES
|
|
|
+ // If we're testing public routing, set the priority so that
|
|
|
+ // messages to different users will have the highest
|
|
|
+ // priority messages sent from users at different servers
|
|
|
+ uint32_t id_low_bits = id &
|
|
|
+ ((1 << DEST_STORAGE_NODE_BITS) - 1);
|
|
|
+ priority = id ^ (id_low_bits << DEST_UID_BITS);
|
|
|
+#endif
|
|
|
+ memcpy(ptr, &priority, sizeof(priority));
|
|
|
+ ptr += sizeof(priority);
|
|
|
}
|
|
|
|
|
|
- // Source id
|
|
|
+ // Sender id is our id
|
|
|
memcpy(ptr, &id, sizeof(id));
|
|
|
- ptr+=(sizeof(id));
|
|
|
+ ptr += sizeof(id);
|
|
|
|
|
|
uint32_t remaining_message_size = start_ptr + msg_size - ptr;
|
|
|
memset(ptr, 0, remaining_message_size);
|
|
|
+#ifdef SHOW_RECEIVED_MESSAGES
|
|
|
+ snprintf((char *)ptr, remaining_message_size, "From %08x to %08x",
|
|
|
+ id, rid);
|
|
|
+#endif
|
|
|
ptr+=(remaining_message_size);
|
|
|
}
|
|
|
|
|
@@ -914,8 +964,8 @@ void Client::epoch_process() {
|
|
|
// encrypted mailbox (both private and public routing) for this
|
|
|
// epoch
|
|
|
boost::asio::async_read(*storage_sock, toreceive,
|
|
|
- [this, enc_tokens, token_bundle_size, pt_token_size,
|
|
|
- recv_pt_mailbox, recv_enc_mailbox]
|
|
|
+ [this, enc_tokens, token_bundle_size, pt_token_size, num_in,
|
|
|
+ recv_pt_mailbox, recv_enc_mailbox, recv_pt_mailbox_size]
|
|
|
(boost::system::error_code ec, std::size_t) {
|
|
|
|
|
|
if (ec) {
|
|
@@ -959,7 +1009,7 @@ void Client::epoch_process() {
|
|
|
enc_tokens, SGX_AESGCM_IV_SIZE,
|
|
|
(unsigned char*) (this->token_list));
|
|
|
|
|
|
- if(decrypted_bytes != pt_token_size) {
|
|
|
+ if (decrypted_bytes != pt_token_size) {
|
|
|
printf("Client::epoch_process gcm_decrypt tokens failed. "
|
|
|
"decrypted_bytes = %d\n", decrypted_bytes);
|
|
|
}
|
|
@@ -980,7 +1030,30 @@ void Client::epoch_process() {
|
|
|
|
|
|
// Do whatever processing with the received messages here
|
|
|
// but for the benchmark, we just ignore the received
|
|
|
- // messages
|
|
|
+ // messages (unless we want to print them)
|
|
|
+
|
|
|
+#ifdef SHOW_RECEIVED_MESSAGES
|
|
|
+ unsigned char *recv_enc_mailbox_ptr =
|
|
|
+ recv_enc_mailbox + SGX_AESGCM_IV_SIZE;
|
|
|
+ unsigned char *recv_enc_mailbox_tag =
|
|
|
+ recv_enc_mailbox + SGX_AESGCM_IV_SIZE + recv_pt_mailbox_size;
|
|
|
+
|
|
|
+ int decrypted_bytes = gcm_decrypt(recv_enc_mailbox_ptr,
|
|
|
+ recv_pt_mailbox_size, NULL, 0, recv_enc_mailbox_tag,
|
|
|
+ (unsigned char*) &(this->stg_key), recv_enc_mailbox,
|
|
|
+ SGX_AESGCM_IV_SIZE, recv_pt_mailbox);
|
|
|
+
|
|
|
+ if (decrypted_bytes != recv_pt_mailbox_size) {
|
|
|
+ printf("Client::epoch_process gcm_decrypt mailbox failed. "
|
|
|
+ "decrypted_bytes = %d\n", decrypted_bytes);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (sim_id < 32) {
|
|
|
+ displayPtMessageBundle(recv_pt_mailbox, num_in,
|
|
|
+ config.msg_size, id);
|
|
|
+ }
|
|
|
+
|
|
|
+#endif
|
|
|
|
|
|
free(recv_enc_mailbox);
|
|
|
free(recv_pt_mailbox);
|