Unverified Commit 1fa379be authored by kladko's avatar kladko

SKALE-2345 Cleaning testst

parent 4ccc28e7
...@@ -46,10 +46,10 @@ ...@@ -46,10 +46,10 @@
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "common.h" #include "common.h"
int printDebugInfo = 0; int printDebugInfo = -1;
int useHTTPS = 1; int useHTTPS = -1;
int encryptKeys = 0; int encryptKeys = -1;
bool autoconfirm = false; int autoconfirm = -1;
SGXRegistrationServer *registrationServer = nullptr; SGXRegistrationServer *registrationServer = nullptr;
HttpServer *httpServer2 = nullptr; HttpServer *httpServer2 = nullptr;
......
...@@ -86,7 +86,6 @@ void initEnclave() { ...@@ -86,7 +86,6 @@ void initEnclave() {
updated = 0; updated = 0;
#ifndef SGX_HW_SIM #ifndef SGX_HW_SIM
unsigned long support; unsigned long support;
support = get_sgx_support(); support = get_sgx_support();
...@@ -108,13 +107,14 @@ void initEnclave() { ...@@ -108,13 +107,14 @@ void initEnclave() {
fprintf(stderr, "sgx_create_enclave: %s: file not found\n", ENCLAVE_NAME); fprintf(stderr, "sgx_create_enclave: %s: file not found\n", ENCLAVE_NAME);
fprintf(stderr, "Did you forget to set LD_LIBRARY_PATH?\n"); fprintf(stderr, "Did you forget to set LD_LIBRARY_PATH?\n");
} else { } else {
spdlog::error("sgx_create_enclave_search failed");
fprintf(stderr, "%s: 0x%04x\n", ENCLAVE_NAME, status); fprintf(stderr, "%s: 0x%04x\n", ENCLAVE_NAME, status);
} }
exit(1); exit(1);
} }
//fprintf(stderr, "Enclave launched\n"); //fprintf(stderr, "Enclave launched\n");
spdlog::info( "Enclave launched"); spdlog::error( "Enclave created and started successfully");
status = tgmp_init(eid); status = tgmp_init(eid);
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
...@@ -122,10 +122,8 @@ void initEnclave() { ...@@ -122,10 +122,8 @@ void initEnclave() {
exit(1); exit(1);
} }
if (printDebugInfo) { spdlog::info("Enclave libtgmp library initialized successfully");
spdlog::info("libtgmp initialized");
//fprintf(stderr, "libtgmp initialized\n");
}
} }
......
...@@ -65,18 +65,25 @@ void printUsage() { ...@@ -65,18 +65,25 @@ void printUsage() {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
bool encryptKeysOption = false;
bool useHTTPSOption = true;
bool printDebugInfoOption = false;
bool autoconfirmOption = false;
bool checkClientCertOption = true;
bool autoSignClientCertOption = false;
void (*SEK_initializer)(); void (*SEK_initializer)();
SEK_initializer = init_SEK; SEK_initializer = init_SEK;
bool checkClientCert = true;
bool sign_automatically = false;
int opt; int opt;
if (argc > 1 && strlen(argv[1]) == 1) { if (argc > 1 && strlen(argv[1]) == 1) {
fprintf(stderr, "option is too short %s\n", argv[1]); printUsage();
exit(1); exit(1);
} }
encryptKeys = 0;
while ((opt = getopt(argc, argv, "cshd0aby")) != -1) { while ((opt = getopt(argc, argv, "cshd0aby")) != -1) {
switch (opt) { switch (opt) {
...@@ -90,25 +97,25 @@ int main(int argc, char *argv[]) { ...@@ -90,25 +97,25 @@ int main(int argc, char *argv[]) {
exit(1); exit(1);
} }
case 'c': case 'c':
checkClientCert = false; checkClientCertOption = false;
break; break;
case 's': case 's':
sign_automatically = true; autoSignClientCertOption = true;
break; break;
case 'd': case 'd':
printDebugInfo = 1; printDebugInfoOption = true;
break; break;
case '0': case '0':
useHTTPS = 0; useHTTPSOption = false;
break; break;
case 'a': case 'a':
encryptKeys = 0; encryptKeysOption = false;
break; break;
case 'b': case 'b':
SEK_initializer = enter_SEK; SEK_initializer = enter_SEK;
break; break;
case 'y': case 'y':
autoconfirm = true; autoconfirmOption = true;
break; break;
case '?': case '?':
printUsage(); printUsage();
...@@ -117,7 +124,10 @@ int main(int argc, char *argv[]) { ...@@ -117,7 +124,10 @@ int main(int argc, char *argv[]) {
break; break;
} }
} }
initAll(checkClientCert, sign_automatically, SEK_initializer);
setFullOptions(printDebugInfoOption, useHTTPSOption, autoconfirmOption, encryptKeysOption);
initAll(checkClientCertOption, autoSignClientCertOption, SEK_initializer);
while (true) { while (true) {
sleep(10); sleep(10);
......
...@@ -39,7 +39,23 @@ ...@@ -39,7 +39,23 @@
extern int printDebugInfo; extern int printDebugInfo;
extern int useHTTPS; extern int useHTTPS;
extern int encryptKeys; extern int encryptKeys;
extern bool autoconfirm; extern int autoconfirm;
inline void setFullOptions(int _printDebugInfo, int _useHTTPS, int _autoconfirm, int _encryptKeys) {
printDebugInfo = _printDebugInfo;
useHTTPS = _useHTTPS;
autoconfirm = _autoconfirm;
encryptKeys = _encryptKeys;
}
inline void setOptions(int _printDebugInfo, int _useHTTPS, int _autoconfirm) {
setFullOptions(_printDebugInfo, _useHTTPS, _autoconfirm, false);
}
#define BUF_LEN 1024 #define BUF_LEN 1024
......
...@@ -89,14 +89,15 @@ void usage() { ...@@ -89,14 +89,15 @@ void usage() {
} }
sgx_launch_token_t token = {0}; sgx_launch_token_t token = {0};
sgx_enclave_id_t eid; sgx_enclave_id_t eid = 0;
sgx_status_t status; sgx_status_t status;
int updated; int updated;
#define TEST_BLS_KEY_SHARE "4160780231445160889237664391382223604184857153814275770598791864649971919844" #define TEST_BLS_KEY_SHARE "4160780231445160889237664391382223604184857153814275770598791864649971919844"
#define TEST_BLS_KEY_NAME "SCHAIN:17:INDEX:5:KEY:1" #define TEST_BLS_KEY_NAME "SCHAIN:17:INDEX:5:KEY:1"
void reset_db() { void resetDB() {
sgx_destroy_enclave(eid);
//string db_name = SGXDATA_FOLDER + WALLETDB_NAME; //string db_name = SGXDATA_FOLDER + WALLETDB_NAME;
REQUIRE(system("rm -rf " REQUIRE(system("rm -rf "
WALLETDB_NAME) == 0); WALLETDB_NAME) == 0);
...@@ -121,23 +122,19 @@ char *encryptTestKey() { ...@@ -121,23 +122,19 @@ char *encryptTestKey() {
TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") { TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") {
printDebugInfo = 1; resetDB();
useHTTPS = 0; setOptions(true, false, true);
autoconfirm = true;
initAll(false, true, init_SEK); initAll(false, true, init_SEK);
auto key = encryptTestKey(); auto key = encryptTestKey();
REQUIRE(key != nullptr); REQUIRE(key != nullptr);
free(key); free(key);
sgx_destroy_enclave(eid);
} }
TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") { TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
{ resetDB();
setOptions(true, false, true);
printDebugInfo = 1;
useHTTPS = 0;
autoconfirm = true;
initAll(false, true, init_SEK); initAll(false, true, init_SEK);
//init_enclave(); //init_enclave();
...@@ -161,15 +158,22 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") { ...@@ -161,15 +158,22 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
}
void destroyEnclave() {
if (eid != 0) {
sgx_destroy_enclave(eid);
eid = 0;
} }
} }
TEST_CASE("DKG gen test", "[dkg-gen]") { TEST_CASE("DKG gen test", "[dkg-gen]") {
resetDB();
setOptions(true, false, true);
initAll(false, true, init_SEK);
autoconfirm = true;
//init_all();
initEnclave();
vector<uint8_t> encrypted_dkg_secret(DKG_MAX_SEALED_LEN, 0); vector<uint8_t> encrypted_dkg_secret(DKG_MAX_SEALED_LEN, 0);
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
...@@ -254,10 +258,13 @@ libff::alt_bn128_G2 VectStringToG2(const vector<string> &G2_str_vect) { ...@@ -254,10 +258,13 @@ 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]") {
autoconfirm = true; resetDB();
//init_all(); setOptions(true, false, true);
initAll(false, true, init_SEK);
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
initEnclave();
vector<uint8_t> encrypted_dkg_secret(DKG_MAX_SEALED_LEN, 0); vector<uint8_t> encrypted_dkg_secret(DKG_MAX_SEALED_LEN, 0);
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
...@@ -325,9 +332,10 @@ TEST_CASE("DKG public shares test", "[dkg-pub_shares]") { ...@@ -325,9 +332,10 @@ 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]") {
autoconfirm = true; resetDB();
// init_all(); setOptions(true, false, true);
initEnclave(); initAll(false, true, init_SEK);
vector<char> errMsg(1024, 1); vector<char> errMsg(1024, 1);
vector<char> result(130, 1); vector<char> result(130, 1);
...@@ -348,12 +356,12 @@ TEST_CASE("DKG encrypted secret shares test", "[dkg-encr_sshares]") { ...@@ -348,12 +356,12 @@ TEST_CASE("DKG encrypted secret shares test", "[dkg-encr_sshares]") {
string pub_keyB = "c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"; string pub_keyB = "c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475";
vector<char> s_shareG2(320,0); vector<char> s_shareG2(320, 0);
status = get_encr_sshare(eid, &err_status, errMsg.data(), encrPRDHKey.data(), &enc_len, result.data(), s_shareG2.data(), status = get_encr_sshare(eid, &err_status, errMsg.data(), encrPRDHKey.data(), &enc_len, result.data(),
(char*) pub_keyB.data(), 2, 2, 1); s_shareG2.data(),
(char *) pub_keyB.data(), 2, 2, 1);
REQUIRE(status == SGX_SUCCESS); REQUIRE(status == SGX_SUCCESS);
printf(" get_encr_sshare completed with status: %d %s \n", err_status, errMsg.data());
cerr << "secret share is " << result.data() << endl; cerr << "secret share is " << result.data() << endl;
...@@ -361,9 +369,10 @@ TEST_CASE("DKG encrypted secret shares test", "[dkg-encr_sshares]") { ...@@ -361,9 +369,10 @@ TEST_CASE("DKG encrypted secret shares test", "[dkg-encr_sshares]") {
} }
TEST_CASE("DKG verification test", "[dkg-verify]") { TEST_CASE("DKG verification test", "[dkg-verify]") {
autoconfirm = true; resetDB();
// init_all(); setOptions(true, false, true);
initEnclave(); initAll(false, true, init_SEK);
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
vector<char> result(130, 0); vector<char> result(130, 0);
...@@ -385,10 +394,11 @@ TEST_CASE("DKG verification test", "[dkg-verify]") { ...@@ -385,10 +394,11 @@ TEST_CASE("DKG verification test", "[dkg-verify]") {
string pub_keyB = "c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"; string pub_keyB = "c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475";
vector<char> s_shareG2(320,0); vector<char> s_shareG2(320, 0);
status = get_encr_sshare(eid, &err_status, errMsg.data(), encrPrDHKey.data(), &enc_len, result.data(), s_shareG2.data(), status = get_encr_sshare(eid, &err_status, errMsg.data(), encrPrDHKey.data(), &enc_len, result.data(),
(char*) pub_keyB.data(), 2, 2, 1); s_shareG2.data(),
(char *) pub_keyB.data(), 2, 2, 1);
REQUIRE(status == SGX_SUCCESS); REQUIRE(status == SGX_SUCCESS);
printf(" get_encr_sshare completed with status: %d %s \n", err_status, errMsg.data()); printf(" get_encr_sshare completed with status: %d %s \n", err_status, errMsg.data());
...@@ -400,8 +410,10 @@ TEST_CASE("DKG verification test", "[dkg-verify]") { ...@@ -400,8 +410,10 @@ 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]") {
autoconfirm = true; resetDB();
initEnclave(); setOptions(true, false, true);
initAll(false, true, init_SEK);
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
int err_status = 0; int err_status = 0;
...@@ -420,12 +432,8 @@ TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") { ...@@ -420,12 +432,8 @@ TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") {
printf("\nwas pub_key_x %s: \n", pub_key_x.data()); printf("\nwas pub_key_x %s: \n", pub_key_x.data());
printf("\nwas pub_key_y %s: \n", pub_key_y.data()); printf("\nwas pub_key_y %s: \n", pub_key_y.data());
/*printf("\nencr priv_key : \n");
for ( int i = 0; i < 1024 ; i++)
printf("%u ", encr_pr_key[i]);*/
string hex = "3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F"; string hex = "3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F";
// char* hex = "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
printf("hash length %d ", (int) hex.size()); printf("hash length %d ", (int) hex.size());
vector<char> signature_r(1024, 0); vector<char> signature_r(1024, 0);
vector<char> signature_s(1024, 0); vector<char> signature_s(1024, 0);
...@@ -442,11 +450,13 @@ TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") { ...@@ -442,11 +450,13 @@ TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") {
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
printf("the end of ecdsa test\n"); printf("the end of ecdsa test\n");
} }
TEST_CASE("Test test", "[test_test]") { TEST_CASE("Test test", "[test_test]") {
autoconfirm = true; resetDB();
initEnclave(); setOptions(true, false, true);
initAll(false, true, init_SEK);
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
int err_status = 0; int err_status = 0;
...@@ -457,16 +467,8 @@ TEST_CASE("Test test", "[test_test]") { ...@@ -457,16 +467,8 @@ TEST_CASE("Test test", "[test_test]") {
status = generate_ecdsa_key(eid, &err_status, errMsg.data(), encr_pr_key.data(), &enc_len, pub_key_x.data(), status = generate_ecdsa_key(eid, &err_status, errMsg.data(), encr_pr_key.data(), &enc_len, pub_key_x.data(),
pub_key_y.data()); pub_key_y.data());
//printf("\nerrMsg %s\n", errMsg );
REQUIRE(status == SGX_SUCCESS);
//printf("\nwas pub_key_x %s: \n", pub_key_x);
//printf("\nwas pub_key_y %s: \n", pub_key_y);
//printf("\nencr priv_key %s: \n");
//for ( int i = 0; i < 1024 ; i++) REQUIRE(status == SGX_SUCCESS);
// printf("%u ", encr_pr_key[i]);
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
...@@ -474,9 +476,9 @@ TEST_CASE("Test test", "[test_test]") { ...@@ -474,9 +476,9 @@ 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]") {
autoconfirm = true; resetDB();
//init_all(); setOptions(true, false, true);
initEnclave(); initAll(false, true, init_SEK);
int err_status = 0; int err_status = 0;
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
...@@ -485,7 +487,6 @@ TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") { ...@@ -485,7 +487,6 @@ TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") {
vector<char> pub_key_y(1024, 0); vector<char> pub_key_y(1024, 0);
uint32_t enc_len = 0; uint32_t enc_len = 0;
//printf("before %p\n", pub_key_x);
status = generate_ecdsa_key(eid, &err_status, errMsg.data(), encr_pr_key.data(), &enc_len, pub_key_x.data(), status = generate_ecdsa_key(eid, &err_status, errMsg.data(), encr_pr_key.data(), &enc_len, pub_key_x.data(),
pub_key_y.data()); pub_key_y.data());
...@@ -513,7 +514,8 @@ TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") { ...@@ -513,7 +514,8 @@ TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") {
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
} }
/*TEST_CASE( "verification test", "[verify]" ) { /*
* ( "verification test", "[verify]" ) {
char* pubshares = "0d72c21fc5a43452ad5f36699822309149ce6ce2cdce50dafa896e873f1b8ddd12f65a2e9c39c617a1f695f076b33b236b47ed773901fc2762f8b6f63277f5e30d7080be8e98c97f913d1920357f345dc0916c1fcb002b7beb060aa8b6b473a011bfafe9f8a5d8ea4c643ca4101e5119adbef5ae64f8dfb39cd10f1e69e31c591858d7eaca25b4c412fe909ca87ca7aadbf6d97d32d9b984e93d436f13d43ec31f40432cc750a64ac239cad6b8f78c1f1dd37427e4ff8c1cc4fe1c950fcbcec10ebfd79e0c19d0587adafe6db4f3c63ea9a329724a8804b63a9422e6898c0923209e828facf3a073254ec31af4231d999ba04eb5b7d1e0056d742a65b766f2f3"; char* pubshares = "0d72c21fc5a43452ad5f36699822309149ce6ce2cdce50dafa896e873f1b8ddd12f65a2e9c39c617a1f695f076b33b236b47ed773901fc2762f8b6f63277f5e30d7080be8e98c97f913d1920357f345dc0916c1fcb002b7beb060aa8b6b473a011bfafe9f8a5d8ea4c643ca4101e5119adbef5ae64f8dfb39cd10f1e69e31c591858d7eaca25b4c412fe909ca87ca7aadbf6d97d32d9b984e93d436f13d43ec31f40432cc750a64ac239cad6b8f78c1f1dd37427e4ff8c1cc4fe1c950fcbcec10ebfd79e0c19d0587adafe6db4f3c63ea9a329724a8804b63a9422e6898c0923209e828facf3a073254ec31af4231d999ba04eb5b7d1e0056d742a65b766f2f3";
...@@ -549,17 +551,14 @@ string ConvertDecToHex(string dec, int numBytes = 32) { ...@@ -549,17 +551,14 @@ string ConvertDecToHex(string dec, int numBytes = 32) {
TEST_CASE("BLS_DKG test", "[bls_dkg]") { TEST_CASE("BLS_DKG test", "[bls_dkg]") {
useHTTPS = 0; resetDB();
printDebugInfo = 1; setOptions(true, false, true);
cerr << "test started" << endl;
initAll(false, true, init_SEK); initAll(false, true, init_SEK);
cerr << "Server inited" << endl;
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;
reset_db();
int n = 16, t = 16; int n = 16, t = 16;
Json::Value EthKeys[n]; Json::Value EthKeys[n];
...@@ -678,20 +677,19 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") { ...@@ -678,20 +677,19 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
BLSPublicKey common_public(make_shared<map<size_t, shared_ptr<BLSPublicKeyShare>>>(koefs_pkeys_map), t, n); BLSPublicKey common_public(make_shared<map<size_t, shared_ptr<BLSPublicKeyShare>>>(koefs_pkeys_map), t, n);
REQUIRE(common_public.VerifySigWithHelper(hash_arr, commonSig, t, n)); REQUIRE(common_public.VerifySigWithHelper(hash_arr, commonSig, t, n));
sgx_destroy_enclave(eid);
} }
TEST_CASE("API test", "[api_test]") { TEST_CASE("API test", "[api_test]") {
autoconfirm = true; setOptions(true, false, true);
//DEBUG_PRINT = 1;
useHTTPS = 0;
//cerr << __GNUC__ << endl;
cerr << "API test started" << endl;
initAll(false, true, init_SEK); initAll(false, true, init_SEK);
//HttpServer httpserver(1025); //HttpServer httpserver(1025);
//SGXWalletServer s(httpserver, //SGXWalletServer s(httpserver,
// JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0) // JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
// s.StartListening(); // s.StartListening();
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
...@@ -788,8 +786,8 @@ TEST_CASE("API test", "[api_test]") { ...@@ -788,8 +786,8 @@ TEST_CASE("API test", "[api_test]") {
} }
TEST_CASE("getServerStatus test", "[getServerStatus_test]") { TEST_CASE("getServerStatus test", "[getServerStatus_test]") {
autoconfirm = true; resetDB();
useHTTPS = 0; setOptions(true, false, true);
initAll(false, true, init_SEK); initAll(false, true, init_SEK);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
...@@ -802,7 +800,6 @@ void SendRPCRequest() { ...@@ -802,7 +800,6 @@ void SendRPCRequest() {
cout << "Hello from thread " << this_thread::get_id() << endl; cout << "Hello from thread " << this_thread::get_id() << endl;
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
reset_db();
int n = 16, t = 16; int n = 16, t = 16;
...@@ -910,10 +907,8 @@ void SendRPCRequest() { ...@@ -910,10 +907,8 @@ void SendRPCRequest() {
} }
TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") { TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
autoconfirm = true; resetDB();
useHTTPS = 0; setOptions(true, false, true);
printDebugInfo = 1;
encryptKeys = 1;
initAll(false, true, init_SEK); initAll(false, true, init_SEK);
...@@ -931,15 +926,11 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") { ...@@ -931,15 +926,11 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
} }
TEST_CASE("ecdsa API test", "[ecdsa_api_test]") { TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
autoconfirm = true; resetDB();
printDebugInfo = 1; setOptions(true, false, true);
useHTTPS = 0;
encryptKeys = 1;
cerr << "ecdsa_api_test started" << endl;
initAll(false, true, init_SEK); initAll(false, true, init_SEK);
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
...@@ -983,20 +974,14 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") { ...@@ -983,20 +974,14 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
} }
TEST_CASE("dkg API test", "[dkg_api_test]") { TEST_CASE("dkg API test", "[dkg_api_test]") {
autoconfirm = true; resetDB();
printDebugInfo = 1; setOptions(true, false, true);
useHTTPS = 0;
cerr << "dkg_api_test started" << endl;
initAll(false, true, init_SEK); initAll(false, true, init_SEK);
cerr << "Server inited" << endl;
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;
reset_db();
string polyName = "POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"; string polyName = "POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1";
Json::Value genPoly = c.generateDKGPoly(polyName, 2); Json::Value genPoly = c.generateDKGPoly(polyName, 2);
...@@ -1061,21 +1046,16 @@ TEST_CASE("dkg API test", "[dkg_api_test]") { ...@@ -1061,21 +1046,16 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
} }
TEST_CASE("isPolyExists test", "[is_poly_test]") { TEST_CASE("isPolyExists test", "[is_poly_test]") {
autoconfirm = true; resetDB();
printDebugInfo = 1; setOptions(true, false, true);
useHTTPS = 0;
cerr << "is_poly_test started" << endl;
initAll(false, true, init_SEK); initAll(false, true, init_SEK);
cerr << "Server inited" << endl;
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;
reset_db();
string polyName = "POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"; string polyName = "POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1";
Json::Value genPoly = c.generateDKGPoly(polyName, 2); Json::Value genPoly = c.generateDKGPoly(polyName, 2);
cout << genPoly << endl; cout << genPoly << endl;
...@@ -1087,19 +1067,16 @@ TEST_CASE("isPolyExists test", "[is_poly_test]") { ...@@ -1087,19 +1067,16 @@ TEST_CASE("isPolyExists test", "[is_poly_test]") {
cout << polyDoesNotExist << endl; cout << polyDoesNotExist << endl;
REQUIRE(!polyDoesNotExist["IsExist"].asBool()); REQUIRE(!polyDoesNotExist["IsExist"].asBool());
sgx_destroy_enclave(eid);
} }
TEST_CASE("AES_DKG test", "[aes_dkg]") { TEST_CASE("AES_DKG test", "[aes_dkg]") {
autoconfirm = true; resetDB();
useHTTPS = 0; setOptions(true, false, true);
printDebugInfo = 1;
encryptKeys = 1;
reset_db();
cerr << "test started" << endl; cerr << "test started" << endl;
initAll(false, true, init_SEK); initAll(false, true, init_SEK);
cerr << "Server inited" << endl;
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;
...@@ -1222,14 +1199,10 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") { ...@@ -1222,14 +1199,10 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
} }
TEST_CASE("bls_sign_api test", "[bls_sign]") { TEST_CASE("bls_sign_api test", "[bls_sign]") {
autoconfirm = true; resetDB();
useHTTPS = 0; setOptions(true, false, true);
printDebugInfo = 1;
encryptKeys = 1;
cerr << "test started" << endl;
initAll(false, true, init_SEK); initAll(false, true, init_SEK);
cerr << "Server inited" << endl;
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;
...@@ -1253,22 +1226,21 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") { ...@@ -1253,22 +1226,21 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
// BLSPublicKeyShare pubKey(make_shared<vector<string>>(pubKey_vect), t, n); // BLSPublicKeyShare pubKey(make_shared<vector<string>>(pubKey_vect), t, n);
// REQUIRE( pubKey.VerifySigWithHelper(hash_arr, make_shared<BLSSigShare>(sig) , t, n)); // REQUIRE( pubKey.VerifySigWithHelper(hash_arr, make_shared<BLSSigShare>(sig) , t, n));
sgx_destroy_enclave(eid);
} }
TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") { TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") {
{ resetDB();
autoconfirm = true; setOptions(true, false, true);
printDebugInfo = 1;
useHTTPS = 0;
initAll(false, true, init_SEK); initAll(false, true, init_SEK);
//init_enclave();
int errStatus = -1; int errStatus = -1;
vector<char> errMsg(BUF_LEN, 0);; vector<char> errMsg(BUF_LEN, 0);;
uint32_t enc_len; uint32_t enc_len;
string key = "123456789"; string key = "123456789";
vector<uint8_t> encrypted_key(BUF_LEN,0); vector<uint8_t> encrypted_key(BUF_LEN, 0);
status = encrypt_key_aes(eid, &errStatus, errMsg.data(), key.c_str(), encrypted_key.data(), &enc_len); status = encrypt_key_aes(eid, &errStatus, errMsg.data(), key.c_str(), encrypted_key.data(), &enc_len);
...@@ -1284,7 +1256,7 @@ TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") { ...@@ -1284,7 +1256,7 @@ TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") {
REQUIRE(key.compare(decr_key.data()) == 0); REQUIRE(key.compare(decr_key.data()) == 0);
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
}
} }
......
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