Unverified Commit 1d56b136 authored by kladko's avatar kladko

SKALE-2454-add-logs-to-enclave

parent 83409277
...@@ -30,11 +30,8 @@ ...@@ -30,11 +30,8 @@
#define EXTERNC #define EXTERNC
#endif #endif
//EXTERNC void init_all(); #include "stddef.h"
// #include "stdint.h"
//EXTERNC void init_daemon();
//
//EXTERNC void init_enclave();
EXTERNC bool bls_sign(const char* encryptedKeyHex, const char* hashHex, size_t t, size_t n, EXTERNC bool bls_sign(const char* encryptedKeyHex, const char* hashHex, size_t t, size_t n,
size_t signerIndex, char* _sig); size_t signerIndex, char* _sig);
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
EXTERNC void setFullOptions(int _printDebugInfo, EXTERNC void setFullOptions(int _printDebugInfo,
int _printTraceInfo, int _useHTTPS, int _autoconfirm, int _encryptKeys); int _printTraceInfo, int _useHTTPS, int _autoconfirm, int _encryptKeys);
EXTERNC void setOptions(int _printDebugInfo, EXTERNC void setOptions(int _printDebugInfo,
int _printTraceInfo, int _useHTTPS, int _autoconfirm); int _printTraceInfo, int _useHTTPS, int _autoconfirm);
......
...@@ -62,7 +62,7 @@ void initUserSpace() { ...@@ -62,7 +62,7 @@ void initUserSpace() {
} }
void initEnclave() { void initEnclave(uint32_t _logLevel) {
eid = 0; eid = 0;
updated = 0; updated = 0;
...@@ -95,7 +95,7 @@ void initEnclave() { ...@@ -95,7 +95,7 @@ void initEnclave() {
spdlog::info("Enclave created and started successfully"); spdlog::info("Enclave created and started successfully");
status = trustedEnclaveInit(eid, 0); status = trustedEnclaveInit(eid, _logLevel);
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
spdlog::error("trustedEnclaveInit failed: {}", status); spdlog::error("trustedEnclaveInit failed: {}", status);
exit(1); exit(1);
...@@ -108,12 +108,12 @@ void initEnclave() { ...@@ -108,12 +108,12 @@ void initEnclave() {
int sgxServerInited = 0; int sgxServerInited = 0;
void initAll(bool _checkCert, bool _autoSign) { void initAll(uint32_t _logLevel, bool _checkCert, bool _autoSign) {
cout << "Running sgxwallet version:" << SGXWALLET_VERSION << endl; cout << "Running sgxwallet version:" << SGXWALLET_VERSION << endl;
CHECK_STATE(sgxServerInited == 0) CHECK_STATE(sgxServerInited == 0)
sgxServerInited = 1; sgxServerInited = 1;
initEnclave(); initEnclave(_logLevel);
initUserSpace(); initUserSpace();
initSEK(); initSEK();
......
...@@ -24,17 +24,19 @@ ...@@ -24,17 +24,19 @@
#ifndef SGXWALLET_SERVERINIT_H #ifndef SGXWALLET_SERVERINIT_H
#define SGXWALLET_SERVERINIT_H #define SGXWALLET_SERVERINIT_H
#include "stdint.h"
#ifdef __cplusplus #ifdef __cplusplus
#define EXTERNC extern "C" #define EXTERNC extern "C"
#else #else
#define EXTERNC #define EXTERNC
#endif #endif
EXTERNC void initAll(bool _checkCert, bool _autoSign); EXTERNC void initAll(uint32_t _logLevel, bool _checkCert, bool _autoSign);
EXTERNC void initUserSpace(); EXTERNC void initUserSpace();
EXTERNC void initEnclave(); EXTERNC void initEnclave(uint32_t _logLevel);
......
...@@ -47,7 +47,7 @@ void oc_printf (const char *str) { ...@@ -47,7 +47,7 @@ void oc_printf (const char *str) {
/* Proxy/Bridge will check the length and null-terminate /* Proxy/Bridge will check the length and null-terminate
* the input string to prevent buffer overflow. * the input string to prevent buffer overflow.
* */ * */
fprintf(stderr, "***ENCLAVE_LOG***: %s", str); fprintf(stderr, "%s", str);
} }
......
...@@ -37,11 +37,12 @@ ...@@ -37,11 +37,12 @@
#include "DHDkg.h" #include "DHDkg.h"
using namespace std;
std::string stringFromFr(libff::alt_bn128_Fr& _el) { string stringFromFr(libff::alt_bn128_Fr& _el) {
mpz_t t; mpz_t t;
mpz_init(t); mpz_init(t);
...@@ -53,11 +54,11 @@ std::string stringFromFr(libff::alt_bn128_Fr& _el) { ...@@ -53,11 +54,11 @@ std::string stringFromFr(libff::alt_bn128_Fr& _el) {
char *tmp = mpz_get_str(arr, 10, t); char *tmp = mpz_get_str(arr, 10, t);
mpz_clear(t); mpz_clear(t);
return std::string(tmp); return string(tmp);
} }
template<class T> template<class T>
std::string ConvertToString(T field_elem, int base = 10) { string ConvertToString(T field_elem, int base = 10) {
mpz_t t; mpz_t t;
mpz_init(t); mpz_init(t);
...@@ -68,13 +69,13 @@ std::string ConvertToString(T field_elem, int base = 10) { ...@@ -68,13 +69,13 @@ std::string ConvertToString(T field_elem, int base = 10) {
char * tmp = mpz_get_str(arr, base, t); char * tmp = mpz_get_str(arr, base, t);
mpz_clear(t); mpz_clear(t);
std::string output = tmp; string output = tmp;
return output; return output;
} }
std::string ConvertG2ToString(const libff::alt_bn128_G2 & elem, int base = 10, std::string delim = ":"){ string ConvertG2ToString(const libff::alt_bn128_G2 & elem, int base = 10, string delim = ":"){
std::string result; string result;
result += ConvertToString(elem.X.c0); result += ConvertToString(elem.X.c0);
result += delim; result += delim;
result += ConvertToString(elem.X.c1); result += ConvertToString(elem.X.c1);
...@@ -86,17 +87,17 @@ std::string ConvertG2ToString(const libff::alt_bn128_G2 & elem, int base = 10, s ...@@ -86,17 +87,17 @@ std::string ConvertG2ToString(const libff::alt_bn128_G2 & elem, int base = 10, s
return result; return result;
} }
std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* coeffs, const char symbol){ vector<libff::alt_bn128_Fr> SplitStringToFr(const char* coeffs, const char symbol){
std::string str(coeffs); string str(coeffs);
std::string delim; string delim;
delim.push_back(symbol); delim.push_back(symbol);
std::vector<libff::alt_bn128_Fr> tokens; vector<libff::alt_bn128_Fr> tokens;
size_t prev = 0, pos = 0; size_t prev = 0, pos = 0;
do do
{ {
pos = str.find(delim, prev); pos = str.find(delim, prev);
if (pos == std::string::npos) pos = str.length(); if (pos == string::npos) pos = str.length();
std::string token = str.substr(prev, pos-prev); string token = str.substr(prev, pos-prev);
if (!token.empty()) { if (!token.empty()) {
libff::alt_bn128_Fr coeff(token.c_str()); libff::alt_bn128_Fr coeff(token.c_str());
tokens.push_back(coeff); tokens.push_back(coeff);
...@@ -110,7 +111,7 @@ std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* coeffs, const char ...@@ -110,7 +111,7 @@ std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* coeffs, const char
int gen_dkg_poly( char* secret, unsigned _t ){ int gen_dkg_poly( char* secret, unsigned _t ){
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
std::string result; string result;
for (size_t i = 0; i < _t; ++i) { for (size_t i = 0; i < _t; ++i) {
libff::alt_bn128_Fr cur_coef = libff::alt_bn128_Fr::random_element(); libff::alt_bn128_Fr cur_coef = libff::alt_bn128_Fr::random_element();
...@@ -129,7 +130,7 @@ int gen_dkg_poly( char* secret, unsigned _t ){ ...@@ -129,7 +130,7 @@ int gen_dkg_poly( char* secret, unsigned _t ){
return 0; return 0;
} }
libff::alt_bn128_Fr PolynomialValue(const std::vector<libff::alt_bn128_Fr>& pol, libff::alt_bn128_Fr point, unsigned _t) { libff::alt_bn128_Fr PolynomialValue(const vector<libff::alt_bn128_Fr>& pol, libff::alt_bn128_Fr point, unsigned _t) {
libff::alt_bn128_Fr value = libff::alt_bn128_Fr::zero(); libff::alt_bn128_Fr value = libff::alt_bn128_Fr::zero();
...@@ -149,9 +150,9 @@ libff::alt_bn128_Fr PolynomialValue(const std::vector<libff::alt_bn128_Fr>& pol, ...@@ -149,9 +150,9 @@ libff::alt_bn128_Fr PolynomialValue(const std::vector<libff::alt_bn128_Fr>& pol,
void calc_secret_shares(const char* decrypted_coeffs, char * secret_shares, // calculates secret shares in base 10 to a string secret_shares, void calc_secret_shares(const char* decrypted_coeffs, char * secret_shares, // calculates secret shares in base 10 to a string secret_shares,
unsigned _t, unsigned _n) { // separated by ":" unsigned _t, unsigned _n) { // separated by ":"
// calculate for each node a list of secret values that will be used for verification // calculate for each node a list of secret values that will be used for verification
std::string result; string result;
char symbol = ':'; char symbol = ':';
std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol); vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
for (size_t i = 0; i < _n; ++i) { for (size_t i = 0; i < _n; ++i) {
libff::alt_bn128_Fr secret_share = PolynomialValue(poly, libff::alt_bn128_Fr(i + 1), _t); libff::alt_bn128_Fr secret_share = PolynomialValue(poly, libff::alt_bn128_Fr(i + 1), _t);
...@@ -167,13 +168,13 @@ int calc_secret_share(const char* decrypted_coeffs, char * s_share, ...@@ -167,13 +168,13 @@ int calc_secret_share(const char* decrypted_coeffs, char * s_share,
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
char symbol = ':'; char symbol = ':';
std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol); vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
if ( poly.size() != _t){ if ( poly.size() != _t){
return 1; return 1;
} }
libff::alt_bn128_Fr secret_share = PolynomialValue(poly, libff::alt_bn128_Fr(ind), _t); libff::alt_bn128_Fr secret_share = PolynomialValue(poly, libff::alt_bn128_Fr(ind), _t);
std::string cur_share = ConvertToString(secret_share, 16);//stringFromFr(secret_share); string cur_share = ConvertToString(secret_share, 16);//stringFromFr(secret_share);
int n_zeroes = 64 - cur_share.size(); int n_zeroes = 64 - cur_share.size();
cur_share.insert(0, n_zeroes, '0'); cur_share.insert(0, n_zeroes, '0');
...@@ -187,17 +188,17 @@ void calc_secret_shareG2_old(const char* decrypted_coeffs, char * s_shareG2, ...@@ -187,17 +188,17 @@ void calc_secret_shareG2_old(const char* decrypted_coeffs, char * s_shareG2,
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
char symbol = ':'; char symbol = ':';
std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol); vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
// if ( poly.size() != _t){ // if ( poly.size() != _t){
// //"t != poly.size()" + // //"t != poly.size()" +
// //strncpy(s_shareG2, std::to_string(poly.size()).c_str(), 18); // //strncpy(s_shareG2, to_string(poly.size()).c_str(), 18);
// } // }
libff::alt_bn128_Fr secret_share = PolynomialValue(poly, libff::alt_bn128_Fr(ind), _t); libff::alt_bn128_Fr secret_share = PolynomialValue(poly, libff::alt_bn128_Fr(ind), _t);
libff::alt_bn128_G2 secret_shareG2 = secret_share * libff::alt_bn128_G2::one(); libff::alt_bn128_G2 secret_shareG2 = secret_share * libff::alt_bn128_G2::one();
std::string secret_shareG2_str = ConvertG2ToString(secret_shareG2); string secret_shareG2_str = ConvertG2ToString(secret_shareG2);
strncpy(s_shareG2, secret_shareG2_str.c_str(), secret_shareG2_str.length() + 1); strncpy(s_shareG2, secret_shareG2_str.c_str(), secret_shareG2_str.length() + 1);
//strncpy(s_shareG2, decrypted_coeffs, 320); //strncpy(s_shareG2, decrypted_coeffs, 320);
...@@ -222,7 +223,7 @@ int calc_secret_shareG2(const char* s_share, char * s_shareG2){ ...@@ -222,7 +223,7 @@ int calc_secret_shareG2(const char* s_share, char * s_shareG2){
secret_shareG2.to_affine_coordinates(); secret_shareG2.to_affine_coordinates();
std::string secret_shareG2_str = ConvertG2ToString(secret_shareG2); string secret_shareG2_str = ConvertG2ToString(secret_shareG2);
strncpy(s_shareG2, secret_shareG2_str.c_str(), secret_shareG2_str.length() + 1); strncpy(s_shareG2, secret_shareG2_str.c_str(), secret_shareG2_str.length() + 1);
...@@ -233,16 +234,16 @@ int calc_public_shares(const char* decrypted_coeffs, char * public_shares, ...@@ -233,16 +234,16 @@ int calc_public_shares(const char* decrypted_coeffs, char * public_shares,
unsigned _t) { unsigned _t) {
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
// calculate for each node a list of public shares // calculate for each node a list of public shares
std::string result; string result;
char symbol = ':'; char symbol = ':';
std::vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol); vector<libff::alt_bn128_Fr> poly = SplitStringToFr(decrypted_coeffs, symbol);
if (poly.size() != _t){ if (poly.size() != _t){
return 1; return 1;
} }
for (size_t i = 0; i < _t; ++i) { for (size_t i = 0; i < _t; ++i) {
libff::alt_bn128_G2 pub_share = poly.at(i) * libff::alt_bn128_G2::one() ; libff::alt_bn128_G2 pub_share = poly.at(i) * libff::alt_bn128_G2::one() ;
pub_share.to_affine_coordinates(); pub_share.to_affine_coordinates();
std::string pub_share_str = ConvertG2ToString(pub_share); string pub_share_str = ConvertG2ToString(pub_share);
result += pub_share_str + ","; result += pub_share_str + ",";
} }
strncpy(public_shares, result.c_str(), result.length()); strncpy(public_shares, result.c_str(), result.length());
...@@ -250,7 +251,7 @@ int calc_public_shares(const char* decrypted_coeffs, char * public_shares, ...@@ -250,7 +251,7 @@ int calc_public_shares(const char* decrypted_coeffs, char * public_shares,
} }
//extern "C" int __gmpz_set_str (mpz_ptr, const char *, int); //extern "C" int __gmpz_set_str (mpz_ptr, const char *, int);
std::string ConvertHexToDec(std::string hex_str){ string ConvertHexToDec(string hex_str){
mpz_t dec; mpz_t dec;
mpz_init(dec); mpz_init(dec);
...@@ -269,10 +270,10 @@ std::string ConvertHexToDec(std::string hex_str){ ...@@ -269,10 +270,10 @@ std::string ConvertHexToDec(std::string hex_str){
int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int ind ){ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int ind ){
std::string pub_shares_str = public_shares; string pub_shares_str = public_shares;
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
std::vector<libff::alt_bn128_G2> pub_shares; vector<libff::alt_bn128_G2> pub_shares;
uint64_t share_length = 256; uint64_t share_length = 256;
uint8_t coord_length = 64; uint8_t coord_length = 64;
...@@ -280,10 +281,10 @@ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int in ...@@ -280,10 +281,10 @@ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int in
libff::alt_bn128_G2 pub_share; libff::alt_bn128_G2 pub_share;
uint64_t pos0 = share_length * i; uint64_t pos0 = share_length * i;
std::string x_c0_str = ConvertHexToDec(pub_shares_str.substr(pos0, coord_length)); string x_c0_str = ConvertHexToDec(pub_shares_str.substr(pos0, coord_length));
std::string x_c1_str = ConvertHexToDec(pub_shares_str.substr(pos0 + coord_length, coord_length)); string x_c1_str = ConvertHexToDec(pub_shares_str.substr(pos0 + coord_length, coord_length));
std::string y_c0_str = ConvertHexToDec(pub_shares_str.substr(pos0 + 2 * coord_length, coord_length)); string y_c0_str = ConvertHexToDec(pub_shares_str.substr(pos0 + 2 * coord_length, coord_length));
std::string y_c1_str = ConvertHexToDec(pub_shares_str.substr(pos0 + 3 * coord_length, coord_length)); string y_c1_str = ConvertHexToDec(pub_shares_str.substr(pos0 + 3 * coord_length, coord_length));
if (x_c0_str == "false" || x_c1_str == "false" || y_c0_str == "false" || y_c1_str == "false"){ if (x_c0_str == "false" || x_c1_str == "false" || y_c0_str == "false" || y_c1_str == "false"){
return 2; return 2;
} }
...@@ -296,10 +297,10 @@ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int in ...@@ -296,10 +297,10 @@ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int in
//for ( int j = 0; j < 4; j++) { //for ( int j = 0; j < 4; j++) {
//uint64_t pos0 = share_length * j; //uint64_t pos0 = share_length * j;
//std::string coord = ConvertHexToDec(pub_shares_str.substr(pos0 + j * coord_length, coord_length)); //string coord = ConvertHexToDec(pub_shares_str.substr(pos0 + j * coord_length, coord_length));
// if ( i == 0) { // if ( i == 0) {
// memset(public_shares, 0, strlen(public_shares)); // memset(public_shares, 0, strlen(public_shares));
// std::string coord = ConvertToString(pub_share.Y.c1); // string coord = ConvertToString(pub_share.Y.c1);
// strncpy(public_shares, coord.c_str(), coord.length()); // strncpy(public_shares, coord.c_str(), coord.length());
// } // }
//} //}
...@@ -318,7 +319,7 @@ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int in ...@@ -318,7 +319,7 @@ int Verification ( char * public_shares, mpz_t decr_secret_share, int _t, int in
libff::alt_bn128_Fr sshare(tmp); libff::alt_bn128_Fr sshare(tmp);
// strncpy(public_shares, tmp, strlen(tmp)); // strncpy(public_shares, tmp, strlen(tmp));
// std::string res = ConvertHexToDec("fe43567238abcdef98760"); // string res = ConvertHexToDec("fe43567238abcdef98760");
// strncpy(public_shares, res.c_str(), res.length()); // strncpy(public_shares, res.c_str(), res.length());
...@@ -367,7 +368,7 @@ int calc_bls_public_key(char* skey_hex, char* pub_key){ ...@@ -367,7 +368,7 @@ int calc_bls_public_key(char* skey_hex, char* pub_key){
libff::alt_bn128_G2 public_key = bls_skey * libff::alt_bn128_G2::one(); libff::alt_bn128_G2 public_key = bls_skey * libff::alt_bn128_G2::one();
public_key.to_affine_coordinates(); public_key.to_affine_coordinates();
std::string result = ConvertG2ToString(public_key); string result = ConvertG2ToString(public_key);
strncpy(pub_key, result.c_str(), result.length()); strncpy(pub_key, result.c_str(), result.length());
......
...@@ -277,11 +277,11 @@ bool hex2carray(const char * _hex, uint64_t *_bin_len, ...@@ -277,11 +277,11 @@ bool hex2carray(const char * _hex, uint64_t *_bin_len,
enum log_level {L_TRACE = 0, L_DEBUG = 1, L_INFO = 2,L_WARNING = 3, L_ERROR = 4 }; enum log_level {L_TRACE = 0, L_DEBUG = 1, L_INFO = 2,L_WARNING = 3, L_ERROR = 4 };
uint32_t logLevel = 2; uint32_t globalLogLevel_ = 2;
void logMsg(log_level _level, char* _msg) { void logMsg(log_level _level, char* _msg) {
if (_level < logLevel) if (_level < globalLogLevel_)
return; return;
if (!_msg) { if (!_msg) {
...@@ -289,13 +289,26 @@ void logMsg(log_level _level, char* _msg) { ...@@ -289,13 +289,26 @@ void logMsg(log_level _level, char* _msg) {
return; return;
} }
oc_printf("***ENCLAVE_LOG***:");
oc_printf(_msg); oc_printf(_msg);
oc_printf("\n");
} }
EXTERNC void LOG_INFO(char* msg) {}; EXTERNC void LOG_INFO(char* _msg) {
EXTERNC void LOG_WARNING(char* _msg) {}; logMsg(L_INFO, _msg);
EXTERNC void LOG_ERROR(char* _msg) {}; };
EXTERNC void LOG_DEBUG(char* _msg) {}; EXTERNC void LOG_WARNING(char* _msg) {
EXTERNC void LOG_TRACE(char* _msg) {}; logMsg(L_WARNING, _msg);
};
EXTERNC void LOG_ERROR(char* _msg) {
logMsg(L_ERROR, _msg);
};
EXTERNC void LOG_DEBUG(char* _msg) {
logMsg(L_DEBUG, _msg);
};
EXTERNC void LOG_TRACE(char* _msg) {
logMsg(L_TRACE, _msg);
};
...@@ -59,6 +59,8 @@ EXTERNC void LOG_DEBUG(char* _msg); ...@@ -59,6 +59,8 @@ EXTERNC void LOG_DEBUG(char* _msg);
EXTERNC void LOG_TRACE(char* _msg); EXTERNC void LOG_TRACE(char* _msg);
extern uint32_t globalLogLevel_;
#endif //SGXWALLET_ENCLAVECOMMON_H #endif //SGXWALLET_ENCLAVECOMMON_H
...@@ -54,7 +54,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -54,7 +54,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "EnclaveConstants.h" #include "EnclaveConstants.h"
#include "EnclaveConstants.h" #include "EnclaveCommon.h"
uint8_t decryptedDkgPoly[DKG_BUFER_LENGTH]; uint8_t decryptedDkgPoly[DKG_BUFER_LENGTH];
...@@ -75,8 +75,12 @@ void free_function(void *, size_t); ...@@ -75,8 +75,12 @@ void free_function(void *, size_t);
void trustedEnclaveInit(uint32_t _logLevel) { void trustedEnclaveInit(uint32_t _logLevel) {
LOG_DEBUG (__FUNCTION__);
globalLogLevel_ = _logLevel;
oc_printf("Initing enclave: library\n");
oc_realloc_func = &reallocate_function; oc_realloc_func = &reallocate_function;
oc_free_func = &free_function; oc_free_func = &free_function;
...@@ -84,6 +88,8 @@ void trustedEnclaveInit(uint32_t _logLevel) { ...@@ -84,6 +88,8 @@ void trustedEnclaveInit(uint32_t _logLevel) {
mp_set_memory_functions(NULL, oc_realloc_func, oc_free_func); mp_set_memory_functions(NULL, oc_realloc_func, oc_free_func);
enclave_init(); enclave_init();
LOG_DEBUG("SUCCESS");
} }
void free_function(void *ptr, size_t sz) { void free_function(void *ptr, size_t sz) {
...@@ -134,6 +140,7 @@ void trustedEMpfDiv(mpf_t *c_un, mpf_t *a_un, mpf_t *b_un) {} ...@@ -134,6 +140,7 @@ void trustedEMpfDiv(mpf_t *c_un, mpf_t *a_un, mpf_t *b_un) {}
void trustedGenerateEcdsaKey(int *errStatus, char *err_string, void trustedGenerateEcdsaKey(int *errStatus, char *err_string,
uint8_t *encrypted_key, uint32_t *enc_len, char *pub_key_x, char *pub_key_y) { uint8_t *encrypted_key, uint32_t *enc_len, char *pub_key_x, char *pub_key_y) {
LOG_DEBUG (__FUNCTION__);
domain_parameters curve = domain_parameters_init(); domain_parameters curve = domain_parameters_init();
domain_parameters_load_curve(curve, secp256k1); domain_parameters_load_curve(curve, secp256k1);
...@@ -210,7 +217,7 @@ void trustedGenerateEcdsaKey(int *errStatus, char *err_string, ...@@ -210,7 +217,7 @@ void trustedGenerateEcdsaKey(int *errStatus, char *err_string,
void trustedGetPublicEcdsaKey(int *errStatus, char *err_string, void trustedGetPublicEcdsaKey(int *errStatus, char *err_string,
uint8_t *encrypted_key, uint32_t dec_len, char *pub_key_x, char *pub_key_y) { uint8_t *encrypted_key, uint32_t dec_len, char *pub_key_x, char *pub_key_y) {
//uint32_t dec_len = 0; LOG_DEBUG (__FUNCTION__);
domain_parameters curve = domain_parameters_init(); domain_parameters curve = domain_parameters_init();
domain_parameters_load_curve(curve, secp256k1); domain_parameters_load_curve(curve, secp256k1);
...@@ -282,6 +289,8 @@ void trustedGetPublicEcdsaKey(int *errStatus, char *err_string, ...@@ -282,6 +289,8 @@ void trustedGetPublicEcdsaKey(int *errStatus, char *err_string,
void trustedEcdsaSign(int *errStatus, char *err_string, uint8_t *encrypted_key, uint32_t dec_len, void trustedEcdsaSign(int *errStatus, char *err_string, uint8_t *encrypted_key, uint32_t dec_len,
unsigned char *hash, char *sig_r, char *sig_s, uint8_t *sig_v, int base) { unsigned char *hash, char *sig_r, char *sig_s, uint8_t *sig_v, int base) {
LOG_DEBUG (__FUNCTION__);
char* arr_m = NULL; char* arr_m = NULL;
char* arr_r = NULL; char* arr_r = NULL;
char* arr_s; char* arr_s;
...@@ -380,7 +389,7 @@ void trustedEcdsaSign(int *errStatus, char *err_string, uint8_t *encrypted_key, ...@@ -380,7 +389,7 @@ void trustedEcdsaSign(int *errStatus, char *err_string, uint8_t *encrypted_key,
void trustedEncryptKey(int *errStatus, char *err_string, char *key, void trustedEncryptKey(int *errStatus, char *err_string, char *key,
uint8_t *encrypted_key, uint32_t *enc_len) { uint8_t *encrypted_key, uint32_t *enc_len) {
LOG_DEBUG (__FUNCTION__);
*errStatus = UNKNOWN_ERROR; *errStatus = UNKNOWN_ERROR;
...@@ -446,7 +455,7 @@ void trustedEncryptKey(int *errStatus, char *err_string, char *key, ...@@ -446,7 +455,7 @@ void trustedEncryptKey(int *errStatus, char *err_string, char *key,
void trustedDecryptKey(int *errStatus, char *err_string, uint8_t *encrypted_key, void trustedDecryptKey(int *errStatus, char *err_string, uint8_t *encrypted_key,
uint32_t enc_len, char *key) { uint32_t enc_len, char *key) {
LOG_DEBUG (__FUNCTION__);
uint32_t decLen; uint32_t decLen;
...@@ -479,17 +488,6 @@ void trustedDecryptKey(int *errStatus, char *err_string, uint8_t *encrypted_key, ...@@ -479,17 +488,6 @@ void trustedDecryptKey(int *errStatus, char *err_string, uint8_t *encrypted_key,
return; return;
} }
// check that key is padded with 0s
// for (int i = keyLen; i < MAX_KEY_LENGTH; i++) {
// if (key[i] != 0) {
// snprintf(err_string, BUF_LEN, "Unpadded key");
// return;
// }
// }
//strncpy(key, "2f993bb09f16c402a27dae868c02791bca7fcf564f1c9e2ba50b142b843a4b60", BUF_LEN);
*errStatus = 0; *errStatus = 0;
return; return;
...@@ -501,9 +499,11 @@ void trustedBlsSignMessage(int *errStatus, char *err_string, uint8_t *encrypted_ ...@@ -501,9 +499,11 @@ void trustedBlsSignMessage(int *errStatus, char *err_string, uint8_t *encrypted_
char *_hashY, char *signature) { char *_hashY, char *signature) {
LOG_DEBUG (__FUNCTION__);
char key[BUF_LEN]; char key[BUF_LEN];
char *sig = (char *) calloc(BUF_LEN, 1); char *sig = (char *) calloc(BUF_LEN, 1);
// char sig[2 * BUF_LEN];
...@@ -528,6 +528,8 @@ void trustedBlsSignMessage(int *errStatus, char *err_string, uint8_t *encrypted_ ...@@ -528,6 +528,8 @@ void trustedBlsSignMessage(int *errStatus, char *err_string, uint8_t *encrypted_
void trustedGenDkgSecret(int *errStatus, char *err_string, uint8_t *encrypted_dkg_secret, uint32_t *enc_len, size_t _t) { void trustedGenDkgSecret(int *errStatus, char *err_string, uint8_t *encrypted_dkg_secret, uint32_t *enc_len, size_t _t) {
LOG_DEBUG (__FUNCTION__);
char dkg_secret[DKG_BUFER_LENGTH]; char dkg_secret[DKG_BUFER_LENGTH];
if (gen_dkg_poly(dkg_secret, _t) != 0) { if (gen_dkg_poly(dkg_secret, _t) != 0) {
...@@ -556,7 +558,9 @@ void trustedGenDkgSecret(int *errStatus, char *err_string, uint8_t *encrypted_dk ...@@ -556,7 +558,9 @@ void trustedGenDkgSecret(int *errStatus, char *err_string, uint8_t *encrypted_dk
void trustedDecryptDkgSecret(int *errStatus, char *err_string, uint8_t *encrypted_dkg_secret, uint8_t *decrypted_dkg_secret, void trustedDecryptDkgSecret(int *errStatus, char *err_string, uint8_t *encrypted_dkg_secret, uint8_t *decrypted_dkg_secret,
uint32_t *dec_len) { uint32_t *dec_len) {
//uint32_t dec_size = DKG_BUFER_LENGTH;//sgx_get_encrypt_txt_len( ( sgx_sealed_data_t *)encrypted_dkg_secret); LOG_DEBUG (__FUNCTION__);
uint32_t decr_len; uint32_t decr_len;
sgx_status_t status = sgx_unseal_data( sgx_status_t status = sgx_unseal_data(
(const sgx_sealed_data_t *) encrypted_dkg_secret, NULL, 0, decrypted_dkg_secret, &decr_len); (const sgx_sealed_data_t *) encrypted_dkg_secret, NULL, 0, decrypted_dkg_secret, &decr_len);
...@@ -574,12 +578,12 @@ void trustedGetSecretShares(int *errStatus, char *err_string, uint8_t *encrypted ...@@ -574,12 +578,12 @@ void trustedGetSecretShares(int *errStatus, char *err_string, uint8_t *encrypted
char *secret_shares, char *secret_shares,
unsigned _t, unsigned _n) { unsigned _t, unsigned _n) {
LOG_DEBUG (__FUNCTION__);
char decrypted_dkg_secret[DKG_BUFER_LENGTH]; char decrypted_dkg_secret[DKG_BUFER_LENGTH];
uint32_t decr_len; uint32_t decr_len;
trustedDecryptDkgSecret(errStatus, err_string, encrypted_dkg_secret, (uint8_t *) decrypted_dkg_secret, &decr_len); trustedDecryptDkgSecret(errStatus, err_string, encrypted_dkg_secret, (uint8_t *) decrypted_dkg_secret, &decr_len);
//sgx_status_t status = sgx_unseal_data(
// (const sgx_sealed_data_t *)encrypted_dkg_secret, NULL, 0, (uint8_t*)decrypted_dkg_secret, &decr_len);
if (*errStatus != 0) { if (*errStatus != 0) {
snprintf(err_string, BUF_LEN, "sgx_unseal_data - encrypted_dkg_secret failed with status %d", *errStatus); snprintf(err_string, BUF_LEN, "sgx_unseal_data - encrypted_dkg_secret failed with status %d", *errStatus);
...@@ -597,6 +601,8 @@ void trustedGetPublicShares(int *errStatus, char *err_string, uint8_t *encrypted ...@@ -597,6 +601,8 @@ void trustedGetPublicShares(int *errStatus, char *err_string, uint8_t *encrypted
char *public_shares, char *public_shares,
unsigned _t, unsigned _n) { unsigned _t, unsigned _n) {
LOG_DEBUG (__FUNCTION__);
char *decrypted_dkg_secret = (char *) calloc(DKG_MAX_SEALED_LEN, 1); char *decrypted_dkg_secret = (char *) calloc(DKG_MAX_SEALED_LEN, 1);
uint32_t decr_len; uint32_t decr_len;
trustedDecryptDkgSecret(errStatus, err_string, (uint8_t *) encrypted_dkg_secret, decrypted_dkg_secret, &decr_len); trustedDecryptDkgSecret(errStatus, err_string, (uint8_t *) encrypted_dkg_secret, decrypted_dkg_secret, &decr_len);
...@@ -632,6 +638,8 @@ void trustedSetEncryptedDkgPoly(int *errStatus, char *err_string, uint8_t *encry ...@@ -632,6 +638,8 @@ void trustedSetEncryptedDkgPoly(int *errStatus, char *err_string, uint8_t *encry
void trustedGetEncryptedSecretShare(int *errStatus, char *err_string, uint8_t *encrypted_skey, uint32_t *dec_len, void trustedGetEncryptedSecretShare(int *errStatus, char *err_string, uint8_t *encrypted_skey, uint32_t *dec_len,
char *result_str, char *s_shareG2, char *pub_keyB, uint8_t _t, uint8_t _n, uint8_t ind) { char *result_str, char *s_shareG2, char *pub_keyB, uint8_t _t, uint8_t _n, uint8_t ind) {
LOG_DEBUG (__FUNCTION__);
char skey[ECDSA_SKEY_LEN]; char skey[ECDSA_SKEY_LEN];
char pub_key_x[BUF_LEN]; char pub_key_x[BUF_LEN];
memset(pub_key_x, 0, BUF_LEN); memset(pub_key_x, 0, BUF_LEN);
...@@ -646,7 +654,6 @@ void trustedGetEncryptedSecretShare(int *errStatus, char *err_string, uint8_t *e ...@@ -646,7 +654,6 @@ void trustedGetEncryptedSecretShare(int *errStatus, char *err_string, uint8_t *e
if (*errStatus != 0) { if (*errStatus != 0) {
return; return;
} }
// snprintf(err_string, BUF_LEN,"pub_key_x is %s", pub_key_x);
*dec_len = enc_len; *dec_len = enc_len;
...@@ -685,35 +692,22 @@ void trustedGetEncryptedSecretShare(int *errStatus, char *err_string, uint8_t *e ...@@ -685,35 +692,22 @@ void trustedGetEncryptedSecretShare(int *errStatus, char *err_string, uint8_t *e
snprintf(err_string, BUF_LEN, "invalid common_key"); snprintf(err_string, BUF_LEN, "invalid common_key");
return; return;
} }
//snprintf(err_string, BUF_LEN ,"cypher is %s length is %d", cypher, strlen(cypher));
strncpy(result_str, cypher, strlen(cypher)); strncpy(result_str, cypher, strlen(cypher));
strncpy(result_str + strlen(cypher), pub_key_x, strlen(pub_key_x)); strncpy(result_str + strlen(cypher), pub_key_x, strlen(pub_key_x));
strncpy(result_str + strlen(pub_key_x) + strlen(pub_key_y), pub_key_y, strlen(pub_key_y)); strncpy(result_str + strlen(pub_key_x) + strlen(pub_key_y), pub_key_y, strlen(pub_key_y));
// snprintf(err_string, BUF_LEN,"s_share is %s length is %d", result_str, strlen(result_str));
//mpz_clear(skey);
//free(skey);
//free(common_key);
//free(pub_key_x);
//free(pub_key_y);
//free(s_share);
//free(cypher);
} }
void trustedComplaintResponse(int *errStatus, char *err_string, uint8_t *encryptedDHKey, uint8_t *encrypted_dkg_secret, void trustedComplaintResponse(int *errStatus, char *err_string, uint8_t *encryptedDHKey, uint8_t *encrypted_dkg_secret,
uint32_t *dec_len, uint32_t *dec_len,
char *DH_key, char *s_shareG2, uint8_t _t, uint8_t _n, uint8_t ind1) { char *DH_key, char *s_shareG2, uint8_t _t, uint8_t _n, uint8_t ind1) {
LOG_DEBUG (__FUNCTION__);
uint32_t enc_len; uint32_t enc_len;
// sgx_status_t status = sgx_unseal_data(
// (const sgx_sealed_data_t *)encryptedDHKey, NULL, 0, (uint8_t *)DH_key, &enc_len);
// if (status != SGX_SUCCESS) {
// snprintf(err_string, BUF_LEN,"sgx_unseal_data - encryptedDHKey failed with status %d", status);
// return;
// }
char decrypted_dkg_secret[DKG_BUFER_LENGTH]; char decrypted_dkg_secret[DKG_BUFER_LENGTH];
uint32_t decr_len; uint32_t decr_len;
...@@ -725,17 +719,14 @@ void trustedComplaintResponse(int *errStatus, char *err_string, uint8_t *encrypt ...@@ -725,17 +719,14 @@ void trustedComplaintResponse(int *errStatus, char *err_string, uint8_t *encrypt
calc_secret_shareG2_old(decrypted_dkg_secret, s_shareG2, _t, ind1); calc_secret_shareG2_old(decrypted_dkg_secret, s_shareG2, _t, ind1);
//snprintf(err_string, BUF_LEN,"poly:%s", decrypted_dkg_secret);
// snprintf(err_string, BUF_LEN,"what the ...");
//snprintf(err_string, BUF_LEN,"s_shareG2:%s", s_shareG2);
// free(decrypted_dkg_secret);
} }
void trustedDkgVerify(int *errStatus, char *err_string, const char *public_shares, const char *s_share, void trustedDkgVerify(int *errStatus, char *err_string, const char *public_shares, const char *s_share,
uint8_t *encrypted_key, uint64_t key_len, unsigned _t, int _ind, int *result) { uint8_t *encrypted_key, uint64_t key_len, unsigned _t, int _ind, int *result) {
//uint32_t dec_len = 625;
LOG_DEBUG (__FUNCTION__);
char skey[ECDSA_SKEY_LEN]; char skey[ECDSA_SKEY_LEN];
sgx_status_t status = sgx_unseal_data( sgx_status_t status = sgx_unseal_data(
(const sgx_sealed_data_t *) encrypted_key, NULL, 0, (uint8_t *) skey, &key_len); (const sgx_sealed_data_t *) encrypted_key, NULL, 0, (uint8_t *) skey, &key_len);
...@@ -767,12 +758,7 @@ void trustedDkgVerify(int *errStatus, char *err_string, const char *public_share ...@@ -767,12 +758,7 @@ void trustedDkgVerify(int *errStatus, char *err_string, const char *public_share
} }
//snprintf(err_string, BUF_LEN,"encr_share is %s length is %d", encr_sshare, strlen(encr_sshare)); LOG_DEBUG (__FUNCTION__);
//snprintf(err_string, BUF_LEN,"s_share is %s length is %d", s_share, strlen(s_share));
// snprintf(err_string, BUF_LEN,"sshare is %s\n", decr_sshare);
// snprintf(err_string + 75, BUF_LEN - 75,"common_key is %s\n", common_key);
// snprintf(err_string + 153, BUF_LEN - 153," s_key is %s", skey);
mpz_t s; mpz_t s;
...@@ -793,6 +779,8 @@ void trustedDkgVerify(int *errStatus, char *err_string, const char *public_share ...@@ -793,6 +779,8 @@ void trustedDkgVerify(int *errStatus, char *err_string, const char *public_share
void trustedCreateBlsKey(int *errStatus, char *err_string, const char *s_shares, void trustedCreateBlsKey(int *errStatus, char *err_string, const char *s_shares,
uint8_t *encrypted_key, uint64_t key_len, uint8_t *encr_bls_key, uint32_t *enc_bls_key_len) { uint8_t *encrypted_key, uint64_t key_len, uint8_t *encr_bls_key, uint32_t *enc_bls_key_len) {
LOG_DEBUG (__FUNCTION__);
char skey[ECDSA_SKEY_LEN]; char skey[ECDSA_SKEY_LEN];
sgx_status_t status = sgx_unseal_data( sgx_status_t status = sgx_unseal_data(
(const sgx_sealed_data_t *) encrypted_key, NULL, 0, (uint8_t *) skey, &key_len); (const sgx_sealed_data_t *) encrypted_key, NULL, 0, (uint8_t *) skey, &key_len);
...@@ -809,9 +797,6 @@ void trustedCreateBlsKey(int *errStatus, char *err_string, const char *s_shares, ...@@ -809,9 +797,6 @@ void trustedCreateBlsKey(int *errStatus, char *err_string, const char *s_shares,
mpz_set_ui(sum, 0); mpz_set_ui(sum, 0);
//snprintf(err_string, BUF_LEN,"comon0 is %s len is %d\n", common_key, strlen(common_key));
for (int i = 0; i < num_shares; i++) { for (int i = 0; i < num_shares; i++) {
char encr_sshare[65]; char encr_sshare[65];
strncpy(encr_sshare, s_shares + 192 * i, 64); strncpy(encr_sshare, s_shares + 192 * i, 64);
...@@ -832,9 +817,6 @@ void trustedCreateBlsKey(int *errStatus, char *err_string, const char *s_shares, ...@@ -832,9 +817,6 @@ void trustedCreateBlsKey(int *errStatus, char *err_string, const char *s_shares,
return; return;
} }
//snprintf(err_string + 85*(i+1) , BUF_LEN,"common is %s len is %d\n", common_key, strlen(common_key));
//snprintf(err_string + 201*i , BUF_LEN,"secret is %s",s_share);
char decr_sshare[65]; char decr_sshare[65];
xor_decrypt(common_key, encr_sshare, decr_sshare); xor_decrypt(common_key, encr_sshare, decr_sshare);
...@@ -844,11 +826,6 @@ void trustedCreateBlsKey(int *errStatus, char *err_string, const char *s_shares, ...@@ -844,11 +826,6 @@ void trustedCreateBlsKey(int *errStatus, char *err_string, const char *s_shares,
mpz_clear(sum); mpz_clear(sum);
return; return;
} }
//decr_sshare[64] = 0;
//snprintf(err_string + 158 * i, BUF_LEN,"decr sshare is %s", decr_sshare);
//snprintf(err_string + 158 * i + 79, BUF_LEN," common_key is %s", common_key);
mpz_t decr_secret_share; mpz_t decr_secret_share;
mpz_init(decr_secret_share); mpz_init(decr_secret_share);
...@@ -891,14 +868,6 @@ void trustedCreateBlsKey(int *errStatus, char *err_string, const char *s_shares, ...@@ -891,14 +868,6 @@ void trustedCreateBlsKey(int *errStatus, char *err_string, const char *s_shares,
*enc_bls_key_len = sealedLen; *enc_bls_key_len = sealedLen;
// mpz_t s;
// mpz_init(s);
// mpz_set_str(s, decr_sshare, 16);
//snprintf(err_string, BUF_LEN,"val is %s", decrypted_dkg_secret);
mpz_clear(bls_key); mpz_clear(bls_key);
mpz_clear(sum); mpz_clear(sum);
mpz_clear(q); mpz_clear(q);
...@@ -906,6 +875,8 @@ void trustedCreateBlsKey(int *errStatus, char *err_string, const char *s_shares, ...@@ -906,6 +875,8 @@ void trustedCreateBlsKey(int *errStatus, char *err_string, const char *s_shares,
void trustedGetBlsPubKey(int *errStatus, char *err_string, uint8_t *encrypted_key, uint64_t key_len, char *bls_pub_key) { void trustedGetBlsPubKey(int *errStatus, char *err_string, uint8_t *encrypted_key, uint64_t key_len, char *bls_pub_key) {
LOG_DEBUG (__FUNCTION__);
char skey_hex[ECDSA_SKEY_LEN]; char skey_hex[ECDSA_SKEY_LEN];
uint32_t len = key_len; uint32_t len = key_len;
...@@ -927,6 +898,9 @@ void trustedGetBlsPubKey(int *errStatus, char *err_string, uint8_t *encrypted_ke ...@@ -927,6 +898,9 @@ void trustedGetBlsPubKey(int *errStatus, char *err_string, uint8_t *encrypted_ke
void trustedGenerateSEK(int *errStatus, char *err_string, void trustedGenerateSEK(int *errStatus, char *err_string,
uint8_t *encrypted_SEK, uint32_t *enc_len, char *SEK_hex) { uint8_t *encrypted_SEK, uint32_t *enc_len, char *SEK_hex) {
LOG_DEBUG (__FUNCTION__);
uint8_t SEK_raw[SGX_AESGCM_KEY_SIZE]; uint8_t SEK_raw[SGX_AESGCM_KEY_SIZE];
sgx_read_rand(SEK_raw, SGX_AESGCM_KEY_SIZE); sgx_read_rand(SEK_raw, SGX_AESGCM_KEY_SIZE);
...@@ -948,15 +922,14 @@ void trustedGenerateSEK(int *errStatus, char *err_string, ...@@ -948,15 +922,14 @@ void trustedGenerateSEK(int *errStatus, char *err_string,
return; return;
} }
//strncpy(SEK_hex, SEK, hex_aes_key_length);
*enc_len = sealedLen; *enc_len = sealedLen;
//free(rand_char);
} }
void trustedSetSEK(int *errStatus, char *err_string, uint8_t *encrypted_SEK, uint64_t encr_len) { void trustedSetSEK(int *errStatus, char *err_string, uint8_t *encrypted_SEK, uint64_t encr_len) {
//memset(AES_key, 0, SGX_AESGCM_KEY_SIZE); LOG_DEBUG (__FUNCTION__);
uint8_t aes_key_hex[SGX_AESGCM_KEY_SIZE * 2]; uint8_t aes_key_hex[SGX_AESGCM_KEY_SIZE * 2];
memset(aes_key_hex, 0, SGX_AESGCM_KEY_SIZE * 2); memset(aes_key_hex, 0, SGX_AESGCM_KEY_SIZE * 2);
...@@ -977,6 +950,8 @@ void trustedSetSEK(int *errStatus, char *err_string, uint8_t *encrypted_SEK, uin ...@@ -977,6 +950,8 @@ void trustedSetSEK(int *errStatus, char *err_string, uint8_t *encrypted_SEK, uin
void trustedSetSEK_backup(int *errStatus, char *err_string, void trustedSetSEK_backup(int *errStatus, char *err_string,
uint8_t *encrypted_SEK, uint32_t *enc_len, const char *SEK_hex) { uint8_t *encrypted_SEK, uint32_t *enc_len, const char *SEK_hex) {
LOG_DEBUG (__FUNCTION__);
uint64_t len; uint64_t len;
hex2carray(SEK_hex, &len, (uint8_t *) AES_key); hex2carray(SEK_hex, &len, (uint8_t *) AES_key);
...@@ -990,14 +965,14 @@ void trustedSetSEK_backup(int *errStatus, char *err_string, ...@@ -990,14 +965,14 @@ void trustedSetSEK_backup(int *errStatus, char *err_string,
return; return;
} }
//strncpy(SEK_hex, SEK, hex_aes_key_length);
*enc_len = sealedLen; *enc_len = sealedLen;
} }
void trustedGenerateEcdsaKeyAES(int *errStatus, char *err_string, void trustedGenerateEcdsaKeyAES(int *errStatus, char *err_string,
uint8_t *encrypted_key, uint32_t *enc_len, char *pub_key_x, char *pub_key_y) { uint8_t *encrypted_key, uint32_t *enc_len, char *pub_key_x, char *pub_key_y) {
LOG_DEBUG (__FUNCTION__);
domain_parameters curve = domain_parameters_init(); domain_parameters curve = domain_parameters_init();
domain_parameters_load_curve(curve, secp256k1); domain_parameters_load_curve(curve, secp256k1);
...@@ -1070,6 +1045,8 @@ void trustedGenerateEcdsaKeyAES(int *errStatus, char *err_string, ...@@ -1070,6 +1045,8 @@ void trustedGenerateEcdsaKeyAES(int *errStatus, char *err_string,
void trustedGetPublicEcdsaKeyAES(int *errStatus, char *err_string, void trustedGetPublicEcdsaKeyAES(int *errStatus, char *err_string,
uint8_t *encrypted_key, uint32_t enc_len, char *pub_key_x, char *pub_key_y) { uint8_t *encrypted_key, uint32_t enc_len, char *pub_key_x, char *pub_key_y) {
LOG_DEBUG (__FUNCTION__);
domain_parameters curve = domain_parameters_init(); domain_parameters curve = domain_parameters_init();
domain_parameters_load_curve(curve, secp256k1); domain_parameters_load_curve(curve, secp256k1);
...@@ -1114,10 +1091,10 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *err_string, ...@@ -1114,10 +1091,10 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *err_string,
int base = 16; int base = 16;
int len = mpz_sizeinbase(Pkey->x, base) + 2; int len = mpz_sizeinbase(Pkey->x, base) + 2;
//snprintf(err_string, BUF_LEN, "len = %d\n", len);
char arr_x[len]; char arr_x[len];
char *px = mpz_get_str(arr_x, base, Pkey->x); char *px = mpz_get_str(arr_x, base, Pkey->x);
//snprintf(err_string, BUF_LEN, "arr=%p px=%p\n", arr_x, px);
int n_zeroes = 64 - strlen(arr_x); int n_zeroes = 64 - strlen(arr_x);
for (int i = 0; i < n_zeroes; i++) { for (int i = 0; i < n_zeroes; i++) {
pub_key_x[i] = '0'; pub_key_x[i] = '0';
...@@ -1141,6 +1118,8 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *err_string, ...@@ -1141,6 +1118,8 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *err_string,
void trustedEcdsaSignAES(int *errStatus, char *err_string, uint8_t *encrypted_key, uint32_t enc_len, void trustedEcdsaSignAES(int *errStatus, char *err_string, uint8_t *encrypted_key, uint32_t enc_len,
unsigned char *hash, char *sig_r, char *sig_s, uint8_t *sig_v, int base) { unsigned char *hash, char *sig_r, char *sig_s, uint8_t *sig_v, int base) {
LOG_DEBUG (__FUNCTION__);
domain_parameters curve = domain_parameters_init(); domain_parameters curve = domain_parameters_init();
domain_parameters_load_curve(curve, secp256k1); domain_parameters_load_curve(curve, secp256k1);
...@@ -1190,9 +1169,6 @@ void trustedEcdsaSignAES(int *errStatus, char *err_string, uint8_t *encrypted_ke ...@@ -1190,9 +1169,6 @@ void trustedEcdsaSignAES(int *errStatus, char *err_string, uint8_t *encrypted_ke
return; return;
} }
//char arr_x[mpz_sizeinbase (Pkey->x, 16) + 2];
//char* px = mpz_get_str(arr_x, 16, Pkey->x);
//snprintf(err_string, BUF_LEN,"pub key x %s ", arr_x);
char arr_m[mpz_sizeinbase(msg_mpz, 16) + 2]; char arr_m[mpz_sizeinbase(msg_mpz, 16) + 2];
char *msg = mpz_get_str(arr_m, 16, msg_mpz); char *msg = mpz_get_str(arr_m, 16, msg_mpz);
...@@ -1219,19 +1195,12 @@ void trustedEcdsaSignAES(int *errStatus, char *err_string, uint8_t *encrypted_ke ...@@ -1219,19 +1195,12 @@ void trustedEcdsaSignAES(int *errStatus, char *err_string, uint8_t *encrypted_ke
void trustedEncryptKeyAES(int *errStatus, char *err_string, const char *key, void trustedEncryptKeyAES(int *errStatus, char *err_string, const char *key,
uint8_t *encrypted_key, uint32_t *enc_len) { uint8_t *encrypted_key, uint32_t *enc_len) {
//init(); LOG_DEBUG (__FUNCTION__);
*errStatus = UNKNOWN_ERROR; *errStatus = UNKNOWN_ERROR;
memset(err_string, 0, BUF_LEN); memset(err_string, 0, BUF_LEN);
// checkKey(errStatus, err_string, key);
//
// if (*errStatus != 0) {
// snprintf(err_string + strlen(err_string), BUF_LEN, "check_key failed");
// return;
// }
memset(encrypted_key, 0, BUF_LEN); memset(encrypted_key, 0, BUF_LEN);
int stat = AES_encrypt(key, encrypted_key); int stat = AES_encrypt(key, encrypted_key);
...@@ -1287,7 +1256,6 @@ void trustedDecryptKeyAES(int *errStatus, char *err_string, uint8_t *encrypted_k ...@@ -1287,7 +1256,6 @@ void trustedDecryptKeyAES(int *errStatus, char *err_string, uint8_t *encrypted_k
return; return;
} }
//snprintf(err_string, BUF_LEN, "decr key is %s", key);
if (decLen > MAX_KEY_LENGTH) { if (decLen > MAX_KEY_LENGTH) {
*errStatus = 1; *errStatus = 1;
...@@ -1315,14 +1283,12 @@ void trustedBlsSignMessageAES(int *errStatus, char *err_string, uint8_t *encrypt ...@@ -1315,14 +1283,12 @@ void trustedBlsSignMessageAES(int *errStatus, char *err_string, uint8_t *encrypt
uint32_t enc_len, char *_hashX, uint32_t enc_len, char *_hashX,
char *_hashY, char *signature) { char *_hashY, char *signature) {
LOG_DEBUG (__FUNCTION__);
char key[BUF_LEN]; char key[BUF_LEN];
memset(key, 0, BUF_LEN); memset(key, 0, BUF_LEN);
char sig[BUF_LEN]; char sig[BUF_LEN];
memset(sig, 0, BUF_LEN); memset(sig, 0, BUF_LEN);
//char* sig = (char*) calloc(BUF_LEN, 1);
enclave_init();
int stat = AES_decrypt(encrypted_key, enc_len, key); int stat = AES_decrypt(encrypted_key, enc_len, key);
...@@ -1340,12 +1306,14 @@ void trustedBlsSignMessageAES(int *errStatus, char *err_string, uint8_t *encrypt ...@@ -1340,12 +1306,14 @@ void trustedBlsSignMessageAES(int *errStatus, char *err_string, uint8_t *encrypt
*errStatus = -1; *errStatus = -1;
return; return;
} }
//free(sig);
} }
void void
trustedGenDkgSecretAES(int *errStatus, char *err_string, uint8_t *encrypted_dkg_secret, uint32_t *enc_len, size_t _t) { trustedGenDkgSecretAES(int *errStatus, char *err_string, uint8_t *encrypted_dkg_secret, uint32_t *enc_len, size_t _t) {
LOG_DEBUG (__FUNCTION__);
char dkg_secret[DKG_BUFER_LENGTH];// = (char*)calloc(DKG_BUFER_LENGTH, 1); char dkg_secret[DKG_BUFER_LENGTH];// = (char*)calloc(DKG_BUFER_LENGTH, 1);
memset(dkg_secret, 0, DKG_BUFER_LENGTH); memset(dkg_secret, 0, DKG_BUFER_LENGTH);
...@@ -1384,13 +1352,15 @@ trustedGenDkgSecretAES(int *errStatus, char *err_string, uint8_t *encrypted_dkg_ ...@@ -1384,13 +1352,15 @@ trustedGenDkgSecretAES(int *errStatus, char *err_string, uint8_t *encrypted_dkg_
*errStatus = -333; *errStatus = -333;
} }
// free(dkg_secret);
} }
void void
trustedDecryptDkgSecretAES(int *errStatus, char *err_string, uint8_t *encrypted_dkg_secret, uint8_t *decrypted_dkg_secret, trustedDecryptDkgSecretAES(int *errStatus, char *err_string, uint8_t *encrypted_dkg_secret, uint8_t *decrypted_dkg_secret,
uint32_t *dec_len) { uint32_t *dec_len) {
LOG_DEBUG (__FUNCTION__);
int status = AES_decrypt(encrypted_dkg_secret, dec_len, decrypted_dkg_secret); int status = AES_decrypt(encrypted_dkg_secret, dec_len, decrypted_dkg_secret);
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
...@@ -1398,10 +1368,13 @@ trustedDecryptDkgSecretAES(int *errStatus, char *err_string, uint8_t *encrypted_ ...@@ -1398,10 +1368,13 @@ trustedDecryptDkgSecretAES(int *errStatus, char *err_string, uint8_t *encrypted_
*errStatus = status; *errStatus = status;
return; return;
} }
//*dec_len = decr_len;
} }
void trustedSetEncryptedDkgPolyAES(int *errStatus, char *err_string, uint8_t *encrypted_poly, uint64_t *enc_len) { void trustedSetEncryptedDkgPolyAES(int *errStatus, char *err_string, uint8_t *encrypted_poly, uint64_t *enc_len) {
LOG_DEBUG (__FUNCTION__);
memset(decryptedDkgPoly, 0, DKG_BUFER_LENGTH); memset(decryptedDkgPoly, 0, DKG_BUFER_LENGTH);
int status = AES_decrypt(encrypted_poly, *enc_len, decryptedDkgPoly); int status = AES_decrypt(encrypted_poly, *enc_len, decryptedDkgPoly);
...@@ -1421,8 +1394,6 @@ void trustedGetEncryptedSecretShareAES(int *errStatus, char *err_string, uint8_t ...@@ -1421,8 +1394,6 @@ void trustedGetEncryptedSecretShareAES(int *errStatus, char *err_string, uint8_t
memset(pub_key_x, 0, BUF_LEN); memset(pub_key_x, 0, BUF_LEN);
char pub_key_y[BUF_LEN]; char pub_key_y[BUF_LEN];
memset(pub_key_y, 0, BUF_LEN); memset(pub_key_y, 0, BUF_LEN);
//char *pub_key_x = (char *)calloc(1024, 1);
// char *pub_key_y = (char *)calloc(1024, 1);
uint32_t enc_len; uint32_t enc_len;
...@@ -1430,7 +1401,7 @@ void trustedGetEncryptedSecretShareAES(int *errStatus, char *err_string, uint8_t ...@@ -1430,7 +1401,7 @@ void trustedGetEncryptedSecretShareAES(int *errStatus, char *err_string, uint8_t
if (*errStatus != 0) { if (*errStatus != 0) {
return; return;
} }
// snprintf(err_string, BUF_LEN,"pub_key_x is %s", pub_key_x);
int status = AES_decrypt(encrypted_skey, enc_len, skey); int status = AES_decrypt(encrypted_skey, enc_len, skey);
skey[ECDSA_SKEY_LEN - 1] = 0; skey[ECDSA_SKEY_LEN - 1] = 0;
...@@ -1446,15 +1417,13 @@ void trustedGetEncryptedSecretShareAES(int *errStatus, char *err_string, uint8_t ...@@ -1446,15 +1417,13 @@ void trustedGetEncryptedSecretShareAES(int *errStatus, char *err_string, uint8_t
char *common_key[ECDSA_SKEY_LEN]; char *common_key[ECDSA_SKEY_LEN];
gen_session_key(skey, pub_keyB, common_key); gen_session_key(skey, pub_keyB, common_key);
//snprintf(err_string + 81, BUF_LEN,"pub_key_B is %s length is %d", pub_keyB, strlen(pub_keyB));
//snprintf(err_string + 88, BUF_LEN - 88,"\ncommon key is %s", common_key);
char *s_share[ECDSA_SKEY_LEN]; char *s_share[ECDSA_SKEY_LEN];
//char s_share[65];
if (calc_secret_share(decryptedDkgPoly, s_share, _t, _n, ind) != 0) { if (calc_secret_share(decryptedDkgPoly, s_share, _t, _n, ind) != 0) {
*errStatus = -1; *errStatus = -1;
// snprintf(err_string, BUF_LEN,"t does not match poly degree");
snprintf(err_string, BUF_LEN, decryptedDkgPoly); snprintf(err_string, BUF_LEN, decryptedDkgPoly);
return; return;
} }
...@@ -1473,21 +1442,12 @@ void trustedGetEncryptedSecretShareAES(int *errStatus, char *err_string, uint8_t ...@@ -1473,21 +1442,12 @@ void trustedGetEncryptedSecretShareAES(int *errStatus, char *err_string, uint8_t
snprintf(err_string, BUF_LEN, "invalid common_key"); snprintf(err_string, BUF_LEN, "invalid common_key");
return; return;
} }
//snprintf(err_string, BUF_LEN ,"cypher is %s length is %d", cypher, strlen(cypher));
strncpy(result_str, cypher, strlen(cypher)); strncpy(result_str, cypher, strlen(cypher));
strncpy(result_str + strlen(cypher), pub_key_x, strlen(pub_key_x)); strncpy(result_str + strlen(cypher), pub_key_x, strlen(pub_key_x));
strncpy(result_str + strlen(pub_key_x) + strlen(pub_key_y), pub_key_y, strlen(pub_key_y)); strncpy(result_str + strlen(pub_key_x) + strlen(pub_key_y), pub_key_y, strlen(pub_key_y));
// snprintf(err_string, BUF_LEN,"s_share is %s length is %d", result_str, strlen(result_str));
//mpz_clear(skey);
//free(skey);
//free(common_key);
//free(pub_key_x);
//free(pub_key_y);
//free(s_share);
//free(cypher);
} }
...@@ -1495,9 +1455,11 @@ void trustedGetPublicSharesAES(int *errStatus, char *err_string, uint8_t *encryp ...@@ -1495,9 +1455,11 @@ void trustedGetPublicSharesAES(int *errStatus, char *err_string, uint8_t *encryp
char *public_shares, char *public_shares,
unsigned _t, unsigned _n) { unsigned _t, unsigned _n) {
LOG_DEBUG (__FUNCTION__);
char *decrypted_dkg_secret = (char *) calloc(DKG_MAX_SEALED_LEN, 1); char *decrypted_dkg_secret = (char *) calloc(DKG_MAX_SEALED_LEN, 1);
memset(decrypted_dkg_secret, 0, DKG_MAX_SEALED_LEN); memset(decrypted_dkg_secret, 0, DKG_MAX_SEALED_LEN);
//char decrypted_dkg_secret[ DKG_MAX_SEALED_LEN];
int status = AES_decrypt(encrypted_dkg_secret, enc_len, decrypted_dkg_secret); int status = AES_decrypt(encrypted_dkg_secret, enc_len, decrypted_dkg_secret);
...@@ -1508,25 +1470,25 @@ void trustedGetPublicSharesAES(int *errStatus, char *err_string, uint8_t *encryp ...@@ -1508,25 +1470,25 @@ void trustedGetPublicSharesAES(int *errStatus, char *err_string, uint8_t *encryp
return; return;
} }
//strncpy(err_string, decrypted_dkg_secret, 1024);
// strncpy(err_string, "before calc_public_shares ", 1024);
if (calc_public_shares(decrypted_dkg_secret, public_shares, _t) != 0) { if (calc_public_shares(decrypted_dkg_secret, public_shares, _t) != 0) {
*errStatus = -1; *errStatus = -1;
snprintf(err_string, BUF_LEN, "t does not match polynomial in db"); snprintf(err_string, BUF_LEN, "t does not match polynomial in db");
return; return;
} }
//free(decrypted_dkg_secret);
} }
void trustedDkgVerifyAES(int *errStatus, char *err_string, const char *public_shares, const char *s_share, void trustedDkgVerifyAES(int *errStatus, char *err_string, const char *public_shares, const char *s_share,
uint8_t *encrypted_key, uint64_t enc_len, unsigned _t, int _ind, int *result) { uint8_t *encrypted_key, uint64_t enc_len, unsigned _t, int _ind, int *result) {
//uint32_t dec_len = 625;
LOG_DEBUG (__FUNCTION__);
char skey[ECDSA_SKEY_LEN]; char skey[ECDSA_SKEY_LEN];
memset(skey, 0, ECDSA_SKEY_LEN); memset(skey, 0, ECDSA_SKEY_LEN);
int status = AES_decrypt(encrypted_key, enc_len, skey); int status = AES_decrypt(encrypted_key, enc_len, skey);
//skey[ECDSA_SKEY_LEN - 1] = 0;
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
snprintf(err_string, BUF_LEN, "AES_decrypt failed (in trustedDkgVerifyAES) with status %d", status); snprintf(err_string, BUF_LEN, "AES_decrypt failed (in trustedDkgVerifyAES) with status %d", status);
...@@ -1537,13 +1499,13 @@ void trustedDkgVerifyAES(int *errStatus, char *err_string, const char *public_sh ...@@ -1537,13 +1499,13 @@ void trustedDkgVerifyAES(int *errStatus, char *err_string, const char *public_sh
char encr_sshare[ECDSA_SKEY_LEN]; char encr_sshare[ECDSA_SKEY_LEN];
memset(encr_sshare, 0, ECDSA_SKEY_LEN); memset(encr_sshare, 0, ECDSA_SKEY_LEN);
strncpy(encr_sshare, s_share, ECDSA_SKEY_LEN - 1); strncpy(encr_sshare, s_share, ECDSA_SKEY_LEN - 1);
//encr_sshare[ECDSA_SKEY_LEN - 1] = 0;
char common_key[ECDSA_SKEY_LEN]; char common_key[ECDSA_SKEY_LEN];
memset(common_key, 0, ECDSA_SKEY_LEN); memset(common_key, 0, ECDSA_SKEY_LEN);
session_key_recover(skey, s_share, common_key); session_key_recover(skey, s_share, common_key);
//common_key[ECDSA_SKEY_LEN - 1] = 0;
if (common_key == NULL || strlen(common_key) == 0) { if (common_key == NULL || strlen(common_key) == 0) {
*errStatus = 1; *errStatus = 1;
snprintf(err_string, BUF_LEN, "invalid common_key"); snprintf(err_string, BUF_LEN, "invalid common_key");
...@@ -1558,15 +1520,6 @@ void trustedDkgVerifyAES(int *errStatus, char *err_string, const char *public_sh ...@@ -1558,15 +1520,6 @@ void trustedDkgVerifyAES(int *errStatus, char *err_string, const char *public_sh
snprintf(err_string, BUF_LEN, "invalid common_key"); snprintf(err_string, BUF_LEN, "invalid common_key");
return; return;
} }
//decr_sshare[ECDSA_SKEY_LEN - 1] = 0;
//snprintf(err_string, BUF_LEN,"encr_share is %s length is %d", encr_sshare, strlen(encr_sshare));
//snprintf(err_string, BUF_LEN,"s_share is %s length is %d", s_share, strlen(s_share));
// snprintf(err_string, BUF_LEN,"sshare is %s\n", decr_sshare);
// snprintf(err_string + 75, BUF_LEN - 75,"common_key is %s\n", common_key);
// snprintf(err_string + 153, BUF_LEN - 153," s_key is %s", skey);
mpz_t s; mpz_t s;
mpz_init(s); mpz_init(s);
...@@ -1586,6 +1539,8 @@ void trustedDkgVerifyAES(int *errStatus, char *err_string, const char *public_sh ...@@ -1586,6 +1539,8 @@ void trustedDkgVerifyAES(int *errStatus, char *err_string, const char *public_sh
void trustedCreateBlsKeyAES(int *errStatus, char *err_string, const char *s_shares, void trustedCreateBlsKeyAES(int *errStatus, char *err_string, const char *s_shares,
uint8_t *encrypted_key, uint64_t key_len, uint8_t *encr_bls_key, uint32_t *enc_bls_key_len) { uint8_t *encrypted_key, uint64_t key_len, uint8_t *encr_bls_key, uint32_t *enc_bls_key_len) {
LOG_DEBUG (__FUNCTION__);
char skey[ECDSA_SKEY_LEN]; char skey[ECDSA_SKEY_LEN];
int status = AES_decrypt(encrypted_key, key_len, skey); int status = AES_decrypt(encrypted_key, key_len, skey);
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
...@@ -1602,8 +1557,6 @@ void trustedCreateBlsKeyAES(int *errStatus, char *err_string, const char *s_shar ...@@ -1602,8 +1557,6 @@ void trustedCreateBlsKeyAES(int *errStatus, char *err_string, const char *s_shar
mpz_set_ui(sum, 0); mpz_set_ui(sum, 0);
//snprintf(err_string, BUF_LEN,"comon0 is %s len is %d\n", common_key, strlen(common_key));
for (int i = 0; i < num_shares; i++) { for (int i = 0; i < num_shares; i++) {
char encr_sshare[65]; char encr_sshare[65];
...@@ -1625,9 +1578,6 @@ void trustedCreateBlsKeyAES(int *errStatus, char *err_string, const char *s_shar ...@@ -1625,9 +1578,6 @@ void trustedCreateBlsKeyAES(int *errStatus, char *err_string, const char *s_shar
return; return;
} }
//snprintf(err_string + 85*(i+1) , BUF_LEN,"common is %s len is %d\n", common_key, strlen(common_key));
//snprintf(err_string + 201*i , BUF_LEN,"secret is %s",s_share);
char decr_sshare[65]; char decr_sshare[65];
xor_decrypt(common_key, encr_sshare, decr_sshare); xor_decrypt(common_key, encr_sshare, decr_sshare);
...@@ -1639,10 +1589,6 @@ void trustedCreateBlsKeyAES(int *errStatus, char *err_string, const char *s_shar ...@@ -1639,10 +1589,6 @@ void trustedCreateBlsKeyAES(int *errStatus, char *err_string, const char *s_shar
} }
decr_sshare[64] = 0; decr_sshare[64] = 0;
//snprintf(err_string + 158 * i, BUF_LEN,"decr sshare is %s", decr_sshare);
//snprintf(err_string + 158 * i + 79, BUF_LEN," common_key is %s", common_key);
mpz_t decr_secret_share; mpz_t decr_secret_share;
mpz_init(decr_secret_share); mpz_init(decr_secret_share);
if (mpz_set_str(decr_secret_share, decr_sshare, 16) == -1) { if (mpz_set_str(decr_secret_share, decr_sshare, 16) == -1) {
...@@ -1692,6 +1638,8 @@ void trustedCreateBlsKeyAES(int *errStatus, char *err_string, const char *s_shar ...@@ -1692,6 +1638,8 @@ void trustedCreateBlsKeyAES(int *errStatus, char *err_string, const char *s_shar
void void
trustedGetBlsPubKeyAES(int *errStatus, char *err_string, uint8_t *encrypted_key, uint64_t key_len, char *bls_pub_key) { trustedGetBlsPubKeyAES(int *errStatus, char *err_string, uint8_t *encrypted_key, uint64_t key_len, char *bls_pub_key) {
LOG_DEBUG (__FUNCTION__);
char skey_hex[ECDSA_SKEY_LEN]; char skey_hex[ECDSA_SKEY_LEN];
uint32_t len = key_len; uint32_t len = key_len;
......
...@@ -33,15 +33,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -33,15 +33,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <stdbool.h>
#include "sgxwallet.h"
#include "BLSCrypto.h" #include "BLSCrypto.h"
#include "ServerInit.h" #include "ServerInit.h"
#include "SEKManager.h" #include "SEKManager.h"
#include "SGXWalletServer.h"
#include "sgxwallet.h"
#include <stdbool.h>
void usage() { void usage() {
...@@ -66,6 +65,8 @@ void printUsage() { ...@@ -66,6 +65,8 @@ void printUsage() {
fprintf(stderr, "-y Do not ask user to acknoledge receipt of backup key \n"); fprintf(stderr, "-y Do not ask user to acknoledge receipt of backup key \n");
} }
enum log_level {L_TRACE = 0, L_DEBUG = 1, L_INFO = 2,L_WARNING = 3, L_ERROR = 4 };
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
bool encryptKeysOption = false; bool encryptKeysOption = false;
...@@ -128,7 +129,17 @@ int main(int argc, char *argv[]) { ...@@ -128,7 +129,17 @@ int main(int argc, char *argv[]) {
setFullOptions(printDebugInfoOption, printTraceInfoOption, useHTTPSOption, autoconfirmOption, encryptKeysOption); setFullOptions(printDebugInfoOption, printTraceInfoOption, useHTTPSOption, autoconfirmOption, encryptKeysOption);
initAll(checkClientCertOption, autoSignClientCertOption);
uint32_t enclaveLogLevel = L_INFO;
if (printTraceInfoOption) {
enclaveLogLevel = L_TRACE;
} else if (printDebugInfoOption) {
enclaveLogLevel = L_DEBUG;
}
initAll(enclaveLogLevel, checkClientCertOption, autoSignClientCertOption);
while (true) { while (true) {
sleep(10); sleep(10);
......
...@@ -135,7 +135,7 @@ void destroyEnclave() { ...@@ -135,7 +135,7 @@ void destroyEnclave() {
TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") { TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
auto key = encryptTestKey(); auto key = encryptTestKey();
REQUIRE(key != nullptr); REQUIRE(key != nullptr);
} }
...@@ -144,7 +144,7 @@ TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") { ...@@ -144,7 +144,7 @@ TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") {
TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") { TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
//init_enclave(); //init_enclave();
...@@ -176,7 +176,7 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") { ...@@ -176,7 +176,7 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
TEST_CASE("DKG gen test", "[dkg-gen]") { TEST_CASE("DKG gen test", "[dkg-gen]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
vector<uint8_t> encryptedDKGSecret(BUF_LEN, 0); vector<uint8_t> encryptedDKGSecret(BUF_LEN, 0);
...@@ -264,7 +264,7 @@ libff::alt_bn128_G2 VectStringToG2(const vector<string> &G2_str_vect) { ...@@ -264,7 +264,7 @@ 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]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
...@@ -339,7 +339,7 @@ TEST_CASE("DKG public shares test", "[dkg-pub-shares]") { ...@@ -339,7 +339,7 @@ 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]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
vector<char> errMsg(BUF_LEN, 0); vector<char> errMsg(BUF_LEN, 0);
...@@ -376,7 +376,7 @@ TEST_CASE("DKG encrypted secret shares test", "[dkg-encr-sshares]") { ...@@ -376,7 +376,7 @@ TEST_CASE("DKG encrypted secret shares test", "[dkg-encr-sshares]") {
TEST_CASE("DKG verification test", "[dkg-verify]") { TEST_CASE("DKG verification test", "[dkg-verify]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
vector<char> errMsg(BUF_LEN, 0); vector<char> errMsg(BUF_LEN, 0);
...@@ -417,7 +417,7 @@ TEST_CASE("DKG verification test", "[dkg-verify]") { ...@@ -417,7 +417,7 @@ TEST_CASE("DKG verification test", "[dkg-verify]") {
TEST_CASE("ECDSA keygen and signature test", "[ecdsa]") { TEST_CASE("ECDSA keygen and signature test", "[ecdsa]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
vector<char> errMsg(BUF_LEN, 0); vector<char> errMsg(BUF_LEN, 0);
...@@ -461,7 +461,7 @@ TEST_CASE("ECDSA keygen and signature test", "[ecdsa]") { ...@@ -461,7 +461,7 @@ TEST_CASE("ECDSA keygen and signature test", "[ecdsa]") {
TEST_CASE("Test test", "[test]") { TEST_CASE("Test test", "[test]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
vector<char> errMsg(BUF_LEN, 0); vector<char> errMsg(BUF_LEN, 0);
int errStatus = 0; int errStatus = 0;
...@@ -483,7 +483,7 @@ TEST_CASE("Test test", "[test]") { ...@@ -483,7 +483,7 @@ TEST_CASE("Test test", "[test]") {
TEST_CASE("get public ECDSA key", "[get-pub-ecdsa-key]") { TEST_CASE("get public ECDSA key", "[get-pub-ecdsa-key]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
int errStatus = 0; int errStatus = 0;
vector<char> errMsg(BUF_LEN, 0); vector<char> errMsg(BUF_LEN, 0);
...@@ -551,7 +551,7 @@ string ConvertDecToHex(string dec, int numBytes = 32) { ...@@ -551,7 +551,7 @@ string ConvertDecToHex(string dec, int numBytes = 32) {
TEST_CASE("BLS_DKG test", "[bls-dkg]") { TEST_CASE("BLS_DKG test", "[bls-dkg]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
...@@ -679,7 +679,7 @@ TEST_CASE("BLS_DKG test", "[bls-dkg]") { ...@@ -679,7 +679,7 @@ TEST_CASE("BLS_DKG test", "[bls-dkg]") {
TEST_CASE("API test", "[api]") { TEST_CASE("API test", "[api]") {
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
//HttpServer httpserver(1025); //HttpServer httpserver(1025);
//SGXWalletServer s(httpserver, //SGXWalletServer s(httpserver,
...@@ -734,7 +734,7 @@ TEST_CASE("API test", "[api]") { ...@@ -734,7 +734,7 @@ TEST_CASE("API test", "[api]") {
TEST_CASE("getServerStatus test", "[get-server-status]") { TEST_CASE("getServerStatus test", "[get-server-status]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
REQUIRE(c.getServerStatus()["status"] == 0); REQUIRE(c.getServerStatus()["status"] == 0);
...@@ -841,7 +841,7 @@ TEST_CASE("ManySimultaneousThreads", "[many-threads-test]") { ...@@ -841,7 +841,7 @@ TEST_CASE("ManySimultaneousThreads", "[many-threads-test]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
vector<thread> threads; vector<thread> threads;
int num_threads = 4; int num_threads = 4;
...@@ -859,7 +859,7 @@ TEST_CASE("ManySimultaneousThreads", "[many-threads-test]") { ...@@ -859,7 +859,7 @@ TEST_CASE("ManySimultaneousThreads", "[many-threads-test]") {
TEST_CASE("ecdsa API test", "[ecdsa-api]") { TEST_CASE("ecdsa API test", "[ecdsa-api]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
...@@ -907,7 +907,7 @@ TEST_CASE("ecdsa API test", "[ecdsa-api]") { ...@@ -907,7 +907,7 @@ TEST_CASE("ecdsa API test", "[ecdsa-api]") {
TEST_CASE("dkg API test", "[dkg-api]") { TEST_CASE("dkg API test", "[dkg-api]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
...@@ -980,7 +980,7 @@ TEST_CASE("dkg API test", "[dkg-api]") { ...@@ -980,7 +980,7 @@ TEST_CASE("dkg API test", "[dkg-api]") {
TEST_CASE("isPolyExists test", "[is-poly]") { TEST_CASE("isPolyExists test", "[is-poly]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
...@@ -1008,7 +1008,7 @@ TEST_CASE("AES_DKG test", "[aes-dkg]") { ...@@ -1008,7 +1008,7 @@ TEST_CASE("AES_DKG test", "[aes-dkg]") {
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
...@@ -1122,7 +1122,7 @@ TEST_CASE("AES_DKG test", "[aes-dkg]") { ...@@ -1122,7 +1122,7 @@ TEST_CASE("AES_DKG test", "[aes-dkg]") {
TEST_CASE("bls_sign_api test", "[bls-sign]") { TEST_CASE("bls_sign_api test", "[bls-sign]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
...@@ -1144,7 +1144,7 @@ TEST_CASE("bls_sign_api test", "[bls-sign]") { ...@@ -1144,7 +1144,7 @@ TEST_CASE("bls_sign_api test", "[bls-sign]") {
TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") { TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") {
resetDB(); resetDB();
setOptions(false, false, false, true); setOptions(false, false, false, true);
initAll(false, true); initAll(0, false, true);
int errStatus = -1; int errStatus = -1;
......
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