Unverified Commit cff22509 authored by kladko's avatar kladko

SKALE-2341 Added tags for older commits

parent 1fa379be
...@@ -273,12 +273,17 @@ bool LevelDB::isInited = false; ...@@ -273,12 +273,17 @@ bool LevelDB::isInited = false;
void LevelDB::initDataFolderAndDBs() { void LevelDB::initDataFolderAndDBs() {
if (isInited) CHECK_STATE(!isInited)
return; isInited = true;
spdlog::info("Initing wallet database ... ");
char cwd[PATH_MAX]; char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) == NULL) { if (getcwd(cwd, sizeof(cwd)) == NULL) {
spdlog::error("could not get cwd"); spdlog::error("could not get current workin directory");
exit(-1); exit(-1);
} }
...@@ -286,17 +291,20 @@ void LevelDB::initDataFolderAndDBs() { ...@@ -286,17 +291,20 @@ void LevelDB::initDataFolderAndDBs() {
struct stat info; struct stat info;
if (stat(sgx_data_folder.c_str(), &info) !=0 ){ if (stat(sgx_data_folder.c_str(), &info) !=0 ){
spdlog::info("going to create sgx_data folder"); spdlog::info("sgx_data folder does not exist. Creating ...");
std::string make_sgx_data_folder = "mkdir " + sgx_data_folder;
if (system(make_sgx_data_folder.c_str()) == 0){ if (system(("mkdir " + sgx_data_folder).c_str()) == 0){
spdlog::info("sgx_data folder was created"); spdlog::info("Successfully created sgx_data folder");
} }
else{ else{
spdlog::error("creating sgx_data folder failed"); spdlog::error("Couldnt create creating sgx_data folder");
exit(-1); exit(-1);
} }
} }
spdlog::info("Opening wallet databases");
auto dbName = sgx_data_folder + WALLETDB_NAME; auto dbName = sgx_data_folder + WALLETDB_NAME;
levelDb = make_shared<LevelDB>(dbName); levelDb = make_shared<LevelDB>(dbName);
...@@ -306,6 +314,8 @@ void LevelDB::initDataFolderAndDBs() { ...@@ -306,6 +314,8 @@ void LevelDB::initDataFolderAndDBs() {
auto csr_status_dbname = sgx_data_folder + "CSR_STATUS_DB"; auto csr_status_dbname = sgx_data_folder + "CSR_STATUS_DB";
csrStatusDb = make_shared<LevelDB>(csr_status_dbname); csrStatusDb = make_shared<LevelDB>(csr_status_dbname);
spdlog::info("Successfully opened databases");
} }
const string &LevelDB::getSgxDataFolder() { const string &LevelDB::getSgxDataFolder() {
......
...@@ -22,64 +22,46 @@ ...@@ -22,64 +22,46 @@
*/ */
#include <memory> #include <memory>
#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "libff/algebra/curves/alt_bn128/alt_bn128_init.hpp" #include "libff/algebra/curves/alt_bn128/alt_bn128_init.hpp"
#include "bls.h" #include "bls.h"
#include "leveldb/db.h" #include "leveldb/db.h"
#include <jsonrpccpp/server/connectors/httpserver.h> #include <jsonrpccpp/server/connectors/httpserver.h>
#include "BLSPrivateKeyShareSGX.h"
#include "spdlog/spdlog.h"
#include <gmp.h>
#include <sgx_urts.h>
#include "BLSPrivateKeyShareSGX.h"
#include "sgxwallet_common.h" #include "sgxwallet_common.h"
#include "create_enclave.h" #include "create_enclave.h"
#include "secure_enclave_u.h" #include "secure_enclave_u.h"
#include "sgx_detect.h" #include "sgx_detect.h"
#include <gmp.h>
#include <sgx_urts.h>
#include "sgxwallet.h" #include "sgxwallet.h"
#include "LevelDB.h" #include "LevelDB.h"
#include "SGXWalletServer.h" #include "SGXWalletServer.h"
#include "SGXRegistrationServer.h" #include "SGXRegistrationServer.h"
#include "SEKManager.h"
#include "CSRManagerServer.h" #include "CSRManagerServer.h"
#include "BLSCrypto.h" #include "BLSCrypto.h"
#include "ServerInit.h" #include "ServerInit.h"
#include <iostream>
#include "spdlog/spdlog.h"
#include <unistd.h>
#include <stdio.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "SGXWalletServer.hpp" #include "SGXWalletServer.hpp"
#include "SGXWALLET_VERSION" #include "SGXWALLET_VERSION"
//#include <system> void initUserSpace() {
void initDaemon() {
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
LevelDB::initDataFolderAndDBs(); LevelDB::initDataFolderAndDBs();
} }
void initEnclave() { void initEnclave() {
eid = 0; eid = 0;
...@@ -95,8 +77,8 @@ void initEnclave() { ...@@ -95,8 +77,8 @@ void initEnclave() {
} }
#endif #endif
if ( printDebugInfo) { if (printDebugInfo) {
spdlog::info("SGX_DEBUG_FLAG = {}", SGX_DEBUG_FLAG); spdlog::info("SGX_DEBUG_FLAG = {}", SGX_DEBUG_FLAG);
} }
status = sgx_create_enclave_search(ENCLAVE_NAME, SGX_DEBUG_FLAG, &token, status = sgx_create_enclave_search(ENCLAVE_NAME, SGX_DEBUG_FLAG, &token,
...@@ -113,8 +95,7 @@ void initEnclave() { ...@@ -113,8 +95,7 @@ void initEnclave() {
exit(1); exit(1);
} }
//fprintf(stderr, "Enclave launched\n"); spdlog::error("Enclave created and started successfully");
spdlog::error( "Enclave created and started successfully");
status = tgmp_init(eid); status = tgmp_init(eid);
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
...@@ -129,29 +110,20 @@ void initEnclave() { ...@@ -129,29 +110,20 @@ void initEnclave() {
int sgxServerInited = 0; int sgxServerInited = 0;
void initAll(bool _checkCert, bool _autoSign, void (*SEK_func)()) { void initAll(bool _checkCert, bool _autoSign) {
cout << "Running sgxwallet version:" << SGXWALLET_VERSION << endl; cout << "Running sgxwallet version:" << SGXWALLET_VERSION << endl;
CHECK_STATE(sgxServerInited == 0)
//spdlog::set_pattern("%c");
if (sgxServerInited == 1)
return;
initEnclave();
initDaemon();
//init_SEK();
SEK_func();
sgxServerInited = 1; sgxServerInited = 1;
initEnclave();
initUserSpace();
init_SEK();
if (useHTTPS) { if (useHTTPS) {
SGXWalletServer::initHttpsServer(_checkCert); SGXWalletServer::initHttpsServer(_checkCert);
initRegistrationServer(_autoSign); initRegistrationServer(_autoSign);
init_csrmanager_server(); init_csrmanager_server();
} } else {
else {
SGXWalletServer::initHttpServer(); SGXWalletServer::initHttpServer();
} }
//std::cerr << "enclave inited" << std::endl;
} }
...@@ -30,9 +30,9 @@ ...@@ -30,9 +30,9 @@
#define EXTERNC #define EXTERNC
#endif #endif
EXTERNC void initAll(bool _checkCert, bool _autoSign, void (*func)()); EXTERNC void initAll(bool _checkCert, bool _autoSign);
EXTERNC void initDaemon(); EXTERNC void initUserSpace();
EXTERNC void initEnclave(); EXTERNC void initEnclave();
......
...@@ -73,8 +73,6 @@ int main(int argc, char *argv[]) { ...@@ -73,8 +73,6 @@ int main(int argc, char *argv[]) {
bool checkClientCertOption = true; bool checkClientCertOption = true;
bool autoSignClientCertOption = false; bool autoSignClientCertOption = false;
void (*SEK_initializer)();
SEK_initializer = init_SEK;
int opt; int opt;
if (argc > 1 && strlen(argv[1]) == 1) { if (argc > 1 && strlen(argv[1]) == 1) {
...@@ -112,7 +110,7 @@ int main(int argc, char *argv[]) { ...@@ -112,7 +110,7 @@ int main(int argc, char *argv[]) {
encryptKeysOption = false; encryptKeysOption = false;
break; break;
case 'b': case 'b':
SEK_initializer = enter_SEK; encryptKeysOption = false;
break; break;
case 'y': case 'y':
autoconfirmOption = true; autoconfirmOption = true;
...@@ -127,7 +125,7 @@ int main(int argc, char *argv[]) { ...@@ -127,7 +125,7 @@ int main(int argc, char *argv[]) {
setFullOptions(printDebugInfoOption, useHTTPSOption, autoconfirmOption, encryptKeysOption); setFullOptions(printDebugInfoOption, useHTTPSOption, autoconfirmOption, encryptKeysOption);
initAll(checkClientCertOption, autoSignClientCertOption, SEK_initializer); initAll(checkClientCertOption, autoSignClientCertOption);
while (true) { while (true) {
sleep(10); sleep(10);
......
...@@ -124,18 +124,18 @@ char *encryptTestKey() { ...@@ -124,18 +124,18 @@ char *encryptTestKey() {
TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") { TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
auto key = encryptTestKey(); auto key = encryptTestKey();
REQUIRE(key != nullptr); REQUIRE(key != nullptr);
free(key); free(key);
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
} }
/* Do later
TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") { TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
//init_enclave(); //init_enclave();
...@@ -160,6 +160,8 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") { ...@@ -160,6 +160,8 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
} }
*/
void destroyEnclave() { void destroyEnclave() {
if (eid != 0) { if (eid != 0) {
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
...@@ -171,7 +173,7 @@ void destroyEnclave() { ...@@ -171,7 +173,7 @@ void destroyEnclave() {
TEST_CASE("DKG gen test", "[dkg-gen]") { TEST_CASE("DKG gen test", "[dkg-gen]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
vector<uint8_t> encrypted_dkg_secret(DKG_MAX_SEALED_LEN, 0); vector<uint8_t> encrypted_dkg_secret(DKG_MAX_SEALED_LEN, 0);
...@@ -260,7 +262,7 @@ libff::alt_bn128_G2 VectStringToG2(const vector<string> &G2_str_vect) { ...@@ -260,7 +262,7 @@ libff::alt_bn128_G2 VectStringToG2(const vector<string> &G2_str_vect) {
TEST_CASE("DKG public shares test", "[dkg-pub_shares]") { TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
...@@ -334,7 +336,7 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") { ...@@ -334,7 +336,7 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
TEST_CASE("DKG encrypted secret shares test", "[dkg-encr_sshares]") { TEST_CASE("DKG encrypted secret shares test", "[dkg-encr_sshares]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
vector<char> errMsg(1024, 1); vector<char> errMsg(1024, 1);
...@@ -371,7 +373,7 @@ TEST_CASE("DKG encrypted secret shares test", "[dkg-encr_sshares]") { ...@@ -371,7 +373,7 @@ TEST_CASE("DKG encrypted secret shares test", "[dkg-encr_sshares]") {
TEST_CASE("DKG verification test", "[dkg-verify]") { TEST_CASE("DKG verification test", "[dkg-verify]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
...@@ -412,7 +414,7 @@ TEST_CASE("DKG verification test", "[dkg-verify]") { ...@@ -412,7 +414,7 @@ TEST_CASE("DKG verification test", "[dkg-verify]") {
TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") { TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
...@@ -456,7 +458,7 @@ TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") { ...@@ -456,7 +458,7 @@ TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") {
TEST_CASE("Test test", "[test_test]") { TEST_CASE("Test test", "[test_test]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
int err_status = 0; int err_status = 0;
...@@ -478,7 +480,7 @@ TEST_CASE("Test test", "[test_test]") { ...@@ -478,7 +480,7 @@ TEST_CASE("Test test", "[test_test]") {
TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") { TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
int err_status = 0; int err_status = 0;
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
...@@ -553,7 +555,7 @@ string ConvertDecToHex(string dec, int numBytes = 32) { ...@@ -553,7 +555,7 @@ string ConvertDecToHex(string dec, int numBytes = 32) {
TEST_CASE("BLS_DKG test", "[bls_dkg]") { TEST_CASE("BLS_DKG test", "[bls_dkg]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
...@@ -683,7 +685,7 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") { ...@@ -683,7 +685,7 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
TEST_CASE("API test", "[api_test]") { TEST_CASE("API test", "[api_test]") {
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
//HttpServer httpserver(1025); //HttpServer httpserver(1025);
//SGXWalletServer s(httpserver, //SGXWalletServer s(httpserver,
...@@ -788,7 +790,7 @@ TEST_CASE("API test", "[api_test]") { ...@@ -788,7 +790,7 @@ TEST_CASE("API test", "[api_test]") {
TEST_CASE("getServerStatus test", "[getServerStatus_test]") { TEST_CASE("getServerStatus test", "[getServerStatus_test]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
REQUIRE(c.getServerStatus()["status"] == 0); REQUIRE(c.getServerStatus()["status"] == 0);
...@@ -910,7 +912,7 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") { ...@@ -910,7 +912,7 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
vector<thread> threads; vector<thread> threads;
int num_threads = 4; int num_threads = 4;
...@@ -928,7 +930,7 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") { ...@@ -928,7 +930,7 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
TEST_CASE("ecdsa API test", "[ecdsa_api_test]") { TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
...@@ -976,7 +978,7 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") { ...@@ -976,7 +978,7 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
TEST_CASE("dkg API test", "[dkg_api_test]") { TEST_CASE("dkg API test", "[dkg_api_test]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
...@@ -1048,7 +1050,7 @@ TEST_CASE("dkg API test", "[dkg_api_test]") { ...@@ -1048,7 +1050,7 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
TEST_CASE("isPolyExists test", "[is_poly_test]") { TEST_CASE("isPolyExists test", "[is_poly_test]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
...@@ -1076,7 +1078,7 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") { ...@@ -1076,7 +1078,7 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
setOptions(true, false, true); setOptions(true, false, true);
cerr << "test started" << endl; cerr << "test started" << endl;
initAll(false, true, init_SEK); initAll(false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
cerr << "Client inited" << endl; cerr << "Client inited" << endl;
...@@ -1201,7 +1203,7 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") { ...@@ -1201,7 +1203,7 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
TEST_CASE("bls_sign_api test", "[bls_sign]") { TEST_CASE("bls_sign_api test", "[bls_sign]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
...@@ -1233,7 +1235,7 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") { ...@@ -1233,7 +1235,7 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") { TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") {
resetDB(); resetDB();
setOptions(true, false, true); setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true);
int errStatus = -1; int errStatus = -1;
......
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