SKALE-3023 add serverConfiguration command

parent 8cc1d2c4
...@@ -43,8 +43,14 @@ ...@@ -43,8 +43,14 @@
shared_ptr <SGXInfoServer> SGXInfoServer::server = nullptr; shared_ptr <SGXInfoServer> SGXInfoServer::server = nullptr;
shared_ptr <HttpServer> SGXInfoServer::httpServer = nullptr; shared_ptr <HttpServer> SGXInfoServer::httpServer = nullptr;
SGXInfoServer::SGXInfoServer(AbstractServerConnector &connector, serverVersion_t type) SGXInfoServer::SGXInfoServer(AbstractServerConnector &connector, serverVersion_t type,
: AbstractInfoServer(connector, type) {} uint32_t _logLevel, bool _autoSign, bool _checkCerts, bool _generateTestKeys)
: AbstractInfoServer(connector, type) {
logLevel_ = _logLevel;
autoSign_ = _autoSign;
checkCerts_ = _checkCerts;
generateTestKeys_ = _generateTestKeys;
}
Json::Value SGXInfoServer::getAllKeysInfo() { Json::Value SGXInfoServer::getAllKeysInfo() {
Json::Value result; Json::Value result;
...@@ -72,13 +78,13 @@ Json::Value SGXInfoServer::getServerConfiguration() { ...@@ -72,13 +78,13 @@ Json::Value SGXInfoServer::getServerConfiguration() {
Json::Value result; Json::Value result;
try { try {
result["autoConfirm"] = false; result["autoConfirm"] = autoconfirm;
result["logLevel"] = false; result["logLevel"] = logLevel_;
result["enclaveLogLevel"] = false; result["enterBackupKey"] = enterBackupKey;
result["backupOption"] = false; result["useHTTPS"] = useHTTPS;
result["HTTPS"] = false; result["autoSign"] = autoSign_;
result["autoSign"] = false; result["checkCerts"] = checkCerts_;
result["createTestKeys"] = false; result["generateTestKeys"] = generateTestKeys_;
} HANDLE_SGX_EXCEPTION(result) } HANDLE_SGX_EXCEPTION(result)
RETURN_SUCCESS(result) RETURN_SUCCESS(result)
...@@ -99,9 +105,9 @@ Json::Value SGXInfoServer::isKeyExist(const string& key) { ...@@ -99,9 +105,9 @@ Json::Value SGXInfoServer::isKeyExist(const string& key) {
RETURN_SUCCESS(result) RETURN_SUCCESS(result)
} }
int SGXInfoServer::initInfoServer() { int SGXInfoServer::initInfoServer(uint32_t _logLevel, bool _autoSign, bool _checkCerts, bool _generateTestKeys) {
httpServer = make_shared<HttpServer>(BASE_PORT + 5); httpServer = make_shared<HttpServer>(BASE_PORT + 5);
server = make_shared<SGXInfoServer>(*httpServer, JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0) server = make_shared<SGXInfoServer>(*httpServer, JSONRPC_SERVER_V2, _logLevel, _autoSign, _checkCerts, _generateTestKeys); // hybrid server (json-rpc 1.0 & 2.0)
if (!server->StartListening()) { if (!server->StartListening()) {
spdlog::error("Info server could not start listening on port {}", BASE_PORT + 5); spdlog::error("Info server could not start listening on port {}", BASE_PORT + 5);
......
...@@ -35,7 +35,10 @@ using namespace std; ...@@ -35,7 +35,10 @@ using namespace std;
class SGXInfoServer : public AbstractInfoServer { class SGXInfoServer : public AbstractInfoServer {
recursive_mutex m; recursive_mutex m;
bool autoSign; uint32_t logLevel_;
bool autoSign_;
bool checkCerts_;
bool generateTestKeys_;
static shared_ptr <HttpServer> httpServer; static shared_ptr <HttpServer> httpServer;
...@@ -45,7 +48,8 @@ public: ...@@ -45,7 +48,8 @@ public:
static shared_ptr <SGXInfoServer> getServer(); static shared_ptr <SGXInfoServer> getServer();
SGXInfoServer(AbstractServerConnector &connector, serverVersion_t type); SGXInfoServer(AbstractServerConnector &connector, serverVersion_t type,
uint32_t _logLevel, bool _autoSign, bool _checkCerts, bool _generateTestKeys);
virtual Json::Value getAllKeysInfo(); virtual Json::Value getAllKeysInfo();
...@@ -55,7 +59,7 @@ public: ...@@ -55,7 +59,7 @@ public:
virtual Json::Value isKeyExist(const string& key); virtual Json::Value isKeyExist(const string& key);
static int initInfoServer(); static int initInfoServer(uint32_t _logLevel, bool _autoSign, bool _checkCerts, bool _generateTestKeys);
}; };
......
...@@ -163,7 +163,7 @@ uint64_t initEnclave() { ...@@ -163,7 +163,7 @@ uint64_t initEnclave() {
void initAll(uint32_t _logLevel, bool _checkCert, bool _autoSign) { void initAll(uint32_t _logLevel, bool _checkCert, bool _autoSign, bool _generateTestKeys) {
static atomic<bool> sgxServerInited(false); static atomic<bool> sgxServerInited(false);
static mutex initMutex; static mutex initMutex;
...@@ -203,7 +203,7 @@ void initAll(uint32_t _logLevel, bool _checkCert, bool _autoSign) { ...@@ -203,7 +203,7 @@ void initAll(uint32_t _logLevel, bool _checkCert, bool _autoSign) {
} else { } else {
SGXWalletServer::initHttpServer(); SGXWalletServer::initHttpServer();
} }
SGXInfoServer::initInfoServer(); SGXInfoServer::initInfoServer(_logLevel, _checkCert, _autoSign, _generateTestKeys);
sgxServerInited = true; sgxServerInited = true;
} catch (SGXException &_e) { } catch (SGXException &_e) {
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#define EXTERNC #define EXTERNC
#endif #endif
EXTERNC void initAll(uint32_t _logLevel, bool _checkCert, bool _autoSign); EXTERNC void initAll(uint32_t _logLevel, bool _checkCert, bool _autoSign, bool _generateTestKeys);
EXTERNC void initUserSpace(); EXTERNC void initUserSpace();
......
...@@ -29,19 +29,19 @@ ...@@ -29,19 +29,19 @@
#include <unistd.h> #include <unistd.h>
int print_hashes(){ int print_hashes(){
jsonrpc::HttpClient client("http://localhost:1028"); jsonrpc::HttpClient client("http://localhost:1028");
StubClient c(client, jsonrpc::JSONRPC_CLIENT_V2); StubClient c(client, jsonrpc::JSONRPC_CLIENT_V2);
std::cout << "Client inited" << std::endl; std::cout << "Client inited" << std::endl;
std::cout << c.getUnsignedCSRs() << std::endl; std::cout << c.getUnsignedCSRs() << std::endl;
exit(0); exit(0);
} }
void sign_by_hash(std::string & hash, int status){ void sign_by_hash(std::string & hash, int status){
jsonrpc::HttpClient client("http://localhost:1028"); jsonrpc::HttpClient client("http://localhost:1028");
StubClient c(client, jsonrpc::JSONRPC_CLIENT_V2); StubClient c(client, jsonrpc::JSONRPC_CLIENT_V2);
std::cout << "Client inited" << std::endl; std::cout << "Client inited" << std::endl;
std::cout << c.signByHash(hash, status) << std::endl; std::cout << c.signByHash(hash, status) << std::endl;
exit(0); exit(0);
} }
void getAllKeysInfo() { void getAllKeysInfo() {
...@@ -67,7 +67,13 @@ void getServerConfiguration() { ...@@ -67,7 +67,13 @@ void getServerConfiguration() {
StubClient c(client, jsonrpc::JSONRPC_CLIENT_V2); StubClient c(client, jsonrpc::JSONRPC_CLIENT_V2);
std::cout << "Info client inited" << std::endl; std::cout << "Info client inited" << std::endl;
Json::Value response = c.getServerConfiguration(); Json::Value response = c.getServerConfiguration();
std::cout << "OPTION autoConfitm certificates switched to " << response["autoConfitm"] << '\n';
std::cout << "OPTION logLevel switched to " << response["logLevel"] << '\n';
std::cout << "OPTION enterBackupKey switched to " << response["enterBackupKey"] << '\n';
std::cout << "OPTION useHTTPS switched to " << response["useHTTPS"] << '\n';
std::cout << "OPTION autoSign certificates switched to " << response["autoSign"] << '\n';
std::cout << "OPTION checkCerts switched to " << response["checkCerts"] << '\n';
std::cout << "OPTION generateTestKeys switched to " << response["generateTestKeys"] << '\n';
exit(0); exit(0);
} }
...@@ -103,7 +109,7 @@ int main(int argc, char *argv[]) { ...@@ -103,7 +109,7 @@ int main(int argc, char *argv[]) {
exit(0); exit(0);
} }
std::string hash; std::string hash;
while ((opt = getopt(argc, argv, "ps:r:")) != -1) { while ((opt = getopt(argc, argv, "ps:r:alci:")) != -1) {
switch (opt) { switch (opt) {
case 'p': print_hashes(); case 'p': print_hashes();
break; break;
......
...@@ -171,7 +171,7 @@ int main(int argc, char *argv[]) { ...@@ -171,7 +171,7 @@ int main(int argc, char *argv[]) {
enclaveLogLevel = L_TRACE; enclaveLogLevel = L_TRACE;
} }
initAll(enclaveLogLevel, checkClientCertOption, autoSignClientCertOption); initAll(enclaveLogLevel, checkClientCertOption, autoSignClientCertOption, generateTestKeys);
ifstream is("sgx_data/4node.json"); ifstream is("sgx_data/4node.json");
......
...@@ -72,7 +72,7 @@ public: ...@@ -72,7 +72,7 @@ public:
TestFixture() { TestFixture() {
TestUtils::resetDB(); TestUtils::resetDB();
setOptions(L_INFO, false, true); setOptions(L_INFO, false, true);
initAll(L_INFO, false, true); initAll(L_INFO, false, true, false);
} }
~TestFixture() { ~TestFixture() {
...@@ -85,7 +85,7 @@ public: ...@@ -85,7 +85,7 @@ public:
TestFixtureHTTPS() { TestFixtureHTTPS() {
TestUtils::resetDB(); TestUtils::resetDB();
setOptions(L_INFO, true, true); setOptions(L_INFO, true, true);
initAll(L_INFO, false, true); initAll(L_INFO, false, true, false);
} }
~TestFixtureHTTPS() { ~TestFixtureHTTPS() {
...@@ -97,7 +97,7 @@ class TestFixtureNoResetFromBackup { ...@@ -97,7 +97,7 @@ class TestFixtureNoResetFromBackup {
public: public:
TestFixtureNoResetFromBackup() { TestFixtureNoResetFromBackup() {
setFullOptions(L_INFO, false, true, true); setFullOptions(L_INFO, false, true, true);
initAll(L_INFO, false, true); initAll(L_INFO, false, true, false);
} }
~TestFixtureNoResetFromBackup() { ~TestFixtureNoResetFromBackup() {
...@@ -110,7 +110,7 @@ class TestFixtureNoReset { ...@@ -110,7 +110,7 @@ class TestFixtureNoReset {
public: public:
TestFixtureNoReset() { TestFixtureNoReset() {
setOptions(L_INFO, false, true); setOptions(L_INFO, false, true);
initAll(L_INFO, false, true); initAll(L_INFO, false, true, false);
} }
~TestFixtureNoReset() { ~TestFixtureNoReset() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment