|
@@ -16,7 +16,7 @@ static sgx_ec256_public_t g_pubkey;
|
|
|
|
|
|
// The communication states for all the nodes. There's an entry for
|
|
|
// ourselves in here, but it is unused.
|
|
|
-std::vector<NodeCommState> commstates;
|
|
|
+std::vector<NodeCommState> g_commstates;
|
|
|
|
|
|
static nodenum_t tot_nodes, my_node_num;
|
|
|
static class CompletedHandshakeCounter {
|
|
@@ -211,9 +211,9 @@ static void handshake_1_msg_received(NodeCommState &nodest,
|
|
|
// Send handshake message 2
|
|
|
nodest.message_start(sizeof(our_dh_pubkey) + sizeof(srv_cli_sig),
|
|
|
false);
|
|
|
- nodest.message_data((uint8_t*)&our_dh_pubkey, sizeof(our_dh_pubkey),
|
|
|
+ nodest.message_data((const uint8_t*)&our_dh_pubkey, sizeof(our_dh_pubkey),
|
|
|
false);
|
|
|
- nodest.message_data((uint8_t*)&srv_cli_sig, sizeof(srv_cli_sig),
|
|
|
+ nodest.message_data((const uint8_t*)&srv_cli_sig, sizeof(srv_cli_sig),
|
|
|
false);
|
|
|
}
|
|
|
|
|
@@ -334,7 +334,7 @@ static void handshake_2_msg_received(NodeCommState &nodest,
|
|
|
|
|
|
// Send handshake message 3
|
|
|
nodest.message_start(sizeof(cli_srv_sig), false);
|
|
|
- nodest.message_data((uint8_t*)&cli_srv_sig, sizeof(cli_srv_sig),
|
|
|
+ nodest.message_data((const uint8_t*)&cli_srv_sig, sizeof(cli_srv_sig),
|
|
|
false);
|
|
|
|
|
|
// Mark the handshake as complete
|
|
@@ -426,7 +426,7 @@ void NodeCommState::message_start(uint32_t plaintext_len, bool encrypt)
|
|
|
}
|
|
|
|
|
|
// Process len bytes of plaintext data into the current message.
|
|
|
-void NodeCommState::message_data(uint8_t *data, uint32_t len, bool encrypt)
|
|
|
+void NodeCommState::message_data(const uint8_t *data, uint32_t len, bool encrypt)
|
|
|
{
|
|
|
while (len > 0) {
|
|
|
if (msg_plaintext_chunk_remain == 0) {
|
|
@@ -443,7 +443,7 @@ void NodeCommState::message_data(uint8_t *data, uint32_t len, bool encrypt)
|
|
|
}
|
|
|
if (encrypt) {
|
|
|
// Encrypt the data
|
|
|
- sgx_aes_gcm128_enc_update(data, bytes_to_process,
|
|
|
+ sgx_aes_gcm128_enc_update((uint8_t*)data, bytes_to_process,
|
|
|
frame+frame_offset, out_aes_gcm_state);
|
|
|
} else {
|
|
|
// Just copy the plaintext data during the handshake
|
|
@@ -554,9 +554,9 @@ bool comms_init_nodestate(const EnclaveAPINodeConfig *apinodeconfigs,
|
|
|
sgx_ecc_state_handle_t ecc_handle;
|
|
|
sgx_ecc256_open_context(&ecc_handle);
|
|
|
|
|
|
- commstates.clear();
|
|
|
+ g_commstates.clear();
|
|
|
tot_nodes = 0;
|
|
|
- commstates.reserve(num_nodes);
|
|
|
+ g_commstates.reserve(num_nodes);
|
|
|
for (nodenum_t i=0; i<num_nodes; ++i) {
|
|
|
// Check that the pubkey is valid
|
|
|
int valid;
|
|
@@ -564,11 +564,11 @@ bool comms_init_nodestate(const EnclaveAPINodeConfig *apinodeconfigs,
|
|
|
ecc_handle, &valid) ||
|
|
|
!valid) {
|
|
|
printf("Pubkey for node %hu invalid\n", i);
|
|
|
- commstates.clear();
|
|
|
+ g_commstates.clear();
|
|
|
sgx_ecc256_close_context(ecc_handle);
|
|
|
return false;
|
|
|
}
|
|
|
- commstates.emplace_back(&apinodeconfigs[i].pubkey, i);
|
|
|
+ g_commstates.emplace_back(&apinodeconfigs[i].pubkey, i);
|
|
|
}
|
|
|
sgx_ecc256_close_context(ecc_handle);
|
|
|
|
|
@@ -578,12 +578,12 @@ bool comms_init_nodestate(const EnclaveAPINodeConfig *apinodeconfigs,
|
|
|
// reflection attacks)
|
|
|
for (nodenum_t i=0; i<num_nodes; ++i) {
|
|
|
if (i == my_node_num) continue;
|
|
|
- if (!memcmp(&commstates[i].pubkey,
|
|
|
- &commstates[my_node_num].pubkey,
|
|
|
- sizeof(commstates[i].pubkey))) {
|
|
|
+ if (!memcmp(&g_commstates[i].pubkey,
|
|
|
+ &g_commstates[my_node_num].pubkey,
|
|
|
+ sizeof(g_commstates[i].pubkey))) {
|
|
|
printf("Pubkey %hu matches our own; possible reflection attack?\n",
|
|
|
i);
|
|
|
- commstates.clear();
|
|
|
+ g_commstates.clear();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -596,8 +596,8 @@ bool comms_init_nodestate(const EnclaveAPINodeConfig *apinodeconfigs,
|
|
|
// to receive the first handshake message from those nodes'
|
|
|
// enclaves.
|
|
|
for (nodenum_t i=0; i<my_node_num; ++i) {
|
|
|
- commstates[i].in_msg_get_buf = default_in_msg_get_buf;
|
|
|
- commstates[i].in_msg_received = handshake_1_msg_received;
|
|
|
+ g_commstates[i].in_msg_get_buf = default_in_msg_get_buf;
|
|
|
+ g_commstates[i].in_msg_received = handshake_1_msg_received;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
@@ -609,7 +609,7 @@ bool ecall_message(nodenum_t node_num, uint32_t message_len)
|
|
|
node_num);
|
|
|
return false;
|
|
|
}
|
|
|
- NodeCommState &nodest = commstates[node_num];
|
|
|
+ NodeCommState &nodest = g_commstates[node_num];
|
|
|
|
|
|
if (nodest.in_msg_size != nodest.in_msg_offset) {
|
|
|
printf("Received ecall_message without completing previous message\n");
|
|
@@ -639,7 +639,7 @@ bool ecall_chunk(nodenum_t node_num, const uint8_t *chunkdata,
|
|
|
node_num);
|
|
|
return false;
|
|
|
}
|
|
|
- NodeCommState &nodest = commstates[node_num];
|
|
|
+ NodeCommState &nodest = g_commstates[node_num];
|
|
|
|
|
|
if (nodest.in_msg_size == nodest.in_msg_offset) {
|
|
|
printf("Received ecall_chunk after completing message\n");
|
|
@@ -713,7 +713,7 @@ void NodeCommState::handshake_start()
|
|
|
// Send the public key as the first message
|
|
|
message_start(sizeof(handshake_dh_pubkey), false);
|
|
|
|
|
|
- message_data((uint8_t*)&handshake_dh_pubkey,
|
|
|
+ message_data((const uint8_t*)&handshake_dh_pubkey,
|
|
|
sizeof(handshake_dh_pubkey), false);
|
|
|
}
|
|
|
|
|
@@ -725,7 +725,7 @@ bool ecall_comms_start(void *cbpointer)
|
|
|
completed_handshake_counter.reset(cbpointer);
|
|
|
|
|
|
for (nodenum_t t = my_node_num+1; t<tot_nodes; ++t) {
|
|
|
- commstates[t].handshake_start();
|
|
|
+ g_commstates[t].handshake_start();
|
|
|
}
|
|
|
return true;
|
|
|
}
|