Unverified Commit 08dd658d authored by svetaro's avatar svetaro

SKALE-1795 Comment some checks

parent a0f4a55d
......@@ -5,8 +5,10 @@
#include "ECDSACrypto.h"
#include "BLSCrypto.h"
#include "sgxwallet.h"
#include <iostream>
#include "RPCException.h"
#include <iostream>
#include <gmp.h>
#include <random>
......@@ -21,6 +23,10 @@ std::vector<std::string> gen_ecdsa_key(){
uint32_t enc_len = 0;
status = generate_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y );
if ( err_status != 0 ){
std::cerr << "RPCException thrown" << std::endl;
throw RPCException(-666, errMsg) ;
}
std::vector<std::string> keys(3);
std::cerr << "account key is " << errMsg << std::endl;
char *hexEncrKey = (char *) calloc(2*BUF_LEN, 1);
......@@ -70,6 +76,9 @@ std::string get_ecdsa_pubkey(const char* encryptedKeyHex){
hex2carray(encryptedKeyHex, &enc_len, encr_pr_key);
status = get_public_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y );
if ( err_status != 0){
throw RPCException(-666, errMsg) ;
}
std::string pubKey = std::string(pub_key_x) + std::string(pub_key_y);
std::cerr << "err str " << errMsg << std::endl;
......@@ -100,6 +109,9 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char
std::cerr << "encrypted len" << dec_len << std::endl;
status = ecdsa_sign1(eid, &err_status, errMsg, encr_key, ECDSA_ENCR_LEN, (unsigned char*)hashHex, signature_r, signature_s, &signature_v, base );
if ( err_status != 0){
throw RPCException(-666, errMsg ) ;
}
std::cerr << "signature r in ecdsa_sign_hash "<< signature_r << std::endl;
std::cerr << "signature s in ecdsa_sign_hash "<< signature_s << std::endl;
......
......@@ -49,7 +49,7 @@ SGXWalletServer::SGXWalletServer(AbstractServerConnector &connector,
int init_server() {
hs = new HttpServer(1026);
hs = new HttpServer(1025);
s = new SGXWalletServer(*hs,
JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
......@@ -73,7 +73,9 @@ importBLSKeyShareImpl(int index, const std::string &_keyShare, const std::string
result["encryptedKeyShare"] = "";
try {
if ( !checkName(_keyShare, "BLS_KEY")){
throw RPCException(INVALID_POLY_NAME, "Invalid BLSKey name");
}
char *encryptedKeyShareHex = encryptBLSKeyShare2Hex(&errStatus, errMsg, _keyShare.c_str());
if (encryptedKeyShareHex == nullptr) {
......@@ -113,7 +115,11 @@ Json::Value blsSignMessageHashImpl(const std::string &keyShareName, const std::s
try {
value = readFromDb(keyShareName);
if ( !checkName(keyShareName, "BLS_KEY")){
throw RPCException(INVALID_POLY_NAME, "Invalid BLSKey name");
}
value = readFromDb(keyShareName);
} catch (RPCException _e) {
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
......@@ -169,7 +175,7 @@ Json::Value generateECDSAKeyImpl() {
try {
keys = gen_ecdsa_key();
if (keys.size() == 0 ) {
throw RPCException(UNKNOWN_ERROR, "");
throw RPCException(UNKNOWN_ERROR, "key was not generated");
}
// std::cerr << "write encr key" << keys.at(0) << std::endl;
std::cerr << "encr key length is" << keys.at(0).length() << std::endl;
......@@ -434,9 +440,9 @@ Json::Value DKGVerificationImpl(const std::string& publicShares, const std::stri
if( !check_n_t(n, t) || ind > n || ind < 0){
throw RPCException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t ");
}
if ( !checkHex(SecretShare, SECRET_SHARE_NUM_BYTES)){
throw RPCException(INVALID_HEX, "Invalid Secret share");
}
// if ( !checkHex(SecretShare, SECRET_SHARE_NUM_BYTES)){
// throw RPCException(INVALID_HEX, "Invalid Secret share");
// }
//std::string keyName = polyName + "_" + std::to_string(ind);
//std::shared_ptr<std::string> encryptedKeyHex_ptr = readFromDb(EthKeyName, "");
......@@ -472,23 +478,23 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s
result["errorMessage"] = "wrong length of secret shares";
return result;
}
if ( !checkECDSAKeyName(EthKeyName)){
throw RPCException(INVALID_ECDSA_KEY_NAME, "Invalid ECDSA key name");
}
// if ( !checkECDSAKeyName(EthKeyName)){
// throw RPCException(INVALID_ECDSA_KEY_NAME, "Invalid ECDSA key name");
// }
if ( !checkName(polyName, "POLY")){
throw RPCException(INVALID_POLY_NAME, "Invalid polynomial name");
}
if ( !checkName(BLSKeyName, "BLS_KEY")){
throw RPCException(INVALID_POLY_NAME, "Invalid polynomial name");
throw RPCException(INVALID_POLY_NAME, "Invalid BLS key name");
}
std::vector<std::string> sshares_vect;
std::cerr << "sshares are " << SecretShare << std::endl;
char sshares[192 * n + 1];
for ( int i = 0; i < n ; i++){
std::string cur_share = SecretShare.substr(192*i, 192*i + 192);
if ( !checkHex(SecretShare, SECRET_SHARE_NUM_BYTES)){
throw RPCException(INVALID_HEX, "Invalid Secret share");
}
// if ( !checkHex(SecretShare, SECRET_SHARE_NUM_BYTES)){
// throw RPCException(INVALID_HEX, "Invalid Secret share");
// }
// std::cerr << " share " << i << " is " << cur_share << std::endl;
sshares_vect.push_back(cur_share);
// std::cerr << sshares_vect[i] << " ";
......@@ -532,7 +538,7 @@ Json::Value GetBLSPublicKeyShareImpl(const std::string & BLSKeyName){
try {
if ( !checkName(BLSKeyName, "BLS_KEY")){
throw RPCException(INVALID_POLY_NAME, "Invalid polynomial name");
throw RPCException(INVALID_POLY_NAME, "Invalid BLSKey name");
}
std::shared_ptr<std::string> encryptedKeyHex_ptr = readFromDb(BLSKeyName);
std::cerr << "encr_bls_key_share is " << *encryptedKeyHex_ptr << std::endl;
......
......@@ -132,20 +132,20 @@ bool checkName (const std::string& Name, const std::string& prefix){
return false;
}
if ( parts.at(2).length() > 64 || parts.at(2).length() < 1){
if ( parts.at(2).length() > 78 || parts.at(2).length() < 1){
return false;
}
if (parts.at(4).length() > 5 || parts.at(4).length() < 1){
return false;
}
if ( parts.at(6).length() > 64 || parts.at(6).length() < 1){
if ( parts.at(6).length() > 78 || parts.at(6).length() < 1){
return false;
}
mpz_t num;
mpz_init(num);
if ( mpz_set_str(num, parts.at(2).c_str(), 16) == -1){
if ( mpz_set_str(num, parts.at(2).c_str(), 10) == -1){
mpz_clear(num);
return false;
}
......@@ -159,7 +159,7 @@ bool checkName (const std::string& Name, const std::string& prefix){
mpz_clear(num);
mpz_init(num);
if ( mpz_set_str(num, parts.at(6).c_str(),16) == -1){
if ( mpz_set_str(num, parts.at(6).c_str(),10) == -1){
mpz_clear(num);
return false;
}
......
......@@ -183,6 +183,7 @@ void generate_ecdsa_key(int *err_status, char *err_string,
sgx_status_t status = sgx_seal_data(0, NULL, ECDSA_SKEY_LEN, (uint8_t *)skey_str, sealedLen,(sgx_sealed_data_t*)encrypted_key);
if( status != SGX_SUCCESS) {
snprintf(err_string, BUF_LEN,"seal ecsdsa private key failed");
*err_status = status;
return;
}
......@@ -209,6 +210,7 @@ void get_public_ecdsa_key(int *err_status, char *err_string,
if (status != SGX_SUCCESS) {
snprintf(err_string, BUF_LEN,"sgx_unseal_data failed with status %d", status);
*err_status = status;
return;
}
......@@ -219,6 +221,7 @@ void get_public_ecdsa_key(int *err_status, char *err_string,
// mpz_import(skey_mpz, 32, 1, sizeof(skey[0]), 0, 0, skey);
if (mpz_set_str(skey_mpz, skey, ECDSA_SKEY_BASE) == -1){
snprintf(err_string, BUF_LEN,"wrong string to init private key");
*err_status = -10;
}
//Public key
......@@ -231,6 +234,7 @@ void get_public_ecdsa_key(int *err_status, char *err_string,
if (!point_cmp(Pkey, Pkey_test)){
snprintf(err_string, BUF_LEN,"Points are not equal");
*err_status = -11;
}
int base = 16;
......@@ -398,8 +402,6 @@ void bls_sign_message(int *err_status, char *err_string, uint8_t *encrypted_key,
return;
}
enclave_sign(key, _hashX, _hashY, sig);
strncpy(signature, sig, BUF_LEN);
......
......@@ -54,7 +54,7 @@
#define INVALID_ECDSA_KEY_NAME -20
#define INVALID_HEX -21
#define SGX_ERROR -666;
#define SGX_ENCLAVE_ERROR -666;
#define WALLETDB_NAME "test_sgxwallet.db"//"sgxwallet.db" //
......
......@@ -718,6 +718,28 @@ TEST_CASE( "pub_bls_key", "[pub_bls]" ) {
using namespace jsonrpc;
using namespace std;
TEST_CASE("BLS_DKG test", "[bls_dkg]") {
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1026");
StubClient c(client, JSONRPC_CLIENT_V2);
cerr << "Client inited" << endl;
int n = 2, t = 2;
Json::Value EthKeys[n];
Json::Value Polys[n];
Json::Value VerifVects[n];
std::vector <std::string> pub_keys;
for ( uint8_t i = 0; i < n; i++){
EthKeys[i] = c.generateECDSAKey();
std::string polyName = "POLY:SCHAIN_ID:1:NODE_ID:" + std::to_string(i) + "DKG_ID:0";
Polys[i] = c.generateDKGPoly(polyName, t);
VerifVects[i] = c.getVerificationVector(polyName, n, t);
}
}
TEST_CASE("API test", "[api_test]") {
cerr << "API test started" << endl;
init_all();
......@@ -726,7 +748,7 @@ TEST_CASE("API test", "[api_test]") {
// JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
// s.StartListening();
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1026");
HttpClient client("http://localhost:1025");
StubClient c(client, JSONRPC_CLIENT_V2);
cerr << "Client inited" << endl;
......@@ -738,9 +760,9 @@ TEST_CASE("API test", "[api_test]") {
//levelDb->deleteDHDKGKey("p2_1:");
//cout << c.generateECDSAKey() << endl;
// cout << c.generateECDSAKey() << endl;
// cout << c.renameESDSAKey("NODE_1CHAIN_1","tmp_NEK:bcacde0d26c0ea2c7e649992e7f791e1fba2492f5b7ae63dadb799075167c7fc");
//cout<<c.getPublicECDSAKey("NEK:697fadfc597bdbfae9ffb7412b80939e848c9c2fec2657bb2122b6d0d4a0dca8");
cout<<c.getPublicECDSAKey("NEK:697fadfc597bdbfae9ffb7412b80939e848c9c2fec2657bb2122b6d0d4a0dca8");
//cout << c.ecdsaSignMessageHash(16, "NEK:697fadfc597bdbfae9ffb7412b80939e848c9c2fec2657bb2122b6d0d4a0dca8","0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db" );
//cout << c.ecdsaSignMessageHash(16, "known_key1","0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db" );
// cout << c.blsSignMessageHash(TEST_BLS_KEY_NAME, "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db", 2,2,1 );
......@@ -797,7 +819,7 @@ TEST_CASE("API test", "[api_test]") {
// cout << c.blsSignMessageHash("dOsRY","38433e5ce087dcc1be82fcc834eae83c256b3db87d34f84440d0b708daa0c6f7", 2, 2, 1);
cout << c.ComplaintResponse("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", 0);
// cout << c.ComplaintResponse("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", 0);
} catch (JsonRpcException &e) {
cerr << e.what() << endl;
......
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