Unverified Commit 6e7e4123 authored by Stan Kladko's avatar Stan Kladko Committed by GitHub

Merge pull request #71 from skalenetwork/bug/SKALE-2345-hw-fails

Bug/skale 2345 hw fails
parents fbec7209 1a324a2a
This diff is collapsed.
......@@ -30,12 +30,6 @@
#define EXTERNC
#endif
//EXTERNC void init_all();
//
//EXTERNC void init_daemon();
//
//EXTERNC void init_enclave();
EXTERNC bool bls_sign(const char* encryptedKeyHex, const char* hashHex, size_t t, size_t n,
size_t signerIndex, char* _sig);
......@@ -49,8 +43,4 @@ EXTERNC bool hex2carray2(const char * _hex, uint64_t *_bin_len,
char * encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key);
char *decryptBLSKeyShareFromHex(int *errStatus, char *errMsg, const char *_encryptedKey);
#endif //SGXWALLET_BLSCRYPTO_H
/*
Copyright (C) 2019-Present SKALE Labs
This file is part of sgxwallet.
sgxwallet is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
sgxwallet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file BLSCrypto.hpp
@author Stan Kladko
@date 2019
*/
#ifndef SGXWALLET_BLSCRYPTO_HPP
#define SGXWALLET_BLSCRYPTO_HPP
#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC
#endif
using namespace std;
shared_ptr<string> encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key);
char *decryptBLSKeyShareFromHex(int *errStatus, char *errMsg, const char *_encryptedKey);
#endif //SGXWALLET_BLSCRYPTO_H
......@@ -80,10 +80,8 @@ BLSPrivateKeyShareSGX::BLSPrivateKeyShareSGX(
requiredSigners = _requiredSigners;
totalSigners = _totalSigners;
std::cerr << "ENTER BLSPrivateKeyShareSGX CONSTRUCTOR" << std::endl;
if (requiredSigners > totalSigners) {
throw std::invalid_argument("requiredSigners > totalSigners");
}
......
This diff is collapsed.
......@@ -31,11 +31,11 @@ std::string gen_dkg_poly( int _t);
std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyHex, int t, int n);
std::vector<std::string> SplitString(const char* koefs, const char symbol);
std::vector<std::string> splitString(const char* koefs, const char symbol);
std::string get_secret_shares(const std::string& polyName, const char* encryptedPolyHex, const std::vector<std::string>& publicKeys, int t, int n);
std::string get_secret_shares(const std::string& _polyName, const char* _encryptedPolyHex, const std::vector<std::string>& _publicKeys, int _t, int _n);
bool VerifyShares(const char* publicShares, const char* encr_sshare, const char * encryptedKeyHex, int t, int n, int ind);
bool verifyShares(const char* publicShares, const char* encr_sshare, const char * encryptedKeyHex, int t, int n, int ind);
std::string decrypt_DHKey(const std::string& polyName, int ind);
......
This diff is collapsed.
......@@ -35,11 +35,13 @@
#define EXTERNC
#endif*/
std::vector<std::string> gen_ecdsa_key();
using namespace std;
std::string get_ecdsa_pubkey(const char* encryptedKeyHex);
vector<string> genECDSAKey();
std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char* hashHex, int base);
string getECDSAPubKey(const char* _encryptedKeyHex);
vector<string> ecdsaSignHash(const char* encryptedKeyHex, const char* hashHex, int base);
#endif //SGXD_ECDSACRYPTO_H
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file Exception.cpp
@author Stan Kladko
@date 2018
*/
#include "Log.h"
#include "Exception.h"
void Exception::logNested(const std::exception &e, int level)
{
string prefix;
if (level == 0) {
prefix = "!Exception:";
} else {
prefix = "!Caused by:";
}
if (dynamic_cast<const std::nested_exception*>(&e) == nullptr) {
LOG(err, string(level, ' ') + prefix + e.what());
return;
} else {
LOG(err, string(level, ' ') + prefix + e.what());
}
try {
std::rethrow_if_nested(e);
} catch(const std::exception& e) {
logNested(e, level + 1);
} catch(...) {}
};
\ No newline at end of file
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file Exception.h
@author Stan Kladko
@date 2018
*/
#pragma once
class Exception : public std::exception {
public:
Exception( const std::string& _message, const std::string& _className ) {
message = _className + ":" + _message;
}
const char* what() const noexcept override {
return message.empty() ? std::exception::what() : message.c_str();
}
const std::string& getMessage() const { return message; }
bool isFatal() const { return fatal; }
private:
std::string message;
protected:
bool fatal = false;
public:
static void logNested( const std::exception& e, int level = 0 );
};
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file InvalidArgumentException.cpp
@author Stan Kladko
@date 2018
*/
#include "Log.h"
#include "InvalidArgumentException.h"
InvalidArgumentException::InvalidArgumentException(const std::string &_message, const string& _className) :
Exception(_message, _className) {
fatal = false;
}
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file InvalidArgumentException.h
@author Stan Kladko
@date 2018
*/
#pragma once
#include "Exception.h"
#include <string>
class InvalidArgumentException : public Exception {
public:
InvalidArgumentException( const std::string& _message, const std::string& _className );
};
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file InvalidStateException.cpp
@author Stan Kladko
@date 2018
*/
#include "common.h"
#include "Log.h"
#include "InvalidStateException.h"
InvalidStateException::InvalidStateException(const std::string &_message, const string& _className) :
Exception(_message, _className) {
fatal = false;
}
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file InvalidStateException.h
@author Stan Kladko
@date 2018
*/
#pragma once
#include "Exception.h"
class InvalidStateException : public Exception {
public:
InvalidStateException( const std::string& _message, const std::string& _className );
};
......@@ -62,10 +62,10 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) {
auto status = db->Get(readOptions, _key, &*result);
if (printDebugInfo) {
spdlog::info("key to read from db: {}",_key );
spdlog::debug("key to read from db: {}",_key );
//std::cerr << "key to read from db: " << _key << std::endl;
}
throwExceptionOnError(status);
......@@ -83,10 +83,10 @@ void LevelDB::writeString(const string &_key, const string &_value) {
throwExceptionOnError(status);
if (printDebugInfo) {
spdlog::info("written key: {}",_key );
spdlog::debug("written key: {}",_key );
// std::cerr << "written key " << _key << std::endl;
}
}
......@@ -100,10 +100,9 @@ void LevelDB::deleteDHDKGKey (const string &_key) {
throwExceptionOnError(status);
if (printDebugInfo) {
spdlog::info("key deleted: {}",full_key );
spdlog::debug("key deleted: {}",full_key );
//std::cerr << "key deleted " << full_key << std::endl;
}
}
void LevelDB::deleteTempNEK(const string &_key){
......@@ -130,10 +129,9 @@ void LevelDB::deleteKey(const string &_key){
throwExceptionOnError(status);
if (printDebugInfo) {
spdlog::info("key deleted: {}",_key );
spdlog::debug("key deleted: {}",_key );
// std::cerr << "key deleted " << _key << std::endl;
}
}
......@@ -213,16 +211,15 @@ void LevelDB::writeDataUnique(const string & Name, const string &value) {
auto key = Name;
if (readString(Name) != nullptr) {
spdlog::info("name {}",Name, " already exists");
spdlog::debug("name {}",Name, " already exists");
// std::cerr << "name " << Name << " already exists" << std::endl;
throw RPCException(KEY_SHARE_ALREADY_EXISTS, "Data with this name already exists");
}
writeString(key, value);
if (printDebugInfo) {
spdlog::info("{}",Name, " is written to db");
//std::cerr << Name << " is written to db " << std::endl;
}
spdlog::debug("{}",Name, " is written to db");
}
......@@ -273,12 +270,17 @@ bool LevelDB::isInited = false;
void LevelDB::initDataFolderAndDBs() {
if (isInited)
return;
CHECK_STATE(!isInited)
isInited = true;
spdlog::info("Initing wallet database ... ");
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) == NULL) {
spdlog::error("could not get cwd");
spdlog::error("could not get current workin directory");
exit(-1);
}
......@@ -286,17 +288,20 @@ void LevelDB::initDataFolderAndDBs() {
struct stat info;
if (stat(sgx_data_folder.c_str(), &info) !=0 ){
spdlog::info("going to create sgx_data folder");
std::string make_sgx_data_folder = "mkdir " + sgx_data_folder;
if (system(make_sgx_data_folder.c_str()) == 0){
spdlog::info("sgx_data folder was created");
spdlog::info("sgx_data folder does not exist. Creating ...");
if (system(("mkdir " + sgx_data_folder).c_str()) == 0){
spdlog::info("Successfully created sgx_data folder");
}
else{
spdlog::error("creating sgx_data folder failed");
spdlog::error("Couldnt create creating sgx_data folder");
exit(-1);
}
}
spdlog::info("Opening wallet databases");
auto dbName = sgx_data_folder + WALLETDB_NAME;
levelDb = make_shared<LevelDB>(dbName);
......@@ -306,6 +311,8 @@ void LevelDB::initDataFolderAndDBs() {
auto csr_status_dbname = sgx_data_folder + "CSR_STATUS_DB";
csrStatusDb = make_shared<LevelDB>(csr_status_dbname);
spdlog::info("Successfully opened databases");
}
const string &LevelDB::getSgxDataFolder() {
......
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file Log.cpp
@author Stan Kladko
@date 2018
*/
#include "spdlog/spdlog.h"
#include "sgxwallet_common.h"
#include "common.h"
#include "Log.h"
using namespace std;
void Log::setGlobalLogLevel(string &_s) {
globalLogLevel = logLevelFromString(_s);
}
level_enum Log::logLevelFromString(string &_s) {
level_enum result = trace;
if (_s == "trace")
result = trace;
else if (_s == "debug")
result = debug;
else if (_s == "info")
result = info;
else if (_s == "warn")
result = warn;
else if (_s == "err")
result = err;
else
throw InvalidArgumentException("Unknown level name " + _s, __CLASS_NAME__);
return result;
}
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file Log.h
@author Stan Kladko
@date 2018
*/
#ifndef _LOG_H
#define _LOG_H
#include <stdlib.h>
#include <iostream>
#include <map>
#include <memory>
#include "InvalidArgumentException.h"
#include "InvalidStateException.h"
#include "common.h"
using namespace std;
class Exception;
#define __CLASS_NAME__ className( __PRETTY_FUNCTION__ )
#define LOG( __SEVERITY__, __MESSAGE__ ) \
cerr << to_string(__SEVERITY__) << " " << __MESSAGE__ << " " << className( __PRETTY_FUNCTION__ ) << endl;
enum level_enum { trace, debug, info, warn, err };
class Log {
public:
level_enum globalLogLevel;
void setGlobalLogLevel( string& _s );
static level_enum logLevelFromString(string &_s);
};
#endif
......@@ -66,11 +66,13 @@ bin_PROGRAMS = sgxwallet testw cert_util
## You can't use $(wildcard ...) with automake so all source files
## have to be explicitly listed.
COMMON_SRC = sgx_stub.c sgx_detect_linux.c create_enclave.c oc_alloc.c
COMMON_SRC = InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp \
SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp RPCException.cpp BLSCrypto.cpp ECDSACrypto.cpp \
DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp \
sgx_stub.c sgx_detect_linux.c create_enclave.c oc_alloc.c
COMMON_ENCLAVE_SRC = secure_enclave_u.c secure_enclave_u.h
sgxwallet_SOURCES = sgxwallet.c SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp RPCException.cpp BLSCrypto.cpp ECDSACrypto.cpp \
DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp $(COMMON_SRC)
sgxwallet_SOURCES = sgxwallet.c $(COMMON_SRC)
nodist_sgxwallet_SOURCES = $(COMMON_ENCLAVE_SRC)
......@@ -104,13 +106,12 @@ sgxwallet_LDADD=-l$(SGX_URTS_LIB) -l$(SGX_UAE_SERVICE_LIB) -LlibBLS/deps/deps_in
-lgnutls -lgcrypt -lcurl -lssl -lcrypto -lz -lpthread
testw_SOURCES=testw.cpp stubclient.cpp SGXWalletServer.cpp RPCException.cpp BLSCrypto.cpp ServerInit.cpp LevelDB.cpp \
DKGCrypto.cpp BLSPrivateKeyShareSGX.cpp ECDSACrypto.cpp ServerDataChecker.cpp SEKManager.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp $(COMMON_SRC)
testw_SOURCES=testw.cpp $(COMMON_SRC)
nodist_testw_SOURCES=${nodist_sgxwallet_SOURCES}
EXTRA_testw_DEPENDENCIES=${EXTRA_sgxwallet_DEPENDENCIES}
testw_LDADD= ${sgxwallet_LDADD}
cert_util_SOURCES=cert_util.cpp stubclient.cpp RPCException.cpp LevelDB.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp
cert_util_SOURCES= InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp cert_util.cpp stubclient.cpp RPCException.cpp LevelDB.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp
cert_util_LDADD=-LlibBLS/deps/deps_inst/x86_or_x64/lib -Lleveldb/build -LlibBLS/build \
-LlibBLS/build/libff/libff \
-l:libbls.a -l:libleveldb.a \
......
......@@ -227,12 +227,10 @@ void enter_SEK(){
void init_SEK(){
std::shared_ptr<std::string> encr_SEK_ptr = LevelDB::getLevelDb()->readString("SEK");
if (encr_SEK_ptr == nullptr){
spdlog::info("SEK was not created yet. Going to create SEK");
spdlog::error("SEK was not created yet. Going to create SEK");
gen_SEK();
}
else{
if (printDebugInfo)
spdlog::info("going to set SEK from db" );
set_SEK(encr_SEK_ptr);
}
}
......
......@@ -46,10 +46,10 @@
#include "spdlog/spdlog.h"
#include "common.h"
int printDebugInfo = 0;
int useHTTPS = 1;
int encryptKeys = 0;
bool autoconfirm = false;
int printDebugInfo = -1;
int useHTTPS = -1;
int encryptKeys = -1;
int autoconfirm = -1;
SGXRegistrationServer *registrationServer = nullptr;
HttpServer *httpServer2 = nullptr;
......@@ -164,13 +164,13 @@ Json::Value GetSertificateImpl(const string &hash) {
}
Json::Value SGXRegistrationServer::signCertificate(const string &csr) {
Json::Value SGXRegistrationServer::SignCertificate(const string &csr) {
spdlog::info("Enter signCertificate ");
lock_guard<recursive_mutex> lock(m);
return signCertificateImpl(csr, autoSign);
}
Json::Value SGXRegistrationServer::getCertificate(const string &hash) {
Json::Value SGXRegistrationServer::GetCertificate(const string &hash) {
lock_guard<recursive_mutex> lock(m);
return GetSertificateImpl(hash);
}
......
......@@ -42,8 +42,8 @@ public:
void set_cert_created(bool b);
virtual Json::Value signCertificate(const std::string& csr);
virtual Json::Value getCertificate(const std::string& hash);
virtual Json::Value SignCertificate(const std::string& csr);
virtual Json::Value GetCertificate(const std::string& hash);
};
......
This diff is collapsed.
......@@ -31,6 +31,8 @@
#endif
EXTERNC void setFullOptions(int _printDebugInfo, int _useHTTPS, int _autoconfirm, int _encryptKeys);
EXTERNC void setOptions(int _printDebugInfo, int _useHTTPS, int _autoconfirm);
......
......@@ -25,9 +25,11 @@
#define SGXWALLET_SGXWALLETSERVER_HPP
#include "abstractstubserver.h"
#include <mutex>
#include "abstractstubserver.h"
#include "BLSCrypto.hpp"
using namespace jsonrpc;
using namespace std;
......@@ -112,7 +114,7 @@ public:
static Json::Value getVerificationVectorImpl(const string &_polyName, int _t, int _n);
static Json::Value getSecretShareImpl(const string &_polyName, const Json::Value &_publicKeys, int _t, int _n);
static Json::Value getSecretShareImpl(const string &_polyName, const Json::Value &_pubKeys, int _t, int _n);
static Json::Value
dkgVerificationImpl(const string &_publicShares, const string &_ethKeyName, const string &_secretShare,
......
......@@ -22,71 +22,52 @@
*/
#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 "bls.h"
#include "leveldb/db.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 "create_enclave.h"
#include "secure_enclave_u.h"
#include "sgx_detect.h"
#include <gmp.h>
#include <sgx_urts.h>
#include "sgxwallet.h"
#include "LevelDB.h"
#include "SGXWalletServer.h"
#include "SGXRegistrationServer.h"
#include "SEKManager.h"
#include "CSRManagerServer.h"
#include "BLSCrypto.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 "SGXWALLET_VERSION"
//#include <system>
void initDaemon() {
void initUserSpace() {
libff::init_alt_bn128_params();
LevelDB::initDataFolderAndDBs();
}
void initEnclave() {
eid = 0;
updated = 0;
#ifndef SGX_HW_SIM
unsigned long support;
support = get_sgx_support();
......@@ -96,9 +77,8 @@ void initEnclave() {
}
#endif
if ( printDebugInfo) {
spdlog::info("SGX_DEBUG_FLAG = {}", SGX_DEBUG_FLAG);
}
spdlog::debug("SGX_DEBUG_FLAG = {}", SGX_DEBUG_FLAG);
status = sgx_create_enclave_search(ENCLAVE_NAME, SGX_DEBUG_FLAG, &token,
&updated, &eid, 0);
......@@ -108,13 +88,13 @@ void initEnclave() {
fprintf(stderr, "sgx_create_enclave: %s: file not found\n", ENCLAVE_NAME);
fprintf(stderr, "Did you forget to set LD_LIBRARY_PATH?\n");
} else {
spdlog::error("sgx_create_enclave_search failed");
fprintf(stderr, "%s: 0x%04x\n", ENCLAVE_NAME, status);
}
exit(1);
}
//fprintf(stderr, "Enclave launched\n");
spdlog::info( "Enclave launched");
spdlog::info("Enclave created and started successfully");
status = tgmp_init(eid);
if (status != SGX_SUCCESS) {
......@@ -122,38 +102,27 @@ void initEnclave() {
exit(1);
}
if (printDebugInfo) {
spdlog::info("libtgmp initialized");
//fprintf(stderr, "libtgmp initialized\n");
}
spdlog::info("Enclave libtgmp library initialized successfully");
}
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;
//spdlog::set_pattern("%c");
if (sgxServerInited == 1)
return;
initEnclave();
initDaemon();
//init_SEK();
SEK_func();
CHECK_STATE(sgxServerInited == 0)
sgxServerInited = 1;
initEnclave();
initUserSpace();
init_SEK();
if (useHTTPS) {
SGXWalletServer::initHttpsServer(_checkCert);
initRegistrationServer(_autoSign);
init_csrmanager_server();
}
else {
init_csrmanager_server();
} else {
SGXWalletServer::initHttpServer();
}
//std::cerr << "enclave inited" << std::endl;
}
......@@ -30,9 +30,9 @@
#define EXTERNC
#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();
......
......@@ -39,16 +39,16 @@ public:
inline virtual void signCertificateI(const Json::Value &request, Json::Value &response)
{
std::cerr << "signCertificateI in abstr server " << std::endl;
response = this->signCertificate( request["certificate"].asString());
response = this->SignCertificate(request["certificate"].asString());
}
inline virtual void getCertificateI(const Json::Value &request, Json::Value &response)
{
response = this->getCertificate( request["hash"].asString());
response = this->GetCertificate(request["hash"].asString());
}
virtual Json::Value signCertificate(const std::string& cert) = 0;
virtual Json::Value getCertificate(const std::string& hash) = 0;
virtual Json::Value SignCertificate(const std::string& cert) = 0;
virtual Json::Value GetCertificate(const std::string& hash) = 0;
};
......
......@@ -32,15 +32,29 @@ using namespace std;
#include <map>
#include <memory>
#define CHECK_ARGUMENT(_EXPRESSION_) \
if (!(_EXPRESSION_)) { \
auto __msg__ = string("Argument Check failed:") + #_EXPRESSION_ + "\n" + __CLASS_NAME__ + ":" + __FUNCTION__ + \
+ " " + string(__FILE__) + ":" + to_string(__LINE__); \
throw runtime_error(__msg__);}
#include "InvalidStateException.h"
inline std::string className(const std::string &prettyFunction) {
size_t colons = prettyFunction.find("::");
if (colons == std::string::npos)
return "::";
size_t begin = prettyFunction.substr(0, colons).rfind(" ") + 1;
size_t end = colons - begin;
return prettyFunction.substr(begin, end);
}
#define __CLASS_NAME__ className( __PRETTY_FUNCTION__ )
#define CHECK_STATE(_EXPRESSION_) \
if (!(_EXPRESSION_)) { \
auto __msg__ = string("State check failed::") + #_EXPRESSION_ + " " + string(__FILE__) + ":" + to_string(__LINE__); \
throw runtime_error(__msg__);}
throw InvalidStateException(__msg__, __CLASS_NAME__);}
#endif //SGXWALLET_COMMON_H
......@@ -5,25 +5,25 @@ cd /usr/src/sdk;
echo $1
if [ "$1" = -t ]; then
set -e
# ./testw [bls-key-encrypt]
# ./testw [bls-key-encrypt-decrypt]
# ./testw [dkg-gen]
# ./testw [dkg-pub_shares]
# ./testw [dkg-verify]
# ./testw [ecdsa_test]
# ./testw [test_test]
# ./testw [get_pub_ecdsa_key_test]
# ./testw [bls_dkg]
# ./testw [api_test]
# ./testw [getServerStatus_test]
# ./testw [dkg_api_test]
# ./testw [is_poly_test]
# ./testw [AES-encrypt-decrypt]
./testw [bls-key-encrypt]
#./testw [bls-key-encrypt-decrypt]
#./testw [dkg-gen]
#./testw [dkg-pub_shares]
#./testw [dkg-verify]
#./testw [ecdsa_test]
#./testw [test_test]
#./testw [get_pub_ecdsa_key_test]
#./testw [bls_dkg]
#./testw [api_test]
#./testw [getServerStatus_test]
#./testw [dkg_api_test]
#./testw [is_poly_test]
#./testw [AES-encrypt-decrypt]
#./testw [ecdsa_api_test]
#./testw [dkg-encr_sshares]
#./testw [bls_sign]
#./testw [many_threads_test]
# ./testw [aes_dkg]
#./testw [bls_sign]
#/testw [many_threads_test]
#./testw [aes_dkg]
else
./sgxwallet $1 $2 $3 $4
fi
......
......@@ -70,11 +70,7 @@ cd scripts; ./build.py; cd ..
Go to the project's top directory, then run
```bash
libtoolize --force
aclocal
autoheader
automake --force-missing --add-missing
autoconf
./autoconf.bash
./configure
make
......
version: '3'
services:
sgxwallet:
image: skalenetwork/sgxwallet:latest_commit
image: skalenetwork/sgxwallet:latest
ports:
- "1026:1026"
- "1027:1027"
......@@ -17,6 +17,7 @@ services:
max-size: "10m"
max-file: "4"
restart: unless-stopped
command: -s -d -y
command: -s
healthcheck:
test: ["CMD", "ls /dev/isg /dev/mei0"]
#!/bin/bash
cd ../skale-admin
source skale-admin/bin/activate
docker stop $(docker ps -a -q)
docker pull skalenetwork/sgxwalletsim:latest
ETH_PRIVATE_KEY=3dd85d854e41db7585080dfdb90f88a83f0c70e229c509a4a1da63d0c82d5ad0 MANAGER_BRANCH=delegation-fix bash ./scripts/deploy_manager.sh
ETH_PRIVATE_KEY=3dd85d854e41db7585080dfdb90f88a83f0c70e229c509a4a1da63d0c82d5ad0 IMA_ENDPOINT=http://localhost:1000 SCHAIN_TYPE=test2 bash ./scripts/run_tests.sh
......@@ -65,18 +65,23 @@ void printUsage() {
}
int main(int argc, char *argv[]) {
void (*SEK_initializer)();
SEK_initializer = init_SEK;
bool checkClientCert = true;
bool sign_automatically = false;
bool encryptKeysOption = false;
bool useHTTPSOption = true;
bool printDebugInfoOption = false;
bool autoconfirmOption = false;
bool checkClientCertOption = true;
bool autoSignClientCertOption = false;
int opt;
if (argc > 1 && strlen(argv[1]) == 1) {
fprintf(stderr, "option is too short %s\n", argv[1]);
printUsage();
exit(1);
}
encryptKeys = 0;
while ((opt = getopt(argc, argv, "cshd0aby")) != -1) {
switch (opt) {
......@@ -90,25 +95,25 @@ int main(int argc, char *argv[]) {
exit(1);
}
case 'c':
checkClientCert = false;
checkClientCertOption = false;
break;
case 's':
sign_automatically = true;
autoSignClientCertOption = true;
break;
case 'd':
printDebugInfo = 1;
printDebugInfoOption = true;
break;
case '0':
useHTTPS = 0;
useHTTPSOption = false;
break;
case 'a':
encryptKeys = 0;
encryptKeysOption = false;
break;
case 'b':
SEK_initializer = enter_SEK;
encryptKeysOption = false;
break;
case 'y':
autoconfirm = true;
autoconfirmOption = true;
break;
case '?':
printUsage();
......@@ -117,7 +122,10 @@ int main(int argc, char *argv[]) {
break;
}
}
initAll(checkClientCert, sign_automatically, SEK_initializer);
setFullOptions(printDebugInfoOption, useHTTPSOption, autoconfirmOption, encryptKeysOption);
initAll(checkClientCertOption, autoSignClientCertOption);
while (true) {
sleep(10);
......
......@@ -30,17 +30,23 @@
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
extern int printDebugInfo;
extern int useHTTPS;
extern int encryptKeys;
extern bool autoconfirm;
extern int autoconfirm;
#define BUF_LEN 1024
#define BUF_LEN 4096
#define MAX_KEY_LENGTH 128
#define MAX_COMPONENT_LENGTH 80
......@@ -52,9 +58,6 @@ extern bool autoconfirm;
#define ADD_ENTROPY_SIZE 32
#define DKG_BUFER_LENGTH 2490//3060
#define DKG_MAX_SEALED_LEN 3050
#define SECRET_SHARE_NUM_BYTES 96
#define ECDSA_SKEY_LEN 65
......
This diff is collapsed.
#!/usr/bin/env python3
# Copyright (C) 2019-Present SKALE Labs
#
# This file is part of sgxwallet.
#
# sgxwallet is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# sgxwallet is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
#
# @file docker_test.py
# @author Stan Kladko
# @date 2020
#
import sys, getpass,os, subprocess, socket, time
username = getpass.getuser()
assert username == "root"
topDir = os.getcwd() + "/sgxwallet"
print("Starting build push")
print("Top directory is:" + topDir)
testList = ["[bls-key-encrypt]", "[dkg-gen]",
"[dkg-encr_sshares]",
"[dkg-verify]",
"[ecdsa_test]",
"[test_test]",
"[get_pub_ecdsa_key_test]",
"[bls_dkg]",
"[api_test]",
"[getServerStatus_test]",
"[many_threads_test]",
"[ecdsa_api_test]",
"[dkg_api_test]",
"[is_poly_test]",
# "[bls_sign]",
"[AES-encrypt-decrypt]"]
for t in testList:
print("Starting " + t)
assert subprocess.call(["./testw", t]) == 0
print("Ending " + t)
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