Unverified Commit 3d23ab77 authored by kladko's avatar kladko

SKALE-2536-fix-cert

parent ed41bdb2
...@@ -87,18 +87,23 @@ Json::Value signCertificateImpl(const string &_csr, bool _autoSign = false) { ...@@ -87,18 +87,23 @@ Json::Value signCertificateImpl(const string &_csr, bool _autoSign = false) {
} }
string genCert = string("cd ") + CERT_DIR + "&& ./" + CERT_CREATE_COMMAND + " " + hash; string genCert = string("cd ") + CERT_DIR + "&& ./"
if (system(("rm -f " + csr_name).c_str()) != 0) { + CERT_CREATE_COMMAND + " " + hash ;
spdlog::error("could not delete csr file");
}
if (system(genCert.c_str()) == 0) { if (system(genCert.c_str()) == 0) {
spdlog::info("CLIENT CERTIFICATE IS SUCCESSFULLY GENERATED"); spdlog::info("Client cert " + hash + " generated");
string db_key = "CSR:HASH:" + hash + "STATUS:"; string db_key = "CSR:HASH:" + hash + "STATUS:";
string status = "0"; string status = "0";
LevelDB::getCsrStatusDb()->writeDataUnique(db_key, status); LevelDB::getCsrStatusDb()->writeDataUnique(db_key, status);
if (system(("rm -f " + csr_name).c_str()) != 0) {
spdlog::error("could not delete csr file");
}
} else { } else {
spdlog::error("CLIENT CERTIFICATE GENERATION FAILED");
spdlog::error("Client cert generation failed: {} ", genCert);
throw SGXException(FAIL_TO_CREATE_CERTIFICATE, "CLIENT CERTIFICATE GENERATION FAILED"); throw SGXException(FAIL_TO_CREATE_CERTIFICATE, "CLIENT CERTIFICATE GENERATION FAILED");
} }
} else { } else {
...@@ -184,3 +189,9 @@ int SGXRegistrationServer::initRegistrationServer(bool _autoSign) { ...@@ -184,3 +189,9 @@ int SGXRegistrationServer::initRegistrationServer(bool _autoSign) {
return 0; return 0;
} }
shared_ptr<SGXRegistrationServer> SGXRegistrationServer::getServer() {
CHECK_STATE(server);
return server;
}
...@@ -38,26 +38,31 @@ ...@@ -38,26 +38,31 @@
using namespace jsonrpc; using namespace jsonrpc;
using namespace std; using namespace std;
class SGXRegistrationServer: public AbstractRegServer { class SGXRegistrationServer : public AbstractRegServer {
recursive_mutex m; recursive_mutex m;
bool autoSign; bool autoSign;
static shared_ptr<SGXRegistrationServer> server;
static shared_ptr<HttpServer> httpServer; static shared_ptr <HttpServer> httpServer;
static shared_ptr <SGXRegistrationServer> server;
public: public:
static shared_ptr <SGXRegistrationServer> getServer();
SGXRegistrationServer(AbstractServerConnector &connector, serverVersion_t type, bool _autoSign = false); SGXRegistrationServer(AbstractServerConnector &connector, serverVersion_t type, bool _autoSign = false);
virtual Json::Value SignCertificate(const string& csr); virtual Json::Value SignCertificate(const string &csr);
virtual Json::Value GetCertificate(const string& hash);
virtual Json::Value GetCertificate(const string &hash);
static int initRegistrationServer(bool _autoSign = false); static int initRegistrationServer(bool _autoSign = false);
}; };
#endif // SGXD_SGXREGISTRATIONSERVER_H #endif // SGXD_SGXREGISTRATIONSERVER_H
\ No newline at end of file
...@@ -69,6 +69,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -69,6 +69,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <thread> #include <thread>
#include "common.h" #include "common.h"
#include "stubclient.h" #include "stubclient.h"
#include "SGXRegistrationServer.h"
#include "SGXWalletServer.h" #include "SGXWalletServer.h"
#include "testw.h" #include "testw.h"
...@@ -303,9 +304,23 @@ public: ...@@ -303,9 +304,23 @@ public:
~TestFixture() { ~TestFixture() {
destroyEnclave(); destroyEnclave();
} }
};
class TestFixtureHTTPS {
public:
TestFixtureHTTPS() {
resetDB();
setOptions(false, false, true, true);
initAll(0, false, true);
}
~TestFixtureHTTPS() {
destroyEnclave();
}
}; };
TEST_CASE_METHOD(TestFixture, "ECDSA keygen and signature test", "[ecdsa-key-sig-gen]") { TEST_CASE_METHOD(TestFixture, "ECDSA keygen and signature test", "[ecdsa-key-sig-gen]") {
...@@ -769,10 +784,12 @@ TEST_CASE_METHOD(TestFixture, "Get ServerStatus", "[get-server-status]") { ...@@ -769,10 +784,12 @@ TEST_CASE_METHOD(TestFixture, "Get ServerStatus", "[get-server-status]") {
} }
TEST_CASE_METHOD(TestFixture, "Cert request sign ServerStatus", "[cert-sign]") { TEST_CASE_METHOD(TestFixtureHTTPS, "Cert request sign", "[cert-sign]") {
HttpClient client(RPC_ENDPOINT);
StubClient c(client, JSONRPC_CLIENT_V2); REQUIRE(SGXRegistrationServer::getServer() != nullptr);
REQUIRE(c.getServerStatus()["status"] == 0); auto result = SGXRegistrationServer::getServer()->SignCertificate("Haha");
REQUIRE(result["status"] == 0);
} }
......
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