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