#include #include "Untrusted.hpp" #include "appconfig.hpp" // The next line suppresses a deprecation warning within boost #define BOOST_BIND_GLOBAL_PLACEHOLDERS #include "boost/property_tree/ptree.hpp" #include "boost/property_tree/json_parser.hpp" // 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". static bool split_host_port(std::string &host, std::string &port, const std::string &hostport) { size_t colon = hostport.find_last_of(':'); if (colon == std::string::npos) { std::cerr << "Cannot parse \"" << hostport << "\" as host:port\n"; return false; } host = hostport.substr(0, colon); port = hostport.substr(colon+1); return true; } // Convert a single hex character into its value from 0 to 15. Return // true on success, false if it wasn't a hex character. static inline bool hextoval(unsigned char &val, char hex) { if (hex >= '0' && hex <= '9') { val = ((unsigned char)hex)-'0'; } else if (hex >= 'a' && hex <= 'f') { val = ((unsigned char)hex)-'a'+10; } else if (hex >= 'A' && hex <= 'F') { val = ((unsigned char)hex)-'A'+10; } else { return false; } return true; } // Convert a 2*len hex character string into a len-byte buffer. Return // true on success, false on failure. static bool hextobuf(unsigned char *buf, const char *str, size_t len) { if (strlen(str) != 2*len) { std::cerr << "Hex string was not the expected size\n"; return false; } for (size_t i=0;i(); } else if (!pentry.first.compare("user_count")) { config.user_count = pentry.second.get_value(); } else if (!pentry.first.compare("token_out")) { config.m_token_out = pentry.second.get_value(); } else if (!pentry.first.compare("token_in")) { config.m_token_in = pentry.second.get_value(); } else if (!pentry.first.compare("id_out")) { config.m_id_out = pentry.second.get_value(); } else if (!pentry.first.compare("id_in")) { config.m_id_in = pentry.second.get_value(); } else if (!pentry.first.compare("master_secret")) { // Currently hardcoding an AES key for client <-> // server communication, but in reality, a key // exchange would be done std::string hex_key = pentry.second.data(); memcpy(config.master_secret, hex_key.c_str(), SGX_AESGCM_KEY_SIZE); } else if (!pentry.first.compare("token_channel")) { config.token_channel = pentry.second.get_value(); } else { std::cerr << "Unknown field in params: " << pentry.first << "\n"; ret = false; } } found_params = true; } else if (!entry.first.compare("nodes")) { for (auto & node : entry.second) { NodeConfig nc; // defaults nc.weight = 1; nc.roles = ROLE_INGESTION | ROLE_ROUTING | ROLE_STORAGE; for (auto & nentry : node.second) { if (!nentry.first.compare("name")) { nc.name = nentry.second.get_value(); if (!myname.compare(nc.name)) { config.my_node_num = nodenum_t(config.nodes.size()); found_my_node = true; } } else if (!nentry.first.compare("pubkey")) { ret &= hextobuf((unsigned char *)&nc.pubkey, nentry.second.get_value().c_str(), sizeof(nc.pubkey)); } else if (!nentry.first.compare("weight")) { nc.weight = nentry.second.get_value(); } else if (!nentry.first.compare("roles")) { nc.roles = nentry.second.get_value(); } else if (!nentry.first.compare("listen")) { ret &= split_host_port(nc.listenhost, nc.listenport, nentry.second.get_value()); } else if (!nentry.first.compare("clisten")) { ret &= split_host_port(nc.clistenhost, nc.clistenport, nentry.second.get_value()); } else if (!nentry.first.compare("slisten")) { ret &= split_host_port(nc.slistenhost, nc.slistenport, nentry.second.get_value()); } else { std::cerr << "Unknown field in host config: " << nentry.first << "\n"; ret = false; } } config.nodes.push_back(std::move(nc)); } } else { std::cerr << "Unknown key in config: " << entry.first << "\n"; ret = false; } } if (!found_params) { std::cerr << "Could not find params in config\n"; ret = false; } if (!found_my_node) { std::cerr << "Could not find my own node entry in config\n"; ret = false; } config.nthreads = nthreads; if (!ret) return ret; // Now load the config into the enclave EnclaveAPIParams apiparams; apiparams.user_count = config.user_count; apiparams.msg_size = config.msg_size; apiparams.m_token_out = config.m_token_out; apiparams.m_token_in = config.m_token_in; apiparams.m_id_out = config.m_id_out; apiparams.m_id_in = config.m_id_in; memcpy(apiparams.master_secret, config.master_secret, SGX_AESGCM_KEY_SIZE); apiparams.token_channel = config.token_channel; nodenum_t num_nodes = (nodenum_t)(config.nodes.size()); std::vector apinodeconfigs; apinodeconfigs.resize(num_nodes); for (nodenum_t i=0; i