Unverified Commit dbf340bd authored by kladko's avatar kladko

bug/SKALE-3751-enable-zeromq

parent fb3c9968
...@@ -118,6 +118,12 @@ void SGXWalletServer::printDB() { ...@@ -118,6 +118,12 @@ void SGXWalletServer::printDB() {
#define NUM_THREADS 200 #define NUM_THREADS 200
#endif #endif
bool SGXWalletServer::verifyCert(string &_certFileName) {
string rootCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.pem";
string verifyCert = "cert/verify_client_cert " + rootCAPath + " " + _certFileName;
return system(verifyCert.c_str()) == 0;
}
int SGXWalletServer::initHttpsServer(bool _checkCerts) { int SGXWalletServer::initHttpsServer(bool _checkCerts) {
COUNT_STATISTICS COUNT_STATISTICS
...@@ -158,6 +164,16 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) { ...@@ -158,6 +164,16 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
} }
} }
spdlog::info("Verifying server cert");
if (verifyCert(certPath)) {
spdlog::info("SERVER CERTIFICATE IS SUCCESSFULLY VERIFIED");
} else {
spdlog::info("SERVER CERTIFICATE VERIFICATION FAILED");
exit(-12);
}
httpServer = make_shared<HttpServer>(BASE_PORT, certPath, keyPath, rootCAPath, _checkCerts, httpServer = make_shared<HttpServer>(BASE_PORT, certPath, keyPath, rootCAPath, _checkCerts,
NUM_THREADS); NUM_THREADS);
...@@ -213,18 +229,19 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k ...@@ -213,18 +229,19 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
} }
if (!checkHex(hashTmp)) { if (!checkHex(hashTmp)) {
throw SGXException(BLS_IMPORT_INVALID_KEY_SHARE, string(__FUNCTION__) + ":Invalid BLS key share, please use hex"); throw SGXException(BLS_IMPORT_INVALID_KEY_SHARE,
string(__FUNCTION__) + ":Invalid BLS key share, please use hex");
} }
encryptedKeyShareHex = encryptBLSKeyShare2Hex(&errStatus, (char *) errMsg.data(), hashTmp.c_str()); encryptedKeyShareHex = encryptBLSKeyShare2Hex(&errStatus, (char *) errMsg.data(), hashTmp.c_str());
if (errStatus != 0) { if (errStatus != 0) {
throw SGXException(errStatus, string(__FUNCTION__) + ":" +errMsg.data()); throw SGXException(errStatus, string(__FUNCTION__) + ":" + errMsg.data());
} }
if (encryptedKeyShareHex.empty()) { if (encryptedKeyShareHex.empty()) {
throw SGXException(BLS_IMPORT_EMPTY_ENCRYPTED_KEY_SHARE,string(__FUNCTION__) + throw SGXException(BLS_IMPORT_EMPTY_ENCRYPTED_KEY_SHARE, string(__FUNCTION__) +
":Empty encrypted key share"); ":Empty encrypted key share");
} }
result["encryptedKeyShare"] = encryptedKeyShareHex; result["encryptedKeyShare"] = encryptedKeyShareHex;
...@@ -309,7 +326,6 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin ...@@ -309,7 +326,6 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
result["signatureShare"] = string(signature.data()); result["signatureShare"] = string(signature.data());
RETURN_SUCCESS(result); RETURN_SUCCESS(result);
} }
...@@ -435,7 +451,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) { ...@@ -435,7 +451,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) {
try { try {
if (!checkECDSAKeyName(_keyName)) { if (!checkECDSAKeyName(_keyName)) {
throw SGXException(INVALID_ECDSA_GETPKEY_KEY_NAME, string(__FUNCTION__) + throw SGXException(INVALID_ECDSA_GETPKEY_KEY_NAME, string(__FUNCTION__) +
":Invalid ECDSA import key name"); ":Invalid ECDSA import key name");
} }
shared_ptr <string> keyStr = readFromDb(_keyName); shared_ptr <string> keyStr = readFromDb(_keyName);
publicKey = getECDSAPubKey(keyStr->c_str()); publicKey = getECDSAPubKey(keyStr->c_str());
...@@ -814,7 +830,7 @@ Json::Value SGXWalletServer::deleteBlsKeyImpl(const string &name) { ...@@ -814,7 +830,7 @@ Json::Value SGXWalletServer::deleteBlsKeyImpl(const string &name) {
result["deleted"] = true; result["deleted"] = true;
} else { } else {
auto error_msg = "BLS key not found: " + name; auto error_msg = "BLS key not found: " + name;
throw SGXException(DELETE_BLS_KEY_NOT_FOUND, string(__FUNCTION__)+ ":" + error_msg.c_str()); throw SGXException(DELETE_BLS_KEY_NOT_FOUND, string(__FUNCTION__) + ":" + error_msg.c_str());
} }
} HANDLE_SGX_EXCEPTION(result) } HANDLE_SGX_EXCEPTION(result)
...@@ -903,8 +919,9 @@ Json::Value SGXWalletServer::dkgVerificationV2Impl(const string &_publicShares, ...@@ -903,8 +919,9 @@ Json::Value SGXWalletServer::dkgVerificationV2Impl(const string &_publicShares,
} }
Json::Value Json::Value
SGXWalletServer::createBLSPrivateKeyV2Impl(const string &_blsKeyName, const string &_ethKeyName, const string &_polyName, SGXWalletServer::createBLSPrivateKeyV2Impl(const string &_blsKeyName, const string &_ethKeyName,
const string &_secretShare, int _t, int _n) { const string &_polyName,
const string &_secretShare, int _t, int _n) {
COUNT_STATISTICS COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -1058,7 +1075,7 @@ SGXWalletServer::dkgVerificationV2(const string &_publicShares, const string &et ...@@ -1058,7 +1075,7 @@ SGXWalletServer::dkgVerificationV2(const string &_publicShares, const string &et
Json::Value Json::Value
SGXWalletServer::createBLSPrivateKeyV2(const string &blsKeyName, const string &ethKeyName, const string &polyName, SGXWalletServer::createBLSPrivateKeyV2(const string &blsKeyName, const string &ethKeyName, const string &polyName,
const string &SecretShare, int t, int n) { const string &SecretShare, int t, int n) {
return createBLSPrivateKeyV2Impl(blsKeyName, ethKeyName, polyName, SecretShare, t, n); return createBLSPrivateKeyV2Impl(blsKeyName, ethKeyName, polyName, SecretShare, t, n);
} }
...@@ -1066,7 +1083,7 @@ shared_ptr <string> SGXWalletServer::readFromDb(const string &name, const string ...@@ -1066,7 +1083,7 @@ shared_ptr <string> SGXWalletServer::readFromDb(const string &name, const string
auto dataStr = checkDataFromDb(prefix + name); auto dataStr = checkDataFromDb(prefix + name);
if (dataStr == nullptr) { if (dataStr == nullptr) {
throw SGXException(KEY_SHARE_DOES_NOT_EXIST, string(__FUNCTION__) + ":Data with this name does not exist"); throw SGXException(KEY_SHARE_DOES_NOT_EXIST, string(__FUNCTION__) + ":Data with this name does not exist");
} }
return dataStr; return dataStr;
......
...@@ -55,7 +55,11 @@ class SGXWalletServer : public AbstractStubServer { ...@@ -55,7 +55,11 @@ class SGXWalletServer : public AbstractStubServer {
static void checkForDuplicate(map <string, string> &_map, recursive_mutex &_m, const string &_key, static void checkForDuplicate(map <string, string> &_map, recursive_mutex &_m, const string &_key,
const string &_value); const string &_value);
public: public:
static bool verifyCert(string& _certFileName);
static const char* getVersion() { static const char* getVersion() {
return TOSTRING(SGXWALLET_VERSION); return TOSTRING(SGXWALLET_VERSION);
} }
......
File added
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