Unverified Commit 3074ad6a authored by Stan Kladko's avatar Stan Kladko Committed by GitHub

Merge pull request #53 from skalenetwork/SKALE-2167-tests

Skale 2167 tests
parents 2e95b40d bc527bf2
......@@ -314,22 +314,21 @@ bool bls_sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
}
}
char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key) {
char *keyArray = (char *) calloc(BUF_LEN, 1);
uint8_t *encryptedKey = (uint8_t *) calloc(BUF_LEN, 1);
char *errMsg = (char *) calloc(BUF_LEN, 1);
strncpy((char *) keyArray, (char *) _key, BUF_LEN);
char* encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key) {
auto keyArray = make_shared<vector<char>>(BUF_LEN, 0);
auto encryptedKey = make_shared<vector<uint8_t>>(BUF_LEN, 0);
auto errMsg = make_shared<vector<char>>(BUF_LEN, 0);
strncpy(keyArray->data(), _key, BUF_LEN);
*errStatus = -1;
unsigned int encryptedLen = 0;
//status = encrypt_key(eid, errStatus, errMsg, keyArray, encryptedKey, &encryptedLen);
status = encrypt_key_aes(eid, errStatus, errMsg, keyArray, encryptedKey, &encryptedLen);
status = encrypt_key_aes(eid, errStatus, errMsg->data(), keyArray->data(), encryptedKey->data(), &encryptedLen);
if (DEBUG_PRINT) {
spdlog::info("errStatus is {}",*errStatus);
spdlog::info(" errMsg is ", errMsg );
spdlog::info(" errMsg is ", errMsg->data() );
}
if (status != SGX_SUCCESS) {
......@@ -339,13 +338,13 @@ char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
}
if (*errStatus != 0) {
throw RPCException(-666, errMsg);
throw RPCException(-666, errMsg->data());
}
char *result = (char *) calloc(2 * BUF_LEN, 1);
carray2Hex(encryptedKey, encryptedLen, result);
carray2Hex(encryptedKey->data(), encryptedLen, result);
return result;
}
......
......@@ -49,8 +49,8 @@ EXTERNC bool hex2carray2(const char * _hex, uint64_t *_bin_len,
EXTERNC char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key);
char * encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key);
EXTERNC char *decryptBLSKeyShareFromHex(int *errStatus, char *errMsg, const char *_encryptedKey);
char *decryptBLSKeyShareFromHex(int *errStatus, char *errMsg, const char *_encryptedKey);
#endif //SGXWALLET_BLSCRYPTO_H
......@@ -146,7 +146,8 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
// printf(" %d ", encr_dkg_poly[i] );
}
uint32_t len;
uint32_t len = 0;
if (!is_aes)
status = get_public_shares(eid, &err_status, errMsg1, encr_dkg_poly, len, public_shares, t, n);
else {
......@@ -170,7 +171,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
vector <string> G2_strings = SplitString( public_shares, ',');
vector <vector <string>> pub_shares_vect;
for ( int i = 0; i < G2_strings.size(); i++){
for ( uint64_t i = 0; i < G2_strings.size(); i++){
vector <string> koef_str = SplitString(G2_strings.at(i).c_str(), ':');
pub_shares_vect.push_back(koef_str);
}
......@@ -382,7 +383,6 @@ vector<string> GetBLSPubKey(const char * encryptedKeyHex){
int err_status = 0;
uint64_t dec_key_len ;
uint8_t encr_bls_key[BUF_LEN];
uint8_t encr_key[BUF_LEN];
if (!hex2carray(encryptedKeyHex, &dec_key_len, encr_key)){
throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex");
......
......@@ -7,7 +7,6 @@ COPY *.txt ./
COPY *.c ./
COPY *.am ./
COPY *.hpp ./
COPY *.sh ./
COPY *.gmp ./
COPY *.ac ./
COPY *.json ./
......@@ -34,6 +33,5 @@ RUN ./configure
RUN make
RUN mkdir /usr/src/sdk/sgx_data
COPY docker/start.sh ./
ENTRYPOINT ["/usr/src/sdk/start.sh"]
......@@ -7,7 +7,6 @@ COPY *.txt ./
COPY *.c ./
COPY *.am ./
COPY *.hpp ./
COPY *.sh ./
COPY *.gmp ./
COPY *.ac ./
COPY *.json ./
......@@ -33,6 +32,7 @@ RUN make
RUN mkdir /usr/src/sdk/sgx_data
COPY docker/start.sh ./
ENTRYPOINT ["/usr/src/sdk/start.sh"]
......@@ -44,8 +44,10 @@ secure_enclave.edl: secure_enclave/secure_enclave.edl
##
#AM_CPPFLAGS += -g -Og
#AM_CFLAGS = -g -Og -rdynamic -Wl,--no-as-needed -lSegFault -fsanitize=address
#AM_CXXFLAGS = ${AM_CPPFLAGS} -rdynamic -Wl,--no-as-needed -lSegFault -fsanitize=address
AM_CFLAGS = -g -Og -rdynamic -Wl,--no-as-needed -lSegFault
AM_CXXFLAGS = ${AM_CPPFLAGS} -rdynamic -Wl,--no-as-needed -lSegFault
AM_CPPFLAGS += -Wall -DSKALE_SGX=1 -DBINARY_OUTPUT=1 -Ileveldb/include -IlibBLS/bls -IlibBLS/libff -IlibBLS -fno-builtin-memset $(GMP_CPPFLAGS) -I. -I./libBLS/deps/deps_inst/x86_or_x64/include
......
......@@ -154,7 +154,11 @@ void gen_SEK(){
std::getline(std::cin, buffer);
} while (case_insensitive_match(confirm_str, buffer)); //(strcmp(confirm_str.c_str(), buffer.c_str()) != 0);
}
system("reset");
if (system("reset") != 0) {
cerr << "Could not execute reset" << endl;
}
LevelDB::getLevelDb()->writeDataUnique("SEK", hexEncrKey.data());
create_test_key();
......
......@@ -152,11 +152,13 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
result["errorMessage"] = "";
result["encryptedKeyShare"] = "";
char *encryptedKeyShareHex = nullptr;
try {
// if ( !checkName(_keyShare, "BLS_KEY")){
// throw RPCException(INVALID_POLY_NAME, "Invalid BLSKey name");
// }
char *encryptedKeyShareHex = encryptBLSKeyShare2Hex(&errStatus, errMsg, _keyShare.c_str());
encryptedKeyShareHex = encryptBLSKeyShare2Hex(&errStatus, errMsg, _keyShare.c_str());
if (encryptedKeyShareHex == nullptr) {
throw RPCException(UNKNOWN_ERROR, "");
......@@ -166,7 +168,7 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
throw RPCException(errStatus, errMsg);
}
result["encryptedKeyShare"] = encryptedKeyShareHex;
result["encryptedKeyShare"] = string(encryptedKeyShareHex);
writeKeyShare(_keyShareName, encryptedKeyShareHex, index, n , t);
......@@ -175,6 +177,10 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
result["errorMessage"] = _e.errString;
}
if (encryptedKeyShareHex != nullptr) {
free(encryptedKeyShareHex);
}
return result;
}
......@@ -487,7 +493,7 @@ Json::Value getSecretShareImpl(const string& polyName, const Json::Value& public
result["errorMessage"] = "";
try {
if (publicKeys.size() != n){
if (publicKeys.size() != (uint64_t) n){
throw RPCException(INVALID_DKG_PARAMS, "wrong number of public keys");
}
if ( !checkName(polyName, "POLY")){
......@@ -543,7 +549,7 @@ Json::Value dkgVerificationImpl(const string& publicShares, const string& ethKey
if ( !checkHex(SecretShare, SECRET_SHARE_NUM_BYTES)){
throw RPCException(INVALID_HEX, "Invalid Secret share");
}
if (publicShares.length() != 256 * t){
if (publicShares.length() != (uint64_t ) 256 * t){
throw RPCException(INVALID_DKG_PARAMS, "Invalid length of public shares");
}
......@@ -573,7 +579,7 @@ Json::Value createBLSPrivateKeyImpl(const string & blsKeyName, const string& eth
try {
if (SecretShare.length() != n * 192){
if (SecretShare.length() != (uint64_t ) n * 192){
spdlog::info("wrong length of secret shares - {}", SecretShare.length());
spdlog::info("secret shares - {}", SecretShare);
throw RPCException(INVALID_SECRET_SHARES_LENGTH, "Invalid secret share length");
......
#!/bin/bash
source /opt/intel/sgxsdk/environment
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/intel/sgxpsw/aesm/
jhid -d
/opt/intel/sgxpsw/aesm/aesm_service &
pid=$!
cd /usr/src/sdk;
sleep 2
cd /usr/src/sdk; ./sgxwallet $1 $2 $3 $4
echo $1
if [ "$1" = -t ]; then
set -e
./testw [bls-key-encrypt]
./testw [bls-key-encrypt-decrypt]
./testw [dkg-gen]
./testw [dkg-pub_shares]
./testw [dkg-verify]
./testw [ecdsa_test]
./testw [test_test]
./testw [get_pub_ecdsa_key_test]
./testw [bls_dkg]
./testw [api_test]
./testw [getServerStatus_test]
./testw [dkg_api_test]
./testw [is_poly_test]
./testw [AES-encrypt-decrypt]
#./testw [ecdsa_api_test]
#./testw [dkg-encr_sshares]
# ./testw [bls_sign]
#./testw [many_threads_test]
# ./testw [aes_dkg]
else
./sgxwallet $1 $2 $3 $4
fi
version: '3'
services:
sgxwallet:
image: skalenetwork/sgxwallet:latest
image: skalenetwork/sgxwallet:latest_commit
ports:
- "1026:1026"
- "1027:1027"
......@@ -17,6 +17,6 @@ services:
max-size: "10m"
max-file: "4"
restart: unless-stopped
command: -s
command: -t
version: '3'
services:
sgxwallet:
image: skalenetwork/sgxwalletsim:latest
image: skalenetwork/sgxwalletsim:latest_commit
ports:
- "1026:1026"
- "1027:1027"
......@@ -14,5 +14,5 @@ services:
max-size: "10m"
max-file: "4"
restart: unless-stopped
command: -s -d -y
command: -t
......@@ -23,6 +23,12 @@
#
import sys, os, subprocess, socket, time
os.chdir("..")
topDir = os.getcwd() + "/sgxwallet"
print("Starting build push")
......@@ -44,13 +50,18 @@ print("Running tests for branch " + BRANCH);
assert subprocess.call(["docker", "image", "inspect", FULL_IMAGE_NAME]) == 0;
#assert subprocess.call(["docker", "run", "-v", topDir + "/sgx_data:/usr/src/sdk/sgx_data",
# "-d", "--network=host", "skalenetwork/" + IMAGE_NAME +":" + TAG_POSTFIX]) == 0
completedProcess = subprocess.run(["docker", "run", "-v", topDir + "/sgx_data:/usr/src/sdk/sgx_data","-t",
"--name", "sgxwallet", "--network=host", "skalenetwork/" + IMAGE_NAME +":" + TAG_POSTFIX, "-t"])
print(completedProcess.stdout)
print(completedProcess.stderr)
assert completedProcess.returncode == 0;
obj = subprocess.Popen(["docker", "run", "-v", topDir + "/sgx_data:/usr/src/sdk/sgx_data","-d","--network=host", "skalenetwork/" + IMAGE_NAME +":" + TAG_POSTFIX, "-y"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
obj.communicate(input=b"i confirm", timeout=5)
obj.terminate()
obj.wait()
assert subprocess.call(["docker", "rm", "sgxwallet"]) == 0
assert subprocess.call(["docker", "run", "-v", topDir + "/sgx_data:/usr/src/sdk/sgx_data","-d",
"--name", "sgxwallet",
"--network=host", "skalenetwork/" + IMAGE_NAME +":" + TAG_POSTFIX, "-y"]) == 0
time.sleep(5);
......@@ -74,9 +85,3 @@ s3.connect((address, 1028))
s1.close()
s2.close()
s3.close()
# Makefile.in generated by automake 1.16.1 from Makefile.am.
# Makefile.in generated by automake 1.15.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2018 Free Software Foundation, Inc.
# Copyright (C) 1994-2017 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
......@@ -137,16 +137,7 @@ am__v_at_0 = @
am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__maybe_remake_depfiles = depfiles
am__depfiles_remade = ./$(DEPDIR)/AESUtils.Po \
./$(DEPDIR)/BLSEnclave.Po ./$(DEPDIR)/DH_dkg.Po \
./$(DEPDIR)/DKGUtils.Po ./$(DEPDIR)/alt_bn128_g1.Po \
./$(DEPDIR)/alt_bn128_g2.Po ./$(DEPDIR)/alt_bn128_init.Po \
./$(DEPDIR)/curves.Po ./$(DEPDIR)/domain_parameters.Po \
./$(DEPDIR)/numbertheory.Po ./$(DEPDIR)/point.Po \
./$(DEPDIR)/secure_enclave.Po ./$(DEPDIR)/secure_enclave_t.Po \
./$(DEPDIR)/signature.Po ./$(DEPDIR)/signed_enclave_debug.Po \
./$(DEPDIR)/signed_enclave_rel.Po
am__depfiles_maybe = depfiles
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
......@@ -375,8 +366,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_srcdir)/build-aux/sgx_enclave.am $(am__empty):
......@@ -441,28 +432,22 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AESUtils.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BLSEnclave.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DH_dkg.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DKGUtils.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alt_bn128_g1.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alt_bn128_g2.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alt_bn128_init.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/curves.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/domain_parameters.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/numbertheory.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/point.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/secure_enclave.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/secure_enclave_t.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signature.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signed_enclave_debug.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signed_enclave_rel.Po@am__quote@ # am--include-marker
$(am__depfiles_remade):
@$(MKDIR_P) $(@D)
@echo '# dummy' >$@-t && $(am__mv) $@-t $@
am--depfiles: $(am__depfiles_remade)
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AESUtils.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BLSEnclave.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DH_dkg.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DKGUtils.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alt_bn128_g1.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alt_bn128_g2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alt_bn128_init.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/curves.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/domain_parameters.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/numbertheory.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/point.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/secure_enclave.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/secure_enclave_t.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signature.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signed_enclave_debug.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signed_enclave_rel.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
......@@ -586,10 +571,7 @@ cscopelist-am: $(am__tagged_files)
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) distdir-am
distdir-am: $(DISTFILES)
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
......@@ -662,22 +644,7 @@ clean: clean-am
clean-am: clean-generic clean-libexecPROGRAMS mostlyclean-am
distclean: distclean-am
-rm -f ./$(DEPDIR)/AESUtils.Po
-rm -f ./$(DEPDIR)/BLSEnclave.Po
-rm -f ./$(DEPDIR)/DH_dkg.Po
-rm -f ./$(DEPDIR)/DKGUtils.Po
-rm -f ./$(DEPDIR)/alt_bn128_g1.Po
-rm -f ./$(DEPDIR)/alt_bn128_g2.Po
-rm -f ./$(DEPDIR)/alt_bn128_init.Po
-rm -f ./$(DEPDIR)/curves.Po
-rm -f ./$(DEPDIR)/domain_parameters.Po
-rm -f ./$(DEPDIR)/numbertheory.Po
-rm -f ./$(DEPDIR)/point.Po
-rm -f ./$(DEPDIR)/secure_enclave.Po
-rm -f ./$(DEPDIR)/secure_enclave_t.Po
-rm -f ./$(DEPDIR)/signature.Po
-rm -f ./$(DEPDIR)/signed_enclave_debug.Po
-rm -f ./$(DEPDIR)/signed_enclave_rel.Po
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
......@@ -723,22 +690,7 @@ install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/AESUtils.Po
-rm -f ./$(DEPDIR)/BLSEnclave.Po
-rm -f ./$(DEPDIR)/DH_dkg.Po
-rm -f ./$(DEPDIR)/DKGUtils.Po
-rm -f ./$(DEPDIR)/alt_bn128_g1.Po
-rm -f ./$(DEPDIR)/alt_bn128_g2.Po
-rm -f ./$(DEPDIR)/alt_bn128_init.Po
-rm -f ./$(DEPDIR)/curves.Po
-rm -f ./$(DEPDIR)/domain_parameters.Po
-rm -f ./$(DEPDIR)/numbertheory.Po
-rm -f ./$(DEPDIR)/point.Po
-rm -f ./$(DEPDIR)/secure_enclave.Po
-rm -f ./$(DEPDIR)/secure_enclave_t.Po
-rm -f ./$(DEPDIR)/signature.Po
-rm -f ./$(DEPDIR)/signed_enclave_debug.Po
-rm -f ./$(DEPDIR)/signed_enclave_rel.Po
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
......@@ -758,19 +710,19 @@ uninstall-am: uninstall-libexecPROGRAMS
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
clean-generic clean-libexecPROGRAMS cscopelist-am ctags \
ctags-am distclean distclean-compile distclean-generic \
distclean-tags distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-info install-info-am \
install-libexecPROGRAMS install-man install-pdf install-pdf-am \
install-ps install-ps-am install-strip installcheck \
installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall \
uninstall-am uninstall-libexecPROGRAMS
.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
clean-libexecPROGRAMS cscopelist-am ctags ctags-am distclean \
distclean-compile distclean-generic distclean-tags distdir dvi \
dvi-am html html-am info info-am install install-am \
install-data install-data-am install-dvi install-dvi-am \
install-exec install-exec-am install-html install-html-am \
install-info install-info-am install-libexecPROGRAMS \
install-man install-pdf install-pdf-am install-ps \
install-ps-am install-strip installcheck installcheck-am \
installdirs maintainer-clean maintainer-clean-generic \
mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \
ps ps-am tags tags-am uninstall uninstall-am \
uninstall-libexecPROGRAMS
.PRECIOUS: Makefile
......
......@@ -73,11 +73,12 @@ int main(int argc, char *argv[]) {
switch (opt) {
case 'h':
if (strlen(argv[1]) == 2 ) {
fprintf(stderr, "-c client certificate will not be checked\n");
fprintf(stderr, "-s client certificate will be signed automatically\n");
fprintf(stderr, "-c do not verify client certificate\n");
fprintf(stderr, "-s sign client certificate without human confirmation \n");
fprintf(stderr, "-d turn on debug output\n");
fprintf(stderr, "-0 SGXWalletServer will be launched on http (not https)\n");
fprintf(stderr, "-b Enter backup key\n");
fprintf(stderr, "-0 launch SGXWalletServer using http (not https)\n");
fprintf(stderr, "-b Restore from back up (you will need to enter backup key) \n");
fprintf(stderr, "-y Do not ask user to acknoledge receipt of backup key \n");
exit(0);
} else {
fprintf(stderr, "unknown flag %s\n", argv[1]);
......
......@@ -12,7 +12,7 @@ class StubClient : public jsonrpc::Client
public:
StubClient(jsonrpc::IClientConnector &conn, jsonrpc::clientVersion_t type = jsonrpc::JSONRPC_CLIENT_V2) : jsonrpc::Client(conn, type) {}
Json::Value importBLSKeyShare(const std::string& keyShare, const std::string& keyShareName, int t, int n, int index) throw (jsonrpc::JsonRpcException)
Json::Value importBLSKeyShare(const std::string& keyShare, const std::string& keyShareName, int t, int n, int index)
{
Json::Value p;
p["index"] = index;
......@@ -27,7 +27,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int t, int n, int signerIndex) throw (jsonrpc::JsonRpcException)
Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int t, int n, int signerIndex)
{
Json::Value p;
p["keyShareName"] = keyShareName;
......@@ -42,7 +42,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value importECDSAKey(const std::string& key, const std::string& keyName) throw (jsonrpc::JsonRpcException)
Json::Value importECDSAKey(const std::string& key, const std::string& keyName)
{
Json::Value p;
p["key"] = key;
......@@ -54,7 +54,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value generateECDSAKey() throw (jsonrpc::JsonRpcException)
Json::Value generateECDSAKey()
{
Json::Value p;
p = Json::nullValue;
......@@ -65,7 +65,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value renameECDSAKey(const std::string& KeyName, const std::string& tempKeyName) throw (jsonrpc::JsonRpcException)
Json::Value renameECDSAKey(const std::string& KeyName, const std::string& tempKeyName)
{
Json::Value p;
p["keyName"] = KeyName;
......@@ -77,7 +77,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value getPublicECDSAKey(const std::string& keyName) throw (jsonrpc::JsonRpcException)
Json::Value getPublicECDSAKey(const std::string& keyName)
{
Json::Value p;
p["keyName"] = keyName;
......@@ -88,7 +88,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value ecdsaSignMessageHash(int base, const std::string& keyName, const std::string& messageHash) throw (jsonrpc::JsonRpcException)
Json::Value ecdsaSignMessageHash(int base, const std::string& keyName, const std::string& messageHash)
{
Json::Value p;
p["base"] = base;
......@@ -101,7 +101,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value generateDKGPoly(const std::string& polyName, int t) throw (jsonrpc::JsonRpcException)
Json::Value generateDKGPoly(const std::string& polyName, int t)
{
Json::Value p;
p["polyName"] = polyName;
......@@ -113,7 +113,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value getVerificationVector(const std::string& polyName, int t, int n) throw (jsonrpc::JsonRpcException)
Json::Value getVerificationVector(const std::string& polyName, int t, int n)
{
Json::Value p;
p["polyName"] = polyName;
......@@ -126,7 +126,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value getSecretShare(const std::string& polyName, const Json::Value& publicKeys, int t, int n) throw (jsonrpc::JsonRpcException)
Json::Value getSecretShare(const std::string& polyName, const Json::Value& publicKeys, int t, int n)
{
Json::Value p;
p["polyName"] = polyName;
......@@ -140,7 +140,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value dkgVerification(const std::string& publicShares, const std::string& ethKeyName, const std::string& SecretShare, int t, int n, int index) throw (jsonrpc::JsonRpcException)
Json::Value dkgVerification(const std::string& publicShares, const std::string& ethKeyName, const std::string& SecretShare, int t, int n, int index)
{
Json::Value p;
p["ethKeyName"] = ethKeyName;
......@@ -156,7 +156,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value createBLSPrivateKey(const std::string & blsKeyName, const std::string& ethKeyName, const std::string& polyName, const std::string& SecretShare, int t, int n) throw (jsonrpc::JsonRpcException)
Json::Value createBLSPrivateKey(const std::string & blsKeyName, const std::string& ethKeyName, const std::string& polyName, const std::string& SecretShare, int t, int n)
{
Json::Value p;
p["blsKeyName"] = blsKeyName;
......@@ -172,7 +172,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value getBLSPublicKeyShare(const std::string & blsKeyName) throw (jsonrpc::JsonRpcException)
Json::Value getBLSPublicKeyShare(const std::string & blsKeyName)
{
Json::Value p;
p["blsKeyName"] = blsKeyName;
......@@ -184,7 +184,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value complaintResponse(const std::string& polyName, int ind) throw (jsonrpc::JsonRpcException)
Json::Value complaintResponse(const std::string& polyName, int ind)
{
Json::Value p;
p["polyName"] = polyName;
......@@ -196,7 +196,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value multG2(const std::string & x) throw (jsonrpc::JsonRpcException)
Json::Value multG2(const std::string & x)
{
Json::Value p;
p["x"] = x;
......@@ -208,7 +208,7 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value isPolyExists(const std::string & polyName) throw (jsonrpc::JsonRpcException)
Json::Value isPolyExists(const std::string & polyName)
{
Json::Value p;
p["polyName"] = polyName;
......@@ -223,7 +223,7 @@ class StubClient : public jsonrpc::Client
////CSRManagerServer
Json::Value getUnsignedCSRs() throw (jsonrpc::JsonRpcException)
Json::Value getUnsignedCSRs()
{
Json::Value p;
p = Json::nullValue;
......@@ -236,7 +236,7 @@ class StubClient : public jsonrpc::Client
Json::Value signByHash(const std::string& hash, int status) throw (jsonrpc::JsonRpcException)
Json::Value signByHash(const std::string& hash, int status)
{
Json::Value p;
p["hash"] = hash;
......@@ -249,7 +249,7 @@ class StubClient : public jsonrpc::Client
}
Json::Value getServerStatus() throw (jsonrpc::JsonRpcException)
Json::Value getServerStatus()
{
Json::Value p;
p = Json::nullValue;
......
#!/bin/bash
set -e
./testw [bls-key-encrypt]
./testw [bls-key-encrypt-decrypt]
./testw [dkg-gen]
./testw [dkg-pub_shares]
#./testw [dkg-encr_sshares]
./testw [dkg-verify]
./testw [ecdsa_test]
./testw [test_test]
./testw [get_pub_ecdsa_key_test]
./testw [bls_dkg]
./testw [api_test]
./testw [getServerStatus_test]
./testw [many_threads_test]
./testw [ecdsa_api_test]
./testw [dkg_api_test]
./testw [is_poly_test]
./testw [aes_dkg]
#./testw [bls_sign]
./testw [AES-encrypt-decrypt]
......@@ -34,19 +34,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <libff/algebra/fields/fp.hpp>
#include <dkg/dkg.h>
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include <libff/algebra/exponentiation/exponentiation.hpp>
#include <libff/algebra/fields/fp.hpp>
#include <dkg/dkg.h>
#include "sgxwallet_common.h"
#include "create_enclave.h"
#include "secure_enclave_u.h"
......@@ -54,46 +46,36 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <gmp.h>
#include <sgx_urts.h>
#include <stdio.h>
#include "BLSCrypto.h"
#include "ServerInit.h"
#include "DKGCrypto.h"
#include "RPCException.h"
#include "LevelDB.h"
#include "SGXWalletServer.hpp"
#include <sgx_tcrypto.h>
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
#include "stubclient.h"
#include "BLSSigShare.h"
#include "BLSSigShareSet.h"
#include "BLSPublicKeyShare.h"
#include "BLSPublicKey.h"
#include "SEKManager.h"
#include <thread>
#include "common.h"
#include "stubclient.h"
#include <jsonrpccpp/client/connectors/httpclient.h>
default_random_engine rand_gen((unsigned int) time(0));
string stringFromFr(libff::alt_bn128_Fr& el) {
string stringFromFr(libff::alt_bn128_Fr &el) {
mpz_t t;
mpz_init(t);
el.as_bigint().to_mpz(t);
char arr[mpz_sizeinbase(t, 10) + 2];
char *tmp = mpz_get_str(arr, 10, t);
mpz_clear(t);
......@@ -115,25 +97,22 @@ int updated;
#define TEST_BLS_KEY_NAME "SCHAIN:17:INDEX:5:KEY:1"
void reset_db() {
//std::string db_name = SGXDATA_FOLDER + WALLETDB_NAME;
REQUIRE(system("rm -rf " WALLETDB_NAME) == 0);
//string db_name = SGXDATA_FOLDER + WALLETDB_NAME;
REQUIRE(system("rm -rf "
WALLETDB_NAME) == 0);
}
char* encryptTestKey() {
char *encryptTestKey() {
const char *key = TEST_BLS_KEY_SHARE;
int errStatus = -1;
char *errMsg = (char *) calloc(BUF_LEN, 1);
char *encryptedKeyHex = encryptBLSKeyShare2Hex(&errStatus, errMsg, key);
vector<char> errMsg(BUF_LEN, 0);;
char *encryptedKeyHex = encryptBLSKeyShare2Hex(&errStatus, errMsg.data(), key);
REQUIRE(encryptedKeyHex != nullptr);
REQUIRE(errStatus == 0);
printf("Encrypt key completed with status: %d %s \n", errStatus, errMsg);
printf("Encrypt key completed with status: %d %s \n", errStatus, errMsg.data());
printf("Encrypted key len %d\n", (int) strlen(encryptedKeyHex));
printf("Encrypted key %s \n", encryptedKeyHex);
......@@ -142,13 +121,13 @@ char* encryptTestKey() {
TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") {
DEBUG_PRINT = 1;
is_sgx_https = 0;
init_all(false, false, init_SEK);
char* key = encryptTestKey();
autoconfirm = true;
init_all(false, true, init_SEK);
auto key = encryptTestKey();
REQUIRE(key != nullptr);
free(key);
}
......@@ -157,210 +136,111 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
DEBUG_PRINT = 1;
is_sgx_https = 0;
autoconfirm = true;
init_all(false, true, init_SEK);
init_all(false, false, init_SEK);
//init_enclave();
int errStatus = -1;
char* errMsg = (char*) calloc(BUF_LEN, 1);
vector<char> errMsg(BUF_LEN, 0);
char* encryptedKey = encryptTestKey();
char *encryptedKey = encryptTestKey();
REQUIRE(encryptedKey != nullptr);
char* plaintextKey = decryptBLSKeyShareFromHex(&errStatus, errMsg, encryptedKey);
char *plaintextKey = decryptBLSKeyShareFromHex(&errStatus, errMsg.data(), encryptedKey);
free(encryptedKey);
REQUIRE(errStatus == 0);
REQUIRE(strcmp(plaintextKey, TEST_BLS_KEY_SHARE) == 0);
printf("Decrypt key completed with status: %d %s \n", errStatus, errMsg);
printf("Decrypt key completed with status: %d %s \n", errStatus, errMsg.data());
printf("Decrypted key len %d\n", (int) strlen(plaintextKey));
printf("Decrypted key: %s\n", plaintextKey);
free(plaintextKey);
sgx_destroy_enclave(eid);
}
}
//TEST_CASE("BLS key import", "[bls-key-import]") {
// reset_db();
// init_all(false, false);
//
//
//
// auto result = importBLSKeyShareImpl(TEST_BLS_KEY_SHARE, TEST_BLS_KEY_NAME, 2, 2, 1);
//
// REQUIRE(result["status"] == 0);
//
// REQUIRE(result["encryptedKeyShare"] != "");
//
//
//TEST_CASE("BLS sign test", "[bls-sign]") {
//
// //init_all();
// init_enclave();
//
// char* encryptedKeyHex ="04000200000000000406ffffff02000000000000000000000b000000000000ff0000000000000000813f8390f6228a568e181a4dadb6508e3e66f5247175d65dbd0d8c7fbfa4df45000000f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000008000000000000000000000000000000000dc044ae0cd79faaf41e8a7abb412790476738a98b5b6ce95fa1a32db5551b0a0d867305f4de558c64fee730a1f62394633c7d4ca65e3a40b7883e89c2801c61918b01c5de8624a52963df6f4de8581bcbdd2f9b69720d4cc764e03a04c7a99314bfdb5d2d55deda2ca40cd691f093fb2ecbae24cdacdd4d5de93189c6dfd6792d7b95bd5e330aec3538e7a85d15793"; //encryptTestKey();
//
// REQUIRE(encryptedKeyHex != nullptr);
//
//
// // const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788";
// const char *hexHash = "3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F";
//
// char* hexHashBuf = (char*) calloc(BUF_LEN, 1);
//
// strncpy(hexHashBuf, hexHash, BUF_LEN);
//
// char sig[BUF_LEN];
// auto result = sign(encryptedKeyHex, hexHashBuf, 2, 2, 1, sig);
//
// REQUIRE(result == true);
// printf("Signature is: %s \n", sig );
//
//}
//
//TEST_CASE("Server BLS sign test", "[bls-server-sign]") {
//
// reset_db();
//
// init_all(false, false);
//
//
// auto result = importBLSKeyShareImpl( TEST_BLS_KEY_SHARE, TEST_BLS_KEY_NAME, 2, 2, 1);
//
// REQUIRE(result["status"] == 0);
//
// REQUIRE(result["encryptedKeyShare"] != "");
//
// const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788";
//
// REQUIRE_NOTHROW(result = blsSignMessageHashImpl(TEST_BLS_KEY_NAME, hexHash,2,2,1));
//
// if (result["status"] != 0) {
// printf("Error message: %s", result["errorMessage"].asString().c_str());
// }
//
//
// REQUIRE(result["status"] == 0);
// REQUIRE(result["signatureShare"] != "");
//
// printf("Signature is: %s \n", result["signatureShare"].asString().c_str());
//
//}
//TEST_CASE("KeysDB test", "[keys-db]") {
//
//
//
// reset_db();
// init_all();
//
//
// string key = TEST_BLS_KEY_SHARE;
// string value = TEST_BLS_KEY_SHARE;
//
//
//
// REQUIRE_THROWS(readKeyShare(key));
//
//
// writeKeyShare(key, value, 1, 2, 1);
//
// REQUIRE(readKeyShare(key) != nullptr);
//
//
//// put your test here
//}
TEST_CASE("DKG gen test", "[dkg-gen]") {
TEST_CASE( "DKG gen test", "[dkg-gen]" ) {
autoconfirm = true;
//init_all();
init_enclave();
uint8_t* encrypted_dkg_secret = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);
vector<uint8_t> encrypted_dkg_secret(DKG_MAX_SEALED_LEN, 0);
vector<char> errMsg(1024, 0);
char* errMsg = (char*) calloc(1024,1);
int err_status = 0;
uint32_t enc_len = 0;
status = gen_dkg_secret (eid, &err_status, errMsg, encrypted_dkg_secret, &enc_len, 32);
status = gen_dkg_secret(eid, &err_status, errMsg.data(), encrypted_dkg_secret.data(), &enc_len, 32);
REQUIRE(status == SGX_SUCCESS);
printf("gen_dkg_secret completed with status: %d %s \n", err_status, errMsg);
printf("gen_dkg_secret completed with status: %d %s \n", err_status, errMsg.data());
printf("\n Length: %d \n", enc_len);
char* secret = (char*)calloc(DKG_BUFER_LENGTH, sizeof(char));
vector<char> secret(DKG_BUFER_LENGTH, 0);
char* errMsg1 = (char*) calloc(1024,1);
vector<char> errMsg1(1024, 0);
uint32_t dec_len;
status = decrypt_dkg_secret(eid, &err_status, errMsg1, encrypted_dkg_secret, (uint8_t*)secret, &dec_len);
REQUIRE(status == SGX_SUCCESS);
status = decrypt_dkg_secret(eid, &err_status, errMsg1.data(), encrypted_dkg_secret.data(),
(uint8_t *) secret.data(), &dec_len);
printf("\ndecrypt_dkg_secret completed with status: %d %s \n", err_status, errMsg1);
printf("decrypted secret %s \n\n", secret);
printf ("secret length %d \n", strlen(secret));
printf ("decr length %d \n", dec_len);
REQUIRE(status == SGX_SUCCESS);
free(errMsg);
free(errMsg1);
free(encrypted_dkg_secret);
free(secret);
printf("\ndecrypt_dkg_secret completed with status: %d %s \n", err_status, errMsg1.data());
printf("decrypted secret %s \n\n", secret.data());
printf("secret length %d \n", (int) strlen(secret.data()));
printf("decr length %d \n", dec_len);
sgx_destroy_enclave(eid);
}
vector<libff::alt_bn128_Fr> SplitStringToFr(const char* koefs, const char symbol){
vector<libff::alt_bn128_Fr> SplitStringToFr(const char *koefs, const char symbol) {
string str(koefs);
string delim;
delim.push_back(symbol);
vector<libff::alt_bn128_Fr> tokens;
size_t prev = 0, pos = 0;
do
{
do {
pos = str.find(delim, prev);
if (pos == string::npos) pos = str.length();
string token = str.substr(prev, pos-prev);
string token = str.substr(prev, pos - prev);
if (!token.empty()) {
libff::alt_bn128_Fr koef(token.c_str());
tokens.push_back(koef);
}
prev = pos + delim.length();
}
while (pos < str.length() && prev < str.length());
} while (pos < str.length() && prev < str.length());
return tokens;
}
vector<string> SplitStringTest(const char* koefs, const char symbol){
vector<string> SplitStringTest(const char *koefs, const char symbol) {
libff::init_alt_bn128_params();
string str(koefs);
string delim;
delim.push_back(symbol);
vector<string> G2_strings;
size_t prev = 0, pos = 0;
do
{
do {
pos = str.find(delim, prev);
if (pos == string::npos) pos = str.length();
string token = str.substr(prev, pos-prev);
string token = str.substr(prev, pos - prev);
if (!token.empty()) {
string koef(token.c_str());
G2_strings.push_back(koef);
}
prev = pos + delim.length();
}
while (pos < str.length() && prev < str.length());
} while (pos < str.length() && prev < str.length());
return G2_strings;
}
libff::alt_bn128_G2 VectStringToG2(const vector<string>& G2_str_vect){
libff::alt_bn128_G2 VectStringToG2(const vector<string> &G2_str_vect) {
libff::init_alt_bn128_params();
libff::alt_bn128_G2 koef = libff::alt_bn128_G2::zero();
koef.X.c0 = libff::alt_bn128_Fq(G2_str_vect.at(0).c_str());
......@@ -373,155 +253,146 @@ libff::alt_bn128_G2 VectStringToG2(const vector<string>& G2_str_vect){
return koef;
}
TEST_CASE( "DKG public shares test", "[dkg-pub_shares]" ) {
TEST_CASE("DKG public shares test", "[dkg-pub_shares]") {
autoconfirm = true;
//init_all();
libff::init_alt_bn128_params();
init_enclave();
uint8_t* encrypted_dkg_secret = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);
vector<uint8_t> encrypted_dkg_secret(DKG_MAX_SEALED_LEN, 0);
vector<char> errMsg(1024, 0);
char* errMsg = (char*) calloc(1024,1);
int err_status = 0;
uint32_t enc_len = 0;
unsigned t = 32, n = 32;
status = gen_dkg_secret (eid, &err_status, errMsg, encrypted_dkg_secret, &enc_len, n);
status = gen_dkg_secret(eid, &err_status, errMsg.data(), encrypted_dkg_secret.data(), &enc_len, n);
REQUIRE(status == SGX_SUCCESS);
//printf("gen_dkg_public completed with status: %d %s \n", err_status, errMsg);
char* errMsg1 = (char*) calloc(1024,1);
vector<char> errMsg1(1024, 0);
char colon = ':';
char* public_shares = (char*)calloc(10000, 1);
status = get_public_shares(eid, &err_status, errMsg1, encrypted_dkg_secret, enc_len, public_shares, t, n);
vector<char> public_shares(10000, 0);
status = get_public_shares(eid, &err_status, errMsg1.data(),
encrypted_dkg_secret.data(), enc_len, public_shares.data(), t, n);
REQUIRE(status == SGX_SUCCESS);
printf("\nget_public_shares status: %d error %s \n\n", err_status, errMsg1);
printf(" LEN: %d \n", strlen(public_shares));
printf(" result: %s \n", public_shares);
vector <string> G2_strings = SplitString( public_shares, ',');
vector <libff::alt_bn128_G2> pub_shares_G2;
for ( int i = 0; i < G2_strings.size(); i++){
vector <string> koef_str = SplitString(G2_strings.at(i).c_str(), ':');
libff::alt_bn128_G2 el = VectStringToG2(koef_str);
printf("\nget_public_shares status: %d error %s \n\n", err_status, errMsg1.data());
printf(" LEN: %d \n", (int) strlen(public_shares.data()));
printf(" result: %s \n", public_shares.data());
vector<string> G2_strings = SplitString(public_shares.data(), ',');
vector<libff::alt_bn128_G2> pub_shares_G2;
for (u_int64_t i = 0; i < G2_strings.size(); i++) {
vector<string> koef_str = SplitString(G2_strings.at(i).c_str(), ':');
//libff::alt_bn128_G2 el = VectStringToG2(koef_str);
//cerr << "pub_share G2 " << i+1 << " : " << endl;
//el.print_coordinates();
pub_shares_G2.push_back(VectStringToG2(koef_str));
}
char* secret = (char*)calloc(DKG_MAX_SEALED_LEN, sizeof(char));
status = decrypt_dkg_secret(eid, &err_status, errMsg1, encrypted_dkg_secret, (uint8_t*)secret, &enc_len);
vector<char> secret(DKG_MAX_SEALED_LEN, 0);
status = decrypt_dkg_secret(eid, &err_status, errMsg1.data(), encrypted_dkg_secret.data(),
(uint8_t *) secret.data(), &enc_len);
REQUIRE(status == SGX_SUCCESS);
printf("\ndecrypt_dkg_secret completed with status: %d %s \n", err_status, errMsg1);
printf("\ndecrypt_dkg_secret completed with status: %d %s \n", err_status, errMsg1.data());
signatures::Dkg dkg_obj(t,n);
signatures::Dkg dkg_obj(t, n);
vector < libff::alt_bn128_Fr> poly = SplitStringToFr((char*)secret, colon);
vector < libff::alt_bn128_G2> pub_shares_dkg = dkg_obj.VerificationVector(poly);
vector<libff::alt_bn128_Fr> poly = SplitStringToFr(secret.data(), colon);
vector<libff::alt_bn128_G2> pub_shares_dkg = dkg_obj.VerificationVector(poly);
printf("calculated public shares (X.c0): \n");
for ( int i = 0; i < pub_shares_dkg.size(); i++){
for (uint32_t i = 0; i < pub_shares_dkg.size(); i++) {
libff::alt_bn128_G2 el = pub_shares_dkg.at(i);
el.to_affine_coordinates();
libff::alt_bn128_Fq x_c0_el = el.X.c0;
mpz_t x_c0;
mpz_init(x_c0);
x_c0_el.as_bigint().to_mpz(x_c0);
char arr[mpz_sizeinbase (x_c0, 10) + 2];
char* share_str = mpz_get_str(arr, 10, x_c0);
char arr[mpz_sizeinbase(x_c0, 10) + 2];
char *share_str = mpz_get_str(arr, 10, x_c0);
printf(" %s \n", share_str);
mpz_clear(x_c0);
}
bool res = (pub_shares_G2 == pub_shares_dkg);
REQUIRE( res == true);
free(errMsg);
free(errMsg1);
free(encrypted_dkg_secret);
free(public_shares);
REQUIRE(res == true);
sgx_destroy_enclave(eid);
}
TEST_CASE( "DKG encrypted secret shares test", "[dkg-encr_sshares]" ) {
TEST_CASE("DKG encrypted secret shares test", "[dkg-encr_sshares]") {
autoconfirm = true;
// init_all();
init_enclave();
uint8_t *encrypted_key = (uint8_t *) calloc(BUF_LEN, 1);
char *errMsg = (char *)calloc(1024, 1);
char *result = (char *)calloc(130, 1);
vector<char> errMsg(1024, 1);
vector<char> result(130, 1);
int err_status = 0;
uint32_t enc_len = 0;
uint8_t* encrypted_dkg_secret = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);
status = gen_dkg_secret (eid, &err_status, errMsg, encrypted_dkg_secret, &enc_len, 2);
vector<uint8_t> encrypted_dkg_secret(DKG_MAX_SEALED_LEN, 0);
status = gen_dkg_secret(eid, &err_status, errMsg.data(), encrypted_dkg_secret.data(), &enc_len, 2);
REQUIRE(status == SGX_SUCCESS);
cerr << " poly generated" << endl;
status = set_encrypted_dkg_poly(eid, &err_status, errMsg, encrypted_dkg_secret);
status = set_encrypted_dkg_poly(eid, &err_status, errMsg.data(), encrypted_dkg_secret.data());
REQUIRE(status == SGX_SUCCESS);
cerr << " poly set" << endl;
uint8_t *encr_pr_DHkey = (uint8_t *)calloc(1024, 1);
char *pub_key_x = (char *)calloc(1024, 1);
char *pub_key_y = (char *)calloc(1024, 1);
vector<uint8_t> encrPRDHKey(1024, 0);
string pub_keyB = "c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475";
vector<char> s_shareG2(320,0);
status = get_encr_sshare(eid, &err_status, errMsg.data(), encrPRDHKey.data(), &enc_len, result.data(), s_shareG2.data(),
(char*) pub_keyB.data(), 2, 2, 1);
char *pub_keyB = "c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475";
char s_shareG2[320];
status = get_encr_sshare(eid, &err_status, errMsg, encr_pr_DHkey, &enc_len, result, s_shareG2,
pub_keyB, 2, 2, 1);
REQUIRE(status == SGX_SUCCESS);
printf(" get_encr_sshare completed with status: %d %s \n", err_status, errMsg);
printf(" get_encr_sshare completed with status: %d %s \n", err_status, errMsg.data());
cerr << "secret share is " << result << endl;
cerr << "secret share is " << result.data() << endl;
sgx_destroy_enclave(eid);
}
TEST_CASE( "DKG verification test", "[dkg-verify]" ) {
TEST_CASE("DKG verification test", "[dkg-verify]") {
autoconfirm = true;
// init_all();
init_enclave();
uint8_t *encrypted_key = (uint8_t *) calloc(BUF_LEN, 1);
char *errMsg = (char *)calloc(1024, 1);
char *result = (char *)calloc(130, 1);
vector<char> errMsg(1024, 0);
vector<char> result(130, 0);
int err_status = 0;
uint32_t enc_len = 0;
vector<uint8_t> encrypted_dkg_secret(DKG_MAX_SEALED_LEN, 1);
uint8_t* encrypted_dkg_secret = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);
status = gen_dkg_secret (eid, &err_status, errMsg, encrypted_dkg_secret, &enc_len, 2);
status = gen_dkg_secret(eid, &err_status, errMsg.data(), encrypted_dkg_secret.data(), &enc_len, 2);
REQUIRE(status == SGX_SUCCESS);
cerr << " poly generated" << endl;
status = set_encrypted_dkg_poly(eid, &err_status, errMsg, encrypted_dkg_secret);
status = set_encrypted_dkg_poly(eid, &err_status, errMsg.data(), encrypted_dkg_secret.data());
REQUIRE(status == SGX_SUCCESS);
cerr << " poly set" << endl;
uint8_t *encr_pr_DHkey = (uint8_t *)calloc(1024, 1);
char *pub_key_x = (char *)calloc(1024, 1);
char *pub_key_y = (char *)calloc(1024, 1);
vector<uint8_t> encrPrDHKey(1024, 0);
char *pub_keyB = "c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475";
string pub_keyB = "c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475";
char s_shareG2[320];
status = get_encr_sshare(eid, &err_status, errMsg, encr_pr_DHkey, &enc_len, result, s_shareG2,
pub_keyB, 2, 2, 1);
vector<char> s_shareG2(320,0);
status = get_encr_sshare(eid, &err_status, errMsg.data(), encrPrDHKey.data(), &enc_len, result.data(), s_shareG2.data(),
(char*) pub_keyB.data(), 2, 2, 1);
REQUIRE(status == SGX_SUCCESS);
printf(" get_encr_sshare completed with status: %d %s \n", err_status, errMsg);
printf(" get_encr_sshare completed with status: %d %s \n", err_status, errMsg.data());
cerr << "secret share is " << result << endl;
cerr << "secret share is " << result.data() << endl;
sgx_destroy_enclave(eid);
......@@ -529,61 +400,63 @@ TEST_CASE( "DKG verification test", "[dkg-verify]" ) {
TEST_CASE("ECDSA keygen and signature test", "[ecdsa_test]") {
autoconfirm = true;
init_enclave();
char *errMsg = (char *)calloc(1024, 1);
vector<char> errMsg(1024, 0);
int err_status = 0;
uint8_t *encr_pr_key = (uint8_t *)calloc(1024, 1);
vector<uint8_t> encr_pr_key(1024, 0);
vector<char> pub_key_x(1024, 0);
vector<char> pub_key_y(1024, 0);
char *pub_key_x = (char *)calloc(1024, 1);
char *pub_key_y = (char *)calloc(1024, 1);
uint32_t enc_len = 0;
//printf("before %p\n", pub_key_x);
status = generate_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y );
printf("\nerrMsg %s\n", errMsg );
status = generate_ecdsa_key(eid, &err_status, errMsg.data(), encr_pr_key.data(), &enc_len, pub_key_x.data(),
pub_key_y.data());
printf("\nerrMsg %s\n", errMsg.data());
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("\nwas pub_key_x %s: \n", pub_key_x.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]);*/
char* hex = "3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F";
string hex = "3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F";
// char* hex = "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
printf("hash length %d ", strlen(hex));
char* signature_r = (char *)calloc(1024, 1);
char* signature_s = (char *)calloc(1024, 1);
printf("hash length %d ", (int) hex.size());
vector<char> signature_r(1024, 0);
vector<char> signature_s(1024, 0);
uint8_t signature_v = 0;
status = ecdsa_sign1(eid, &err_status, errMsg, encr_pr_key, enc_len, (unsigned char*)hex, signature_r, signature_s, &signature_v, 16);
status = ecdsa_sign1(eid, &err_status, errMsg.data(), encr_pr_key.data(), enc_len, (unsigned char *) hex.data(),
signature_r.data(),
signature_s.data(), &signature_v, 16);
REQUIRE(status == SGX_SUCCESS);
printf("\nsignature r : %s ", signature_r);
printf("\nsignature s: %s ", signature_s);
printf("\nsignature r : %s ", signature_r.data());
printf("\nsignature s: %s ", signature_s.data());
printf("\nsignature v: %u ", signature_v);
printf("\n %s \n", errMsg);
printf("\n %s \n", errMsg.data());
free(errMsg);
sgx_destroy_enclave(eid);
printf("the end of ecdsa test\n");
}
TEST_CASE("Test test", "[test_test]") {
autoconfirm = true;
init_enclave();
char *errMsg = (char *)calloc(1024, 1);
vector<char> errMsg(1024, 0);
int err_status = 0;
uint8_t *encr_pr_key = (uint8_t *)calloc(1024, 1);
char *pub_key_x = (char *)calloc(1024, 1);
char *pub_key_y = (char *)calloc(1024, 1);
vector<uint8_t> encr_pr_key(1024, 0);
vector<char> pub_key_x(1024, 0);
vector<char> pub_key_y(1024, 0);
uint32_t enc_len = 0;
status = generate_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y );
status = generate_ecdsa_key(eid, &err_status, errMsg.data(), encr_pr_key.data(), &enc_len, pub_key_x.data(),
pub_key_y.data());
//printf("\nerrMsg %s\n", errMsg );
REQUIRE(status == SGX_SUCCESS);
......@@ -595,50 +468,48 @@ TEST_CASE("Test test", "[test_test]") {
//for ( int i = 0; i < 1024 ; i++)
// printf("%u ", encr_pr_key[i]);
//printf( "haha");
//free(errMsg);
sgx_destroy_enclave(eid);
}
TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") {
autoconfirm = true;
//init_all();
init_enclave();
char *errMsg = (char *)calloc(1024, 1);
int err_status = 0;
uint8_t *encr_pr_key = (uint8_t *)calloc(1024, 1);
char *pub_key_x = (char *)calloc(1024, 1);
char *pub_key_y = (char *)calloc(1024, 1);
vector<char> errMsg(1024, 0);
vector<uint8_t> encr_pr_key(1024, 0);
vector<char> pub_key_x(1024, 0);
vector<char> pub_key_y(1024, 0);
uint32_t enc_len = 0;
//printf("before %p\n", pub_key_x);
status = generate_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y );
printf("\nerrMsg %s\n", errMsg );
status = generate_ecdsa_key(eid, &err_status, errMsg.data(), encr_pr_key.data(), &enc_len, pub_key_x.data(),
pub_key_y.data());
printf("\nerrMsg %s\n", errMsg.data());
REQUIRE(status == SGX_SUCCESS);
printf("\nwas pub_key_x %s length %d: \n", pub_key_x, strlen(pub_key_x));
printf("\nwas pub_key_y %s length %d: \n", pub_key_y, strlen(pub_key_y));
printf("\nwas pub_key_x %s length %d: \n", pub_key_x.data(), (int) strlen(pub_key_x.data()));
printf("\nwas pub_key_y %s length %d: \n", pub_key_y.data(), (int) strlen(pub_key_y.data()));
/*printf("\nencr priv_key %s: \n");
for ( int i = 0; i < 1024 ; i++)
printf("%u ", encr_pr_key[i]);*/
char *got_pub_key_x = (char *)calloc(1024, 1);
char *got_pub_key_y = (char *)calloc(1024, 1);
vector<char> got_pub_key_x(1024, 0);
vector<char> got_pub_key_y(1024, 0);
status = get_public_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, enc_len, got_pub_key_x, got_pub_key_y);
status = get_public_ecdsa_key(eid, &err_status, errMsg.data(), encr_pr_key.data(), enc_len, got_pub_key_x.data(),
got_pub_key_y.data());
REQUIRE(status == SGX_SUCCESS);
printf("\nnow pub_key_x %s: \n", got_pub_key_x);
printf("\nnow pub_key_y %s: \n", got_pub_key_y);
printf("\n pr key %s \n", errMsg);
printf("\nnow pub_key_x %s: \n", got_pub_key_x.data());
printf("\nnow pub_key_y %s: \n", got_pub_key_y.data());
printf("\n pr key %s \n", errMsg.data());
free(errMsg);
sgx_destroy_enclave(eid);
}
......@@ -656,19 +527,18 @@ TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") {
}*/
#include "stubclient.h"
#include <jsonrpccpp/client/connectors/httpclient.h>
using namespace jsonrpc;
using namespace std;
string ConvertDecToHex(string dec, int numBytes = 32){
string ConvertDecToHex(string dec, int numBytes = 32) {
mpz_t num;
mpz_init(num);
mpz_set_str(num, dec.c_str(), 10);
char tmp[mpz_sizeinbase (num, 16) + 2];
char * hex = mpz_get_str(tmp, 16, num);
vector<char> tmp(mpz_sizeinbase(num, 16) + 2, 0);
char *hex = mpz_get_str(tmp.data(), 16, num);
string result = hex;
int n_zeroes = numBytes * 2 - result.length();
......@@ -681,8 +551,8 @@ string ConvertDecToHex(string dec, int numBytes = 32){
TEST_CASE("BLS_DKG test", "[bls_dkg]") {
is_sgx_https = 0;
DEBUG_PRINT = 1;
cerr<< "test started" << endl;
init_all(false, false, init_SEK);
cerr << "test started" << endl;
init_all(false, true, init_SEK);
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2);
......@@ -703,9 +573,10 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
int schain_id = rand_gen();
int dkg_id = rand_gen();
for ( uint8_t i = 0; i < n; i++){
for (uint8_t i = 0; i < n; i++) {
EthKeys[i] = c.generateECDSAKey();
string polyName = "POLY:SCHAIN_ID:" + to_string(schain_id) + ":NODE_ID:" + to_string(i) + ":DKG_ID:" + to_string(dkg_id);
string polyName =
"POLY:SCHAIN_ID:" + to_string(schain_id) + ":NODE_ID:" + to_string(i) + ":DKG_ID:" + to_string(dkg_id);
c.generateDKGPoly(polyName, t);
poly_names[i] = polyName;
......@@ -716,14 +587,14 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
}
for ( uint8_t i = 0; i < n; i++){
for (uint8_t i = 0; i < n; i++) {
secretShares[i] = c.getSecretShare(poly_names[i], pubEthKeys, t, n);
cout << secretShares[i] << std::endl;
cout << secretShares[i] << endl;
REQUIRE(secretShares[i]["status"] == 0);
for ( uint8_t k = 0; k < t; k++ ) {
for (uint8_t k = 0; k < t; k++) {
for (uint8_t j = 0; j < 4; j++) {
string pubShare = VerifVects[i]["verificationVector"][k][j].asString();
REQUIRE(pubShare.length() > 60 );
REQUIRE(pubShare.length() > 60);
pubShares[i] += ConvertDecToHex(pubShare);
}
}
......@@ -737,24 +608,26 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
int k = 0;
vector < string> secShares_vect(n);
vector<string> secShares_vect(n);
vector <string> pSharesBad(pubShares);
vector<string> pSharesBad(pubShares);
for ( int i = 0; i < n; i++)
for ( int j = 0; j < n; j++){
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
// if ( i != j ){
cerr << "secretShare length is " << secretShares[i]["secretShare"].asString().length() << endl;
string secretShare = secretShares[i]["secretShare"].asString().substr(192*j, 192);
secShares_vect[i] += secretShares[j]["secretShare"].asString().substr(192*i, 192);
cerr << "pubShare is " << pubShares[i] << std::endl;
bool res = c.dkgVerification(pubShares[i], EthKeys[j]["keyName"].asString(), secretShare, t, n, j)["result"].asBool();
string secretShare = secretShares[i]["secretShare"].asString().substr(192 * j, 192);
secShares_vect[i] += secretShares[j]["secretShare"].asString().substr(192 * i, 192);
cerr << "pubShare is " << pubShares[i] << endl;
bool res = c.dkgVerification(pubShares[i], EthKeys[j]["keyName"].asString(), secretShare, t, n,
j)["result"].asBool();
k++;
cerr << "NOW K IS " << k << " i is " << i << " j is " << j << endl;
REQUIRE(res);
pSharesBad[i][0] = 'q';
Json::Value wrongVerif = c.dkgVerification(pSharesBad[i], EthKeys[j]["keyName"].asString(), secretShare, t, n, j);
Json::Value wrongVerif = c.dkgVerification(pSharesBad[i], EthKeys[j]["keyName"].asString(), secretShare, t,
n, j);
res = wrongVerif["result"].asBool();
REQUIRE(!res);
cerr << "wrong verification " << wrongVerif << endl;
......@@ -767,19 +640,20 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
auto hash_arr = make_shared<array<uint8_t, 32>>();
uint64_t binLen;
if (!hex2carray(hash.c_str(), &binLen, hash_arr->data())){
if (!hex2carray(hash.c_str(), &binLen, hash_arr->data())) {
throw RPCException(INVALID_HEX, "Invalid hash");
}
map<size_t, shared_ptr<BLSPublicKeyShare>> koefs_pkeys_map;
for ( int i = 0; i < t; i++){
for (int i = 0; i < t; i++) {
string endName = poly_names[i].substr(4);
string blsName = "BLS_KEY" + poly_names[i].substr(4);
string secretShare = secretShares[i]["secretShare"].asString();
//cout << c.createBLSPrivateKey(blsName, EthKeys[i]["keyName"].asString(), poly_names[i], secretShare, t, n);
cout << c.createBLSPrivateKey(blsName, EthKeys[i]["keyName"].asString(), poly_names[i], secShares_vect[i], t, n);
cout << c.createBLSPrivateKey(blsName, EthKeys[i]["keyName"].asString(), poly_names[i], secShares_vect[i], t,
n);
pubBLSKeys[i] = c.getBLSPublicKeyShare(blsName);
cerr << "BLS KEY SHARE NAME IS " << blsName << endl;
//string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
......@@ -790,29 +664,29 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
sigShareSet.addSigShare(make_shared<BLSSigShare>(sig));
vector<string> pubKey_vect;
for ( uint8_t j = 0; j < 4; j++){
for (uint8_t j = 0; j < 4; j++) {
pubKey_vect.push_back(pubBLSKeys[i]["blsPublicKeyShare"][j].asString());
}
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));
koefs_pkeys_map[i+1] = make_shared<BLSPublicKeyShare>(pubKey);
koefs_pkeys_map[i + 1] = make_shared<BLSPublicKeyShare>(pubKey);
}
shared_ptr<BLSSignature> commonSig = sigShareSet.merge();
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));
}
TEST_CASE("API test", "[api_test]") {
autoconfirm = true;
//DEBUG_PRINT = 1;
is_sgx_https = 0;
//cerr << __GNUC__ << endl;
cerr << "API test started" << endl;
init_all(false, false, init_SEK);
init_all(false, true, init_SEK);
//HttpServer httpserver(1025);
//SGXWalletServer s(httpserver,
// JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
......@@ -836,7 +710,8 @@ TEST_CASE("API test", "[api_test]") {
Json::Value genKey = c.generateECDSAKey();
cout << genKey << endl;
cout << c.ecdsaSignMessageHash(16, genKey["keyName"].asString(),"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db" );
cout << c.ecdsaSignMessageHash(16, genKey["keyName"].asString(),
"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db");
Json::Value getPubKey = c.getPublicECDSAKey(genKey["keyName"].asString());
cout << getPubKey << endl;
// cout << c.renameESDSAKey("NODE_1CHAIN_1","tmp_NEK:bcacde0d26c0ea2c7e649992e7f791e1fba2492f5b7ae63dadb799075167c7fc");
......@@ -860,8 +735,10 @@ TEST_CASE("API test", "[api_test]") {
// 2,2);
Json::Value publicKeys;
publicKeys.append("505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2");
publicKeys.append("378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25");
publicKeys.append(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2");
publicKeys.append(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25");
// cout << c.getSecretShare("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", publicKeys, 2, 2);
// cout << c.generateDKGPoly("p3", 3);
// cout << c.getSecretShare("p3",
......@@ -911,8 +788,9 @@ TEST_CASE("API test", "[api_test]") {
}
TEST_CASE("getServerStatus test", "[getServerStatus_test]") {
autoconfirm = true;
is_sgx_https = 0;
init_all( false, false, init_SEK );
init_all(false, true, init_SEK);
HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2);
REQUIRE(c.getServerStatus()["status"] == 0);
......@@ -920,8 +798,7 @@ TEST_CASE("getServerStatus test", "[getServerStatus_test]") {
}
void SendRPCRequest(){
void SendRPCRequest() {
cout << "Hello from thread " << this_thread::get_id() << endl;
HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2);
......@@ -940,20 +817,21 @@ void SendRPCRequest(){
int schain_id = rand_gen();
int dkg_id = rand_gen();
for ( uint8_t i = 0; i < n; i++){
for (uint8_t i = 0; i < n; i++) {
EthKeys[i] = c.generateECDSAKey();
string polyName = "POLY:SCHAIN_ID:" + to_string(schain_id) + ":NODE_ID:" + to_string(i) + ":DKG_ID:" + to_string(dkg_id);
string polyName =
"POLY:SCHAIN_ID:" + to_string(schain_id) + ":NODE_ID:" + to_string(i) + ":DKG_ID:" + to_string(dkg_id);
c.generateDKGPoly(polyName, t);
poly_names[i] = polyName;
VerifVects[i] = c.getVerificationVector(polyName, t, n);
REQUIRE( VerifVects[i]["status"] == 0);
REQUIRE(VerifVects[i]["status"] == 0);
cout << "VV " << i << " " << VerifVects[i] << endl;
pubEthKeys.append(EthKeys[i]["publicKey"]);
}
for ( uint8_t i = 0; i < n; i++){
for (uint8_t i = 0; i < n; i++) {
secretShares[i] = c.getSecretShare(poly_names[i], pubEthKeys, t, n);
for ( uint8_t k = 0; k < t; k++ ) {
for (uint8_t k = 0; k < t; k++) {
for (uint8_t j = 0; j < 4; j++) {
string pubShare = VerifVects[i]["Verification Vector"][k][j].asString();
pubShares[i] += ConvertDecToHex(pubShare);
......@@ -966,17 +844,16 @@ void SendRPCRequest(){
int k = 0;
vector <string> secShares_vect(n);
vector<string> secShares_vect(n);
for ( int i = 0; i < n; i++)
for ( int j = 0; j < n; j++){
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
// if ( i != j ){
cerr << "SecretShare length is " << secretShares[i]["secretShare"].asString().length() << endl;
string secretShare = secretShares[i]["secretShare"].asString().substr(192*j, 192 );
secShares_vect[i] += secretShares[j]["secretShare"].asString().substr(192*i, 192 );
string secretShare = secretShares[i]["secretShare"].asString().substr(192 * j, 192);
secShares_vect[i] += secretShares[j]["secretShare"].asString().substr(192 * i, 192);
Json::Value verif = c.dkgVerification(pubShares[i], EthKeys[j]["keyName"].asString(), secretShare, t, n, j);
cout << verif;
bool res = verif["result"].asBool();
k++;
cerr << "NOW K IS " << k << " i is " << i << " j is " << j << endl;
// REQUIRE( res );
......@@ -984,26 +861,26 @@ void SendRPCRequest(){
}
BLSSigShareSet sigShareSet(t, n);
string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
auto hash_arr = make_shared<array<uint8_t, 32>>();
uint64_t binLen;
if (!hex2carray(hash.c_str(), &binLen, hash_arr->data())){
if (!hex2carray(hash.c_str(), &binLen, hash_arr->data())) {
throw RPCException(INVALID_HEX, "Invalid hash");
}
map<size_t, shared_ptr<BLSPublicKeyShare>> koefs_pkeys_map;
for ( int i = 0; i < t ; i++){
for (int i = 0; i < t; i++) {
string endName = poly_names[i].substr(4);
string blsName = "BLS_KEY" + poly_names[i].substr(4);
string secretShare = secretShares[i]["secretShare"].asString();
//cout << c.createBLSPrivateKey(blsName, EthKeys[i]["keyName"].asString(), poly_names[i], secretShare, t, n);
cout << c.createBLSPrivateKey(blsName, EthKeys[i]["keyName"].asString(), poly_names[i], secShares_vect[i], t, n);
cout << c.createBLSPrivateKey(blsName, EthKeys[i]["keyName"].asString(), poly_names[i], secShares_vect[i], t,
n);
pubBLSKeys[i] = c.getBLSPublicKeyShare(blsName);
cerr << "BLS KEY SHARE NAME IS " << blsName << endl;
string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
......@@ -1030,22 +907,23 @@ void SendRPCRequest(){
// REQUIRE( common_public.VerifySigWithHelper(hash_arr, commonSig, t, n) );
}
}
TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
autoconfirm = true;
is_sgx_https = 0;
DEBUG_PRINT = 1;
is_aes = 1;
init_all( false, false, init_SEK );
init_all(false, true, init_SEK);
vector<thread> threads;
int num_threads = 4;
for (int i = 0; i < num_threads; i++){
for (int i = 0; i < num_threads; i++) {
threads.push_back(thread(SendRPCRequest));
}
for(auto& thread : threads){
for (auto &thread : threads) {
thread.join();
}
......@@ -1053,12 +931,13 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
}
TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
autoconfirm = true;
DEBUG_PRINT = 1;
is_sgx_https = 0;
is_aes = 1;
cerr << "ecdsa_api_test started" << endl;
init_all(false, false, init_SEK);
init_all(false, true, init_SEK);
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1029");
......@@ -1075,7 +954,8 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
REQUIRE(getPubKey["status"].asInt() == 0);
REQUIRE(getPubKey["publicKey"].asString() == genKey["publicKey"].asString());
Json::Value ecdsaSign = c.ecdsaSignMessageHash(16, genKey["keyName"].asString(), "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db");
Json::Value ecdsaSign = c.ecdsaSignMessageHash(16, genKey["keyName"].asString(),
"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db");
cout << ecdsaSign << endl;
REQUIRE(ecdsaSign["status"].asInt() == 0);
......@@ -1103,11 +983,12 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
}
TEST_CASE("dkg API test", "[dkg_api_test]") {
autoconfirm = true;
DEBUG_PRINT = 1;
is_sgx_https = 0;
cerr << "dkg_api_test started" << endl;
init_all(false, false, init_SEK);
init_all(false, true, init_SEK);
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1029");
......@@ -1121,8 +1002,10 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
Json::Value genPoly = c.generateDKGPoly(polyName, 2);
Json::Value publicKeys;
publicKeys.append("505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2");
publicKeys.append("378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25");
publicKeys.append(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2");
publicKeys.append(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25");
// wrongName
Json::Value genPolyWrongName = c.generateDKGPoly("poly", 2);
......@@ -1156,7 +1039,8 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
cout << verifVectWrong_n << endl;
Json::Value publicKeys1;
publicKeys1.append("505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2");
publicKeys1.append(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2");
Json::Value secretSharesWrong_n = c.getSecretShare(polyName, publicKeys1, 2, 1);
REQUIRE(secretSharesWrong_n["status"].asInt() != 0);
cout << secretSharesWrong_n << endl;
......@@ -1169,7 +1053,7 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
//wrong verif
Json::Value Skeys = c.getSecretShare(polyName, publicKeys, 2, 2);
Json::Value verifVect = c.getVerificationVector(polyName, 2, 2);
Json::Value verificationWrongSkeys = c.dkgVerification("","","",2, 2, 1);
Json::Value verificationWrongSkeys = c.dkgVerification("", "", "", 2, 2, 1);
REQUIRE(verificationWrongSkeys["status"].asInt() != 0);
cout << verificationWrongSkeys << endl;
......@@ -1177,11 +1061,12 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
}
TEST_CASE("isPolyExists test", "[is_poly_test]") {
autoconfirm = true;
DEBUG_PRINT = 1;
is_sgx_https = 0;
cerr << "is_poly_test started" << endl;
init_all(false, false, init_SEK);
init_all(false, true, init_SEK);
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1029");
......@@ -1205,15 +1090,15 @@ TEST_CASE("isPolyExists test", "[is_poly_test]") {
}
TEST_CASE("AES_DKG test", "[aes_dkg]") {
autoconfirm = true;
is_sgx_https = 0;
DEBUG_PRINT = 1;
is_aes = 1;
reset_db();
std::cerr << "test started" << std::endl;
init_all(false, false, init_SEK);
cerr << "test started" << endl;
init_all(false, true, init_SEK);
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2);
......@@ -1231,24 +1116,25 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
int schain_id = rand_gen();
int dkg_id = rand_gen();
for ( uint8_t i = 0; i < n; i++){
for (uint8_t i = 0; i < n; i++) {
EthKeys[i] = c.generateECDSAKey();
std::cerr << "after gen key" << std::endl;
string polyName = "POLY:SCHAIN_ID:" + to_string(schain_id) + ":NODE_ID:" + to_string(i) + ":DKG_ID:" + to_string(dkg_id);
cerr << "after gen key" << endl;
string polyName =
"POLY:SCHAIN_ID:" + to_string(schain_id) + ":NODE_ID:" + to_string(i) + ":DKG_ID:" + to_string(dkg_id);
REQUIRE(EthKeys[i]["status"] == 0);
cout << c.generateDKGPoly(polyName, t);
poly_names[i] = polyName;
VerifVects[i] = c.getVerificationVector(polyName, t, n);
cout << "VV " << i << " " << VerifVects[i] << std::endl;
cout << "VV " << i << " " << VerifVects[i] << endl;
pubEthKeys.append(EthKeys[i]["publicKey"]);
}
for ( uint8_t i = 0; i < n; i++){
for (uint8_t i = 0; i < n; i++) {
secretShares[i] = c.getSecretShare(poly_names[i], pubEthKeys, t, n);
cout << secretShares[i] << std::endl;
cout << secretShares[i] << endl;
REQUIRE(secretShares[i]["status"] == 0);
for ( uint8_t k = 0; k < t; k++ )
for (uint8_t j = 0; j < 4; j++){
for (uint8_t k = 0; k < t; k++)
for (uint8_t j = 0; j < 4; j++) {
string pubShare = VerifVects[i]["verificationVector"][k][j].asString();
pubShares[i] += ConvertDecToHex(pubShare);
}
......@@ -1262,20 +1148,20 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
}
int k = 0;
vector <string> secShares_vect(n);
vector<string> secShares_vect(n);
for ( int i = 0; i < n; i++)
for ( int j = 0; j < n; j++){
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
// if ( i != j ){
cerr << "SecretShare length is " << secretShares[i]["secretShare"].asString().length() << endl;
string secretShare = secretShares[i]["secretShare"].asString().substr(192 * j, 192 );
secShares_vect[i] += secretShares[j]["secretShare"].asString().substr(192 * i, 192 );
string secretShare = secretShares[i]["secretShare"].asString().substr(192 * j, 192);
secShares_vect[i] += secretShares[j]["secretShare"].asString().substr(192 * i, 192);
Json::Value verif = c.dkgVerification(pubShares[i], EthKeys[j]["keyName"].asString(), secretShare, t, n, j);
cout << verif;
bool res = verif["result"].asBool();
k++;
cerr << "NOW K IS " << k << " i is " << i << " j is " << j << endl;
REQUIRE( res );
REQUIRE(res);
// }
}
......@@ -1292,56 +1178,57 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
auto hash_arr = make_shared<array<uint8_t, 32>>();
uint64_t binLen;
if (!hex2carray(hash.c_str(), &binLen, hash_arr->data())){
if (!hex2carray(hash.c_str(), &binLen, hash_arr->data())) {
throw RPCException(INVALID_HEX, "Invalid hash");
}
map<size_t, shared_ptr<BLSPublicKeyShare>> koefs_pkeys_map;
for ( int i = 0; i < t; i++){
for (int i = 0; i < t; i++) {
string endName = poly_names[i].substr(4);
string blsName = "BLS_KEY" + poly_names[i].substr(4);
cout << c.createBLSPrivateKey(blsName, EthKeys[i]["keyName"].asString(), poly_names[i], secShares_vect[i], t, n);
cout << c.createBLSPrivateKey(blsName, EthKeys[i]["keyName"].asString(), poly_names[i], secShares_vect[i], t,
n);
pubBLSKeys[i] = c.getBLSPublicKeyShare(blsName);
cout << pubBLSKeys[i] << endl;
REQUIRE(pubBLSKeys[i]["status"] == 0);
cerr << "BLS KEY SHARE NAME IS" << blsName << endl;
string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
BLSSigShares[i] = c.blsSignMessageHash(blsName, hash, t, n, i + 1);
cout << BLSSigShares[i] << std::endl;
REQUIRE( BLSSigShares[i]["status"] == 0);
cout << BLSSigShares[i] << endl;
REQUIRE(BLSSigShares[i]["status"] == 0);
cerr << i << " sig share is created " << endl;
shared_ptr<string> sig_share_ptr = make_shared<string>(BLSSigShares[i]["signatureShare"].asString());
BLSSigShare sig(sig_share_ptr, i + 1, t, n);
sigShareSet.addSigShare(make_shared<BLSSigShare>(sig));
vector<string> pubKey_vect;
for ( uint8_t j = 0; j < 4; j++){
for (uint8_t j = 0; j < 4; j++) {
pubKey_vect.push_back(pubBLSKeys[i]["blsPublicKeyShare"][j].asString());
}
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));
koefs_pkeys_map[i+1] = make_shared<BLSPublicKeyShare>(pubKey);
koefs_pkeys_map[i + 1] = make_shared<BLSPublicKeyShare>(pubKey);
}
shared_ptr<BLSSignature> commonSig = sigShareSet.merge();
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("bls_sign_api test", "[bls_sign]") {
autoconfirm = true;
is_sgx_https = 0;
DEBUG_PRINT = 1;
is_aes = 1;
std::cerr << "test started" << std::endl;
init_all(false, false, init_SEK);
cerr << "test started" << endl;
init_all(false, true, init_SEK);
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2);
......@@ -1355,7 +1242,6 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
cout << pubBLSKey << endl;
Json::Value sign = c.blsSignMessageHash(blsName, hash, t, n, 1);
cout << sign << endl;
REQUIRE(sign["status"] == 0);
......@@ -1371,38 +1257,126 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") {
{
autoconfirm = true;
DEBUG_PRINT = 1;
is_sgx_https = 0;
init_all(false, false, init_SEK);
init_all(false, true, init_SEK);
//init_enclave();
int errStatus = -1;
char* errMsg = (char*) calloc(BUF_LEN, 1);
vector<char> errMsg(BUF_LEN, 0);;
uint32_t enc_len;
string key = "123456789";
vector<uint8_t> encrypted_key(BUF_LEN,0);
std::string key = "123456789";
uint8_t encrypted_key[BUF_LEN];
memset(encrypted_key, 0, BUF_LEN);
status = encrypt_key_aes(eid, &errStatus, errMsg, key.c_str(), encrypted_key, &enc_len);
status = encrypt_key_aes(eid, &errStatus, errMsg.data(), key.c_str(), encrypted_key.data(), &enc_len);
REQUIRE(status == 0);
std::cerr << "key encrypted with status " << status << " err msg " << errMsg << std::endl;
cerr << "key encrypted with status " << status << " err msg " << errMsg.data() << endl;
char decr_key[BUF_LEN];
memset(decr_key, 0, BUF_LEN);
status = decrypt_key_aes(eid, &errStatus, errMsg, encrypted_key, enc_len, decr_key);
vector<char> decr_key(BUF_LEN, 0);
status = decrypt_key_aes(eid, &errStatus, errMsg.data(), encrypted_key.data(), enc_len, decr_key.data());
REQUIRE(status == 0);
std::cerr << "key encrypted with status " << status << " err msg " << errMsg << std::endl;
std::cerr << "decrypted key is " << decr_key << std::endl;
REQUIRE( key.compare(decr_key) == 0);
cerr << "key encrypted with status " << status << " err msg " << errMsg.data() << endl;
cerr << "decrypted key is " << decr_key.data() << endl;
REQUIRE(key.compare(decr_key.data()) == 0);
sgx_destroy_enclave(eid);
}
}
//TEST_CASE("BLS key import", "[bls-key-import]") {
// reset_db();
// init_all(false, true);
//
//
//
// auto result = importBLSKeyShareImpl(TEST_BLS_KEY_SHARE, TEST_BLS_KEY_NAME, 2, 2, 1);
//
// REQUIRE(result["status"] == 0);
//
// REQUIRE(result["encryptedKeyShare"] != "");
//
//
//TEST_CASE("BLS sign test", "[bls-sign]") {
//
// //init_all();
// init_enclave();
//
// char* encryptedKeyHex ="04000200000000000406ffffff02000000000000000000000b000000000000ff0000000000000000813f8390f6228a568e181a4dadb6508e3e66f5247175d65dbd0d8c7fbfa4df45000000f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000008000000000000000000000000000000000dc044ae0cd79faaf41e8a7abb412790476738a98b5b6ce95fa1a32db5551b0a0d867305f4de558c64fee730a1f62394633c7d4ca65e3a40b7883e89c2801c61918b01c5de8624a52963df6f4de8581bcbdd2f9b69720d4cc764e03a04c7a99314bfdb5d2d55deda2ca40cd691f093fb2ecbae24cdacdd4d5de93189c6dfd6792d7b95bd5e330aec3538e7a85d15793"; //encryptTestKey();
//
// REQUIRE(encryptedKeyHex != nullptr);
//
//
// // const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788";
// const char *hexHash = "3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F";
//
// char* hexHashBuf = (char*) calloc(BUF_LEN, 1);
//
// strncpy(hexHashBuf, hexHash, BUF_LEN);
//
// char sig[BUF_LEN];
// auto result = sign(encryptedKeyHex, hexHashBuf, 2, 2, 1, sig);
//
// REQUIRE(result == true);
// printf("Signature is: %s \n", sig );
//
//}
//
//TEST_CASE("Server BLS sign test", "[bls-server-sign]") {
//
// reset_db();
//
// init_all(false, true);
//
//
// auto result = importBLSKeyShareImpl( TEST_BLS_KEY_SHARE, TEST_BLS_KEY_NAME, 2, 2, 1);
//
// REQUIRE(result["status"] == 0);
//
// REQUIRE(result["encryptedKeyShare"] != "");
//
// const char *hexHash = "001122334455667788" "001122334455667788" "001122334455667788" "001122334455667788";
//
// REQUIRE_NOTHROW(result = blsSignMessageHashImpl(TEST_BLS_KEY_NAME, hexHash,2,2,1));
//
// if (result["status"] != 0) {
// printf("Error message: %s", result["errorMessage"].asString().c_str());
// }
//
//
// REQUIRE(result["status"] == 0);
// REQUIRE(result["signatureShare"] != "");
//
// printf("Signature is: %s \n", result["signatureShare"].asString().c_str());
//
//}
//TEST_CASE("KeysDB test", "[keys-db]") {
//
//
//
// reset_db();
// init_all();
//
//
// string key = TEST_BLS_KEY_SHARE;
// string value = TEST_BLS_KEY_SHARE;
//
//
//
// REQUIRE_THROWS(readKeyShare(key));
//
//
// writeKeyShare(key, value, 1, 2, 1);
//
// REQUIRE(readKeyShare(key) != nullptr);
//
//
//// put your test here
//}
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