Unverified Commit 3255c3e4 authored by Oleh Nikolaiev's avatar Oleh Nikolaiev Committed by GitHub

Merge pull request #290 from skalenetwork/bug/SKALE-4005-graceful-exit

Bug/skale 4005 graceful exit
parents df089ab5 c433c730
......@@ -110,7 +110,7 @@ Json::Value CSRManagerServer::signByHash(const string &hash, int status) {
return signByHashImpl(hash, status);
}
int CSRManagerServer::initCSRManagerServer() {
void CSRManagerServer::initCSRManagerServer() {
hs3 = make_shared<jsonrpc::HttpServer>(BASE_PORT + 2);
hs3->BindLocalhost();
cs = make_shared<CSRManagerServer>(*hs3, JSONRPC_SERVER_V2); // server (json-rpc 2.0)
......@@ -119,9 +119,20 @@ int CSRManagerServer::initCSRManagerServer() {
if (!cs->StartListening()) {
spdlog::info("CSR manager server could not start listening");
exit(-1);
throw SGXException(CSR_MANAGER_SERVER_FAILED_TO_START, "CSRManager server could not start listening.");
} else {
spdlog::info("CSR manager server started on port {}", BASE_PORT + 2);
}
return 0;
};
int CSRManagerServer::exitServer() {
spdlog::info("Stoping CSRManager server");
if (cs && !cs->StopListening()) {
spdlog::error("CSRManager server could not be stopped. Will forcefully terminate the app");
} else {
spdlog::info("CSRManager server stopped");
}
return 0;
}
......@@ -49,7 +49,9 @@ class CSRManagerServer : public abstractCSRManagerServer {
virtual Json::Value getUnsignedCSRs();
virtual Json::Value signByHash(const string& hash, int status);
static int initCSRManagerServer();
static void initCSRManagerServer();
static int exitServer();
};
......
#include <chrono>
#include <thread>
#include "ExitHandler.h"
void ExitHandler::exitHandler( int s ) {
exitHandler( s, ec_success );
}
void ExitHandler::exitHandler( int s, ExitHandler::exit_code_t ec ) {
m_signal = s;
if ( ec != ec_success ) {
g_ec = ec;
}
s_shouldExit = true;
}
volatile bool ExitHandler::s_shouldExit = false;
volatile int ExitHandler::m_signal = -1;
volatile ExitHandler::exit_code_t ExitHandler::g_ec = ExitHandler::ec_success;
#ifndef EXITHANDLER_H
#define EXITHANDLER_H
#include <signal.h>
class ExitHandler {
public:
enum exit_code_t {
ec_success = 0,
ec_initing_user_space = 202, // error or exception while initializing user space
};
private:
static volatile bool s_shouldExit;
static volatile int m_signal;
static volatile exit_code_t g_ec;
ExitHandler() = delete;
public:
static void exitHandler( int s );
static void exitHandler( int s, ExitHandler::exit_code_t ec );
static bool shouldExit() { return s_shouldExit; }
static int getSignal() { return m_signal; }
static exit_code_t requestedExitCode() { return g_ec; }
};
#endif // EXITHANDLER_H
......@@ -274,8 +274,8 @@ void LevelDB::initDataFolderAndDBs() {
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) == NULL) {
spdlog::error("could not get current workin directory");
exit(-2);
spdlog::error("Could not get current working directory.");
throw SGXException(COULD_NOT_GET_WORKING_DIRECTORY, "Could not get current working directory.");
}
sgx_data_folder = string(cwd) + "/" + SGXDATA_FOLDER;
......@@ -288,8 +288,8 @@ void LevelDB::initDataFolderAndDBs() {
spdlog::info("Successfully created sgx_data folder");
}
else{
spdlog::error("Couldnt create creating sgx_data folder");
exit(-3);
spdlog::error("Could not create sgx_data folder.");
throw SGXException(ERROR_CREATING_SGX_DATA_FOLDER, "Could not create sgx_data folder.");
}
}
......
......@@ -70,7 +70,7 @@ bin_PROGRAMS = sgxwallet testw sgx_util
## have to be explicitly listed
COMMON_SRC = SGXException.cpp ZMQClient.cpp BLSSignRspMessage.cpp ECDSASignRspMessage.cpp ECDSASignReqMessage.cpp BLSSignReqMessage.cpp ZMQMessage.cpp ZMQServer.cpp ServerWorker.cpp InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp \
COMMON_SRC = SGXException.cpp ExitHandler.cpp ZMQClient.cpp BLSSignRspMessage.cpp ECDSASignRspMessage.cpp ECDSASignReqMessage.cpp BLSSignReqMessage.cpp ZMQMessage.cpp ZMQServer.cpp ServerWorker.cpp InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp \
SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp BLSCrypto.cpp \
DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp \
third_party/intel/sgx_stub.c third_party/intel/sgx_detect_linux.c third_party/intel/create_enclave.c third_party/intel/oc_alloc.c \
......@@ -116,12 +116,12 @@ nodist_testw_SOURCES=${nodist_sgxwallet_SOURCES}
EXTRA_testw_DEPENDENCIES=${EXTRA_sgxwallet_DEPENDENCIES}
testw_LDADD= ${sgxwallet_LDADD}
sgx_util_SOURCES= SGXException.cpp InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp sgx_util.cpp stubclient.cpp LevelDB.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp
sgx_util_SOURCES= SGXException.cpp ExitHandler.cpp InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp sgx_util.cpp stubclient.cpp LevelDB.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp
sgx_util_LDADD=-LlibBLS/deps/deps_inst/x86_or_x64/lib -Lleveldb/build -LlibBLS/build \
-LlibBLS/build/libff/libff \
-Llibzmq/build/lib/ \
-l:libzmq.a \
-l:libbls.a -l:libleveldb.a \
-l:libff.a -lgmp -ljsonrpccpp-stub -ljsonrpccpp-server -ljsonrpccpp-client -ljsonrpccpp-common -ljsoncpp -lmicrohttpd -lgnutls -lgcrypt -lidn2 -lcurl -lssl -lcrypto -lz -lpthread -ldl
-l:libff.a -lgmp -ljsonrpccpp-stub -ljsonrpccpp-server -ljsonrpccpp-client -ljsonrpccpp-common -ljsoncpp -lmicrohttpd -lgnutls -lgcrypt -lidn2 -lcurl -lssl -lcrypto -lz -lpthread -ldl
......@@ -90,7 +90,7 @@ void validate_SEK() {
if (!hex2carray(test_key_ptr->c_str(), &len, encr_test_key.data(),
BUF_LEN)) {
spdlog::error("Corrupt test key is LevelDB");
exit(-4);
throw SGXException(CORRUPT_DATABASE, "Corrupt test key is LevelDB");
}
sgx_status_t status = SGX_SUCCESS;
......@@ -108,7 +108,7 @@ void validate_SEK() {
spdlog::error("Invalid storage key. You need to recover using backup key");
spdlog::error("Set the correct backup key into sgx_datasgxwallet_backup_key.txt");
spdlog::error("Then run sgxwallet using backup flag");
exit(-5);
throw SGXException(INVALID_SEK, "Invalid storage key. Recover using backup key");
}
}
......@@ -181,6 +181,7 @@ void gen_SEK() {
if (!autoconfirm) {
sleep(10);
string confirm_str = "I confirm";
string buffer;
do {
......@@ -201,21 +202,6 @@ void gen_SEK() {
setSEK(encrypted_SEK_ptr);
validate_SEK();
}
static std::atomic<int> isSgxWalletExiting(0);
void safeExit() {
// this is to make sure exit is only called once if called from multiple threads
auto previousValue = isSgxWalletExiting.exchange(1);
if (previousValue != 1)
exit(-6);
}
void setSEK(shared_ptr <string> hex_encrypted_SEK) {
......@@ -241,10 +227,7 @@ void setSEK(shared_ptr <string> hex_encrypted_SEK) {
HANDLE_TRUSTED_FUNCTION_ERROR(status, err_status, errMsg.data());
validate_SEK();
}
#include "experimental/filesystem"
......@@ -256,13 +239,13 @@ void enter_SEK() {
shared_ptr <string> test_key_ptr = LevelDB::getLevelDb()->readString("TEST_KEY");
if (test_key_ptr == nullptr) {
spdlog::error("Error: corrupt or empty LevelDB database");
exit(-7);
throw SGXException(CORRUPT_DATABASE, "Could not find TEST_KEY in database.");
}
if (!experimental::filesystem::is_regular_file(BACKUP_PATH)) {
spdlog::error("File does not exist: " BACKUP_PATH);
exit(-8);
spdlog::error("File does not exist: " BACKUP_PATH);
throw SGXException(FILE_NOT_FOUND, "File does not exist: " BACKUP_PATH);
}
ifstream sek_file(BACKUP_PATH);
......@@ -278,7 +261,7 @@ void enter_SEK() {
while (!checkHex(sek, 16)) {
spdlog::error("Invalid hex in key");
exit(-9);
throw SGXException(SET_SEK_INVALID_SEK_HEX, "Invalid hex in key");
}
auto encrypted_SEK = check_and_set_SEK(sek);
......@@ -298,10 +281,10 @@ void enter_SEK() {
}
void initSEK() {
shared_ptr <string> encrypted_SEK_ptr = LevelDB::getLevelDb()->readString("SEK");
if (enterBackupKey) {
enter_SEK();
} else {
shared_ptr <string> encrypted_SEK_ptr = LevelDB::getLevelDb()->readString("SEK");
if (encrypted_SEK_ptr == nullptr) {
spdlog::warn("SEK was not created yet. Going to create SEK");
gen_SEK();
......
......@@ -47,8 +47,6 @@ EXTERNC void initSEK();
EXTERNC void setSEK();
EXTERNC void safeExit();
......
......@@ -107,7 +107,7 @@ Json::Value SGXInfoServer::isKeyExist(const string& key) {
RETURN_SUCCESS(result)
}
int SGXInfoServer::initInfoServer(uint32_t _logLevel, bool _autoSign, bool _checkCerts, bool _generateTestKeys) {
void SGXInfoServer::initInfoServer(uint32_t _logLevel, bool _autoSign, bool _checkCerts, bool _generateTestKeys) {
httpServer = make_shared<HttpServer>(BASE_PORT + 4);
server = make_shared<SGXInfoServer>(*httpServer, JSONRPC_SERVER_V2, _logLevel, _autoSign, _checkCerts, _generateTestKeys); // hybrid server (json-rpc 1.0 & 2.0)
......@@ -115,12 +115,22 @@ int SGXInfoServer::initInfoServer(uint32_t _logLevel, bool _autoSign, bool _chec
if (!server->StartListening()) {
spdlog::error("Info server could not start listening on port {}", BASE_PORT + 4);
exit(-10);
throw SGXException(SGX_INFO_SERVER_FAILED_TO_START, "Info server could not start listening.");
} else {
spdlog::info("Info server started on port {}", BASE_PORT + 4);
}
}
int SGXInfoServer::exitServer() {
spdlog::info("Stoping SGXInfo server");
if (server && !server->StopListening()) {
spdlog::error("SGXInfo server could not be stopped. Will forcefully terminate the app");
} else {
spdlog::info("SGXInfo server stopped");
}
return 0;
return 0;
}
shared_ptr<SGXInfoServer> SGXInfoServer::getServer() {
......
......@@ -59,7 +59,9 @@ public:
virtual Json::Value isKeyExist(const string& key);
static int initInfoServer(uint32_t _logLevel, bool _autoSign, bool _checkCerts, bool _generateTestKeys);
static void initInfoServer(uint32_t _logLevel, bool _autoSign, bool _checkCerts, bool _generateTestKeys);
static int exitServer();
};
......
......@@ -162,7 +162,7 @@ Json::Value SGXRegistrationServer::GetCertificate(const string &hash) {
}
int SGXRegistrationServer::initRegistrationServer(bool _autoSign) {
void SGXRegistrationServer::initRegistrationServer(bool _autoSign) {
httpServer = make_shared<HttpServer>(BASE_PORT + 1);
server = make_shared<SGXRegistrationServer>(*httpServer,
JSONRPC_SERVER_V2,
......@@ -172,12 +172,22 @@ int SGXRegistrationServer::initRegistrationServer(bool _autoSign) {
if (!server->StartListening()) {
spdlog::error("Registration server could not start listening on port {}", BASE_PORT + 1);
exit(-10);
throw SGXException(REGISTRATION_SERVER_FAILED_TO_START, "Registration server could not start listening.");
} else {
spdlog::info("Registration server started on port {}", BASE_PORT + 1);
}
}
int SGXRegistrationServer::exitServer() {
spdlog::info("Stoping registration server");
if (server && !server->StopListening()) {
spdlog::error("Registration server could not be stopped. Will forcefully terminate the app");
} else {
spdlog::info("Registration server stopped");
}
return 0;
return 0;
}
......
......@@ -60,9 +60,10 @@ public:
virtual Json::Value GetCertificate(const string &hash);
static int initRegistrationServer(bool _autoSign = false);
static void initRegistrationServer(bool _autoSign = false);
static int exitServer();
};
#endif // SGXD_SGXREGISTRATIONSERVER_H
\ No newline at end of file
#endif // SGXD_SGXREGISTRATIONSERVER_H
......@@ -21,7 +21,9 @@
@date 2019
*/
#include <chrono>
#include <iostream>
#include <thread>
#include "abstractstubserver.h"
#include <jsonrpccpp/server/connectors/httpserver.h>
......@@ -30,11 +32,9 @@
#include <stdlib.h>
#include <unistd.h>
#include "sgxwallet_common.h"
#include "sgxwallet.h"
#include "SGXException.h"
#include "LevelDB.h"
#include "BLSCrypto.h"
......@@ -139,7 +139,7 @@ void SGXWalletServer::createCertsIfNeeded() {
spdlog::info("ROOT CA CERTIFICATE IS SUCCESSFULLY GENERATED");
} else {
spdlog::error("ROOT CA CERTIFICATE GENERATION FAILED");
exit(-11);
throw SGXException(FAIL_TO_CREATE_CERTIFICATE, "ROOT CA CERTIFICATE GENERATION FAILED");
}
}
......@@ -156,7 +156,7 @@ void SGXWalletServer::createCertsIfNeeded() {
spdlog::info("SERVER CERTIFICATE IS SUCCESSFULLY GENERATED");
} else {
spdlog::info("SERVER CERTIFICATE GENERATION FAILED");
exit(-12);
throw SGXException(FAIL_TO_CREATE_CERTIFICATE, "SERVER CERTIFICATE GENERATION FAILED");
}
}
......@@ -166,20 +166,16 @@ void SGXWalletServer::createCertsIfNeeded() {
spdlog::info("SERVER CERTIFICATE IS SUCCESSFULLY VERIFIED");
} else {
spdlog::info("SERVER CERTIFICATE VERIFICATION FAILED");
exit(-12);
throw SGXException(FAIL_TO_VERIFY_CERTIFICATE, "SERVER CERTIFICATE VERIFICATION FAILED");
}
}
int SGXWalletServer::initHttpsServer(bool _checkCerts) {
void SGXWalletServer::initHttpsServer(bool _checkCerts) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__);
spdlog::info("Initing server, number of threads: {}", NUM_THREADS);
string certPath = string(SGXDATA_FOLDER) + "cert_data/SGXServerCert.crt";
string keyPath = string(SGXDATA_FOLDER) + "cert_data/SGXServerCert.key";
string rootCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.pem";
......@@ -195,14 +191,13 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
if (!server->StartListening()) {
spdlog::error("SGX Server could not start listening");
exit(-13);
throw SGXException(SGX_SERVER_FAILED_TO_START, "Https server could not start listening.");
} else {
spdlog::info("SGX Server started on port {}", BASE_PORT);
}
return 0;
}
int SGXWalletServer::initHttpServer() { //without ssl
void SGXWalletServer::initHttpServer() { //without ssl
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__);
......@@ -214,9 +209,20 @@ int SGXWalletServer::initHttpServer() { //without ssl
JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
if (!server->StartListening()) {
spdlog::error("Server could not start listening");
exit(-14);
throw SGXException(SGX_SERVER_FAILED_TO_START, "Http server could not start listening.");
}
return 0;
}
int SGXWalletServer::exitServer() {
spdlog::info("Stoping sgx server");
if (server && !server->StopListening()) {
spdlog::error("Sgx server could not be stopped. Will forcefully terminate the app");
} else {
spdlog::info("Sgx server stopped");
}
return 0;
}
Json::Value
......
......@@ -39,8 +39,6 @@ using namespace std;
#define TOSTRING(x) STRINGIFY(x)
class SGXWalletServer : public AbstractStubServer {
static shared_ptr<SGXWalletServer> server;
static shared_ptr<HttpServer> httpServer;
......@@ -178,9 +176,11 @@ public:
static void printDB();
static int initHttpServer();
static void initHttpServer();
static void initHttpsServer(bool _checkCerts);
static int initHttpsServer(bool _checkCerts);
static int exitServer();
static void createCertsIfNeeded();
};
......
......@@ -42,6 +42,7 @@
#include <unistd.h>
#include "ExitHandler.h"
#include "BLSPrivateKeyShareSGX.h"
#include "sgxwallet_common.h"
#include "third_party/intel/create_enclave.h"
......@@ -70,7 +71,7 @@ void systemHealthCheck() {
ulimit = exec("/bin/bash -c \"ulimit -n\"");
} catch (...) {
spdlog::error("Execution of '/bin/bash -c ulimit -n' failed");
exit(-15);
throw SGXException(EXECUTION_ULIMIT_FAILED, "Execution of '/bin/bash -c ulimit -n' failed.");
}
int noFiles = strtol(ulimit.c_str(), NULL, 10);
......@@ -84,13 +85,10 @@ void systemHealthCheck() {
"and setting 'DefaultLimitNOFILE=65535'\n"
"After that, restart sgxwallet";
spdlog::error(errStr);
exit(-16);
throw SGXException(WRONG_ULIMIT, errStr);
}
}
void initUserSpace() {
libff::inhibit_profiling_counters = true;
......@@ -103,8 +101,6 @@ void initUserSpace() {
systemHealthCheck();
#endif
}
......@@ -116,7 +112,7 @@ uint64_t initEnclave() {
support = get_sgx_support();
if (!SGX_OK(support)) {
sgx_support_perror(support);
exit(-17);
throw SGXException(COULD_NOT_INIT_ENCLAVE, "SGX is not supported or not enabled");
}
#endif
......@@ -147,7 +143,7 @@ uint64_t initEnclave() {
} else {
spdlog::error("sgx_create_enclave_search failed {} {}", ENCLAVE_NAME, status);
}
exit(-21);
throw SGXException(COULD_NOT_INIT_ENCLAVE, "Error initing enclave. Please re-check your enviroment.");
}
spdlog::info("Enclave created and started successfully");
......@@ -222,15 +218,24 @@ void initAll(uint32_t _logLevel, bool _checkCert,
sgxServerInited = true;
} catch (SGXException &_e) {
spdlog::error(_e.getMessage());
exit(-18);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
} catch (exception &_e) {
spdlog::error(_e.what());
exit(-19);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
}
catch (...) {
exception_ptr p = current_exception();
printf("Exception %s \n", p.__cxa_exception_type()->name());
spdlog::error("Unknown exception");
exit(-22);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
}
};
void exitAll() {
SGXWalletServer::exitServer();
SGXRegistrationServer::exitServer();
CSRManagerServer::exitServer();
SGXInfoServer::exitServer();
ZMQServer::exitZMQServer();
}
......@@ -34,6 +34,8 @@
EXTERNC void initAll(uint32_t _logLevel, bool _checkCert, bool _checkZMQSig, bool _autoSign, bool _generateTestKeys);
void exitAll();
EXTERNC void initUserSpace();
EXTERNC uint64_t initEnclave();
......
......@@ -29,6 +29,7 @@
#include "common.h"
#include "SGXException.h"
#include "ZMQServer.h"
#include "sgxwallet_common.h"
......@@ -71,14 +72,14 @@ void ZMQServer::run() {
auto port = BASE_PORT + 5;
spdlog::info("Starting zmq server on port {} ...", port);
spdlog::info("Starting zmq server on port {} ...", port);
try {
CHECK_STATE(frontend);
frontend->bind("tcp://*:" + to_string(port));
} catch (...) {
spdlog::error("Server task could not bind to port:{}", port);
exit(ZMQ_COULD_NOT_BIND_FRONT_END);
throw SGXException(ZMQ_COULD_NOT_BIND_FRONT_END, "Server task could not bind.");
}
spdlog::info("Bound port ...");
......@@ -88,7 +89,7 @@ void ZMQServer::run() {
backend->bind("inproc://backend");
} catch (exception &e) {
spdlog::error("Could not bind to zmq backend: {}", e.what());
exit(ZMQ_COULD_NOT_BIND_BACK_END);
throw SGXException(ZMQ_COULD_NOT_BIND_BACK_END, "Could not bind to zmq backend.");
}
......@@ -103,7 +104,7 @@ void ZMQServer::run() {
}
} catch (std::exception &e) {
spdlog::error("Could not create zmq server workers:{} ", e.what());
exit(ZMQ_COULD_NOT_CREATE_WORKERS);
throw SGXException(ZMQ_COULD_NOT_CREATE_WORKERS, "Could not create zmq server workers.");
};
......@@ -123,7 +124,7 @@ void ZMQServer::run() {
return;
}
spdlog::info("Error, exiting zmq server ...");
exit(ZMQ_COULD_NOT_CREATE_PROXY);
throw SGXException(ZMQ_COULD_NOT_CREATE_PROXY, "Error, exiting zmq server.");
}
}
......@@ -206,4 +207,4 @@ ZMQServer::~ZMQServer() {
spdlog::info("Deleting ZMQ context");
ctx_ = nullptr;
spdlog::info("Deleted ZMQ context");
}
\ No newline at end of file
}
......@@ -2,7 +2,7 @@ version: '3'
services:
sgxwallet:
image: skalenetwork/sgxwallet_signed:latest
restart: always
restart: unless-stopped
ports:
- "1026:1026"
- "1027:1027"
......@@ -20,7 +20,6 @@ services:
options:
max-size: "10m"
max-file: "4"
restart: unless-stopped
command: -s -y -d
healthcheck:
test: ["CMD", "ls", "/dev/isgx", "/dev/mei0"]
......
......@@ -2,7 +2,7 @@ version: '3'
services:
sgxwallet:
image: skalenetwork/sgxwallet_sim:develop-latest
restart: always
restart: unless-stopped
ports:
- "1026:1026"
- "1027:1027"
......@@ -17,5 +17,4 @@ services:
options:
max-size: "10m"
max-file: "4"
restart: unless-stopped
command: -s -y
......@@ -21,15 +21,17 @@
@date 2020
*/
#include <csignal>
#include <stdbool.h>
#include "ExitHandler.h"
#include "BLSCrypto.h"
#include "ServerInit.h"
#include "SEKManager.h"
#include "SGXWalletServer.h"
#include <fstream>
#include "TestUtils.h"
......@@ -41,11 +43,6 @@
#include "sgxwallet.h"
void SGXWallet::usage() {
cerr << "usage: sgxwallet\n";
exit(-21);
}
void SGXWallet::printUsage() {
cerr << "\nAvailable flags:\n";
cerr << "\nDebug flags:\n\n";
......@@ -88,6 +85,11 @@ void SGXWallet::serializeKeys(const vector<string>& _ecdsaKeyNames, const vector
fs.close();
}
void SGXWallet::signalHandler( int signalNo ) {
spdlog::info("Received exit signal {}.", signalNo);
ExitHandler::exitHandler( signalNo );
}
int main(int argc, char *argv[]) {
bool enterBackupKeyOption = false;
......@@ -99,18 +101,20 @@ int main(int argc, char *argv[]) {
bool autoSignClientCertOption = false;
bool generateTestKeys = false;
std::signal(SIGABRT, SGXWallet::signalHandler);
int opt;
if (argc > 1 && strlen(argv[1]) == 1) {
SGXWallet::printUsage();
exit(-22);
exit(-21);
}
while ((opt = getopt(argc, argv, "cshd0abyvVnT")) != -1) {
switch (opt) {
case 'h':
SGXWallet::printUsage();
exit(-24);
exit(-22);
case 'c':
checkClientCertOption = false;
break;
......@@ -178,7 +182,7 @@ int main(int argc, char *argv[]) {
ifstream is("sgx_data/4node.json");
if (generateTestKeys && !is.good()) {
if (generateTestKeys && !is.good() && !!ExitHandler::shouldExit()) {
cerr << "Generating test keys ..." << endl;
HttpClient client(RPC_ENDPOINT);
......@@ -206,9 +210,14 @@ int main(int argc, char *argv[]) {
while (true) {
while ( !ExitHandler::shouldExit() ) {
sleep(10);
}
return 0;
ExitHandler::exit_code_t exitCode = ExitHandler::requestedExitCode();
int signal = ExitHandler::getSignal();
spdlog::info("Will exit with exit code {}", exitCode);
exitAll();
spdlog::info("Exiting with exit code {} and signal", exitCode, signal);
return exitCode;
}
......@@ -26,7 +26,8 @@ class SGXWallet {
public:
static void usage();
static void signalHandler( int signalNo );
static void printUsage();
static void serializeKeys( const vector<string>& _ecdsaKeyNames,
......
......@@ -172,8 +172,18 @@ extern bool autoconfirm;
#define ZMQ_COULD_NOT_BIND_BACK_END -99
#define ZMQ_COULD_NOT_CREATE_WORKERS -100
#define ZMQ_COULD_NOT_CREATE_PROXY -101
#define REGISTRATION_SERVER_FAILED_TO_START -102
#define CSR_MANAGER_SERVER_FAILED_TO_START -103
#define SGX_INFO_SERVER_FAILED_TO_START -104
#define COULD_NOT_GET_WORKING_DIRECTORY -105
#define ERROR_CREATING_SGX_DATA_FOLDER -106
#define EXECUTION_ULIMIT_FAILED -107
#define WRONG_ULIMIT -108
#define COULD_NOT_INIT_ENCLAVE -109
#define FAIL_TO_VERIFY_CERTIFICATE -110
#define SGX_SERVER_FAILED_TO_START -111
#define CORRUPT_DATABASE -112
#define INVALID_SEK -113
#define SGX_ENCLAVE_ERROR -666
......@@ -181,7 +191,7 @@ extern bool autoconfirm;
#define BASE_PORT 1026
#define WALLETDB_NAME "sgxwallet.db"//"test_sgxwallet.db"
#define WALLETDB_NAME "sgxwallet.db"
#define ENCLAVE_NAME "secure_enclave.signed.so"
#define SGXDATA_FOLDER "sgx_data/"
......
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